blob: 5d01e03a9ca8b3955c78ca881044f4e4f2220f6f [file] [log] [blame]
Daniel Dunbar0498cfc2009-11-10 19:51:53 +00001//===--- Options.cpp - clang-cc Option Handling ---------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// This file contains "pure" option handling, it is only responsible for turning
11// the options into internal *Option classes, but shouldn't have any other
12// logic.
13
14#include "Options.h"
Daniel Dunbar339c1342009-11-11 08:13:55 +000015#include "clang/Basic/LangOptions.h"
16#include "clang/Basic/TargetInfo.h"
17#include "clang/Frontend/AnalysisConsumer.h"
Chandler Carruth2811ccf2009-11-12 17:24:48 +000018#include "clang/CodeGen/CodeGenOptions.h"
Daniel Dunbar0e0bae82009-11-11 21:43:12 +000019#include "clang/Frontend/DependencyOutputOptions.h"
Daniel Dunbar0db4b762009-11-11 08:13:40 +000020#include "clang/Frontend/DiagnosticOptions.h"
Daniel Dunbar26266882009-11-12 23:52:32 +000021#include "clang/Frontend/FrontendOptions.h"
Daniel Dunbarf7973292009-11-11 08:13:32 +000022#include "clang/Frontend/HeaderSearchOptions.h"
Daniel Dunbarb52d2432009-11-11 06:10:03 +000023#include "clang/Frontend/PCHReader.h"
24#include "clang/Frontend/PreprocessorOptions.h"
Daniel Dunbar29cf7462009-11-11 10:07:44 +000025#include "clang/Frontend/PreprocessorOutputOptions.h"
Daniel Dunbarb52d2432009-11-11 06:10:03 +000026#include "llvm/ADT/STLExtras.h"
Daniel Dunbar0498cfc2009-11-10 19:51:53 +000027#include "llvm/ADT/StringMap.h"
28#include "llvm/Support/CommandLine.h"
Dan Gohman0063e982009-11-10 21:21:27 +000029#include <stdio.h>
Daniel Dunbar0498cfc2009-11-10 19:51:53 +000030
31using namespace clang;
32
33//===----------------------------------------------------------------------===//
Daniel Dunbar339c1342009-11-11 08:13:55 +000034// Analyzer Options
35//===----------------------------------------------------------------------===//
36
37namespace analyzeroptions {
38
39static llvm::cl::list<Analyses>
40AnalysisList(llvm::cl::desc("Source Code Analysis - Checks and Analyses"),
41llvm::cl::values(
42#define ANALYSIS(NAME, CMDFLAG, DESC, SCOPE)\
43clEnumValN(NAME, CMDFLAG, DESC),
44#include "clang/Frontend/Analyses.def"
45clEnumValEnd));
46
47static llvm::cl::opt<AnalysisStores>
48AnalysisStoreOpt("analyzer-store",
49 llvm::cl::desc("Source Code Analysis - Abstract Memory Store Models"),
50 llvm::cl::init(BasicStoreModel),
51 llvm::cl::values(
52#define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN)\
53clEnumValN(NAME##Model, CMDFLAG, DESC),
54#include "clang/Frontend/Analyses.def"
55clEnumValEnd));
56
57static llvm::cl::opt<AnalysisConstraints>
58AnalysisConstraintsOpt("analyzer-constraints",
59 llvm::cl::desc("Source Code Analysis - Symbolic Constraint Engines"),
60 llvm::cl::init(RangeConstraintsModel),
61 llvm::cl::values(
62#define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN)\
63clEnumValN(NAME##Model, CMDFLAG, DESC),
64#include "clang/Frontend/Analyses.def"
65clEnumValEnd));
66
67static llvm::cl::opt<AnalysisDiagClients>
68AnalysisDiagOpt("analyzer-output",
69 llvm::cl::desc("Source Code Analysis - Output Options"),
70 llvm::cl::init(PD_HTML),
71 llvm::cl::values(
72#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN, AUTOCREATE)\
73clEnumValN(PD_##NAME, CMDFLAG, DESC),
74#include "clang/Frontend/Analyses.def"
75clEnumValEnd));
76
77static llvm::cl::opt<bool>
78AnalyzeAll("analyzer-opt-analyze-headers",
79 llvm::cl::desc("Force the static analyzer to analyze "
80 "functions defined in header files"));
81
82static llvm::cl::opt<bool>
83AnalyzerDisplayProgress("analyzer-display-progress",
84 llvm::cl::desc("Emit verbose output about the analyzer's progress."));
85
86static llvm::cl::opt<std::string>
87AnalyzeSpecificFunction("analyze-function",
88 llvm::cl::desc("Run analysis on specific function"));
89
90static llvm::cl::opt<bool>
91EagerlyAssume("analyzer-eagerly-assume",
92 llvm::cl::init(false),
93 llvm::cl::desc("Eagerly assume the truth/falseness of some "
94 "symbolic constraints."));
95
96static llvm::cl::opt<bool>
97PurgeDead("analyzer-purge-dead",
98 llvm::cl::init(true),
99 llvm::cl::desc("Remove dead symbols, bindings, and constraints before"
100 " processing a statement."));
101
102static llvm::cl::opt<bool>
103TrimGraph("trim-egraph",
104 llvm::cl::desc("Only show error-related paths in the analysis graph"));
105
106static llvm::cl::opt<bool>
107VisualizeEGDot("analyzer-viz-egraph-graphviz",
108 llvm::cl::desc("Display exploded graph using GraphViz"));
109
110static llvm::cl::opt<bool>
111VisualizeEGUbi("analyzer-viz-egraph-ubigraph",
112 llvm::cl::desc("Display exploded graph using Ubigraph"));
113
114}
115
116void clang::InitializeAnalyzerOptions(AnalyzerOptions &Opts) {
117 using namespace analyzeroptions;
118 Opts.AnalysisList = AnalysisList;
119 Opts.AnalysisStoreOpt = AnalysisStoreOpt;
120 Opts.AnalysisConstraintsOpt = AnalysisConstraintsOpt;
121 Opts.AnalysisDiagOpt = AnalysisDiagOpt;
122 Opts.VisualizeEGDot = VisualizeEGDot;
123 Opts.VisualizeEGUbi = VisualizeEGUbi;
124 Opts.AnalyzeAll = AnalyzeAll;
125 Opts.AnalyzerDisplayProgress = AnalyzerDisplayProgress;
126 Opts.PurgeDead = PurgeDead;
127 Opts.EagerlyAssume = EagerlyAssume;
128 Opts.AnalyzeSpecificFunction = AnalyzeSpecificFunction;
129 Opts.TrimGraph = TrimGraph;
130}
131
132
133//===----------------------------------------------------------------------===//
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000134// Code Generation Options
135//===----------------------------------------------------------------------===//
136
137namespace codegenoptions {
138
139static llvm::cl::opt<bool>
140DisableLLVMOptimizations("disable-llvm-optzns",
141 llvm::cl::desc("Don't run LLVM optimization passes"));
142
143static llvm::cl::opt<bool>
144DisableRedZone("disable-red-zone",
145 llvm::cl::desc("Do not emit code that uses the red zone."),
146 llvm::cl::init(false));
147
148static llvm::cl::opt<bool>
149GenerateDebugInfo("g",
150 llvm::cl::desc("Generate source level debug information"));
151
152static llvm::cl::opt<bool>
153NoCommon("fno-common",
154 llvm::cl::desc("Compile common globals like normal definitions"),
155 llvm::cl::ValueDisallowed);
156
157static llvm::cl::opt<bool>
158NoImplicitFloat("no-implicit-float",
159 llvm::cl::desc("Don't generate implicit floating point instructions (x86-only)"),
160 llvm::cl::init(false));
161
162static llvm::cl::opt<bool>
163NoMergeConstants("fno-merge-all-constants",
164 llvm::cl::desc("Disallow merging of constants."));
165
166// It might be nice to add bounds to the CommandLine library directly.
167struct OptLevelParser : public llvm::cl::parser<unsigned> {
168 bool parse(llvm::cl::Option &O, llvm::StringRef ArgName,
169 llvm::StringRef Arg, unsigned &Val) {
170 if (llvm::cl::parser<unsigned>::parse(O, ArgName, Arg, Val))
171 return true;
172 if (Val > 3)
173 return O.error("'" + Arg + "' invalid optimization level!");
174 return false;
175 }
176};
177static llvm::cl::opt<unsigned, false, OptLevelParser>
178OptLevel("O", llvm::cl::Prefix,
179 llvm::cl::desc("Optimization level"),
180 llvm::cl::init(0));
181
182static llvm::cl::opt<bool>
183OptSize("Os", llvm::cl::desc("Optimize for size"));
184
185static llvm::cl::opt<std::string>
186TargetCPU("mcpu",
187 llvm::cl::desc("Target a specific cpu type (-mcpu=help for details)"));
188
189static llvm::cl::list<std::string>
190TargetFeatures("target-feature", llvm::cl::desc("Target specific attributes"));
191
192}
193
194//===----------------------------------------------------------------------===//
Daniel Dunbar0e0bae82009-11-11 21:43:12 +0000195// Dependency Output Options
196//===----------------------------------------------------------------------===//
197
198namespace dependencyoutputoptions {
199
200static llvm::cl::opt<std::string>
201DependencyFile("dependency-file",
202 llvm::cl::desc("Filename (or -) to write dependency output to"));
203
204static llvm::cl::opt<bool>
205DependenciesIncludeSystemHeaders("sys-header-deps",
206 llvm::cl::desc("Include system headers in dependency output"));
207
208static llvm::cl::list<std::string>
209DependencyTargets("MT",
210 llvm::cl::desc("Specify target for dependency"));
211
212static llvm::cl::opt<bool>
213PhonyDependencyTarget("MP",
214 llvm::cl::desc("Create phony target for each dependency "
215 "(other than main file)"));
216
217}
218
219//===----------------------------------------------------------------------===//
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000220// Diagnostic Options
221//===----------------------------------------------------------------------===//
222
223namespace diagnosticoptions {
224
Daniel Dunbar11e729d2009-11-12 07:28:21 +0000225static llvm::cl::opt<std::string>
226DumpBuildInformation("dump-build-information",
227 llvm::cl::value_desc("filename"),
228 llvm::cl::desc("output a dump of some build information to a file"));
229
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000230static llvm::cl::opt<bool>
231NoShowColumn("fno-show-column",
232 llvm::cl::desc("Do not include column number on diagnostics"));
233
234static llvm::cl::opt<bool>
235NoShowLocation("fno-show-source-location",
236 llvm::cl::desc("Do not include source location information with"
237 " diagnostics"));
238
239static llvm::cl::opt<bool>
240NoCaretDiagnostics("fno-caret-diagnostics",
241 llvm::cl::desc("Do not include source line and caret with"
242 " diagnostics"));
243
244static llvm::cl::opt<bool>
245NoDiagnosticsFixIt("fno-diagnostics-fixit-info",
246 llvm::cl::desc("Do not include fixit information in"
247 " diagnostics"));
248
Daniel Dunbar69079432009-11-12 07:28:44 +0000249static llvm::cl::opt<bool> OptNoWarnings("w");
250
251static llvm::cl::opt<bool> OptPedantic("pedantic");
252
253static llvm::cl::opt<bool> OptPedanticErrors("pedantic-errors");
254
255// This gets all -W options, including -Werror, -W[no-]system-headers, etc. The
256// driver has stripped off -Wa,foo etc. The driver has also translated -W to
257// -Wextra, so we don't need to worry about it.
258static llvm::cl::list<std::string>
259OptWarnings("W", llvm::cl::Prefix, llvm::cl::ValueOptional);
260
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000261static llvm::cl::opt<bool>
262PrintSourceRangeInfo("fdiagnostics-print-source-range-info",
263 llvm::cl::desc("Print source range spans in numeric form"));
264
265static llvm::cl::opt<bool>
266PrintDiagnosticOption("fdiagnostics-show-option",
267 llvm::cl::desc("Print diagnostic name with mappable diagnostics"));
268
269static llvm::cl::opt<unsigned>
270MessageLength("fmessage-length",
271 llvm::cl::desc("Format message diagnostics so that they fit "
272 "within N columns or fewer, when possible."),
273 llvm::cl::value_desc("N"));
274
275static llvm::cl::opt<bool>
276PrintColorDiagnostic("fcolor-diagnostics",
277 llvm::cl::desc("Use colors in diagnostics"));
278
Daniel Dunbar69079432009-11-12 07:28:44 +0000279static llvm::cl::opt<bool>
280SilenceRewriteMacroWarning("Wno-rewrite-macros", llvm::cl::init(false),
281 llvm::cl::desc("Silence ObjC rewriting warnings"));
282
Daniel Dunbar26266882009-11-12 23:52:32 +0000283static llvm::cl::opt<bool>
284VerifyDiagnostics("verify",
285 llvm::cl::desc("Verify emitted diagnostics and warnings"));
286
287}
288
289
290//===----------------------------------------------------------------------===//
291// Frontend Options
292//===----------------------------------------------------------------------===//
293
294namespace frontendoptions {
295
Daniel Dunbar914474c2009-11-13 01:02:10 +0000296static llvm::cl::opt<ParsedSourceLocation>
297CodeCompletionAt("code-completion-at",
298 llvm::cl::value_desc("file:line:column"),
299 llvm::cl::desc("Dump code-completion information at a location"));
300
301static llvm::cl::opt<bool>
302CodeCompletionDebugPrinter("code-completion-debug-printer",
303 llvm::cl::desc("Use the \"debug\" code-completion print"),
304 llvm::cl::init(true));
305
306static llvm::cl::opt<bool>
307CodeCompletionWantsMacros("code-completion-macros",
308 llvm::cl::desc("Include macros in code-completion results"));
309
Daniel Dunbar26266882009-11-12 23:52:32 +0000310static llvm::cl::opt<bool>
311DisableFree("disable-free",
312 llvm::cl::desc("Disable freeing of memory on exit"),
313 llvm::cl::init(false));
314
315static llvm::cl::opt<bool>
316EmptyInputOnly("empty-input-only",
317 llvm::cl::desc("Force running on an empty input file"));
318
319static llvm::cl::list<std::string>
320InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input files>"));
321
322static llvm::cl::opt<std::string>
323InheritanceViewCls("cxx-inheritance-view",
324 llvm::cl::value_desc("class name"),
325 llvm::cl::desc("View C++ inheritance for a specified class"));
326
327static llvm::cl::opt<bool>
328FixItAll("fixit", llvm::cl::desc("Apply fix-it advice to the input source"));
329
Daniel Dunbarc86804b2009-11-12 23:52:56 +0000330static llvm::cl::list<ParsedSourceLocation>
331FixItAtLocations("fixit-at", llvm::cl::value_desc("source-location"),
332 llvm::cl::desc("Perform Fix-It modifications at the given source location"));
333
Daniel Dunbar26266882009-11-12 23:52:32 +0000334static llvm::cl::opt<std::string>
335OutputFile("o",
336 llvm::cl::value_desc("path"),
337 llvm::cl::desc("Specify output file"));
338
339static llvm::cl::opt<bool>
340RelocatablePCH("relocatable-pch",
341 llvm::cl::desc("Whether to build a relocatable precompiled "
342 "header"));
343static llvm::cl::opt<bool>
344Stats("print-stats",
345 llvm::cl::desc("Print performance metrics and statistics"));
346
Daniel Dunbar21dac5e2009-11-13 01:02:19 +0000347static llvm::cl::opt<std::string>
348TargetABI("target-abi",
349 llvm::cl::desc("Target a particular ABI type"));
350
351static llvm::cl::opt<std::string>
352TargetTriple("triple",
353 llvm::cl::desc("Specify target triple (e.g. i686-apple-darwin9)"));
354
Daniel Dunbar26266882009-11-12 23:52:32 +0000355static llvm::cl::opt<bool>
356TimeReport("ftime-report",
357 llvm::cl::desc("Print the amount of time each "
358 "phase of compilation takes"));
359
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000360}
361
362//===----------------------------------------------------------------------===//
Daniel Dunbar56749082009-11-11 07:26:12 +0000363// Language Options
364//===----------------------------------------------------------------------===//
365
366namespace langoptions {
367
368static llvm::cl::opt<bool>
369AllowBuiltins("fbuiltin", llvm::cl::init(true),
370 llvm::cl::desc("Disable implicit builtin knowledge of functions"));
371
372static llvm::cl::opt<bool>
373AltiVec("faltivec", llvm::cl::desc("Enable AltiVec vector initializer syntax"),
374 llvm::cl::init(false));
375
376static llvm::cl::opt<bool>
377AccessControl("faccess-control",
378 llvm::cl::desc("Enable C++ access control"));
379
380static llvm::cl::opt<bool>
381CharIsSigned("fsigned-char",
382 llvm::cl::desc("Force char to be a signed/unsigned type"));
383
384static llvm::cl::opt<bool>
385DollarsInIdents("fdollars-in-identifiers",
386 llvm::cl::desc("Allow '$' in identifiers"));
387
388static llvm::cl::opt<bool>
389EmitAllDecls("femit-all-decls",
390 llvm::cl::desc("Emit all declarations, even if unused"));
391
392static llvm::cl::opt<bool>
393EnableBlocks("fblocks", llvm::cl::desc("enable the 'blocks' language feature"));
394
395static llvm::cl::opt<bool>
396EnableHeinousExtensions("fheinous-gnu-extensions",
397 llvm::cl::desc("enable GNU extensions that you really really shouldn't use"),
398 llvm::cl::ValueDisallowed, llvm::cl::Hidden);
399
400static llvm::cl::opt<bool>
401Exceptions("fexceptions",
402 llvm::cl::desc("Enable support for exception handling"));
403
404static llvm::cl::opt<bool>
405Freestanding("ffreestanding",
406 llvm::cl::desc("Assert that the compilation takes place in a "
407 "freestanding environment"));
408
409static llvm::cl::opt<bool>
410GNURuntime("fgnu-runtime",
411 llvm::cl::desc("Generate output compatible with the standard GNU "
412 "Objective-C runtime"));
413
414/// LangStds - Language standards we support.
415enum LangStds {
416 lang_unspecified,
417 lang_c89, lang_c94, lang_c99,
418 lang_gnu89, lang_gnu99,
419 lang_cxx98, lang_gnucxx98,
420 lang_cxx0x, lang_gnucxx0x
421};
422static llvm::cl::opt<LangStds>
423LangStd("std", llvm::cl::desc("Language standard to compile for"),
424 llvm::cl::init(lang_unspecified),
425 llvm::cl::values(clEnumValN(lang_c89, "c89", "ISO C 1990"),
426 clEnumValN(lang_c89, "c90", "ISO C 1990"),
427 clEnumValN(lang_c89, "iso9899:1990", "ISO C 1990"),
428 clEnumValN(lang_c94, "iso9899:199409",
429 "ISO C 1990 with amendment 1"),
430 clEnumValN(lang_c99, "c99", "ISO C 1999"),
431 clEnumValN(lang_c99, "c9x", "ISO C 1999"),
432 clEnumValN(lang_c99, "iso9899:1999", "ISO C 1999"),
433 clEnumValN(lang_c99, "iso9899:199x", "ISO C 1999"),
434 clEnumValN(lang_gnu89, "gnu89",
435 "ISO C 1990 with GNU extensions"),
436 clEnumValN(lang_gnu99, "gnu99",
437 "ISO C 1999 with GNU extensions (default for C)"),
438 clEnumValN(lang_gnu99, "gnu9x",
439 "ISO C 1999 with GNU extensions"),
440 clEnumValN(lang_cxx98, "c++98",
441 "ISO C++ 1998 with amendments"),
442 clEnumValN(lang_gnucxx98, "gnu++98",
443 "ISO C++ 1998 with amendments and GNU "
444 "extensions (default for C++)"),
445 clEnumValN(lang_cxx0x, "c++0x",
446 "Upcoming ISO C++ 200x with amendments"),
447 clEnumValN(lang_gnucxx0x, "gnu++0x",
448 "Upcoming ISO C++ 200x with amendments and GNU "
449 "extensions"),
450 clEnumValEnd));
451
452static llvm::cl::opt<bool>
453MSExtensions("fms-extensions",
454 llvm::cl::desc("Accept some non-standard constructs used in "
455 "Microsoft header files "));
456
457static llvm::cl::opt<std::string>
458MainFileName("main-file-name",
459 llvm::cl::desc("Main file name to use for debug info"));
460
461static llvm::cl::opt<bool>
462MathErrno("fmath-errno", llvm::cl::init(true),
463 llvm::cl::desc("Require math functions to respect errno"));
464
465static llvm::cl::opt<bool>
466NeXTRuntime("fnext-runtime",
467 llvm::cl::desc("Generate output compatible with the NeXT "
468 "runtime"));
469
470static llvm::cl::opt<bool>
471NoElideConstructors("fno-elide-constructors",
472 llvm::cl::desc("Disable C++ copy constructor elision"));
473
474static llvm::cl::opt<bool>
475NoLaxVectorConversions("fno-lax-vector-conversions",
476 llvm::cl::desc("Disallow implicit conversions between "
477 "vectors with a different number of "
478 "elements or different element types"));
479
480
481static llvm::cl::opt<bool>
482NoOperatorNames("fno-operator-names",
483 llvm::cl::desc("Do not treat C++ operator name keywords as "
484 "synonyms for operators"));
485
486static llvm::cl::opt<std::string>
487ObjCConstantStringClass("fconstant-string-class",
488 llvm::cl::value_desc("class name"),
489 llvm::cl::desc("Specify the class to use for constant "
490 "Objective-C string objects."));
491
492static llvm::cl::opt<bool>
493ObjCEnableGC("fobjc-gc",
494 llvm::cl::desc("Enable Objective-C garbage collection"));
495
496static llvm::cl::opt<bool>
497ObjCExclusiveGC("fobjc-gc-only",
498 llvm::cl::desc("Use GC exclusively for Objective-C related "
499 "memory management"));
500
501static llvm::cl::opt<bool>
502ObjCEnableGCBitmapPrint("print-ivar-layout",
503 llvm::cl::desc("Enable Objective-C Ivar layout bitmap print trace"));
504
505static llvm::cl::opt<bool>
506ObjCNonFragileABI("fobjc-nonfragile-abi",
507 llvm::cl::desc("enable objective-c's nonfragile abi"));
508
509static llvm::cl::opt<bool>
510OverflowChecking("ftrapv",
511 llvm::cl::desc("Trap on integer overflow"),
512 llvm::cl::init(false));
513
514static llvm::cl::opt<unsigned>
515PICLevel("pic-level", llvm::cl::desc("Value for __PIC__"));
516
517static llvm::cl::opt<bool>
518PThread("pthread", llvm::cl::desc("Support POSIX threads in generated code"),
519 llvm::cl::init(false));
520
521static llvm::cl::opt<bool>
522PascalStrings("fpascal-strings",
523 llvm::cl::desc("Recognize and construct Pascal-style "
524 "string literals"));
525
Daniel Dunbar56749082009-11-11 07:26:12 +0000526static llvm::cl::opt<bool>
527Rtti("frtti", llvm::cl::init(true),
528 llvm::cl::desc("Enable generation of rtti information"));
529
530static llvm::cl::opt<bool>
531ShortWChar("fshort-wchar",
532 llvm::cl::desc("Force wchar_t to be a short unsigned int"));
533
534static llvm::cl::opt<bool>
535StaticDefine("static-define", llvm::cl::desc("Should __STATIC__ be defined"));
536
537static llvm::cl::opt<int>
538StackProtector("stack-protector",
539 llvm::cl::desc("Enable stack protectors"),
540 llvm::cl::init(-1));
541
542static llvm::cl::opt<LangOptions::VisibilityMode>
543SymbolVisibility("fvisibility",
544 llvm::cl::desc("Set the default symbol visibility:"),
545 llvm::cl::init(LangOptions::Default),
546 llvm::cl::values(clEnumValN(LangOptions::Default, "default",
547 "Use default symbol visibility"),
548 clEnumValN(LangOptions::Hidden, "hidden",
549 "Use hidden symbol visibility"),
550 clEnumValN(LangOptions::Protected,"protected",
551 "Use protected symbol visibility"),
552 clEnumValEnd));
553
554static llvm::cl::opt<unsigned>
555TemplateDepth("ftemplate-depth", llvm::cl::init(99),
556 llvm::cl::desc("Maximum depth of recursive template "
557 "instantiation"));
558
559static llvm::cl::opt<bool>
560Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences"));
561
562static llvm::cl::opt<bool>
563WritableStrings("fwritable-strings",
564 llvm::cl::desc("Store string literals as writable data"));
565
566}
567
568//===----------------------------------------------------------------------===//
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000569// General Preprocessor Options
570//===----------------------------------------------------------------------===//
571
572namespace preprocessoroptions {
573
574static llvm::cl::list<std::string>
575D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
576 llvm::cl::desc("Predefine the specified macro"));
577
578static llvm::cl::list<std::string>
579ImplicitIncludes("include", llvm::cl::value_desc("file"),
580 llvm::cl::desc("Include file before parsing"));
581static llvm::cl::list<std::string>
582ImplicitMacroIncludes("imacros", llvm::cl::value_desc("file"),
583 llvm::cl::desc("Include macros from file before parsing"));
584
585static llvm::cl::opt<std::string>
586ImplicitIncludePCH("include-pch", llvm::cl::value_desc("file"),
587 llvm::cl::desc("Include precompiled header file"));
588
589static llvm::cl::opt<std::string>
590ImplicitIncludePTH("include-pth", llvm::cl::value_desc("file"),
591 llvm::cl::desc("Include file before parsing"));
592
Daniel Dunbarb3cb98e2009-11-12 02:53:59 +0000593static llvm::cl::opt<std::string>
594TokenCache("token-cache", llvm::cl::value_desc("path"),
595 llvm::cl::desc("Use specified token cache file"));
596
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000597static llvm::cl::list<std::string>
598U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
599 llvm::cl::desc("Undefine the specified macro"));
600
601static llvm::cl::opt<bool>
602UndefMacros("undef", llvm::cl::value_desc("macro"),
603 llvm::cl::desc("undef all system defines"));
604
605}
606
607//===----------------------------------------------------------------------===//
Daniel Dunbarf7973292009-11-11 08:13:32 +0000608// Header Search Options
609//===----------------------------------------------------------------------===//
610
611namespace headersearchoptions {
612
613static llvm::cl::opt<bool>
614nostdinc("nostdinc", llvm::cl::desc("Disable standard #include directories"));
615
616static llvm::cl::opt<bool>
617nobuiltininc("nobuiltininc",
618 llvm::cl::desc("Disable builtin #include directories"));
619
620// Various command line options. These four add directories to each chain.
621static llvm::cl::list<std::string>
622F_dirs("F", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
623 llvm::cl::desc("Add directory to framework include search path"));
624
625static llvm::cl::list<std::string>
626I_dirs("I", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
627 llvm::cl::desc("Add directory to include search path"));
628
629static llvm::cl::list<std::string>
630idirafter_dirs("idirafter", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
631 llvm::cl::desc("Add directory to AFTER include search path"));
632
633static llvm::cl::list<std::string>
634iquote_dirs("iquote", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
635 llvm::cl::desc("Add directory to QUOTE include search path"));
636
637static llvm::cl::list<std::string>
638isystem_dirs("isystem", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
639 llvm::cl::desc("Add directory to SYSTEM include search path"));
640
641// These handle -iprefix/-iwithprefix/-iwithprefixbefore.
642static llvm::cl::list<std::string>
643iprefix_vals("iprefix", llvm::cl::value_desc("prefix"), llvm::cl::Prefix,
644 llvm::cl::desc("Set the -iwithprefix/-iwithprefixbefore prefix"));
645static llvm::cl::list<std::string>
646iwithprefix_vals("iwithprefix", llvm::cl::value_desc("dir"), llvm::cl::Prefix,
647 llvm::cl::desc("Set directory to SYSTEM include search path with prefix"));
648static llvm::cl::list<std::string>
649iwithprefixbefore_vals("iwithprefixbefore", llvm::cl::value_desc("dir"),
650 llvm::cl::Prefix,
651 llvm::cl::desc("Set directory to include search path with prefix"));
652
653static llvm::cl::opt<std::string>
654isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::init("/"),
655 llvm::cl::desc("Set the system root directory (usually /)"));
656
Daniel Dunbar1417c742009-11-12 23:52:46 +0000657static llvm::cl::opt<bool>
658Verbose("v", llvm::cl::desc("Enable verbose output"));
659
Daniel Dunbarf7973292009-11-11 08:13:32 +0000660}
661
662//===----------------------------------------------------------------------===//
Daniel Dunbar29cf7462009-11-11 10:07:44 +0000663// Preprocessed Output Options
664//===----------------------------------------------------------------------===//
665
666namespace preprocessoroutputoptions {
667
668static llvm::cl::opt<bool>
669DisableLineMarkers("P", llvm::cl::desc("Disable linemarker output in -E mode"));
670
671static llvm::cl::opt<bool>
672EnableCommentOutput("C", llvm::cl::desc("Enable comment output in -E mode"));
673
674static llvm::cl::opt<bool>
675EnableMacroCommentOutput("CC",
676 llvm::cl::desc("Enable comment output in -E mode, "
677 "even from macro expansions"));
678static llvm::cl::opt<bool>
679DumpMacros("dM", llvm::cl::desc("Print macro definitions in -E mode instead of"
680 " normal output"));
681static llvm::cl::opt<bool>
682DumpDefines("dD", llvm::cl::desc("Print macro definitions in -E mode in "
683 "addition to normal output"));
684
685}
686
687//===----------------------------------------------------------------------===//
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000688// Option Object Construction
689//===----------------------------------------------------------------------===//
690
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000691void clang::InitializeCodeGenOptions(CodeGenOptions &Opts,
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000692 const TargetInfo &Target) {
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000693 using namespace codegenoptions;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000694
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000695 // Compute the target features, we need the target to handle this because
696 // features may have dependencies on one another.
697 llvm::StringMap<bool> Features;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000698 Target.getDefaultFeatures(TargetCPU, Features);
699
700 // Apply the user specified deltas.
701 for (llvm::cl::list<std::string>::iterator it = TargetFeatures.begin(),
702 ie = TargetFeatures.end(); it != ie; ++it) {
703 const char *Name = it->c_str();
704
705 // FIXME: Don't handle errors like this.
706 if (Name[0] != '-' && Name[0] != '+') {
707 fprintf(stderr, "error: clang-cc: invalid target feature string: %s\n",
708 Name);
709 exit(1);
710 }
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000711
712 // Apply the feature via the target.
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000713 if (!Target.setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) {
714 fprintf(stderr, "error: clang-cc: invalid target feature name: %s\n",
715 Name + 1);
716 exit(1);
717 }
718 }
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000719
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000720 // Add the features to the compile options.
721 //
722 // FIXME: If we are completely confident that we have the right set, we only
723 // need to pass the minuses.
724 for (llvm::StringMap<bool>::const_iterator it = Features.begin(),
725 ie = Features.end(); it != ie; ++it)
726 Opts.Features.push_back(std::string(it->second ? "+" : "-") + it->first());
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000727
728 // -Os implies -O2
729 Opts.OptimizationLevel = OptSize ? 2 : OptLevel;
730
731 // We must always run at least the always inlining pass.
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000732 Opts.Inlining = (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining
733 : CodeGenOptions::OnlyAlwaysInlining;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000734
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000735 Opts.CPU = TargetCPU;
736 Opts.DebugInfo = GenerateDebugInfo;
737 Opts.DisableLLVMOpts = DisableLLVMOptimizations;
738 Opts.DisableRedZone = DisableRedZone;
739 Opts.MergeAllConstants = !NoMergeConstants;
740 Opts.NoCommon = NoCommon;
741 Opts.NoImplicitFloat = NoImplicitFloat;
742 Opts.OptimizeSize = OptSize;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000743 Opts.SimplifyLibCalls = 1;
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000744 Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize);
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000745
746#ifdef NDEBUG
747 Opts.VerifyModule = 0;
748#endif
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000749}
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000750
Daniel Dunbar0e0bae82009-11-11 21:43:12 +0000751void clang::InitializeDependencyOutputOptions(DependencyOutputOptions &Opts) {
752 using namespace dependencyoutputoptions;
753
754 Opts.OutputFile = DependencyFile;
Daniel Dunbar26266882009-11-12 23:52:32 +0000755 Opts.Targets = DependencyTargets;
Daniel Dunbar0e0bae82009-11-11 21:43:12 +0000756 Opts.IncludeSystemHeaders = DependenciesIncludeSystemHeaders;
757 Opts.UsePhonyTargets = PhonyDependencyTarget;
758}
759
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000760void clang::InitializeDiagnosticOptions(DiagnosticOptions &Opts) {
761 using namespace diagnosticoptions;
762
Daniel Dunbar26266882009-11-12 23:52:32 +0000763 Opts.Warnings = OptWarnings;
Daniel Dunbar11e729d2009-11-12 07:28:21 +0000764 Opts.DumpBuildInformation = DumpBuildInformation;
Daniel Dunbar69079432009-11-12 07:28:44 +0000765 Opts.IgnoreWarnings = OptNoWarnings;
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000766 Opts.MessageLength = MessageLength;
Daniel Dunbar69079432009-11-12 07:28:44 +0000767 Opts.NoRewriteMacros = SilenceRewriteMacroWarning;
768 Opts.Pedantic = OptPedantic;
769 Opts.PedanticErrors = OptPedanticErrors;
Daniel Dunbar11e729d2009-11-12 07:28:21 +0000770 Opts.ShowCarets = !NoCaretDiagnostics;
771 Opts.ShowColors = PrintColorDiagnostic;
772 Opts.ShowColumn = !NoShowColumn;
773 Opts.ShowFixits = !NoDiagnosticsFixIt;
774 Opts.ShowLocation = !NoShowLocation;
775 Opts.ShowOptionNames = PrintDiagnosticOption;
776 Opts.ShowSourceRanges = PrintSourceRangeInfo;
Daniel Dunbar26266882009-11-12 23:52:32 +0000777 Opts.VerifyDiagnostics = VerifyDiagnostics;
778}
779
780void clang::InitializeFrontendOptions(FrontendOptions &Opts) {
781 using namespace frontendoptions;
782
Daniel Dunbar914474c2009-11-13 01:02:10 +0000783 Opts.CodeCompletionAt = CodeCompletionAt;
784 Opts.DebugCodeCompletionPrinter = CodeCompletionDebugPrinter;
Daniel Dunbar26266882009-11-12 23:52:32 +0000785 Opts.DisableFree = DisableFree;
786 Opts.EmptyInputOnly = EmptyInputOnly;
787 Opts.FixItAll = FixItAll;
Daniel Dunbarc86804b2009-11-12 23:52:56 +0000788 Opts.FixItLocations = FixItAtLocations;
Daniel Dunbar26266882009-11-12 23:52:32 +0000789 Opts.InputFilenames = InputFilenames;
790 Opts.OutputFile = OutputFile;
Daniel Dunbar914474c2009-11-13 01:02:10 +0000791 Opts.RelocatablePCH = RelocatablePCH;
792 Opts.ShowMacrosInCodeCompletion = CodeCompletionWantsMacros;
793 Opts.ShowStats = Stats;
794 Opts.ShowTimers = TimeReport;
Daniel Dunbar21dac5e2009-11-13 01:02:19 +0000795 Opts.TargetABI = TargetABI;
796 Opts.TargetTriple = TargetTriple;
Daniel Dunbar26266882009-11-12 23:52:32 +0000797 Opts.ViewClassInheritance = InheritanceViewCls;
798
799 // '-' is the default input if none is given.
800 if (Opts.InputFilenames.empty())
801 Opts.InputFilenames.push_back("-");
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000802}
803
Daniel Dunbarf7973292009-11-11 08:13:32 +0000804void clang::InitializeHeaderSearchOptions(HeaderSearchOptions &Opts,
805 llvm::StringRef BuiltinIncludePath,
Daniel Dunbarf7973292009-11-11 08:13:32 +0000806 const LangOptions &Lang) {
807 using namespace headersearchoptions;
808
809 Opts.Sysroot = isysroot;
810 Opts.Verbose = Verbose;
811
812 // Handle -I... and -F... options, walking the lists in parallel.
813 unsigned Iidx = 0, Fidx = 0;
814 while (Iidx < I_dirs.size() && Fidx < F_dirs.size()) {
815 if (I_dirs.getPosition(Iidx) < F_dirs.getPosition(Fidx)) {
816 Opts.AddPath(I_dirs[Iidx], frontend::Angled, false, true, false);
817 ++Iidx;
818 } else {
819 Opts.AddPath(F_dirs[Fidx], frontend::Angled, false, true, true);
820 ++Fidx;
821 }
822 }
823
824 // Consume what's left from whatever list was longer.
825 for (; Iidx != I_dirs.size(); ++Iidx)
826 Opts.AddPath(I_dirs[Iidx], frontend::Angled, false, true, false);
827 for (; Fidx != F_dirs.size(); ++Fidx)
828 Opts.AddPath(F_dirs[Fidx], frontend::Angled, false, true, true);
829
830 // Handle -idirafter... options.
831 for (unsigned i = 0, e = idirafter_dirs.size(); i != e; ++i)
832 Opts.AddPath(idirafter_dirs[i], frontend::After,
833 false, true, false);
834
835 // Handle -iquote... options.
836 for (unsigned i = 0, e = iquote_dirs.size(); i != e; ++i)
837 Opts.AddPath(iquote_dirs[i], frontend::Quoted, false, true, false);
838
839 // Handle -isystem... options.
840 for (unsigned i = 0, e = isystem_dirs.size(); i != e; ++i)
841 Opts.AddPath(isystem_dirs[i], frontend::System, false, true, false);
842
843 // Walk the -iprefix/-iwithprefix/-iwithprefixbefore argument lists in
844 // parallel, processing the values in order of occurance to get the right
845 // prefixes.
846 {
847 std::string Prefix = ""; // FIXME: this isn't the correct default prefix.
848 unsigned iprefix_idx = 0;
849 unsigned iwithprefix_idx = 0;
850 unsigned iwithprefixbefore_idx = 0;
851 bool iprefix_done = iprefix_vals.empty();
852 bool iwithprefix_done = iwithprefix_vals.empty();
853 bool iwithprefixbefore_done = iwithprefixbefore_vals.empty();
854 while (!iprefix_done || !iwithprefix_done || !iwithprefixbefore_done) {
855 if (!iprefix_done &&
856 (iwithprefix_done ||
857 iprefix_vals.getPosition(iprefix_idx) <
858 iwithprefix_vals.getPosition(iwithprefix_idx)) &&
859 (iwithprefixbefore_done ||
860 iprefix_vals.getPosition(iprefix_idx) <
861 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
862 Prefix = iprefix_vals[iprefix_idx];
863 ++iprefix_idx;
864 iprefix_done = iprefix_idx == iprefix_vals.size();
865 } else if (!iwithprefix_done &&
866 (iwithprefixbefore_done ||
867 iwithprefix_vals.getPosition(iwithprefix_idx) <
868 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
869 Opts.AddPath(Prefix+iwithprefix_vals[iwithprefix_idx],
870 frontend::System, false, false, false);
871 ++iwithprefix_idx;
872 iwithprefix_done = iwithprefix_idx == iwithprefix_vals.size();
873 } else {
874 Opts.AddPath(Prefix+iwithprefixbefore_vals[iwithprefixbefore_idx],
875 frontend::Angled, false, false, false);
876 ++iwithprefixbefore_idx;
877 iwithprefixbefore_done =
878 iwithprefixbefore_idx == iwithprefixbefore_vals.size();
879 }
880 }
881 }
882
883 // Add CPATH environment paths.
884 if (const char *Env = getenv("CPATH"))
885 Opts.EnvIncPath = Env;
886
887 // Add language specific environment paths.
888 if (Lang.CPlusPlus && Lang.ObjC1) {
889 if (const char *Env = getenv("OBJCPLUS_INCLUDE_PATH"))
890 Opts.LangEnvIncPath = Env;
891 } else if (Lang.CPlusPlus) {
892 if (const char *Env = getenv("CPLUS_INCLUDE_PATH"))
893 Opts.LangEnvIncPath = Env;
894 } else if (Lang.ObjC1) {
895 if (const char *Env = getenv("OBJC_INCLUDE_PATH"))
896 Opts.LangEnvIncPath = Env;
897 } else {
898 if (const char *Env = getenv("C_INCLUDE_PATH"))
899 Opts.LangEnvIncPath = Env;
900 }
901
902 if (!nobuiltininc)
903 Opts.BuiltinIncludePath = BuiltinIncludePath;
904
905 Opts.UseStandardIncludes = !nostdinc;
906}
907
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000908void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) {
909 using namespace preprocessoroptions;
910
911 Opts.setImplicitPCHInclude(ImplicitIncludePCH);
912 Opts.setImplicitPTHInclude(ImplicitIncludePTH);
913
Daniel Dunbarb3cb98e2009-11-12 02:53:59 +0000914 // Select the token cache file, we don't support more than one currently so we
915 // can't have both an implicit-pth and a token cache file.
916 if (TokenCache.getPosition() && ImplicitIncludePTH.getPosition()) {
917 // FIXME: Don't fail like this.
918 fprintf(stderr, "error: cannot use both -token-cache and -include-pth "
919 "options\n");
920 exit(1);
921 }
922 if (TokenCache.getPosition())
923 Opts.setTokenCache(TokenCache);
924 else
925 Opts.setTokenCache(ImplicitIncludePTH);
926
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000927 // Use predefines?
928 Opts.setUsePredefines(!UndefMacros);
929
930 // Add macros from the command line.
931 unsigned d = 0, D = D_macros.size();
932 unsigned u = 0, U = U_macros.size();
933 while (d < D || u < U) {
934 if (u == U || (d < D && D_macros.getPosition(d) < U_macros.getPosition(u)))
935 Opts.addMacroDef(D_macros[d++]);
936 else
937 Opts.addMacroUndef(U_macros[u++]);
938 }
939
940 // If -imacros are specified, include them now. These are processed before
941 // any -include directives.
942 for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i)
943 Opts.addMacroInclude(ImplicitMacroIncludes[i]);
944
945 // Add the ordered list of -includes, sorting in the implicit include options
946 // at the appropriate location.
947 llvm::SmallVector<std::pair<unsigned, std::string*>, 8> OrderedPaths;
948 std::string OriginalFile;
949
950 if (!ImplicitIncludePTH.empty())
951 OrderedPaths.push_back(std::make_pair(ImplicitIncludePTH.getPosition(),
952 &ImplicitIncludePTH));
953 if (!ImplicitIncludePCH.empty()) {
954 OriginalFile = PCHReader::getOriginalSourceFile(ImplicitIncludePCH);
955 // FIXME: Don't fail like this.
956 if (OriginalFile.empty())
957 exit(1);
958 OrderedPaths.push_back(std::make_pair(ImplicitIncludePCH.getPosition(),
959 &OriginalFile));
960 }
961 for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i)
962 OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i),
963 &ImplicitIncludes[i]));
964 llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end());
965
966 for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i)
967 Opts.addInclude(*OrderedPaths[i].second);
968}
Daniel Dunbar56749082009-11-11 07:26:12 +0000969
970void clang::InitializeLangOptions(LangOptions &Options, LangKind LK,
971 TargetInfo &Target,
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000972 const CodeGenOptions &CodeGenOpts) {
Daniel Dunbar56749082009-11-11 07:26:12 +0000973 using namespace langoptions;
974
975 bool NoPreprocess = false;
976
977 switch (LK) {
978 default: assert(0 && "Unknown language kind!");
979 case langkind_asm_cpp:
980 Options.AsmPreprocessor = 1;
981 // FALLTHROUGH
982 case langkind_c_cpp:
983 NoPreprocess = true;
984 // FALLTHROUGH
985 case langkind_c:
986 // Do nothing.
987 break;
988 case langkind_cxx_cpp:
989 NoPreprocess = true;
990 // FALLTHROUGH
991 case langkind_cxx:
992 Options.CPlusPlus = 1;
993 break;
994 case langkind_objc_cpp:
995 NoPreprocess = true;
996 // FALLTHROUGH
997 case langkind_objc:
998 Options.ObjC1 = Options.ObjC2 = 1;
999 break;
1000 case langkind_objcxx_cpp:
1001 NoPreprocess = true;
1002 // FALLTHROUGH
1003 case langkind_objcxx:
1004 Options.ObjC1 = Options.ObjC2 = 1;
1005 Options.CPlusPlus = 1;
1006 break;
1007 case langkind_ocl:
1008 Options.OpenCL = 1;
1009 Options.AltiVec = 1;
1010 Options.CXXOperatorNames = 1;
1011 Options.LaxVectorConversions = 1;
1012 break;
1013 }
1014
1015 if (ObjCExclusiveGC)
1016 Options.setGCMode(LangOptions::GCOnly);
1017 else if (ObjCEnableGC)
1018 Options.setGCMode(LangOptions::HybridGC);
1019
1020 if (ObjCEnableGCBitmapPrint)
1021 Options.ObjCGCBitmapPrint = 1;
1022
1023 if (AltiVec)
1024 Options.AltiVec = 1;
1025
1026 if (PThread)
1027 Options.POSIXThreads = 1;
1028
1029 Options.setVisibilityMode(SymbolVisibility);
1030 Options.OverflowChecking = OverflowChecking;
1031
1032
1033 // Allow the target to set the default the language options as it sees fit.
1034 Target.getDefaultLangOptions(Options);
1035
1036 // Pass the map of target features to the target for validation and
1037 // processing.
Chandler Carruth2811ccf2009-11-12 17:24:48 +00001038 Target.HandleTargetFeatures(CodeGenOpts.Features);
Daniel Dunbar56749082009-11-11 07:26:12 +00001039
1040 if (LangStd == lang_unspecified) {
1041 // Based on the base language, pick one.
1042 switch (LK) {
1043 case langkind_ast: assert(0 && "Invalid call for AST inputs");
1044 case lang_unspecified: assert(0 && "Unknown base language");
1045 case langkind_ocl:
1046 LangStd = lang_c99;
1047 break;
1048 case langkind_c:
1049 case langkind_asm_cpp:
1050 case langkind_c_cpp:
1051 case langkind_objc:
1052 case langkind_objc_cpp:
1053 LangStd = lang_gnu99;
1054 break;
1055 case langkind_cxx:
1056 case langkind_cxx_cpp:
1057 case langkind_objcxx:
1058 case langkind_objcxx_cpp:
1059 LangStd = lang_gnucxx98;
1060 break;
1061 }
1062 }
1063
1064 switch (LangStd) {
1065 default: assert(0 && "Unknown language standard!");
1066
1067 // Fall through from newer standards to older ones. This isn't really right.
1068 // FIXME: Enable specifically the right features based on the language stds.
1069 case lang_gnucxx0x:
1070 case lang_cxx0x:
1071 Options.CPlusPlus0x = 1;
1072 // FALL THROUGH
1073 case lang_gnucxx98:
1074 case lang_cxx98:
1075 Options.CPlusPlus = 1;
1076 Options.CXXOperatorNames = !NoOperatorNames;
1077 // FALL THROUGH.
1078 case lang_gnu99:
1079 case lang_c99:
1080 Options.C99 = 1;
1081 Options.HexFloats = 1;
1082 // FALL THROUGH.
1083 case lang_gnu89:
1084 Options.BCPLComment = 1; // Only for C99/C++.
1085 // FALL THROUGH.
1086 case lang_c94:
1087 Options.Digraphs = 1; // C94, C99, C++.
1088 // FALL THROUGH.
1089 case lang_c89:
1090 break;
1091 }
1092
1093 // GNUMode - Set if we're in gnu99, gnu89, gnucxx98, etc.
1094 switch (LangStd) {
1095 default: assert(0 && "Unknown language standard!");
1096 case lang_gnucxx0x:
1097 case lang_gnucxx98:
1098 case lang_gnu99:
1099 case lang_gnu89:
1100 Options.GNUMode = 1;
1101 break;
1102 case lang_cxx0x:
1103 case lang_cxx98:
1104 case lang_c99:
1105 case lang_c94:
1106 case lang_c89:
1107 Options.GNUMode = 0;
1108 break;
1109 }
1110
1111 if (Options.CPlusPlus) {
1112 Options.C99 = 0;
1113 Options.HexFloats = 0;
1114 }
1115
1116 if (LangStd == lang_c89 || LangStd == lang_c94 || LangStd == lang_gnu89)
1117 Options.ImplicitInt = 1;
1118 else
1119 Options.ImplicitInt = 0;
1120
1121 // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
1122 // is specified, or -std is set to a conforming mode.
1123 Options.Trigraphs = !Options.GNUMode;
1124 if (Trigraphs.getPosition())
1125 Options.Trigraphs = Trigraphs; // Command line option wins if specified.
1126
1127 // If in a conformant language mode (e.g. -std=c99) Blocks defaults to off
1128 // even if they are normally on for the target. In GNU modes (e.g.
1129 // -std=gnu99) the default for blocks depends on the target settings.
1130 // However, blocks are not turned off when compiling Obj-C or Obj-C++ code.
1131 if (!Options.ObjC1 && !Options.GNUMode)
1132 Options.Blocks = 0;
1133
1134 // Default to not accepting '$' in identifiers when preprocessing assembler,
1135 // but do accept when preprocessing C. FIXME: these defaults are right for
1136 // darwin, are they right everywhere?
1137 Options.DollarIdents = LK != langkind_asm_cpp;
1138 if (DollarsInIdents.getPosition()) // Explicit setting overrides default.
1139 Options.DollarIdents = DollarsInIdents;
1140
1141 if (PascalStrings.getPosition())
1142 Options.PascalStrings = PascalStrings;
1143 if (MSExtensions.getPosition())
1144 Options.Microsoft = MSExtensions;
1145 Options.WritableStrings = WritableStrings;
1146 if (NoLaxVectorConversions.getPosition())
1147 Options.LaxVectorConversions = 0;
1148 Options.Exceptions = Exceptions;
1149 Options.Rtti = Rtti;
1150 if (EnableBlocks.getPosition())
1151 Options.Blocks = EnableBlocks;
1152 if (CharIsSigned.getPosition())
1153 Options.CharIsSigned = CharIsSigned;
1154 if (ShortWChar.getPosition())
1155 Options.ShortWChar = ShortWChar;
1156
1157 if (!AllowBuiltins)
1158 Options.NoBuiltin = 1;
1159 if (Freestanding)
1160 Options.Freestanding = Options.NoBuiltin = 1;
1161
1162 if (EnableHeinousExtensions)
1163 Options.HeinousExtensions = 1;
1164
1165 if (AccessControl)
1166 Options.AccessControl = 1;
1167
1168 Options.ElideConstructors = !NoElideConstructors;
1169
1170 // OpenCL and C++ both have bool, true, false keywords.
1171 Options.Bool = Options.OpenCL | Options.CPlusPlus;
1172
1173 Options.MathErrno = MathErrno;
1174
1175 Options.InstantiationDepth = TemplateDepth;
1176
1177 // Override the default runtime if the user requested it.
1178 if (NeXTRuntime)
1179 Options.NeXTRuntime = 1;
1180 else if (GNURuntime)
1181 Options.NeXTRuntime = 0;
1182
1183 if (!ObjCConstantStringClass.empty())
1184 Options.ObjCConstantStringClass = ObjCConstantStringClass.c_str();
1185
1186 if (ObjCNonFragileABI)
1187 Options.ObjCNonFragileABI = 1;
1188
1189 if (EmitAllDecls)
1190 Options.EmitAllDecls = 1;
1191
1192 // The __OPTIMIZE_SIZE__ define is tied to -Oz, which we don't support.
1193 Options.OptimizeSize = 0;
Chandler Carruth2811ccf2009-11-12 17:24:48 +00001194 Options.Optimize = !!CodeGenOpts.OptimizationLevel;
Daniel Dunbar56749082009-11-11 07:26:12 +00001195
1196 assert(PICLevel <= 2 && "Invalid value for -pic-level");
1197 Options.PICLevel = PICLevel;
1198
1199 Options.GNUInline = !Options.C99;
1200 // FIXME: This is affected by other options (-fno-inline).
1201
1202 // This is the __NO_INLINE__ define, which just depends on things like the
1203 // optimization level and -fno-inline, not actually whether the backend has
1204 // inlining enabled.
Chandler Carruth2811ccf2009-11-12 17:24:48 +00001205 Options.NoInline = !CodeGenOpts.OptimizationLevel;
Daniel Dunbar56749082009-11-11 07:26:12 +00001206
1207 Options.Static = StaticDefine;
1208
1209 switch (StackProtector) {
1210 default:
1211 assert(StackProtector <= 2 && "Invalid value for -stack-protector");
1212 case -1: break;
1213 case 0: Options.setStackProtectorMode(LangOptions::SSPOff); break;
1214 case 1: Options.setStackProtectorMode(LangOptions::SSPOn); break;
1215 case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break;
1216 }
1217
1218 if (MainFileName.getPosition())
1219 Options.setMainFileName(MainFileName.c_str());
1220
1221 Target.setForcedLangOptions(Options);
1222}
Daniel Dunbar29cf7462009-11-11 10:07:44 +00001223
1224void
1225clang::InitializePreprocessorOutputOptions(PreprocessorOutputOptions &Opts) {
1226 using namespace preprocessoroutputoptions;
1227
1228 Opts.ShowCPP = !DumpMacros;
1229 Opts.ShowMacros = DumpMacros || DumpDefines;
1230 Opts.ShowLineMarkers = !DisableLineMarkers;
1231 Opts.ShowComments = EnableCommentOutput;
1232 Opts.ShowMacroComments = EnableMacroCommentOutput;
1233}