@@ -19,6 +19,7 @@ use crate::llvm::debuginfo::{
1919use crate :: value:: Value ;
2020
2121use log:: debug;
22+ use rustc_ast:: ast;
2223use rustc_codegen_ssa:: traits:: * ;
2324use rustc_data_structures:: const_cstr;
2425use rustc_data_structures:: fingerprint:: Fingerprint ;
@@ -824,14 +825,60 @@ fn file_metadata_raw(
824825 }
825826}
826827
828+ trait MsvcBasicName {
829+ fn msvc_basic_name ( self ) -> & ' static str ;
830+ }
831+
832+ impl MsvcBasicName for ast:: IntTy {
833+ fn msvc_basic_name ( self ) -> & ' static str {
834+ match self {
835+ ast:: IntTy :: Isize => "ptrdiff_t" ,
836+ ast:: IntTy :: I8 => "__int8" ,
837+ ast:: IntTy :: I16 => "__int16" ,
838+ ast:: IntTy :: I32 => "__int32" ,
839+ ast:: IntTy :: I64 => "__int64" ,
840+ ast:: IntTy :: I128 => "__int128" ,
841+ }
842+ }
843+ }
844+
845+ impl MsvcBasicName for ast:: UintTy {
846+ fn msvc_basic_name ( self ) -> & ' static str {
847+ match self {
848+ ast:: UintTy :: Usize => "size_t" ,
849+ ast:: UintTy :: U8 => "unsigned __int8" ,
850+ ast:: UintTy :: U16 => "unsigned __int16" ,
851+ ast:: UintTy :: U32 => "unsigned __int32" ,
852+ ast:: UintTy :: U64 => "unsigned __int64" ,
853+ ast:: UintTy :: U128 => "unsigned __int128" ,
854+ }
855+ }
856+ }
857+
858+ impl MsvcBasicName for ast:: FloatTy {
859+ fn msvc_basic_name ( self ) -> & ' static str {
860+ match self {
861+ ast:: FloatTy :: F32 => "float" ,
862+ ast:: FloatTy :: F64 => "double" ,
863+ }
864+ }
865+ }
866+
827867fn basic_type_metadata ( cx : & CodegenCx < ' ll , ' tcx > , t : Ty < ' tcx > ) -> & ' ll DIType {
828868 debug ! ( "basic_type_metadata: {:?}" , t) ;
829869
870+ // When targeting MSVC, emit MSVC style type names for compatibility with
871+ // .natvis visualizers (and perhaps other existing native debuggers?)
872+ let msvc_like_names = cx. tcx . sess . target . target . options . is_like_msvc ;
873+
830874 let ( name, encoding) = match t. kind {
831875 ty:: Never => ( "!" , DW_ATE_unsigned ) ,
832876 ty:: Tuple ( ref elements) if elements. is_empty ( ) => ( "()" , DW_ATE_unsigned ) ,
833877 ty:: Bool => ( "bool" , DW_ATE_boolean ) ,
834878 ty:: Char => ( "char" , DW_ATE_unsigned_char ) ,
879+ ty:: Int ( int_ty) if msvc_like_names => ( int_ty. msvc_basic_name ( ) , DW_ATE_signed ) ,
880+ ty:: Uint ( uint_ty) if msvc_like_names => ( uint_ty. msvc_basic_name ( ) , DW_ATE_unsigned ) ,
881+ ty:: Float ( float_ty) if msvc_like_names => ( float_ty. msvc_basic_name ( ) , DW_ATE_float ) ,
835882 ty:: Int ( int_ty) => ( int_ty. name_str ( ) , DW_ATE_signed ) ,
836883 ty:: Uint ( uint_ty) => ( uint_ty. name_str ( ) , DW_ATE_unsigned ) ,
837884 ty:: Float ( float_ty) => ( float_ty. name_str ( ) , DW_ATE_float ) ,
@@ -848,7 +895,30 @@ fn basic_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
848895 )
849896 } ;
850897
851- ty_metadata
898+ if !msvc_like_names {
899+ return ty_metadata;
900+ }
901+
902+ let typedef_name = match t. kind {
903+ ty:: Int ( int_ty) => int_ty. name_str ( ) ,
904+ ty:: Uint ( uint_ty) => uint_ty. name_str ( ) ,
905+ ty:: Float ( float_ty) => float_ty. name_str ( ) ,
906+ _ => return ty_metadata,
907+ } ;
908+
909+ let typedef_metadata = unsafe {
910+ llvm:: LLVMRustDIBuilderCreateTypedef (
911+ DIB ( cx) ,
912+ ty_metadata,
913+ typedef_name. as_ptr ( ) . cast ( ) ,
914+ typedef_name. len ( ) ,
915+ unknown_file_metadata ( cx) ,
916+ 0 ,
917+ None ,
918+ )
919+ } ;
920+
921+ typedef_metadata
852922}
853923
854924fn foreign_type_metadata (
0 commit comments