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