Skip to content

Commit 8a745fe

Browse files
authored
Unrolled build for rust-lang#121700
Rollup merge of rust-lang#121700 - rcvalle:rust-cfi-dont-compress-user-defined-builtin-types, r=compiler-errors CFI: Don't compress user-defined builtin types Doesn't compress user-defined builtin types (see https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-builtin and https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-compression).
2 parents 71a7b66 + 8f7b921 commit 8a745fe

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,20 @@ fn encode_ty<'tcx>(
546546
if let Some(cfi_encoding) = tcx.get_attr(def_id, sym::cfi_encoding) {
547547
// Use user-defined CFI encoding for type
548548
if let Some(value_str) = cfi_encoding.value_str() {
549-
if !value_str.to_string().trim().is_empty() {
550-
s.push_str(value_str.to_string().trim());
549+
let value_str = value_str.to_string();
550+
let str = value_str.trim();
551+
if !str.is_empty() {
552+
s.push_str(str);
553+
// Don't compress user-defined builtin types (see
554+
// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-builtin and
555+
// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling-compression).
556+
let builtin_types = [
557+
"v", "w", "b", "c", "a", "h", "s", "t", "i", "j", "l", "m", "x", "y",
558+
"n", "o", "f", "d", "e", "g", "z",
559+
];
560+
if !builtin_types.contains(&str) {
561+
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
562+
}
551563
} else {
552564
#[allow(
553565
rustc::diagnostic_outside_of_impl,
@@ -563,7 +575,6 @@ fn encode_ty<'tcx>(
563575
} else {
564576
bug!("encode_ty: invalid `cfi_encoding` for `{:?}`", ty.kind());
565577
}
566-
compress(dict, DictKey::Ty(ty, TyQ::None), &mut s);
567578
} else if options.contains(EncodeTyOptions::GENERALIZE_REPR_C) && adt_def.repr().c() {
568579
// For cross-language LLVM CFI support, the encoding must be compatible at the FFI
569580
// boundary. For instance:

tests/codegen/sanitizer/cfi-emit-type-metadata-attr-cfi-encoding.rs

+25
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ extern {
1818
#[repr(transparent)]
1919
pub struct Type3(i32);
2020

21+
#[cfi_encoding = "i"]
22+
pub struct Type4(i32);
23+
24+
#[cfi_encoding = "j"]
25+
#[repr(transparent)]
26+
pub struct Type5(u32);
27+
2128
pub fn foo0(_: Type1) { }
2229
// CHECK: define{{.*}}foo0{{.*}}!type ![[TYPE0:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
2330
pub fn foo1(_: Type1, _: Type1) { }
@@ -36,6 +43,18 @@ pub fn foo7(_: *mut Type3, _: *mut Type3) { }
3643
// CHECK: define{{.*}}foo7{{.*}}!type ![[TYPE7:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
3744
pub fn foo8(_: *mut Type3, _: *mut Type3, _: *mut Type3) { }
3845
// CHECK: define{{.*}}foo8{{.*}}!type ![[TYPE8:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
46+
pub fn foo9(_: Type4) { }
47+
// CHECK: define{{.*}}foo9{{.*}}!type ![[TYPE9:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
48+
pub fn foo10(_: Type4, _: Type4) { }
49+
// CHECK: define{{.*}}foo10{{.*}}!type ![[TYPE10:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
50+
pub fn foo11(_: Type4, _: Type4, _: Type4) { }
51+
// CHECK: define{{.*}}foo11{{.*}}!type ![[TYPE11:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
52+
pub fn foo12(_: Type5) { }
53+
// CHECK: define{{.*}}foo12{{.*}}!type ![[TYPE12:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
54+
pub fn foo13(_: Type5, _: Type5) { }
55+
// CHECK: define{{.*}}foo13{{.*}}!type ![[TYPE13:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
56+
pub fn foo14(_: Type5, _: Type5, _: Type5) { }
57+
// CHECK: define{{.*}}foo14{{.*}}!type ![[TYPE14:[0-9]+]] !type !{{[0-9]+}} !type !{{[0-9]+}} !type !{{[0-9]+}}
3958

4059
// CHECK: ![[TYPE0]] = !{i64 0, !"_ZTSFv3FooE"}
4160
// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFv3FooS_E"}
@@ -46,3 +65,9 @@ pub fn foo8(_: *mut Type3, _: *mut Type3, _: *mut Type3) { }
4665
// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFvP3BazE"}
4766
// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFvP3BazS0_E"}
4867
// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFvP3BazS0_S0_E"}
68+
// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFviE"}
69+
// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFviiE"}
70+
// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFviiiE"}
71+
// CHECK: ![[TYPE12]] = !{i64 0, !"_ZTSFvjE"}
72+
// CHECK: ![[TYPE13]] = !{i64 0, !"_ZTSFvjjE"}
73+
// CHECK: ![[TYPE14]] = !{i64 0, !"_ZTSFvjjjE"}

0 commit comments

Comments
 (0)