Skip to content

Commit 95d7591

Browse files
[debuginfo] Update cpp-like enum decoding docs to account for wrapping tag ranges.
1 parent 171d8a3 commit 95d7591

File tree

1 file changed

+12
-2
lines changed
  • compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums

1 file changed

+12
-2
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const SINGLE_VARIANT_VIRTUAL_DISR: u64 = 0;
142142
/// let begin = variant_field.field("DISCR_BEGIN");
143143
/// let end = variant_field.field("DISCR_END");
144144
///
145-
/// if tag >= begin && tag <= end {
145+
/// if is_in_range(tag, begin, end) {
146146
/// return (variant_field.field("NAME"), variant_field.value);
147147
/// }
148148
/// }
@@ -169,7 +169,7 @@ const SINGLE_VARIANT_VIRTUAL_DISR: u64 = 0;
169169
/// let end = (variant_field.field("DISCR128_END_LO").value as u128) |
170170
/// (variant_field.field("DISCR128_END_HI").value as u128 << 64);
171171
///
172-
/// if tag >= begin && tag <= end {
172+
/// if is_in_range(tag, begin, end) {
173173
/// return (variant_field.field("NAME"), variant_field.value);
174174
/// }
175175
/// }
@@ -180,6 +180,16 @@ const SINGLE_VARIANT_VIRTUAL_DISR: u64 = 0;
180180
/// unreachable!();
181181
/// }
182182
///
183+
/// // Check if a value is within the given range
184+
/// // (where the range might wrap around the value space)
185+
/// fn is_in_range(value, start, end) -> bool {
186+
/// if start < end {
187+
/// value >= start && value <= end
188+
/// } else {
189+
/// value >= start || value <= end
190+
/// }
191+
/// }
192+
///
183193
/// ```
184194
pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
185195
cx: &CodegenCx<'ll, 'tcx>,

0 commit comments

Comments
 (0)