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