about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/debuginfo/metadata
diff options
context:
space:
mode:
authorMichael Woerister <michaelwoerister@posteo>2022-07-20 16:15:02 +0200
committerMichael Woerister <michaelwoerister@posteo>2022-08-12 10:53:08 +0200
commit95d75914788aaae88930701f3c419257adbf8288 (patch)
treea1d1ed3b18407ecee53af4ec07668e0c9f26f584 /compiler/rustc_codegen_llvm/src/debuginfo/metadata
parent171d8a3f57b00ff9d213c74729c5ff228b016c8c (diff)
downloadrust-95d75914788aaae88930701f3c419257adbf8288.tar.gz
rust-95d75914788aaae88930701f3c419257adbf8288.zip
[debuginfo] Update cpp-like enum decoding docs to account for wrapping tag ranges.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/debuginfo/metadata')
-rw-r--r--compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs
index 410cfbc2de8..e3951c8d0f9 100644
--- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs
+++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs
@@ -142,7 +142,7 @@ const SINGLE_VARIANT_VIRTUAL_DISR: u64 = 0;
 ///                 let begin = variant_field.field("DISCR_BEGIN");
 ///                 let end = variant_field.field("DISCR_END");
 ///
-///                 if tag >= begin && tag <= end {
+///                 if is_in_range(tag, begin, end) {
 ///                     return (variant_field.field("NAME"), variant_field.value);
 ///                 }
 ///             }
@@ -169,7 +169,7 @@ const SINGLE_VARIANT_VIRTUAL_DISR: u64 = 0;
 ///                 let end = (variant_field.field("DISCR128_END_LO").value as u128) |
 ///                           (variant_field.field("DISCR128_END_HI").value as u128 << 64);
 ///
-///                 if tag >= begin && tag <= end {
+///                 if is_in_range(tag, begin, end) {
 ///                     return (variant_field.field("NAME"), variant_field.value);
 ///                 }
 ///             }
@@ -180,6 +180,16 @@ const SINGLE_VARIANT_VIRTUAL_DISR: u64 = 0;
 ///     unreachable!();
 /// }
 ///
+/// // Check if a value is within the given range
+/// // (where the range might wrap around the value space)
+/// fn is_in_range(value, start, end) -> bool {
+///     if start < end {
+///         value >= start && value <= end
+///     } else {
+///         value >= start || value <= end
+///     }
+/// }
+///
 /// ```
 pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
     cx: &CodegenCx<'ll, 'tcx>,