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