Skip to content

Commit 5fd3e89

Browse files
committed
test: support both (legacy and v0) choices of mangling.
1 parent 408bf9d commit 5fd3e89

19 files changed

+245
-58
lines changed

src/test/codegen/drop.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ pub fn droppy() {
1919
// that's one new drop call per call to possibly_unwinding(), and finally 3 drop calls for the
2020
// regular function exit. We used to have problems with quadratic growths of drop calls in such
2121
// functions.
22-
// CHECK-NOT: invoke{{.*}}drop{{.*}}SomeUniqueName
23-
// CHECK: call{{.*}}drop{{.*}}SomeUniqueName
24-
// CHECK: call{{.*}}drop{{.*}}SomeUniqueName
25-
// CHECK-NOT: call{{.*}}drop{{.*}}SomeUniqueName
26-
// CHECK: invoke{{.*}}drop{{.*}}SomeUniqueName
27-
// CHECK: call{{.*}}drop{{.*}}SomeUniqueName
28-
// CHECK: invoke{{.*}}drop{{.*}}SomeUniqueName
29-
// CHECK: call{{.*}}drop{{.*}}SomeUniqueName
30-
// CHECK-NOT: {{(call|invoke).*}}drop{{.*}}SomeUniqueName
22+
// FIXME(eddyb) the `void @` forces a match on the instruction, instead of the
23+
// comment, that's `; call core::ptr::real_drop_in_place::<drop::SomeUniqueName>`
24+
// for the `v0` mangling, should switch to matching on that once `legacy` is gone.
25+
// CHECK-NOT: invoke void @{{.*}}drop_in_place{{.*}}SomeUniqueName
26+
// CHECK: call void @{{.*}}drop_in_place{{.*}}SomeUniqueName
27+
// CHECK: call void @{{.*}}drop_in_place{{.*}}SomeUniqueName
28+
// CHECK-NOT: call void @{{.*}}drop_in_place{{.*}}SomeUniqueName
29+
// CHECK: invoke void @{{.*}}drop_in_place{{.*}}SomeUniqueName
30+
// CHECK: call void @{{.*}}drop_in_place{{.*}}SomeUniqueName
31+
// CHECK: invoke void @{{.*}}drop_in_place{{.*}}SomeUniqueName
32+
// CHECK: call void @{{.*}}drop_in_place{{.*}}SomeUniqueName
33+
// CHECK-NOT: {{(call|invoke) void @.*}}drop_in_place{{.*}}SomeUniqueName
3134
// The next line checks for the } that ends the function definition
3235
// CHECK-LABEL: {{^[}]}}
3336
let _s = SomeUniqueName;

src/test/codegen/external-no-mangle-fns.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ const HIDDEN: () = {
3333
};
3434

3535
// The surrounding item should not accidentally become external
36-
// CHECK: define internal{{.*}} void @_ZN22external_no_mangle_fns1x
36+
// CHECK-LABEL: ; external_no_mangle_fns::x
37+
// CHECK-NEXT: ; Function Attrs:
38+
// CHECK-NEXT: define internal
3739
#[inline(never)]
3840
fn x() {
3941
// CHECK: define void @g()

src/test/codegen/external-no-mangle-statics.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,6 @@ fn x() {
7575
#[no_mangle]
7676
pub static mut P: u8 = 0;
7777
}
78-
// CHECK: define internal void @_ZN26external_no_mangle_statics1x{{.*$}}
78+
// CHECK-LABEL: ; external_no_mangle_statics::x
79+
// CHECK-NEXT: ; Function Attrs:
80+
// CHECK-NEXT: define internal

src/test/codegen/internalize-closures.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ pub fn main() {
44

55
// We want to make sure that closures get 'internal' linkage instead of
66
// 'weak_odr' when they are not shared between codegen units
7-
// CHECK: define internal {{.*}}_ZN20internalize_closures4main{{.*}}$u7b$$u7b$closure$u7d$$u7d$
7+
// FIXME(eddyb) `legacy` mangling uses `{{closure}}`, while `v0`
8+
// uses `{closure#0}`, switch to the latter once `legacy` is gone.
9+
// CHECK-LABEL: ; internalize_closures::main::{{.*}}closure
10+
// CHECK-NEXT: ; Function Attrs:
11+
// CHECK-NEXT: define internal
812
let c = |x:i32| { x + 1 };
913
let _ = c(1);
1014
}

src/test/codegen/link-dead-code.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55
// This test makes sure that, when -Clink-dead-code is specified, we generate
66
// code for functions that would otherwise be skipped.
77

8-
// CHECK-LABEL: define hidden i32 @_ZN14link_dead_code8const_fn
8+
// CHECK-LABEL: ; link_dead_code::const_fn
9+
// CHECK-NEXT: ; Function Attrs:
10+
// CHECK-NEXT: define hidden
911
const fn const_fn() -> i32 { 1 }
1012

11-
// CHECK-LABEL: define hidden i32 @_ZN14link_dead_code9inline_fn
13+
// CHECK-LABEL: ; link_dead_code::inline_fn
14+
// CHECK-NEXT: ; Function Attrs:
15+
// CHECK-NEXT: define hidden
1216
#[inline]
1317
fn inline_fn() -> i32 { 2 }
1418

15-
// CHECK-LABEL: define hidden i32 @_ZN14link_dead_code10private_fn
19+
// CHECK-LABEL: ; link_dead_code::private_fn
20+
// CHECK-NEXT: ; Function Attrs:
21+
// CHECK-NEXT: define hidden
1622
fn private_fn() -> i32 { 3 }

src/test/codegen/local-generics-in-exe-internalized.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
// Check that local generics are internalized if they are in the same CGU
44

5-
// CHECK: define internal {{.*}} @_ZN34local_generics_in_exe_internalized3foo{{.*}}
5+
// CHECK-LABEL: ; local_generics_in_exe_internalized::foo
6+
// CHECK-NEXT: ; Function Attrs:
7+
// CHECK-NEXT: define internal
68
pub fn foo<T>(x: T, y: T) -> (T, T) {
79
(x, y)
810
}

src/test/codegen/target-cpu-on-functions.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ pub extern fn exported() {
1313
not_exported();
1414
}
1515

16-
// CHECK-LABEL: define {{.*}} @_ZN23target_cpu_on_functions12not_exported{{.*}}() {{.*}} #0
16+
// CHECK-LABEL: ; target_cpu_on_functions::not_exported
17+
// CHECK-NEXT: ; Function Attrs:
18+
// CHECK-NEXT: define {{.*}}() {{.*}} #0
1719
fn not_exported() {}
1820

1921
// CHECK: attributes #0 = {{.*}} "target-cpu"="{{.*}}"

src/test/run-make-fulldeps/stable-symbol-names/Makefile

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
# The following command will:
44
# 1. dump the symbols of a library using `nm`
55
# 2. extract only those lines that we are interested in via `grep`
6-
# 3. from those lines, extract just the symbol name via `sed`
7-
# (symbol names always start with "_ZN" and end with "E")
6+
# 3. from those lines, extract just the symbol name via `sed`, which:
7+
# * always starts with "_ZN" and ends with "E" (`legacy` mangling)
8+
# * always starts with "_R" (`v0` mangling)
89
# 4. sort those symbol names for deterministic comparison
910
# 5. write the result into a file
1011

1112
dump-symbols = nm "$(TMPDIR)/lib$(1).rlib" \
1213
| grep -E "$(2)" \
13-
| sed "s/.*\(_ZN.*E\).*/\1/" \
14+
| sed -E "s/.*(_ZN.*E|_R[a-zA-Z0-9_]*).*/\1/" \
1415
| sort \
1516
> "$(TMPDIR)/$(1)$(3).nm"
1617

src/test/run-make-fulldeps/symbol-visibility/Makefile

+12-9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ EXE_NAME=an_executable
1919
COMBINED_CDYLIB_NAME=libcombined_rlib_dylib.dylib
2020
endif
2121

22+
# `grep` regex for symbols produced by either `legacy` or `v0` mangling
23+
RE_ANY_RUST_SYMBOL="_ZN.*h.*E\|_R[a-zA-Z0-9_]+"
24+
2225
all:
2326
$(RUSTC) -Zshare-generics=no an_rlib.rs
2427
$(RUSTC) -Zshare-generics=no a_cdylib.rs
@@ -31,20 +34,20 @@ all:
3134
# Check that a cdylib exports the public #[no_mangle] functions of dependencies
3235
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c public_c_function_from_rlib)" -eq "1" ]
3336
# Check that a cdylib DOES NOT export any public Rust functions
34-
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c _ZN.*h.*E)" -eq "0" ]
37+
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c $(RE_ANY_RUST_SYMBOL))" -eq "0" ]
3538

