• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; Tests the Subzero "name mangling" when using the "pnacl-sz --prefix"
2; option.  Also does a quick smoke test of -ffunction-sections.
3
4; REQUIRES: allow_dump
5; RUN: %p2i -i %s --args --verbose none -ffunction-sections | FileCheck %s
6; TODO(stichnot): The following line causes this test to fail.
7; RUIN: %p2i --assemble --disassemble -i %s --args --verbose none \
8; RUIN:   | FileCheck %s
9; RUN: %p2i -i %s --args --verbose none --prefix Subzero -ffunction-sections \
10; RUN:   | FileCheck --check-prefix=MANGLE %s
11
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.
17; CHECK-LABEL: .text.FuncC
18; CHECK: FuncC:
19; MANGLE-LABEL: .text.SubzeroFuncC
20; MANGLE: SubzeroFuncC:
21
22define internal void @_ZN13TestNamespace4FuncEi(i32 %i) {
23entry:
24  ret void
25}
26; This is Func(int) nested inside namespace TestNamespace.
27; CHECK-LABEL: .text._ZN13TestNamespace4FuncEi
28; CHECK: _ZN13TestNamespace4FuncEi:
29; MANGLE-LABEL: .text._ZN7Subzero13TestNamespace4FuncEi
30; MANGLE: _ZN7Subzero13TestNamespace4FuncEi:
31
32define internal void @_ZN13TestNamespace15NestedNamespace4FuncEi(i32 %i) {
33entry:
34  ret void
35}
36; This is Func(int) nested inside two namespaces.
37; CHECK-LABEL: .text._ZN13TestNamespace15NestedNamespace4FuncEi
38; CHECK: _ZN13TestNamespace15NestedNamespace4FuncEi:
39; MANGLE-LABEL: .text._ZN7Subzero13TestNamespace15NestedNamespace4FuncEi
40; MANGLE: _ZN7Subzero13TestNamespace15NestedNamespace4FuncEi:
41
42define internal void @_Z13FuncCPlusPlusi(i32 %i) {
43entry:
44  ret void
45}
46; This is a non-nested, mangled C++ symbol.
47; CHECK-LABEL: .text._Z13FuncCPlusPlusi
48; CHECK: _Z13FuncCPlusPlusi:
49; MANGLE-LABEL: .text._ZN7Subzero13FuncCPlusPlusEi
50; 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.
57; CHECK-LABEL: .text._ZN12_GLOBAL__N_18FuncAnonEi
58; CHECK: _ZN12_GLOBAL__N_18FuncAnonEi:
59; MANGLE-LABEL: .text._ZN7Subzero12_GLOBAL__N_18FuncAnonEi
60; 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}
69; MANGLE-LABEL: .text.Subzero_ZN
70; 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}
77; MANGLE-LABEL: .text._ZN7Subzero12FuncCPlusPluEsi
78; 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}
85; MANGLE-LABEL: .text._ZN7Subzero14FuncCPlusPlusiE
86; 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}
93; MANGLE-LABEL: .text.Subzero_Z114FuncCPlusPlusi
94; 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}
101; MANGLE-LABEL: .text.Subzero_Z4294967296FuncCPlusPlusi
102; 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}
109; MANGLE-LABEL: .text._ZN7Subzero0EFuncCPlusPlusi
110; 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}
119; MANGLE-LABEL: .text.Subzero_Z-1FuncCPlusPlusi
120; MANGLE: Subzero_Z-1FuncCPlusPlusi:
121
122
123; Test for substitution incrementing.  This single test captures:
124;   S<num>_ ==> S<num+1>_ for single-digit <num>
125;   S_ ==> S0_
126;   String length increase, e.g. SZZZ_ ==> S1000_
127;   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() {
133; MANGLE-LABEL: .text._ZN7Subzero3fooEP10MyClassS1xP10MyClassS2xRS0_RS2_S0_S2_S1000_SZA00_S12345
134; MANGLE: _ZN7Subzero3fooEP10MyClassS1xP10MyClassS2xRS0_RS2_S0_S2_S1000_SZA00_S12345:
135entry:
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() {
141; MANGLE-LABEL: .text.Subzerofoo_S_S0_SZ_S
142; MANGLE: Subzerofoo_S_S0_SZ_S:
143entry:
144  ret void
145}
146