@@ -11,7 +11,7 @@ use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
11
11
use rustc_middle:: ty:: { self , AdtDef , CoroutineArgs , CoroutineArgsExt , Ty } ;
12
12
use smallvec:: smallvec;
13
13
14
- use crate :: common:: { AsCCharPtr , CodegenCx } ;
14
+ use crate :: common:: CodegenCx ;
15
15
use crate :: debuginfo:: dwarf_const:: DW_TAG_const_type ;
16
16
use crate :: debuginfo:: metadata:: enums:: DiscrResult ;
17
17
use crate :: debuginfo:: metadata:: type_map:: { self , Stub , UniqueTypeId } ;
@@ -378,20 +378,17 @@ fn build_single_variant_union_fields<'ll, 'tcx>(
378
378
variant_struct_type_wrapper_di_node,
379
379
None ,
380
380
) ,
381
- unsafe {
382
- llvm:: LLVMRustDIBuilderCreateStaticMemberType (
383
- DIB ( cx) ,
384
- enum_type_di_node,
385
- TAG_FIELD_NAME . as_c_char_ptr( ) ,
386
- TAG_FIELD_NAME . len( ) ,
387
- unknown_file_metadata( cx) ,
388
- UNKNOWN_LINE_NUMBER ,
389
- variant_names_type_di_node,
390
- visibility_flags,
391
- Some ( cx. const_u64( SINGLE_VARIANT_VIRTUAL_DISR ) ) ,
392
- tag_base_type_align. bits( ) as u32 ,
393
- )
394
- }
381
+ create_static_member_type(
382
+ cx,
383
+ enum_type_di_node,
384
+ TAG_FIELD_NAME ,
385
+ unknown_file_metadata( cx) ,
386
+ UNKNOWN_LINE_NUMBER ,
387
+ variant_names_type_di_node,
388
+ visibility_flags,
389
+ Some ( cx. const_u64( SINGLE_VARIANT_VIRTUAL_DISR ) ) ,
390
+ tag_base_type_align,
391
+ ) ,
395
392
]
396
393
}
397
394
@@ -570,27 +567,28 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
570
567
let build_assoc_const = |name : & str ,
571
568
type_di_node_ : & ' ll DIType ,
572
569
value : u64 ,
573
- align : Align | unsafe {
570
+ align : Align |
571
+ -> & ' ll llvm:: Metadata {
574
572
// FIXME: Currently we force all DISCR_* values to be u64's as LLDB seems to have
575
573
// problems inspecting other value types. Since DISCR_* is typically only going to be
576
574
// directly inspected via the debugger visualizer - which compares it to the `tag` value
577
575
// (whose type is not modified at all) it shouldn't cause any real problems.
578
576
let ( t_di, align) = if name == ASSOC_CONST_DISCR_NAME {
579
- ( type_di_node_, align. bits ( ) as u32 )
577
+ ( type_di_node_, align)
580
578
} else {
581
579
let ty_u64 = Ty :: new_uint ( cx. tcx , ty:: UintTy :: U64 ) ;
582
- ( type_di_node ( cx, ty_u64) , Align :: EIGHT . bits ( ) as u32 )
580
+ ( type_di_node ( cx, ty_u64) , Align :: EIGHT )
583
581
} ;
584
582
585
583
// must wrap type in a `const` modifier for LLDB to be able to inspect the value of the member
586
- let field_type =
587
- llvm:: LLVMRustDIBuilderCreateQualifiedType ( DIB ( cx) , DW_TAG_const_type , t_di) ;
584
+ let field_type = unsafe {
585
+ llvm:: LLVMDIBuilderCreateQualifiedType ( DIB ( cx) , DW_TAG_const_type , t_di)
586
+ } ;
588
587
589
- llvm :: LLVMRustDIBuilderCreateStaticMemberType (
590
- DIB ( cx ) ,
588
+ create_static_member_type (
589
+ cx ,
591
590
wrapper_struct_type_di_node,
592
- name. as_c_char_ptr ( ) ,
593
- name. len ( ) ,
591
+ name,
594
592
unknown_file_metadata ( cx) ,
595
593
UNKNOWN_LINE_NUMBER ,
596
594
field_type,
@@ -975,3 +973,30 @@ fn variant_struct_wrapper_type_name(variant_index: VariantIdx) -> Cow<'static, s
975
973
. map ( |& s| Cow :: from ( s) )
976
974
. unwrap_or_else ( || format ! ( "Variant{}" , variant_index. as_usize( ) ) . into ( ) )
977
975
}
976
+
977
+ fn create_static_member_type < ' ll > (
978
+ cx : & CodegenCx < ' ll , ' _ > ,
979
+ scope : & ' ll llvm:: Metadata ,
980
+ name : & str ,
981
+ file : & ' ll llvm:: Metadata ,
982
+ line_number : c_uint ,
983
+ ty : & ' ll llvm:: Metadata ,
984
+ flags : DIFlags ,
985
+ value : Option < & ' ll llvm:: Value > ,
986
+ align : Align ,
987
+ ) -> & ' ll llvm:: Metadata {
988
+ unsafe {
989
+ llvm:: LLVMDIBuilderCreateStaticMemberType (
990
+ DIB ( cx) ,
991
+ scope,
992
+ name. as_ptr ( ) ,
993
+ name. len ( ) ,
994
+ file,
995
+ line_number,
996
+ ty,
997
+ flags,
998
+ value,
999
+ align. bits ( ) as c_uint ,
1000
+ )
1001
+ }
1002
+ }
0 commit comments