@@ -11,14 +11,15 @@ use rustc_abi::{ExternAbi, Integer};
1111use rustc_data_structures:: base_n:: { ALPHANUMERIC_ONLY , CASE_INSENSITIVE , ToBaseN } ;
1212use rustc_data_structures:: fx:: FxHashMap ;
1313use rustc_hir as hir;
14+ use rustc_hir:: attrs:: AttributeKind ;
15+ use rustc_hir:: find_attr;
1416use rustc_middle:: bug;
1517use rustc_middle:: ty:: layout:: IntegerExt ;
1618use rustc_middle:: ty:: {
1719 self , Const , ExistentialPredicate , FloatTy , FnSig , GenericArg , GenericArgKind , GenericArgsRef ,
1820 IntTy , List , Region , RegionKind , TermKind , Ty , TyCtxt , TypeFoldable , UintTy ,
1921} ;
2022use rustc_span:: def_id:: DefId ;
21- use rustc_span:: sym;
2223use tracing:: instrument;
2324
2425use crate :: cfi:: typeid:: TypeIdOptions ;
@@ -446,36 +447,20 @@ pub(crate) fn encode_ty<'tcx>(
446447 ty:: Adt ( adt_def, args) => {
447448 let mut s = String :: new ( ) ;
448449 let def_id = adt_def. did ( ) ;
449- if let Some ( cfi_encoding) = tcx. get_attr ( def_id, sym:: cfi_encoding) {
450+ if let Some ( encoding) = find_attr ! ( tcx. get_all_attrs( def_id) , AttributeKind :: CfiEncoding { encoding } => encoding)
451+ {
452+ let encoding = encoding. as_str ( ) ;
450453 // Use user-defined CFI encoding for type
451- if let Some ( value_str) = cfi_encoding. value_str ( ) {
452- let value_str = value_str. as_str ( ) . trim ( ) ;
453- if !value_str. is_empty ( ) {
454- s. push_str ( value_str) ;
455- // Don't compress user-defined builtin types (see
456- // https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-builtin and
457- // https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-compression).
458- let builtin_types = [
459- "v" , "w" , "b" , "c" , "a" , "h" , "s" , "t" , "i" , "j" , "l" , "m" , "x" , "y" ,
460- "n" , "o" , "f" , "d" , "e" , "g" , "z" , "Dh" ,
461- ] ;
462- if !builtin_types. contains ( & value_str) {
463- compress ( dict, DictKey :: Ty ( ty, TyQ :: None ) , & mut s) ;
464- }
465- } else {
466- #[ allow(
467- rustc:: diagnostic_outside_of_impl,
468- rustc:: untranslatable_diagnostic
469- ) ]
470- tcx. dcx ( )
471- . struct_span_err (
472- cfi_encoding. span ( ) ,
473- format ! ( "invalid `cfi_encoding` for `{:?}`" , ty. kind( ) ) ,
474- )
475- . emit ( ) ;
476- }
477- } else {
478- bug ! ( "encode_ty: invalid `cfi_encoding` for `{:?}`" , ty. kind( ) ) ;
454+ s. push_str ( & encoding) ;
455+ // Don't compress user-defined builtin types (see
456+ // https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-builtin and
457+ // https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-compression).
458+ let builtin_types = [
459+ "v" , "w" , "b" , "c" , "a" , "h" , "s" , "t" , "i" , "j" , "l" , "m" , "x" , "y" , "n" , "o" ,
460+ "f" , "d" , "e" , "g" , "z" , "Dh" ,
461+ ] ;
462+ if !builtin_types. contains ( & encoding) {
463+ compress ( dict, DictKey :: Ty ( ty, TyQ :: None ) , & mut s) ;
479464 }
480465 } else if options. contains ( EncodeTyOptions :: GENERALIZE_REPR_C ) && adt_def. repr ( ) . c ( ) {
481466 // For cross-language LLVM CFI support, the encoding must be compatible at the FFI
@@ -508,30 +493,16 @@ pub(crate) fn encode_ty<'tcx>(
508493 ty:: Foreign ( def_id) => {
509494 // <length><name>, where <name> is <unscoped-name>
510495 let mut s = String :: new ( ) ;
511- if let Some ( cfi_encoding) = tcx. get_attr ( * def_id, sym:: cfi_encoding) {
496+
497+ if let Some ( encoding) = find_attr ! ( tcx. get_all_attrs( * def_id) , AttributeKind :: CfiEncoding { encoding} => encoding)
498+ {
512499 // Use user-defined CFI encoding for type
513- if let Some ( value_str) = cfi_encoding. value_str ( ) {
514- if !value_str. to_string ( ) . trim ( ) . is_empty ( ) {
515- s. push_str ( value_str. to_string ( ) . trim ( ) ) ;
516- } else {
517- #[ allow(
518- rustc:: diagnostic_outside_of_impl,
519- rustc:: untranslatable_diagnostic
520- ) ]
521- tcx. dcx ( )
522- . struct_span_err (
523- cfi_encoding. span ( ) ,
524- format ! ( "invalid `cfi_encoding` for `{:?}`" , ty. kind( ) ) ,
525- )
526- . emit ( ) ;
527- }
528- } else {
529- bug ! ( "encode_ty: invalid `cfi_encoding` for `{:?}`" , ty. kind( ) ) ;
530- }
500+ s. push_str ( encoding. as_str ( ) ) ;
531501 } else {
532502 let name = tcx. item_name ( * def_id) . to_string ( ) ;
533503 let _ = write ! ( s, "{}{}" , name. len( ) , name) ;
534- }
504+ } ;
505+
535506 compress ( dict, DictKey :: Ty ( ty, TyQ :: None ) , & mut s) ;
536507 typeid. push_str ( & s) ;
537508 }
0 commit comments