@@ -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,30 @@ 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 ( ( attr_span, encoding) ) = find_attr ! ( tcx. get_all_attrs( def_id) , AttributeKind :: CfiEncoding { attr_span, encoding } => ( attr_span, encoding) )
451+ {
450452 // 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 ( ) ;
453+ let encoding = encoding. as_str ( ) . trim ( ) ;
454+ if !encoding. is_empty ( ) {
455+ s. push_str ( encoding) ;
456+ // Don't compress user-defined builtin types (see
457+ // https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-builtin and
458+ // https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-compression).
459+ let builtin_types = [
460+ "v" , "w" , "b" , "c" , "a" , "h" , "s" , "t" , "i" , "j" , "l" , "m" , "x" , "y" , "n" ,
461+ "o" , "f" , "d" , "e" , "g" , "z" , "Dh" ,
462+ ] ;
463+ if !builtin_types. contains ( & encoding) {
464+ compress ( dict, DictKey :: Ty ( ty, TyQ :: None ) , & mut s) ;
476465 }
477466 } else {
478- bug ! ( "encode_ty: invalid `cfi_encoding` for `{:?}`" , ty. kind( ) ) ;
467+ #[ allow( rustc:: diagnostic_outside_of_impl, rustc:: untranslatable_diagnostic) ]
468+ tcx. dcx ( )
469+ . struct_span_err (
470+ * attr_span,
471+ format ! ( "invalid `cfi_encoding` for `{:?}`" , ty. kind( ) ) ,
472+ )
473+ . emit ( ) ;
479474 }
480475 } else if options. contains ( EncodeTyOptions :: GENERALIZE_REPR_C ) && adt_def. repr ( ) . c ( ) {
481476 // For cross-language LLVM CFI support, the encoding must be compatible at the FFI
@@ -508,30 +503,27 @@ pub(crate) fn encode_ty<'tcx>(
508503 ty:: Foreign ( def_id) => {
509504 // <length><name>, where <name> is <unscoped-name>
510505 let mut s = String :: new ( ) ;
511- if let Some ( cfi_encoding) = tcx. get_attr ( * def_id, sym:: cfi_encoding) {
506+
507+ if let Some ( ( attr_span, encoding) ) = find_attr ! ( tcx. get_all_attrs( * def_id) , AttributeKind :: CfiEncoding { attr_span, encoding} => ( attr_span, encoding) )
508+ {
512509 // 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- }
510+ let encoding = encoding. as_str ( ) . trim ( ) ;
511+ if !encoding. is_empty ( ) {
512+ s. push_str ( encoding) ;
528513 } else {
529- bug ! ( "encode_ty: invalid `cfi_encoding` for `{:?}`" , ty. kind( ) ) ;
514+ #[ allow( rustc:: diagnostic_outside_of_impl, rustc:: untranslatable_diagnostic) ]
515+ tcx. dcx ( )
516+ . struct_span_err (
517+ * attr_span,
518+ format ! ( "invalid `cfi_encoding` for `{:?}`" , ty. kind( ) ) ,
519+ )
520+ . emit ( ) ;
530521 }
531522 } else {
532523 let name = tcx. item_name ( * def_id) . to_string ( ) ;
533524 let _ = write ! ( s, "{}{}" , name. len( ) , name) ;
534- }
525+ } ;
526+
535527 compress ( dict, DictKey :: Ty ( ty, TyQ :: None ) , & mut s) ;
536528 typeid. push_str ( & s) ;
537529 }
0 commit comments