blob: 1ba73f73ba195dbece45f48b9bd546ee8b4a1c08 [file] [log] [blame]
Jim Stichnothfa0cfa52015-02-26 09:42:36 -08001; Tests the Subzero "name mangling" when using the "pnacl-sz --prefix"
Jim Stichnoth989a7032014-08-08 10:13:44 -07002; option. Also does a quick smoke test of -ffunction-sections.
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -07003
Karl Schimpf9bb188d2014-12-10 12:54:34 -08004; REQUIRES: allow_dump
Karl Schimpf2a5324a2014-09-25 09:37:49 -07005; RUN: %p2i -i %s --args --verbose none -ffunction-sections | FileCheck %s
6; TODO(stichnot): The following line causes this test to fail.
Jan Vounga2703ae2015-02-19 11:27:44 -08007; RUIN: %p2i --assemble --disassemble -i %s --args --verbose none \
8; RUIN: | FileCheck %s
Karl Schimpf2a5324a2014-09-25 09:37:49 -07009; RUN: %p2i -i %s --args --verbose none --prefix Subzero -ffunction-sections \
Jan Vounga2703ae2015-02-19 11:27:44 -080010; RUN: | FileCheck --check-prefix=MANGLE %s
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070011
12define internal void @FuncC(i32 %i) {
13entry:
14 ret void
15}
16; FuncC is a C symbol that isn't recognized as a C++ mangled symbol.
Jim Stichnoth989a7032014-08-08 10:13:44 -070017; CHECK-LABEL: .text.FuncC
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070018; CHECK: FuncC:
Jim Stichnoth989a7032014-08-08 10:13:44 -070019; MANGLE-LABEL: .text.SubzeroFuncC
20; MANGLE: SubzeroFuncC:
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070021
22define internal void @_ZN13TestNamespace4FuncEi(i32 %i) {
23entry:
24 ret void
25}
26; This is Func(int) nested inside namespace TestNamespace.
Jim Stichnoth989a7032014-08-08 10:13:44 -070027; CHECK-LABEL: .text._ZN13TestNamespace4FuncEi
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070028; CHECK: _ZN13TestNamespace4FuncEi:
Jim Stichnoth989a7032014-08-08 10:13:44 -070029; MANGLE-LABEL: .text._ZN7Subzero13TestNamespace4FuncEi
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070030; MANGLE: _ZN7Subzero13TestNamespace4FuncEi:
31
32define internal void @_ZN13TestNamespace15NestedNamespace4FuncEi(i32 %i) {
33entry:
34 ret void
35}
36; This is Func(int) nested inside two namespaces.
Jim Stichnoth989a7032014-08-08 10:13:44 -070037; CHECK-LABEL: .text._ZN13TestNamespace15NestedNamespace4FuncEi
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070038; CHECK: _ZN13TestNamespace15NestedNamespace4FuncEi:
Jim Stichnoth989a7032014-08-08 10:13:44 -070039; MANGLE-LABEL: .text._ZN7Subzero13TestNamespace15NestedNamespace4FuncEi
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070040; MANGLE: _ZN7Subzero13TestNamespace15NestedNamespace4FuncEi:
41
42define internal void @_Z13FuncCPlusPlusi(i32 %i) {
43entry:
44 ret void
45}
46; This is a non-nested, mangled C++ symbol.
Jim Stichnoth989a7032014-08-08 10:13:44 -070047; CHECK-LABEL: .text._Z13FuncCPlusPlusi
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070048; CHECK: _Z13FuncCPlusPlusi:
Jim Stichnoth989a7032014-08-08 10:13:44 -070049; MANGLE-LABEL: .text._ZN7Subzero13FuncCPlusPlusEi
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070050; MANGLE: _ZN7Subzero13FuncCPlusPlusEi:
51
52define internal void @_ZN12_GLOBAL__N_18FuncAnonEi(i32 %i) {
53entry:
54 ret void
55}
56; This is FuncAnon(int) nested inside an anonymous namespace.
Jim Stichnoth989a7032014-08-08 10:13:44 -070057; CHECK-LABEL: .text._ZN12_GLOBAL__N_18FuncAnonEi
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070058; CHECK: _ZN12_GLOBAL__N_18FuncAnonEi:
Jim Stichnoth989a7032014-08-08 10:13:44 -070059; MANGLE-LABEL: .text._ZN7Subzero12_GLOBAL__N_18FuncAnonEi
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070060; MANGLE: _ZN7Subzero12_GLOBAL__N_18FuncAnonEi:
61
62; Now for the illegitimate examples.
63
64; Test for _ZN with no suffix. Don't crash, prepend Subzero.
65define internal void @_ZN(i32 %i) {
66entry:
67 ret void
68}
Jim Stichnoth989a7032014-08-08 10:13:44 -070069; MANGLE-LABEL: .text.Subzero_ZN
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070070; MANGLE: Subzero_ZN:
71
72; Test for _Z<len><str> where <len> is smaller than it should be.
73define internal void @_Z12FuncCPlusPlusi(i32 %i) {
74entry:
75 ret void
76}
Jim Stichnoth989a7032014-08-08 10:13:44 -070077; MANGLE-LABEL: .text._ZN7Subzero12FuncCPlusPluEsi
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070078; MANGLE: _ZN7Subzero12FuncCPlusPluEsi:
79
80; Test for _Z<len><str> where <len> is slightly larger than it should be.
81define internal void @_Z14FuncCPlusPlusi(i32 %i) {
82entry:
83 ret void
84}
Jim Stichnoth989a7032014-08-08 10:13:44 -070085; MANGLE-LABEL: .text._ZN7Subzero14FuncCPlusPlusiE
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070086; MANGLE: _ZN7Subzero14FuncCPlusPlusiE:
87
88; Test for _Z<len><str> where <len> is much larger than it should be.
89define internal void @_Z114FuncCPlusPlusi(i32 %i) {
90entry:
91 ret void
92}
Jim Stichnoth989a7032014-08-08 10:13:44 -070093; MANGLE-LABEL: .text.Subzero_Z114FuncCPlusPlusi
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070094; MANGLE: Subzero_Z114FuncCPlusPlusi:
95
96; Test for _Z<len><str> where we try to overflow the uint32_t holding <len>.
97define internal void @_Z4294967296FuncCPlusPlusi(i32 %i) {
98entry:
99 ret void
100}
Jim Stichnoth989a7032014-08-08 10:13:44 -0700101; MANGLE-LABEL: .text.Subzero_Z4294967296FuncCPlusPlusi
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700102; MANGLE: Subzero_Z4294967296FuncCPlusPlusi:
103
104; Test for _Z<len><str> where <len> is 0.
105define internal void @_Z0FuncCPlusPlusi(i32 %i) {
106entry:
107 ret void
108}
Jim Stichnoth989a7032014-08-08 10:13:44 -0700109; MANGLE-LABEL: .text._ZN7Subzero0EFuncCPlusPlusi
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700110; MANGLE: _ZN7Subzero0EFuncCPlusPlusi:
111
112; Test for _Z<len><str> where <len> is -1. LLVM explicitly allows the
113; '-' character in identifiers.
114
115define internal void @_Z-1FuncCPlusPlusi(i32 %i) {
116entry:
117 ret void
118}
Jim Stichnoth989a7032014-08-08 10:13:44 -0700119; MANGLE-LABEL: .text.Subzero_Z-1FuncCPlusPlusi
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700120; MANGLE: Subzero_Z-1FuncCPlusPlusi:
121
Jim Stichnoth217dc082014-07-11 14:06:55 -0700122
123; Test for substitution incrementing. This single test captures:
124; S<num>_ ==> S<num+1>_ for single-digit <num>
125; S_ ==> S0_
Jim Stichnoth78b4c0b2014-07-11 15:29:23 -0700126; String length increase, e.g. SZZZ_ ==> S1000_
Jim Stichnoth217dc082014-07-11 14:06:55 -0700127; At least one digit wrapping without length increase, e.g. SZ9ZZ_ ==> SZA00_
128; Unrelated identifiers containing S[0-9A-Z]* , e.g. MyClassS1x
129; A proper substring of S<num>_ at the end of the string
130; (to test parser edge cases)
131
132define internal void @_Z3fooP10MyClassS1xP10MyClassS2xRS_RS1_S_S1_SZZZ_SZ9ZZ_S12345() {
Jim Stichnoth989a7032014-08-08 10:13:44 -0700133; MANGLE-LABEL: .text._ZN7Subzero3fooEP10MyClassS1xP10MyClassS2xRS0_RS2_S0_S2_S1000_SZA00_S12345
134; MANGLE: _ZN7Subzero3fooEP10MyClassS1xP10MyClassS2xRS0_RS2_S0_S2_S1000_SZA00_S12345:
Jim Stichnoth217dc082014-07-11 14:06:55 -0700135entry:
136 ret void
137}
138
139; Test that unmangled (non-C++) strings don't have substitutions updated.
140define internal void @foo_S_S0_SZ_S() {
Jim Stichnoth989a7032014-08-08 10:13:44 -0700141; MANGLE-LABEL: .text.Subzerofoo_S_S0_SZ_S
142; MANGLE: Subzerofoo_S_S0_SZ_S:
Jim Stichnoth217dc082014-07-11 14:06:55 -0700143entry:
144 ret void
145}