blob: bedf852811e9f58f0821c989c488f31b5e9396c9 [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
347static llvm::cl::opt<bool>
348TimeReport("ftime-report",
349 llvm::cl::desc("Print the amount of time each "
350 "phase of compilation takes"));
351
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000352}
353
354//===----------------------------------------------------------------------===//
Daniel Dunbar56749082009-11-11 07:26:12 +0000355// Language Options
356//===----------------------------------------------------------------------===//
357
358namespace langoptions {
359
360static llvm::cl::opt<bool>
361AllowBuiltins("fbuiltin", llvm::cl::init(true),
362 llvm::cl::desc("Disable implicit builtin knowledge of functions"));
363
364static llvm::cl::opt<bool>
365AltiVec("faltivec", llvm::cl::desc("Enable AltiVec vector initializer syntax"),
366 llvm::cl::init(false));
367
368static llvm::cl::opt<bool>
369AccessControl("faccess-control",
370 llvm::cl::desc("Enable C++ access control"));
371
372static llvm::cl::opt<bool>
373CharIsSigned("fsigned-char",
374 llvm::cl::desc("Force char to be a signed/unsigned type"));
375
376static llvm::cl::opt<bool>
377DollarsInIdents("fdollars-in-identifiers",
378 llvm::cl::desc("Allow '$' in identifiers"));
379
380static llvm::cl::opt<bool>
381EmitAllDecls("femit-all-decls",
382 llvm::cl::desc("Emit all declarations, even if unused"));
383
384static llvm::cl::opt<bool>
385EnableBlocks("fblocks", llvm::cl::desc("enable the 'blocks' language feature"));
386
387static llvm::cl::opt<bool>
388EnableHeinousExtensions("fheinous-gnu-extensions",
389 llvm::cl::desc("enable GNU extensions that you really really shouldn't use"),
390 llvm::cl::ValueDisallowed, llvm::cl::Hidden);
391
392static llvm::cl::opt<bool>
393Exceptions("fexceptions",
394 llvm::cl::desc("Enable support for exception handling"));
395
396static llvm::cl::opt<bool>
397Freestanding("ffreestanding",
398 llvm::cl::desc("Assert that the compilation takes place in a "
399 "freestanding environment"));
400
401static llvm::cl::opt<bool>
402GNURuntime("fgnu-runtime",
403 llvm::cl::desc("Generate output compatible with the standard GNU "
404 "Objective-C runtime"));
405
406/// LangStds - Language standards we support.
407enum LangStds {
408 lang_unspecified,
409 lang_c89, lang_c94, lang_c99,
410 lang_gnu89, lang_gnu99,
411 lang_cxx98, lang_gnucxx98,
412 lang_cxx0x, lang_gnucxx0x
413};
414static llvm::cl::opt<LangStds>
415LangStd("std", llvm::cl::desc("Language standard to compile for"),
416 llvm::cl::init(lang_unspecified),
417 llvm::cl::values(clEnumValN(lang_c89, "c89", "ISO C 1990"),
418 clEnumValN(lang_c89, "c90", "ISO C 1990"),
419 clEnumValN(lang_c89, "iso9899:1990", "ISO C 1990"),
420 clEnumValN(lang_c94, "iso9899:199409",
421 "ISO C 1990 with amendment 1"),
422 clEnumValN(lang_c99, "c99", "ISO C 1999"),
423 clEnumValN(lang_c99, "c9x", "ISO C 1999"),
424 clEnumValN(lang_c99, "iso9899:1999", "ISO C 1999"),
425 clEnumValN(lang_c99, "iso9899:199x", "ISO C 1999"),
426 clEnumValN(lang_gnu89, "gnu89",
427 "ISO C 1990 with GNU extensions"),
428 clEnumValN(lang_gnu99, "gnu99",
429 "ISO C 1999 with GNU extensions (default for C)"),
430 clEnumValN(lang_gnu99, "gnu9x",
431 "ISO C 1999 with GNU extensions"),
432 clEnumValN(lang_cxx98, "c++98",
433 "ISO C++ 1998 with amendments"),
434 clEnumValN(lang_gnucxx98, "gnu++98",
435 "ISO C++ 1998 with amendments and GNU "
436 "extensions (default for C++)"),
437 clEnumValN(lang_cxx0x, "c++0x",
438 "Upcoming ISO C++ 200x with amendments"),
439 clEnumValN(lang_gnucxx0x, "gnu++0x",
440 "Upcoming ISO C++ 200x with amendments and GNU "
441 "extensions"),
442 clEnumValEnd));
443
444static llvm::cl::opt<bool>
445MSExtensions("fms-extensions",
446 llvm::cl::desc("Accept some non-standard constructs used in "
447 "Microsoft header files "));
448
449static llvm::cl::opt<std::string>
450MainFileName("main-file-name",
451 llvm::cl::desc("Main file name to use for debug info"));
452
453static llvm::cl::opt<bool>
454MathErrno("fmath-errno", llvm::cl::init(true),
455 llvm::cl::desc("Require math functions to respect errno"));
456
457static llvm::cl::opt<bool>
458NeXTRuntime("fnext-runtime",
459 llvm::cl::desc("Generate output compatible with the NeXT "
460 "runtime"));
461
462static llvm::cl::opt<bool>
463NoElideConstructors("fno-elide-constructors",
464 llvm::cl::desc("Disable C++ copy constructor elision"));
465
466static llvm::cl::opt<bool>
467NoLaxVectorConversions("fno-lax-vector-conversions",
468 llvm::cl::desc("Disallow implicit conversions between "
469 "vectors with a different number of "
470 "elements or different element types"));
471
472
473static llvm::cl::opt<bool>
474NoOperatorNames("fno-operator-names",
475 llvm::cl::desc("Do not treat C++ operator name keywords as "
476 "synonyms for operators"));
477
478static llvm::cl::opt<std::string>
479ObjCConstantStringClass("fconstant-string-class",
480 llvm::cl::value_desc("class name"),
481 llvm::cl::desc("Specify the class to use for constant "
482 "Objective-C string objects."));
483
484static llvm::cl::opt<bool>
485ObjCEnableGC("fobjc-gc",
486 llvm::cl::desc("Enable Objective-C garbage collection"));
487
488static llvm::cl::opt<bool>
489ObjCExclusiveGC("fobjc-gc-only",
490 llvm::cl::desc("Use GC exclusively for Objective-C related "
491 "memory management"));
492
493static llvm::cl::opt<bool>
494ObjCEnableGCBitmapPrint("print-ivar-layout",
495 llvm::cl::desc("Enable Objective-C Ivar layout bitmap print trace"));
496
497static llvm::cl::opt<bool>
498ObjCNonFragileABI("fobjc-nonfragile-abi",
499 llvm::cl::desc("enable objective-c's nonfragile abi"));
500
501static llvm::cl::opt<bool>
502OverflowChecking("ftrapv",
503 llvm::cl::desc("Trap on integer overflow"),
504 llvm::cl::init(false));
505
506static llvm::cl::opt<unsigned>
507PICLevel("pic-level", llvm::cl::desc("Value for __PIC__"));
508
509static llvm::cl::opt<bool>
510PThread("pthread", llvm::cl::desc("Support POSIX threads in generated code"),
511 llvm::cl::init(false));
512
513static llvm::cl::opt<bool>
514PascalStrings("fpascal-strings",
515 llvm::cl::desc("Recognize and construct Pascal-style "
516 "string literals"));
517
Daniel Dunbar56749082009-11-11 07:26:12 +0000518static llvm::cl::opt<bool>
519Rtti("frtti", llvm::cl::init(true),
520 llvm::cl::desc("Enable generation of rtti information"));
521
522static llvm::cl::opt<bool>
523ShortWChar("fshort-wchar",
524 llvm::cl::desc("Force wchar_t to be a short unsigned int"));
525
526static llvm::cl::opt<bool>
527StaticDefine("static-define", llvm::cl::desc("Should __STATIC__ be defined"));
528
529static llvm::cl::opt<int>
530StackProtector("stack-protector",
531 llvm::cl::desc("Enable stack protectors"),
532 llvm::cl::init(-1));
533
534static llvm::cl::opt<LangOptions::VisibilityMode>
535SymbolVisibility("fvisibility",
536 llvm::cl::desc("Set the default symbol visibility:"),
537 llvm::cl::init(LangOptions::Default),
538 llvm::cl::values(clEnumValN(LangOptions::Default, "default",
539 "Use default symbol visibility"),
540 clEnumValN(LangOptions::Hidden, "hidden",
541 "Use hidden symbol visibility"),
542 clEnumValN(LangOptions::Protected,"protected",
543 "Use protected symbol visibility"),
544 clEnumValEnd));
545
546static llvm::cl::opt<unsigned>
547TemplateDepth("ftemplate-depth", llvm::cl::init(99),
548 llvm::cl::desc("Maximum depth of recursive template "
549 "instantiation"));
550
551static llvm::cl::opt<bool>
552Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences"));
553
554static llvm::cl::opt<bool>
555WritableStrings("fwritable-strings",
556 llvm::cl::desc("Store string literals as writable data"));
557
558}
559
560//===----------------------------------------------------------------------===//
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000561// General Preprocessor Options
562//===----------------------------------------------------------------------===//
563
564namespace preprocessoroptions {
565
566static llvm::cl::list<std::string>
567D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
568 llvm::cl::desc("Predefine the specified macro"));
569
570static llvm::cl::list<std::string>
571ImplicitIncludes("include", llvm::cl::value_desc("file"),
572 llvm::cl::desc("Include file before parsing"));
573static llvm::cl::list<std::string>
574ImplicitMacroIncludes("imacros", llvm::cl::value_desc("file"),
575 llvm::cl::desc("Include macros from file before parsing"));
576
577static llvm::cl::opt<std::string>
578ImplicitIncludePCH("include-pch", llvm::cl::value_desc("file"),
579 llvm::cl::desc("Include precompiled header file"));
580
581static llvm::cl::opt<std::string>
582ImplicitIncludePTH("include-pth", llvm::cl::value_desc("file"),
583 llvm::cl::desc("Include file before parsing"));
584
Daniel Dunbarb3cb98e2009-11-12 02:53:59 +0000585static llvm::cl::opt<std::string>
586TokenCache("token-cache", llvm::cl::value_desc("path"),
587 llvm::cl::desc("Use specified token cache file"));
588
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000589static llvm::cl::list<std::string>
590U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
591 llvm::cl::desc("Undefine the specified macro"));
592
593static llvm::cl::opt<bool>
594UndefMacros("undef", llvm::cl::value_desc("macro"),
595 llvm::cl::desc("undef all system defines"));
596
597}
598
599//===----------------------------------------------------------------------===//
Daniel Dunbarf7973292009-11-11 08:13:32 +0000600// Header Search Options
601//===----------------------------------------------------------------------===//
602
603namespace headersearchoptions {
604
605static llvm::cl::opt<bool>
606nostdinc("nostdinc", llvm::cl::desc("Disable standard #include directories"));
607
608static llvm::cl::opt<bool>
609nobuiltininc("nobuiltininc",
610 llvm::cl::desc("Disable builtin #include directories"));
611
612// Various command line options. These four add directories to each chain.
613static llvm::cl::list<std::string>
614F_dirs("F", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
615 llvm::cl::desc("Add directory to framework include search path"));
616
617static llvm::cl::list<std::string>
618I_dirs("I", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
619 llvm::cl::desc("Add directory to include search path"));
620
621static llvm::cl::list<std::string>
622idirafter_dirs("idirafter", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
623 llvm::cl::desc("Add directory to AFTER include search path"));
624
625static llvm::cl::list<std::string>
626iquote_dirs("iquote", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
627 llvm::cl::desc("Add directory to QUOTE include search path"));
628
629static llvm::cl::list<std::string>
630isystem_dirs("isystem", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
631 llvm::cl::desc("Add directory to SYSTEM include search path"));
632
633// These handle -iprefix/-iwithprefix/-iwithprefixbefore.
634static llvm::cl::list<std::string>
635iprefix_vals("iprefix", llvm::cl::value_desc("prefix"), llvm::cl::Prefix,
636 llvm::cl::desc("Set the -iwithprefix/-iwithprefixbefore prefix"));
637static llvm::cl::list<std::string>
638iwithprefix_vals("iwithprefix", llvm::cl::value_desc("dir"), llvm::cl::Prefix,
639 llvm::cl::desc("Set directory to SYSTEM include search path with prefix"));
640static llvm::cl::list<std::string>
641iwithprefixbefore_vals("iwithprefixbefore", llvm::cl::value_desc("dir"),
642 llvm::cl::Prefix,
643 llvm::cl::desc("Set directory to include search path with prefix"));
644
645static llvm::cl::opt<std::string>
646isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::init("/"),
647 llvm::cl::desc("Set the system root directory (usually /)"));
648
Daniel Dunbar1417c742009-11-12 23:52:46 +0000649static llvm::cl::opt<bool>
650Verbose("v", llvm::cl::desc("Enable verbose output"));
651
Daniel Dunbarf7973292009-11-11 08:13:32 +0000652}
653
654//===----------------------------------------------------------------------===//
Daniel Dunbar29cf7462009-11-11 10:07:44 +0000655// Preprocessed Output Options
656//===----------------------------------------------------------------------===//
657
658namespace preprocessoroutputoptions {
659
660static llvm::cl::opt<bool>
661DisableLineMarkers("P", llvm::cl::desc("Disable linemarker output in -E mode"));
662
663static llvm::cl::opt<bool>
664EnableCommentOutput("C", llvm::cl::desc("Enable comment output in -E mode"));
665
666static llvm::cl::opt<bool>
667EnableMacroCommentOutput("CC",
668 llvm::cl::desc("Enable comment output in -E mode, "
669 "even from macro expansions"));
670static llvm::cl::opt<bool>
671DumpMacros("dM", llvm::cl::desc("Print macro definitions in -E mode instead of"
672 " normal output"));
673static llvm::cl::opt<bool>
674DumpDefines("dD", llvm::cl::desc("Print macro definitions in -E mode in "
675 "addition to normal output"));
676
677}
678
679//===----------------------------------------------------------------------===//
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000680// Option Object Construction
681//===----------------------------------------------------------------------===//
682
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000683void clang::InitializeCodeGenOptions(CodeGenOptions &Opts,
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000684 const TargetInfo &Target) {
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000685 using namespace codegenoptions;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000686
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000687 // Compute the target features, we need the target to handle this because
688 // features may have dependencies on one another.
689 llvm::StringMap<bool> Features;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000690 Target.getDefaultFeatures(TargetCPU, Features);
691
692 // Apply the user specified deltas.
693 for (llvm::cl::list<std::string>::iterator it = TargetFeatures.begin(),
694 ie = TargetFeatures.end(); it != ie; ++it) {
695 const char *Name = it->c_str();
696
697 // FIXME: Don't handle errors like this.
698 if (Name[0] != '-' && Name[0] != '+') {
699 fprintf(stderr, "error: clang-cc: invalid target feature string: %s\n",
700 Name);
701 exit(1);
702 }
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000703
704 // Apply the feature via the target.
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000705 if (!Target.setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) {
706 fprintf(stderr, "error: clang-cc: invalid target feature name: %s\n",
707 Name + 1);
708 exit(1);
709 }
710 }
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000711
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000712 // Add the features to the compile options.
713 //
714 // FIXME: If we are completely confident that we have the right set, we only
715 // need to pass the minuses.
716 for (llvm::StringMap<bool>::const_iterator it = Features.begin(),
717 ie = Features.end(); it != ie; ++it)
718 Opts.Features.push_back(std::string(it->second ? "+" : "-") + it->first());
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000719
720 // -Os implies -O2
721 Opts.OptimizationLevel = OptSize ? 2 : OptLevel;
722
723 // We must always run at least the always inlining pass.
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000724 Opts.Inlining = (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining
725 : CodeGenOptions::OnlyAlwaysInlining;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000726
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000727 Opts.CPU = TargetCPU;
728 Opts.DebugInfo = GenerateDebugInfo;
729 Opts.DisableLLVMOpts = DisableLLVMOptimizations;
730 Opts.DisableRedZone = DisableRedZone;
731 Opts.MergeAllConstants = !NoMergeConstants;
732 Opts.NoCommon = NoCommon;
733 Opts.NoImplicitFloat = NoImplicitFloat;
734 Opts.OptimizeSize = OptSize;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000735 Opts.SimplifyLibCalls = 1;
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000736 Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize);
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000737
738#ifdef NDEBUG
739 Opts.VerifyModule = 0;
740#endif
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000741}
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000742
Daniel Dunbar0e0bae82009-11-11 21:43:12 +0000743void clang::InitializeDependencyOutputOptions(DependencyOutputOptions &Opts) {
744 using namespace dependencyoutputoptions;
745
746 Opts.OutputFile = DependencyFile;
Daniel Dunbar26266882009-11-12 23:52:32 +0000747 Opts.Targets = DependencyTargets;
Daniel Dunbar0e0bae82009-11-11 21:43:12 +0000748 Opts.IncludeSystemHeaders = DependenciesIncludeSystemHeaders;
749 Opts.UsePhonyTargets = PhonyDependencyTarget;
750}
751
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000752void clang::InitializeDiagnosticOptions(DiagnosticOptions &Opts) {
753 using namespace diagnosticoptions;
754
Daniel Dunbar26266882009-11-12 23:52:32 +0000755 Opts.Warnings = OptWarnings;
Daniel Dunbar11e729d2009-11-12 07:28:21 +0000756 Opts.DumpBuildInformation = DumpBuildInformation;
Daniel Dunbar69079432009-11-12 07:28:44 +0000757 Opts.IgnoreWarnings = OptNoWarnings;
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000758 Opts.MessageLength = MessageLength;
Daniel Dunbar69079432009-11-12 07:28:44 +0000759 Opts.NoRewriteMacros = SilenceRewriteMacroWarning;
760 Opts.Pedantic = OptPedantic;
761 Opts.PedanticErrors = OptPedanticErrors;
Daniel Dunbar11e729d2009-11-12 07:28:21 +0000762 Opts.ShowCarets = !NoCaretDiagnostics;
763 Opts.ShowColors = PrintColorDiagnostic;
764 Opts.ShowColumn = !NoShowColumn;
765 Opts.ShowFixits = !NoDiagnosticsFixIt;
766 Opts.ShowLocation = !NoShowLocation;
767 Opts.ShowOptionNames = PrintDiagnosticOption;
768 Opts.ShowSourceRanges = PrintSourceRangeInfo;
Daniel Dunbar26266882009-11-12 23:52:32 +0000769 Opts.VerifyDiagnostics = VerifyDiagnostics;
770}
771
772void clang::InitializeFrontendOptions(FrontendOptions &Opts) {
773 using namespace frontendoptions;
774
Daniel Dunbar914474c2009-11-13 01:02:10 +0000775 Opts.CodeCompletionAt = CodeCompletionAt;
776 Opts.DebugCodeCompletionPrinter = CodeCompletionDebugPrinter;
Daniel Dunbar26266882009-11-12 23:52:32 +0000777 Opts.DisableFree = DisableFree;
778 Opts.EmptyInputOnly = EmptyInputOnly;
779 Opts.FixItAll = FixItAll;
Daniel Dunbarc86804b2009-11-12 23:52:56 +0000780 Opts.FixItLocations = FixItAtLocations;
Daniel Dunbar26266882009-11-12 23:52:32 +0000781 Opts.InputFilenames = InputFilenames;
782 Opts.OutputFile = OutputFile;
Daniel Dunbar914474c2009-11-13 01:02:10 +0000783 Opts.RelocatablePCH = RelocatablePCH;
784 Opts.ShowMacrosInCodeCompletion = CodeCompletionWantsMacros;
785 Opts.ShowStats = Stats;
786 Opts.ShowTimers = TimeReport;
Daniel Dunbar26266882009-11-12 23:52:32 +0000787 Opts.ViewClassInheritance = InheritanceViewCls;
788
789 // '-' is the default input if none is given.
790 if (Opts.InputFilenames.empty())
791 Opts.InputFilenames.push_back("-");
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000792}
793
Daniel Dunbarf7973292009-11-11 08:13:32 +0000794void clang::InitializeHeaderSearchOptions(HeaderSearchOptions &Opts,
795 llvm::StringRef BuiltinIncludePath,
Daniel Dunbarf7973292009-11-11 08:13:32 +0000796 const LangOptions &Lang) {
797 using namespace headersearchoptions;
798
799 Opts.Sysroot = isysroot;
800 Opts.Verbose = Verbose;
801
802 // Handle -I... and -F... options, walking the lists in parallel.
803 unsigned Iidx = 0, Fidx = 0;
804 while (Iidx < I_dirs.size() && Fidx < F_dirs.size()) {
805 if (I_dirs.getPosition(Iidx) < F_dirs.getPosition(Fidx)) {
806 Opts.AddPath(I_dirs[Iidx], frontend::Angled, false, true, false);
807 ++Iidx;
808 } else {
809 Opts.AddPath(F_dirs[Fidx], frontend::Angled, false, true, true);
810 ++Fidx;
811 }
812 }
813
814 // Consume what's left from whatever list was longer.
815 for (; Iidx != I_dirs.size(); ++Iidx)
816 Opts.AddPath(I_dirs[Iidx], frontend::Angled, false, true, false);
817 for (; Fidx != F_dirs.size(); ++Fidx)
818 Opts.AddPath(F_dirs[Fidx], frontend::Angled, false, true, true);
819
820 // Handle -idirafter... options.
821 for (unsigned i = 0, e = idirafter_dirs.size(); i != e; ++i)
822 Opts.AddPath(idirafter_dirs[i], frontend::After,
823 false, true, false);
824
825 // Handle -iquote... options.
826 for (unsigned i = 0, e = iquote_dirs.size(); i != e; ++i)
827 Opts.AddPath(iquote_dirs[i], frontend::Quoted, false, true, false);
828
829 // Handle -isystem... options.
830 for (unsigned i = 0, e = isystem_dirs.size(); i != e; ++i)
831 Opts.AddPath(isystem_dirs[i], frontend::System, false, true, false);
832
833 // Walk the -iprefix/-iwithprefix/-iwithprefixbefore argument lists in
834 // parallel, processing the values in order of occurance to get the right
835 // prefixes.
836 {
837 std::string Prefix = ""; // FIXME: this isn't the correct default prefix.
838 unsigned iprefix_idx = 0;
839 unsigned iwithprefix_idx = 0;
840 unsigned iwithprefixbefore_idx = 0;
841 bool iprefix_done = iprefix_vals.empty();
842 bool iwithprefix_done = iwithprefix_vals.empty();
843 bool iwithprefixbefore_done = iwithprefixbefore_vals.empty();
844 while (!iprefix_done || !iwithprefix_done || !iwithprefixbefore_done) {
845 if (!iprefix_done &&
846 (iwithprefix_done ||
847 iprefix_vals.getPosition(iprefix_idx) <
848 iwithprefix_vals.getPosition(iwithprefix_idx)) &&
849 (iwithprefixbefore_done ||
850 iprefix_vals.getPosition(iprefix_idx) <
851 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
852 Prefix = iprefix_vals[iprefix_idx];
853 ++iprefix_idx;
854 iprefix_done = iprefix_idx == iprefix_vals.size();
855 } else if (!iwithprefix_done &&
856 (iwithprefixbefore_done ||
857 iwithprefix_vals.getPosition(iwithprefix_idx) <
858 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
859 Opts.AddPath(Prefix+iwithprefix_vals[iwithprefix_idx],
860 frontend::System, false, false, false);
861 ++iwithprefix_idx;
862 iwithprefix_done = iwithprefix_idx == iwithprefix_vals.size();
863 } else {
864 Opts.AddPath(Prefix+iwithprefixbefore_vals[iwithprefixbefore_idx],
865 frontend::Angled, false, false, false);
866 ++iwithprefixbefore_idx;
867 iwithprefixbefore_done =
868 iwithprefixbefore_idx == iwithprefixbefore_vals.size();
869 }
870 }
871 }
872
873 // Add CPATH environment paths.
874 if (const char *Env = getenv("CPATH"))
875 Opts.EnvIncPath = Env;
876
877 // Add language specific environment paths.
878 if (Lang.CPlusPlus && Lang.ObjC1) {
879 if (const char *Env = getenv("OBJCPLUS_INCLUDE_PATH"))
880 Opts.LangEnvIncPath = Env;
881 } else if (Lang.CPlusPlus) {
882 if (const char *Env = getenv("CPLUS_INCLUDE_PATH"))
883 Opts.LangEnvIncPath = Env;
884 } else if (Lang.ObjC1) {
885 if (const char *Env = getenv("OBJC_INCLUDE_PATH"))
886 Opts.LangEnvIncPath = Env;
887 } else {
888 if (const char *Env = getenv("C_INCLUDE_PATH"))
889 Opts.LangEnvIncPath = Env;
890 }
891
892 if (!nobuiltininc)
893 Opts.BuiltinIncludePath = BuiltinIncludePath;
894
895 Opts.UseStandardIncludes = !nostdinc;
896}
897
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000898void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) {
899 using namespace preprocessoroptions;
900
901 Opts.setImplicitPCHInclude(ImplicitIncludePCH);
902 Opts.setImplicitPTHInclude(ImplicitIncludePTH);
903
Daniel Dunbarb3cb98e2009-11-12 02:53:59 +0000904 // Select the token cache file, we don't support more than one currently so we
905 // can't have both an implicit-pth and a token cache file.
906 if (TokenCache.getPosition() && ImplicitIncludePTH.getPosition()) {
907 // FIXME: Don't fail like this.
908 fprintf(stderr, "error: cannot use both -token-cache and -include-pth "
909 "options\n");
910 exit(1);
911 }
912 if (TokenCache.getPosition())
913 Opts.setTokenCache(TokenCache);
914 else
915 Opts.setTokenCache(ImplicitIncludePTH);
916
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000917 // Use predefines?
918 Opts.setUsePredefines(!UndefMacros);
919
920 // Add macros from the command line.
921 unsigned d = 0, D = D_macros.size();
922 unsigned u = 0, U = U_macros.size();
923 while (d < D || u < U) {
924 if (u == U || (d < D && D_macros.getPosition(d) < U_macros.getPosition(u)))
925 Opts.addMacroDef(D_macros[d++]);
926 else
927 Opts.addMacroUndef(U_macros[u++]);
928 }
929
930 // If -imacros are specified, include them now. These are processed before
931 // any -include directives.
932 for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i)
933 Opts.addMacroInclude(ImplicitMacroIncludes[i]);
934
935 // Add the ordered list of -includes, sorting in the implicit include options
936 // at the appropriate location.
937 llvm::SmallVector<std::pair<unsigned, std::string*>, 8> OrderedPaths;
938 std::string OriginalFile;
939
940 if (!ImplicitIncludePTH.empty())
941 OrderedPaths.push_back(std::make_pair(ImplicitIncludePTH.getPosition(),
942 &ImplicitIncludePTH));
943 if (!ImplicitIncludePCH.empty()) {
944 OriginalFile = PCHReader::getOriginalSourceFile(ImplicitIncludePCH);
945 // FIXME: Don't fail like this.
946 if (OriginalFile.empty())
947 exit(1);
948 OrderedPaths.push_back(std::make_pair(ImplicitIncludePCH.getPosition(),
949 &OriginalFile));
950 }
951 for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i)
952 OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i),
953 &ImplicitIncludes[i]));
954 llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end());
955
956 for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i)
957 Opts.addInclude(*OrderedPaths[i].second);
958}
Daniel Dunbar56749082009-11-11 07:26:12 +0000959
960void clang::InitializeLangOptions(LangOptions &Options, LangKind LK,
961 TargetInfo &Target,
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000962 const CodeGenOptions &CodeGenOpts) {
Daniel Dunbar56749082009-11-11 07:26:12 +0000963 using namespace langoptions;
964
965 bool NoPreprocess = false;
966
967 switch (LK) {
968 default: assert(0 && "Unknown language kind!");
969 case langkind_asm_cpp:
970 Options.AsmPreprocessor = 1;
971 // FALLTHROUGH
972 case langkind_c_cpp:
973 NoPreprocess = true;
974 // FALLTHROUGH
975 case langkind_c:
976 // Do nothing.
977 break;
978 case langkind_cxx_cpp:
979 NoPreprocess = true;
980 // FALLTHROUGH
981 case langkind_cxx:
982 Options.CPlusPlus = 1;
983 break;
984 case langkind_objc_cpp:
985 NoPreprocess = true;
986 // FALLTHROUGH
987 case langkind_objc:
988 Options.ObjC1 = Options.ObjC2 = 1;
989 break;
990 case langkind_objcxx_cpp:
991 NoPreprocess = true;
992 // FALLTHROUGH
993 case langkind_objcxx:
994 Options.ObjC1 = Options.ObjC2 = 1;
995 Options.CPlusPlus = 1;
996 break;
997 case langkind_ocl:
998 Options.OpenCL = 1;
999 Options.AltiVec = 1;
1000 Options.CXXOperatorNames = 1;
1001 Options.LaxVectorConversions = 1;
1002 break;
1003 }
1004
1005 if (ObjCExclusiveGC)
1006 Options.setGCMode(LangOptions::GCOnly);
1007 else if (ObjCEnableGC)
1008 Options.setGCMode(LangOptions::HybridGC);
1009
1010 if (ObjCEnableGCBitmapPrint)
1011 Options.ObjCGCBitmapPrint = 1;
1012
1013 if (AltiVec)
1014 Options.AltiVec = 1;
1015
1016 if (PThread)
1017 Options.POSIXThreads = 1;
1018
1019 Options.setVisibilityMode(SymbolVisibility);
1020 Options.OverflowChecking = OverflowChecking;
1021
1022
1023 // Allow the target to set the default the language options as it sees fit.
1024 Target.getDefaultLangOptions(Options);
1025
1026 // Pass the map of target features to the target for validation and
1027 // processing.
Chandler Carruth2811ccf2009-11-12 17:24:48 +00001028 Target.HandleTargetFeatures(CodeGenOpts.Features);
Daniel Dunbar56749082009-11-11 07:26:12 +00001029
1030 if (LangStd == lang_unspecified) {
1031 // Based on the base language, pick one.
1032 switch (LK) {
1033 case langkind_ast: assert(0 && "Invalid call for AST inputs");
1034 case lang_unspecified: assert(0 && "Unknown base language");
1035 case langkind_ocl:
1036 LangStd = lang_c99;
1037 break;
1038 case langkind_c:
1039 case langkind_asm_cpp:
1040 case langkind_c_cpp:
1041 case langkind_objc:
1042 case langkind_objc_cpp:
1043 LangStd = lang_gnu99;
1044 break;
1045 case langkind_cxx:
1046 case langkind_cxx_cpp:
1047 case langkind_objcxx:
1048 case langkind_objcxx_cpp:
1049 LangStd = lang_gnucxx98;
1050 break;
1051 }
1052 }
1053
1054 switch (LangStd) {
1055 default: assert(0 && "Unknown language standard!");
1056
1057 // Fall through from newer standards to older ones. This isn't really right.
1058 // FIXME: Enable specifically the right features based on the language stds.
1059 case lang_gnucxx0x:
1060 case lang_cxx0x:
1061 Options.CPlusPlus0x = 1;
1062 // FALL THROUGH
1063 case lang_gnucxx98:
1064 case lang_cxx98:
1065 Options.CPlusPlus = 1;
1066 Options.CXXOperatorNames = !NoOperatorNames;
1067 // FALL THROUGH.
1068 case lang_gnu99:
1069 case lang_c99:
1070 Options.C99 = 1;
1071 Options.HexFloats = 1;
1072 // FALL THROUGH.
1073 case lang_gnu89:
1074 Options.BCPLComment = 1; // Only for C99/C++.
1075 // FALL THROUGH.
1076 case lang_c94:
1077 Options.Digraphs = 1; // C94, C99, C++.
1078 // FALL THROUGH.
1079 case lang_c89:
1080 break;
1081 }
1082
1083 // GNUMode - Set if we're in gnu99, gnu89, gnucxx98, etc.
1084 switch (LangStd) {
1085 default: assert(0 && "Unknown language standard!");
1086 case lang_gnucxx0x:
1087 case lang_gnucxx98:
1088 case lang_gnu99:
1089 case lang_gnu89:
1090 Options.GNUMode = 1;
1091 break;
1092 case lang_cxx0x:
1093 case lang_cxx98:
1094 case lang_c99:
1095 case lang_c94:
1096 case lang_c89:
1097 Options.GNUMode = 0;
1098 break;
1099 }
1100
1101 if (Options.CPlusPlus) {
1102 Options.C99 = 0;
1103 Options.HexFloats = 0;
1104 }
1105
1106 if (LangStd == lang_c89 || LangStd == lang_c94 || LangStd == lang_gnu89)
1107 Options.ImplicitInt = 1;
1108 else
1109 Options.ImplicitInt = 0;
1110
1111 // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
1112 // is specified, or -std is set to a conforming mode.
1113 Options.Trigraphs = !Options.GNUMode;
1114 if (Trigraphs.getPosition())
1115 Options.Trigraphs = Trigraphs; // Command line option wins if specified.
1116
1117 // If in a conformant language mode (e.g. -std=c99) Blocks defaults to off
1118 // even if they are normally on for the target. In GNU modes (e.g.
1119 // -std=gnu99) the default for blocks depends on the target settings.
1120 // However, blocks are not turned off when compiling Obj-C or Obj-C++ code.
1121 if (!Options.ObjC1 && !Options.GNUMode)
1122 Options.Blocks = 0;
1123
1124 // Default to not accepting '$' in identifiers when preprocessing assembler,
1125 // but do accept when preprocessing C. FIXME: these defaults are right for
1126 // darwin, are they right everywhere?
1127 Options.DollarIdents = LK != langkind_asm_cpp;
1128 if (DollarsInIdents.getPosition()) // Explicit setting overrides default.
1129 Options.DollarIdents = DollarsInIdents;
1130
1131 if (PascalStrings.getPosition())
1132 Options.PascalStrings = PascalStrings;
1133 if (MSExtensions.getPosition())
1134 Options.Microsoft = MSExtensions;
1135 Options.WritableStrings = WritableStrings;
1136 if (NoLaxVectorConversions.getPosition())
1137 Options.LaxVectorConversions = 0;
1138 Options.Exceptions = Exceptions;
1139 Options.Rtti = Rtti;
1140 if (EnableBlocks.getPosition())
1141 Options.Blocks = EnableBlocks;
1142 if (CharIsSigned.getPosition())
1143 Options.CharIsSigned = CharIsSigned;
1144 if (ShortWChar.getPosition())
1145 Options.ShortWChar = ShortWChar;
1146
1147 if (!AllowBuiltins)
1148 Options.NoBuiltin = 1;
1149 if (Freestanding)
1150 Options.Freestanding = Options.NoBuiltin = 1;
1151
1152 if (EnableHeinousExtensions)
1153 Options.HeinousExtensions = 1;
1154
1155 if (AccessControl)
1156 Options.AccessControl = 1;
1157
1158 Options.ElideConstructors = !NoElideConstructors;
1159
1160 // OpenCL and C++ both have bool, true, false keywords.
1161 Options.Bool = Options.OpenCL | Options.CPlusPlus;
1162
1163 Options.MathErrno = MathErrno;
1164
1165 Options.InstantiationDepth = TemplateDepth;
1166
1167 // Override the default runtime if the user requested it.
1168 if (NeXTRuntime)
1169 Options.NeXTRuntime = 1;
1170 else if (GNURuntime)
1171 Options.NeXTRuntime = 0;
1172
1173 if (!ObjCConstantStringClass.empty())
1174 Options.ObjCConstantStringClass = ObjCConstantStringClass.c_str();
1175
1176 if (ObjCNonFragileABI)
1177 Options.ObjCNonFragileABI = 1;
1178
1179 if (EmitAllDecls)
1180 Options.EmitAllDecls = 1;
1181
1182 // The __OPTIMIZE_SIZE__ define is tied to -Oz, which we don't support.
1183 Options.OptimizeSize = 0;
Chandler Carruth2811ccf2009-11-12 17:24:48 +00001184 Options.Optimize = !!CodeGenOpts.OptimizationLevel;
Daniel Dunbar56749082009-11-11 07:26:12 +00001185
1186 assert(PICLevel <= 2 && "Invalid value for -pic-level");
1187 Options.PICLevel = PICLevel;
1188
1189 Options.GNUInline = !Options.C99;
1190 // FIXME: This is affected by other options (-fno-inline).
1191
1192 // This is the __NO_INLINE__ define, which just depends on things like the
1193 // optimization level and -fno-inline, not actually whether the backend has
1194 // inlining enabled.
Chandler Carruth2811ccf2009-11-12 17:24:48 +00001195 Options.NoInline = !CodeGenOpts.OptimizationLevel;
Daniel Dunbar56749082009-11-11 07:26:12 +00001196
1197 Options.Static = StaticDefine;
1198
1199 switch (StackProtector) {
1200 default:
1201 assert(StackProtector <= 2 && "Invalid value for -stack-protector");
1202 case -1: break;
1203 case 0: Options.setStackProtectorMode(LangOptions::SSPOff); break;
1204 case 1: Options.setStackProtectorMode(LangOptions::SSPOn); break;
1205 case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break;
1206 }
1207
1208 if (MainFileName.getPosition())
1209 Options.setMainFileName(MainFileName.c_str());
1210
1211 Target.setForcedLangOptions(Options);
1212}
Daniel Dunbar29cf7462009-11-11 10:07:44 +00001213
1214void
1215clang::InitializePreprocessorOutputOptions(PreprocessorOutputOptions &Opts) {
1216 using namespace preprocessoroutputoptions;
1217
1218 Opts.ShowCPP = !DumpMacros;
1219 Opts.ShowMacros = DumpMacros || DumpDefines;
1220 Opts.ShowLineMarkers = !DisableLineMarkers;
1221 Opts.ShowComments = EnableCommentOutput;
1222 Opts.ShowMacroComments = EnableMacroCommentOutput;
1223}