1 // Check to make sure clang is somewhat picky about -g options.
2 // rdar://10383444
3 
4 // Linux.
5 // RUN: %clang -### -c -g %s -target x86_64-linux-gnu 2>&1 \
6 // RUN:             | FileCheck -check-prefix=G -check-prefix=G_GDB %s
7 // RUN: %clang -### -c -g2 %s -target x86_64-linux-gnu 2>&1 \
8 // RUN:             | FileCheck -check-prefix=G %s
9 // RUN: %clang -### -c -g3 %s -target x86_64-linux-gnu 2>&1 \
10 // RUN:             | FileCheck -check-prefix=G %s
11 // RUN: %clang -### -c -ggdb %s -target x86_64-linux-gnu 2>&1 \
12 // RUN:             | FileCheck -check-prefix=G -check-prefix=G_GDB %s
13 // RUN: %clang -### -c -ggdb1 %s -target x86_64-linux-gnu 2>&1 \
14 // RUN:             | FileCheck -check-prefix=GLTO_ONLY -check-prefix=G_GDB %s
15 // RUN: %clang -### -c -ggdb3 %s -target x86_64-linux-gnu 2>&1 \
16 // RUN:             | FileCheck -check-prefix=G %s
17 // RUN: %clang -### -c -glldb %s -target x86_64-linux-gnu 2>&1 \
18 // RUN:             | FileCheck -check-prefix=G -check-prefix=G_LLDB %s
19 // RUN: %clang -### -c -gsce %s -target x86_64-linux-gnu 2>&1 \
20 
21 // Darwin.
22 // RUN:             | FileCheck -check-prefix=G -check-prefix=G_SCE %s
23 // RUN: %clang -### -c -g %s -target x86_64-apple-darwin 2>&1 \
24 // RUN:             | FileCheck -check-prefix=G_STANDALONE \
25 // RUN:                         -check-prefix=G_DWARF2 \
26 // RUN:                         -check-prefix=G_LLDB %s
27 // RUN: %clang -### -c -g %s -target x86_64-apple-darwin16 2>&1 \
28 // RUN:             | FileCheck -check-prefix=G_STANDALONE \
29 // RUN:                         -check-prefix=G_DWARF4 \
30 // RUN:                         -check-prefix=G_LLDB %s
31 // RUN: %clang -### -c -g2 %s -target x86_64-apple-darwin16 2>&1 \
32 // RUN:             | FileCheck -check-prefix=G_STANDALONE \
33 // RUN:                         -check-prefix=G_DWARF4 %s
34 // RUN: %clang -### -c -g3 %s -target x86_64-apple-darwin16 2>&1 \
35 // RUN:             | FileCheck -check-prefix=G_STANDALONE \
36 // RUN:                         -check-prefix=G_DWARF4 %s
37 // RUN: %clang -### -c -ggdb %s -target x86_64-apple-darwin16 2>&1 \
38 // RUN:             | FileCheck -check-prefix=G_STANDALONE \
39 // RUN:                         -check-prefix=G_DWARF4 \
40 // RUN:                         -check-prefix=G_GDB %s
41 // RUN: %clang -### -c -ggdb1 %s -target x86_64-apple-darwin16 2>&1 \
42 // RUN:             | FileCheck -check-prefix=GLTO_ONLY %s
43 // RUN: %clang -### -c -ggdb3 %s -target x86_64-apple-darwin16 2>&1 \
44 // RUN:             | FileCheck -check-prefix=G_STANDALONE \
45 // RUN:                         -check-prefix=G_DWARF4 %s
46 // RUN: %clang -### -c -g %s -target x86_64-apple-macosx10.11 2>&1 \
47 // RUN:             | FileCheck -check-prefix=G_STANDALONE \
48 // RUN:                         -check-prefix=G_DWARF4 %s
49 // RUN: %clang -### -c -g %s -target x86_64-apple-macosx10.10 2>&1 \
50 // RUN:             | FileCheck -check-prefix=G_ONLY_DWARF2 %s
51 // RUN: %clang -### -c -g %s -target armv7-apple-ios9.0 2>&1 \
52 // RUN:             | FileCheck -check-prefix=G_STANDALONE \
53 // RUN:                         -check-prefix=G_DWARF4 %s
54 // RUN: %clang -### -c -g %s -target armv7-apple-ios8.0 2>&1 \
55 // RUN:             | FileCheck -check-prefix=G_ONLY_DWARF2 %s
56 // RUN: %clang -### -c -g %s -target armv7k-apple-watchos 2>&1 \
57 // RUN:             | FileCheck -check-prefix=G_STANDALONE \
58 // RUN:                         -check-prefix=G_DWARF4 %s
59 // RUN: %clang -### -c -g %s -target arm64-apple-tvos9.0 2>&1 \
60 // RUN:             | FileCheck -check-prefix=G_STANDALONE \
61 // RUN:                         -check-prefix=G_DWARF4 %s
62 
63 // FreeBSD.
64 // RUN: %clang -### -c -g %s -target x86_64-pc-freebsd10.0 2>&1 \
65 // RUN:             | FileCheck -check-prefix=G_GDB %s
66 
67 // On the PS4, -g defaults to -gno-column-info, and we always generate the
68 // arange section.
69 // RUN: %clang -### -c %s -target x86_64-scei-ps4 2>&1 \
70 // RUN:             | FileCheck -check-prefix=NOG_PS4 %s
71 // RUN: %clang -### -c %s -g -target x86_64-scei-ps4 2>&1 \
72 // RUN:             | FileCheck -check-prefix=G_PS4 %s
73 // RUN: %clang -### -c %s -g -target x86_64-scei-ps4 2>&1 \
74 // RUN:             | FileCheck -check-prefix=G_SCE %s
75 // RUN: %clang -### -c %s -g -target x86_64-scei-ps4 2>&1 \
76 // RUN:             | FileCheck -check-prefix=NOCI %s
77 // RUN: %clang -### -c %s -g -gcolumn-info -target x86_64-scei-ps4 2>&1 \
78 // RUN:             | FileCheck -check-prefix=CI %s
79 
80 // RUN: %clang -### -c -gdwarf-2 %s 2>&1 \
81 // RUN:             | FileCheck -check-prefix=G_ONLY_DWARF2 %s
82 //
83 // RUN: not %clang -### -c -gfoo %s 2>&1 | FileCheck -check-prefix=G_ERR %s
84 // RUN: %clang -### -c -g -g0 %s 2>&1 | FileCheck -check-prefix=G_NO %s
85 // RUN: %clang -### -c -ggdb0 %s 2>&1 | FileCheck -check-prefix=G_NO %s
86 // RUN: %clang -### -c -glldb -g0 %s 2>&1 | FileCheck -check-prefix=G_NO %s
87 // RUN: %clang -### -c -glldb -g1 %s 2>&1 \
88 // RUN:             | FileCheck -check-prefix=GLTO_ONLY -check-prefix=G_LLDB %s
89 //
90 // PS4 defaults to sce; -ggdb0 changes tuning but turns off debug info,
91 // then -g turns it back on without affecting tuning.
92 // RUN: %clang -### -c -ggdb0 -g -target x86_64-scei-ps4 %s 2>&1 \
93 // RUN:             | FileCheck -check-prefix=G -check-prefix=G_GDB %s
94 //
95 // RUN: %clang -### -c -g1 %s 2>&1 \
96 // RUN:             | FileCheck -check-prefix=GLTO_ONLY %s
97 // RUN: %clang -### -c -gmlt %s 2>&1 \
98 // RUN:             | FileCheck -check-prefix=GLTO_ONLY %s
99 // RUN: %clang -### -c -gline-tables-only %s 2>&1 \
100 // RUN:             | FileCheck -check-prefix=GLTO_ONLY %s
101 // RUN: %clang -### -c -gline-tables-only %s -target x86_64-apple-darwin 2>&1 \
102 // RUN:             | FileCheck -check-prefix=GLTO_ONLY %s
103 // RUN: %clang -### -c -gline-tables-only %s -target i686-pc-openbsd 2>&1 \
104 // RUN:             | FileCheck -check-prefix=GLTO_ONLY_DWARF2 %s
105 // RUN: %clang -### -c -gline-tables-only %s -target x86_64-pc-freebsd10.0 2>&1 \
106 // RUN:             | FileCheck -check-prefix=GLTO_ONLY_DWARF2 %s
107 // RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-linux-gnu 2>&1 \
108 // RUN:             | FileCheck -check-prefix=G_ONLY %s
109 // RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-apple-darwin16 2>&1 \
110 // RUN:             | FileCheck -check-prefix=G_STANDALONE -check-prefix=G_DWARF4 %s
111 // RUN: %clang -### -c -gline-tables-only -g %s -target i686-pc-openbsd 2>&1 \
112 // RUN:             | FileCheck -check-prefix=G_ONLY_DWARF2 %s
113 // RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-pc-freebsd10.0 2>&1 \
114 // RUN:             | FileCheck -check-prefix=G_ONLY_DWARF2 %s
115 // RUN: %clang -### -c -gline-tables-only -g %s -target i386-pc-solaris 2>&1 \
116 // RUN:             | FileCheck -check-prefix=G_ONLY_DWARF2 %s
117 // RUN: %clang -### -c -gline-tables-only -g0 %s 2>&1 \
118 // RUN:             | FileCheck -check-prefix=GLTO_NO %s
119 //
120 // RUN: %clang -### -c -grecord-gcc-switches %s 2>&1 \
121 //             | FileCheck -check-prefix=GRECORD %s
122 // RUN: %clang -### -c -gno-record-gcc-switches %s 2>&1 \
123 //             | FileCheck -check-prefix=GNO_RECORD %s
124 // RUN: %clang -### -c -grecord-gcc-switches -gno-record-gcc-switches %s 2>&1 \
125 //             | FileCheck -check-prefix=GNO_RECORD %s/
126 // RUN: %clang -### -c -grecord-gcc-switches -o - %s 2>&1 \
127 //             | FileCheck -check-prefix=GRECORD_O %s
128 // RUN: %clang -### -c -O3 -ffunction-sections -grecord-gcc-switches %s 2>&1 \
129 //             | FileCheck -check-prefix=GRECORD_OPT %s
130 //
131 // RUN: %clang -### -c -gstrict-dwarf -gno-strict-dwarf %s 2>&1 \
132 // RUN:        | FileCheck -check-prefix=GIGNORE %s
133 //
134 // RUN: %clang -### -c -ggnu-pubnames %s 2>&1 | FileCheck -check-prefix=GOPT %s
135 //
136 // RUN: %clang -### -c -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=GARANGE %s
137 //
138 // RUN: %clang -### -fdebug-types-section %s 2>&1 \
139 // RUN:        | FileCheck -check-prefix=FDTS %s
140 //
141 // RUN: %clang -### -fdebug-types-section -fno-debug-types-section %s 2>&1 \
142 // RUN:        | FileCheck -check-prefix=NOFDTS %s
143 //
144 // RUN: %clang -### -g -gno-column-info %s 2>&1 \
145 // RUN:        | FileCheck -check-prefix=NOCI %s
146 //
147 // RUN: %clang -### -g -target x86_64-unknown-unknown %s 2>&1 \
148 //             | FileCheck -check-prefix=CI %s
149 //
150 // RUN: %clang -### -gmodules %s 2>&1 \
151 // RUN:        | FileCheck -check-prefix=GEXTREFS %s
152 //
153 // RUN: %clang -### -gmodules -g %s 2>&1 \
154 // RUN:        | FileCheck -check-prefix=GEXTREFS %s
155 //
156 // RUN: %clang -### -gline-tables-only -gmodules %s 2>&1 \
157 // RUN:        | FileCheck -check-prefix=GEXTREFS %s
158 //
159 // RUN: %clang -### -gmodules -gline-tables-only %s 2>&1 \
160 // RUN:        | FileCheck -check-prefix=GLTO_ONLY %s
161 //
162 // G: "-cc1"
163 // G: "-debug-info-kind=limited"
164 //
165 // NOG_PS4: "-cc1"
166 // NOG_PS4-NOT "-dwarf-version=
167 // NOG_PS4: "-generate-arange-section"
168 // NOG_PS4-NOT: "-dwarf-version=
169 //
170 // G_PS4: "-cc1"
171 // G_PS4: "-dwarf-version=
172 // G_PS4: "-generate-arange-section"
173 //
174 // G_ERR: error: unknown argument:
175 //
176 // G_NO: "-cc1"
177 // G_NO-NOT: -debug-info-kind=
178 //
179 // GLTO_ONLY: "-cc1"
180 // GLTO_ONLY-NOT: "-dwarf-ext-refs"
181 // GLTO_ONLY: "-debug-info-kind=line-tables-only"
182 // GLTO_ONLY-NOT: "-dwarf-ext-refs"
183 //
184 // GLTO_ONLY_DWARF2: "-cc1"
185 // GLTO_ONLY_DWARF2: "-debug-info-kind=line-tables-only"
186 // GLTO_ONLY_DWARF2: "-dwarf-version=2"
187 //
188 // G_ONLY: "-cc1"
189 // G_ONLY: "-debug-info-kind=limited"
190 //
191 // These tests assert that "-gline-tables-only" "-g" uses the latter,
192 // but otherwise not caring about the DebugInfoKind.
193 // G_ONLY_DWARF2: "-cc1"
194 // G_ONLY_DWARF2: "-debug-info-kind={{standalone|limited}}"
195 // G_ONLY_DWARF2: "-dwarf-version=2"
196 //
197 // G_STANDALONE: "-cc1"
198 // G_STANDALONE: "-debug-info-kind=standalone"
199 // G_DWARF4: "-dwarf-version=4"
200 //
201 // G_GDB:  "-debugger-tuning=gdb"
202 // G_LLDB: "-debugger-tuning=lldb"
203 // G_SCE:  "-debugger-tuning=sce"
204 //
205 // This tests asserts that "-gline-tables-only" "-g0" disables debug info.
206 // GLTO_NO: "-cc1"
207 // GLTO_NO-NOT: -debug-info-kind=
208 //
209 // GRECORD: "-dwarf-debug-flags"
210 // GRECORD: -### -c -grecord-gcc-switches
211 //
212 // GNO_RECORD-NOT: "-dwarf-debug-flags"
213 // GNO_RECORD-NOT: -### -c -grecord-gcc-switches
214 //
215 // GRECORD_O: "-dwarf-debug-flags"
216 // GRECORD_O: -### -c -grecord-gcc-switches -o -
217 //
218 // GRECORD_OPT: -### -c -O3 -ffunction-sections -grecord-gcc-switches
219 //
220 // GIGNORE-NOT: "argument unused during compilation"
221 //
222 // GOPT: -generate-gnu-dwarf-pub-sections
223 //
224 // GARANGE: -generate-arange-section
225 //
226 // FDTS: "-backend-option" "-generate-type-units"
227 //
228 // NOFDTS-NOT: "-backend-option" "-generate-type-units"
229 //
230 // CI: "-dwarf-column-info"
231 //
232 // NOCI-NOT: "-dwarf-column-info"
233 //
234 // GEXTREFS: "-dwarf-ext-refs" "-fmodule-format=obj" "-debug-info-kind={{standalone|limited}}"
235 
236 // RUN: not %clang -cc1 -debug-info-kind=watkind 2>&1 | FileCheck -check-prefix=BADSTRING1 %s
237 // BADSTRING1: error: invalid value 'watkind' in '-debug-info-kind=watkind'
238 // RUN: not %clang -cc1 -debugger-tuning=gmodal 2>&1 | FileCheck -check-prefix=BADSTRING2 %s
239 // BADSTRING2: error: invalid value 'gmodal' in '-debugger-tuning=gmodal'
240 
241 // RUN: %clang -### -fdebug-macro    %s 2>&1 | FileCheck -check-prefix=MACRO %s
242 // RUN: %clang -### -fno-debug-macro %s 2>&1 | FileCheck -check-prefix=NOMACRO %s
243 // RUN: %clang -###                  %s 2>&1 | FileCheck -check-prefix=NOMACRO %s
244 // MACRO: "-debug-info-macro"
245 // NOMACRO-NOT: "-debug-info-macro"
246