blob: e27d6973779d852510f81fc6045a4f4ca684ccae [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>
Daniel Dunbar484afa22009-11-19 04:55:23 +0000107NoPurgeDead("analyzer-no-purge-dead",
Daniel Dunbard8027782009-11-19 05:32:09 +0000108 llvm::cl::desc("Don't remove dead symbols, bindings, and constraints before"
Ted Kremenekaedb7432009-11-13 01:15:47 +0000109 " processing a statement"));
Daniel Dunbard2cfa012009-11-11 08:13:55 +0000110
111static llvm::cl::opt<bool>
112TrimGraph("trim-egraph",
113 llvm::cl::desc("Only show error-related paths in the analysis graph"));
114
115static llvm::cl::opt<bool>
116VisualizeEGDot("analyzer-viz-egraph-graphviz",
117 llvm::cl::desc("Display exploded graph using GraphViz"));
118
119static llvm::cl::opt<bool>
120VisualizeEGUbi("analyzer-viz-egraph-ubigraph",
121 llvm::cl::desc("Display exploded graph using Ubigraph"));
122
123}
124
Daniel Dunbard2cfa012009-11-11 08:13:55 +0000125//===----------------------------------------------------------------------===//
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000126// Code Generation Options
127//===----------------------------------------------------------------------===//
128
129namespace codegenoptions {
130
131static llvm::cl::opt<bool>
132DisableLLVMOptimizations("disable-llvm-optzns",
133 llvm::cl::desc("Don't run LLVM optimization passes"));
134
135static llvm::cl::opt<bool>
136DisableRedZone("disable-red-zone",
Daniel Dunbar71f5f9f2009-11-19 04:55:06 +0000137 llvm::cl::desc("Do not emit code that uses the red zone."));
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000138
139static llvm::cl::opt<bool>
140GenerateDebugInfo("g",
141 llvm::cl::desc("Generate source level debug information"));
142
143static llvm::cl::opt<bool>
144NoCommon("fno-common",
145 llvm::cl::desc("Compile common globals like normal definitions"),
146 llvm::cl::ValueDisallowed);
147
148static llvm::cl::opt<bool>
149NoImplicitFloat("no-implicit-float",
Daniel Dunbar71f5f9f2009-11-19 04:55:06 +0000150 llvm::cl::desc("Don't generate implicit floating point instructions (x86-only)"));
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000151
152static llvm::cl::opt<bool>
153NoMergeConstants("fno-merge-all-constants",
154 llvm::cl::desc("Disallow merging of constants."));
155
156// It might be nice to add bounds to the CommandLine library directly.
157struct OptLevelParser : public llvm::cl::parser<unsigned> {
158 bool parse(llvm::cl::Option &O, llvm::StringRef ArgName,
159 llvm::StringRef Arg, unsigned &Val) {
160 if (llvm::cl::parser<unsigned>::parse(O, ArgName, Arg, Val))
161 return true;
162 if (Val > 3)
163 return O.error("'" + Arg + "' invalid optimization level!");
164 return false;
165 }
166};
167static llvm::cl::opt<unsigned, false, OptLevelParser>
168OptLevel("O", llvm::cl::Prefix,
169 llvm::cl::desc("Optimization level"),
170 llvm::cl::init(0));
171
172static llvm::cl::opt<bool>
173OptSize("Os", llvm::cl::desc("Optimize for size"));
174
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000175}
176
177//===----------------------------------------------------------------------===//
Daniel Dunbar89d1fdf2009-11-11 21:43:12 +0000178// Dependency Output Options
179//===----------------------------------------------------------------------===//
180
181namespace dependencyoutputoptions {
182
183static llvm::cl::opt<std::string>
184DependencyFile("dependency-file",
185 llvm::cl::desc("Filename (or -) to write dependency output to"));
186
187static llvm::cl::opt<bool>
188DependenciesIncludeSystemHeaders("sys-header-deps",
189 llvm::cl::desc("Include system headers in dependency output"));
190
191static llvm::cl::list<std::string>
192DependencyTargets("MT",
193 llvm::cl::desc("Specify target for dependency"));
194
195static llvm::cl::opt<bool>
196PhonyDependencyTarget("MP",
197 llvm::cl::desc("Create phony target for each dependency "
198 "(other than main file)"));
199
200}
201
202//===----------------------------------------------------------------------===//
Daniel Dunbardcd40fb2009-11-11 08:13:40 +0000203// Diagnostic Options
204//===----------------------------------------------------------------------===//
205
206namespace diagnosticoptions {
207
Daniel Dunbar8fd69a02009-11-12 07:28:21 +0000208static llvm::cl::opt<std::string>
209DumpBuildInformation("dump-build-information",
210 llvm::cl::value_desc("filename"),
211 llvm::cl::desc("output a dump of some build information to a file"));
212
Daniel Dunbardcd40fb2009-11-11 08:13:40 +0000213static llvm::cl::opt<bool>
214NoShowColumn("fno-show-column",
215 llvm::cl::desc("Do not include column number on diagnostics"));
216
217static llvm::cl::opt<bool>
218NoShowLocation("fno-show-source-location",
219 llvm::cl::desc("Do not include source location information with"
220 " diagnostics"));
221
222static llvm::cl::opt<bool>
223NoCaretDiagnostics("fno-caret-diagnostics",
224 llvm::cl::desc("Do not include source line and caret with"
225 " diagnostics"));
226
227static llvm::cl::opt<bool>
228NoDiagnosticsFixIt("fno-diagnostics-fixit-info",
229 llvm::cl::desc("Do not include fixit information in"
230 " diagnostics"));
231
Daniel Dunbar4c0e8272009-11-12 07:28:44 +0000232static llvm::cl::opt<bool> OptNoWarnings("w");
233
234static llvm::cl::opt<bool> OptPedantic("pedantic");
235
236static llvm::cl::opt<bool> OptPedanticErrors("pedantic-errors");
237
238// This gets all -W options, including -Werror, -W[no-]system-headers, etc. The
239// driver has stripped off -Wa,foo etc. The driver has also translated -W to
240// -Wextra, so we don't need to worry about it.
241static llvm::cl::list<std::string>
242OptWarnings("W", llvm::cl::Prefix, llvm::cl::ValueOptional);
243
Daniel Dunbardcd40fb2009-11-11 08:13:40 +0000244static llvm::cl::opt<bool>
245PrintSourceRangeInfo("fdiagnostics-print-source-range-info",
246 llvm::cl::desc("Print source range spans in numeric form"));
247
248static llvm::cl::opt<bool>
249PrintDiagnosticOption("fdiagnostics-show-option",
250 llvm::cl::desc("Print diagnostic name with mappable diagnostics"));
251
252static llvm::cl::opt<unsigned>
253MessageLength("fmessage-length",
254 llvm::cl::desc("Format message diagnostics so that they fit "
255 "within N columns or fewer, when possible."),
256 llvm::cl::value_desc("N"));
257
258static llvm::cl::opt<bool>
259PrintColorDiagnostic("fcolor-diagnostics",
260 llvm::cl::desc("Use colors in diagnostics"));
261
Daniel Dunbar4c0e8272009-11-12 07:28:44 +0000262static llvm::cl::opt<bool>
Daniel Dunbar71f5f9f2009-11-19 04:55:06 +0000263SilenceRewriteMacroWarning("Wno-rewrite-macros",
Daniel Dunbar4c0e8272009-11-12 07:28:44 +0000264 llvm::cl::desc("Silence ObjC rewriting warnings"));
265
Daniel Dunbarf996c052009-11-12 23:52:32 +0000266static llvm::cl::opt<bool>
267VerifyDiagnostics("verify",
268 llvm::cl::desc("Verify emitted diagnostics and warnings"));
269
270}
271
Daniel Dunbarf996c052009-11-12 23:52:32 +0000272//===----------------------------------------------------------------------===//
273// Frontend Options
274//===----------------------------------------------------------------------===//
275
276namespace frontendoptions {
277
Daniel Dunbar7fbd42f2009-11-14 22:32:38 +0000278using namespace clang::frontend;
279
Daniel Dunbar4a1f60f2009-11-13 01:02:10 +0000280static llvm::cl::opt<ParsedSourceLocation>
281CodeCompletionAt("code-completion-at",
282 llvm::cl::value_desc("file:line:column"),
283 llvm::cl::desc("Dump code-completion information at a location"));
284
285static llvm::cl::opt<bool>
Daniel Dunbard8027782009-11-19 05:32:09 +0000286NoCodeCompletionDebugPrinter("no-code-completion-debug-printer",
287 llvm::cl::desc("Don't the \"debug\" code-completion print"));
Daniel Dunbar4a1f60f2009-11-13 01:02:10 +0000288
289static llvm::cl::opt<bool>
290CodeCompletionWantsMacros("code-completion-macros",
291 llvm::cl::desc("Include macros in code-completion results"));
292
Daniel Dunbarf996c052009-11-12 23:52:32 +0000293static llvm::cl::opt<bool>
294DisableFree("disable-free",
Daniel Dunbar71f5f9f2009-11-19 04:55:06 +0000295 llvm::cl::desc("Disable freeing of memory on exit"));
Daniel Dunbarf996c052009-11-12 23:52:32 +0000296
297static llvm::cl::opt<bool>
298EmptyInputOnly("empty-input-only",
299 llvm::cl::desc("Force running on an empty input file"));
300
Daniel Dunbar27b19dc2009-11-13 02:06:12 +0000301static llvm::cl::opt<FrontendOptions::InputKind>
302InputType("x", llvm::cl::desc("Input language type"),
303 llvm::cl::init(FrontendOptions::IK_None),
304 llvm::cl::values(clEnumValN(FrontendOptions::IK_C, "c", "C"),
305 clEnumValN(FrontendOptions::IK_OpenCL, "cl", "OpenCL C"),
306 clEnumValN(FrontendOptions::IK_CXX, "c++", "C++"),
307 clEnumValN(FrontendOptions::IK_ObjC, "objective-c",
308 "Objective C"),
309 clEnumValN(FrontendOptions::IK_ObjCXX, "objective-c++",
310 "Objective C++"),
311 clEnumValN(FrontendOptions::IK_PreprocessedC,
312 "cpp-output",
313 "Preprocessed C"),
314 clEnumValN(FrontendOptions::IK_Asm,
315 "assembler-with-cpp",
316 "Assembly Source Codde"),
317 clEnumValN(FrontendOptions::IK_PreprocessedCXX,
318 "c++-cpp-output",
319 "Preprocessed C++"),
320 clEnumValN(FrontendOptions::IK_PreprocessedObjC,
321 "objective-c-cpp-output",
322 "Preprocessed Objective C"),
323 clEnumValN(FrontendOptions::IK_PreprocessedObjCXX,
324 "objective-c++-cpp-output",
325 "Preprocessed Objective C++"),
326 clEnumValN(FrontendOptions::IK_C, "c-header",
327 "C header"),
328 clEnumValN(FrontendOptions::IK_ObjC, "objective-c-header",
329 "Objective-C header"),
330 clEnumValN(FrontendOptions::IK_CXX, "c++-header",
331 "C++ header"),
332 clEnumValN(FrontendOptions::IK_ObjCXX,
333 "objective-c++-header",
334 "Objective-C++ header"),
335 clEnumValN(FrontendOptions::IK_AST, "ast",
336 "Clang AST"),
337 clEnumValEnd));
338
Daniel Dunbarf996c052009-11-12 23:52:32 +0000339static llvm::cl::list<std::string>
340InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input files>"));
341
342static llvm::cl::opt<std::string>
343InheritanceViewCls("cxx-inheritance-view",
344 llvm::cl::value_desc("class name"),
345 llvm::cl::desc("View C++ inheritance for a specified class"));
346
Daniel Dunbara5c3d982009-11-12 23:52:56 +0000347static llvm::cl::list<ParsedSourceLocation>
348FixItAtLocations("fixit-at", llvm::cl::value_desc("source-location"),
349 llvm::cl::desc("Perform Fix-It modifications at the given source location"));
350
Daniel Dunbarf996c052009-11-12 23:52:32 +0000351static llvm::cl::opt<std::string>
352OutputFile("o",
353 llvm::cl::value_desc("path"),
354 llvm::cl::desc("Specify output file"));
355
Daniel Dunbard392dd02009-11-15 00:12:04 +0000356static llvm::cl::opt<std::string>
357PluginActionName("plugin",
358 llvm::cl::desc("Use the named plugin action "
359 "(use \"help\" to list available options)"));
360
Daniel Dunbar7fbd42f2009-11-14 22:32:38 +0000361static llvm::cl::opt<ActionKind>
362ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
363 llvm::cl::init(ParseSyntaxOnly),
364 llvm::cl::values(
365 clEnumValN(RunPreprocessorOnly, "Eonly",
366 "Just run preprocessor, no output (for timings)"),
367 clEnumValN(PrintPreprocessedInput, "E",
368 "Run preprocessor, emit preprocessed file"),
369 clEnumValN(DumpRawTokens, "dump-raw-tokens",
370 "Lex file in raw mode and dump raw tokens"),
371 clEnumValN(RunAnalysis, "analyze",
372 "Run static analysis engine"),
373 clEnumValN(DumpTokens, "dump-tokens",
374 "Run preprocessor, dump internal rep of tokens"),
375 clEnumValN(ParseNoop, "parse-noop",
376 "Run parser with noop callbacks (for timings)"),
377 clEnumValN(ParseSyntaxOnly, "fsyntax-only",
378 "Run parser and perform semantic analysis"),
379 clEnumValN(FixIt, "fixit",
380 "Apply fix-it advice to the input source"),
381 clEnumValN(ParsePrintCallbacks, "parse-print-callbacks",
382 "Run parser and print each callback invoked"),
383 clEnumValN(EmitHTML, "emit-html",
384 "Output input source as HTML"),
385 clEnumValN(ASTPrint, "ast-print",
386 "Build ASTs and then pretty-print them"),
387 clEnumValN(ASTPrintXML, "ast-print-xml",
388 "Build ASTs and then print them in XML format"),
389 clEnumValN(ASTDump, "ast-dump",
390 "Build ASTs and then debug dump them"),
391 clEnumValN(ASTView, "ast-view",
392 "Build ASTs and view them with GraphViz"),
393 clEnumValN(PrintDeclContext, "print-decl-contexts",
394 "Print DeclContexts and their Decls"),
395 clEnumValN(DumpRecordLayouts, "dump-record-layouts",
396 "Dump record layout information"),
397 clEnumValN(GeneratePTH, "emit-pth",
398 "Generate pre-tokenized header file"),
399 clEnumValN(GeneratePCH, "emit-pch",
400 "Generate pre-compiled header file"),
401 clEnumValN(EmitAssembly, "S",
402 "Emit native assembly code"),
403 clEnumValN(EmitLLVM, "emit-llvm",
404 "Build ASTs then convert to LLVM, emit .ll file"),
405 clEnumValN(EmitBC, "emit-llvm-bc",
406 "Build ASTs then convert to LLVM, emit .bc file"),
407 clEnumValN(EmitLLVMOnly, "emit-llvm-only",
408 "Build ASTs and convert to LLVM, discarding output"),
409 clEnumValN(RewriteTest, "rewrite-test",
410 "Rewriter playground"),
411 clEnumValN(RewriteObjC, "rewrite-objc",
412 "Rewrite ObjC into C (code rewriter example)"),
413 clEnumValN(RewriteMacros, "rewrite-macros",
414 "Expand macros without full preprocessing"),
415 clEnumValN(RewriteBlocks, "rewrite-blocks",
416 "Rewrite Blocks to C"),
417 clEnumValEnd));
418
Daniel Dunbarf996c052009-11-12 23:52:32 +0000419static llvm::cl::opt<bool>
420RelocatablePCH("relocatable-pch",
421 llvm::cl::desc("Whether to build a relocatable precompiled "
422 "header"));
423static llvm::cl::opt<bool>
424Stats("print-stats",
425 llvm::cl::desc("Print performance metrics and statistics"));
426
427static llvm::cl::opt<bool>
428TimeReport("ftime-report",
429 llvm::cl::desc("Print the amount of time each "
430 "phase of compilation takes"));
431
Daniel Dunbardcd40fb2009-11-11 08:13:40 +0000432}
433
434//===----------------------------------------------------------------------===//
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000435// Language Options
436//===----------------------------------------------------------------------===//
437
438namespace langoptions {
439
440static llvm::cl::opt<bool>
Daniel Dunbar484afa22009-11-19 04:55:23 +0000441NoBuiltin("fno-builtin",
442 llvm::cl::desc("Disable implicit builtin knowledge of functions"));
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000443
444static llvm::cl::opt<bool>
Daniel Dunbar71f5f9f2009-11-19 04:55:06 +0000445AltiVec("faltivec", llvm::cl::desc("Enable AltiVec vector initializer syntax"));
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000446
447static llvm::cl::opt<bool>
448AccessControl("faccess-control",
449 llvm::cl::desc("Enable C++ access control"));
450
451static llvm::cl::opt<bool>
452CharIsSigned("fsigned-char",
453 llvm::cl::desc("Force char to be a signed/unsigned type"));
454
455static llvm::cl::opt<bool>
456DollarsInIdents("fdollars-in-identifiers",
457 llvm::cl::desc("Allow '$' in identifiers"));
458
459static llvm::cl::opt<bool>
460EmitAllDecls("femit-all-decls",
461 llvm::cl::desc("Emit all declarations, even if unused"));
462
463static llvm::cl::opt<bool>
464EnableBlocks("fblocks", llvm::cl::desc("enable the 'blocks' language feature"));
465
466static llvm::cl::opt<bool>
467EnableHeinousExtensions("fheinous-gnu-extensions",
468 llvm::cl::desc("enable GNU extensions that you really really shouldn't use"),
469 llvm::cl::ValueDisallowed, llvm::cl::Hidden);
470
471static llvm::cl::opt<bool>
472Exceptions("fexceptions",
473 llvm::cl::desc("Enable support for exception handling"));
474
475static llvm::cl::opt<bool>
476Freestanding("ffreestanding",
477 llvm::cl::desc("Assert that the compilation takes place in a "
478 "freestanding environment"));
479
480static llvm::cl::opt<bool>
481GNURuntime("fgnu-runtime",
482 llvm::cl::desc("Generate output compatible with the standard GNU "
483 "Objective-C runtime"));
484
485/// LangStds - Language standards we support.
486enum LangStds {
487 lang_unspecified,
488 lang_c89, lang_c94, lang_c99,
489 lang_gnu89, lang_gnu99,
490 lang_cxx98, lang_gnucxx98,
491 lang_cxx0x, lang_gnucxx0x
492};
493static llvm::cl::opt<LangStds>
494LangStd("std", llvm::cl::desc("Language standard to compile for"),
495 llvm::cl::init(lang_unspecified),
496 llvm::cl::values(clEnumValN(lang_c89, "c89", "ISO C 1990"),
497 clEnumValN(lang_c89, "c90", "ISO C 1990"),
498 clEnumValN(lang_c89, "iso9899:1990", "ISO C 1990"),
499 clEnumValN(lang_c94, "iso9899:199409",
500 "ISO C 1990 with amendment 1"),
501 clEnumValN(lang_c99, "c99", "ISO C 1999"),
502 clEnumValN(lang_c99, "c9x", "ISO C 1999"),
503 clEnumValN(lang_c99, "iso9899:1999", "ISO C 1999"),
504 clEnumValN(lang_c99, "iso9899:199x", "ISO C 1999"),
505 clEnumValN(lang_gnu89, "gnu89",
506 "ISO C 1990 with GNU extensions"),
507 clEnumValN(lang_gnu99, "gnu99",
508 "ISO C 1999 with GNU extensions (default for C)"),
509 clEnumValN(lang_gnu99, "gnu9x",
510 "ISO C 1999 with GNU extensions"),
511 clEnumValN(lang_cxx98, "c++98",
512 "ISO C++ 1998 with amendments"),
513 clEnumValN(lang_gnucxx98, "gnu++98",
514 "ISO C++ 1998 with amendments and GNU "
515 "extensions (default for C++)"),
516 clEnumValN(lang_cxx0x, "c++0x",
517 "Upcoming ISO C++ 200x with amendments"),
518 clEnumValN(lang_gnucxx0x, "gnu++0x",
519 "Upcoming ISO C++ 200x with amendments and GNU "
520 "extensions"),
521 clEnumValEnd));
522
523static llvm::cl::opt<bool>
524MSExtensions("fms-extensions",
525 llvm::cl::desc("Accept some non-standard constructs used in "
526 "Microsoft header files "));
527
528static llvm::cl::opt<std::string>
529MainFileName("main-file-name",
530 llvm::cl::desc("Main file name to use for debug info"));
531
532static llvm::cl::opt<bool>
Daniel Dunbar484afa22009-11-19 04:55:23 +0000533NoMathErrno("fno-math-errno",
Daniel Dunbard8027782009-11-19 05:32:09 +0000534 llvm::cl::desc("Don't require math functions to respect errno"));
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000535
536static llvm::cl::opt<bool>
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000537NoElideConstructors("fno-elide-constructors",
538 llvm::cl::desc("Disable C++ copy constructor elision"));
539
540static llvm::cl::opt<bool>
541NoLaxVectorConversions("fno-lax-vector-conversions",
542 llvm::cl::desc("Disallow implicit conversions between "
543 "vectors with a different number of "
544 "elements or different element types"));
545
546
547static llvm::cl::opt<bool>
548NoOperatorNames("fno-operator-names",
549 llvm::cl::desc("Do not treat C++ operator name keywords as "
550 "synonyms for operators"));
551
552static llvm::cl::opt<std::string>
553ObjCConstantStringClass("fconstant-string-class",
554 llvm::cl::value_desc("class name"),
555 llvm::cl::desc("Specify the class to use for constant "
556 "Objective-C string objects."));
557
558static llvm::cl::opt<bool>
559ObjCEnableGC("fobjc-gc",
560 llvm::cl::desc("Enable Objective-C garbage collection"));
561
562static llvm::cl::opt<bool>
563ObjCExclusiveGC("fobjc-gc-only",
564 llvm::cl::desc("Use GC exclusively for Objective-C related "
565 "memory management"));
566
567static llvm::cl::opt<bool>
568ObjCEnableGCBitmapPrint("print-ivar-layout",
569 llvm::cl::desc("Enable Objective-C Ivar layout bitmap print trace"));
570
571static llvm::cl::opt<bool>
572ObjCNonFragileABI("fobjc-nonfragile-abi",
573 llvm::cl::desc("enable objective-c's nonfragile abi"));
574
575static llvm::cl::opt<bool>
576OverflowChecking("ftrapv",
Daniel Dunbar71f5f9f2009-11-19 04:55:06 +0000577 llvm::cl::desc("Trap on integer overflow"));
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000578
579static llvm::cl::opt<unsigned>
580PICLevel("pic-level", llvm::cl::desc("Value for __PIC__"));
581
582static llvm::cl::opt<bool>
Daniel Dunbar71f5f9f2009-11-19 04:55:06 +0000583PThread("pthread", llvm::cl::desc("Support POSIX threads in generated code"));
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000584
585static llvm::cl::opt<bool>
586PascalStrings("fpascal-strings",
587 llvm::cl::desc("Recognize and construct Pascal-style "
588 "string literals"));
589
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000590static llvm::cl::opt<bool>
Daniel Dunbar484afa22009-11-19 04:55:23 +0000591NoRtti("fno-rtti",
Daniel Dunbard8027782009-11-19 05:32:09 +0000592 llvm::cl::desc("Disable generation of rtti information"));
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000593
594static llvm::cl::opt<bool>
595ShortWChar("fshort-wchar",
596 llvm::cl::desc("Force wchar_t to be a short unsigned int"));
597
598static llvm::cl::opt<bool>
599StaticDefine("static-define", llvm::cl::desc("Should __STATIC__ be defined"));
600
601static llvm::cl::opt<int>
602StackProtector("stack-protector",
603 llvm::cl::desc("Enable stack protectors"),
604 llvm::cl::init(-1));
605
606static llvm::cl::opt<LangOptions::VisibilityMode>
607SymbolVisibility("fvisibility",
608 llvm::cl::desc("Set the default symbol visibility:"),
609 llvm::cl::init(LangOptions::Default),
610 llvm::cl::values(clEnumValN(LangOptions::Default, "default",
611 "Use default symbol visibility"),
612 clEnumValN(LangOptions::Hidden, "hidden",
613 "Use hidden symbol visibility"),
614 clEnumValN(LangOptions::Protected,"protected",
615 "Use protected symbol visibility"),
616 clEnumValEnd));
617
618static llvm::cl::opt<unsigned>
619TemplateDepth("ftemplate-depth", llvm::cl::init(99),
620 llvm::cl::desc("Maximum depth of recursive template "
621 "instantiation"));
622
623static llvm::cl::opt<bool>
624Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences"));
625
626static llvm::cl::opt<bool>
627WritableStrings("fwritable-strings",
628 llvm::cl::desc("Store string literals as writable data"));
629
630}
631
632//===----------------------------------------------------------------------===//
Daniel Dunbar999215c2009-11-11 06:10:03 +0000633// General Preprocessor Options
634//===----------------------------------------------------------------------===//
635
636namespace preprocessoroptions {
637
638static llvm::cl::list<std::string>
639D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
640 llvm::cl::desc("Predefine the specified macro"));
641
642static llvm::cl::list<std::string>
643ImplicitIncludes("include", llvm::cl::value_desc("file"),
644 llvm::cl::desc("Include file before parsing"));
645static llvm::cl::list<std::string>
646ImplicitMacroIncludes("imacros", llvm::cl::value_desc("file"),
647 llvm::cl::desc("Include macros from file before parsing"));
648
649static llvm::cl::opt<std::string>
650ImplicitIncludePCH("include-pch", llvm::cl::value_desc("file"),
651 llvm::cl::desc("Include precompiled header file"));
652
653static llvm::cl::opt<std::string>
654ImplicitIncludePTH("include-pth", llvm::cl::value_desc("file"),
655 llvm::cl::desc("Include file before parsing"));
656
Daniel Dunbar29403032009-11-12 02:53:59 +0000657static llvm::cl::opt<std::string>
658TokenCache("token-cache", llvm::cl::value_desc("path"),
659 llvm::cl::desc("Use specified token cache file"));
660
Daniel Dunbar999215c2009-11-11 06:10:03 +0000661static llvm::cl::list<std::string>
662U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
663 llvm::cl::desc("Undefine the specified macro"));
664
665static llvm::cl::opt<bool>
666UndefMacros("undef", llvm::cl::value_desc("macro"),
667 llvm::cl::desc("undef all system defines"));
668
669}
670
671//===----------------------------------------------------------------------===//
Daniel Dunbarf527a122009-11-11 08:13:32 +0000672// Header Search Options
673//===----------------------------------------------------------------------===//
674
675namespace headersearchoptions {
676
677static llvm::cl::opt<bool>
678nostdinc("nostdinc", llvm::cl::desc("Disable standard #include directories"));
679
680static llvm::cl::opt<bool>
681nobuiltininc("nobuiltininc",
682 llvm::cl::desc("Disable builtin #include directories"));
683
684// Various command line options. These four add directories to each chain.
685static llvm::cl::list<std::string>
686F_dirs("F", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
687 llvm::cl::desc("Add directory to framework include search path"));
688
689static llvm::cl::list<std::string>
690I_dirs("I", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
691 llvm::cl::desc("Add directory to include search path"));
692
693static llvm::cl::list<std::string>
694idirafter_dirs("idirafter", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
695 llvm::cl::desc("Add directory to AFTER include search path"));
696
697static llvm::cl::list<std::string>
698iquote_dirs("iquote", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
699 llvm::cl::desc("Add directory to QUOTE include search path"));
700
701static llvm::cl::list<std::string>
702isystem_dirs("isystem", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
703 llvm::cl::desc("Add directory to SYSTEM include search path"));
704
705// These handle -iprefix/-iwithprefix/-iwithprefixbefore.
706static llvm::cl::list<std::string>
707iprefix_vals("iprefix", llvm::cl::value_desc("prefix"), llvm::cl::Prefix,
708 llvm::cl::desc("Set the -iwithprefix/-iwithprefixbefore prefix"));
709static llvm::cl::list<std::string>
710iwithprefix_vals("iwithprefix", llvm::cl::value_desc("dir"), llvm::cl::Prefix,
711 llvm::cl::desc("Set directory to SYSTEM include search path with prefix"));
712static llvm::cl::list<std::string>
713iwithprefixbefore_vals("iwithprefixbefore", llvm::cl::value_desc("dir"),
714 llvm::cl::Prefix,
715 llvm::cl::desc("Set directory to include search path with prefix"));
716
717static llvm::cl::opt<std::string>
718isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::init("/"),
719 llvm::cl::desc("Set the system root directory (usually /)"));
720
Daniel Dunbareb515862009-11-12 23:52:46 +0000721static llvm::cl::opt<bool>
722Verbose("v", llvm::cl::desc("Enable verbose output"));
723
Daniel Dunbarf527a122009-11-11 08:13:32 +0000724}
725
726//===----------------------------------------------------------------------===//
Daniel Dunbar22bdabf2009-11-11 10:07:44 +0000727// Preprocessed Output Options
728//===----------------------------------------------------------------------===//
729
730namespace preprocessoroutputoptions {
731
732static llvm::cl::opt<bool>
733DisableLineMarkers("P", llvm::cl::desc("Disable linemarker output in -E mode"));
734
735static llvm::cl::opt<bool>
736EnableCommentOutput("C", llvm::cl::desc("Enable comment output in -E mode"));
737
738static llvm::cl::opt<bool>
739EnableMacroCommentOutput("CC",
740 llvm::cl::desc("Enable comment output in -E mode, "
741 "even from macro expansions"));
742static llvm::cl::opt<bool>
743DumpMacros("dM", llvm::cl::desc("Print macro definitions in -E mode instead of"
744 " normal output"));
745static llvm::cl::opt<bool>
746DumpDefines("dD", llvm::cl::desc("Print macro definitions in -E mode in "
747 "addition to normal output"));
748
749}
Daniel Dunbarb9bbd542009-11-15 06:48:46 +0000750//===----------------------------------------------------------------------===//
751// Target Options
752//===----------------------------------------------------------------------===//
753
754namespace targetoptions {
755
756static llvm::cl::opt<std::string>
757TargetABI("target-abi",
758 llvm::cl::desc("Target a particular ABI type"));
759
760static llvm::cl::opt<std::string>
761TargetCPU("mcpu",
762 llvm::cl::desc("Target a specific cpu type (-mcpu=help for details)"));
763
764static llvm::cl::list<std::string>
765TargetFeatures("target-feature", llvm::cl::desc("Target specific attributes"));
766
767static llvm::cl::opt<std::string>
768TargetTriple("triple",
769 llvm::cl::desc("Specify target triple (e.g. i686-apple-darwin9)"));
770
771}
Daniel Dunbar22bdabf2009-11-11 10:07:44 +0000772
773//===----------------------------------------------------------------------===//
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000774// Option Object Construction
775//===----------------------------------------------------------------------===//
776
Daniel Dunbar19b04ff2009-11-17 05:05:08 +0000777void clang::InitializeAnalyzerOptions(AnalyzerOptions &Opts) {
778 using namespace analyzeroptions;
779 Opts.AnalysisList = AnalysisList;
780 Opts.AnalysisStoreOpt = AnalysisStoreOpt;
781 Opts.AnalysisConstraintsOpt = AnalysisConstraintsOpt;
782 Opts.AnalysisDiagOpt = AnalysisDiagOpt;
783 Opts.VisualizeEGDot = VisualizeEGDot;
784 Opts.VisualizeEGUbi = VisualizeEGUbi;
785 Opts.AnalyzeAll = AnalyzeAll;
786 Opts.AnalyzerDisplayProgress = AnalyzerDisplayProgress;
Daniel Dunbar484afa22009-11-19 04:55:23 +0000787 Opts.PurgeDead = !NoPurgeDead;
Daniel Dunbar19b04ff2009-11-17 05:05:08 +0000788 Opts.EagerlyAssume = EagerlyAssume;
789 Opts.AnalyzeSpecificFunction = AnalyzeSpecificFunction;
790 Opts.EnableExperimentalChecks = AnalyzerExperimentalChecks;
791 Opts.EnableExperimentalInternalChecks = AnalyzerExperimentalInternalChecks;
792 Opts.TrimGraph = TrimGraph;
793}
794
Daniel Dunbar77a9d2b2009-11-16 22:38:14 +0000795void clang::InitializeCodeGenOptions(CodeGenOptions &Opts,
796 const LangOptions &Lang,
797 bool TimePasses) {
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000798 using namespace codegenoptions;
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000799
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000800 // -Os implies -O2
801 Opts.OptimizationLevel = OptSize ? 2 : OptLevel;
802
803 // We must always run at least the always inlining pass.
Chandler Carruthbc55fe22009-11-12 17:24:48 +0000804 Opts.Inlining = (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining
805 : CodeGenOptions::OnlyAlwaysInlining;
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000806
Daniel Dunbar979586e2009-11-11 09:38:56 +0000807 Opts.DebugInfo = GenerateDebugInfo;
808 Opts.DisableLLVMOpts = DisableLLVMOptimizations;
809 Opts.DisableRedZone = DisableRedZone;
810 Opts.MergeAllConstants = !NoMergeConstants;
811 Opts.NoCommon = NoCommon;
812 Opts.NoImplicitFloat = NoImplicitFloat;
813 Opts.OptimizeSize = OptSize;
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000814 Opts.SimplifyLibCalls = 1;
Daniel Dunbar979586e2009-11-11 09:38:56 +0000815 Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize);
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000816
Daniel Dunbar77a9d2b2009-11-16 22:38:14 +0000817 // FIXME: Eliminate this dependency?
818 if (Lang.NoBuiltin)
819 Opts.SimplifyLibCalls = 0;
820 if (Lang.CPlusPlus)
821 Opts.NoCommon = 1;
822 Opts.TimePasses = TimePasses;
823
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000824#ifdef NDEBUG
825 Opts.VerifyModule = 0;
826#endif
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000827}
Daniel Dunbar999215c2009-11-11 06:10:03 +0000828
Daniel Dunbar89d1fdf2009-11-11 21:43:12 +0000829void clang::InitializeDependencyOutputOptions(DependencyOutputOptions &Opts) {
830 using namespace dependencyoutputoptions;
831
832 Opts.OutputFile = DependencyFile;
Daniel Dunbarf996c052009-11-12 23:52:32 +0000833 Opts.Targets = DependencyTargets;
Daniel Dunbar89d1fdf2009-11-11 21:43:12 +0000834 Opts.IncludeSystemHeaders = DependenciesIncludeSystemHeaders;
835 Opts.UsePhonyTargets = PhonyDependencyTarget;
836}
837
Daniel Dunbardcd40fb2009-11-11 08:13:40 +0000838void clang::InitializeDiagnosticOptions(DiagnosticOptions &Opts) {
839 using namespace diagnosticoptions;
840
Daniel Dunbarf996c052009-11-12 23:52:32 +0000841 Opts.Warnings = OptWarnings;
Daniel Dunbar8fd69a02009-11-12 07:28:21 +0000842 Opts.DumpBuildInformation = DumpBuildInformation;
Daniel Dunbar4c0e8272009-11-12 07:28:44 +0000843 Opts.IgnoreWarnings = OptNoWarnings;
Daniel Dunbardcd40fb2009-11-11 08:13:40 +0000844 Opts.MessageLength = MessageLength;
Daniel Dunbar4c0e8272009-11-12 07:28:44 +0000845 Opts.NoRewriteMacros = SilenceRewriteMacroWarning;
846 Opts.Pedantic = OptPedantic;
847 Opts.PedanticErrors = OptPedanticErrors;
Daniel Dunbar8fd69a02009-11-12 07:28:21 +0000848 Opts.ShowCarets = !NoCaretDiagnostics;
849 Opts.ShowColors = PrintColorDiagnostic;
850 Opts.ShowColumn = !NoShowColumn;
851 Opts.ShowFixits = !NoDiagnosticsFixIt;
852 Opts.ShowLocation = !NoShowLocation;
853 Opts.ShowOptionNames = PrintDiagnosticOption;
854 Opts.ShowSourceRanges = PrintSourceRangeInfo;
Daniel Dunbarf996c052009-11-12 23:52:32 +0000855 Opts.VerifyDiagnostics = VerifyDiagnostics;
856}
857
858void clang::InitializeFrontendOptions(FrontendOptions &Opts) {
859 using namespace frontendoptions;
860
Daniel Dunbard392dd02009-11-15 00:12:04 +0000861 // Select program action.
862 Opts.ProgramAction = ProgAction;
863 if (PluginActionName.getPosition()) {
864 Opts.ProgramAction = frontend::PluginAction;
865 Opts.ActionName = PluginActionName;
866 }
867
Daniel Dunbar4a1f60f2009-11-13 01:02:10 +0000868 Opts.CodeCompletionAt = CodeCompletionAt;
Daniel Dunbard8027782009-11-19 05:32:09 +0000869 Opts.DebugCodeCompletionPrinter = !NoCodeCompletionDebugPrinter;
Daniel Dunbarf996c052009-11-12 23:52:32 +0000870 Opts.DisableFree = DisableFree;
871 Opts.EmptyInputOnly = EmptyInputOnly;
Daniel Dunbara5c3d982009-11-12 23:52:56 +0000872 Opts.FixItLocations = FixItAtLocations;
Daniel Dunbarf996c052009-11-12 23:52:32 +0000873 Opts.OutputFile = OutputFile;
Daniel Dunbar4a1f60f2009-11-13 01:02:10 +0000874 Opts.RelocatablePCH = RelocatablePCH;
875 Opts.ShowMacrosInCodeCompletion = CodeCompletionWantsMacros;
876 Opts.ShowStats = Stats;
877 Opts.ShowTimers = TimeReport;
Daniel Dunbarf996c052009-11-12 23:52:32 +0000878 Opts.ViewClassInheritance = InheritanceViewCls;
879
880 // '-' is the default input if none is given.
Daniel Dunbar27b19dc2009-11-13 02:06:12 +0000881 if (InputFilenames.empty()) {
882 FrontendOptions::InputKind IK = InputType;
883 if (IK == FrontendOptions::IK_None) IK = FrontendOptions::IK_C;
884 Opts.Inputs.push_back(std::make_pair(IK, "-"));
885 } else {
886 for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
887 FrontendOptions::InputKind IK = InputType;
888 llvm::StringRef Ext =
889 llvm::StringRef(InputFilenames[i]).rsplit('.').second;
890 if (IK == FrontendOptions::IK_None)
891 IK = FrontendOptions::getInputKindForExtension(Ext);
892 Opts.Inputs.push_back(std::make_pair(IK, InputFilenames[i]));
Daniel Dunbar27b19dc2009-11-13 02:06:12 +0000893 }
894 }
Daniel Dunbardcd40fb2009-11-11 08:13:40 +0000895}
896
Daniel Dunbarf527a122009-11-11 08:13:32 +0000897void clang::InitializeHeaderSearchOptions(HeaderSearchOptions &Opts,
Daniel Dunbar24347f72009-11-16 22:38:40 +0000898 llvm::StringRef BuiltinIncludePath) {
Daniel Dunbarf527a122009-11-11 08:13:32 +0000899 using namespace headersearchoptions;
900
901 Opts.Sysroot = isysroot;
902 Opts.Verbose = Verbose;
903
904 // Handle -I... and -F... options, walking the lists in parallel.
905 unsigned Iidx = 0, Fidx = 0;
906 while (Iidx < I_dirs.size() && Fidx < F_dirs.size()) {
907 if (I_dirs.getPosition(Iidx) < F_dirs.getPosition(Fidx)) {
Daniel Dunbar92881db2009-11-17 05:04:15 +0000908 Opts.AddPath(I_dirs[Iidx], frontend::Angled, true, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000909 ++Iidx;
910 } else {
Daniel Dunbar92881db2009-11-17 05:04:15 +0000911 Opts.AddPath(F_dirs[Fidx], frontend::Angled, true, true);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000912 ++Fidx;
913 }
914 }
915
916 // Consume what's left from whatever list was longer.
917 for (; Iidx != I_dirs.size(); ++Iidx)
Daniel Dunbar92881db2009-11-17 05:04:15 +0000918 Opts.AddPath(I_dirs[Iidx], frontend::Angled, true, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000919 for (; Fidx != F_dirs.size(); ++Fidx)
Daniel Dunbar92881db2009-11-17 05:04:15 +0000920 Opts.AddPath(F_dirs[Fidx], frontend::Angled, true, true);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000921
922 // Handle -idirafter... options.
923 for (unsigned i = 0, e = idirafter_dirs.size(); i != e; ++i)
Daniel Dunbar92881db2009-11-17 05:04:15 +0000924 Opts.AddPath(idirafter_dirs[i], frontend::After, true, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000925
926 // Handle -iquote... options.
927 for (unsigned i = 0, e = iquote_dirs.size(); i != e; ++i)
Daniel Dunbar92881db2009-11-17 05:04:15 +0000928 Opts.AddPath(iquote_dirs[i], frontend::Quoted, true, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000929
930 // Handle -isystem... options.
931 for (unsigned i = 0, e = isystem_dirs.size(); i != e; ++i)
Daniel Dunbar92881db2009-11-17 05:04:15 +0000932 Opts.AddPath(isystem_dirs[i], frontend::System, true, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000933
934 // Walk the -iprefix/-iwithprefix/-iwithprefixbefore argument lists in
935 // parallel, processing the values in order of occurance to get the right
936 // prefixes.
937 {
938 std::string Prefix = ""; // FIXME: this isn't the correct default prefix.
939 unsigned iprefix_idx = 0;
940 unsigned iwithprefix_idx = 0;
941 unsigned iwithprefixbefore_idx = 0;
942 bool iprefix_done = iprefix_vals.empty();
943 bool iwithprefix_done = iwithprefix_vals.empty();
944 bool iwithprefixbefore_done = iwithprefixbefore_vals.empty();
945 while (!iprefix_done || !iwithprefix_done || !iwithprefixbefore_done) {
946 if (!iprefix_done &&
947 (iwithprefix_done ||
948 iprefix_vals.getPosition(iprefix_idx) <
949 iwithprefix_vals.getPosition(iwithprefix_idx)) &&
950 (iwithprefixbefore_done ||
951 iprefix_vals.getPosition(iprefix_idx) <
952 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
953 Prefix = iprefix_vals[iprefix_idx];
954 ++iprefix_idx;
955 iprefix_done = iprefix_idx == iprefix_vals.size();
956 } else if (!iwithprefix_done &&
957 (iwithprefixbefore_done ||
958 iwithprefix_vals.getPosition(iwithprefix_idx) <
959 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
960 Opts.AddPath(Prefix+iwithprefix_vals[iwithprefix_idx],
Daniel Dunbar92881db2009-11-17 05:04:15 +0000961 frontend::System, false, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000962 ++iwithprefix_idx;
963 iwithprefix_done = iwithprefix_idx == iwithprefix_vals.size();
964 } else {
965 Opts.AddPath(Prefix+iwithprefixbefore_vals[iwithprefixbefore_idx],
Daniel Dunbar92881db2009-11-17 05:04:15 +0000966 frontend::Angled, false, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000967 ++iwithprefixbefore_idx;
968 iwithprefixbefore_done =
969 iwithprefixbefore_idx == iwithprefixbefore_vals.size();
970 }
971 }
972 }
973
974 // Add CPATH environment paths.
975 if (const char *Env = getenv("CPATH"))
976 Opts.EnvIncPath = Env;
977
978 // Add language specific environment paths.
Daniel Dunbar24347f72009-11-16 22:38:40 +0000979 if (const char *Env = getenv("OBJCPLUS_INCLUDE_PATH"))
980 Opts.ObjCXXEnvIncPath = Env;
981 if (const char *Env = getenv("CPLUS_INCLUDE_PATH"))
982 Opts.CXXEnvIncPath = Env;
983 if (const char *Env = getenv("OBJC_INCLUDE_PATH"))
984 Opts.CEnvIncPath = Env;
985 if (const char *Env = getenv("C_INCLUDE_PATH"))
986 Opts.CEnvIncPath = Env;
Daniel Dunbarf527a122009-11-11 08:13:32 +0000987
988 if (!nobuiltininc)
989 Opts.BuiltinIncludePath = BuiltinIncludePath;
990
991 Opts.UseStandardIncludes = !nostdinc;
992}
993
Daniel Dunbar999215c2009-11-11 06:10:03 +0000994void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) {
995 using namespace preprocessoroptions;
996
Daniel Dunbard6ea9022009-11-17 05:52:41 +0000997 Opts.ImplicitPCHInclude = ImplicitIncludePCH;
998 Opts.ImplicitPTHInclude = ImplicitIncludePTH;
Daniel Dunbar999215c2009-11-11 06:10:03 +0000999
Daniel Dunbar29403032009-11-12 02:53:59 +00001000 // Select the token cache file, we don't support more than one currently so we
1001 // can't have both an implicit-pth and a token cache file.
1002 if (TokenCache.getPosition() && ImplicitIncludePTH.getPosition()) {
1003 // FIXME: Don't fail like this.
1004 fprintf(stderr, "error: cannot use both -token-cache and -include-pth "
1005 "options\n");
1006 exit(1);
1007 }
1008 if (TokenCache.getPosition())
Daniel Dunbard6ea9022009-11-17 05:52:41 +00001009 Opts.TokenCache = TokenCache;
Daniel Dunbar29403032009-11-12 02:53:59 +00001010 else
Daniel Dunbard6ea9022009-11-17 05:52:41 +00001011 Opts.TokenCache = ImplicitIncludePTH;
Daniel Dunbar29403032009-11-12 02:53:59 +00001012
Daniel Dunbar999215c2009-11-11 06:10:03 +00001013 // Use predefines?
Daniel Dunbard6ea9022009-11-17 05:52:41 +00001014 Opts.UsePredefines = !UndefMacros;
Daniel Dunbar999215c2009-11-11 06:10:03 +00001015
1016 // Add macros from the command line.
1017 unsigned d = 0, D = D_macros.size();
1018 unsigned u = 0, U = U_macros.size();
1019 while (d < D || u < U) {
1020 if (u == U || (d < D && D_macros.getPosition(d) < U_macros.getPosition(u)))
1021 Opts.addMacroDef(D_macros[d++]);
1022 else
1023 Opts.addMacroUndef(U_macros[u++]);
1024 }
1025
1026 // If -imacros are specified, include them now. These are processed before
1027 // any -include directives.
1028 for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i)
Daniel Dunbard6ea9022009-11-17 05:52:41 +00001029 Opts.MacroIncludes.push_back(ImplicitMacroIncludes[i]);
Daniel Dunbar999215c2009-11-11 06:10:03 +00001030
1031 // Add the ordered list of -includes, sorting in the implicit include options
1032 // at the appropriate location.
1033 llvm::SmallVector<std::pair<unsigned, std::string*>, 8> OrderedPaths;
1034 std::string OriginalFile;
1035
1036 if (!ImplicitIncludePTH.empty())
1037 OrderedPaths.push_back(std::make_pair(ImplicitIncludePTH.getPosition(),
1038 &ImplicitIncludePTH));
1039 if (!ImplicitIncludePCH.empty()) {
1040 OriginalFile = PCHReader::getOriginalSourceFile(ImplicitIncludePCH);
1041 // FIXME: Don't fail like this.
1042 if (OriginalFile.empty())
1043 exit(1);
1044 OrderedPaths.push_back(std::make_pair(ImplicitIncludePCH.getPosition(),
1045 &OriginalFile));
1046 }
1047 for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i)
1048 OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i),
1049 &ImplicitIncludes[i]));
1050 llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end());
1051
1052 for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i)
Daniel Dunbard6ea9022009-11-17 05:52:41 +00001053 Opts.Includes.push_back(*OrderedPaths[i].second);
Daniel Dunbar999215c2009-11-11 06:10:03 +00001054}
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001055
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001056void clang::InitializeLangOptions(LangOptions &Options,
1057 FrontendOptions::InputKind IK,
Daniel Dunbar77a9d2b2009-11-16 22:38:14 +00001058 TargetInfo &Target) {
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001059 using namespace langoptions;
1060
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001061
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001062 switch (IK) {
1063 case FrontendOptions::IK_None:
1064 case FrontendOptions::IK_AST:
1065 assert(0 && "Invalid input kind!");
1066 case FrontendOptions::IK_Asm:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001067 Options.AsmPreprocessor = 1;
1068 // FALLTHROUGH
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001069 case FrontendOptions::IK_PreprocessedC:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001070 // FALLTHROUGH
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001071 case FrontendOptions::IK_C:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001072 // Do nothing.
1073 break;
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001074 case FrontendOptions::IK_PreprocessedCXX:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001075 // FALLTHROUGH
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001076 case FrontendOptions::IK_CXX:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001077 Options.CPlusPlus = 1;
1078 break;
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001079 case FrontendOptions::IK_PreprocessedObjC:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001080 // FALLTHROUGH
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001081 case FrontendOptions::IK_ObjC:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001082 Options.ObjC1 = Options.ObjC2 = 1;
1083 break;
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001084 case FrontendOptions::IK_PreprocessedObjCXX:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001085 // FALLTHROUGH
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001086 case FrontendOptions::IK_ObjCXX:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001087 Options.ObjC1 = Options.ObjC2 = 1;
1088 Options.CPlusPlus = 1;
1089 break;
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001090 case FrontendOptions::IK_OpenCL:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001091 Options.OpenCL = 1;
1092 Options.AltiVec = 1;
1093 Options.CXXOperatorNames = 1;
1094 Options.LaxVectorConversions = 1;
1095 break;
1096 }
1097
1098 if (ObjCExclusiveGC)
1099 Options.setGCMode(LangOptions::GCOnly);
1100 else if (ObjCEnableGC)
1101 Options.setGCMode(LangOptions::HybridGC);
1102
1103 if (ObjCEnableGCBitmapPrint)
1104 Options.ObjCGCBitmapPrint = 1;
1105
1106 if (AltiVec)
1107 Options.AltiVec = 1;
1108
1109 if (PThread)
1110 Options.POSIXThreads = 1;
1111
1112 Options.setVisibilityMode(SymbolVisibility);
1113 Options.OverflowChecking = OverflowChecking;
1114
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001115 if (LangStd == lang_unspecified) {
1116 // Based on the base language, pick one.
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001117 switch (IK) {
1118 case FrontendOptions::IK_None:
1119 case FrontendOptions::IK_AST:
1120 assert(0 && "Invalid input kind!");
1121 case FrontendOptions::IK_OpenCL:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001122 LangStd = lang_c99;
1123 break;
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001124 case FrontendOptions::IK_Asm:
1125 case FrontendOptions::IK_C:
1126 case FrontendOptions::IK_PreprocessedC:
1127 case FrontendOptions::IK_ObjC:
1128 case FrontendOptions::IK_PreprocessedObjC:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001129 LangStd = lang_gnu99;
1130 break;
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001131 case FrontendOptions::IK_CXX:
1132 case FrontendOptions::IK_PreprocessedCXX:
1133 case FrontendOptions::IK_ObjCXX:
1134 case FrontendOptions::IK_PreprocessedObjCXX:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001135 LangStd = lang_gnucxx98;
1136 break;
1137 }
1138 }
1139
1140 switch (LangStd) {
1141 default: assert(0 && "Unknown language standard!");
1142
1143 // Fall through from newer standards to older ones. This isn't really right.
1144 // FIXME: Enable specifically the right features based on the language stds.
1145 case lang_gnucxx0x:
1146 case lang_cxx0x:
1147 Options.CPlusPlus0x = 1;
1148 // FALL THROUGH
1149 case lang_gnucxx98:
1150 case lang_cxx98:
1151 Options.CPlusPlus = 1;
1152 Options.CXXOperatorNames = !NoOperatorNames;
1153 // FALL THROUGH.
1154 case lang_gnu99:
1155 case lang_c99:
1156 Options.C99 = 1;
1157 Options.HexFloats = 1;
1158 // FALL THROUGH.
1159 case lang_gnu89:
1160 Options.BCPLComment = 1; // Only for C99/C++.
1161 // FALL THROUGH.
1162 case lang_c94:
1163 Options.Digraphs = 1; // C94, C99, C++.
1164 // FALL THROUGH.
1165 case lang_c89:
1166 break;
1167 }
1168
1169 // GNUMode - Set if we're in gnu99, gnu89, gnucxx98, etc.
1170 switch (LangStd) {
1171 default: assert(0 && "Unknown language standard!");
1172 case lang_gnucxx0x:
1173 case lang_gnucxx98:
1174 case lang_gnu99:
1175 case lang_gnu89:
1176 Options.GNUMode = 1;
1177 break;
1178 case lang_cxx0x:
1179 case lang_cxx98:
1180 case lang_c99:
1181 case lang_c94:
1182 case lang_c89:
1183 Options.GNUMode = 0;
1184 break;
1185 }
1186
1187 if (Options.CPlusPlus) {
1188 Options.C99 = 0;
1189 Options.HexFloats = 0;
1190 }
1191
1192 if (LangStd == lang_c89 || LangStd == lang_c94 || LangStd == lang_gnu89)
1193 Options.ImplicitInt = 1;
1194 else
1195 Options.ImplicitInt = 0;
1196
1197 // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
1198 // is specified, or -std is set to a conforming mode.
1199 Options.Trigraphs = !Options.GNUMode;
1200 if (Trigraphs.getPosition())
1201 Options.Trigraphs = Trigraphs; // Command line option wins if specified.
1202
1203 // If in a conformant language mode (e.g. -std=c99) Blocks defaults to off
1204 // even if they are normally on for the target. In GNU modes (e.g.
1205 // -std=gnu99) the default for blocks depends on the target settings.
1206 // However, blocks are not turned off when compiling Obj-C or Obj-C++ code.
1207 if (!Options.ObjC1 && !Options.GNUMode)
1208 Options.Blocks = 0;
1209
1210 // Default to not accepting '$' in identifiers when preprocessing assembler,
1211 // but do accept when preprocessing C. FIXME: these defaults are right for
1212 // darwin, are they right everywhere?
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001213 Options.DollarIdents = IK != FrontendOptions::IK_Asm;
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001214 if (DollarsInIdents.getPosition()) // Explicit setting overrides default.
1215 Options.DollarIdents = DollarsInIdents;
1216
1217 if (PascalStrings.getPosition())
1218 Options.PascalStrings = PascalStrings;
1219 if (MSExtensions.getPosition())
1220 Options.Microsoft = MSExtensions;
1221 Options.WritableStrings = WritableStrings;
1222 if (NoLaxVectorConversions.getPosition())
1223 Options.LaxVectorConversions = 0;
1224 Options.Exceptions = Exceptions;
Daniel Dunbar484afa22009-11-19 04:55:23 +00001225 Options.Rtti = !NoRtti;
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001226 if (EnableBlocks.getPosition())
1227 Options.Blocks = EnableBlocks;
1228 if (CharIsSigned.getPosition())
1229 Options.CharIsSigned = CharIsSigned;
1230 if (ShortWChar.getPosition())
1231 Options.ShortWChar = ShortWChar;
1232
Daniel Dunbar484afa22009-11-19 04:55:23 +00001233 Options.NoBuiltin = NoBuiltin;
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001234 if (Freestanding)
1235 Options.Freestanding = Options.NoBuiltin = 1;
1236
1237 if (EnableHeinousExtensions)
1238 Options.HeinousExtensions = 1;
1239
1240 if (AccessControl)
1241 Options.AccessControl = 1;
1242
1243 Options.ElideConstructors = !NoElideConstructors;
1244
1245 // OpenCL and C++ both have bool, true, false keywords.
1246 Options.Bool = Options.OpenCL | Options.CPlusPlus;
1247
Daniel Dunbar484afa22009-11-19 04:55:23 +00001248 Options.MathErrno = !NoMathErrno;
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001249
1250 Options.InstantiationDepth = TemplateDepth;
1251
1252 // Override the default runtime if the user requested it.
Daniel Dunbar4656c532009-11-17 07:07:28 +00001253 if (GNURuntime)
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001254 Options.NeXTRuntime = 0;
1255
1256 if (!ObjCConstantStringClass.empty())
1257 Options.ObjCConstantStringClass = ObjCConstantStringClass.c_str();
1258
1259 if (ObjCNonFragileABI)
1260 Options.ObjCNonFragileABI = 1;
1261
1262 if (EmitAllDecls)
1263 Options.EmitAllDecls = 1;
1264
1265 // The __OPTIMIZE_SIZE__ define is tied to -Oz, which we don't support.
1266 Options.OptimizeSize = 0;
Daniel Dunbar77a9d2b2009-11-16 22:38:14 +00001267 Options.Optimize = codegenoptions::OptSize || codegenoptions::OptLevel;
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001268
1269 assert(PICLevel <= 2 && "Invalid value for -pic-level");
1270 Options.PICLevel = PICLevel;
1271
1272 Options.GNUInline = !Options.C99;
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001273
1274 // This is the __NO_INLINE__ define, which just depends on things like the
1275 // optimization level and -fno-inline, not actually whether the backend has
1276 // inlining enabled.
Daniel Dunbar77a9d2b2009-11-16 22:38:14 +00001277 //
1278 // FIXME: This is affected by other options (-fno-inline).
1279 Options.NoInline = !codegenoptions::OptLevel;
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001280
1281 Options.Static = StaticDefine;
1282
1283 switch (StackProtector) {
1284 default:
1285 assert(StackProtector <= 2 && "Invalid value for -stack-protector");
1286 case -1: break;
1287 case 0: Options.setStackProtectorMode(LangOptions::SSPOff); break;
1288 case 1: Options.setStackProtectorMode(LangOptions::SSPOn); break;
1289 case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break;
1290 }
1291
1292 if (MainFileName.getPosition())
1293 Options.setMainFileName(MainFileName.c_str());
1294
1295 Target.setForcedLangOptions(Options);
1296}
Daniel Dunbar22bdabf2009-11-11 10:07:44 +00001297
1298void
1299clang::InitializePreprocessorOutputOptions(PreprocessorOutputOptions &Opts) {
1300 using namespace preprocessoroutputoptions;
1301
1302 Opts.ShowCPP = !DumpMacros;
1303 Opts.ShowMacros = DumpMacros || DumpDefines;
1304 Opts.ShowLineMarkers = !DisableLineMarkers;
1305 Opts.ShowComments = EnableCommentOutput;
1306 Opts.ShowMacroComments = EnableMacroCommentOutput;
1307}
Daniel Dunbarb9bbd542009-11-15 06:48:46 +00001308
1309void clang::InitializeTargetOptions(TargetOptions &Opts) {
1310 using namespace targetoptions;
1311
1312 Opts.ABI = TargetABI;
1313 Opts.CPU = TargetCPU;
1314 Opts.Triple = TargetTriple;
1315 Opts.Features = TargetFeatures;
1316
1317 // Use the host triple if unspecified.
1318 if (Opts.Triple.empty())
1319 Opts.Triple = llvm::sys::getHostTriple();
1320}