3639
# Check that a Rust dylib exports its monomorphic functions
3740
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_c_function_from_rust_dylib)" -eq "1" ]
38-
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c _ZN.*public_rust_function_from_rust_dylib.*E)" -eq "1" ]
41+
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_rust_function_from_rust_dylib)" -eq "1" ]
3942
# Check that a Rust dylib does not export generics if -Zshare-generics=no
40-
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c _ZN.*public_generic_function_from_rust_dylib.*E)" -eq "0" ]
43+
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_generic_function_from_rust_dylib)" -eq "0" ]
4144

4245

4346
# Check that a Rust dylib exports the monomorphic functions from its dependencies
4447
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_c_function_from_rlib)" -eq "1" ]
4548
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_rust_function_from_rlib)" -eq "1" ]
4649
# Check that a Rust dylib does not export generics if -Zshare-generics=no
47-
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c _ZN.*public_generic_function_from_rlib.*E)" -eq "0" ]
50+
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_generic_function_from_rlib)" -eq "0" ]
4851

4952
# Check that an executable does not export any dynamic symbols
5053
[ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -c public_c_function_from_rlib)" -eq "0" ]
@@ -58,7 +61,7 @@ all:
5861
# Check that a cdylib exports the public #[no_mangle] functions of dependencies
5962
[ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -c public_c_function_from_rlib)" -eq "1" ]
6063
# Check that a cdylib DOES NOT export any public Rust functions
61-
[ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -c _ZN.*h.*E)" -eq "0" ]
64+
[ "$$($(NM) $(TMPDIR)/$(COMBINED_CDYLIB_NAME) | grep -c $(RE_ANY_RUST_SYMBOL))" -eq "0" ]
6265

