Clang Project

clang_source_code/test/Driver/debug-options.c
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// Windows.
68// RUN: %clang -### -c -g %s -target x86_64-w64-windows-gnu 2>&1 \
69// RUN:             | FileCheck -check-prefix=G_GDB %s
70// RUN: %clang -### -c -g %s -target x86_64-windows-msvc 2>&1 \
71// RUN:             | FileCheck -check-prefix=G_NOTUNING %s
72// RUN: %clang_cl -### -c -Z7 -target x86_64-windows-msvc -- %s 2>&1 \
73// RUN:             | FileCheck -check-prefix=G_NOTUNING %s
74
75// On the PS4, -g defaults to -gno-column-info, and we always generate the
76// arange section.
77// RUN: %clang -### -c %s -target x86_64-scei-ps4 2>&1 \
78// RUN:             | FileCheck -check-prefix=NOG_PS4 %s
79// RUN: %clang -### -c %s -g -target x86_64-scei-ps4 2>&1 \
80// RUN:             | FileCheck -check-prefix=G_PS4 %s
81// RUN: %clang -### -c %s -g -target x86_64-scei-ps4 2>&1 \
82// RUN:             | FileCheck -check-prefix=G_SCE %s
83// RUN: %clang -### -c %s -g -target x86_64-scei-ps4 2>&1 \
84// RUN:             | FileCheck -check-prefix=NOCI %s
85// RUN: %clang -### -c %s -g -gcolumn-info -target x86_64-scei-ps4 2>&1 \
86// RUN:             | FileCheck -check-prefix=CI %s
87// RUN: %clang -### -c %s -gsce -target x86_64-unknown-linux 2>&1 \
88// RUN:             | FileCheck -check-prefix=NOCI %s
89
90// RUN: %clang -### -c -gdwarf-2 %s 2>&1 \
91// RUN:             | FileCheck -check-prefix=G_ONLY_DWARF2 %s
92//
93// RUN: not %clang -### -c -gfoo %s 2>&1 | FileCheck -check-prefix=G_ERR %s
94// RUN: %clang -### -c -g -g0 %s 2>&1 | FileCheck -check-prefix=G_NO %s
95// RUN: %clang -### -c -ggdb0 %s 2>&1 | FileCheck -check-prefix=G_NO %s
96// RUN: %clang -### -c -glldb -g0 %s 2>&1 | FileCheck -check-prefix=G_NO %s
97// RUN: %clang -### -c -glldb -g1 %s 2>&1 \
98// RUN:             | FileCheck -check-prefix=GLTO_ONLY -check-prefix=G_LLDB %s
99//
100// PS4 defaults to sce; -ggdb0 changes tuning but turns off debug info,
101// then -g turns it back on without affecting tuning.
102// RUN: %clang -### -c -ggdb0 -g -target x86_64-scei-ps4 %s 2>&1 \
103// RUN:             | FileCheck -check-prefix=G -check-prefix=G_GDB %s
104//
105// RUN: %clang -### -c -g1 %s 2>&1 \
106// RUN:             | FileCheck -check-prefix=GLTO_ONLY %s
107// RUN: %clang -### -c -gmlt %s 2>&1 \
108// RUN:             | FileCheck -check-prefix=GLTO_ONLY %s
109// RUN: %clang -### -c -gline-tables-only %s 2>&1 \
110// RUN:             | FileCheck -check-prefix=GLTO_ONLY %s
111// RUN: %clang -### -c -gline-tables-only %s -target x86_64-apple-darwin 2>&1 \
112// RUN:             | FileCheck -check-prefix=GLTO_ONLY %s
113// RUN: %clang -### -c -gline-tables-only %s -target i686-pc-openbsd 2>&1 \
114// RUN:             | FileCheck -check-prefix=GLTO_ONLY_DWARF2 %s
115// RUN: %clang -### -c -gline-tables-only %s -target x86_64-pc-freebsd10.0 2>&1 \
116// RUN:             | FileCheck -check-prefix=GLTO_ONLY_DWARF2 %s
117// RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-linux-gnu 2>&1 \
118// RUN:             | FileCheck -check-prefix=G_ONLY %s
119// RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-apple-darwin16 2>&1 \
120// RUN:             | FileCheck -check-prefix=G_STANDALONE -check-prefix=G_DWARF4 %s
121// RUN: %clang -### -c -gline-tables-only -g %s -target i686-pc-openbsd 2>&1 \
122// RUN:             | FileCheck -check-prefix=G_ONLY_DWARF2 %s
123// RUN: %clang -### -c -gline-tables-only -g %s -target x86_64-pc-freebsd10.0 2>&1 \
124// RUN:             | FileCheck -check-prefix=G_ONLY_DWARF2 %s
125// RUN: %clang -### -c -gline-tables-only -g %s -target i386-pc-solaris 2>&1 \
126// RUN:             | FileCheck -check-prefix=G_ONLY_DWARF2 %s
127// RUN: %clang -### -c -gline-tables-only -g0 %s 2>&1 \
128// RUN:             | FileCheck -check-prefix=GLTO_NO %s
129//
130// RUN: %clang -### -c -gline-directives-only %s -target x86_64-apple-darwin 2>&1 \
131// RUN:             | FileCheck -check-prefix=GLIO_ONLY %s
132// RUN: %clang -### -c -gline-directives-only %s -target i686-pc-openbsd 2>&1 \
133// RUN:             | FileCheck -check-prefix=GLIO_ONLY_DWARF2 %s
134// RUN: %clang -### -c -gline-directives-only %s -target x86_64-pc-freebsd10.0 2>&1 \
135// RUN:             | FileCheck -check-prefix=GLIO_ONLY_DWARF2 %s
136// RUN: %clang -### -c -gline-directives-only -g %s -target x86_64-linux-gnu 2>&1 \
137// RUN:             | FileCheck -check-prefix=G_ONLY %s
138// RUN: %clang -### -c -gline-directives-only -g %s -target x86_64-apple-darwin16 2>&1 \
139// RUN:             | FileCheck -check-prefix=G_STANDALONE -check-prefix=G_DWARF4 %s
140// RUN: %clang -### -c -gline-directives-only -g %s -target i686-pc-openbsd 2>&1 \
141// RUN:             | FileCheck -check-prefix=G_ONLY_DWARF2 %s
142// RUN: %clang -### -c -gline-directives-only -g %s -target x86_64-pc-freebsd10.0 2>&1 \
143// RUN:             | FileCheck -check-prefix=G_ONLY_DWARF2 %s
144// RUN: %clang -### -c -gline-directives-only -g %s -target i386-pc-solaris 2>&1 \
145// RUN:             | FileCheck -check-prefix=G_ONLY_DWARF2 %s
146// RUN: %clang -### -c -gline-directives-only -g0 %s 2>&1 \
147// RUN:             | FileCheck -check-prefix=GLIO_NO %s
148//
149// RUN: %clang -### -c -grecord-gcc-switches %s 2>&1 \
150//             | FileCheck -check-prefix=GRECORD %s
151// RUN: %clang -### -c -gno-record-gcc-switches %s 2>&1 \
152//             | FileCheck -check-prefix=GNO_RECORD %s
153// RUN: %clang -### -c -grecord-gcc-switches -gno-record-gcc-switches %s 2>&1 \
154//             | FileCheck -check-prefix=GNO_RECORD %s/
155// RUN: %clang -### -c -grecord-gcc-switches -o - %s 2>&1 \
156//             | FileCheck -check-prefix=GRECORD_O %s
157// RUN: %clang -### -c -O3 -ffunction-sections -grecord-gcc-switches %s 2>&1 \
158//             | FileCheck -check-prefix=GRECORD_OPT %s
159//
160// RUN: %clang -### -c -grecord-command-line %s 2>&1 \
161//             | FileCheck -check-prefix=GRECORD %s
162// RUN: %clang -### -c -gno-record-command-line %s 2>&1 \
163//             | FileCheck -check-prefix=GNO_RECORD %s
164// RUN: %clang -### -c -grecord-command-line -gno-record-command-line %s 2>&1 \
165//             | FileCheck -check-prefix=GNO_RECORD %s/
166// RUN: %clang -### -c -grecord-command-line -o - %s 2>&1 \
167//             | FileCheck -check-prefix=GRECORD_O %s
168// RUN: %clang -### -c -O3 -ffunction-sections -grecord-command-line %s 2>&1 \
169//             | FileCheck -check-prefix=GRECORD_OPT %s
170//
171// RUN: %clang -### -c -gstrict-dwarf -gno-strict-dwarf %s 2>&1 \
172// RUN:        | FileCheck -check-prefix=GIGNORE %s
173//
174// RUN: %clang -### -c -ggnu-pubnames %s 2>&1 | FileCheck -check-prefix=GPUB %s
175// RUN: %clang -### -c -ggdb %s 2>&1 | FileCheck -check-prefix=NOPUB %s
176// RUN: %clang -### -c -ggnu-pubnames -gno-gnu-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s
177// RUN: %clang -### -c -ggnu-pubnames -gno-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s
178//
179// RUN: %clang -### -c -gpubnames %s 2>&1 | FileCheck -check-prefix=PUB %s
180// RUN: %clang -### -c -ggdb %s 2>&1 | FileCheck -check-prefix=NOPUB %s
181// RUN: %clang -### -c -gpubnames -gno-gnu-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s
182// RUN: %clang -### -c -gpubnames -gno-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s
183//
184// RUN: %clang -### -c -gsplit-dwarf %s 2>&1 | FileCheck -check-prefix=GPUB %s
185// RUN: %clang -### -c -gsplit-dwarf -gno-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s
186//
187// RUN: %clang -### -c -fdebug-ranges-base-address %s 2>&1 | FileCheck -check-prefix=RNGBSE %s
188// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NORNGBSE %s
189// RUN: %clang -### -c -fdebug-ranges-base-address -fno-debug-ranges-base-address %s 2>&1 | FileCheck -check-prefix=NORNGBSE %s
190//
191// RUN: %clang -### -c -glldb %s 2>&1 | FileCheck -check-prefix=GPUB %s
192// RUN: %clang -### -c -glldb -gno-pubnames %s 2>&1 | FileCheck -check-prefix=NOPUB %s
193//
194// RUN: %clang -### -c -gdwarf-aranges %s 2>&1 | FileCheck -check-prefix=GARANGE %s
195//
196// RUN: %clang -### -fdebug-types-section -target x86_64-unknown-linux %s 2>&1 \
197// RUN:        | FileCheck -check-prefix=FDTS %s
198//
199// RUN: %clang -### -fdebug-types-section -fno-debug-types-section -target x86_64-unknown-linux %s 2>&1 \
200// RUN:        | FileCheck -check-prefix=NOFDTS %s
201//
202// RUN: %clang -### -fdebug-types-section -target x86_64-apple-darwin %s 2>&1 \
203// RUN:        | FileCheck -check-prefix=FDTSE %s
204//
205// RUN: %clang -### -fdebug-types-section -fno-debug-types-section -target x86_64-apple-darwin %s 2>&1 \
206// RUN:        | FileCheck -check-prefix=NOFDTSE %s
207//
208// RUN: %clang -### -g -gno-column-info %s 2>&1 \
209// RUN:        | FileCheck -check-prefix=NOCI %s
210//
211// RUN: %clang -### -g -target x86_64-unknown-unknown %s 2>&1 \
212//             | FileCheck -check-prefix=CI %s
213//
214// RUN: %clang -### -gmodules %s 2>&1 \
215// RUN:        | FileCheck -check-prefix=GEXTREFS %s
216//
217// RUN: %clang -### -gmodules -g %s 2>&1 \
218// RUN:        | FileCheck -check-prefix=GEXTREFS %s
219//
220// RUN: %clang -### -gline-tables-only -gmodules %s 2>&1 \
221// RUN:        | FileCheck -check-prefix=GEXTREFS %s
222//
223// RUN: %clang -### -gmodules -gline-tables-only %s 2>&1 \
224// RUN:        | FileCheck -check-prefix=GLTO_ONLY %s
225//
226// RUN: %clang -### -target %itanium_abi_triple -gmodules -gline-directives-only %s 2>&1 \
227// RUN:        | FileCheck -check-prefix=GLIO_ONLY %s
228//
229// G: "-cc1"
230// G: "-debug-info-kind=limited"
231//
232// NOG_PS4: "-cc1"
233// NOG_PS4-NOT "-dwarf-version=
234// NOG_PS4: "-generate-arange-section"
235// NOG_PS4-NOT: "-dwarf-version=
236//
237// G_PS4: "-cc1"
238// G_PS4: "-dwarf-version=
239// G_PS4: "-generate-arange-section"
240//
241// G_ERR: error: unknown argument:
242//
243// G_NO: "-cc1"
244// G_NO-NOT: -debug-info-kind=
245//
246// GLTO_ONLY: "-cc1"
247// GLTO_ONLY-NOT: "-dwarf-ext-refs"
248// GLTO_ONLY: "-debug-info-kind=line-tables-only"
249// GLTO_ONLY-NOT: "-dwarf-ext-refs"
250//
251// GLTO_ONLY_DWARF2: "-cc1"
252// GLTO_ONLY_DWARF2: "-debug-info-kind=line-tables-only"
253// GLTO_ONLY_DWARF2: "-dwarf-version=2"
254//
255// GLIO_ONLY: "-cc1"
256// GLIO_ONLY-NOT: "-dwarf-ext-refs"
257// GLIO_ONLY: "-debug-info-kind=line-directives-only"
258// GLIO_ONLY-NOT: "-dwarf-ext-refs"
259//
260// GLIO_ONLY_DWARF2: "-cc1"
261// GLIO_ONLY_DWARF2: "-debug-info-kind=line-directives-only"
262// GLIO_ONLY_DWARF2: "-dwarf-version=2"
263//
264// G_ONLY: "-cc1"
265// G_ONLY: "-debug-info-kind=limited"
266//
267// These tests assert that "-gline-tables-only" "-g" uses the latter,
268// but otherwise not caring about the DebugInfoKind.
269// G_ONLY_DWARF2: "-cc1"
270// G_ONLY_DWARF2: "-debug-info-kind={{standalone|limited}}"
271// G_ONLY_DWARF2: "-dwarf-version=2"
272//
273// G_STANDALONE: "-cc1"
274// G_STANDALONE: "-debug-info-kind=standalone"
275// G_DWARF4: "-dwarf-version=4"
276//
277// G_GDB:  "-debugger-tuning=gdb"
278// G_LLDB: "-debugger-tuning=lldb"
279// G_SCE:  "-debugger-tuning=sce"
280//
281// G_NOTUNING: "-cc1"
282// G_NOTUNING-NOT: "-debugger-tuning="
283//
284// This tests asserts that "-gline-tables-only" "-g0" disables debug info.
285// GLTO_NO: "-cc1"
286// GLTO_NO-NOT: -debug-info-kind=
287//
288// This tests asserts that "-gline-directives-only" "-g0" disables debug info.
289// GLIO_NO: "-cc1"
290// GLIO_NO-NOT: -debug-info-kind=
291//
292// GRECORD: "-dwarf-debug-flags"
293// GRECORD: -### -c -grecord-gcc-switches
294//
295// GNO_RECORD-NOT: "-dwarf-debug-flags"
296// GNO_RECORD-NOT: -### -c -grecord-gcc-switches
297//
298// GRECORD_O: "-dwarf-debug-flags"
299// GRECORD_O: -### -c -grecord-gcc-switches -o -
300//
301// GRECORD_OPT: -### -c -O3 -ffunction-sections -grecord-gcc-switches
302//
303// GIGNORE-NOT: "argument unused during compilation"
304//
305// GPUB: -ggnu-pubnames
306// NOPUB-NOT: -ggnu-pubnames
307// NOPUB-NOT: -gpubnames
308//
309// PUB: -gpubnames
310//
311// RNGBSE: -fdebug-ranges-base-address
312// NORNGBSE-NOT: -fdebug-ranges-base-address
313//
314// GARANGE: -generate-arange-section
315//
316// FDTS: "-mllvm" "-generate-type-units"
317// FDTSE: error: unsupported option '-fdebug-types-section' for target 'x86_64-apple-darwin'
318//
319// NOFDTS-NOT: "-mllvm" "-generate-type-units"
320// NOFDTSE-NOT: error: unsupported option '-fdebug-types-section' for target 'x86_64-apple-darwin'
321//
322// CI: "-dwarf-column-info"
323//
324// NOCI-NOT: "-dwarf-column-info"
325//
326// GEXTREFS: "-dwarf-ext-refs" "-fmodule-format=obj"
327// GEXTREFS: "-debug-info-kind={{standalone|limited}}"
328
329// RUN: not %clang -cc1 -debug-info-kind=watkind 2>&1 | FileCheck -check-prefix=BADSTRING1 %s
330// BADSTRING1: error: invalid value 'watkind' in '-debug-info-kind=watkind'
331// RUN: not %clang -cc1 -debugger-tuning=gmodal 2>&1 | FileCheck -check-prefix=BADSTRING2 %s
332// BADSTRING2: error: invalid value 'gmodal' in '-debugger-tuning=gmodal'
333
334// RUN: %clang -### -fdebug-macro    %s 2>&1 | FileCheck -check-prefix=MACRO %s
335// RUN: %clang -### -fno-debug-macro %s 2>&1 | FileCheck -check-prefix=NOMACRO %s
336// RUN: %clang -###                  %s 2>&1 | FileCheck -check-prefix=NOMACRO %s
337// MACRO: "-debug-info-macro"
338// NOMACRO-NOT: "-debug-info-macro"
339//
340// RUN: %clang -### -gdwarf-5 -gembed-source %s 2>&1 | FileCheck -check-prefix=GEMBED_5 %s
341// RUN: %clang -### -gdwarf-2 -gembed-source %s 2>&1 | FileCheck -check-prefix=GEMBED_2 %s
342// RUN: %clang -### -gdwarf-5 -gno-embed-source %s 2>&1 | FileCheck -check-prefix=NOGEMBED_5 %s
343// RUN: %clang -### -gdwarf-2 -gno-embed-source %s 2>&1 | FileCheck -check-prefix=NOGEMBED_2 %s
344//
345// GEMBED_5:  "-gembed-source"
346// GEMBED_2:  error: invalid argument '-gembed-source' only allowed with '-gdwarf-5'
347// NOGEMBED_5-NOT:  "-gembed-source"
348// NOGEMBED_2-NOT:  error: invalid argument '-gembed-source' only allowed with '-gdwarf-5'
349