blob: 8d3caf84f163b9d6d9f585d3f669d4b43c978094 [file] [log] [blame]
Daniel Dunbarf89a32a2009-11-10 19:51:53 +00001//===--- Options.cpp - clang-cc Option Handling ---------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// This file contains "pure" option handling, it is only responsible for turning
11// the options into internal *Option classes, but shouldn't have any other
12// logic.
13
14#include "Options.h"
Daniel Dunbard2cfa012009-11-11 08:13:55 +000015#include "clang/Basic/LangOptions.h"
16#include "clang/Basic/TargetInfo.h"
Daniel Dunbarb9bbd542009-11-15 06:48:46 +000017#include "clang/Basic/TargetOptions.h"
Daniel Dunbard2cfa012009-11-11 08:13:55 +000018#include "clang/Frontend/AnalysisConsumer.h"
Chandler Carruthbc55fe22009-11-12 17:24:48 +000019#include "clang/CodeGen/CodeGenOptions.h"
Daniel Dunbar89d1fdf2009-11-11 21:43:12 +000020#include "clang/Frontend/DependencyOutputOptions.h"
Daniel Dunbardcd40fb2009-11-11 08:13:40 +000021#include "clang/Frontend/DiagnosticOptions.h"
Daniel Dunbarf996c052009-11-12 23:52:32 +000022#include "clang/Frontend/FrontendOptions.h"
Daniel Dunbarf527a122009-11-11 08:13:32 +000023#include "clang/Frontend/HeaderSearchOptions.h"
Daniel Dunbar999215c2009-11-11 06:10:03 +000024#include "clang/Frontend/PCHReader.h"
25#include "clang/Frontend/PreprocessorOptions.h"
Daniel Dunbar22bdabf2009-11-11 10:07:44 +000026#include "clang/Frontend/PreprocessorOutputOptions.h"
Daniel Dunbar999215c2009-11-11 06:10:03 +000027#include "llvm/ADT/STLExtras.h"
Daniel Dunbarf89a32a2009-11-10 19:51:53 +000028#include "llvm/ADT/StringMap.h"
29#include "llvm/Support/CommandLine.h"
Daniel Dunbard392dd02009-11-15 00:12:04 +000030#include "llvm/Support/RegistryParser.h"
Daniel Dunbarb9bbd542009-11-15 06:48:46 +000031#include "llvm/System/Host.h"
Dan Gohmanad5ef3d2009-11-10 21:21:27 +000032#include <stdio.h>
Daniel Dunbarf89a32a2009-11-10 19:51:53 +000033
34using namespace clang;
35
36//===----------------------------------------------------------------------===//
Daniel Dunbard2cfa012009-11-11 08:13:55 +000037// Analyzer Options
38//===----------------------------------------------------------------------===//
39
40namespace analyzeroptions {
41
42static llvm::cl::list<Analyses>
43AnalysisList(llvm::cl::desc("Source Code Analysis - Checks and Analyses"),
44llvm::cl::values(
45#define ANALYSIS(NAME, CMDFLAG, DESC, SCOPE)\
46clEnumValN(NAME, CMDFLAG, DESC),
47#include "clang/Frontend/Analyses.def"
48clEnumValEnd));
49
50static llvm::cl::opt<AnalysisStores>
51AnalysisStoreOpt("analyzer-store",
52 llvm::cl::desc("Source Code Analysis - Abstract Memory Store Models"),
53 llvm::cl::init(BasicStoreModel),
54 llvm::cl::values(
55#define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN)\
56clEnumValN(NAME##Model, CMDFLAG, DESC),
57#include "clang/Frontend/Analyses.def"
58clEnumValEnd));
59
60static llvm::cl::opt<AnalysisConstraints>
61AnalysisConstraintsOpt("analyzer-constraints",
62 llvm::cl::desc("Source Code Analysis - Symbolic Constraint Engines"),
63 llvm::cl::init(RangeConstraintsModel),
64 llvm::cl::values(
65#define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN)\
66clEnumValN(NAME##Model, CMDFLAG, DESC),
67#include "clang/Frontend/Analyses.def"
68clEnumValEnd));
69
70static llvm::cl::opt<AnalysisDiagClients>
71AnalysisDiagOpt("analyzer-output",
72 llvm::cl::desc("Source Code Analysis - Output Options"),
73 llvm::cl::init(PD_HTML),
74 llvm::cl::values(
75#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN, AUTOCREATE)\
76clEnumValN(PD_##NAME, CMDFLAG, DESC),
77#include "clang/Frontend/Analyses.def"
78clEnumValEnd));
79
80static llvm::cl::opt<bool>
81AnalyzeAll("analyzer-opt-analyze-headers",
82 llvm::cl::desc("Force the static analyzer to analyze "
83 "functions defined in header files"));
Ted Kremenekaedb7432009-11-13 01:15:47 +000084
Daniel Dunbard2cfa012009-11-11 08:13:55 +000085static llvm::cl::opt<bool>
86AnalyzerDisplayProgress("analyzer-display-progress",
Ted Kremenekaedb7432009-11-13 01:15:47 +000087 llvm::cl::desc("Emit verbose output about the analyzer's progress"));
Daniel Dunbard2cfa012009-11-11 08:13:55 +000088
Ted Kremenekaedb7432009-11-13 01:15:47 +000089static llvm::cl::opt<bool>
90AnalyzerExperimentalChecks("analyzer-experimental-checks",
91 llvm::cl::desc("Use experimental path-sensitive checks"));
Ted Kremenek4ef13f82009-11-13 18:46:29 +000092
93static llvm::cl::opt<bool>
94AnalyzerExperimentalInternalChecks("analyzer-experimental-internal-checks",
95 llvm::cl::desc("Use new default path-sensitive checks currently in testing"));
Ted Kremenekaedb7432009-11-13 01:15:47 +000096
Daniel Dunbard2cfa012009-11-11 08:13:55 +000097static llvm::cl::opt<std::string>
98AnalyzeSpecificFunction("analyze-function",
99 llvm::cl::desc("Run analysis on specific function"));
100
101static llvm::cl::opt<bool>
102EagerlyAssume("analyzer-eagerly-assume",
Daniel Dunbard2cfa012009-11-11 08:13:55 +0000103 llvm::cl::desc("Eagerly assume the truth/falseness of some "
Ted Kremenekaedb7432009-11-13 01:15:47 +0000104 "symbolic constraints"));
Daniel Dunbard2cfa012009-11-11 08:13:55 +0000105
106static llvm::cl::opt<bool>
107PurgeDead("analyzer-purge-dead",
108 llvm::cl::init(true),
109 llvm::cl::desc("Remove dead symbols, bindings, and constraints before"
Ted Kremenekaedb7432009-11-13 01:15:47 +0000110 " processing a statement"));
Daniel Dunbard2cfa012009-11-11 08:13:55 +0000111
112static llvm::cl::opt<bool>
113TrimGraph("trim-egraph",
114 llvm::cl::desc("Only show error-related paths in the analysis graph"));
115
116static llvm::cl::opt<bool>
117VisualizeEGDot("analyzer-viz-egraph-graphviz",
118 llvm::cl::desc("Display exploded graph using GraphViz"));
119
120static llvm::cl::opt<bool>
121VisualizeEGUbi("analyzer-viz-egraph-ubigraph",
122 llvm::cl::desc("Display exploded graph using Ubigraph"));
123
124}
125
Daniel Dunbard2cfa012009-11-11 08:13:55 +0000126//===----------------------------------------------------------------------===//
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000127// Code Generation Options
128//===----------------------------------------------------------------------===//
129
130namespace codegenoptions {
131
132static llvm::cl::opt<bool>
133DisableLLVMOptimizations("disable-llvm-optzns",
134 llvm::cl::desc("Don't run LLVM optimization passes"));
135
136static llvm::cl::opt<bool>
137DisableRedZone("disable-red-zone",
Daniel Dunbar71f5f9f2009-11-19 04:55:06 +0000138 llvm::cl::desc("Do not emit code that uses the red zone."));
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000139
140static llvm::cl::opt<bool>
141GenerateDebugInfo("g",
142 llvm::cl::desc("Generate source level debug information"));
143
144static llvm::cl::opt<bool>
145NoCommon("fno-common",
146 llvm::cl::desc("Compile common globals like normal definitions"),
147 llvm::cl::ValueDisallowed);
148
149static llvm::cl::opt<bool>
150NoImplicitFloat("no-implicit-float",
Daniel Dunbar71f5f9f2009-11-19 04:55:06 +0000151 llvm::cl::desc("Don't generate implicit floating point instructions (x86-only)"));
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000152
153static llvm::cl::opt<bool>
154NoMergeConstants("fno-merge-all-constants",
155 llvm::cl::desc("Disallow merging of constants."));
156
157// It might be nice to add bounds to the CommandLine library directly.
158struct OptLevelParser : public llvm::cl::parser<unsigned> {
159 bool parse(llvm::cl::Option &O, llvm::StringRef ArgName,
160 llvm::StringRef Arg, unsigned &Val) {
161 if (llvm::cl::parser<unsigned>::parse(O, ArgName, Arg, Val))
162 return true;
163 if (Val > 3)
164 return O.error("'" + Arg + "' invalid optimization level!");
165 return false;
166 }
167};
168static llvm::cl::opt<unsigned, false, OptLevelParser>
169OptLevel("O", llvm::cl::Prefix,
170 llvm::cl::desc("Optimization level"),
171 llvm::cl::init(0));
172
173static llvm::cl::opt<bool>
174OptSize("Os", llvm::cl::desc("Optimize for size"));
175
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000176}
177
178//===----------------------------------------------------------------------===//
Daniel Dunbar89d1fdf2009-11-11 21:43:12 +0000179// Dependency Output Options
180//===----------------------------------------------------------------------===//
181
182namespace dependencyoutputoptions {
183
184static llvm::cl::opt<std::string>
185DependencyFile("dependency-file",
186 llvm::cl::desc("Filename (or -) to write dependency output to"));
187
188static llvm::cl::opt<bool>
189DependenciesIncludeSystemHeaders("sys-header-deps",
190 llvm::cl::desc("Include system headers in dependency output"));
191
192static llvm::cl::list<std::string>
193DependencyTargets("MT",
194 llvm::cl::desc("Specify target for dependency"));
195
196static llvm::cl::opt<bool>
197PhonyDependencyTarget("MP",
198 llvm::cl::desc("Create phony target for each dependency "
199 "(other than main file)"));
200
201}
202
203//===----------------------------------------------------------------------===//
Daniel Dunbardcd40fb2009-11-11 08:13:40 +0000204// Diagnostic Options
205//===----------------------------------------------------------------------===//
206
207namespace diagnosticoptions {
208
Daniel Dunbar8fd69a02009-11-12 07:28:21 +0000209static llvm::cl::opt<std::string>
210DumpBuildInformation("dump-build-information",
211 llvm::cl::value_desc("filename"),
212 llvm::cl::desc("output a dump of some build information to a file"));
213
Daniel Dunbardcd40fb2009-11-11 08:13:40 +0000214static llvm::cl::opt<bool>
215NoShowColumn("fno-show-column",
216 llvm::cl::desc("Do not include column number on diagnostics"));
217
218static llvm::cl::opt<bool>
219NoShowLocation("fno-show-source-location",
220 llvm::cl::desc("Do not include source location information with"
221 " diagnostics"));
222
223static llvm::cl::opt<bool>
224NoCaretDiagnostics("fno-caret-diagnostics",
225 llvm::cl::desc("Do not include source line and caret with"
226 " diagnostics"));
227
228static llvm::cl::opt<bool>
229NoDiagnosticsFixIt("fno-diagnostics-fixit-info",
230 llvm::cl::desc("Do not include fixit information in"
231 " diagnostics"));
232
Daniel Dunbar4c0e8272009-11-12 07:28:44 +0000233static llvm::cl::opt<bool> OptNoWarnings("w");
234
235static llvm::cl::opt<bool> OptPedantic("pedantic");
236
237static llvm::cl::opt<bool> OptPedanticErrors("pedantic-errors");
238
239// This gets all -W options, including -Werror, -W[no-]system-headers, etc. The
240// driver has stripped off -Wa,foo etc. The driver has also translated -W to
241// -Wextra, so we don't need to worry about it.
242static llvm::cl::list<std::string>
243OptWarnings("W", llvm::cl::Prefix, llvm::cl::ValueOptional);
244
Daniel Dunbardcd40fb2009-11-11 08:13:40 +0000245static llvm::cl::opt<bool>
246PrintSourceRangeInfo("fdiagnostics-print-source-range-info",
247 llvm::cl::desc("Print source range spans in numeric form"));
248
249static llvm::cl::opt<bool>
250PrintDiagnosticOption("fdiagnostics-show-option",
251 llvm::cl::desc("Print diagnostic name with mappable diagnostics"));
252
253static llvm::cl::opt<unsigned>
254MessageLength("fmessage-length",
255 llvm::cl::desc("Format message diagnostics so that they fit "
256 "within N columns or fewer, when possible."),
257 llvm::cl::value_desc("N"));
258
259static llvm::cl::opt<bool>
260PrintColorDiagnostic("fcolor-diagnostics",
261 llvm::cl::desc("Use colors in diagnostics"));
262
Daniel Dunbar4c0e8272009-11-12 07:28:44 +0000263static llvm::cl::opt<bool>
Daniel Dunbar71f5f9f2009-11-19 04:55:06 +0000264SilenceRewriteMacroWarning("Wno-rewrite-macros",
Daniel Dunbar4c0e8272009-11-12 07:28:44 +0000265 llvm::cl::desc("Silence ObjC rewriting warnings"));
266
Daniel Dunbarf996c052009-11-12 23:52:32 +0000267static llvm::cl::opt<bool>
268VerifyDiagnostics("verify",
269 llvm::cl::desc("Verify emitted diagnostics and warnings"));
270
271}
272
Daniel Dunbarf996c052009-11-12 23:52:32 +0000273//===----------------------------------------------------------------------===//
274// Frontend Options
275//===----------------------------------------------------------------------===//
276
277namespace frontendoptions {
278
Daniel Dunbar7fbd42f2009-11-14 22:32:38 +0000279using namespace clang::frontend;
280
Daniel Dunbar4a1f60f2009-11-13 01:02:10 +0000281static llvm::cl::opt<ParsedSourceLocation>
282CodeCompletionAt("code-completion-at",
283 llvm::cl::value_desc("file:line:column"),
284 llvm::cl::desc("Dump code-completion information at a location"));
285
286static llvm::cl::opt<bool>
287CodeCompletionDebugPrinter("code-completion-debug-printer",
288 llvm::cl::desc("Use the \"debug\" code-completion print"),
289 llvm::cl::init(true));
290
291static llvm::cl::opt<bool>
292CodeCompletionWantsMacros("code-completion-macros",
293 llvm::cl::desc("Include macros in code-completion results"));
294
Daniel Dunbarf996c052009-11-12 23:52:32 +0000295static llvm::cl::opt<bool>
296DisableFree("disable-free",
Daniel Dunbar71f5f9f2009-11-19 04:55:06 +0000297 llvm::cl::desc("Disable freeing of memory on exit"));
Daniel Dunbarf996c052009-11-12 23:52:32 +0000298
299static llvm::cl::opt<bool>
300EmptyInputOnly("empty-input-only",
301 llvm::cl::desc("Force running on an empty input file"));
302
Daniel Dunbar27b19dc2009-11-13 02:06:12 +0000303static llvm::cl::opt<FrontendOptions::InputKind>
304InputType("x", llvm::cl::desc("Input language type"),
305 llvm::cl::init(FrontendOptions::IK_None),
306 llvm::cl::values(clEnumValN(FrontendOptions::IK_C, "c", "C"),
307 clEnumValN(FrontendOptions::IK_OpenCL, "cl", "OpenCL C"),
308 clEnumValN(FrontendOptions::IK_CXX, "c++", "C++"),
309 clEnumValN(FrontendOptions::IK_ObjC, "objective-c",
310 "Objective C"),
311 clEnumValN(FrontendOptions::IK_ObjCXX, "objective-c++",
312 "Objective C++"),
313 clEnumValN(FrontendOptions::IK_PreprocessedC,
314 "cpp-output",
315 "Preprocessed C"),
316 clEnumValN(FrontendOptions::IK_Asm,
317 "assembler-with-cpp",
318 "Assembly Source Codde"),
319 clEnumValN(FrontendOptions::IK_PreprocessedCXX,
320 "c++-cpp-output",
321 "Preprocessed C++"),
322 clEnumValN(FrontendOptions::IK_PreprocessedObjC,
323 "objective-c-cpp-output",
324 "Preprocessed Objective C"),
325 clEnumValN(FrontendOptions::IK_PreprocessedObjCXX,
326 "objective-c++-cpp-output",
327 "Preprocessed Objective C++"),
328 clEnumValN(FrontendOptions::IK_C, "c-header",
329 "C header"),
330 clEnumValN(FrontendOptions::IK_ObjC, "objective-c-header",
331 "Objective-C header"),
332 clEnumValN(FrontendOptions::IK_CXX, "c++-header",
333 "C++ header"),
334 clEnumValN(FrontendOptions::IK_ObjCXX,
335 "objective-c++-header",
336 "Objective-C++ header"),
337 clEnumValN(FrontendOptions::IK_AST, "ast",
338 "Clang AST"),
339 clEnumValEnd));
340
Daniel Dunbarf996c052009-11-12 23:52:32 +0000341static llvm::cl::list<std::string>
342InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input files>"));
343
344static llvm::cl::opt<std::string>
345InheritanceViewCls("cxx-inheritance-view",
346 llvm::cl::value_desc("class name"),
347 llvm::cl::desc("View C++ inheritance for a specified class"));
348
Daniel Dunbara5c3d982009-11-12 23:52:56 +0000349static llvm::cl::list<ParsedSourceLocation>
350FixItAtLocations("fixit-at", llvm::cl::value_desc("source-location"),
351 llvm::cl::desc("Perform Fix-It modifications at the given source location"));
352
Daniel Dunbarf996c052009-11-12 23:52:32 +0000353static llvm::cl::opt<std::string>
354OutputFile("o",
355 llvm::cl::value_desc("path"),
356 llvm::cl::desc("Specify output file"));
357
Daniel Dunbard392dd02009-11-15 00:12:04 +0000358static llvm::cl::opt<std::string>
359PluginActionName("plugin",
360 llvm::cl::desc("Use the named plugin action "
361 "(use \"help\" to list available options)"));
362
Daniel Dunbar7fbd42f2009-11-14 22:32:38 +0000363static llvm::cl::opt<ActionKind>
364ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
365 llvm::cl::init(ParseSyntaxOnly),
366 llvm::cl::values(
367 clEnumValN(RunPreprocessorOnly, "Eonly",
368 "Just run preprocessor, no output (for timings)"),
369 clEnumValN(PrintPreprocessedInput, "E",
370 "Run preprocessor, emit preprocessed file"),
371 clEnumValN(DumpRawTokens, "dump-raw-tokens",
372 "Lex file in raw mode and dump raw tokens"),
373 clEnumValN(RunAnalysis, "analyze",
374 "Run static analysis engine"),
375 clEnumValN(DumpTokens, "dump-tokens",
376 "Run preprocessor, dump internal rep of tokens"),
377 clEnumValN(ParseNoop, "parse-noop",
378 "Run parser with noop callbacks (for timings)"),
379 clEnumValN(ParseSyntaxOnly, "fsyntax-only",
380 "Run parser and perform semantic analysis"),
381 clEnumValN(FixIt, "fixit",
382 "Apply fix-it advice to the input source"),
383 clEnumValN(ParsePrintCallbacks, "parse-print-callbacks",
384 "Run parser and print each callback invoked"),
385 clEnumValN(EmitHTML, "emit-html",
386 "Output input source as HTML"),
387 clEnumValN(ASTPrint, "ast-print",
388 "Build ASTs and then pretty-print them"),
389 clEnumValN(ASTPrintXML, "ast-print-xml",
390 "Build ASTs and then print them in XML format"),
391 clEnumValN(ASTDump, "ast-dump",
392 "Build ASTs and then debug dump them"),
393 clEnumValN(ASTView, "ast-view",
394 "Build ASTs and view them with GraphViz"),
395 clEnumValN(PrintDeclContext, "print-decl-contexts",
396 "Print DeclContexts and their Decls"),
397 clEnumValN(DumpRecordLayouts, "dump-record-layouts",
398 "Dump record layout information"),
399 clEnumValN(GeneratePTH, "emit-pth",
400 "Generate pre-tokenized header file"),
401 clEnumValN(GeneratePCH, "emit-pch",
402 "Generate pre-compiled header file"),
403 clEnumValN(EmitAssembly, "S",
404 "Emit native assembly code"),
405 clEnumValN(EmitLLVM, "emit-llvm",
406 "Build ASTs then convert to LLVM, emit .ll file"),
407 clEnumValN(EmitBC, "emit-llvm-bc",
408 "Build ASTs then convert to LLVM, emit .bc file"),
409 clEnumValN(EmitLLVMOnly, "emit-llvm-only",
410 "Build ASTs and convert to LLVM, discarding output"),
411 clEnumValN(RewriteTest, "rewrite-test",
412 "Rewriter playground"),
413 clEnumValN(RewriteObjC, "rewrite-objc",
414 "Rewrite ObjC into C (code rewriter example)"),
415 clEnumValN(RewriteMacros, "rewrite-macros",
416 "Expand macros without full preprocessing"),
417 clEnumValN(RewriteBlocks, "rewrite-blocks",
418 "Rewrite Blocks to C"),
419 clEnumValEnd));
420
Daniel Dunbarf996c052009-11-12 23:52:32 +0000421static llvm::cl::opt<bool>
422RelocatablePCH("relocatable-pch",
423 llvm::cl::desc("Whether to build a relocatable precompiled "
424 "header"));
425static llvm::cl::opt<bool>
426Stats("print-stats",
427 llvm::cl::desc("Print performance metrics and statistics"));
428
429static llvm::cl::opt<bool>
430TimeReport("ftime-report",
431 llvm::cl::desc("Print the amount of time each "
432 "phase of compilation takes"));
433
Daniel Dunbardcd40fb2009-11-11 08:13:40 +0000434}
435
436//===----------------------------------------------------------------------===//
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000437// Language Options
438//===----------------------------------------------------------------------===//
439
440namespace langoptions {
441
442static llvm::cl::opt<bool>
443AllowBuiltins("fbuiltin", llvm::cl::init(true),
444 llvm::cl::desc("Disable implicit builtin knowledge of functions"));
445
446static llvm::cl::opt<bool>
Daniel Dunbar71f5f9f2009-11-19 04:55:06 +0000447AltiVec("faltivec", llvm::cl::desc("Enable AltiVec vector initializer syntax"));
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000448
449static llvm::cl::opt<bool>
450AccessControl("faccess-control",
451 llvm::cl::desc("Enable C++ access control"));
452
453static llvm::cl::opt<bool>
454CharIsSigned("fsigned-char",
455 llvm::cl::desc("Force char to be a signed/unsigned type"));
456
457static llvm::cl::opt<bool>
458DollarsInIdents("fdollars-in-identifiers",
459 llvm::cl::desc("Allow '$' in identifiers"));
460
461static llvm::cl::opt<bool>
462EmitAllDecls("femit-all-decls",
463 llvm::cl::desc("Emit all declarations, even if unused"));
464
465static llvm::cl::opt<bool>
466EnableBlocks("fblocks", llvm::cl::desc("enable the 'blocks' language feature"));
467
468static llvm::cl::opt<bool>
469EnableHeinousExtensions("fheinous-gnu-extensions",
470 llvm::cl::desc("enable GNU extensions that you really really shouldn't use"),
471 llvm::cl::ValueDisallowed, llvm::cl::Hidden);
472
473static llvm::cl::opt<bool>
474Exceptions("fexceptions",
475 llvm::cl::desc("Enable support for exception handling"));
476
477static llvm::cl::opt<bool>
478Freestanding("ffreestanding",
479 llvm::cl::desc("Assert that the compilation takes place in a "
480 "freestanding environment"));
481
482static llvm::cl::opt<bool>
483GNURuntime("fgnu-runtime",
484 llvm::cl::desc("Generate output compatible with the standard GNU "
485 "Objective-C runtime"));
486
487/// LangStds - Language standards we support.
488enum LangStds {
489 lang_unspecified,
490 lang_c89, lang_c94, lang_c99,
491 lang_gnu89, lang_gnu99,
492 lang_cxx98, lang_gnucxx98,
493 lang_cxx0x, lang_gnucxx0x
494};
495static llvm::cl::opt<LangStds>
496LangStd("std", llvm::cl::desc("Language standard to compile for"),
497 llvm::cl::init(lang_unspecified),
498 llvm::cl::values(clEnumValN(lang_c89, "c89", "ISO C 1990"),
499 clEnumValN(lang_c89, "c90", "ISO C 1990"),
500 clEnumValN(lang_c89, "iso9899:1990", "ISO C 1990"),
501 clEnumValN(lang_c94, "iso9899:199409",
502 "ISO C 1990 with amendment 1"),
503 clEnumValN(lang_c99, "c99", "ISO C 1999"),
504 clEnumValN(lang_c99, "c9x", "ISO C 1999"),
505 clEnumValN(lang_c99, "iso9899:1999", "ISO C 1999"),
506 clEnumValN(lang_c99, "iso9899:199x", "ISO C 1999"),
507 clEnumValN(lang_gnu89, "gnu89",
508 "ISO C 1990 with GNU extensions"),
509 clEnumValN(lang_gnu99, "gnu99",
510 "ISO C 1999 with GNU extensions (default for C)"),
511 clEnumValN(lang_gnu99, "gnu9x",
512 "ISO C 1999 with GNU extensions"),
513 clEnumValN(lang_cxx98, "c++98",
514 "ISO C++ 1998 with amendments"),
515 clEnumValN(lang_gnucxx98, "gnu++98",
516 "ISO C++ 1998 with amendments and GNU "
517 "extensions (default for C++)"),
518 clEnumValN(lang_cxx0x, "c++0x",
519 "Upcoming ISO C++ 200x with amendments"),
520 clEnumValN(lang_gnucxx0x, "gnu++0x",
521 "Upcoming ISO C++ 200x with amendments and GNU "
522 "extensions"),
523 clEnumValEnd));
524
525static llvm::cl::opt<bool>
526MSExtensions("fms-extensions",
527 llvm::cl::desc("Accept some non-standard constructs used in "
528 "Microsoft header files "));
529
530static llvm::cl::opt<std::string>
531MainFileName("main-file-name",
532 llvm::cl::desc("Main file name to use for debug info"));
533
534static llvm::cl::opt<bool>
535MathErrno("fmath-errno", llvm::cl::init(true),
536 llvm::cl::desc("Require math functions to respect errno"));
537
538static llvm::cl::opt<bool>
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000539NoElideConstructors("fno-elide-constructors",
540 llvm::cl::desc("Disable C++ copy constructor elision"));
541
542static llvm::cl::opt<bool>
543NoLaxVectorConversions("fno-lax-vector-conversions",
544 llvm::cl::desc("Disallow implicit conversions between "
545 "vectors with a different number of "
546 "elements or different element types"));
547
548
549static llvm::cl::opt<bool>
550NoOperatorNames("fno-operator-names",
551 llvm::cl::desc("Do not treat C++ operator name keywords as "
552 "synonyms for operators"));
553
554static llvm::cl::opt<std::string>
555ObjCConstantStringClass("fconstant-string-class",
556 llvm::cl::value_desc("class name"),
557 llvm::cl::desc("Specify the class to use for constant "
558 "Objective-C string objects."));
559
560static llvm::cl::opt<bool>
561ObjCEnableGC("fobjc-gc",
562 llvm::cl::desc("Enable Objective-C garbage collection"));
563
564static llvm::cl::opt<bool>
565ObjCExclusiveGC("fobjc-gc-only",
566 llvm::cl::desc("Use GC exclusively for Objective-C related "
567 "memory management"));
568
569static llvm::cl::opt<bool>
570ObjCEnableGCBitmapPrint("print-ivar-layout",
571 llvm::cl::desc("Enable Objective-C Ivar layout bitmap print trace"));
572
573static llvm::cl::opt<bool>
574ObjCNonFragileABI("fobjc-nonfragile-abi",
575 llvm::cl::desc("enable objective-c's nonfragile abi"));
576
577static llvm::cl::opt<bool>
578OverflowChecking("ftrapv",
Daniel Dunbar71f5f9f2009-11-19 04:55:06 +0000579 llvm::cl::desc("Trap on integer overflow"));
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000580
581static llvm::cl::opt<unsigned>
582PICLevel("pic-level", llvm::cl::desc("Value for __PIC__"));
583
584static llvm::cl::opt<bool>
Daniel Dunbar71f5f9f2009-11-19 04:55:06 +0000585PThread("pthread", llvm::cl::desc("Support POSIX threads in generated code"));
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000586
587static llvm::cl::opt<bool>
588PascalStrings("fpascal-strings",
589 llvm::cl::desc("Recognize and construct Pascal-style "
590 "string literals"));
591
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000592static llvm::cl::opt<bool>
593Rtti("frtti", llvm::cl::init(true),
594 llvm::cl::desc("Enable generation of rtti information"));
595
596static llvm::cl::opt<bool>
597ShortWChar("fshort-wchar",
598 llvm::cl::desc("Force wchar_t to be a short unsigned int"));
599
600static llvm::cl::opt<bool>
601StaticDefine("static-define", llvm::cl::desc("Should __STATIC__ be defined"));
602
603static llvm::cl::opt<int>
604StackProtector("stack-protector",
605 llvm::cl::desc("Enable stack protectors"),
606 llvm::cl::init(-1));
607
608static llvm::cl::opt<LangOptions::VisibilityMode>
609SymbolVisibility("fvisibility",
610 llvm::cl::desc("Set the default symbol visibility:"),
611 llvm::cl::init(LangOptions::Default),
612 llvm::cl::values(clEnumValN(LangOptions::Default, "default",
613 "Use default symbol visibility"),
614 clEnumValN(LangOptions::Hidden, "hidden",
615 "Use hidden symbol visibility"),
616 clEnumValN(LangOptions::Protected,"protected",
617 "Use protected symbol visibility"),
618 clEnumValEnd));
619
620static llvm::cl::opt<unsigned>
621TemplateDepth("ftemplate-depth", llvm::cl::init(99),
622 llvm::cl::desc("Maximum depth of recursive template "
623 "instantiation"));
624
625static llvm::cl::opt<bool>
626Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences"));
627
628static llvm::cl::opt<bool>
629WritableStrings("fwritable-strings",
630 llvm::cl::desc("Store string literals as writable data"));
631
632}
633
634//===----------------------------------------------------------------------===//
Daniel Dunbar999215c2009-11-11 06:10:03 +0000635// General Preprocessor Options
636//===----------------------------------------------------------------------===//
637
638namespace preprocessoroptions {
639
640static llvm::cl::list<std::string>
641D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
642 llvm::cl::desc("Predefine the specified macro"));
643
644static llvm::cl::list<std::string>
645ImplicitIncludes("include", llvm::cl::value_desc("file"),
646 llvm::cl::desc("Include file before parsing"));
647static llvm::cl::list<std::string>
648ImplicitMacroIncludes("imacros", llvm::cl::value_desc("file"),
649 llvm::cl::desc("Include macros from file before parsing"));
650
651static llvm::cl::opt<std::string>
652ImplicitIncludePCH("include-pch", llvm::cl::value_desc("file"),
653 llvm::cl::desc("Include precompiled header file"));
654
655static llvm::cl::opt<std::string>
656ImplicitIncludePTH("include-pth", llvm::cl::value_desc("file"),
657 llvm::cl::desc("Include file before parsing"));
658
Daniel Dunbar29403032009-11-12 02:53:59 +0000659static llvm::cl::opt<std::string>
660TokenCache("token-cache", llvm::cl::value_desc("path"),
661 llvm::cl::desc("Use specified token cache file"));
662
Daniel Dunbar999215c2009-11-11 06:10:03 +0000663static llvm::cl::list<std::string>
664U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
665 llvm::cl::desc("Undefine the specified macro"));
666
667static llvm::cl::opt<bool>
668UndefMacros("undef", llvm::cl::value_desc("macro"),
669 llvm::cl::desc("undef all system defines"));
670
671}
672
673//===----------------------------------------------------------------------===//
Daniel Dunbarf527a122009-11-11 08:13:32 +0000674// Header Search Options
675//===----------------------------------------------------------------------===//
676
677namespace headersearchoptions {
678
679static llvm::cl::opt<bool>
680nostdinc("nostdinc", llvm::cl::desc("Disable standard #include directories"));
681
682static llvm::cl::opt<bool>
683nobuiltininc("nobuiltininc",
684 llvm::cl::desc("Disable builtin #include directories"));
685
686// Various command line options. These four add directories to each chain.
687static llvm::cl::list<std::string>
688F_dirs("F", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
689 llvm::cl::desc("Add directory to framework include search path"));
690
691static llvm::cl::list<std::string>
692I_dirs("I", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
693 llvm::cl::desc("Add directory to include search path"));
694
695static llvm::cl::list<std::string>
696idirafter_dirs("idirafter", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
697 llvm::cl::desc("Add directory to AFTER include search path"));
698
699static llvm::cl::list<std::string>
700iquote_dirs("iquote", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
701 llvm::cl::desc("Add directory to QUOTE include search path"));
702
703static llvm::cl::list<std::string>
704isystem_dirs("isystem", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
705 llvm::cl::desc("Add directory to SYSTEM include search path"));
706
707// These handle -iprefix/-iwithprefix/-iwithprefixbefore.
708static llvm::cl::list<std::string>
709iprefix_vals("iprefix", llvm::cl::value_desc("prefix"), llvm::cl::Prefix,
710 llvm::cl::desc("Set the -iwithprefix/-iwithprefixbefore prefix"));
711static llvm::cl::list<std::string>
712iwithprefix_vals("iwithprefix", llvm::cl::value_desc("dir"), llvm::cl::Prefix,
713 llvm::cl::desc("Set directory to SYSTEM include search path with prefix"));
714static llvm::cl::list<std::string>
715iwithprefixbefore_vals("iwithprefixbefore", llvm::cl::value_desc("dir"),
716 llvm::cl::Prefix,
717 llvm::cl::desc("Set directory to include search path with prefix"));
718
719static llvm::cl::opt<std::string>
720isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::init("/"),
721 llvm::cl::desc("Set the system root directory (usually /)"));
722
Daniel Dunbareb515862009-11-12 23:52:46 +0000723static llvm::cl::opt<bool>
724Verbose("v", llvm::cl::desc("Enable verbose output"));
725
Daniel Dunbarf527a122009-11-11 08:13:32 +0000726}
727
728//===----------------------------------------------------------------------===//
Daniel Dunbar22bdabf2009-11-11 10:07:44 +0000729// Preprocessed Output Options
730//===----------------------------------------------------------------------===//
731
732namespace preprocessoroutputoptions {
733
734static llvm::cl::opt<bool>
735DisableLineMarkers("P", llvm::cl::desc("Disable linemarker output in -E mode"));
736
737static llvm::cl::opt<bool>
738EnableCommentOutput("C", llvm::cl::desc("Enable comment output in -E mode"));
739
740static llvm::cl::opt<bool>
741EnableMacroCommentOutput("CC",
742 llvm::cl::desc("Enable comment output in -E mode, "
743 "even from macro expansions"));
744static llvm::cl::opt<bool>
745DumpMacros("dM", llvm::cl::desc("Print macro definitions in -E mode instead of"
746 " normal output"));
747static llvm::cl::opt<bool>
748DumpDefines("dD", llvm::cl::desc("Print macro definitions in -E mode in "
749 "addition to normal output"));
750
751}
Daniel Dunbarb9bbd542009-11-15 06:48:46 +0000752//===----------------------------------------------------------------------===//
753// Target Options
754//===----------------------------------------------------------------------===//
755
756namespace targetoptions {
757
758static llvm::cl::opt<std::string>
759TargetABI("target-abi",
760 llvm::cl::desc("Target a particular ABI type"));
761
762static llvm::cl::opt<std::string>
763TargetCPU("mcpu",
764 llvm::cl::desc("Target a specific cpu type (-mcpu=help for details)"));
765
766static llvm::cl::list<std::string>
767TargetFeatures("target-feature", llvm::cl::desc("Target specific attributes"));
768
769static llvm::cl::opt<std::string>
770TargetTriple("triple",
771 llvm::cl::desc("Specify target triple (e.g. i686-apple-darwin9)"));
772
773}
Daniel Dunbar22bdabf2009-11-11 10:07:44 +0000774
775//===----------------------------------------------------------------------===//
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000776// Option Object Construction
777//===----------------------------------------------------------------------===//
778
Daniel Dunbar19b04ff2009-11-17 05:05:08 +0000779void clang::InitializeAnalyzerOptions(AnalyzerOptions &Opts) {
780 using namespace analyzeroptions;
781 Opts.AnalysisList = AnalysisList;
782 Opts.AnalysisStoreOpt = AnalysisStoreOpt;
783 Opts.AnalysisConstraintsOpt = AnalysisConstraintsOpt;
784 Opts.AnalysisDiagOpt = AnalysisDiagOpt;
785 Opts.VisualizeEGDot = VisualizeEGDot;
786 Opts.VisualizeEGUbi = VisualizeEGUbi;
787 Opts.AnalyzeAll = AnalyzeAll;
788 Opts.AnalyzerDisplayProgress = AnalyzerDisplayProgress;
789 Opts.PurgeDead = PurgeDead;
790 Opts.EagerlyAssume = EagerlyAssume;
791 Opts.AnalyzeSpecificFunction = AnalyzeSpecificFunction;
792 Opts.EnableExperimentalChecks = AnalyzerExperimentalChecks;
793 Opts.EnableExperimentalInternalChecks = AnalyzerExperimentalInternalChecks;
794 Opts.TrimGraph = TrimGraph;
795}
796
Daniel Dunbar77a9d2b2009-11-16 22:38:14 +0000797void clang::InitializeCodeGenOptions(CodeGenOptions &Opts,
798 const LangOptions &Lang,
799 bool TimePasses) {
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000800 using namespace codegenoptions;
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000801
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000802 // -Os implies -O2
803 Opts.OptimizationLevel = OptSize ? 2 : OptLevel;
804
805 // We must always run at least the always inlining pass.
Chandler Carruthbc55fe22009-11-12 17:24:48 +0000806 Opts.Inlining = (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining
807 : CodeGenOptions::OnlyAlwaysInlining;
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000808
Daniel Dunbar979586e2009-11-11 09:38:56 +0000809 Opts.DebugInfo = GenerateDebugInfo;
810 Opts.DisableLLVMOpts = DisableLLVMOptimizations;
811 Opts.DisableRedZone = DisableRedZone;
812 Opts.MergeAllConstants = !NoMergeConstants;
813 Opts.NoCommon = NoCommon;
814 Opts.NoImplicitFloat = NoImplicitFloat;
815 Opts.OptimizeSize = OptSize;
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000816 Opts.SimplifyLibCalls = 1;
Daniel Dunbar979586e2009-11-11 09:38:56 +0000817 Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize);
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000818
Daniel Dunbar77a9d2b2009-11-16 22:38:14 +0000819 // FIXME: Eliminate this dependency?
820 if (Lang.NoBuiltin)
821 Opts.SimplifyLibCalls = 0;
822 if (Lang.CPlusPlus)
823 Opts.NoCommon = 1;
824 Opts.TimePasses = TimePasses;
825
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000826#ifdef NDEBUG
827 Opts.VerifyModule = 0;
828#endif
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000829}
Daniel Dunbar999215c2009-11-11 06:10:03 +0000830
Daniel Dunbar89d1fdf2009-11-11 21:43:12 +0000831void clang::InitializeDependencyOutputOptions(DependencyOutputOptions &Opts) {
832 using namespace dependencyoutputoptions;
833
834 Opts.OutputFile = DependencyFile;
Daniel Dunbarf996c052009-11-12 23:52:32 +0000835 Opts.Targets = DependencyTargets;
Daniel Dunbar89d1fdf2009-11-11 21:43:12 +0000836 Opts.IncludeSystemHeaders = DependenciesIncludeSystemHeaders;
837 Opts.UsePhonyTargets = PhonyDependencyTarget;
838}
839
Daniel Dunbardcd40fb2009-11-11 08:13:40 +0000840void clang::InitializeDiagnosticOptions(DiagnosticOptions &Opts) {
841 using namespace diagnosticoptions;
842
Daniel Dunbarf996c052009-11-12 23:52:32 +0000843 Opts.Warnings = OptWarnings;
Daniel Dunbar8fd69a02009-11-12 07:28:21 +0000844 Opts.DumpBuildInformation = DumpBuildInformation;
Daniel Dunbar4c0e8272009-11-12 07:28:44 +0000845 Opts.IgnoreWarnings = OptNoWarnings;
Daniel Dunbardcd40fb2009-11-11 08:13:40 +0000846 Opts.MessageLength = MessageLength;
Daniel Dunbar4c0e8272009-11-12 07:28:44 +0000847 Opts.NoRewriteMacros = SilenceRewriteMacroWarning;
848 Opts.Pedantic = OptPedantic;
849 Opts.PedanticErrors = OptPedanticErrors;
Daniel Dunbar8fd69a02009-11-12 07:28:21 +0000850 Opts.ShowCarets = !NoCaretDiagnostics;
851 Opts.ShowColors = PrintColorDiagnostic;
852 Opts.ShowColumn = !NoShowColumn;
853 Opts.ShowFixits = !NoDiagnosticsFixIt;
854 Opts.ShowLocation = !NoShowLocation;
855 Opts.ShowOptionNames = PrintDiagnosticOption;
856 Opts.ShowSourceRanges = PrintSourceRangeInfo;
Daniel Dunbarf996c052009-11-12 23:52:32 +0000857 Opts.VerifyDiagnostics = VerifyDiagnostics;
858}
859
860void clang::InitializeFrontendOptions(FrontendOptions &Opts) {
861 using namespace frontendoptions;
862
Daniel Dunbard392dd02009-11-15 00:12:04 +0000863 // Select program action.
864 Opts.ProgramAction = ProgAction;
865 if (PluginActionName.getPosition()) {
866 Opts.ProgramAction = frontend::PluginAction;
867 Opts.ActionName = PluginActionName;
868 }
869
Daniel Dunbar4a1f60f2009-11-13 01:02:10 +0000870 Opts.CodeCompletionAt = CodeCompletionAt;
871 Opts.DebugCodeCompletionPrinter = CodeCompletionDebugPrinter;
Daniel Dunbarf996c052009-11-12 23:52:32 +0000872 Opts.DisableFree = DisableFree;
873 Opts.EmptyInputOnly = EmptyInputOnly;
Daniel Dunbara5c3d982009-11-12 23:52:56 +0000874 Opts.FixItLocations = FixItAtLocations;
Daniel Dunbarf996c052009-11-12 23:52:32 +0000875 Opts.OutputFile = OutputFile;
Daniel Dunbar4a1f60f2009-11-13 01:02:10 +0000876 Opts.RelocatablePCH = RelocatablePCH;
877 Opts.ShowMacrosInCodeCompletion = CodeCompletionWantsMacros;
878 Opts.ShowStats = Stats;
879 Opts.ShowTimers = TimeReport;
Daniel Dunbarf996c052009-11-12 23:52:32 +0000880 Opts.ViewClassInheritance = InheritanceViewCls;
881
882 // '-' is the default input if none is given.
Daniel Dunbar27b19dc2009-11-13 02:06:12 +0000883 if (InputFilenames.empty()) {
884 FrontendOptions::InputKind IK = InputType;
885 if (IK == FrontendOptions::IK_None) IK = FrontendOptions::IK_C;
886 Opts.Inputs.push_back(std::make_pair(IK, "-"));
887 } else {
888 for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
889 FrontendOptions::InputKind IK = InputType;
890 llvm::StringRef Ext =
891 llvm::StringRef(InputFilenames[i]).rsplit('.').second;
892 if (IK == FrontendOptions::IK_None)
893 IK = FrontendOptions::getInputKindForExtension(Ext);
894 Opts.Inputs.push_back(std::make_pair(IK, InputFilenames[i]));
Daniel Dunbar27b19dc2009-11-13 02:06:12 +0000895 }
896 }
Daniel Dunbardcd40fb2009-11-11 08:13:40 +0000897}
898
Daniel Dunbarf527a122009-11-11 08:13:32 +0000899void clang::InitializeHeaderSearchOptions(HeaderSearchOptions &Opts,
Daniel Dunbar24347f72009-11-16 22:38:40 +0000900 llvm::StringRef BuiltinIncludePath) {
Daniel Dunbarf527a122009-11-11 08:13:32 +0000901 using namespace headersearchoptions;
902
903 Opts.Sysroot = isysroot;
904 Opts.Verbose = Verbose;
905
906 // Handle -I... and -F... options, walking the lists in parallel.
907 unsigned Iidx = 0, Fidx = 0;
908 while (Iidx < I_dirs.size() && Fidx < F_dirs.size()) {
909 if (I_dirs.getPosition(Iidx) < F_dirs.getPosition(Fidx)) {
Daniel Dunbar92881db2009-11-17 05:04:15 +0000910 Opts.AddPath(I_dirs[Iidx], frontend::Angled, true, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000911 ++Iidx;
912 } else {
Daniel Dunbar92881db2009-11-17 05:04:15 +0000913 Opts.AddPath(F_dirs[Fidx], frontend::Angled, true, true);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000914 ++Fidx;
915 }
916 }
917
918 // Consume what's left from whatever list was longer.
919 for (; Iidx != I_dirs.size(); ++Iidx)
Daniel Dunbar92881db2009-11-17 05:04:15 +0000920 Opts.AddPath(I_dirs[Iidx], frontend::Angled, true, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000921 for (; Fidx != F_dirs.size(); ++Fidx)
Daniel Dunbar92881db2009-11-17 05:04:15 +0000922 Opts.AddPath(F_dirs[Fidx], frontend::Angled, true, true);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000923
924 // Handle -idirafter... options.
925 for (unsigned i = 0, e = idirafter_dirs.size(); i != e; ++i)
Daniel Dunbar92881db2009-11-17 05:04:15 +0000926 Opts.AddPath(idirafter_dirs[i], frontend::After, true, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000927
928 // Handle -iquote... options.
929 for (unsigned i = 0, e = iquote_dirs.size(); i != e; ++i)
Daniel Dunbar92881db2009-11-17 05:04:15 +0000930 Opts.AddPath(iquote_dirs[i], frontend::Quoted, true, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000931
932 // Handle -isystem... options.
933 for (unsigned i = 0, e = isystem_dirs.size(); i != e; ++i)
Daniel Dunbar92881db2009-11-17 05:04:15 +0000934 Opts.AddPath(isystem_dirs[i], frontend::System, true, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000935
936 // Walk the -iprefix/-iwithprefix/-iwithprefixbefore argument lists in
937 // parallel, processing the values in order of occurance to get the right
938 // prefixes.
939 {
940 std::string Prefix = ""; // FIXME: this isn't the correct default prefix.
941 unsigned iprefix_idx = 0;
942 unsigned iwithprefix_idx = 0;
943 unsigned iwithprefixbefore_idx = 0;
944 bool iprefix_done = iprefix_vals.empty();
945 bool iwithprefix_done = iwithprefix_vals.empty();
946 bool iwithprefixbefore_done = iwithprefixbefore_vals.empty();
947 while (!iprefix_done || !iwithprefix_done || !iwithprefixbefore_done) {
948 if (!iprefix_done &&
949 (iwithprefix_done ||
950 iprefix_vals.getPosition(iprefix_idx) <
951 iwithprefix_vals.getPosition(iwithprefix_idx)) &&
952 (iwithprefixbefore_done ||
953 iprefix_vals.getPosition(iprefix_idx) <
954 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
955 Prefix = iprefix_vals[iprefix_idx];
956 ++iprefix_idx;
957 iprefix_done = iprefix_idx == iprefix_vals.size();
958 } else if (!iwithprefix_done &&
959 (iwithprefixbefore_done ||
960 iwithprefix_vals.getPosition(iwithprefix_idx) <
961 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
962 Opts.AddPath(Prefix+iwithprefix_vals[iwithprefix_idx],
Daniel Dunbar92881db2009-11-17 05:04:15 +0000963 frontend::System, false, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000964 ++iwithprefix_idx;
965 iwithprefix_done = iwithprefix_idx == iwithprefix_vals.size();
966 } else {
967 Opts.AddPath(Prefix+iwithprefixbefore_vals[iwithprefixbefore_idx],
Daniel Dunbar92881db2009-11-17 05:04:15 +0000968 frontend::Angled, false, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000969 ++iwithprefixbefore_idx;
970 iwithprefixbefore_done =
971 iwithprefixbefore_idx == iwithprefixbefore_vals.size();
972 }
973 }
974 }
975
976 // Add CPATH environment paths.
977 if (const char *Env = getenv("CPATH"))
978 Opts.EnvIncPath = Env;
979
980 // Add language specific environment paths.
Daniel Dunbar24347f72009-11-16 22:38:40 +0000981 if (const char *Env = getenv("OBJCPLUS_INCLUDE_PATH"))
982 Opts.ObjCXXEnvIncPath = Env;
983 if (const char *Env = getenv("CPLUS_INCLUDE_PATH"))
984 Opts.CXXEnvIncPath = Env;
985 if (const char *Env = getenv("OBJC_INCLUDE_PATH"))
986 Opts.CEnvIncPath = Env;
987 if (const char *Env = getenv("C_INCLUDE_PATH"))
988 Opts.CEnvIncPath = Env;
Daniel Dunbarf527a122009-11-11 08:13:32 +0000989
990 if (!nobuiltininc)
991 Opts.BuiltinIncludePath = BuiltinIncludePath;
992
993 Opts.UseStandardIncludes = !nostdinc;
994}
995
Daniel Dunbar999215c2009-11-11 06:10:03 +0000996void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) {
997 using namespace preprocessoroptions;
998
Daniel Dunbard6ea9022009-11-17 05:52:41 +0000999 Opts.ImplicitPCHInclude = ImplicitIncludePCH;
1000 Opts.ImplicitPTHInclude = ImplicitIncludePTH;
Daniel Dunbar999215c2009-11-11 06:10:03 +00001001
Daniel Dunbar29403032009-11-12 02:53:59 +00001002 // Select the token cache file, we don't support more than one currently so we
1003 // can't have both an implicit-pth and a token cache file.
1004 if (TokenCache.getPosition() && ImplicitIncludePTH.getPosition()) {
1005 // FIXME: Don't fail like this.
1006 fprintf(stderr, "error: cannot use both -token-cache and -include-pth "
1007 "options\n");
1008 exit(1);
1009 }
1010 if (TokenCache.getPosition())
Daniel Dunbard6ea9022009-11-17 05:52:41 +00001011 Opts.TokenCache = TokenCache;
Daniel Dunbar29403032009-11-12 02:53:59 +00001012 else
Daniel Dunbard6ea9022009-11-17 05:52:41 +00001013 Opts.TokenCache = ImplicitIncludePTH;
Daniel Dunbar29403032009-11-12 02:53:59 +00001014
Daniel Dunbar999215c2009-11-11 06:10:03 +00001015 // Use predefines?
Daniel Dunbard6ea9022009-11-17 05:52:41 +00001016 Opts.UsePredefines = !UndefMacros;
Daniel Dunbar999215c2009-11-11 06:10:03 +00001017
1018 // Add macros from the command line.
1019 unsigned d = 0, D = D_macros.size();
1020 unsigned u = 0, U = U_macros.size();
1021 while (d < D || u < U) {
1022 if (u == U || (d < D && D_macros.getPosition(d) < U_macros.getPosition(u)))
1023 Opts.addMacroDef(D_macros[d++]);
1024 else
1025 Opts.addMacroUndef(U_macros[u++]);
1026 }
1027
1028 // If -imacros are specified, include them now. These are processed before
1029 // any -include directives.
1030 for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i)
Daniel Dunbard6ea9022009-11-17 05:52:41 +00001031 Opts.MacroIncludes.push_back(ImplicitMacroIncludes[i]);
Daniel Dunbar999215c2009-11-11 06:10:03 +00001032
1033 // Add the ordered list of -includes, sorting in the implicit include options
1034 // at the appropriate location.
1035 llvm::SmallVector<std::pair<unsigned, std::string*>, 8> OrderedPaths;
1036 std::string OriginalFile;
1037
1038 if (!ImplicitIncludePTH.empty())
1039 OrderedPaths.push_back(std::make_pair(ImplicitIncludePTH.getPosition(),
1040 &ImplicitIncludePTH));
1041 if (!ImplicitIncludePCH.empty()) {
1042 OriginalFile = PCHReader::getOriginalSourceFile(ImplicitIncludePCH);
1043 // FIXME: Don't fail like this.
1044 if (OriginalFile.empty())
1045 exit(1);
1046 OrderedPaths.push_back(std::make_pair(ImplicitIncludePCH.getPosition(),
1047 &OriginalFile));
1048 }
1049 for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i)
1050 OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i),
1051 &ImplicitIncludes[i]));
1052 llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end());
1053
1054 for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i)
Daniel Dunbard6ea9022009-11-17 05:52:41 +00001055 Opts.Includes.push_back(*OrderedPaths[i].second);
Daniel Dunbar999215c2009-11-11 06:10:03 +00001056}
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001057
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001058void clang::InitializeLangOptions(LangOptions &Options,
1059 FrontendOptions::InputKind IK,
Daniel Dunbar77a9d2b2009-11-16 22:38:14 +00001060 TargetInfo &Target) {
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001061 using namespace langoptions;
1062
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001063
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001064 switch (IK) {
1065 case FrontendOptions::IK_None:
1066 case FrontendOptions::IK_AST:
1067 assert(0 && "Invalid input kind!");
1068 case FrontendOptions::IK_Asm:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001069 Options.AsmPreprocessor = 1;
1070 // FALLTHROUGH
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001071 case FrontendOptions::IK_PreprocessedC:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001072 // FALLTHROUGH
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001073 case FrontendOptions::IK_C:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001074 // Do nothing.
1075 break;
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001076 case FrontendOptions::IK_PreprocessedCXX:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001077 // FALLTHROUGH
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001078 case FrontendOptions::IK_CXX:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001079 Options.CPlusPlus = 1;
1080 break;
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001081 case FrontendOptions::IK_PreprocessedObjC:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001082 // FALLTHROUGH
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001083 case FrontendOptions::IK_ObjC:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001084 Options.ObjC1 = Options.ObjC2 = 1;
1085 break;
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001086 case FrontendOptions::IK_PreprocessedObjCXX:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001087 // FALLTHROUGH
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001088 case FrontendOptions::IK_ObjCXX:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001089 Options.ObjC1 = Options.ObjC2 = 1;
1090 Options.CPlusPlus = 1;
1091 break;
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001092 case FrontendOptions::IK_OpenCL:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001093 Options.OpenCL = 1;
1094 Options.AltiVec = 1;
1095 Options.CXXOperatorNames = 1;
1096 Options.LaxVectorConversions = 1;
1097 break;
1098 }
1099
1100 if (ObjCExclusiveGC)
1101 Options.setGCMode(LangOptions::GCOnly);
1102 else if (ObjCEnableGC)
1103 Options.setGCMode(LangOptions::HybridGC);
1104
1105 if (ObjCEnableGCBitmapPrint)
1106 Options.ObjCGCBitmapPrint = 1;
1107
1108 if (AltiVec)
1109 Options.AltiVec = 1;
1110
1111 if (PThread)
1112 Options.POSIXThreads = 1;
1113
1114 Options.setVisibilityMode(SymbolVisibility);
1115 Options.OverflowChecking = OverflowChecking;
1116
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001117 if (LangStd == lang_unspecified) {
1118 // Based on the base language, pick one.
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001119 switch (IK) {
1120 case FrontendOptions::IK_None:
1121 case FrontendOptions::IK_AST:
1122 assert(0 && "Invalid input kind!");
1123 case FrontendOptions::IK_OpenCL:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001124 LangStd = lang_c99;
1125 break;
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001126 case FrontendOptions::IK_Asm:
1127 case FrontendOptions::IK_C:
1128 case FrontendOptions::IK_PreprocessedC:
1129 case FrontendOptions::IK_ObjC:
1130 case FrontendOptions::IK_PreprocessedObjC:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001131 LangStd = lang_gnu99;
1132 break;
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001133 case FrontendOptions::IK_CXX:
1134 case FrontendOptions::IK_PreprocessedCXX:
1135 case FrontendOptions::IK_ObjCXX:
1136 case FrontendOptions::IK_PreprocessedObjCXX:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001137 LangStd = lang_gnucxx98;
1138 break;
1139 }
1140 }
1141
1142 switch (LangStd) {
1143 default: assert(0 && "Unknown language standard!");
1144
1145 // Fall through from newer standards to older ones. This isn't really right.
1146 // FIXME: Enable specifically the right features based on the language stds.
1147 case lang_gnucxx0x:
1148 case lang_cxx0x:
1149 Options.CPlusPlus0x = 1;
1150 // FALL THROUGH
1151 case lang_gnucxx98:
1152 case lang_cxx98:
1153 Options.CPlusPlus = 1;
1154 Options.CXXOperatorNames = !NoOperatorNames;
1155 // FALL THROUGH.
1156 case lang_gnu99:
1157 case lang_c99:
1158 Options.C99 = 1;
1159 Options.HexFloats = 1;
1160 // FALL THROUGH.
1161 case lang_gnu89:
1162 Options.BCPLComment = 1; // Only for C99/C++.
1163 // FALL THROUGH.
1164 case lang_c94:
1165 Options.Digraphs = 1; // C94, C99, C++.
1166 // FALL THROUGH.
1167 case lang_c89:
1168 break;
1169 }
1170
1171 // GNUMode - Set if we're in gnu99, gnu89, gnucxx98, etc.
1172 switch (LangStd) {
1173 default: assert(0 && "Unknown language standard!");
1174 case lang_gnucxx0x:
1175 case lang_gnucxx98:
1176 case lang_gnu99:
1177 case lang_gnu89:
1178 Options.GNUMode = 1;
1179 break;
1180 case lang_cxx0x:
1181 case lang_cxx98:
1182 case lang_c99:
1183 case lang_c94:
1184 case lang_c89:
1185 Options.GNUMode = 0;
1186 break;
1187 }
1188
1189 if (Options.CPlusPlus) {
1190 Options.C99 = 0;
1191 Options.HexFloats = 0;
1192 }
1193
1194 if (LangStd == lang_c89 || LangStd == lang_c94 || LangStd == lang_gnu89)
1195 Options.ImplicitInt = 1;
1196 else
1197 Options.ImplicitInt = 0;
1198
1199 // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
1200 // is specified, or -std is set to a conforming mode.
1201 Options.Trigraphs = !Options.GNUMode;
1202 if (Trigraphs.getPosition())
1203 Options.Trigraphs = Trigraphs; // Command line option wins if specified.
1204
1205 // If in a conformant language mode (e.g. -std=c99) Blocks defaults to off
1206 // even if they are normally on for the target. In GNU modes (e.g.
1207 // -std=gnu99) the default for blocks depends on the target settings.
1208 // However, blocks are not turned off when compiling Obj-C or Obj-C++ code.
1209 if (!Options.ObjC1 && !Options.GNUMode)
1210 Options.Blocks = 0;
1211
1212 // Default to not accepting '$' in identifiers when preprocessing assembler,
1213 // but do accept when preprocessing C. FIXME: these defaults are right for
1214 // darwin, are they right everywhere?
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001215 Options.DollarIdents = IK != FrontendOptions::IK_Asm;
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001216 if (DollarsInIdents.getPosition()) // Explicit setting overrides default.
1217 Options.DollarIdents = DollarsInIdents;
1218
1219 if (PascalStrings.getPosition())
1220 Options.PascalStrings = PascalStrings;
1221 if (MSExtensions.getPosition())
1222 Options.Microsoft = MSExtensions;
1223 Options.WritableStrings = WritableStrings;
1224 if (NoLaxVectorConversions.getPosition())
1225 Options.LaxVectorConversions = 0;
1226 Options.Exceptions = Exceptions;
1227 Options.Rtti = Rtti;
1228 if (EnableBlocks.getPosition())
1229 Options.Blocks = EnableBlocks;
1230 if (CharIsSigned.getPosition())
1231 Options.CharIsSigned = CharIsSigned;
1232 if (ShortWChar.getPosition())
1233 Options.ShortWChar = ShortWChar;
1234
1235 if (!AllowBuiltins)
1236 Options.NoBuiltin = 1;
1237 if (Freestanding)
1238 Options.Freestanding = Options.NoBuiltin = 1;
1239
1240 if (EnableHeinousExtensions)
1241 Options.HeinousExtensions = 1;
1242
1243 if (AccessControl)
1244 Options.AccessControl = 1;
1245
1246 Options.ElideConstructors = !NoElideConstructors;
1247
1248 // OpenCL and C++ both have bool, true, false keywords.
1249 Options.Bool = Options.OpenCL | Options.CPlusPlus;
1250
1251 Options.MathErrno = MathErrno;
1252
1253 Options.InstantiationDepth = TemplateDepth;
1254
1255 // Override the default runtime if the user requested it.
Daniel Dunbar4656c532009-11-17 07:07:28 +00001256 if (GNURuntime)
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001257 Options.NeXTRuntime = 0;
1258
1259 if (!ObjCConstantStringClass.empty())
1260 Options.ObjCConstantStringClass = ObjCConstantStringClass.c_str();
1261
1262 if (ObjCNonFragileABI)
1263 Options.ObjCNonFragileABI = 1;
1264
1265 if (EmitAllDecls)
1266 Options.EmitAllDecls = 1;
1267
1268 // The __OPTIMIZE_SIZE__ define is tied to -Oz, which we don't support.
1269 Options.OptimizeSize = 0;
Daniel Dunbar77a9d2b2009-11-16 22:38:14 +00001270 Options.Optimize = codegenoptions::OptSize || codegenoptions::OptLevel;
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001271
1272 assert(PICLevel <= 2 && "Invalid value for -pic-level");
1273 Options.PICLevel = PICLevel;
1274
1275 Options.GNUInline = !Options.C99;
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001276
1277 // This is the __NO_INLINE__ define, which just depends on things like the
1278 // optimization level and -fno-inline, not actually whether the backend has
1279 // inlining enabled.
Daniel Dunbar77a9d2b2009-11-16 22:38:14 +00001280 //
1281 // FIXME: This is affected by other options (-fno-inline).
1282 Options.NoInline = !codegenoptions::OptLevel;
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001283
1284 Options.Static = StaticDefine;
1285
1286 switch (StackProtector) {
1287 default:
1288 assert(StackProtector <= 2 && "Invalid value for -stack-protector");
1289 case -1: break;
1290 case 0: Options.setStackProtectorMode(LangOptions::SSPOff); break;
1291 case 1: Options.setStackProtectorMode(LangOptions::SSPOn); break;
1292 case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break;
1293 }
1294
1295 if (MainFileName.getPosition())
1296 Options.setMainFileName(MainFileName.c_str());
1297
1298 Target.setForcedLangOptions(Options);
1299}
Daniel Dunbar22bdabf2009-11-11 10:07:44 +00001300
1301void
1302clang::InitializePreprocessorOutputOptions(PreprocessorOutputOptions &Opts) {
1303 using namespace preprocessoroutputoptions;
1304
1305 Opts.ShowCPP = !DumpMacros;
1306 Opts.ShowMacros = DumpMacros || DumpDefines;
1307 Opts.ShowLineMarkers = !DisableLineMarkers;
1308 Opts.ShowComments = EnableCommentOutput;
1309 Opts.ShowMacroComments = EnableMacroCommentOutput;
1310}
Daniel Dunbarb9bbd542009-11-15 06:48:46 +00001311
1312void clang::InitializeTargetOptions(TargetOptions &Opts) {
1313 using namespace targetoptions;
1314
1315 Opts.ABI = TargetABI;
1316 Opts.CPU = TargetCPU;
1317 Opts.Triple = TargetTriple;
1318 Opts.Features = TargetFeatures;
1319
1320 // Use the host triple if unspecified.
1321 if (Opts.Triple.empty())
1322 Opts.Triple = llvm::sys::getHostTriple();
1323}