6366

6467
$(RUSTC) -Zshare-generics=yes an_rlib.rs
@@ -71,17 +74,17 @@ all:
7174
# Check that a cdylib exports the public #[no_mangle] functions of dependencies
7275
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c public_c_function_from_rlib)" -eq "1" ]
7376
# Check that a cdylib DOES NOT export any public Rust functions
74-
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c _ZN.*h.*E)" -eq "0" ]
77+
[ "$$($(NM) $(TMPDIR)/$(CDYLIB_NAME) | grep -c $(RE_ANY_RUST_SYMBOL))" -eq "0" ]
7578

7679
# Check that a Rust dylib exports its monomorphic functions, including generics this time
7780
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_c_function_from_rust_dylib)" -eq "1" ]
78-
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c _ZN.*public_rust_function_from_rust_dylib.*E)" -eq "1" ]
79-
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c _ZN.*public_generic_function_from_rust_dylib.*E)" -eq "1" ]
81+
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_rust_function_from_rust_dylib)" -eq "1" ]
82+
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_generic_function_from_rust_dylib)" -eq "1" ]
8083

8184
# Check that a Rust dylib exports the monomorphic functions from its dependencies
8285
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_c_function_from_rlib)" -eq "1" ]
8386
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_rust_function_from_rlib)" -eq "1" ]
84-
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c _ZN.*public_generic_function_from_rlib.*E)" -eq "1" ]
87+
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_generic_function_from_rlib)" -eq "1" ]
8588

