Rollup merge of #69734 - tmiasko:di-enumerator, r=ecstatic-morse

Change DIBuilderCreateEnumerator signature to match LLVM 9

* Change DIBuilderCreateEnumerator signature to match LLVM 9 C API.
* Use provided is unsigned flag when emitting enumerators.
This commit is contained in:
Mazdak Farrokhzad 2020-03-08 20:54:31 +01:00 committed by GitHub
commit e2617a98c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 12 deletions

View File

@ -1779,13 +1779,20 @@ fn prepare_enum_metadata(
.discriminants(cx.tcx)
.zip(&def.variants)
.map(|((_, discr), v)| {
let name = SmallCStr::new(&v.ident.as_str());
let name = v.ident.as_str();
let is_unsigned = match discr.ty.kind {
ty::Int(_) => false,
ty::Uint(_) => true,
_ => bug!("non integer discriminant"),
};
unsafe {
Some(llvm::LLVMRustDIBuilderCreateEnumerator(
DIB(cx),
name.as_ptr(),
name.as_ptr().cast(),
name.len(),
// FIXME: what if enumeration has i128 discriminant?
discr.val as u64,
discr.val as i64,
is_unsigned,
))
}
})
@ -1794,13 +1801,15 @@ fn prepare_enum_metadata(
.as_generator()
.variant_range(enum_def_id, cx.tcx)
.map(|variant_index| {
let name = SmallCStr::new(&substs.as_generator().variant_name(variant_index));
let name = substs.as_generator().variant_name(variant_index);
unsafe {
Some(llvm::LLVMRustDIBuilderCreateEnumerator(
DIB(cx),
name.as_ptr(),
// FIXME: what if enumeration has i128 discriminant?
variant_index.as_usize() as u64,
name.as_ptr().cast(),
name.len(),
// Generators use u32 as discriminant type.
variant_index.as_u32().into(),
true, // IsUnsigned
))
}
})

View File

@ -1776,7 +1776,9 @@ extern "C" {
pub fn LLVMRustDIBuilderCreateEnumerator(
Builder: &DIBuilder<'a>,
Name: *const c_char,
Val: u64,
NameLen: size_t,
Value: i64,
IsUnsigned: bool,
) -> &'a DIEnumerator;
pub fn LLVMRustDIBuilderCreateEnumerationType(

View File

@ -891,10 +891,10 @@ extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd(
unwrap(InsertAtEnd)));
}
extern "C" LLVMMetadataRef
LLVMRustDIBuilderCreateEnumerator(LLVMRustDIBuilderRef Builder,
const char *Name, uint64_t Val) {
return wrap(Builder->createEnumerator(Name, Val));
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerator(
LLVMRustDIBuilderRef Builder, const char *Name, size_t NameLen,
int64_t Value, bool IsUnsigned) {
return wrap(Builder->createEnumerator({Name, NameLen}, Value, IsUnsigned));
}
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerationType(

View File

@ -0,0 +1,27 @@
// Verify that DIEnumerator uses isUnsigned flag when appropriate.
//
// compile-flags: -g -C no-prepopulate-passes
#[repr(i64)]
pub enum I64 {
I64Min = std::i64::MIN,
I64Max = std::i64::MAX,
}
#[repr(u64)]
pub enum U64 {
U64Min = std::u64::MIN,
U64Max = std::u64::MAX,
}
fn main() {
let _a = I64::I64Min;
let _b = I64::I64Max;
let _c = U64::U64Min;
let _d = U64::U64Max;
}
// CHECK: !DIEnumerator(name: "I64Min", value: -9223372036854775808)
// CHECK: !DIEnumerator(name: "I64Max", value: 9223372036854775807)
// CHECK: !DIEnumerator(name: "U64Min", value: 0, isUnsigned: true)
// CHECK: !DIEnumerator(name: "U64Max", value: 18446744073709551615, isUnsigned: true)