Skip to content

Commit 97032d6

Browse files
committed
CFI: Add char to CFI integer normalization
Adds char to CFI integer normalization to conform to rust-lang#118032 for cross-language CFI support.
1 parent f16c81f commit 97032d6

File tree

2 files changed

+29
-63
lines changed

2 files changed

+29
-63
lines changed

compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -773,12 +773,7 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
773773
let mut ty = ty;
774774

775775
match ty.kind() {
776-
ty::Float(..)
777-
| ty::Char
778-
| ty::Str
779-
| ty::Never
780-
| ty::Foreign(..)
781-
| ty::CoroutineWitness(..) => {}
776+
ty::Float(..) | ty::Str | ty::Never | ty::Foreign(..) | ty::CoroutineWitness(..) => {}
782777

783778
ty::Bool => {
784779
if options.contains(EncodeTyOptions::NORMALIZE_INTEGERS) {
@@ -792,6 +787,14 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
792787
}
793788
}
794789

790+
ty::Char => {
791+
if options.contains(EncodeTyOptions::NORMALIZE_INTEGERS) {
792+
// Since #118032, char is guaranteed to have the same size, alignment, and function
793+
// call ABI as u32 on all platforms.
794+
ty = tcx.types.u32;
795+
}
796+
}
797+
795798
ty::Int(..) | ty::Uint(..) => {
796799
if options.contains(EncodeTyOptions::NORMALIZE_INTEGERS) {
797800
// Note: C99 7.18.2.4 requires uintptr_t and intptr_t to be at least 16-bit wide.

tests/codegen/sanitizer/cfi-normalize-integers.rs

+20-57
Original file line numberDiff line numberDiff line change
@@ -6,78 +6,41 @@
66
#![crate_type="lib"]
77

88
extern crate core;
9-
use core::ffi::*;
109

1110
pub fn foo0(_: bool) { }
1211
// CHECK: define{{.*}}foo0{{.*}}!type ![[TYPE0:[0-9]+]] !type !{{[0-9]+}}
13-
pub fn foo1(_: bool, _: c_uchar) { }
12+
pub fn foo1(_: bool, _: bool) { }
1413
// CHECK: define{{.*}}foo1{{.*}}!type ![[TYPE1:[0-9]+]] !type !{{[0-9]+}}
15-
pub fn foo2(_: bool, _: c_uchar, _: c_uchar) { }
14+
pub fn foo2(_: bool, _: bool, _: bool) { }
1615
// CHECK: define{{.*}}foo2{{.*}}!type ![[TYPE2:[0-9]+]] !type !{{[0-9]+}}
17-
pub fn foo3(_: isize) { }
16+
pub fn foo3(_: char) { }
1817
// CHECK: define{{.*}}foo3{{.*}}!type ![[TYPE3:[0-9]+]] !type !{{[0-9]+}}
19-
pub fn foo4(_: isize, _: c_long) { }
18+
pub fn foo4(_: char, _: char) { }
2019
// CHECK: define{{.*}}foo4{{.*}}!type ![[TYPE4:[0-9]+]] !type !{{[0-9]+}}
21-
pub fn foo5(_: isize, _: c_long, _: c_longlong) { }
20+
pub fn foo5(_: char, _: char, _: char) { }
2221
// CHECK: define{{.*}}foo5{{.*}}!type ![[TYPE5:[0-9]+]] !type !{{[0-9]+}}
23-
pub fn foo6(_: usize) { }
22+
pub fn foo6(_: isize) { }
2423
// CHECK: define{{.*}}foo6{{.*}}!type ![[TYPE6:[0-9]+]] !type !{{[0-9]+}}
25-
pub fn foo7(_: usize, _: c_ulong) { }
24+
pub fn foo7(_: isize, _: isize) { }
2625
// CHECK: define{{.*}}foo7{{.*}}!type ![[TYPE7:[0-9]+]] !type !{{[0-9]+}}
27-
pub fn foo8(_: usize, _: c_ulong, _: c_ulonglong) { }
26+
pub fn foo8(_: isize, _: isize, _: isize) { }
2827
// CHECK: define{{.*}}foo8{{.*}}!type ![[TYPE8:[0-9]+]] !type !{{[0-9]+}}
29-
pub fn foo9(_: c_schar) { }
28+
pub fn foo9(_: (), _: usize) { }
3029
// CHECK: define{{.*}}foo9{{.*}}!type ![[TYPE9:[0-9]+]] !type !{{[0-9]+}}
31-
pub fn foo10(_: c_char, _: c_schar) { }
30+
pub fn foo10(_: (), _: usize, _: usize) { }
3231
// CHECK: define{{.*}}foo10{{.*}}!type ![[TYPE10:[0-9]+]] !type !{{[0-9]+}}
33-
pub fn foo11(_: c_char, _: c_schar, _: c_schar) { }
32+
pub fn foo11(_: (), _: usize, _: usize, _: usize) { }
3433
// CHECK: define{{.*}}foo11{{.*}}!type ![[TYPE11:[0-9]+]] !type !{{[0-9]+}}
35-
pub fn foo12(_: c_int) { }
36-
// CHECK: define{{.*}}foo12{{.*}}!type ![[TYPE12:[0-9]+]] !type !{{[0-9]+}}
37-
pub fn foo13(_: c_int, _: c_int) { }
38-
// CHECK: define{{.*}}foo13{{.*}}!type ![[TYPE13:[0-9]+]] !type !{{[0-9]+}}
39-
pub fn foo14(_: c_int, _: c_int, _: c_int) { }
40-
// CHECK: define{{.*}}foo14{{.*}}!type ![[TYPE14:[0-9]+]] !type !{{[0-9]+}}
41-
pub fn foo15(_: c_short) { }
42-
// CHECK: define{{.*}}foo15{{.*}}!type ![[TYPE15:[0-9]+]] !type !{{[0-9]+}}
43-
pub fn foo16(_: c_short, _: c_short) { }
44-
// CHECK: define{{.*}}foo16{{.*}}!type ![[TYPE16:[0-9]+]] !type !{{[0-9]+}}
45-
pub fn foo17(_: c_short, _: c_short, _: c_short) { }
46-
// CHECK: define{{.*}}foo17{{.*}}!type ![[TYPE17:[0-9]+]] !type !{{[0-9]+}}
47-
pub fn foo18(_: c_uint) { }
48-
// CHECK: define{{.*}}foo18{{.*}}!type ![[TYPE18:[0-9]+]] !type !{{[0-9]+}}
49-
pub fn foo19(_: c_uint, _: c_uint) { }
50-
// CHECK: define{{.*}}foo19{{.*}}!type ![[TYPE19:[0-9]+]] !type !{{[0-9]+}}
51-
pub fn foo20(_: c_uint, _: c_uint, _: c_uint) { }
52-
// CHECK: define{{.*}}foo20{{.*}}!type ![[TYPE20:[0-9]+]] !type !{{[0-9]+}}
53-
pub fn foo21(_: c_ushort) { }
54-
// CHECK: define{{.*}}foo21{{.*}}!type ![[TYPE21:[0-9]+]] !type !{{[0-9]+}}
55-
pub fn foo22(_: c_ushort, _: c_ushort) { }
56-
// CHECK: define{{.*}}foo22{{.*}}!type ![[TYPE22:[0-9]+]] !type !{{[0-9]+}}
57-
pub fn foo23(_: c_ushort, _: c_ushort, _: c_ushort) { }
58-
// CHECK: define{{.*}}foo23{{.*}}!type ![[TYPE23:[0-9]+]] !type !{{[0-9]+}}
5934

6035
// CHECK: ![[TYPE0]] = !{i64 0, !"_ZTSFvu2u8E.normalized"}
6136
// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvu2u8S_E.normalized"}
6237
// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvu2u8S_S_E.normalized"}
63-
// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFv{{u3i16|u3i32|u3i64}}E.normalized"}
64-
// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFv{{u3i16|u3i32|u3i64}}{{u3i32|u3i64|S_}}E.normalized"}
65-
// CHECK: ![[TYPE5]] = !{i64 0, !"_ZTSFv{{u3i16|u3i32|u3i64}}{{u3i32|u3i64|S_}}{{u3i64|S_|S0_}}E.normalized"}
66-
// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFv{{u3u16|u3u32|u3u64}}E.normalized"}
67-
// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFv{{u3u16|u3u32|u3u64}}{{u3u32|u3u64|S_}}E.normalized"}
68-
// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFv{{u3u16|u3u32|u3u64}}{{u3u32|u3u64|S_}}{{u3u64|S_|S0_}}E.normalized"}
69-
// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvu2i8E.normalized"}
70-
// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFv{{u2i8S_|u2u8u2i8}}E.normalized"}
71-
// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFv{{u2i8S_S_|u2u8u2i8S0_}}E.normalized"}
72-
// CHECK: ![[TYPE12]] = !{i64 0, !"_ZTSFv{{u3i16|u3i32|u3i64}}E.normalized"}
73-
// CHECK: ![[TYPE13]] = !{i64 0, !"_ZTSFv{{u3i16|u3i32|u3i64}}S_E.normalized"}
74-
// CHECK: ![[TYPE14]] = !{i64 0, !"_ZTSFv{{u3i16|u3i32|u3i64}}S_S_E.normalized"}
75-
// CHECK: ![[TYPE15]] = !{i64 0, !"_ZTSFvu3i16E.normalized"}
76-
// CHECK: ![[TYPE16]] = !{i64 0, !"_ZTSFvu3i16S_E.normalized"}
77-
// CHECK: ![[TYPE17]] = !{i64 0, !"_ZTSFvu3i16S_S_E.normalized"}
78-
// CHECK: ![[TYPE18]] = !{i64 0, !"_ZTSFv{{u3u16|u3u32|u3u64}}E.normalized"}
79-
// CHECK: ![[TYPE19]] = !{i64 0, !"_ZTSFv{{u3u16|u3u32|u3u64}}S_E.normalized"}
80-
// CHECK: ![[TYPE20]] = !{i64 0, !"_ZTSFv{{u3u16|u3u32|u3u64}}S_S_E.normalized"}
81-
// CHECK: ![[TYPE21]] = !{i64 0, !"_ZTSFvu3u16E.normalized"}
82-
// CHECK: ![[TYPE22]] = !{i64 0, !"_ZTSFvu3u16S_E.normalized"}
83-
// CHECK: ![[TYPE23]] = !{i64 0, !"_ZTSFvu3u16S_S_E.normalized"}
38+
// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvu3u32E.normalized"}
39+
// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvu3u32S_E.normalized"}
40+
// CHECK: ![[TYPE5]] = !{i64 0, !"_ZTSFvu3u32S_S_E.normalized"}
41+
// CHECK: ![[TYPE6]] = !{i64 0, !"_ZTSFv{{u3i16|u3i32|u3i64|u4i128}}E.normalized"}
42+
// CHECK: ![[TYPE7]] = !{i64 0, !"_ZTSFv{{u3i16|u3i32|u3i64|u4i128}}S_E.normalized"}
43+
// CHECK: ![[TYPE8]] = !{i64 0, !"_ZTSFv{{u3i16|u3i32|u3i64|u4i128}}S_S_E.normalized"}
44+
// CHECK: ![[TYPE9]] = !{i64 0, !"_ZTSFvv{{u3u16|u3u32|u3u64|u4u128}}E.normalized"}
45+
// CHECK: ![[TYPE10]] = !{i64 0, !"_ZTSFvv{{u3u16|u3u32|u3u64|u4u128}}S_E.normalized"}
46+
// CHECK: ![[TYPE11]] = !{i64 0, !"_ZTSFvv{{u3u16|u3u32|u3u64|u4u128}}S_S_E.normalized"}

0 commit comments

Comments
 (0)