8689
# Check that an executable does not export any dynamic symbols
8790
[ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -c public_c_function_from_rlib)" -eq "0" ]

src/test/run-pass/backtrace.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ fn expected(fn_name: &str) -> String {
4242
format!(" backtrace::{}", fn_name)
4343
}
4444

45+
fn contains_verbose_expected(s: &str, fn_name: &str) -> bool {
46+
// HACK(eddyb) work around the fact that verbosely demangled stack traces
47+
// (from `RUST_BACKTRACE=full`, or, as is the case here, panic-in-panic)
48+
// may contain symbols with hashes in them, i.e. `backtrace[...]::`.
49+
let prefix = " backtrace";
50+
let suffix = &format!("::{}", fn_name);
51+
s.match_indices(prefix).any(|(i, _)| {
52+
s[i + prefix.len()..]
53+
.trim_start_matches('[')
54+
.trim_start_matches(char::is_alphanumeric)
55+
.trim_start_matches(']')
56+
.starts_with(suffix)
57+
})
58+
}
59+
4560
fn runtest(me: &str) {
4661
// Make sure that the stack trace is printed
4762
let p = template(me).arg("fail").env("RUST_BACKTRACE", "1").spawn().unwrap();
@@ -79,7 +94,7 @@ fn runtest(me: &str) {
7994
let s = str::from_utf8(&out.stderr).unwrap();
8095
// loosened the following from double::h to double:: due to
8196
// spurious failures on mac, 32bit, optimized
82-
assert!(s.contains("stack backtrace") && s.contains(&expected("double")),
97+
assert!(s.contains("stack backtrace") && contains_verbose_expected(s, "double"),
8398
"bad output3: {}", s);
8499

85100
// Make sure a stack trace isn't printed too many times

src/test/ui/symbol-names/basic.stderr renamed to src/test/ui/symbol-names/basic.legacy.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error: symbol-name(_ZN5basic4main17hd72940ef9669d526E)
2-
--> $DIR/basic.rs:3:1
2+
--> $DIR/basic.rs:7:1
33
|
44
LL | #[rustc_symbol_name]
55
| ^^^^^^^^^^^^^^^^^^^^
66

77
error: demangling(basic::main::hd72940ef9669d526)
8-
--> $DIR/basic.rs:3:1
8+
--> $DIR/basic.rs:7:1
99
|
1010
LL | #[rustc_symbol_name]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212

1313
error: demangling-alt(basic::main)
14-
--> $DIR/basic.rs:3:1
14+
--> $DIR/basic.rs:7:1
1515
|
1616
LL | #[rustc_symbol_name]
1717
| ^^^^^^^^^^^^^^^^^^^^
1818

1919
error: def-path(main)
20-
--> $DIR/basic.rs:7:1
20+
--> $DIR/basic.rs:14:1
2121
|
2222
LL | #[rustc_def_path]
2323
| ^^^^^^^^^^^^^^^^^

src/test/ui/symbol-names/basic.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
// revisions: legacy v0
2+
//[legacy]compile-flags: -Z symbol-mangling-version=legacy
3+
//[v0]compile-flags: -Z symbol-mangling-version=v0
4+
15
#![feature(rustc_attrs)]
26

37
#[rustc_symbol_name]
4-
//~^ ERROR symbol-name(_ZN5basic4main
5-
//~| ERROR demangling(basic::main
6-
//~| ERROR demangling-alt(basic::main)
7-
#[rustc_def_path] //~ ERROR def-path(main)
8+
//[legacy]~^ ERROR symbol-name(_ZN5basic4main
9+
//[legacy]~| ERROR demangling(basic::main
10+
//[legacy]~| ERROR demangling-alt(basic::main)
11+
//[v0]~^^^^ ERROR symbol-name(_RNvCs4fqI2P2rA04_5basic4main)
12+
//[v0]~| ERROR demangling(basic[317d481089b8c8fe]::main)
13+
//[v0]~| ERROR demangling-alt(basic::main)
14+
#[rustc_def_path]
15+
//[legacy]~^ ERROR def-path(main)
16+
//[v0]~^^ ERROR def-path(main)
817
fn main() {
918
}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: symbol-name(_RNvCs4fqI2P2rA04_5basic4main)
2+
--> $DIR/basic.rs:7:1
3+
|
4+
LL | #[rustc_symbol_name]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
7+
error: demangling(basic[317d481089b8c8fe]::main)
8+
--> $DIR/basic.rs:7:1
9+
|
10+
LL | #[rustc_symbol_name]
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: demangling-alt(basic::main)
14+
--> $DIR/basic.rs:7:1
15+
|
16+
LL | #[rustc_symbol_name]
17+
| ^^^^^^^^^^^^^^^^^^^^
18+
19+
error: def-path(main)
20+
--> $DIR/basic.rs:14:1
21+
|
22+
LL | #[rustc_def_path]
23+
| ^^^^^^^^^^^^^^^^^
24+
25+
error: aborting due to 4 previous errors
26+

src/test/ui/symbol-names/impl1.stderr renamed to src/test/ui/symbol-names/impl1.legacy.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
error: symbol-name(_ZN5impl13foo3Foo3bar17he53b9bee7600ed8dE)
2-
--> $DIR/impl1.rs:8:9
2+
--> $DIR/impl1.rs:12:9
33
|
44
LL | #[rustc_symbol_name]
55
| ^^^^^^^^^^^^^^^^^^^^
66

77
error: demangling(impl1::foo::Foo::bar::he53b9bee7600ed8d)
8-
--> $DIR/impl1.rs:8:9
8+
--> $DIR/impl1.rs:12:9
99
|
1010
LL | #[rustc_symbol_name]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212

1313
error: demangling-alt(impl1::foo::Foo::bar)
14-
--> $DIR/impl1.rs:8:9
14+
--> $DIR/impl1.rs:12:9
1515
|
1616
LL | #[rustc_symbol_name]
1717
| ^^^^^^^^^^^^^^^^^^^^
1818

1919
error: def-path(foo::Foo::bar)
20-
--> $DIR/impl1.rs:12:9
20+
--> $DIR/impl1.rs:19:9
2121
|
2222
LL | #[rustc_def_path]
2323
| ^^^^^^^^^^^^^^^^^
2424

2525
error: symbol-name(_ZN5impl13bar33_$LT$impl$u20$impl1..foo..Foo$GT$3baz17h86c41f0462d901d4E)
26-
--> $DIR/impl1.rs:21:9
26+
--> $DIR/impl1.rs:30:9
2727
|
2828
LL | #[rustc_symbol_name]
2929
| ^^^^^^^^^^^^^^^^^^^^
3030

3131
error: demangling(impl1::bar::<impl impl1::foo::Foo>::baz::h86c41f0462d901d4)
32-
--> $DIR/impl1.rs:21:9
32+
--> $DIR/impl1.rs:30:9
3333
|
3434
LL | #[rustc_symbol_name]
3535
| ^^^^^^^^^^^^^^^^^^^^
3636

3737
error: demangling-alt(impl1::bar::<impl impl1::foo::Foo>::baz)
38-
--> $DIR/impl1.rs:21:9
38+
--> $DIR/impl1.rs:30:9
3939
|
4040
LL | #[rustc_symbol_name]
4141
| ^^^^^^^^^^^^^^^^^^^^
4242

4343
error: def-path(bar::<impl foo::Foo>::baz)
44-
--> $DIR/impl1.rs:25:9
44+
--> $DIR/impl1.rs:37:9
4545
|
4646
LL | #[rustc_def_path]
4747
| ^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)