[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Driver / frame-pointer-elim.c
blobcdedcc7ae4c89f57c0d915e78a48e35f3c391e3e
1 // KEEP-ALL-NOT: warning: argument unused
2 // KEEP-ALL: "-mframe-pointer=all"
3 // KEEP-NON-LEAF-NOT: warning: argument unused
4 // KEEP-NON-LEAF: "-mframe-pointer=non-leaf"
5 // KEEP-NONE-NOT: warning: argument unused
6 // KEEP-NONE: "-mframe-pointer=none"
8 // On Linux x86, omit frame pointer when optimization is enabled.
9 // RUN: %clang -### --target=i386-linux -S -fomit-frame-pointer %s 2>&1 | \
10 // RUN: FileCheck --check-prefix=KEEP-NONE %s
11 // RUN: %clang -### --target=i386-linux -S -O1 %s 2>&1 | \
12 // RUN: FileCheck --check-prefix=KEEP-NONE %s
14 // -fno-omit-frame-pointer or -pg disables frame pointer omission.
15 // RUN: %clang -### --target=i386-linux -S %s 2>&1 | \
16 // RUN: FileCheck --check-prefix=KEEP-ALL %s
17 // RUN: %clang -### --target=i386-linux -S -O1 -fno-omit-frame-pointer %s 2>&1 | \
18 // RUN: FileCheck --check-prefix=KEEP-ALL %s
19 // RUN: %clang -### --target=i386-linux -S -O1 -pg %s 2>&1 | \
20 // RUN: FileCheck --check-prefix=KEEP-ALL %s
22 // -momit-leaf-frame-pointer omits leaf frame pointer.
23 // -fno-omit-frame-pointer loses out to -momit-leaf-frame-pointer.
24 // RUN: %clang -### --target=i386 -S -momit-leaf-frame-pointer %s 2>&1 | \
25 // RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
26 // RUN: %clang -### --target=i386-linux -S -O1 -fno-omit-frame-pointer -momit-leaf-frame-pointer %s 2>&1 | \
27 // RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
28 // RUN: %clang -### --target=i386-linux -S -O1 -momit-leaf-frame-pointer %s 2>&1 | \
29 // RUN: FileCheck --check-prefix=KEEP-NONE %s
31 // fno-omit-frame-pointer -momit-leaf-frame-pointer can be overwritten by
32 // fomit-frame-pointer later on the command without warning
33 // RUN: %clang -### --target=i386-linux -S -O1 -fno-omit-frame-pointer -momit-leaf-frame-pointer -fomit-frame-pointer %s 2>&1 | \
34 // RUN: FileCheck --check-prefix=KEEP-NONE %s
36 // RUN: %clang -### --target=i386-linux -S -O1 -fno-omit-frame-pointer -momit-leaf-frame-pointer %s 2>&1 | \
37 // RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
38 // Explicit or default -fomit-frame-pointer wins over -mno-omit-leaf-frame-pointer.
39 // RUN: %clang -### --target=i386 -S %s -fomit-frame-pointer -mno-omit-leaf-frame-pointer 2>&1 | \
40 // RUN: FileCheck --check-prefix=KEEP-NONE %s
41 // RUN: %clang -### --target=i386-linux -S %s -O1 -mno-omit-leaf-frame-pointer 2>&1 | \
42 // RUN: FileCheck --check-prefix=KEEP-NONE %s
44 // -pg -fomit-frame-pointer => error.
45 // RUN: not %clang -### -S -fomit-frame-pointer -pg %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MIX-OMIT-FP-PG %s
46 // RUN: %clang -### -S -fomit-frame-pointer -fno-omit-frame-pointer -pg %s 2>&1 | FileCheck -check-prefix=CHECK-MIX-NO-OMIT-FP-PG %s
47 // CHECK-NO-MIX-OMIT-FP-PG: '-fomit-frame-pointer' not allowed with '-pg'
48 // CHECK-MIX-NO-OMIT-FP-PG-NOT: '-fomit-frame-pointer' not allowed with '-pg'
50 // NetBSD follows the same rules as Linux.
51 // RUN: %clang -### --target=x86_64-unknown-netbsd -S -O1 %s 2>&1 | \
52 // RUN: FileCheck --check-prefix=KEEP-NONE %s
54 // RUN: %clang -### --target=x86_64-unknown-netbsd -S %s 2>&1 | \
55 // RUN: FileCheck --check-prefix=KEEP-ALL %s
57 // Darwin disables omitting the leaf frame pointer even under optimization
58 // unless the command lines are given.
59 // RUN: %clang -### -target i386-apple-darwin -S %s 2>&1 | \
60 // RUN: FileCheck --check-prefix=KEEP-ALL %s
62 // RUN: %clang -### -target i386-apple-darwin -S -O1 %s 2>&1 | \
63 // RUN: FileCheck --check-prefix=KEEP-ALL %s
65 // RUN: %clang -### --target=i386-darwin -S -fomit-frame-pointer %s 2>&1 | \
66 // RUN: FileCheck --check-prefix=KEEP-NONE %s
68 // RUN: %clang -### --target=i386-darwin -S -momit-leaf-frame-pointer %s 2>&1 | \
69 // RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
71 // RUN: %clang -### -target armv7s-apple-ios -fomit-frame-pointer %s 2>&1 | \
72 // RUN: FileCheck --check-prefix=WARN-OMIT-7S %s
73 // WARN-OMIT-7S: warning: optimization flag '-fomit-frame-pointer' is not supported for target 'armv7s'
74 // WARN-OMIT-7S: "-mframe-pointer=all"
76 // RUN: %clang -### -target armv7k-apple-watchos -fomit-frame-pointer %s 2>&1 | \
77 // RUN: FileCheck --check-prefix=WARN-OMIT-7K %s
78 // WARN-OMIT-7K: warning: optimization flag '-fomit-frame-pointer' is not supported for target 'armv7k'
79 // WARN-OMIT-7K: "-mframe-pointer=all"
81 // RUN: %clang -### -target armv7s-apple-ios8.0 -momit-leaf-frame-pointer %s 2>&1 | \
82 // RUN: FileCheck --check-prefix=WARN-OMIT-LEAF-7S %s
83 // WARN-OMIT-LEAF-7S-NOT: warning: optimization flag '-momit-leaf-frame-pointer' is not supported for target 'armv7s'
84 // WARN-OMIT-LEAF-7S: "-mframe-pointer=non-leaf"
86 // On AArch64, PS4, PS5, and VE, default to omitting the frame pointer on leaf
87 // functions
88 // RUN: %clang -### --target=aarch64 -S %s 2>&1 | \
89 // RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
90 // RUN: %clang -### --target=x86_64-scei-ps4 -S %s 2>&1 | \
91 // RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
92 // RUN: %clang -### --target=x86_64-scei-ps4 -S -O2 %s 2>&1 | \
93 // RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
94 // RUN: %clang -### --target=x86_64-sie-ps5 -S %s 2>&1 | \
95 // RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
96 // RUN: %clang -### --target=x86_64-sie-ps5 -S -O2 %s 2>&1 | \
97 // RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
98 // RUN: %clang -### -target aarch64-apple-darwin -arch arm64_32 -S %s 2>&1 | \
99 // RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
100 // RUN: %clang -### --target=ve-unknown-linux-gnu -S %s 2>&1 | \
101 // RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
102 // RUN: %clang -### --target=aarch64-linux-android -S %s 2>&1 | \
103 // RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
104 // RUN: %clang -### --target=aarch64-linux-android -S -O2 %s 2>&1 | \
105 // RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
106 // RUN: %clang -### --target=aarch64-linux-android -S -Os %s 2>&1 | \
107 // RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
109 // RUN: %clang -### --target=powerpc64 -S %s 2>&1 | \
110 // RUN: FileCheck --check-prefix=KEEP-ALL %s
111 // RUN: %clang -### --target=powerpc64 -S -O1 %s 2>&1 | \
112 // RUN: FileCheck --check-prefix=KEEP-NONE %s
114 // SPARC targets omit the frame pointer when optimizations are enabled.
115 // RUN: %clang -### --target=sparc -S %s 2>&1 | \
116 // RUN: FileCheck --check-prefix=KEEP-ALL %s
117 // RUN: %clang -### --target=sparc -S -O1 %s 2>&1 | \
118 // RUN: FileCheck --check-prefix=KEEP-NONE %s
119 // RUN: %clang -### --target=sparcel -S %s 2>&1 | \
120 // RUN: FileCheck --check-prefix=KEEP-ALL %s
121 // RUN: %clang -### --target=sparcel -S -O1 %s 2>&1 | \
122 // RUN: FileCheck --check-prefix=KEEP-NONE %s
123 // RUN: %clang -### --target=sparc64 -S %s 2>&1 | \
124 // RUN: FileCheck --check-prefix=KEEP-ALL %s
125 // RUN: %clang -### --target=sparc64 -S -O1 %s 2>&1 | \
126 // RUN: FileCheck --check-prefix=KEEP-NONE %s
128 // M68k targets omit the frame pointer when optimizations are enabled.
129 // RUN: %clang -### --target=m68k -S %s 2>&1 | \
130 // RUN: FileCheck --check-prefix=KEEP-ALL %s
131 // RUN: %clang -### --target=m68k -S -O1 %s 2>&1 | \
132 // RUN: FileCheck --check-prefix=KEEP-NONE %s
134 // For AAarch32 (A32, T32) linux targets, default omit frame pointer when
135 // optimizations are enabled.
136 // RUN: %clang -### --target=arm-linux-gnueabihf- -marm -S %s 2>&1 | \
137 // RUN: FileCheck --check-prefix=KEEP-ALL %s
138 // RUN: %clang -### --target=arm-linux-gnueabihf- -mthumb -S %s 2>&1 | \
139 // RUN: FileCheck --check-prefix=KEEP-ALL %s
140 // RUN: %clang -### --target=arm-linux-gnueabihf- -marm -mbig-endian -S %s 2>&1 | \
141 // RUN: FileCheck --check-prefix=KEEP-ALL %s
142 // RUN: %clang -### --target=arm-linux-gnueabihf- -mthumb -mbig-endian -S %s 2>&1 | \
143 // RUN: FileCheck --check-prefix=KEEP-ALL %s
144 // RUN: %clang -### --target=arm-linux-gnueabihf- -marm -O1 -S %s 2>&1 | \
145 // RUN: FileCheck --check-prefix=KEEP-NONE %s
146 // RUN: %clang -### --target=arm-linux-gnueabihf- -mthumb -O1 -S %s 2>&1 | \
147 // RUN: FileCheck --check-prefix=KEEP-NONE %s
148 // RUN: %clang -### --target=arm-linux-gnueabihf- -marm -mbig-endian -O1 -S %s 2>&1 | \
149 // RUN: FileCheck --check-prefix=KEEP-NONE %s
150 // RUN: %clang -### --target=arm-linux-gnueabihf- -mthumb -mbig-endian -O1 -S %s 2>&1 | \
151 // RUN: FileCheck --check-prefix=KEEP-NONE %s
152 // For Android, keep the framepointers always.
153 // RUN: %clang -### --target=armv7a-linux-androideabi- -marm -O1 -S %s 2>&1 | \
154 // RUN: FileCheck --check-prefix=KEEP-ALL %s
155 // RUN: %clang -### --target=armv7a-linux-androideabi- -mthumb -O1 -S %s 2>&1 | \
156 // RUN: FileCheck --check-prefix=KEEP-ALL %s
157 // RUN: %clang -### --target=armv7a-linux-androideabi- -marm -mbig-endian -O1 -S %s 2>&1 | \
158 // RUN: FileCheck --check-prefix=KEEP-ALL %s
159 // RUN: %clang -### --target=armv7a-linux-androideabi- -mthumb -mbig-endian -O1 -S %s 2>&1 | \
160 // RUN: FileCheck --check-prefix=KEEP-ALL %s
161 // RUN: %clang -### --target=riscv64-linux-android -O1 -S %s 2>&1 | \
162 // RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
163 // RUN: not %clang -### --target=riscv64-linux-android -mbig-endian -O1 -S %s 2>&1 | \
164 // RUN: FileCheck --check-prefix=KEEP-NON-LEAF %s
165 void f0() {}
166 void f1() { f0(); }