blob: b5190ebcae54ba26d7e41304f92dfb9cb3d7909b [file] [log] [blame]
Daniel Dunbar0498cfc2009-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 Dunbar339c1342009-11-11 08:13:55 +000015#include "clang/Basic/LangOptions.h"
16#include "clang/Basic/TargetInfo.h"
Daniel Dunbard58c03f2009-11-15 06:48:46 +000017#include "clang/Basic/TargetOptions.h"
Daniel Dunbar339c1342009-11-11 08:13:55 +000018#include "clang/Frontend/AnalysisConsumer.h"
Chandler Carruth2811ccf2009-11-12 17:24:48 +000019#include "clang/CodeGen/CodeGenOptions.h"
Daniel Dunbar0e0bae82009-11-11 21:43:12 +000020#include "clang/Frontend/DependencyOutputOptions.h"
Daniel Dunbar0db4b762009-11-11 08:13:40 +000021#include "clang/Frontend/DiagnosticOptions.h"
Daniel Dunbar26266882009-11-12 23:52:32 +000022#include "clang/Frontend/FrontendOptions.h"
Daniel Dunbarf7973292009-11-11 08:13:32 +000023#include "clang/Frontend/HeaderSearchOptions.h"
Daniel Dunbarb52d2432009-11-11 06:10:03 +000024#include "clang/Frontend/PCHReader.h"
25#include "clang/Frontend/PreprocessorOptions.h"
Daniel Dunbar29cf7462009-11-11 10:07:44 +000026#include "clang/Frontend/PreprocessorOutputOptions.h"
Daniel Dunbarb52d2432009-11-11 06:10:03 +000027#include "llvm/ADT/STLExtras.h"
Daniel Dunbar0498cfc2009-11-10 19:51:53 +000028#include "llvm/ADT/StringMap.h"
29#include "llvm/Support/CommandLine.h"
Daniel Dunbard10c5b82009-11-15 00:12:04 +000030#include "llvm/Support/RegistryParser.h"
Daniel Dunbard58c03f2009-11-15 06:48:46 +000031#include "llvm/System/Host.h"
Dan Gohman0063e982009-11-10 21:21:27 +000032#include <stdio.h>
Daniel Dunbar0498cfc2009-11-10 19:51:53 +000033
34using namespace clang;
35
36//===----------------------------------------------------------------------===//
Daniel Dunbar339c1342009-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 Kremenekeb941132009-11-13 01:15:47 +000084
Daniel Dunbar339c1342009-11-11 08:13:55 +000085static llvm::cl::opt<bool>
86AnalyzerDisplayProgress("analyzer-display-progress",
Ted Kremenekeb941132009-11-13 01:15:47 +000087 llvm::cl::desc("Emit verbose output about the analyzer's progress"));
Daniel Dunbar339c1342009-11-11 08:13:55 +000088
Ted Kremenekeb941132009-11-13 01:15:47 +000089static llvm::cl::opt<bool>
90AnalyzerExperimentalChecks("analyzer-experimental-checks",
91 llvm::cl::desc("Use experimental path-sensitive checks"));
Ted Kremenek8382cf52009-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 Kremenekeb941132009-11-13 01:15:47 +000096
Daniel Dunbar339c1342009-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",
103 llvm::cl::init(false),
104 llvm::cl::desc("Eagerly assume the truth/falseness of some "
Ted Kremenekeb941132009-11-13 01:15:47 +0000105 "symbolic constraints"));
Daniel Dunbar339c1342009-11-11 08:13:55 +0000106
107static llvm::cl::opt<bool>
108PurgeDead("analyzer-purge-dead",
109 llvm::cl::init(true),
110 llvm::cl::desc("Remove dead symbols, bindings, and constraints before"
Ted Kremenekeb941132009-11-13 01:15:47 +0000111 " processing a statement"));
Daniel Dunbar339c1342009-11-11 08:13:55 +0000112
113static llvm::cl::opt<bool>
114TrimGraph("trim-egraph",
115 llvm::cl::desc("Only show error-related paths in the analysis graph"));
116
117static llvm::cl::opt<bool>
118VisualizeEGDot("analyzer-viz-egraph-graphviz",
119 llvm::cl::desc("Display exploded graph using GraphViz"));
120
121static llvm::cl::opt<bool>
122VisualizeEGUbi("analyzer-viz-egraph-ubigraph",
123 llvm::cl::desc("Display exploded graph using Ubigraph"));
124
125}
126
Daniel Dunbar339c1342009-11-11 08:13:55 +0000127//===----------------------------------------------------------------------===//
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000128// Code Generation Options
129//===----------------------------------------------------------------------===//
130
131namespace codegenoptions {
132
133static llvm::cl::opt<bool>
134DisableLLVMOptimizations("disable-llvm-optzns",
135 llvm::cl::desc("Don't run LLVM optimization passes"));
136
137static llvm::cl::opt<bool>
138DisableRedZone("disable-red-zone",
139 llvm::cl::desc("Do not emit code that uses the red zone."),
140 llvm::cl::init(false));
141
142static llvm::cl::opt<bool>
143GenerateDebugInfo("g",
144 llvm::cl::desc("Generate source level debug information"));
145
146static llvm::cl::opt<bool>
147NoCommon("fno-common",
148 llvm::cl::desc("Compile common globals like normal definitions"),
149 llvm::cl::ValueDisallowed);
150
151static llvm::cl::opt<bool>
152NoImplicitFloat("no-implicit-float",
153 llvm::cl::desc("Don't generate implicit floating point instructions (x86-only)"),
154 llvm::cl::init(false));
155
156static llvm::cl::opt<bool>
157NoMergeConstants("fno-merge-all-constants",
158 llvm::cl::desc("Disallow merging of constants."));
159
160// It might be nice to add bounds to the CommandLine library directly.
161struct OptLevelParser : public llvm::cl::parser<unsigned> {
162 bool parse(llvm::cl::Option &O, llvm::StringRef ArgName,
163 llvm::StringRef Arg, unsigned &Val) {
164 if (llvm::cl::parser<unsigned>::parse(O, ArgName, Arg, Val))
165 return true;
166 if (Val > 3)
167 return O.error("'" + Arg + "' invalid optimization level!");
168 return false;
169 }
170};
171static llvm::cl::opt<unsigned, false, OptLevelParser>
172OptLevel("O", llvm::cl::Prefix,
173 llvm::cl::desc("Optimization level"),
174 llvm::cl::init(0));
175
176static llvm::cl::opt<bool>
177OptSize("Os", llvm::cl::desc("Optimize for size"));
178
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000179}
180
181//===----------------------------------------------------------------------===//
Daniel Dunbar0e0bae82009-11-11 21:43:12 +0000182// Dependency Output Options
183//===----------------------------------------------------------------------===//
184
185namespace dependencyoutputoptions {
186
187static llvm::cl::opt<std::string>
188DependencyFile("dependency-file",
189 llvm::cl::desc("Filename (or -) to write dependency output to"));
190
191static llvm::cl::opt<bool>
192DependenciesIncludeSystemHeaders("sys-header-deps",
193 llvm::cl::desc("Include system headers in dependency output"));
194
195static llvm::cl::list<std::string>
196DependencyTargets("MT",
197 llvm::cl::desc("Specify target for dependency"));
198
199static llvm::cl::opt<bool>
200PhonyDependencyTarget("MP",
201 llvm::cl::desc("Create phony target for each dependency "
202 "(other than main file)"));
203
204}
205
206//===----------------------------------------------------------------------===//
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000207// Diagnostic Options
208//===----------------------------------------------------------------------===//
209
210namespace diagnosticoptions {
211
Daniel Dunbar11e729d2009-11-12 07:28:21 +0000212static llvm::cl::opt<std::string>
213DumpBuildInformation("dump-build-information",
214 llvm::cl::value_desc("filename"),
215 llvm::cl::desc("output a dump of some build information to a file"));
216
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000217static llvm::cl::opt<bool>
218NoShowColumn("fno-show-column",
219 llvm::cl::desc("Do not include column number on diagnostics"));
220
221static llvm::cl::opt<bool>
222NoShowLocation("fno-show-source-location",
223 llvm::cl::desc("Do not include source location information with"
224 " diagnostics"));
225
226static llvm::cl::opt<bool>
227NoCaretDiagnostics("fno-caret-diagnostics",
228 llvm::cl::desc("Do not include source line and caret with"
229 " diagnostics"));
230
231static llvm::cl::opt<bool>
232NoDiagnosticsFixIt("fno-diagnostics-fixit-info",
233 llvm::cl::desc("Do not include fixit information in"
234 " diagnostics"));
235
Daniel Dunbar69079432009-11-12 07:28:44 +0000236static llvm::cl::opt<bool> OptNoWarnings("w");
237
238static llvm::cl::opt<bool> OptPedantic("pedantic");
239
240static llvm::cl::opt<bool> OptPedanticErrors("pedantic-errors");
241
242// This gets all -W options, including -Werror, -W[no-]system-headers, etc. The
243// driver has stripped off -Wa,foo etc. The driver has also translated -W to
244// -Wextra, so we don't need to worry about it.
245static llvm::cl::list<std::string>
246OptWarnings("W", llvm::cl::Prefix, llvm::cl::ValueOptional);
247
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000248static llvm::cl::opt<bool>
249PrintSourceRangeInfo("fdiagnostics-print-source-range-info",
250 llvm::cl::desc("Print source range spans in numeric form"));
251
252static llvm::cl::opt<bool>
253PrintDiagnosticOption("fdiagnostics-show-option",
254 llvm::cl::desc("Print diagnostic name with mappable diagnostics"));
255
256static llvm::cl::opt<unsigned>
257MessageLength("fmessage-length",
258 llvm::cl::desc("Format message diagnostics so that they fit "
259 "within N columns or fewer, when possible."),
260 llvm::cl::value_desc("N"));
261
262static llvm::cl::opt<bool>
263PrintColorDiagnostic("fcolor-diagnostics",
264 llvm::cl::desc("Use colors in diagnostics"));
265
Daniel Dunbar69079432009-11-12 07:28:44 +0000266static llvm::cl::opt<bool>
267SilenceRewriteMacroWarning("Wno-rewrite-macros", llvm::cl::init(false),
268 llvm::cl::desc("Silence ObjC rewriting warnings"));
269
Daniel Dunbar26266882009-11-12 23:52:32 +0000270static llvm::cl::opt<bool>
271VerifyDiagnostics("verify",
272 llvm::cl::desc("Verify emitted diagnostics and warnings"));
273
274}
275
Daniel Dunbar26266882009-11-12 23:52:32 +0000276//===----------------------------------------------------------------------===//
277// Frontend Options
278//===----------------------------------------------------------------------===//
279
280namespace frontendoptions {
281
Daniel Dunbar9a8a83b2009-11-14 22:32:38 +0000282using namespace clang::frontend;
283
Daniel Dunbar914474c2009-11-13 01:02:10 +0000284static llvm::cl::opt<ParsedSourceLocation>
285CodeCompletionAt("code-completion-at",
286 llvm::cl::value_desc("file:line:column"),
287 llvm::cl::desc("Dump code-completion information at a location"));
288
289static llvm::cl::opt<bool>
290CodeCompletionDebugPrinter("code-completion-debug-printer",
291 llvm::cl::desc("Use the \"debug\" code-completion print"),
292 llvm::cl::init(true));
293
294static llvm::cl::opt<bool>
295CodeCompletionWantsMacros("code-completion-macros",
296 llvm::cl::desc("Include macros in code-completion results"));
297
Daniel Dunbar26266882009-11-12 23:52:32 +0000298static llvm::cl::opt<bool>
299DisableFree("disable-free",
300 llvm::cl::desc("Disable freeing of memory on exit"),
301 llvm::cl::init(false));
302
303static llvm::cl::opt<bool>
304EmptyInputOnly("empty-input-only",
305 llvm::cl::desc("Force running on an empty input file"));
306
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +0000307static llvm::cl::opt<FrontendOptions::InputKind>
308InputType("x", llvm::cl::desc("Input language type"),
309 llvm::cl::init(FrontendOptions::IK_None),
310 llvm::cl::values(clEnumValN(FrontendOptions::IK_C, "c", "C"),
311 clEnumValN(FrontendOptions::IK_OpenCL, "cl", "OpenCL C"),
312 clEnumValN(FrontendOptions::IK_CXX, "c++", "C++"),
313 clEnumValN(FrontendOptions::IK_ObjC, "objective-c",
314 "Objective C"),
315 clEnumValN(FrontendOptions::IK_ObjCXX, "objective-c++",
316 "Objective C++"),
317 clEnumValN(FrontendOptions::IK_PreprocessedC,
318 "cpp-output",
319 "Preprocessed C"),
320 clEnumValN(FrontendOptions::IK_Asm,
321 "assembler-with-cpp",
322 "Assembly Source Codde"),
323 clEnumValN(FrontendOptions::IK_PreprocessedCXX,
324 "c++-cpp-output",
325 "Preprocessed C++"),
326 clEnumValN(FrontendOptions::IK_PreprocessedObjC,
327 "objective-c-cpp-output",
328 "Preprocessed Objective C"),
329 clEnumValN(FrontendOptions::IK_PreprocessedObjCXX,
330 "objective-c++-cpp-output",
331 "Preprocessed Objective C++"),
332 clEnumValN(FrontendOptions::IK_C, "c-header",
333 "C header"),
334 clEnumValN(FrontendOptions::IK_ObjC, "objective-c-header",
335 "Objective-C header"),
336 clEnumValN(FrontendOptions::IK_CXX, "c++-header",
337 "C++ header"),
338 clEnumValN(FrontendOptions::IK_ObjCXX,
339 "objective-c++-header",
340 "Objective-C++ header"),
341 clEnumValN(FrontendOptions::IK_AST, "ast",
342 "Clang AST"),
343 clEnumValEnd));
344
Daniel Dunbar26266882009-11-12 23:52:32 +0000345static llvm::cl::list<std::string>
346InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input files>"));
347
348static llvm::cl::opt<std::string>
349InheritanceViewCls("cxx-inheritance-view",
350 llvm::cl::value_desc("class name"),
351 llvm::cl::desc("View C++ inheritance for a specified class"));
352
Daniel Dunbarc86804b2009-11-12 23:52:56 +0000353static llvm::cl::list<ParsedSourceLocation>
354FixItAtLocations("fixit-at", llvm::cl::value_desc("source-location"),
355 llvm::cl::desc("Perform Fix-It modifications at the given source location"));
356
Daniel Dunbar26266882009-11-12 23:52:32 +0000357static llvm::cl::opt<std::string>
358OutputFile("o",
359 llvm::cl::value_desc("path"),
360 llvm::cl::desc("Specify output file"));
361
Daniel Dunbard10c5b82009-11-15 00:12:04 +0000362static llvm::cl::opt<std::string>
363PluginActionName("plugin",
364 llvm::cl::desc("Use the named plugin action "
365 "(use \"help\" to list available options)"));
366
Daniel Dunbar9a8a83b2009-11-14 22:32:38 +0000367static llvm::cl::opt<ActionKind>
368ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
369 llvm::cl::init(ParseSyntaxOnly),
370 llvm::cl::values(
371 clEnumValN(RunPreprocessorOnly, "Eonly",
372 "Just run preprocessor, no output (for timings)"),
373 clEnumValN(PrintPreprocessedInput, "E",
374 "Run preprocessor, emit preprocessed file"),
375 clEnumValN(DumpRawTokens, "dump-raw-tokens",
376 "Lex file in raw mode and dump raw tokens"),
377 clEnumValN(RunAnalysis, "analyze",
378 "Run static analysis engine"),
379 clEnumValN(DumpTokens, "dump-tokens",
380 "Run preprocessor, dump internal rep of tokens"),
381 clEnumValN(ParseNoop, "parse-noop",
382 "Run parser with noop callbacks (for timings)"),
383 clEnumValN(ParseSyntaxOnly, "fsyntax-only",
384 "Run parser and perform semantic analysis"),
385 clEnumValN(FixIt, "fixit",
386 "Apply fix-it advice to the input source"),
387 clEnumValN(ParsePrintCallbacks, "parse-print-callbacks",
388 "Run parser and print each callback invoked"),
389 clEnumValN(EmitHTML, "emit-html",
390 "Output input source as HTML"),
391 clEnumValN(ASTPrint, "ast-print",
392 "Build ASTs and then pretty-print them"),
393 clEnumValN(ASTPrintXML, "ast-print-xml",
394 "Build ASTs and then print them in XML format"),
395 clEnumValN(ASTDump, "ast-dump",
396 "Build ASTs and then debug dump them"),
397 clEnumValN(ASTView, "ast-view",
398 "Build ASTs and view them with GraphViz"),
399 clEnumValN(PrintDeclContext, "print-decl-contexts",
400 "Print DeclContexts and their Decls"),
401 clEnumValN(DumpRecordLayouts, "dump-record-layouts",
402 "Dump record layout information"),
403 clEnumValN(GeneratePTH, "emit-pth",
404 "Generate pre-tokenized header file"),
405 clEnumValN(GeneratePCH, "emit-pch",
406 "Generate pre-compiled header file"),
407 clEnumValN(EmitAssembly, "S",
408 "Emit native assembly code"),
409 clEnumValN(EmitLLVM, "emit-llvm",
410 "Build ASTs then convert to LLVM, emit .ll file"),
411 clEnumValN(EmitBC, "emit-llvm-bc",
412 "Build ASTs then convert to LLVM, emit .bc file"),
413 clEnumValN(EmitLLVMOnly, "emit-llvm-only",
414 "Build ASTs and convert to LLVM, discarding output"),
415 clEnumValN(RewriteTest, "rewrite-test",
416 "Rewriter playground"),
417 clEnumValN(RewriteObjC, "rewrite-objc",
418 "Rewrite ObjC into C (code rewriter example)"),
419 clEnumValN(RewriteMacros, "rewrite-macros",
420 "Expand macros without full preprocessing"),
421 clEnumValN(RewriteBlocks, "rewrite-blocks",
422 "Rewrite Blocks to C"),
423 clEnumValEnd));
424
Daniel Dunbar26266882009-11-12 23:52:32 +0000425static llvm::cl::opt<bool>
426RelocatablePCH("relocatable-pch",
427 llvm::cl::desc("Whether to build a relocatable precompiled "
428 "header"));
429static llvm::cl::opt<bool>
430Stats("print-stats",
431 llvm::cl::desc("Print performance metrics and statistics"));
432
433static llvm::cl::opt<bool>
434TimeReport("ftime-report",
435 llvm::cl::desc("Print the amount of time each "
436 "phase of compilation takes"));
437
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000438}
439
440//===----------------------------------------------------------------------===//
Daniel Dunbar56749082009-11-11 07:26:12 +0000441// Language Options
442//===----------------------------------------------------------------------===//
443
444namespace langoptions {
445
446static llvm::cl::opt<bool>
447AllowBuiltins("fbuiltin", llvm::cl::init(true),
448 llvm::cl::desc("Disable implicit builtin knowledge of functions"));
449
450static llvm::cl::opt<bool>
451AltiVec("faltivec", llvm::cl::desc("Enable AltiVec vector initializer syntax"),
452 llvm::cl::init(false));
453
454static llvm::cl::opt<bool>
455AccessControl("faccess-control",
456 llvm::cl::desc("Enable C++ access control"));
457
458static llvm::cl::opt<bool>
459CharIsSigned("fsigned-char",
460 llvm::cl::desc("Force char to be a signed/unsigned type"));
461
462static llvm::cl::opt<bool>
463DollarsInIdents("fdollars-in-identifiers",
464 llvm::cl::desc("Allow '$' in identifiers"));
465
466static llvm::cl::opt<bool>
467EmitAllDecls("femit-all-decls",
468 llvm::cl::desc("Emit all declarations, even if unused"));
469
470static llvm::cl::opt<bool>
471EnableBlocks("fblocks", llvm::cl::desc("enable the 'blocks' language feature"));
472
473static llvm::cl::opt<bool>
474EnableHeinousExtensions("fheinous-gnu-extensions",
475 llvm::cl::desc("enable GNU extensions that you really really shouldn't use"),
476 llvm::cl::ValueDisallowed, llvm::cl::Hidden);
477
478static llvm::cl::opt<bool>
479Exceptions("fexceptions",
480 llvm::cl::desc("Enable support for exception handling"));
481
482static llvm::cl::opt<bool>
483Freestanding("ffreestanding",
484 llvm::cl::desc("Assert that the compilation takes place in a "
485 "freestanding environment"));
486
487static llvm::cl::opt<bool>
488GNURuntime("fgnu-runtime",
489 llvm::cl::desc("Generate output compatible with the standard GNU "
490 "Objective-C runtime"));
491
492/// LangStds - Language standards we support.
493enum LangStds {
494 lang_unspecified,
495 lang_c89, lang_c94, lang_c99,
496 lang_gnu89, lang_gnu99,
497 lang_cxx98, lang_gnucxx98,
498 lang_cxx0x, lang_gnucxx0x
499};
500static llvm::cl::opt<LangStds>
501LangStd("std", llvm::cl::desc("Language standard to compile for"),
502 llvm::cl::init(lang_unspecified),
503 llvm::cl::values(clEnumValN(lang_c89, "c89", "ISO C 1990"),
504 clEnumValN(lang_c89, "c90", "ISO C 1990"),
505 clEnumValN(lang_c89, "iso9899:1990", "ISO C 1990"),
506 clEnumValN(lang_c94, "iso9899:199409",
507 "ISO C 1990 with amendment 1"),
508 clEnumValN(lang_c99, "c99", "ISO C 1999"),
509 clEnumValN(lang_c99, "c9x", "ISO C 1999"),
510 clEnumValN(lang_c99, "iso9899:1999", "ISO C 1999"),
511 clEnumValN(lang_c99, "iso9899:199x", "ISO C 1999"),
512 clEnumValN(lang_gnu89, "gnu89",
513 "ISO C 1990 with GNU extensions"),
514 clEnumValN(lang_gnu99, "gnu99",
515 "ISO C 1999 with GNU extensions (default for C)"),
516 clEnumValN(lang_gnu99, "gnu9x",
517 "ISO C 1999 with GNU extensions"),
518 clEnumValN(lang_cxx98, "c++98",
519 "ISO C++ 1998 with amendments"),
520 clEnumValN(lang_gnucxx98, "gnu++98",
521 "ISO C++ 1998 with amendments and GNU "
522 "extensions (default for C++)"),
523 clEnumValN(lang_cxx0x, "c++0x",
524 "Upcoming ISO C++ 200x with amendments"),
525 clEnumValN(lang_gnucxx0x, "gnu++0x",
526 "Upcoming ISO C++ 200x with amendments and GNU "
527 "extensions"),
528 clEnumValEnd));
529
530static llvm::cl::opt<bool>
531MSExtensions("fms-extensions",
532 llvm::cl::desc("Accept some non-standard constructs used in "
533 "Microsoft header files "));
534
535static llvm::cl::opt<std::string>
536MainFileName("main-file-name",
537 llvm::cl::desc("Main file name to use for debug info"));
538
539static llvm::cl::opt<bool>
540MathErrno("fmath-errno", llvm::cl::init(true),
541 llvm::cl::desc("Require math functions to respect errno"));
542
543static llvm::cl::opt<bool>
Daniel Dunbar56749082009-11-11 07:26:12 +0000544NoElideConstructors("fno-elide-constructors",
545 llvm::cl::desc("Disable C++ copy constructor elision"));
546
547static llvm::cl::opt<bool>
548NoLaxVectorConversions("fno-lax-vector-conversions",
549 llvm::cl::desc("Disallow implicit conversions between "
550 "vectors with a different number of "
551 "elements or different element types"));
552
553
554static llvm::cl::opt<bool>
555NoOperatorNames("fno-operator-names",
556 llvm::cl::desc("Do not treat C++ operator name keywords as "
557 "synonyms for operators"));
558
559static llvm::cl::opt<std::string>
560ObjCConstantStringClass("fconstant-string-class",
561 llvm::cl::value_desc("class name"),
562 llvm::cl::desc("Specify the class to use for constant "
563 "Objective-C string objects."));
564
565static llvm::cl::opt<bool>
566ObjCEnableGC("fobjc-gc",
567 llvm::cl::desc("Enable Objective-C garbage collection"));
568
569static llvm::cl::opt<bool>
570ObjCExclusiveGC("fobjc-gc-only",
571 llvm::cl::desc("Use GC exclusively for Objective-C related "
572 "memory management"));
573
574static llvm::cl::opt<bool>
575ObjCEnableGCBitmapPrint("print-ivar-layout",
576 llvm::cl::desc("Enable Objective-C Ivar layout bitmap print trace"));
577
578static llvm::cl::opt<bool>
579ObjCNonFragileABI("fobjc-nonfragile-abi",
580 llvm::cl::desc("enable objective-c's nonfragile abi"));
581
582static llvm::cl::opt<bool>
583OverflowChecking("ftrapv",
584 llvm::cl::desc("Trap on integer overflow"),
585 llvm::cl::init(false));
586
587static llvm::cl::opt<unsigned>
588PICLevel("pic-level", llvm::cl::desc("Value for __PIC__"));
589
590static llvm::cl::opt<bool>
591PThread("pthread", llvm::cl::desc("Support POSIX threads in generated code"),
592 llvm::cl::init(false));
593
594static llvm::cl::opt<bool>
595PascalStrings("fpascal-strings",
596 llvm::cl::desc("Recognize and construct Pascal-style "
597 "string literals"));
598
Daniel Dunbar56749082009-11-11 07:26:12 +0000599static llvm::cl::opt<bool>
600Rtti("frtti", llvm::cl::init(true),
601 llvm::cl::desc("Enable generation of rtti information"));
602
603static llvm::cl::opt<bool>
604ShortWChar("fshort-wchar",
605 llvm::cl::desc("Force wchar_t to be a short unsigned int"));
606
607static llvm::cl::opt<bool>
608StaticDefine("static-define", llvm::cl::desc("Should __STATIC__ be defined"));
609
610static llvm::cl::opt<int>
611StackProtector("stack-protector",
612 llvm::cl::desc("Enable stack protectors"),
613 llvm::cl::init(-1));
614
615static llvm::cl::opt<LangOptions::VisibilityMode>
616SymbolVisibility("fvisibility",
617 llvm::cl::desc("Set the default symbol visibility:"),
618 llvm::cl::init(LangOptions::Default),
619 llvm::cl::values(clEnumValN(LangOptions::Default, "default",
620 "Use default symbol visibility"),
621 clEnumValN(LangOptions::Hidden, "hidden",
622 "Use hidden symbol visibility"),
623 clEnumValN(LangOptions::Protected,"protected",
624 "Use protected symbol visibility"),
625 clEnumValEnd));
626
627static llvm::cl::opt<unsigned>
628TemplateDepth("ftemplate-depth", llvm::cl::init(99),
629 llvm::cl::desc("Maximum depth of recursive template "
630 "instantiation"));
631
632static llvm::cl::opt<bool>
633Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences"));
634
635static llvm::cl::opt<bool>
636WritableStrings("fwritable-strings",
637 llvm::cl::desc("Store string literals as writable data"));
638
639}
640
641//===----------------------------------------------------------------------===//
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000642// General Preprocessor Options
643//===----------------------------------------------------------------------===//
644
645namespace preprocessoroptions {
646
647static llvm::cl::list<std::string>
648D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
649 llvm::cl::desc("Predefine the specified macro"));
650
651static llvm::cl::list<std::string>
652ImplicitIncludes("include", llvm::cl::value_desc("file"),
653 llvm::cl::desc("Include file before parsing"));
654static llvm::cl::list<std::string>
655ImplicitMacroIncludes("imacros", llvm::cl::value_desc("file"),
656 llvm::cl::desc("Include macros from file before parsing"));
657
658static llvm::cl::opt<std::string>
659ImplicitIncludePCH("include-pch", llvm::cl::value_desc("file"),
660 llvm::cl::desc("Include precompiled header file"));
661
662static llvm::cl::opt<std::string>
663ImplicitIncludePTH("include-pth", llvm::cl::value_desc("file"),
664 llvm::cl::desc("Include file before parsing"));
665
Daniel Dunbarb3cb98e2009-11-12 02:53:59 +0000666static llvm::cl::opt<std::string>
667TokenCache("token-cache", llvm::cl::value_desc("path"),
668 llvm::cl::desc("Use specified token cache file"));
669
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000670static llvm::cl::list<std::string>
671U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
672 llvm::cl::desc("Undefine the specified macro"));
673
674static llvm::cl::opt<bool>
675UndefMacros("undef", llvm::cl::value_desc("macro"),
676 llvm::cl::desc("undef all system defines"));
677
678}
679
680//===----------------------------------------------------------------------===//
Daniel Dunbarf7973292009-11-11 08:13:32 +0000681// Header Search Options
682//===----------------------------------------------------------------------===//
683
684namespace headersearchoptions {
685
686static llvm::cl::opt<bool>
687nostdinc("nostdinc", llvm::cl::desc("Disable standard #include directories"));
688
689static llvm::cl::opt<bool>
690nobuiltininc("nobuiltininc",
691 llvm::cl::desc("Disable builtin #include directories"));
692
693// Various command line options. These four add directories to each chain.
694static llvm::cl::list<std::string>
695F_dirs("F", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
696 llvm::cl::desc("Add directory to framework include search path"));
697
698static llvm::cl::list<std::string>
699I_dirs("I", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
700 llvm::cl::desc("Add directory to include search path"));
701
702static llvm::cl::list<std::string>
703idirafter_dirs("idirafter", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
704 llvm::cl::desc("Add directory to AFTER include search path"));
705
706static llvm::cl::list<std::string>
707iquote_dirs("iquote", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
708 llvm::cl::desc("Add directory to QUOTE include search path"));
709
710static llvm::cl::list<std::string>
711isystem_dirs("isystem", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
712 llvm::cl::desc("Add directory to SYSTEM include search path"));
713
714// These handle -iprefix/-iwithprefix/-iwithprefixbefore.
715static llvm::cl::list<std::string>
716iprefix_vals("iprefix", llvm::cl::value_desc("prefix"), llvm::cl::Prefix,
717 llvm::cl::desc("Set the -iwithprefix/-iwithprefixbefore prefix"));
718static llvm::cl::list<std::string>
719iwithprefix_vals("iwithprefix", llvm::cl::value_desc("dir"), llvm::cl::Prefix,
720 llvm::cl::desc("Set directory to SYSTEM include search path with prefix"));
721static llvm::cl::list<std::string>
722iwithprefixbefore_vals("iwithprefixbefore", llvm::cl::value_desc("dir"),
723 llvm::cl::Prefix,
724 llvm::cl::desc("Set directory to include search path with prefix"));
725
726static llvm::cl::opt<std::string>
727isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::init("/"),
728 llvm::cl::desc("Set the system root directory (usually /)"));
729
Daniel Dunbar1417c742009-11-12 23:52:46 +0000730static llvm::cl::opt<bool>
731Verbose("v", llvm::cl::desc("Enable verbose output"));
732
Daniel Dunbarf7973292009-11-11 08:13:32 +0000733}
734
735//===----------------------------------------------------------------------===//
Daniel Dunbar29cf7462009-11-11 10:07:44 +0000736// Preprocessed Output Options
737//===----------------------------------------------------------------------===//
738
739namespace preprocessoroutputoptions {
740
741static llvm::cl::opt<bool>
742DisableLineMarkers("P", llvm::cl::desc("Disable linemarker output in -E mode"));
743
744static llvm::cl::opt<bool>
745EnableCommentOutput("C", llvm::cl::desc("Enable comment output in -E mode"));
746
747static llvm::cl::opt<bool>
748EnableMacroCommentOutput("CC",
749 llvm::cl::desc("Enable comment output in -E mode, "
750 "even from macro expansions"));
751static llvm::cl::opt<bool>
752DumpMacros("dM", llvm::cl::desc("Print macro definitions in -E mode instead of"
753 " normal output"));
754static llvm::cl::opt<bool>
755DumpDefines("dD", llvm::cl::desc("Print macro definitions in -E mode in "
756 "addition to normal output"));
757
758}
Daniel Dunbard58c03f2009-11-15 06:48:46 +0000759//===----------------------------------------------------------------------===//
760// Target Options
761//===----------------------------------------------------------------------===//
762
763namespace targetoptions {
764
765static llvm::cl::opt<std::string>
766TargetABI("target-abi",
767 llvm::cl::desc("Target a particular ABI type"));
768
769static llvm::cl::opt<std::string>
770TargetCPU("mcpu",
771 llvm::cl::desc("Target a specific cpu type (-mcpu=help for details)"));
772
773static llvm::cl::list<std::string>
774TargetFeatures("target-feature", llvm::cl::desc("Target specific attributes"));
775
776static llvm::cl::opt<std::string>
777TargetTriple("triple",
778 llvm::cl::desc("Specify target triple (e.g. i686-apple-darwin9)"));
779
780}
Daniel Dunbar29cf7462009-11-11 10:07:44 +0000781
782//===----------------------------------------------------------------------===//
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000783// Option Object Construction
784//===----------------------------------------------------------------------===//
785
Daniel Dunbar223ebe32009-11-17 05:05:08 +0000786void clang::InitializeAnalyzerOptions(AnalyzerOptions &Opts) {
787 using namespace analyzeroptions;
788 Opts.AnalysisList = AnalysisList;
789 Opts.AnalysisStoreOpt = AnalysisStoreOpt;
790 Opts.AnalysisConstraintsOpt = AnalysisConstraintsOpt;
791 Opts.AnalysisDiagOpt = AnalysisDiagOpt;
792 Opts.VisualizeEGDot = VisualizeEGDot;
793 Opts.VisualizeEGUbi = VisualizeEGUbi;
794 Opts.AnalyzeAll = AnalyzeAll;
795 Opts.AnalyzerDisplayProgress = AnalyzerDisplayProgress;
796 Opts.PurgeDead = PurgeDead;
797 Opts.EagerlyAssume = EagerlyAssume;
798 Opts.AnalyzeSpecificFunction = AnalyzeSpecificFunction;
799 Opts.EnableExperimentalChecks = AnalyzerExperimentalChecks;
800 Opts.EnableExperimentalInternalChecks = AnalyzerExperimentalInternalChecks;
801 Opts.TrimGraph = TrimGraph;
802}
803
Daniel Dunbar6143ea22009-11-16 22:38:14 +0000804void clang::InitializeCodeGenOptions(CodeGenOptions &Opts,
805 const LangOptions &Lang,
806 bool TimePasses) {
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000807 using namespace codegenoptions;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000808
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000809 // -Os implies -O2
810 Opts.OptimizationLevel = OptSize ? 2 : OptLevel;
811
812 // We must always run at least the always inlining pass.
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000813 Opts.Inlining = (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining
814 : CodeGenOptions::OnlyAlwaysInlining;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000815
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000816 Opts.DebugInfo = GenerateDebugInfo;
817 Opts.DisableLLVMOpts = DisableLLVMOptimizations;
818 Opts.DisableRedZone = DisableRedZone;
819 Opts.MergeAllConstants = !NoMergeConstants;
820 Opts.NoCommon = NoCommon;
821 Opts.NoImplicitFloat = NoImplicitFloat;
822 Opts.OptimizeSize = OptSize;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000823 Opts.SimplifyLibCalls = 1;
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000824 Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize);
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000825
Daniel Dunbar6143ea22009-11-16 22:38:14 +0000826 // FIXME: Eliminate this dependency?
827 if (Lang.NoBuiltin)
828 Opts.SimplifyLibCalls = 0;
829 if (Lang.CPlusPlus)
830 Opts.NoCommon = 1;
831 Opts.TimePasses = TimePasses;
832
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000833#ifdef NDEBUG
834 Opts.VerifyModule = 0;
835#endif
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000836}
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000837
Daniel Dunbar0e0bae82009-11-11 21:43:12 +0000838void clang::InitializeDependencyOutputOptions(DependencyOutputOptions &Opts) {
839 using namespace dependencyoutputoptions;
840
841 Opts.OutputFile = DependencyFile;
Daniel Dunbar26266882009-11-12 23:52:32 +0000842 Opts.Targets = DependencyTargets;
Daniel Dunbar0e0bae82009-11-11 21:43:12 +0000843 Opts.IncludeSystemHeaders = DependenciesIncludeSystemHeaders;
844 Opts.UsePhonyTargets = PhonyDependencyTarget;
845}
846
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000847void clang::InitializeDiagnosticOptions(DiagnosticOptions &Opts) {
848 using namespace diagnosticoptions;
849
Daniel Dunbar26266882009-11-12 23:52:32 +0000850 Opts.Warnings = OptWarnings;
Daniel Dunbar11e729d2009-11-12 07:28:21 +0000851 Opts.DumpBuildInformation = DumpBuildInformation;
Daniel Dunbar69079432009-11-12 07:28:44 +0000852 Opts.IgnoreWarnings = OptNoWarnings;
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000853 Opts.MessageLength = MessageLength;
Daniel Dunbar69079432009-11-12 07:28:44 +0000854 Opts.NoRewriteMacros = SilenceRewriteMacroWarning;
855 Opts.Pedantic = OptPedantic;
856 Opts.PedanticErrors = OptPedanticErrors;
Daniel Dunbar11e729d2009-11-12 07:28:21 +0000857 Opts.ShowCarets = !NoCaretDiagnostics;
858 Opts.ShowColors = PrintColorDiagnostic;
859 Opts.ShowColumn = !NoShowColumn;
860 Opts.ShowFixits = !NoDiagnosticsFixIt;
861 Opts.ShowLocation = !NoShowLocation;
862 Opts.ShowOptionNames = PrintDiagnosticOption;
863 Opts.ShowSourceRanges = PrintSourceRangeInfo;
Daniel Dunbar26266882009-11-12 23:52:32 +0000864 Opts.VerifyDiagnostics = VerifyDiagnostics;
865}
866
867void clang::InitializeFrontendOptions(FrontendOptions &Opts) {
868 using namespace frontendoptions;
869
Daniel Dunbard10c5b82009-11-15 00:12:04 +0000870 // Select program action.
871 Opts.ProgramAction = ProgAction;
872 if (PluginActionName.getPosition()) {
873 Opts.ProgramAction = frontend::PluginAction;
874 Opts.ActionName = PluginActionName;
875 }
876
Daniel Dunbar914474c2009-11-13 01:02:10 +0000877 Opts.CodeCompletionAt = CodeCompletionAt;
878 Opts.DebugCodeCompletionPrinter = CodeCompletionDebugPrinter;
Daniel Dunbar26266882009-11-12 23:52:32 +0000879 Opts.DisableFree = DisableFree;
880 Opts.EmptyInputOnly = EmptyInputOnly;
Daniel Dunbarc86804b2009-11-12 23:52:56 +0000881 Opts.FixItLocations = FixItAtLocations;
Daniel Dunbar26266882009-11-12 23:52:32 +0000882 Opts.OutputFile = OutputFile;
Daniel Dunbar914474c2009-11-13 01:02:10 +0000883 Opts.RelocatablePCH = RelocatablePCH;
884 Opts.ShowMacrosInCodeCompletion = CodeCompletionWantsMacros;
885 Opts.ShowStats = Stats;
886 Opts.ShowTimers = TimeReport;
Daniel Dunbar26266882009-11-12 23:52:32 +0000887 Opts.ViewClassInheritance = InheritanceViewCls;
888
889 // '-' is the default input if none is given.
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +0000890 if (InputFilenames.empty()) {
891 FrontendOptions::InputKind IK = InputType;
892 if (IK == FrontendOptions::IK_None) IK = FrontendOptions::IK_C;
893 Opts.Inputs.push_back(std::make_pair(IK, "-"));
894 } else {
895 for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
896 FrontendOptions::InputKind IK = InputType;
897 llvm::StringRef Ext =
898 llvm::StringRef(InputFilenames[i]).rsplit('.').second;
899 if (IK == FrontendOptions::IK_None)
900 IK = FrontendOptions::getInputKindForExtension(Ext);
901 Opts.Inputs.push_back(std::make_pair(IK, InputFilenames[i]));
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +0000902 }
903 }
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000904}
905
Daniel Dunbarf7973292009-11-11 08:13:32 +0000906void clang::InitializeHeaderSearchOptions(HeaderSearchOptions &Opts,
Daniel Dunbarc363cb12009-11-16 22:38:40 +0000907 llvm::StringRef BuiltinIncludePath) {
Daniel Dunbarf7973292009-11-11 08:13:32 +0000908 using namespace headersearchoptions;
909
910 Opts.Sysroot = isysroot;
911 Opts.Verbose = Verbose;
912
913 // Handle -I... and -F... options, walking the lists in parallel.
914 unsigned Iidx = 0, Fidx = 0;
915 while (Iidx < I_dirs.size() && Fidx < F_dirs.size()) {
916 if (I_dirs.getPosition(Iidx) < F_dirs.getPosition(Fidx)) {
Daniel Dunbar1b483e72009-11-17 05:04:15 +0000917 Opts.AddPath(I_dirs[Iidx], frontend::Angled, true, false);
Daniel Dunbarf7973292009-11-11 08:13:32 +0000918 ++Iidx;
919 } else {
Daniel Dunbar1b483e72009-11-17 05:04:15 +0000920 Opts.AddPath(F_dirs[Fidx], frontend::Angled, true, true);
Daniel Dunbarf7973292009-11-11 08:13:32 +0000921 ++Fidx;
922 }
923 }
924
925 // Consume what's left from whatever list was longer.
926 for (; Iidx != I_dirs.size(); ++Iidx)
Daniel Dunbar1b483e72009-11-17 05:04:15 +0000927 Opts.AddPath(I_dirs[Iidx], frontend::Angled, true, false);
Daniel Dunbarf7973292009-11-11 08:13:32 +0000928 for (; Fidx != F_dirs.size(); ++Fidx)
Daniel Dunbar1b483e72009-11-17 05:04:15 +0000929 Opts.AddPath(F_dirs[Fidx], frontend::Angled, true, true);
Daniel Dunbarf7973292009-11-11 08:13:32 +0000930
931 // Handle -idirafter... options.
932 for (unsigned i = 0, e = idirafter_dirs.size(); i != e; ++i)
Daniel Dunbar1b483e72009-11-17 05:04:15 +0000933 Opts.AddPath(idirafter_dirs[i], frontend::After, true, false);
Daniel Dunbarf7973292009-11-11 08:13:32 +0000934
935 // Handle -iquote... options.
936 for (unsigned i = 0, e = iquote_dirs.size(); i != e; ++i)
Daniel Dunbar1b483e72009-11-17 05:04:15 +0000937 Opts.AddPath(iquote_dirs[i], frontend::Quoted, true, false);
Daniel Dunbarf7973292009-11-11 08:13:32 +0000938
939 // Handle -isystem... options.
940 for (unsigned i = 0, e = isystem_dirs.size(); i != e; ++i)
Daniel Dunbar1b483e72009-11-17 05:04:15 +0000941 Opts.AddPath(isystem_dirs[i], frontend::System, true, false);
Daniel Dunbarf7973292009-11-11 08:13:32 +0000942
943 // Walk the -iprefix/-iwithprefix/-iwithprefixbefore argument lists in
944 // parallel, processing the values in order of occurance to get the right
945 // prefixes.
946 {
947 std::string Prefix = ""; // FIXME: this isn't the correct default prefix.
948 unsigned iprefix_idx = 0;
949 unsigned iwithprefix_idx = 0;
950 unsigned iwithprefixbefore_idx = 0;
951 bool iprefix_done = iprefix_vals.empty();
952 bool iwithprefix_done = iwithprefix_vals.empty();
953 bool iwithprefixbefore_done = iwithprefixbefore_vals.empty();
954 while (!iprefix_done || !iwithprefix_done || !iwithprefixbefore_done) {
955 if (!iprefix_done &&
956 (iwithprefix_done ||
957 iprefix_vals.getPosition(iprefix_idx) <
958 iwithprefix_vals.getPosition(iwithprefix_idx)) &&
959 (iwithprefixbefore_done ||
960 iprefix_vals.getPosition(iprefix_idx) <
961 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
962 Prefix = iprefix_vals[iprefix_idx];
963 ++iprefix_idx;
964 iprefix_done = iprefix_idx == iprefix_vals.size();
965 } else if (!iwithprefix_done &&
966 (iwithprefixbefore_done ||
967 iwithprefix_vals.getPosition(iwithprefix_idx) <
968 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
969 Opts.AddPath(Prefix+iwithprefix_vals[iwithprefix_idx],
Daniel Dunbar1b483e72009-11-17 05:04:15 +0000970 frontend::System, false, false);
Daniel Dunbarf7973292009-11-11 08:13:32 +0000971 ++iwithprefix_idx;
972 iwithprefix_done = iwithprefix_idx == iwithprefix_vals.size();
973 } else {
974 Opts.AddPath(Prefix+iwithprefixbefore_vals[iwithprefixbefore_idx],
Daniel Dunbar1b483e72009-11-17 05:04:15 +0000975 frontend::Angled, false, false);
Daniel Dunbarf7973292009-11-11 08:13:32 +0000976 ++iwithprefixbefore_idx;
977 iwithprefixbefore_done =
978 iwithprefixbefore_idx == iwithprefixbefore_vals.size();
979 }
980 }
981 }
982
983 // Add CPATH environment paths.
984 if (const char *Env = getenv("CPATH"))
985 Opts.EnvIncPath = Env;
986
987 // Add language specific environment paths.
Daniel Dunbarc363cb12009-11-16 22:38:40 +0000988 if (const char *Env = getenv("OBJCPLUS_INCLUDE_PATH"))
989 Opts.ObjCXXEnvIncPath = Env;
990 if (const char *Env = getenv("CPLUS_INCLUDE_PATH"))
991 Opts.CXXEnvIncPath = Env;
992 if (const char *Env = getenv("OBJC_INCLUDE_PATH"))
993 Opts.CEnvIncPath = Env;
994 if (const char *Env = getenv("C_INCLUDE_PATH"))
995 Opts.CEnvIncPath = Env;
Daniel Dunbarf7973292009-11-11 08:13:32 +0000996
997 if (!nobuiltininc)
998 Opts.BuiltinIncludePath = BuiltinIncludePath;
999
1000 Opts.UseStandardIncludes = !nostdinc;
1001}
1002
Daniel Dunbarb52d2432009-11-11 06:10:03 +00001003void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) {
1004 using namespace preprocessoroptions;
1005
Daniel Dunbar049d3a02009-11-17 05:52:41 +00001006 Opts.ImplicitPCHInclude = ImplicitIncludePCH;
1007 Opts.ImplicitPTHInclude = ImplicitIncludePTH;
Daniel Dunbarb52d2432009-11-11 06:10:03 +00001008
Daniel Dunbarb3cb98e2009-11-12 02:53:59 +00001009 // Select the token cache file, we don't support more than one currently so we
1010 // can't have both an implicit-pth and a token cache file.
1011 if (TokenCache.getPosition() && ImplicitIncludePTH.getPosition()) {
1012 // FIXME: Don't fail like this.
1013 fprintf(stderr, "error: cannot use both -token-cache and -include-pth "
1014 "options\n");
1015 exit(1);
1016 }
1017 if (TokenCache.getPosition())
Daniel Dunbar049d3a02009-11-17 05:52:41 +00001018 Opts.TokenCache = TokenCache;
Daniel Dunbarb3cb98e2009-11-12 02:53:59 +00001019 else
Daniel Dunbar049d3a02009-11-17 05:52:41 +00001020 Opts.TokenCache = ImplicitIncludePTH;
Daniel Dunbarb3cb98e2009-11-12 02:53:59 +00001021
Daniel Dunbarb52d2432009-11-11 06:10:03 +00001022 // Use predefines?
Daniel Dunbar049d3a02009-11-17 05:52:41 +00001023 Opts.UsePredefines = !UndefMacros;
Daniel Dunbarb52d2432009-11-11 06:10:03 +00001024
1025 // Add macros from the command line.
1026 unsigned d = 0, D = D_macros.size();
1027 unsigned u = 0, U = U_macros.size();
1028 while (d < D || u < U) {
1029 if (u == U || (d < D && D_macros.getPosition(d) < U_macros.getPosition(u)))
1030 Opts.addMacroDef(D_macros[d++]);
1031 else
1032 Opts.addMacroUndef(U_macros[u++]);
1033 }
1034
1035 // If -imacros are specified, include them now. These are processed before
1036 // any -include directives.
1037 for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i)
Daniel Dunbar049d3a02009-11-17 05:52:41 +00001038 Opts.MacroIncludes.push_back(ImplicitMacroIncludes[i]);
Daniel Dunbarb52d2432009-11-11 06:10:03 +00001039
1040 // Add the ordered list of -includes, sorting in the implicit include options
1041 // at the appropriate location.
1042 llvm::SmallVector<std::pair<unsigned, std::string*>, 8> OrderedPaths;
1043 std::string OriginalFile;
1044
1045 if (!ImplicitIncludePTH.empty())
1046 OrderedPaths.push_back(std::make_pair(ImplicitIncludePTH.getPosition(),
1047 &ImplicitIncludePTH));
1048 if (!ImplicitIncludePCH.empty()) {
1049 OriginalFile = PCHReader::getOriginalSourceFile(ImplicitIncludePCH);
1050 // FIXME: Don't fail like this.
1051 if (OriginalFile.empty())
1052 exit(1);
1053 OrderedPaths.push_back(std::make_pair(ImplicitIncludePCH.getPosition(),
1054 &OriginalFile));
1055 }
1056 for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i)
1057 OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i),
1058 &ImplicitIncludes[i]));
1059 llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end());
1060
1061 for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i)
Daniel Dunbar049d3a02009-11-17 05:52:41 +00001062 Opts.Includes.push_back(*OrderedPaths[i].second);
Daniel Dunbarb52d2432009-11-11 06:10:03 +00001063}
Daniel Dunbar56749082009-11-11 07:26:12 +00001064
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001065void clang::InitializeLangOptions(LangOptions &Options,
1066 FrontendOptions::InputKind IK,
Daniel Dunbar6143ea22009-11-16 22:38:14 +00001067 TargetInfo &Target) {
Daniel Dunbar56749082009-11-11 07:26:12 +00001068 using namespace langoptions;
1069
Daniel Dunbar56749082009-11-11 07:26:12 +00001070
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001071 switch (IK) {
1072 case FrontendOptions::IK_None:
1073 case FrontendOptions::IK_AST:
1074 assert(0 && "Invalid input kind!");
1075 case FrontendOptions::IK_Asm:
Daniel Dunbar56749082009-11-11 07:26:12 +00001076 Options.AsmPreprocessor = 1;
1077 // FALLTHROUGH
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001078 case FrontendOptions::IK_PreprocessedC:
Daniel Dunbar56749082009-11-11 07:26:12 +00001079 // FALLTHROUGH
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001080 case FrontendOptions::IK_C:
Daniel Dunbar56749082009-11-11 07:26:12 +00001081 // Do nothing.
1082 break;
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001083 case FrontendOptions::IK_PreprocessedCXX:
Daniel Dunbar56749082009-11-11 07:26:12 +00001084 // FALLTHROUGH
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001085 case FrontendOptions::IK_CXX:
Daniel Dunbar56749082009-11-11 07:26:12 +00001086 Options.CPlusPlus = 1;
1087 break;
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001088 case FrontendOptions::IK_PreprocessedObjC:
Daniel Dunbar56749082009-11-11 07:26:12 +00001089 // FALLTHROUGH
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001090 case FrontendOptions::IK_ObjC:
Daniel Dunbar56749082009-11-11 07:26:12 +00001091 Options.ObjC1 = Options.ObjC2 = 1;
1092 break;
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001093 case FrontendOptions::IK_PreprocessedObjCXX:
Daniel Dunbar56749082009-11-11 07:26:12 +00001094 // FALLTHROUGH
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001095 case FrontendOptions::IK_ObjCXX:
Daniel Dunbar56749082009-11-11 07:26:12 +00001096 Options.ObjC1 = Options.ObjC2 = 1;
1097 Options.CPlusPlus = 1;
1098 break;
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001099 case FrontendOptions::IK_OpenCL:
Daniel Dunbar56749082009-11-11 07:26:12 +00001100 Options.OpenCL = 1;
1101 Options.AltiVec = 1;
1102 Options.CXXOperatorNames = 1;
1103 Options.LaxVectorConversions = 1;
1104 break;
1105 }
1106
1107 if (ObjCExclusiveGC)
1108 Options.setGCMode(LangOptions::GCOnly);
1109 else if (ObjCEnableGC)
1110 Options.setGCMode(LangOptions::HybridGC);
1111
1112 if (ObjCEnableGCBitmapPrint)
1113 Options.ObjCGCBitmapPrint = 1;
1114
1115 if (AltiVec)
1116 Options.AltiVec = 1;
1117
1118 if (PThread)
1119 Options.POSIXThreads = 1;
1120
1121 Options.setVisibilityMode(SymbolVisibility);
1122 Options.OverflowChecking = OverflowChecking;
1123
Daniel Dunbar56749082009-11-11 07:26:12 +00001124 if (LangStd == lang_unspecified) {
1125 // Based on the base language, pick one.
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001126 switch (IK) {
1127 case FrontendOptions::IK_None:
1128 case FrontendOptions::IK_AST:
1129 assert(0 && "Invalid input kind!");
1130 case FrontendOptions::IK_OpenCL:
Daniel Dunbar56749082009-11-11 07:26:12 +00001131 LangStd = lang_c99;
1132 break;
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001133 case FrontendOptions::IK_Asm:
1134 case FrontendOptions::IK_C:
1135 case FrontendOptions::IK_PreprocessedC:
1136 case FrontendOptions::IK_ObjC:
1137 case FrontendOptions::IK_PreprocessedObjC:
Daniel Dunbar56749082009-11-11 07:26:12 +00001138 LangStd = lang_gnu99;
1139 break;
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001140 case FrontendOptions::IK_CXX:
1141 case FrontendOptions::IK_PreprocessedCXX:
1142 case FrontendOptions::IK_ObjCXX:
1143 case FrontendOptions::IK_PreprocessedObjCXX:
Daniel Dunbar56749082009-11-11 07:26:12 +00001144 LangStd = lang_gnucxx98;
1145 break;
1146 }
1147 }
1148
1149 switch (LangStd) {
1150 default: assert(0 && "Unknown language standard!");
1151
1152 // Fall through from newer standards to older ones. This isn't really right.
1153 // FIXME: Enable specifically the right features based on the language stds.
1154 case lang_gnucxx0x:
1155 case lang_cxx0x:
1156 Options.CPlusPlus0x = 1;
1157 // FALL THROUGH
1158 case lang_gnucxx98:
1159 case lang_cxx98:
1160 Options.CPlusPlus = 1;
1161 Options.CXXOperatorNames = !NoOperatorNames;
1162 // FALL THROUGH.
1163 case lang_gnu99:
1164 case lang_c99:
1165 Options.C99 = 1;
1166 Options.HexFloats = 1;
1167 // FALL THROUGH.
1168 case lang_gnu89:
1169 Options.BCPLComment = 1; // Only for C99/C++.
1170 // FALL THROUGH.
1171 case lang_c94:
1172 Options.Digraphs = 1; // C94, C99, C++.
1173 // FALL THROUGH.
1174 case lang_c89:
1175 break;
1176 }
1177
1178 // GNUMode - Set if we're in gnu99, gnu89, gnucxx98, etc.
1179 switch (LangStd) {
1180 default: assert(0 && "Unknown language standard!");
1181 case lang_gnucxx0x:
1182 case lang_gnucxx98:
1183 case lang_gnu99:
1184 case lang_gnu89:
1185 Options.GNUMode = 1;
1186 break;
1187 case lang_cxx0x:
1188 case lang_cxx98:
1189 case lang_c99:
1190 case lang_c94:
1191 case lang_c89:
1192 Options.GNUMode = 0;
1193 break;
1194 }
1195
1196 if (Options.CPlusPlus) {
1197 Options.C99 = 0;
1198 Options.HexFloats = 0;
1199 }
1200
1201 if (LangStd == lang_c89 || LangStd == lang_c94 || LangStd == lang_gnu89)
1202 Options.ImplicitInt = 1;
1203 else
1204 Options.ImplicitInt = 0;
1205
1206 // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
1207 // is specified, or -std is set to a conforming mode.
1208 Options.Trigraphs = !Options.GNUMode;
1209 if (Trigraphs.getPosition())
1210 Options.Trigraphs = Trigraphs; // Command line option wins if specified.
1211
1212 // If in a conformant language mode (e.g. -std=c99) Blocks defaults to off
1213 // even if they are normally on for the target. In GNU modes (e.g.
1214 // -std=gnu99) the default for blocks depends on the target settings.
1215 // However, blocks are not turned off when compiling Obj-C or Obj-C++ code.
1216 if (!Options.ObjC1 && !Options.GNUMode)
1217 Options.Blocks = 0;
1218
1219 // Default to not accepting '$' in identifiers when preprocessing assembler,
1220 // but do accept when preprocessing C. FIXME: these defaults are right for
1221 // darwin, are they right everywhere?
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001222 Options.DollarIdents = IK != FrontendOptions::IK_Asm;
Daniel Dunbar56749082009-11-11 07:26:12 +00001223 if (DollarsInIdents.getPosition()) // Explicit setting overrides default.
1224 Options.DollarIdents = DollarsInIdents;
1225
1226 if (PascalStrings.getPosition())
1227 Options.PascalStrings = PascalStrings;
1228 if (MSExtensions.getPosition())
1229 Options.Microsoft = MSExtensions;
1230 Options.WritableStrings = WritableStrings;
1231 if (NoLaxVectorConversions.getPosition())
1232 Options.LaxVectorConversions = 0;
1233 Options.Exceptions = Exceptions;
1234 Options.Rtti = Rtti;
1235 if (EnableBlocks.getPosition())
1236 Options.Blocks = EnableBlocks;
1237 if (CharIsSigned.getPosition())
1238 Options.CharIsSigned = CharIsSigned;
1239 if (ShortWChar.getPosition())
1240 Options.ShortWChar = ShortWChar;
1241
1242 if (!AllowBuiltins)
1243 Options.NoBuiltin = 1;
1244 if (Freestanding)
1245 Options.Freestanding = Options.NoBuiltin = 1;
1246
1247 if (EnableHeinousExtensions)
1248 Options.HeinousExtensions = 1;
1249
1250 if (AccessControl)
1251 Options.AccessControl = 1;
1252
1253 Options.ElideConstructors = !NoElideConstructors;
1254
1255 // OpenCL and C++ both have bool, true, false keywords.
1256 Options.Bool = Options.OpenCL | Options.CPlusPlus;
1257
1258 Options.MathErrno = MathErrno;
1259
1260 Options.InstantiationDepth = TemplateDepth;
1261
1262 // Override the default runtime if the user requested it.
Daniel Dunbarc5a97ec2009-11-17 07:07:28 +00001263 if (GNURuntime)
Daniel Dunbar56749082009-11-11 07:26:12 +00001264 Options.NeXTRuntime = 0;
1265
1266 if (!ObjCConstantStringClass.empty())
1267 Options.ObjCConstantStringClass = ObjCConstantStringClass.c_str();
1268
1269 if (ObjCNonFragileABI)
1270 Options.ObjCNonFragileABI = 1;
1271
1272 if (EmitAllDecls)
1273 Options.EmitAllDecls = 1;
1274
1275 // The __OPTIMIZE_SIZE__ define is tied to -Oz, which we don't support.
1276 Options.OptimizeSize = 0;
Daniel Dunbar6143ea22009-11-16 22:38:14 +00001277 Options.Optimize = codegenoptions::OptSize || codegenoptions::OptLevel;
Daniel Dunbar56749082009-11-11 07:26:12 +00001278
1279 assert(PICLevel <= 2 && "Invalid value for -pic-level");
1280 Options.PICLevel = PICLevel;
1281
1282 Options.GNUInline = !Options.C99;
Daniel Dunbar56749082009-11-11 07:26:12 +00001283
1284 // This is the __NO_INLINE__ define, which just depends on things like the
1285 // optimization level and -fno-inline, not actually whether the backend has
1286 // inlining enabled.
Daniel Dunbar6143ea22009-11-16 22:38:14 +00001287 //
1288 // FIXME: This is affected by other options (-fno-inline).
1289 Options.NoInline = !codegenoptions::OptLevel;
Daniel Dunbar56749082009-11-11 07:26:12 +00001290
1291 Options.Static = StaticDefine;
1292
1293 switch (StackProtector) {
1294 default:
1295 assert(StackProtector <= 2 && "Invalid value for -stack-protector");
1296 case -1: break;
1297 case 0: Options.setStackProtectorMode(LangOptions::SSPOff); break;
1298 case 1: Options.setStackProtectorMode(LangOptions::SSPOn); break;
1299 case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break;
1300 }
1301
1302 if (MainFileName.getPosition())
1303 Options.setMainFileName(MainFileName.c_str());
1304
1305 Target.setForcedLangOptions(Options);
1306}
Daniel Dunbar29cf7462009-11-11 10:07:44 +00001307
1308void
1309clang::InitializePreprocessorOutputOptions(PreprocessorOutputOptions &Opts) {
1310 using namespace preprocessoroutputoptions;
1311
1312 Opts.ShowCPP = !DumpMacros;
1313 Opts.ShowMacros = DumpMacros || DumpDefines;
1314 Opts.ShowLineMarkers = !DisableLineMarkers;
1315 Opts.ShowComments = EnableCommentOutput;
1316 Opts.ShowMacroComments = EnableMacroCommentOutput;
1317}
Daniel Dunbard58c03f2009-11-15 06:48:46 +00001318
1319void clang::InitializeTargetOptions(TargetOptions &Opts) {
1320 using namespace targetoptions;
1321
1322 Opts.ABI = TargetABI;
1323 Opts.CPU = TargetCPU;
1324 Opts.Triple = TargetTriple;
1325 Opts.Features = TargetFeatures;
1326
1327 // Use the host triple if unspecified.
1328 if (Opts.Triple.empty())
1329 Opts.Triple = llvm::sys::getHostTriple();
1330}