Skip to content

Commit 30650f8

Browse files
committed
debuginfo: Use is unsigned flag when emitting enumerators
1 parent ebd941b commit 30650f8

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/librustc_codegen_llvm/debuginfo/metadata.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1780,14 +1780,19 @@ fn prepare_enum_metadata(
17801780
.zip(&def.variants)
17811781
.map(|((_, discr), v)| {
17821782
let name = v.ident.as_str();
1783+
let is_unsigned = match discr.ty.kind {
1784+
ty::Int(_) => false,
1785+
ty::Uint(_) => true,
1786+
_ => bug!("non integer discriminant"),
1787+
};
17831788
unsafe {
17841789
Some(llvm::LLVMRustDIBuilderCreateEnumerator(
17851790
DIB(cx),
17861791
name.as_ptr().cast(),
17871792
name.len(),
17881793
// FIXME: what if enumeration has i128 discriminant?
17891794
discr.val as i64,
1790-
false, // FIXME: IsUnsigned.
1795+
is_unsigned,
17911796
))
17921797
}
17931798
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Verify that DIEnumerator uses isUnsigned flag when appropriate.
2+
//
3+
// compile-flags: -g -C no-prepopulate-passes
4+
5+
#[repr(i64)]
6+
pub enum I64 {
7+
I64Min = std::i64::MIN,
8+
I64Max = std::i64::MAX,
9+
}
10+
11+
#[repr(u64)]
12+
pub enum U64 {
13+
U64Min = std::u64::MIN,
14+
U64Max = std::u64::MAX,
15+
}
16+
17+
fn main() {
18+
let _a = I64::I64Min;
19+
let _b = I64::I64Max;
20+
let _c = U64::U64Min;
21+
let _d = U64::U64Max;
22+
}
23+
24+
// CHECK: !DIEnumerator(name: "I64Min", value: -9223372036854775808)
25+
// CHECK: !DIEnumerator(name: "I64Max", value: 9223372036854775807)
26+
// CHECK: !DIEnumerator(name: "U64Min", value: 0, isUnsigned: true)
27+
// CHECK: !DIEnumerator(name: "U64Max", value: 18446744073709551615, isUnsigned: true)

0 commit comments

Comments
 (0)