Skip to content

Commit fad7339

Browse files
Rollup merge of #106232 - maurer:transparent-subst, r=rcvalle
CFI: Monomorphize transparent ADTs before typeid Monomorphise `#[repr(transparent)]` parameterized ADTs before turning them into an Itanium mangled String. `#[repr(transparent)]` ADTs currently use the single field to represent them in their CFI type ID to ensure that they are compatible. However, if that type involves a type parameter instantiated at the ADT level, as in `ManuallyDrop`, this will currently ICE as the `Parameter` type cannot be mangled. Since this happens at lowering time, it should always be concrete after substitution. Fixes #106230
2 parents ff3326d + fb2c27d commit fad7339

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

Diff for: compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ fn encode_const<'tcx>(
164164

165165
/// Encodes a FnSig using the Itanium C++ ABI with vendor extended type qualifiers and types for
166166
/// Rust types that are not used at the FFI boundary.
167+
#[instrument(level = "trace", skip(tcx, dict))]
167168
fn encode_fnsig<'tcx>(
168169
tcx: TyCtxt<'tcx>,
169170
fn_sig: &FnSig<'tcx>,
@@ -653,6 +654,7 @@ fn encode_ty<'tcx>(
653654
// Transforms a ty:Ty for being encoded and used in the substitution dictionary. It transforms all
654655
// c_void types into unit types unconditionally, and generalizes all pointers if
655656
// TransformTyOptions::GENERALIZE_POINTERS option is set.
657+
#[instrument(level = "trace", skip(tcx))]
656658
fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptions) -> Ty<'tcx> {
657659
let mut ty = ty;
658660

@@ -698,7 +700,7 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
698700
!is_zst
699701
});
700702
if let Some(field) = field {
701-
let ty0 = tcx.type_of(field.did);
703+
let ty0 = tcx.bound_type_of(field.did).subst(tcx, substs);
702704
// Generalize any repr(transparent) user-defined type that is either a pointer
703705
// or reference, and either references itself or any other type that contains or
704706
// references itself, to avoid a reference cycle.
@@ -827,6 +829,7 @@ fn transform_substs<'tcx>(
827829

828830
/// Returns a type metadata identifier for the specified FnAbi using the Itanium C++ ABI with vendor
829831
/// extended type qualifiers and types for Rust types that are not used at the FFI boundary.
832+
#[instrument(level = "trace", skip(tcx))]
830833
pub fn typeid_for_fnabi<'tcx>(
831834
tcx: TyCtxt<'tcx>,
832835
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,

Diff for: src/test/codegen/sanitizer-cfi-emit-type-metadata-id-itanium-cxx-abi.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ pub struct Type13<'a> {
131131
member3: &'a Type13<'a>,
132132
}
133133

134+
// Helper type to allow `Type14<Bar>` to be a unique ID
135+
pub struct Bar;
136+
137+
// repr(transparent) parameterized type
138+
#[repr(transparent)]
139+
pub struct Type14<T>(T);
140+
134141
pub fn foo0(_: ()) { }
135142
// CHECK: define{{.*}}foo0{{.*}}!type ![[TYPE0:[0-9]+]]
136143
pub fn foo1(_: c_void, _: ()) { }
@@ -425,6 +432,12 @@ pub fn foo145(_: Type13, _: Type13) { }
425432
// CHECK: define{{.*}}foo145{{.*}}!type ![[TYPE145:[0-9]+]]
426433
pub fn foo146(_: Type13, _: Type13, _: Type13) { }
427434
// CHECK: define{{.*}}foo146{{.*}}!type ![[TYPE146:[0-9]+]]
435+
pub fn foo147(_: Type14<Bar>) { }
436+
// CHECK: define{{.*}}foo147{{.*}}!type ![[TYPE147:[0-9]+]]
437+
pub fn foo148(_: Type14<Bar>, _: Type14<Bar>) { }
438+
// CHECK: define{{.*}}foo148{{.*}}!type ![[TYPE148:[0-9]+]]
439+
pub fn foo149(_: Type14<Bar>, _: Type14<Bar>, _: Type14<Bar>) { }
440+
// CHECK: define{{.*}}foo149{{.*}}!type ![[TYPE149:[0-9]+]]
428441

429442
// CHECK: ![[TYPE0]] = !{i64 0, !"_ZTSFvvE"}
430443
// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvvvE"}
@@ -570,6 +583,9 @@ pub fn foo146(_: Type13, _: Type13, _: Type13) { }
570583
// CHECK: ![[TYPE141]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_51sanitizer_cfi_emit_type_metadata_id_itanium_cxx_abi3FooE"}
571584
// CHECK: ![[TYPE142]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_51sanitizer_cfi_emit_type_metadata_id_itanium_cxx_abi3FooS_E"}
572585
// CHECK: ![[TYPE143]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_51sanitizer_cfi_emit_type_metadata_id_itanium_cxx_abi3FooS_S_E"}
573-
// CHECK: ![[TYPE144]] = !{i64 0, !"_ZTSFvu3refIu3refIvEEE"}
574-
// CHECK: ![[TYPE145]] = !{i64 0, !"_ZTSFvu3refIu3refIvEES0_E"}
575-
// CHECK: ![[TYPE146]] = !{i64 0, !"_ZTSFvu3refIu3refIvEES0_S0_E"}
586+
// CHECK: ![[TYPE144]] = !{i64 0, !"_ZTSFvu3refIvEE"}
587+
// CHECK: ![[TYPE145]] = !{i64 0, !"_ZTSFvu3refIvES_E"}
588+
// CHECK: ![[TYPE146]] = !{i64 0, !"_ZTSFvu3refIvES_S_E"}
589+
// CHECK: ![[TYPE147]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_51sanitizer_cfi_emit_type_metadata_id_itanium_cxx_abi3BarE
590+
// CHECK: ![[TYPE148]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_51sanitizer_cfi_emit_type_metadata_id_itanium_cxx_abi3BarS_E
591+
// CHECK: ![[TYPE149]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_51sanitizer_cfi_emit_type_metadata_id_itanium_cxx_abi3BarS_S_E

0 commit comments

Comments
 (0)