blob: 34f9c4a4cbe395d0b336a5736035667eca7d29cd [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 Dunbard2cfa012009-11-11 08:13:55 +0000108 llvm::cl::desc("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>
286CodeCompletionDebugPrinter("code-completion-debug-printer",
287 llvm::cl::desc("Use the \"debug\" code-completion print"),
288 llvm::cl::init(true));
289
290static llvm::cl::opt<bool>
291CodeCompletionWantsMacros("code-completion-macros",
292 llvm::cl::desc("Include macros in code-completion results"));
293
Daniel Dunbarf996c052009-11-12 23:52:32 +0000294static llvm::cl::opt<bool>
295DisableFree("disable-free",
Daniel Dunbar71f5f9f2009-11-19 04:55:06 +0000296 llvm::cl::desc("Disable freeing of memory on exit"));
Daniel Dunbarf996c052009-11-12 23:52:32 +0000297
298static llvm::cl::opt<bool>
299EmptyInputOnly("empty-input-only",
300 llvm::cl::desc("Force running on an empty input file"));
301
Daniel Dunbar27b19dc2009-11-13 02:06:12 +0000302static llvm::cl::opt<FrontendOptions::InputKind>
303InputType("x", llvm::cl::desc("Input language type"),
304 llvm::cl::init(FrontendOptions::IK_None),
305 llvm::cl::values(clEnumValN(FrontendOptions::IK_C, "c", "C"),
306 clEnumValN(FrontendOptions::IK_OpenCL, "cl", "OpenCL C"),
307 clEnumValN(FrontendOptions::IK_CXX, "c++", "C++"),
308 clEnumValN(FrontendOptions::IK_ObjC, "objective-c",
309 "Objective C"),
310 clEnumValN(FrontendOptions::IK_ObjCXX, "objective-c++",
311 "Objective C++"),
312 clEnumValN(FrontendOptions::IK_PreprocessedC,
313 "cpp-output",
314 "Preprocessed C"),
315 clEnumValN(FrontendOptions::IK_Asm,
316 "assembler-with-cpp",
317 "Assembly Source Codde"),
318 clEnumValN(FrontendOptions::IK_PreprocessedCXX,
319 "c++-cpp-output",
320 "Preprocessed C++"),
321 clEnumValN(FrontendOptions::IK_PreprocessedObjC,
322 "objective-c-cpp-output",
323 "Preprocessed Objective C"),
324 clEnumValN(FrontendOptions::IK_PreprocessedObjCXX,
325 "objective-c++-cpp-output",
326 "Preprocessed Objective C++"),
327 clEnumValN(FrontendOptions::IK_C, "c-header",
328 "C header"),
329 clEnumValN(FrontendOptions::IK_ObjC, "objective-c-header",
330 "Objective-C header"),
331 clEnumValN(FrontendOptions::IK_CXX, "c++-header",
332 "C++ header"),
333 clEnumValN(FrontendOptions::IK_ObjCXX,
334 "objective-c++-header",
335 "Objective-C++ header"),
336 clEnumValN(FrontendOptions::IK_AST, "ast",
337 "Clang AST"),
338 clEnumValEnd));
339
Daniel Dunbarf996c052009-11-12 23:52:32 +0000340static llvm::cl::list<std::string>
341InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input files>"));
342
343static llvm::cl::opt<std::string>
344InheritanceViewCls("cxx-inheritance-view",
345 llvm::cl::value_desc("class name"),
346 llvm::cl::desc("View C++ inheritance for a specified class"));
347
Daniel Dunbara5c3d982009-11-12 23:52:56 +0000348static llvm::cl::list<ParsedSourceLocation>
349FixItAtLocations("fixit-at", llvm::cl::value_desc("source-location"),
350 llvm::cl::desc("Perform Fix-It modifications at the given source location"));
351
Daniel Dunbarf996c052009-11-12 23:52:32 +0000352static llvm::cl::opt<std::string>
353OutputFile("o",
354 llvm::cl::value_desc("path"),
355 llvm::cl::desc("Specify output file"));
356
Daniel Dunbard392dd02009-11-15 00:12:04 +0000357static llvm::cl::opt<std::string>
358PluginActionName("plugin",
359 llvm::cl::desc("Use the named plugin action "
360 "(use \"help\" to list available options)"));
361
Daniel Dunbar7fbd42f2009-11-14 22:32:38 +0000362static llvm::cl::opt<ActionKind>
363ProgAction(llvm::cl::desc("Choose output type:"), llvm::cl::ZeroOrMore,
364 llvm::cl::init(ParseSyntaxOnly),
365 llvm::cl::values(
366 clEnumValN(RunPreprocessorOnly, "Eonly",
367 "Just run preprocessor, no output (for timings)"),
368 clEnumValN(PrintPreprocessedInput, "E",
369 "Run preprocessor, emit preprocessed file"),
370 clEnumValN(DumpRawTokens, "dump-raw-tokens",
371 "Lex file in raw mode and dump raw tokens"),
372 clEnumValN(RunAnalysis, "analyze",
373 "Run static analysis engine"),
374 clEnumValN(DumpTokens, "dump-tokens",
375 "Run preprocessor, dump internal rep of tokens"),
376 clEnumValN(ParseNoop, "parse-noop",
377 "Run parser with noop callbacks (for timings)"),
378 clEnumValN(ParseSyntaxOnly, "fsyntax-only",
379 "Run parser and perform semantic analysis"),
380 clEnumValN(FixIt, "fixit",
381 "Apply fix-it advice to the input source"),
382 clEnumValN(ParsePrintCallbacks, "parse-print-callbacks",
383 "Run parser and print each callback invoked"),
384 clEnumValN(EmitHTML, "emit-html",
385 "Output input source as HTML"),
386 clEnumValN(ASTPrint, "ast-print",
387 "Build ASTs and then pretty-print them"),
388 clEnumValN(ASTPrintXML, "ast-print-xml",
389 "Build ASTs and then print them in XML format"),
390 clEnumValN(ASTDump, "ast-dump",
391 "Build ASTs and then debug dump them"),
392 clEnumValN(ASTView, "ast-view",
393 "Build ASTs and view them with GraphViz"),
394 clEnumValN(PrintDeclContext, "print-decl-contexts",
395 "Print DeclContexts and their Decls"),
396 clEnumValN(DumpRecordLayouts, "dump-record-layouts",
397 "Dump record layout information"),
398 clEnumValN(GeneratePTH, "emit-pth",
399 "Generate pre-tokenized header file"),
400 clEnumValN(GeneratePCH, "emit-pch",
401 "Generate pre-compiled header file"),
402 clEnumValN(EmitAssembly, "S",
403 "Emit native assembly code"),
404 clEnumValN(EmitLLVM, "emit-llvm",
405 "Build ASTs then convert to LLVM, emit .ll file"),
406 clEnumValN(EmitBC, "emit-llvm-bc",
407 "Build ASTs then convert to LLVM, emit .bc file"),
408 clEnumValN(EmitLLVMOnly, "emit-llvm-only",
409 "Build ASTs and convert to LLVM, discarding output"),
410 clEnumValN(RewriteTest, "rewrite-test",
411 "Rewriter playground"),
412 clEnumValN(RewriteObjC, "rewrite-objc",
413 "Rewrite ObjC into C (code rewriter example)"),
414 clEnumValN(RewriteMacros, "rewrite-macros",
415 "Expand macros without full preprocessing"),
416 clEnumValN(RewriteBlocks, "rewrite-blocks",
417 "Rewrite Blocks to C"),
418 clEnumValEnd));
419
Daniel Dunbarf996c052009-11-12 23:52:32 +0000420static llvm::cl::opt<bool>
421RelocatablePCH("relocatable-pch",
422 llvm::cl::desc("Whether to build a relocatable precompiled "
423 "header"));
424static llvm::cl::opt<bool>
425Stats("print-stats",
426 llvm::cl::desc("Print performance metrics and statistics"));
427
428static llvm::cl::opt<bool>
429TimeReport("ftime-report",
430 llvm::cl::desc("Print the amount of time each "
431 "phase of compilation takes"));
432
Daniel Dunbardcd40fb2009-11-11 08:13:40 +0000433}
434
435//===----------------------------------------------------------------------===//
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000436// Language Options
437//===----------------------------------------------------------------------===//
438
439namespace langoptions {
440
441static llvm::cl::opt<bool>
Daniel Dunbar484afa22009-11-19 04:55:23 +0000442NoBuiltin("fno-builtin",
443 llvm::cl::desc("Disable implicit builtin knowledge of functions"));
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000444
445static llvm::cl::opt<bool>
Daniel Dunbar71f5f9f2009-11-19 04:55:06 +0000446AltiVec("faltivec", llvm::cl::desc("Enable AltiVec vector initializer syntax"));
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000447
448static llvm::cl::opt<bool>
449AccessControl("faccess-control",
450 llvm::cl::desc("Enable C++ access control"));
451
452static llvm::cl::opt<bool>
453CharIsSigned("fsigned-char",
454 llvm::cl::desc("Force char to be a signed/unsigned type"));
455
456static llvm::cl::opt<bool>
457DollarsInIdents("fdollars-in-identifiers",
458 llvm::cl::desc("Allow '$' in identifiers"));
459
460static llvm::cl::opt<bool>
461EmitAllDecls("femit-all-decls",
462 llvm::cl::desc("Emit all declarations, even if unused"));
463
464static llvm::cl::opt<bool>
465EnableBlocks("fblocks", llvm::cl::desc("enable the 'blocks' language feature"));
466
467static llvm::cl::opt<bool>
468EnableHeinousExtensions("fheinous-gnu-extensions",
469 llvm::cl::desc("enable GNU extensions that you really really shouldn't use"),
470 llvm::cl::ValueDisallowed, llvm::cl::Hidden);
471
472static llvm::cl::opt<bool>
473Exceptions("fexceptions",
474 llvm::cl::desc("Enable support for exception handling"));
475
476static llvm::cl::opt<bool>
477Freestanding("ffreestanding",
478 llvm::cl::desc("Assert that the compilation takes place in a "
479 "freestanding environment"));
480
481static llvm::cl::opt<bool>
482GNURuntime("fgnu-runtime",
483 llvm::cl::desc("Generate output compatible with the standard GNU "
484 "Objective-C runtime"));
485
486/// LangStds - Language standards we support.
487enum LangStds {
488 lang_unspecified,
489 lang_c89, lang_c94, lang_c99,
490 lang_gnu89, lang_gnu99,
491 lang_cxx98, lang_gnucxx98,
492 lang_cxx0x, lang_gnucxx0x
493};
494static llvm::cl::opt<LangStds>
495LangStd("std", llvm::cl::desc("Language standard to compile for"),
496 llvm::cl::init(lang_unspecified),
497 llvm::cl::values(clEnumValN(lang_c89, "c89", "ISO C 1990"),
498 clEnumValN(lang_c89, "c90", "ISO C 1990"),
499 clEnumValN(lang_c89, "iso9899:1990", "ISO C 1990"),
500 clEnumValN(lang_c94, "iso9899:199409",
501 "ISO C 1990 with amendment 1"),
502 clEnumValN(lang_c99, "c99", "ISO C 1999"),
503 clEnumValN(lang_c99, "c9x", "ISO C 1999"),
504 clEnumValN(lang_c99, "iso9899:1999", "ISO C 1999"),
505 clEnumValN(lang_c99, "iso9899:199x", "ISO C 1999"),
506 clEnumValN(lang_gnu89, "gnu89",
507 "ISO C 1990 with GNU extensions"),
508 clEnumValN(lang_gnu99, "gnu99",
509 "ISO C 1999 with GNU extensions (default for C)"),
510 clEnumValN(lang_gnu99, "gnu9x",
511 "ISO C 1999 with GNU extensions"),
512 clEnumValN(lang_cxx98, "c++98",
513 "ISO C++ 1998 with amendments"),
514 clEnumValN(lang_gnucxx98, "gnu++98",
515 "ISO C++ 1998 with amendments and GNU "
516 "extensions (default for C++)"),
517 clEnumValN(lang_cxx0x, "c++0x",
518 "Upcoming ISO C++ 200x with amendments"),
519 clEnumValN(lang_gnucxx0x, "gnu++0x",
520 "Upcoming ISO C++ 200x with amendments and GNU "
521 "extensions"),
522 clEnumValEnd));
523
524static llvm::cl::opt<bool>
525MSExtensions("fms-extensions",
526 llvm::cl::desc("Accept some non-standard constructs used in "
527 "Microsoft header files "));
528
529static llvm::cl::opt<std::string>
530MainFileName("main-file-name",
531 llvm::cl::desc("Main file name to use for debug info"));
532
533static llvm::cl::opt<bool>
Daniel Dunbar484afa22009-11-19 04:55:23 +0000534NoMathErrno("fno-math-errno",
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000535 llvm::cl::desc("Require math functions to respect errno"));
536
537static llvm::cl::opt<bool>
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000538NoElideConstructors("fno-elide-constructors",
539 llvm::cl::desc("Disable C++ copy constructor elision"));
540
541static llvm::cl::opt<bool>
542NoLaxVectorConversions("fno-lax-vector-conversions",
543 llvm::cl::desc("Disallow implicit conversions between "
544 "vectors with a different number of "
545 "elements or different element types"));
546
547
548static llvm::cl::opt<bool>
549NoOperatorNames("fno-operator-names",
550 llvm::cl::desc("Do not treat C++ operator name keywords as "
551 "synonyms for operators"));
552
553static llvm::cl::opt<std::string>
554ObjCConstantStringClass("fconstant-string-class",
555 llvm::cl::value_desc("class name"),
556 llvm::cl::desc("Specify the class to use for constant "
557 "Objective-C string objects."));
558
559static llvm::cl::opt<bool>
560ObjCEnableGC("fobjc-gc",
561 llvm::cl::desc("Enable Objective-C garbage collection"));
562
563static llvm::cl::opt<bool>
564ObjCExclusiveGC("fobjc-gc-only",
565 llvm::cl::desc("Use GC exclusively for Objective-C related "
566 "memory management"));
567
568static llvm::cl::opt<bool>
569ObjCEnableGCBitmapPrint("print-ivar-layout",
570 llvm::cl::desc("Enable Objective-C Ivar layout bitmap print trace"));
571
572static llvm::cl::opt<bool>
573ObjCNonFragileABI("fobjc-nonfragile-abi",
574 llvm::cl::desc("enable objective-c's nonfragile abi"));
575
576static llvm::cl::opt<bool>
577OverflowChecking("ftrapv",
Daniel Dunbar71f5f9f2009-11-19 04:55:06 +0000578 llvm::cl::desc("Trap on integer overflow"));
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000579
580static llvm::cl::opt<unsigned>
581PICLevel("pic-level", llvm::cl::desc("Value for __PIC__"));
582
583static llvm::cl::opt<bool>
Daniel Dunbar71f5f9f2009-11-19 04:55:06 +0000584PThread("pthread", llvm::cl::desc("Support POSIX threads in generated code"));
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000585
586static llvm::cl::opt<bool>
587PascalStrings("fpascal-strings",
588 llvm::cl::desc("Recognize and construct Pascal-style "
589 "string literals"));
590
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000591static llvm::cl::opt<bool>
Daniel Dunbar484afa22009-11-19 04:55:23 +0000592NoRtti("fno-rtti",
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000593 llvm::cl::desc("Enable generation of rtti information"));
594
595static llvm::cl::opt<bool>
596ShortWChar("fshort-wchar",
597 llvm::cl::desc("Force wchar_t to be a short unsigned int"));
598
599static llvm::cl::opt<bool>
600StaticDefine("static-define", llvm::cl::desc("Should __STATIC__ be defined"));
601
602static llvm::cl::opt<int>
603StackProtector("stack-protector",
604 llvm::cl::desc("Enable stack protectors"),
605 llvm::cl::init(-1));
606
607static llvm::cl::opt<LangOptions::VisibilityMode>
608SymbolVisibility("fvisibility",
609 llvm::cl::desc("Set the default symbol visibility:"),
610 llvm::cl::init(LangOptions::Default),
611 llvm::cl::values(clEnumValN(LangOptions::Default, "default",
612 "Use default symbol visibility"),
613 clEnumValN(LangOptions::Hidden, "hidden",
614 "Use hidden symbol visibility"),
615 clEnumValN(LangOptions::Protected,"protected",
616 "Use protected symbol visibility"),
617 clEnumValEnd));
618
619static llvm::cl::opt<unsigned>
620TemplateDepth("ftemplate-depth", llvm::cl::init(99),
621 llvm::cl::desc("Maximum depth of recursive template "
622 "instantiation"));
623
624static llvm::cl::opt<bool>
625Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences"));
626
627static llvm::cl::opt<bool>
628WritableStrings("fwritable-strings",
629 llvm::cl::desc("Store string literals as writable data"));
630
631}
632
633//===----------------------------------------------------------------------===//
Daniel Dunbar999215c2009-11-11 06:10:03 +0000634// General Preprocessor Options
635//===----------------------------------------------------------------------===//
636
637namespace preprocessoroptions {
638
639static llvm::cl::list<std::string>
640D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
641 llvm::cl::desc("Predefine the specified macro"));
642
643static llvm::cl::list<std::string>
644ImplicitIncludes("include", llvm::cl::value_desc("file"),
645 llvm::cl::desc("Include file before parsing"));
646static llvm::cl::list<std::string>
647ImplicitMacroIncludes("imacros", llvm::cl::value_desc("file"),
648 llvm::cl::desc("Include macros from file before parsing"));
649
650static llvm::cl::opt<std::string>
651ImplicitIncludePCH("include-pch", llvm::cl::value_desc("file"),
652 llvm::cl::desc("Include precompiled header file"));
653
654static llvm::cl::opt<std::string>
655ImplicitIncludePTH("include-pth", llvm::cl::value_desc("file"),
656 llvm::cl::desc("Include file before parsing"));
657
Daniel Dunbar29403032009-11-12 02:53:59 +0000658static llvm::cl::opt<std::string>
659TokenCache("token-cache", llvm::cl::value_desc("path"),
660 llvm::cl::desc("Use specified token cache file"));
661
Daniel Dunbar999215c2009-11-11 06:10:03 +0000662static llvm::cl::list<std::string>
663U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
664 llvm::cl::desc("Undefine the specified macro"));
665
666static llvm::cl::opt<bool>
667UndefMacros("undef", llvm::cl::value_desc("macro"),
668 llvm::cl::desc("undef all system defines"));
669
670}
671
672//===----------------------------------------------------------------------===//
Daniel Dunbarf527a122009-11-11 08:13:32 +0000673// Header Search Options
674//===----------------------------------------------------------------------===//
675
676namespace headersearchoptions {
677
678static llvm::cl::opt<bool>
679nostdinc("nostdinc", llvm::cl::desc("Disable standard #include directories"));
680
681static llvm::cl::opt<bool>
682nobuiltininc("nobuiltininc",
683 llvm::cl::desc("Disable builtin #include directories"));
684
685// Various command line options. These four add directories to each chain.
686static llvm::cl::list<std::string>
687F_dirs("F", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
688 llvm::cl::desc("Add directory to framework include search path"));
689
690static llvm::cl::list<std::string>
691I_dirs("I", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
692 llvm::cl::desc("Add directory to include search path"));
693
694static llvm::cl::list<std::string>
695idirafter_dirs("idirafter", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
696 llvm::cl::desc("Add directory to AFTER include search path"));
697
698static llvm::cl::list<std::string>
699iquote_dirs("iquote", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
700 llvm::cl::desc("Add directory to QUOTE include search path"));
701
702static llvm::cl::list<std::string>
703isystem_dirs("isystem", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
704 llvm::cl::desc("Add directory to SYSTEM include search path"));
705
706// These handle -iprefix/-iwithprefix/-iwithprefixbefore.
707static llvm::cl::list<std::string>
708iprefix_vals("iprefix", llvm::cl::value_desc("prefix"), llvm::cl::Prefix,
709 llvm::cl::desc("Set the -iwithprefix/-iwithprefixbefore prefix"));
710static llvm::cl::list<std::string>
711iwithprefix_vals("iwithprefix", llvm::cl::value_desc("dir"), llvm::cl::Prefix,
712 llvm::cl::desc("Set directory to SYSTEM include search path with prefix"));
713static llvm::cl::list<std::string>
714iwithprefixbefore_vals("iwithprefixbefore", llvm::cl::value_desc("dir"),
715 llvm::cl::Prefix,
716 llvm::cl::desc("Set directory to include search path with prefix"));
717
718static llvm::cl::opt<std::string>
719isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::init("/"),
720 llvm::cl::desc("Set the system root directory (usually /)"));
721
Daniel Dunbareb515862009-11-12 23:52:46 +0000722static llvm::cl::opt<bool>
723Verbose("v", llvm::cl::desc("Enable verbose output"));
724
Daniel Dunbarf527a122009-11-11 08:13:32 +0000725}
726
727//===----------------------------------------------------------------------===//
Daniel Dunbar22bdabf2009-11-11 10:07:44 +0000728// Preprocessed Output Options
729//===----------------------------------------------------------------------===//
730
731namespace preprocessoroutputoptions {
732
733static llvm::cl::opt<bool>
734DisableLineMarkers("P", llvm::cl::desc("Disable linemarker output in -E mode"));
735
736static llvm::cl::opt<bool>
737EnableCommentOutput("C", llvm::cl::desc("Enable comment output in -E mode"));
738
739static llvm::cl::opt<bool>
740EnableMacroCommentOutput("CC",
741 llvm::cl::desc("Enable comment output in -E mode, "
742 "even from macro expansions"));
743static llvm::cl::opt<bool>
744DumpMacros("dM", llvm::cl::desc("Print macro definitions in -E mode instead of"
745 " normal output"));
746static llvm::cl::opt<bool>
747DumpDefines("dD", llvm::cl::desc("Print macro definitions in -E mode in "
748 "addition to normal output"));
749
750}
Daniel Dunbarb9bbd542009-11-15 06:48:46 +0000751//===----------------------------------------------------------------------===//
752// Target Options
753//===----------------------------------------------------------------------===//
754
755namespace targetoptions {
756
757static llvm::cl::opt<std::string>
758TargetABI("target-abi",
759 llvm::cl::desc("Target a particular ABI type"));
760
761static llvm::cl::opt<std::string>
762TargetCPU("mcpu",
763 llvm::cl::desc("Target a specific cpu type (-mcpu=help for details)"));
764
765static llvm::cl::list<std::string>
766TargetFeatures("target-feature", llvm::cl::desc("Target specific attributes"));
767
768static llvm::cl::opt<std::string>
769TargetTriple("triple",
770 llvm::cl::desc("Specify target triple (e.g. i686-apple-darwin9)"));
771
772}
Daniel Dunbar22bdabf2009-11-11 10:07:44 +0000773
774//===----------------------------------------------------------------------===//
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000775// Option Object Construction
776//===----------------------------------------------------------------------===//
777
Daniel Dunbar19b04ff2009-11-17 05:05:08 +0000778void clang::InitializeAnalyzerOptions(AnalyzerOptions &Opts) {
779 using namespace analyzeroptions;
780 Opts.AnalysisList = AnalysisList;
781 Opts.AnalysisStoreOpt = AnalysisStoreOpt;
782 Opts.AnalysisConstraintsOpt = AnalysisConstraintsOpt;
783 Opts.AnalysisDiagOpt = AnalysisDiagOpt;
784 Opts.VisualizeEGDot = VisualizeEGDot;
785 Opts.VisualizeEGUbi = VisualizeEGUbi;
786 Opts.AnalyzeAll = AnalyzeAll;
787 Opts.AnalyzerDisplayProgress = AnalyzerDisplayProgress;
Daniel Dunbar484afa22009-11-19 04:55:23 +0000788 Opts.PurgeDead = !NoPurgeDead;
Daniel Dunbar19b04ff2009-11-17 05:05:08 +0000789 Opts.EagerlyAssume = EagerlyAssume;
790 Opts.AnalyzeSpecificFunction = AnalyzeSpecificFunction;
791 Opts.EnableExperimentalChecks = AnalyzerExperimentalChecks;
792 Opts.EnableExperimentalInternalChecks = AnalyzerExperimentalInternalChecks;
793 Opts.TrimGraph = TrimGraph;
794}
795
Daniel Dunbar77a9d2b2009-11-16 22:38:14 +0000796void clang::InitializeCodeGenOptions(CodeGenOptions &Opts,
797 const LangOptions &Lang,
798 bool TimePasses) {
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000799 using namespace codegenoptions;
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000800
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000801 // -Os implies -O2
802 Opts.OptimizationLevel = OptSize ? 2 : OptLevel;
803
804 // We must always run at least the always inlining pass.
Chandler Carruthbc55fe22009-11-12 17:24:48 +0000805 Opts.Inlining = (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining
806 : CodeGenOptions::OnlyAlwaysInlining;
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000807
Daniel Dunbar979586e2009-11-11 09:38:56 +0000808 Opts.DebugInfo = GenerateDebugInfo;
809 Opts.DisableLLVMOpts = DisableLLVMOptimizations;
810 Opts.DisableRedZone = DisableRedZone;
811 Opts.MergeAllConstants = !NoMergeConstants;
812 Opts.NoCommon = NoCommon;
813 Opts.NoImplicitFloat = NoImplicitFloat;
814 Opts.OptimizeSize = OptSize;
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000815 Opts.SimplifyLibCalls = 1;
Daniel Dunbar979586e2009-11-11 09:38:56 +0000816 Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize);
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000817
Daniel Dunbar77a9d2b2009-11-16 22:38:14 +0000818 // FIXME: Eliminate this dependency?
819 if (Lang.NoBuiltin)
820 Opts.SimplifyLibCalls = 0;
821 if (Lang.CPlusPlus)
822 Opts.NoCommon = 1;
823 Opts.TimePasses = TimePasses;
824
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000825#ifdef NDEBUG
826 Opts.VerifyModule = 0;
827#endif
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000828}
Daniel Dunbar999215c2009-11-11 06:10:03 +0000829
Daniel Dunbar89d1fdf2009-11-11 21:43:12 +0000830void clang::InitializeDependencyOutputOptions(DependencyOutputOptions &Opts) {
831 using namespace dependencyoutputoptions;
832
833 Opts.OutputFile = DependencyFile;
Daniel Dunbarf996c052009-11-12 23:52:32 +0000834 Opts.Targets = DependencyTargets;
Daniel Dunbar89d1fdf2009-11-11 21:43:12 +0000835 Opts.IncludeSystemHeaders = DependenciesIncludeSystemHeaders;
836 Opts.UsePhonyTargets = PhonyDependencyTarget;
837}
838
Daniel Dunbardcd40fb2009-11-11 08:13:40 +0000839void clang::InitializeDiagnosticOptions(DiagnosticOptions &Opts) {
840 using namespace diagnosticoptions;
841
Daniel Dunbarf996c052009-11-12 23:52:32 +0000842 Opts.Warnings = OptWarnings;
Daniel Dunbar8fd69a02009-11-12 07:28:21 +0000843 Opts.DumpBuildInformation = DumpBuildInformation;
Daniel Dunbar4c0e8272009-11-12 07:28:44 +0000844 Opts.IgnoreWarnings = OptNoWarnings;
Daniel Dunbardcd40fb2009-11-11 08:13:40 +0000845 Opts.MessageLength = MessageLength;
Daniel Dunbar4c0e8272009-11-12 07:28:44 +0000846 Opts.NoRewriteMacros = SilenceRewriteMacroWarning;
847 Opts.Pedantic = OptPedantic;
848 Opts.PedanticErrors = OptPedanticErrors;
Daniel Dunbar8fd69a02009-11-12 07:28:21 +0000849 Opts.ShowCarets = !NoCaretDiagnostics;
850 Opts.ShowColors = PrintColorDiagnostic;
851 Opts.ShowColumn = !NoShowColumn;
852 Opts.ShowFixits = !NoDiagnosticsFixIt;
853 Opts.ShowLocation = !NoShowLocation;
854 Opts.ShowOptionNames = PrintDiagnosticOption;
855 Opts.ShowSourceRanges = PrintSourceRangeInfo;
Daniel Dunbarf996c052009-11-12 23:52:32 +0000856 Opts.VerifyDiagnostics = VerifyDiagnostics;
857}
858
859void clang::InitializeFrontendOptions(FrontendOptions &Opts) {
860 using namespace frontendoptions;
861
Daniel Dunbard392dd02009-11-15 00:12:04 +0000862 // Select program action.
863 Opts.ProgramAction = ProgAction;
864 if (PluginActionName.getPosition()) {
865 Opts.ProgramAction = frontend::PluginAction;
866 Opts.ActionName = PluginActionName;
867 }
868
Daniel Dunbar4a1f60f2009-11-13 01:02:10 +0000869 Opts.CodeCompletionAt = CodeCompletionAt;
870 Opts.DebugCodeCompletionPrinter = CodeCompletionDebugPrinter;
Daniel Dunbarf996c052009-11-12 23:52:32 +0000871 Opts.DisableFree = DisableFree;
872 Opts.EmptyInputOnly = EmptyInputOnly;
Daniel Dunbara5c3d982009-11-12 23:52:56 +0000873 Opts.FixItLocations = FixItAtLocations;
Daniel Dunbarf996c052009-11-12 23:52:32 +0000874 Opts.OutputFile = OutputFile;
Daniel Dunbar4a1f60f2009-11-13 01:02:10 +0000875 Opts.RelocatablePCH = RelocatablePCH;
876 Opts.ShowMacrosInCodeCompletion = CodeCompletionWantsMacros;
877 Opts.ShowStats = Stats;
878 Opts.ShowTimers = TimeReport;
Daniel Dunbarf996c052009-11-12 23:52:32 +0000879 Opts.ViewClassInheritance = InheritanceViewCls;
880
881 // '-' is the default input if none is given.
Daniel Dunbar27b19dc2009-11-13 02:06:12 +0000882 if (InputFilenames.empty()) {
883 FrontendOptions::InputKind IK = InputType;
884 if (IK == FrontendOptions::IK_None) IK = FrontendOptions::IK_C;
885 Opts.Inputs.push_back(std::make_pair(IK, "-"));
886 } else {
887 for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
888 FrontendOptions::InputKind IK = InputType;
889 llvm::StringRef Ext =
890 llvm::StringRef(InputFilenames[i]).rsplit('.').second;
891 if (IK == FrontendOptions::IK_None)
892 IK = FrontendOptions::getInputKindForExtension(Ext);
893 Opts.Inputs.push_back(std::make_pair(IK, InputFilenames[i]));
Daniel Dunbar27b19dc2009-11-13 02:06:12 +0000894 }
895 }
Daniel Dunbardcd40fb2009-11-11 08:13:40 +0000896}
897
Daniel Dunbarf527a122009-11-11 08:13:32 +0000898void clang::InitializeHeaderSearchOptions(HeaderSearchOptions &Opts,
Daniel Dunbar24347f72009-11-16 22:38:40 +0000899 llvm::StringRef BuiltinIncludePath) {
Daniel Dunbarf527a122009-11-11 08:13:32 +0000900 using namespace headersearchoptions;
901
902 Opts.Sysroot = isysroot;
903 Opts.Verbose = Verbose;
904
905 // Handle -I... and -F... options, walking the lists in parallel.
906 unsigned Iidx = 0, Fidx = 0;
907 while (Iidx < I_dirs.size() && Fidx < F_dirs.size()) {
908 if (I_dirs.getPosition(Iidx) < F_dirs.getPosition(Fidx)) {
Daniel Dunbar92881db2009-11-17 05:04:15 +0000909 Opts.AddPath(I_dirs[Iidx], frontend::Angled, true, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000910 ++Iidx;
911 } else {
Daniel Dunbar92881db2009-11-17 05:04:15 +0000912 Opts.AddPath(F_dirs[Fidx], frontend::Angled, true, true);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000913 ++Fidx;
914 }
915 }
916
917 // Consume what's left from whatever list was longer.
918 for (; Iidx != I_dirs.size(); ++Iidx)
Daniel Dunbar92881db2009-11-17 05:04:15 +0000919 Opts.AddPath(I_dirs[Iidx], frontend::Angled, true, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000920 for (; Fidx != F_dirs.size(); ++Fidx)
Daniel Dunbar92881db2009-11-17 05:04:15 +0000921 Opts.AddPath(F_dirs[Fidx], frontend::Angled, true, true);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000922
923 // Handle -idirafter... options.
924 for (unsigned i = 0, e = idirafter_dirs.size(); i != e; ++i)
Daniel Dunbar92881db2009-11-17 05:04:15 +0000925 Opts.AddPath(idirafter_dirs[i], frontend::After, true, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000926
927 // Handle -iquote... options.
928 for (unsigned i = 0, e = iquote_dirs.size(); i != e; ++i)
Daniel Dunbar92881db2009-11-17 05:04:15 +0000929 Opts.AddPath(iquote_dirs[i], frontend::Quoted, true, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000930
931 // Handle -isystem... options.
932 for (unsigned i = 0, e = isystem_dirs.size(); i != e; ++i)
Daniel Dunbar92881db2009-11-17 05:04:15 +0000933 Opts.AddPath(isystem_dirs[i], frontend::System, true, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000934
935 // Walk the -iprefix/-iwithprefix/-iwithprefixbefore argument lists in
936 // parallel, processing the values in order of occurance to get the right
937 // prefixes.
938 {
939 std::string Prefix = ""; // FIXME: this isn't the correct default prefix.
940 unsigned iprefix_idx = 0;
941 unsigned iwithprefix_idx = 0;
942 unsigned iwithprefixbefore_idx = 0;
943 bool iprefix_done = iprefix_vals.empty();
944 bool iwithprefix_done = iwithprefix_vals.empty();
945 bool iwithprefixbefore_done = iwithprefixbefore_vals.empty();
946 while (!iprefix_done || !iwithprefix_done || !iwithprefixbefore_done) {
947 if (!iprefix_done &&
948 (iwithprefix_done ||
949 iprefix_vals.getPosition(iprefix_idx) <
950 iwithprefix_vals.getPosition(iwithprefix_idx)) &&
951 (iwithprefixbefore_done ||
952 iprefix_vals.getPosition(iprefix_idx) <
953 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
954 Prefix = iprefix_vals[iprefix_idx];
955 ++iprefix_idx;
956 iprefix_done = iprefix_idx == iprefix_vals.size();
957 } else if (!iwithprefix_done &&
958 (iwithprefixbefore_done ||
959 iwithprefix_vals.getPosition(iwithprefix_idx) <
960 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
961 Opts.AddPath(Prefix+iwithprefix_vals[iwithprefix_idx],
Daniel Dunbar92881db2009-11-17 05:04:15 +0000962 frontend::System, false, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000963 ++iwithprefix_idx;
964 iwithprefix_done = iwithprefix_idx == iwithprefix_vals.size();
965 } else {
966 Opts.AddPath(Prefix+iwithprefixbefore_vals[iwithprefixbefore_idx],
Daniel Dunbar92881db2009-11-17 05:04:15 +0000967 frontend::Angled, false, false);
Daniel Dunbarf527a122009-11-11 08:13:32 +0000968 ++iwithprefixbefore_idx;
969 iwithprefixbefore_done =
970 iwithprefixbefore_idx == iwithprefixbefore_vals.size();
971 }
972 }
973 }
974
975 // Add CPATH environment paths.
976 if (const char *Env = getenv("CPATH"))
977 Opts.EnvIncPath = Env;
978
979 // Add language specific environment paths.
Daniel Dunbar24347f72009-11-16 22:38:40 +0000980 if (const char *Env = getenv("OBJCPLUS_INCLUDE_PATH"))
981 Opts.ObjCXXEnvIncPath = Env;
982 if (const char *Env = getenv("CPLUS_INCLUDE_PATH"))
983 Opts.CXXEnvIncPath = Env;
984 if (const char *Env = getenv("OBJC_INCLUDE_PATH"))
985 Opts.CEnvIncPath = Env;
986 if (const char *Env = getenv("C_INCLUDE_PATH"))
987 Opts.CEnvIncPath = Env;
Daniel Dunbarf527a122009-11-11 08:13:32 +0000988
989 if (!nobuiltininc)
990 Opts.BuiltinIncludePath = BuiltinIncludePath;
991
992 Opts.UseStandardIncludes = !nostdinc;
993}
994
Daniel Dunbar999215c2009-11-11 06:10:03 +0000995void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) {
996 using namespace preprocessoroptions;
997
Daniel Dunbard6ea9022009-11-17 05:52:41 +0000998 Opts.ImplicitPCHInclude = ImplicitIncludePCH;
999 Opts.ImplicitPTHInclude = ImplicitIncludePTH;
Daniel Dunbar999215c2009-11-11 06:10:03 +00001000
Daniel Dunbar29403032009-11-12 02:53:59 +00001001 // Select the token cache file, we don't support more than one currently so we
1002 // can't have both an implicit-pth and a token cache file.
1003 if (TokenCache.getPosition() && ImplicitIncludePTH.getPosition()) {
1004 // FIXME: Don't fail like this.
1005 fprintf(stderr, "error: cannot use both -token-cache and -include-pth "
1006 "options\n");
1007 exit(1);
1008 }
1009 if (TokenCache.getPosition())
Daniel Dunbard6ea9022009-11-17 05:52:41 +00001010 Opts.TokenCache = TokenCache;
Daniel Dunbar29403032009-11-12 02:53:59 +00001011 else
Daniel Dunbard6ea9022009-11-17 05:52:41 +00001012 Opts.TokenCache = ImplicitIncludePTH;
Daniel Dunbar29403032009-11-12 02:53:59 +00001013
Daniel Dunbar999215c2009-11-11 06:10:03 +00001014 // Use predefines?
Daniel Dunbard6ea9022009-11-17 05:52:41 +00001015 Opts.UsePredefines = !UndefMacros;
Daniel Dunbar999215c2009-11-11 06:10:03 +00001016
1017 // Add macros from the command line.
1018 unsigned d = 0, D = D_macros.size();
1019 unsigned u = 0, U = U_macros.size();
1020 while (d < D || u < U) {
1021 if (u == U || (d < D && D_macros.getPosition(d) < U_macros.getPosition(u)))
1022 Opts.addMacroDef(D_macros[d++]);
1023 else
1024 Opts.addMacroUndef(U_macros[u++]);
1025 }
1026
1027 // If -imacros are specified, include them now. These are processed before
1028 // any -include directives.
1029 for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i)
Daniel Dunbard6ea9022009-11-17 05:52:41 +00001030 Opts.MacroIncludes.push_back(ImplicitMacroIncludes[i]);
Daniel Dunbar999215c2009-11-11 06:10:03 +00001031
1032 // Add the ordered list of -includes, sorting in the implicit include options
1033 // at the appropriate location.
1034 llvm::SmallVector<std::pair<unsigned, std::string*>, 8> OrderedPaths;
1035 std::string OriginalFile;
1036
1037 if (!ImplicitIncludePTH.empty())
1038 OrderedPaths.push_back(std::make_pair(ImplicitIncludePTH.getPosition(),
1039 &ImplicitIncludePTH));
1040 if (!ImplicitIncludePCH.empty()) {
1041 OriginalFile = PCHReader::getOriginalSourceFile(ImplicitIncludePCH);
1042 // FIXME: Don't fail like this.
1043 if (OriginalFile.empty())
1044 exit(1);
1045 OrderedPaths.push_back(std::make_pair(ImplicitIncludePCH.getPosition(),
1046 &OriginalFile));
1047 }
1048 for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i)
1049 OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i),
1050 &ImplicitIncludes[i]));
1051 llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end());
1052
1053 for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i)
Daniel Dunbard6ea9022009-11-17 05:52:41 +00001054 Opts.Includes.push_back(*OrderedPaths[i].second);
Daniel Dunbar999215c2009-11-11 06:10:03 +00001055}
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001056
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001057void clang::InitializeLangOptions(LangOptions &Options,
1058 FrontendOptions::InputKind IK,
Daniel Dunbar77a9d2b2009-11-16 22:38:14 +00001059 TargetInfo &Target) {
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001060 using namespace langoptions;
1061
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001062
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001063 switch (IK) {
1064 case FrontendOptions::IK_None:
1065 case FrontendOptions::IK_AST:
1066 assert(0 && "Invalid input kind!");
1067 case FrontendOptions::IK_Asm:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001068 Options.AsmPreprocessor = 1;
1069 // FALLTHROUGH
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001070 case FrontendOptions::IK_PreprocessedC:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001071 // FALLTHROUGH
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001072 case FrontendOptions::IK_C:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001073 // Do nothing.
1074 break;
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001075 case FrontendOptions::IK_PreprocessedCXX:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001076 // FALLTHROUGH
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001077 case FrontendOptions::IK_CXX:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001078 Options.CPlusPlus = 1;
1079 break;
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001080 case FrontendOptions::IK_PreprocessedObjC:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001081 // FALLTHROUGH
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001082 case FrontendOptions::IK_ObjC:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001083 Options.ObjC1 = Options.ObjC2 = 1;
1084 break;
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001085 case FrontendOptions::IK_PreprocessedObjCXX:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001086 // FALLTHROUGH
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001087 case FrontendOptions::IK_ObjCXX:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001088 Options.ObjC1 = Options.ObjC2 = 1;
1089 Options.CPlusPlus = 1;
1090 break;
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001091 case FrontendOptions::IK_OpenCL:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001092 Options.OpenCL = 1;
1093 Options.AltiVec = 1;
1094 Options.CXXOperatorNames = 1;
1095 Options.LaxVectorConversions = 1;
1096 break;
1097 }
1098
1099 if (ObjCExclusiveGC)
1100 Options.setGCMode(LangOptions::GCOnly);
1101 else if (ObjCEnableGC)
1102 Options.setGCMode(LangOptions::HybridGC);
1103
1104 if (ObjCEnableGCBitmapPrint)
1105 Options.ObjCGCBitmapPrint = 1;
1106
1107 if (AltiVec)
1108 Options.AltiVec = 1;
1109
1110 if (PThread)
1111 Options.POSIXThreads = 1;
1112
1113 Options.setVisibilityMode(SymbolVisibility);
1114 Options.OverflowChecking = OverflowChecking;
1115
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001116 if (LangStd == lang_unspecified) {
1117 // Based on the base language, pick one.
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001118 switch (IK) {
1119 case FrontendOptions::IK_None:
1120 case FrontendOptions::IK_AST:
1121 assert(0 && "Invalid input kind!");
1122 case FrontendOptions::IK_OpenCL:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001123 LangStd = lang_c99;
1124 break;
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001125 case FrontendOptions::IK_Asm:
1126 case FrontendOptions::IK_C:
1127 case FrontendOptions::IK_PreprocessedC:
1128 case FrontendOptions::IK_ObjC:
1129 case FrontendOptions::IK_PreprocessedObjC:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001130 LangStd = lang_gnu99;
1131 break;
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001132 case FrontendOptions::IK_CXX:
1133 case FrontendOptions::IK_PreprocessedCXX:
1134 case FrontendOptions::IK_ObjCXX:
1135 case FrontendOptions::IK_PreprocessedObjCXX:
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001136 LangStd = lang_gnucxx98;
1137 break;
1138 }
1139 }
1140
1141 switch (LangStd) {
1142 default: assert(0 && "Unknown language standard!");
1143
1144 // Fall through from newer standards to older ones. This isn't really right.
1145 // FIXME: Enable specifically the right features based on the language stds.
1146 case lang_gnucxx0x:
1147 case lang_cxx0x:
1148 Options.CPlusPlus0x = 1;
1149 // FALL THROUGH
1150 case lang_gnucxx98:
1151 case lang_cxx98:
1152 Options.CPlusPlus = 1;
1153 Options.CXXOperatorNames = !NoOperatorNames;
1154 // FALL THROUGH.
1155 case lang_gnu99:
1156 case lang_c99:
1157 Options.C99 = 1;
1158 Options.HexFloats = 1;
1159 // FALL THROUGH.
1160 case lang_gnu89:
1161 Options.BCPLComment = 1; // Only for C99/C++.
1162 // FALL THROUGH.
1163 case lang_c94:
1164 Options.Digraphs = 1; // C94, C99, C++.
1165 // FALL THROUGH.
1166 case lang_c89:
1167 break;
1168 }
1169
1170 // GNUMode - Set if we're in gnu99, gnu89, gnucxx98, etc.
1171 switch (LangStd) {
1172 default: assert(0 && "Unknown language standard!");
1173 case lang_gnucxx0x:
1174 case lang_gnucxx98:
1175 case lang_gnu99:
1176 case lang_gnu89:
1177 Options.GNUMode = 1;
1178 break;
1179 case lang_cxx0x:
1180 case lang_cxx98:
1181 case lang_c99:
1182 case lang_c94:
1183 case lang_c89:
1184 Options.GNUMode = 0;
1185 break;
1186 }
1187
1188 if (Options.CPlusPlus) {
1189 Options.C99 = 0;
1190 Options.HexFloats = 0;
1191 }
1192
1193 if (LangStd == lang_c89 || LangStd == lang_c94 || LangStd == lang_gnu89)
1194 Options.ImplicitInt = 1;
1195 else
1196 Options.ImplicitInt = 0;
1197
1198 // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
1199 // is specified, or -std is set to a conforming mode.
1200 Options.Trigraphs = !Options.GNUMode;
1201 if (Trigraphs.getPosition())
1202 Options.Trigraphs = Trigraphs; // Command line option wins if specified.
1203
1204 // If in a conformant language mode (e.g. -std=c99) Blocks defaults to off
1205 // even if they are normally on for the target. In GNU modes (e.g.
1206 // -std=gnu99) the default for blocks depends on the target settings.
1207 // However, blocks are not turned off when compiling Obj-C or Obj-C++ code.
1208 if (!Options.ObjC1 && !Options.GNUMode)
1209 Options.Blocks = 0;
1210
1211 // Default to not accepting '$' in identifiers when preprocessing assembler,
1212 // but do accept when preprocessing C. FIXME: these defaults are right for
1213 // darwin, are they right everywhere?
Daniel Dunbar27b19dc2009-11-13 02:06:12 +00001214 Options.DollarIdents = IK != FrontendOptions::IK_Asm;
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001215 if (DollarsInIdents.getPosition()) // Explicit setting overrides default.
1216 Options.DollarIdents = DollarsInIdents;
1217
1218 if (PascalStrings.getPosition())
1219 Options.PascalStrings = PascalStrings;
1220 if (MSExtensions.getPosition())
1221 Options.Microsoft = MSExtensions;
1222 Options.WritableStrings = WritableStrings;
1223 if (NoLaxVectorConversions.getPosition())
1224 Options.LaxVectorConversions = 0;
1225 Options.Exceptions = Exceptions;
Daniel Dunbar484afa22009-11-19 04:55:23 +00001226 Options.Rtti = !NoRtti;
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001227 if (EnableBlocks.getPosition())
1228 Options.Blocks = EnableBlocks;
1229 if (CharIsSigned.getPosition())
1230 Options.CharIsSigned = CharIsSigned;
1231 if (ShortWChar.getPosition())
1232 Options.ShortWChar = ShortWChar;
1233
Daniel Dunbar484afa22009-11-19 04:55:23 +00001234 Options.NoBuiltin = NoBuiltin;
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001235 if (Freestanding)
1236 Options.Freestanding = Options.NoBuiltin = 1;
1237
1238 if (EnableHeinousExtensions)
1239 Options.HeinousExtensions = 1;
1240
1241 if (AccessControl)
1242 Options.AccessControl = 1;
1243
1244 Options.ElideConstructors = !NoElideConstructors;
1245
1246 // OpenCL and C++ both have bool, true, false keywords.
1247 Options.Bool = Options.OpenCL | Options.CPlusPlus;
1248
Daniel Dunbar484afa22009-11-19 04:55:23 +00001249 Options.MathErrno = !NoMathErrno;
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001250
1251 Options.InstantiationDepth = TemplateDepth;
1252
1253 // Override the default runtime if the user requested it.
Daniel Dunbar4656c532009-11-17 07:07:28 +00001254 if (GNURuntime)
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001255 Options.NeXTRuntime = 0;
1256
1257 if (!ObjCConstantStringClass.empty())
1258 Options.ObjCConstantStringClass = ObjCConstantStringClass.c_str();
1259
1260 if (ObjCNonFragileABI)
1261 Options.ObjCNonFragileABI = 1;
1262
1263 if (EmitAllDecls)
1264 Options.EmitAllDecls = 1;
1265
1266 // The __OPTIMIZE_SIZE__ define is tied to -Oz, which we don't support.
1267 Options.OptimizeSize = 0;
Daniel Dunbar77a9d2b2009-11-16 22:38:14 +00001268 Options.Optimize = codegenoptions::OptSize || codegenoptions::OptLevel;
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001269
1270 assert(PICLevel <= 2 && "Invalid value for -pic-level");
1271 Options.PICLevel = PICLevel;
1272
1273 Options.GNUInline = !Options.C99;
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001274
1275 // This is the __NO_INLINE__ define, which just depends on things like the
1276 // optimization level and -fno-inline, not actually whether the backend has
1277 // inlining enabled.
Daniel Dunbar77a9d2b2009-11-16 22:38:14 +00001278 //
1279 // FIXME: This is affected by other options (-fno-inline).
1280 Options.NoInline = !codegenoptions::OptLevel;
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +00001281
1282 Options.Static = StaticDefine;
1283
1284 switch (StackProtector) {
1285 default:
1286 assert(StackProtector <= 2 && "Invalid value for -stack-protector");
1287 case -1: break;
1288 case 0: Options.setStackProtectorMode(LangOptions::SSPOff); break;
1289 case 1: Options.setStackProtectorMode(LangOptions::SSPOn); break;
1290 case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break;
1291 }
1292
1293 if (MainFileName.getPosition())
1294 Options.setMainFileName(MainFileName.c_str());
1295
1296 Target.setForcedLangOptions(Options);
1297}
Daniel Dunbar22bdabf2009-11-11 10:07:44 +00001298
1299void
1300clang::InitializePreprocessorOutputOptions(PreprocessorOutputOptions &Opts) {
1301 using namespace preprocessoroutputoptions;
1302
1303 Opts.ShowCPP = !DumpMacros;
1304 Opts.ShowMacros = DumpMacros || DumpDefines;
1305 Opts.ShowLineMarkers = !DisableLineMarkers;
1306 Opts.ShowComments = EnableCommentOutput;
1307 Opts.ShowMacroComments = EnableMacroCommentOutput;
1308}
Daniel Dunbarb9bbd542009-11-15 06:48:46 +00001309
1310void clang::InitializeTargetOptions(TargetOptions &Opts) {
1311 using namespace targetoptions;
1312
1313 Opts.ABI = TargetABI;
1314 Opts.CPU = TargetCPU;
1315 Opts.Triple = TargetTriple;
1316 Opts.Features = TargetFeatures;
1317
1318 // Use the host triple if unspecified.
1319 if (Opts.Triple.empty())
1320 Opts.Triple = llvm::sys::getHostTriple();
1321}