blob: 1251dcc4dbc354abee9ebe4bfa7c368a7d685e59 [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
631}
632
633//===----------------------------------------------------------------------===//
Daniel Dunbar29cf7462009-11-11 10:07:44 +0000634// Preprocessed Output Options
635//===----------------------------------------------------------------------===//
636
637namespace preprocessoroutputoptions {
638
639static llvm::cl::opt<bool>
640DisableLineMarkers("P", llvm::cl::desc("Disable linemarker output in -E mode"));
641
642static llvm::cl::opt<bool>
643EnableCommentOutput("C", llvm::cl::desc("Enable comment output in -E mode"));
644
645static llvm::cl::opt<bool>
646EnableMacroCommentOutput("CC",
647 llvm::cl::desc("Enable comment output in -E mode, "
648 "even from macro expansions"));
649static llvm::cl::opt<bool>
650DumpMacros("dM", llvm::cl::desc("Print macro definitions in -E mode instead of"
651 " normal output"));
652static llvm::cl::opt<bool>
653DumpDefines("dD", llvm::cl::desc("Print macro definitions in -E mode in "
654 "addition to normal output"));
655
656}
657
658//===----------------------------------------------------------------------===//
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000659// Option Object Construction
660//===----------------------------------------------------------------------===//
661
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000662void clang::InitializeCodeGenOptions(CodeGenOptions &Opts,
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000663 const TargetInfo &Target) {
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000664 using namespace codegenoptions;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000665
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000666 // Compute the target features, we need the target to handle this because
667 // features may have dependencies on one another.
668 llvm::StringMap<bool> Features;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000669 Target.getDefaultFeatures(TargetCPU, Features);
670
671 // Apply the user specified deltas.
672 for (llvm::cl::list<std::string>::iterator it = TargetFeatures.begin(),
673 ie = TargetFeatures.end(); it != ie; ++it) {
674 const char *Name = it->c_str();
675
676 // FIXME: Don't handle errors like this.
677 if (Name[0] != '-' && Name[0] != '+') {
678 fprintf(stderr, "error: clang-cc: invalid target feature string: %s\n",
679 Name);
680 exit(1);
681 }
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000682
683 // Apply the feature via the target.
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000684 if (!Target.setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) {
685 fprintf(stderr, "error: clang-cc: invalid target feature name: %s\n",
686 Name + 1);
687 exit(1);
688 }
689 }
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000690
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000691 // Add the features to the compile options.
692 //
693 // FIXME: If we are completely confident that we have the right set, we only
694 // need to pass the minuses.
695 for (llvm::StringMap<bool>::const_iterator it = Features.begin(),
696 ie = Features.end(); it != ie; ++it)
697 Opts.Features.push_back(std::string(it->second ? "+" : "-") + it->first());
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000698
699 // -Os implies -O2
700 Opts.OptimizationLevel = OptSize ? 2 : OptLevel;
701
702 // We must always run at least the always inlining pass.
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000703 Opts.Inlining = (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining
704 : CodeGenOptions::OnlyAlwaysInlining;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000705
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000706 Opts.CPU = TargetCPU;
707 Opts.DebugInfo = GenerateDebugInfo;
708 Opts.DisableLLVMOpts = DisableLLVMOptimizations;
709 Opts.DisableRedZone = DisableRedZone;
710 Opts.MergeAllConstants = !NoMergeConstants;
711 Opts.NoCommon = NoCommon;
712 Opts.NoImplicitFloat = NoImplicitFloat;
713 Opts.OptimizeSize = OptSize;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000714 Opts.SimplifyLibCalls = 1;
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000715 Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize);
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000716
717#ifdef NDEBUG
718 Opts.VerifyModule = 0;
719#endif
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000720}
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000721
Daniel Dunbar0e0bae82009-11-11 21:43:12 +0000722void clang::InitializeDependencyOutputOptions(DependencyOutputOptions &Opts) {
723 using namespace dependencyoutputoptions;
724
725 Opts.OutputFile = DependencyFile;
Daniel Dunbar26266882009-11-12 23:52:32 +0000726 Opts.Targets = DependencyTargets;
Daniel Dunbar0e0bae82009-11-11 21:43:12 +0000727 Opts.IncludeSystemHeaders = DependenciesIncludeSystemHeaders;
728 Opts.UsePhonyTargets = PhonyDependencyTarget;
729}
730
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000731void clang::InitializeDiagnosticOptions(DiagnosticOptions &Opts) {
732 using namespace diagnosticoptions;
733
Daniel Dunbar26266882009-11-12 23:52:32 +0000734 Opts.Warnings = OptWarnings;
Daniel Dunbar11e729d2009-11-12 07:28:21 +0000735 Opts.DumpBuildInformation = DumpBuildInformation;
Daniel Dunbar69079432009-11-12 07:28:44 +0000736 Opts.IgnoreWarnings = OptNoWarnings;
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000737 Opts.MessageLength = MessageLength;
Daniel Dunbar69079432009-11-12 07:28:44 +0000738 Opts.NoRewriteMacros = SilenceRewriteMacroWarning;
739 Opts.Pedantic = OptPedantic;
740 Opts.PedanticErrors = OptPedanticErrors;
Daniel Dunbar11e729d2009-11-12 07:28:21 +0000741 Opts.ShowCarets = !NoCaretDiagnostics;
742 Opts.ShowColors = PrintColorDiagnostic;
743 Opts.ShowColumn = !NoShowColumn;
744 Opts.ShowFixits = !NoDiagnosticsFixIt;
745 Opts.ShowLocation = !NoShowLocation;
746 Opts.ShowOptionNames = PrintDiagnosticOption;
747 Opts.ShowSourceRanges = PrintSourceRangeInfo;
Daniel Dunbar26266882009-11-12 23:52:32 +0000748 Opts.VerifyDiagnostics = VerifyDiagnostics;
749}
750
751void clang::InitializeFrontendOptions(FrontendOptions &Opts) {
752 using namespace frontendoptions;
753
754 Opts.DisableFree = DisableFree;
755 Opts.EmptyInputOnly = EmptyInputOnly;
756 Opts.FixItAll = FixItAll;
757 Opts.RelocatablePCH = RelocatablePCH;
758 Opts.ShowStats = Stats;
759 Opts.ShowTimers = TimeReport;
760 Opts.InputFilenames = InputFilenames;
761 Opts.OutputFile = OutputFile;
762 Opts.ViewClassInheritance = InheritanceViewCls;
763
764 // '-' is the default input if none is given.
765 if (Opts.InputFilenames.empty())
766 Opts.InputFilenames.push_back("-");
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000767}
768
Daniel Dunbarf7973292009-11-11 08:13:32 +0000769void clang::InitializeHeaderSearchOptions(HeaderSearchOptions &Opts,
770 llvm::StringRef BuiltinIncludePath,
771 bool Verbose,
772 const LangOptions &Lang) {
773 using namespace headersearchoptions;
774
775 Opts.Sysroot = isysroot;
776 Opts.Verbose = Verbose;
777
778 // Handle -I... and -F... options, walking the lists in parallel.
779 unsigned Iidx = 0, Fidx = 0;
780 while (Iidx < I_dirs.size() && Fidx < F_dirs.size()) {
781 if (I_dirs.getPosition(Iidx) < F_dirs.getPosition(Fidx)) {
782 Opts.AddPath(I_dirs[Iidx], frontend::Angled, false, true, false);
783 ++Iidx;
784 } else {
785 Opts.AddPath(F_dirs[Fidx], frontend::Angled, false, true, true);
786 ++Fidx;
787 }
788 }
789
790 // Consume what's left from whatever list was longer.
791 for (; Iidx != I_dirs.size(); ++Iidx)
792 Opts.AddPath(I_dirs[Iidx], frontend::Angled, false, true, false);
793 for (; Fidx != F_dirs.size(); ++Fidx)
794 Opts.AddPath(F_dirs[Fidx], frontend::Angled, false, true, true);
795
796 // Handle -idirafter... options.
797 for (unsigned i = 0, e = idirafter_dirs.size(); i != e; ++i)
798 Opts.AddPath(idirafter_dirs[i], frontend::After,
799 false, true, false);
800
801 // Handle -iquote... options.
802 for (unsigned i = 0, e = iquote_dirs.size(); i != e; ++i)
803 Opts.AddPath(iquote_dirs[i], frontend::Quoted, false, true, false);
804
805 // Handle -isystem... options.
806 for (unsigned i = 0, e = isystem_dirs.size(); i != e; ++i)
807 Opts.AddPath(isystem_dirs[i], frontend::System, false, true, false);
808
809 // Walk the -iprefix/-iwithprefix/-iwithprefixbefore argument lists in
810 // parallel, processing the values in order of occurance to get the right
811 // prefixes.
812 {
813 std::string Prefix = ""; // FIXME: this isn't the correct default prefix.
814 unsigned iprefix_idx = 0;
815 unsigned iwithprefix_idx = 0;
816 unsigned iwithprefixbefore_idx = 0;
817 bool iprefix_done = iprefix_vals.empty();
818 bool iwithprefix_done = iwithprefix_vals.empty();
819 bool iwithprefixbefore_done = iwithprefixbefore_vals.empty();
820 while (!iprefix_done || !iwithprefix_done || !iwithprefixbefore_done) {
821 if (!iprefix_done &&
822 (iwithprefix_done ||
823 iprefix_vals.getPosition(iprefix_idx) <
824 iwithprefix_vals.getPosition(iwithprefix_idx)) &&
825 (iwithprefixbefore_done ||
826 iprefix_vals.getPosition(iprefix_idx) <
827 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
828 Prefix = iprefix_vals[iprefix_idx];
829 ++iprefix_idx;
830 iprefix_done = iprefix_idx == iprefix_vals.size();
831 } else if (!iwithprefix_done &&
832 (iwithprefixbefore_done ||
833 iwithprefix_vals.getPosition(iwithprefix_idx) <
834 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
835 Opts.AddPath(Prefix+iwithprefix_vals[iwithprefix_idx],
836 frontend::System, false, false, false);
837 ++iwithprefix_idx;
838 iwithprefix_done = iwithprefix_idx == iwithprefix_vals.size();
839 } else {
840 Opts.AddPath(Prefix+iwithprefixbefore_vals[iwithprefixbefore_idx],
841 frontend::Angled, false, false, false);
842 ++iwithprefixbefore_idx;
843 iwithprefixbefore_done =
844 iwithprefixbefore_idx == iwithprefixbefore_vals.size();
845 }
846 }
847 }
848
849 // Add CPATH environment paths.
850 if (const char *Env = getenv("CPATH"))
851 Opts.EnvIncPath = Env;
852
853 // Add language specific environment paths.
854 if (Lang.CPlusPlus && Lang.ObjC1) {
855 if (const char *Env = getenv("OBJCPLUS_INCLUDE_PATH"))
856 Opts.LangEnvIncPath = Env;
857 } else if (Lang.CPlusPlus) {
858 if (const char *Env = getenv("CPLUS_INCLUDE_PATH"))
859 Opts.LangEnvIncPath = Env;
860 } else if (Lang.ObjC1) {
861 if (const char *Env = getenv("OBJC_INCLUDE_PATH"))
862 Opts.LangEnvIncPath = Env;
863 } else {
864 if (const char *Env = getenv("C_INCLUDE_PATH"))
865 Opts.LangEnvIncPath = Env;
866 }
867
868 if (!nobuiltininc)
869 Opts.BuiltinIncludePath = BuiltinIncludePath;
870
871 Opts.UseStandardIncludes = !nostdinc;
872}
873
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000874void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) {
875 using namespace preprocessoroptions;
876
877 Opts.setImplicitPCHInclude(ImplicitIncludePCH);
878 Opts.setImplicitPTHInclude(ImplicitIncludePTH);
879
Daniel Dunbarb3cb98e2009-11-12 02:53:59 +0000880 // Select the token cache file, we don't support more than one currently so we
881 // can't have both an implicit-pth and a token cache file.
882 if (TokenCache.getPosition() && ImplicitIncludePTH.getPosition()) {
883 // FIXME: Don't fail like this.
884 fprintf(stderr, "error: cannot use both -token-cache and -include-pth "
885 "options\n");
886 exit(1);
887 }
888 if (TokenCache.getPosition())
889 Opts.setTokenCache(TokenCache);
890 else
891 Opts.setTokenCache(ImplicitIncludePTH);
892
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000893 // Use predefines?
894 Opts.setUsePredefines(!UndefMacros);
895
896 // Add macros from the command line.
897 unsigned d = 0, D = D_macros.size();
898 unsigned u = 0, U = U_macros.size();
899 while (d < D || u < U) {
900 if (u == U || (d < D && D_macros.getPosition(d) < U_macros.getPosition(u)))
901 Opts.addMacroDef(D_macros[d++]);
902 else
903 Opts.addMacroUndef(U_macros[u++]);
904 }
905
906 // If -imacros are specified, include them now. These are processed before
907 // any -include directives.
908 for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i)
909 Opts.addMacroInclude(ImplicitMacroIncludes[i]);
910
911 // Add the ordered list of -includes, sorting in the implicit include options
912 // at the appropriate location.
913 llvm::SmallVector<std::pair<unsigned, std::string*>, 8> OrderedPaths;
914 std::string OriginalFile;
915
916 if (!ImplicitIncludePTH.empty())
917 OrderedPaths.push_back(std::make_pair(ImplicitIncludePTH.getPosition(),
918 &ImplicitIncludePTH));
919 if (!ImplicitIncludePCH.empty()) {
920 OriginalFile = PCHReader::getOriginalSourceFile(ImplicitIncludePCH);
921 // FIXME: Don't fail like this.
922 if (OriginalFile.empty())
923 exit(1);
924 OrderedPaths.push_back(std::make_pair(ImplicitIncludePCH.getPosition(),
925 &OriginalFile));
926 }
927 for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i)
928 OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i),
929 &ImplicitIncludes[i]));
930 llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end());
931
932 for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i)
933 Opts.addInclude(*OrderedPaths[i].second);
934}
Daniel Dunbar56749082009-11-11 07:26:12 +0000935
936void clang::InitializeLangOptions(LangOptions &Options, LangKind LK,
937 TargetInfo &Target,
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000938 const CodeGenOptions &CodeGenOpts) {
Daniel Dunbar56749082009-11-11 07:26:12 +0000939 using namespace langoptions;
940
941 bool NoPreprocess = false;
942
943 switch (LK) {
944 default: assert(0 && "Unknown language kind!");
945 case langkind_asm_cpp:
946 Options.AsmPreprocessor = 1;
947 // FALLTHROUGH
948 case langkind_c_cpp:
949 NoPreprocess = true;
950 // FALLTHROUGH
951 case langkind_c:
952 // Do nothing.
953 break;
954 case langkind_cxx_cpp:
955 NoPreprocess = true;
956 // FALLTHROUGH
957 case langkind_cxx:
958 Options.CPlusPlus = 1;
959 break;
960 case langkind_objc_cpp:
961 NoPreprocess = true;
962 // FALLTHROUGH
963 case langkind_objc:
964 Options.ObjC1 = Options.ObjC2 = 1;
965 break;
966 case langkind_objcxx_cpp:
967 NoPreprocess = true;
968 // FALLTHROUGH
969 case langkind_objcxx:
970 Options.ObjC1 = Options.ObjC2 = 1;
971 Options.CPlusPlus = 1;
972 break;
973 case langkind_ocl:
974 Options.OpenCL = 1;
975 Options.AltiVec = 1;
976 Options.CXXOperatorNames = 1;
977 Options.LaxVectorConversions = 1;
978 break;
979 }
980
981 if (ObjCExclusiveGC)
982 Options.setGCMode(LangOptions::GCOnly);
983 else if (ObjCEnableGC)
984 Options.setGCMode(LangOptions::HybridGC);
985
986 if (ObjCEnableGCBitmapPrint)
987 Options.ObjCGCBitmapPrint = 1;
988
989 if (AltiVec)
990 Options.AltiVec = 1;
991
992 if (PThread)
993 Options.POSIXThreads = 1;
994
995 Options.setVisibilityMode(SymbolVisibility);
996 Options.OverflowChecking = OverflowChecking;
997
998
999 // Allow the target to set the default the language options as it sees fit.
1000 Target.getDefaultLangOptions(Options);
1001
1002 // Pass the map of target features to the target for validation and
1003 // processing.
Chandler Carruth2811ccf2009-11-12 17:24:48 +00001004 Target.HandleTargetFeatures(CodeGenOpts.Features);
Daniel Dunbar56749082009-11-11 07:26:12 +00001005
1006 if (LangStd == lang_unspecified) {
1007 // Based on the base language, pick one.
1008 switch (LK) {
1009 case langkind_ast: assert(0 && "Invalid call for AST inputs");
1010 case lang_unspecified: assert(0 && "Unknown base language");
1011 case langkind_ocl:
1012 LangStd = lang_c99;
1013 break;
1014 case langkind_c:
1015 case langkind_asm_cpp:
1016 case langkind_c_cpp:
1017 case langkind_objc:
1018 case langkind_objc_cpp:
1019 LangStd = lang_gnu99;
1020 break;
1021 case langkind_cxx:
1022 case langkind_cxx_cpp:
1023 case langkind_objcxx:
1024 case langkind_objcxx_cpp:
1025 LangStd = lang_gnucxx98;
1026 break;
1027 }
1028 }
1029
1030 switch (LangStd) {
1031 default: assert(0 && "Unknown language standard!");
1032
1033 // Fall through from newer standards to older ones. This isn't really right.
1034 // FIXME: Enable specifically the right features based on the language stds.
1035 case lang_gnucxx0x:
1036 case lang_cxx0x:
1037 Options.CPlusPlus0x = 1;
1038 // FALL THROUGH
1039 case lang_gnucxx98:
1040 case lang_cxx98:
1041 Options.CPlusPlus = 1;
1042 Options.CXXOperatorNames = !NoOperatorNames;
1043 // FALL THROUGH.
1044 case lang_gnu99:
1045 case lang_c99:
1046 Options.C99 = 1;
1047 Options.HexFloats = 1;
1048 // FALL THROUGH.
1049 case lang_gnu89:
1050 Options.BCPLComment = 1; // Only for C99/C++.
1051 // FALL THROUGH.
1052 case lang_c94:
1053 Options.Digraphs = 1; // C94, C99, C++.
1054 // FALL THROUGH.
1055 case lang_c89:
1056 break;
1057 }
1058
1059 // GNUMode - Set if we're in gnu99, gnu89, gnucxx98, etc.
1060 switch (LangStd) {
1061 default: assert(0 && "Unknown language standard!");
1062 case lang_gnucxx0x:
1063 case lang_gnucxx98:
1064 case lang_gnu99:
1065 case lang_gnu89:
1066 Options.GNUMode = 1;
1067 break;
1068 case lang_cxx0x:
1069 case lang_cxx98:
1070 case lang_c99:
1071 case lang_c94:
1072 case lang_c89:
1073 Options.GNUMode = 0;
1074 break;
1075 }
1076
1077 if (Options.CPlusPlus) {
1078 Options.C99 = 0;
1079 Options.HexFloats = 0;
1080 }
1081
1082 if (LangStd == lang_c89 || LangStd == lang_c94 || LangStd == lang_gnu89)
1083 Options.ImplicitInt = 1;
1084 else
1085 Options.ImplicitInt = 0;
1086
1087 // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
1088 // is specified, or -std is set to a conforming mode.
1089 Options.Trigraphs = !Options.GNUMode;
1090 if (Trigraphs.getPosition())
1091 Options.Trigraphs = Trigraphs; // Command line option wins if specified.
1092
1093 // If in a conformant language mode (e.g. -std=c99) Blocks defaults to off
1094 // even if they are normally on for the target. In GNU modes (e.g.
1095 // -std=gnu99) the default for blocks depends on the target settings.
1096 // However, blocks are not turned off when compiling Obj-C or Obj-C++ code.
1097 if (!Options.ObjC1 && !Options.GNUMode)
1098 Options.Blocks = 0;
1099
1100 // Default to not accepting '$' in identifiers when preprocessing assembler,
1101 // but do accept when preprocessing C. FIXME: these defaults are right for
1102 // darwin, are they right everywhere?
1103 Options.DollarIdents = LK != langkind_asm_cpp;
1104 if (DollarsInIdents.getPosition()) // Explicit setting overrides default.
1105 Options.DollarIdents = DollarsInIdents;
1106
1107 if (PascalStrings.getPosition())
1108 Options.PascalStrings = PascalStrings;
1109 if (MSExtensions.getPosition())
1110 Options.Microsoft = MSExtensions;
1111 Options.WritableStrings = WritableStrings;
1112 if (NoLaxVectorConversions.getPosition())
1113 Options.LaxVectorConversions = 0;
1114 Options.Exceptions = Exceptions;
1115 Options.Rtti = Rtti;
1116 if (EnableBlocks.getPosition())
1117 Options.Blocks = EnableBlocks;
1118 if (CharIsSigned.getPosition())
1119 Options.CharIsSigned = CharIsSigned;
1120 if (ShortWChar.getPosition())
1121 Options.ShortWChar = ShortWChar;
1122
1123 if (!AllowBuiltins)
1124 Options.NoBuiltin = 1;
1125 if (Freestanding)
1126 Options.Freestanding = Options.NoBuiltin = 1;
1127
1128 if (EnableHeinousExtensions)
1129 Options.HeinousExtensions = 1;
1130
1131 if (AccessControl)
1132 Options.AccessControl = 1;
1133
1134 Options.ElideConstructors = !NoElideConstructors;
1135
1136 // OpenCL and C++ both have bool, true, false keywords.
1137 Options.Bool = Options.OpenCL | Options.CPlusPlus;
1138
1139 Options.MathErrno = MathErrno;
1140
1141 Options.InstantiationDepth = TemplateDepth;
1142
1143 // Override the default runtime if the user requested it.
1144 if (NeXTRuntime)
1145 Options.NeXTRuntime = 1;
1146 else if (GNURuntime)
1147 Options.NeXTRuntime = 0;
1148
1149 if (!ObjCConstantStringClass.empty())
1150 Options.ObjCConstantStringClass = ObjCConstantStringClass.c_str();
1151
1152 if (ObjCNonFragileABI)
1153 Options.ObjCNonFragileABI = 1;
1154
1155 if (EmitAllDecls)
1156 Options.EmitAllDecls = 1;
1157
1158 // The __OPTIMIZE_SIZE__ define is tied to -Oz, which we don't support.
1159 Options.OptimizeSize = 0;
Chandler Carruth2811ccf2009-11-12 17:24:48 +00001160 Options.Optimize = !!CodeGenOpts.OptimizationLevel;
Daniel Dunbar56749082009-11-11 07:26:12 +00001161
1162 assert(PICLevel <= 2 && "Invalid value for -pic-level");
1163 Options.PICLevel = PICLevel;
1164
1165 Options.GNUInline = !Options.C99;
1166 // FIXME: This is affected by other options (-fno-inline).
1167
1168 // This is the __NO_INLINE__ define, which just depends on things like the
1169 // optimization level and -fno-inline, not actually whether the backend has
1170 // inlining enabled.
Chandler Carruth2811ccf2009-11-12 17:24:48 +00001171 Options.NoInline = !CodeGenOpts.OptimizationLevel;
Daniel Dunbar56749082009-11-11 07:26:12 +00001172
1173 Options.Static = StaticDefine;
1174
1175 switch (StackProtector) {
1176 default:
1177 assert(StackProtector <= 2 && "Invalid value for -stack-protector");
1178 case -1: break;
1179 case 0: Options.setStackProtectorMode(LangOptions::SSPOff); break;
1180 case 1: Options.setStackProtectorMode(LangOptions::SSPOn); break;
1181 case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break;
1182 }
1183
1184 if (MainFileName.getPosition())
1185 Options.setMainFileName(MainFileName.c_str());
1186
1187 Target.setForcedLangOptions(Options);
1188}
Daniel Dunbar29cf7462009-11-11 10:07:44 +00001189
1190void
1191clang::InitializePreprocessorOutputOptions(PreprocessorOutputOptions &Opts) {
1192 using namespace preprocessoroutputoptions;
1193
1194 Opts.ShowCPP = !DumpMacros;
1195 Opts.ShowMacros = DumpMacros || DumpDefines;
1196 Opts.ShowLineMarkers = !DisableLineMarkers;
1197 Opts.ShowComments = EnableCommentOutput;
1198 Opts.ShowMacroComments = EnableMacroCommentOutput;
1199}