blob: 0a6c2143e06bab14a494540a874f2f3bd988f732 [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
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +0000324static llvm::cl::opt<FrontendOptions::InputKind>
325InputType("x", llvm::cl::desc("Input language type"),
326 llvm::cl::init(FrontendOptions::IK_None),
327 llvm::cl::values(clEnumValN(FrontendOptions::IK_C, "c", "C"),
328 clEnumValN(FrontendOptions::IK_OpenCL, "cl", "OpenCL C"),
329 clEnumValN(FrontendOptions::IK_CXX, "c++", "C++"),
330 clEnumValN(FrontendOptions::IK_ObjC, "objective-c",
331 "Objective C"),
332 clEnumValN(FrontendOptions::IK_ObjCXX, "objective-c++",
333 "Objective C++"),
334 clEnumValN(FrontendOptions::IK_PreprocessedC,
335 "cpp-output",
336 "Preprocessed C"),
337 clEnumValN(FrontendOptions::IK_Asm,
338 "assembler-with-cpp",
339 "Assembly Source Codde"),
340 clEnumValN(FrontendOptions::IK_PreprocessedCXX,
341 "c++-cpp-output",
342 "Preprocessed C++"),
343 clEnumValN(FrontendOptions::IK_PreprocessedObjC,
344 "objective-c-cpp-output",
345 "Preprocessed Objective C"),
346 clEnumValN(FrontendOptions::IK_PreprocessedObjCXX,
347 "objective-c++-cpp-output",
348 "Preprocessed Objective C++"),
349 clEnumValN(FrontendOptions::IK_C, "c-header",
350 "C header"),
351 clEnumValN(FrontendOptions::IK_ObjC, "objective-c-header",
352 "Objective-C header"),
353 clEnumValN(FrontendOptions::IK_CXX, "c++-header",
354 "C++ header"),
355 clEnumValN(FrontendOptions::IK_ObjCXX,
356 "objective-c++-header",
357 "Objective-C++ header"),
358 clEnumValN(FrontendOptions::IK_AST, "ast",
359 "Clang AST"),
360 clEnumValEnd));
361
Daniel Dunbar26266882009-11-12 23:52:32 +0000362static llvm::cl::list<std::string>
363InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input files>"));
364
365static llvm::cl::opt<std::string>
366InheritanceViewCls("cxx-inheritance-view",
367 llvm::cl::value_desc("class name"),
368 llvm::cl::desc("View C++ inheritance for a specified class"));
369
370static llvm::cl::opt<bool>
371FixItAll("fixit", llvm::cl::desc("Apply fix-it advice to the input source"));
372
Daniel Dunbarc86804b2009-11-12 23:52:56 +0000373static llvm::cl::list<ParsedSourceLocation>
374FixItAtLocations("fixit-at", llvm::cl::value_desc("source-location"),
375 llvm::cl::desc("Perform Fix-It modifications at the given source location"));
376
Daniel Dunbar26266882009-11-12 23:52:32 +0000377static llvm::cl::opt<std::string>
378OutputFile("o",
379 llvm::cl::value_desc("path"),
380 llvm::cl::desc("Specify output file"));
381
382static llvm::cl::opt<bool>
383RelocatablePCH("relocatable-pch",
384 llvm::cl::desc("Whether to build a relocatable precompiled "
385 "header"));
386static llvm::cl::opt<bool>
387Stats("print-stats",
388 llvm::cl::desc("Print performance metrics and statistics"));
389
Daniel Dunbar21dac5e2009-11-13 01:02:19 +0000390static llvm::cl::opt<std::string>
391TargetABI("target-abi",
392 llvm::cl::desc("Target a particular ABI type"));
393
394static llvm::cl::opt<std::string>
395TargetTriple("triple",
396 llvm::cl::desc("Specify target triple (e.g. i686-apple-darwin9)"));
397
Daniel Dunbar26266882009-11-12 23:52:32 +0000398static llvm::cl::opt<bool>
399TimeReport("ftime-report",
400 llvm::cl::desc("Print the amount of time each "
401 "phase of compilation takes"));
402
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000403}
404
405//===----------------------------------------------------------------------===//
Daniel Dunbar56749082009-11-11 07:26:12 +0000406// Language Options
407//===----------------------------------------------------------------------===//
408
409namespace langoptions {
410
411static llvm::cl::opt<bool>
412AllowBuiltins("fbuiltin", llvm::cl::init(true),
413 llvm::cl::desc("Disable implicit builtin knowledge of functions"));
414
415static llvm::cl::opt<bool>
416AltiVec("faltivec", llvm::cl::desc("Enable AltiVec vector initializer syntax"),
417 llvm::cl::init(false));
418
419static llvm::cl::opt<bool>
420AccessControl("faccess-control",
421 llvm::cl::desc("Enable C++ access control"));
422
423static llvm::cl::opt<bool>
424CharIsSigned("fsigned-char",
425 llvm::cl::desc("Force char to be a signed/unsigned type"));
426
427static llvm::cl::opt<bool>
428DollarsInIdents("fdollars-in-identifiers",
429 llvm::cl::desc("Allow '$' in identifiers"));
430
431static llvm::cl::opt<bool>
432EmitAllDecls("femit-all-decls",
433 llvm::cl::desc("Emit all declarations, even if unused"));
434
435static llvm::cl::opt<bool>
436EnableBlocks("fblocks", llvm::cl::desc("enable the 'blocks' language feature"));
437
438static llvm::cl::opt<bool>
439EnableHeinousExtensions("fheinous-gnu-extensions",
440 llvm::cl::desc("enable GNU extensions that you really really shouldn't use"),
441 llvm::cl::ValueDisallowed, llvm::cl::Hidden);
442
443static llvm::cl::opt<bool>
444Exceptions("fexceptions",
445 llvm::cl::desc("Enable support for exception handling"));
446
447static llvm::cl::opt<bool>
448Freestanding("ffreestanding",
449 llvm::cl::desc("Assert that the compilation takes place in a "
450 "freestanding environment"));
451
452static llvm::cl::opt<bool>
453GNURuntime("fgnu-runtime",
454 llvm::cl::desc("Generate output compatible with the standard GNU "
455 "Objective-C runtime"));
456
457/// LangStds - Language standards we support.
458enum LangStds {
459 lang_unspecified,
460 lang_c89, lang_c94, lang_c99,
461 lang_gnu89, lang_gnu99,
462 lang_cxx98, lang_gnucxx98,
463 lang_cxx0x, lang_gnucxx0x
464};
465static llvm::cl::opt<LangStds>
466LangStd("std", llvm::cl::desc("Language standard to compile for"),
467 llvm::cl::init(lang_unspecified),
468 llvm::cl::values(clEnumValN(lang_c89, "c89", "ISO C 1990"),
469 clEnumValN(lang_c89, "c90", "ISO C 1990"),
470 clEnumValN(lang_c89, "iso9899:1990", "ISO C 1990"),
471 clEnumValN(lang_c94, "iso9899:199409",
472 "ISO C 1990 with amendment 1"),
473 clEnumValN(lang_c99, "c99", "ISO C 1999"),
474 clEnumValN(lang_c99, "c9x", "ISO C 1999"),
475 clEnumValN(lang_c99, "iso9899:1999", "ISO C 1999"),
476 clEnumValN(lang_c99, "iso9899:199x", "ISO C 1999"),
477 clEnumValN(lang_gnu89, "gnu89",
478 "ISO C 1990 with GNU extensions"),
479 clEnumValN(lang_gnu99, "gnu99",
480 "ISO C 1999 with GNU extensions (default for C)"),
481 clEnumValN(lang_gnu99, "gnu9x",
482 "ISO C 1999 with GNU extensions"),
483 clEnumValN(lang_cxx98, "c++98",
484 "ISO C++ 1998 with amendments"),
485 clEnumValN(lang_gnucxx98, "gnu++98",
486 "ISO C++ 1998 with amendments and GNU "
487 "extensions (default for C++)"),
488 clEnumValN(lang_cxx0x, "c++0x",
489 "Upcoming ISO C++ 200x with amendments"),
490 clEnumValN(lang_gnucxx0x, "gnu++0x",
491 "Upcoming ISO C++ 200x with amendments and GNU "
492 "extensions"),
493 clEnumValEnd));
494
495static llvm::cl::opt<bool>
496MSExtensions("fms-extensions",
497 llvm::cl::desc("Accept some non-standard constructs used in "
498 "Microsoft header files "));
499
500static llvm::cl::opt<std::string>
501MainFileName("main-file-name",
502 llvm::cl::desc("Main file name to use for debug info"));
503
504static llvm::cl::opt<bool>
505MathErrno("fmath-errno", llvm::cl::init(true),
506 llvm::cl::desc("Require math functions to respect errno"));
507
508static llvm::cl::opt<bool>
509NeXTRuntime("fnext-runtime",
510 llvm::cl::desc("Generate output compatible with the NeXT "
511 "runtime"));
512
513static llvm::cl::opt<bool>
514NoElideConstructors("fno-elide-constructors",
515 llvm::cl::desc("Disable C++ copy constructor elision"));
516
517static llvm::cl::opt<bool>
518NoLaxVectorConversions("fno-lax-vector-conversions",
519 llvm::cl::desc("Disallow implicit conversions between "
520 "vectors with a different number of "
521 "elements or different element types"));
522
523
524static llvm::cl::opt<bool>
525NoOperatorNames("fno-operator-names",
526 llvm::cl::desc("Do not treat C++ operator name keywords as "
527 "synonyms for operators"));
528
529static llvm::cl::opt<std::string>
530ObjCConstantStringClass("fconstant-string-class",
531 llvm::cl::value_desc("class name"),
532 llvm::cl::desc("Specify the class to use for constant "
533 "Objective-C string objects."));
534
535static llvm::cl::opt<bool>
536ObjCEnableGC("fobjc-gc",
537 llvm::cl::desc("Enable Objective-C garbage collection"));
538
539static llvm::cl::opt<bool>
540ObjCExclusiveGC("fobjc-gc-only",
541 llvm::cl::desc("Use GC exclusively for Objective-C related "
542 "memory management"));
543
544static llvm::cl::opt<bool>
545ObjCEnableGCBitmapPrint("print-ivar-layout",
546 llvm::cl::desc("Enable Objective-C Ivar layout bitmap print trace"));
547
548static llvm::cl::opt<bool>
549ObjCNonFragileABI("fobjc-nonfragile-abi",
550 llvm::cl::desc("enable objective-c's nonfragile abi"));
551
552static llvm::cl::opt<bool>
553OverflowChecking("ftrapv",
554 llvm::cl::desc("Trap on integer overflow"),
555 llvm::cl::init(false));
556
557static llvm::cl::opt<unsigned>
558PICLevel("pic-level", llvm::cl::desc("Value for __PIC__"));
559
560static llvm::cl::opt<bool>
561PThread("pthread", llvm::cl::desc("Support POSIX threads in generated code"),
562 llvm::cl::init(false));
563
564static llvm::cl::opt<bool>
565PascalStrings("fpascal-strings",
566 llvm::cl::desc("Recognize and construct Pascal-style "
567 "string literals"));
568
Daniel Dunbar56749082009-11-11 07:26:12 +0000569static llvm::cl::opt<bool>
570Rtti("frtti", llvm::cl::init(true),
571 llvm::cl::desc("Enable generation of rtti information"));
572
573static llvm::cl::opt<bool>
574ShortWChar("fshort-wchar",
575 llvm::cl::desc("Force wchar_t to be a short unsigned int"));
576
577static llvm::cl::opt<bool>
578StaticDefine("static-define", llvm::cl::desc("Should __STATIC__ be defined"));
579
580static llvm::cl::opt<int>
581StackProtector("stack-protector",
582 llvm::cl::desc("Enable stack protectors"),
583 llvm::cl::init(-1));
584
585static llvm::cl::opt<LangOptions::VisibilityMode>
586SymbolVisibility("fvisibility",
587 llvm::cl::desc("Set the default symbol visibility:"),
588 llvm::cl::init(LangOptions::Default),
589 llvm::cl::values(clEnumValN(LangOptions::Default, "default",
590 "Use default symbol visibility"),
591 clEnumValN(LangOptions::Hidden, "hidden",
592 "Use hidden symbol visibility"),
593 clEnumValN(LangOptions::Protected,"protected",
594 "Use protected symbol visibility"),
595 clEnumValEnd));
596
597static llvm::cl::opt<unsigned>
598TemplateDepth("ftemplate-depth", llvm::cl::init(99),
599 llvm::cl::desc("Maximum depth of recursive template "
600 "instantiation"));
601
602static llvm::cl::opt<bool>
603Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences"));
604
605static llvm::cl::opt<bool>
606WritableStrings("fwritable-strings",
607 llvm::cl::desc("Store string literals as writable data"));
608
609}
610
611//===----------------------------------------------------------------------===//
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000612// General Preprocessor Options
613//===----------------------------------------------------------------------===//
614
615namespace preprocessoroptions {
616
617static llvm::cl::list<std::string>
618D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
619 llvm::cl::desc("Predefine the specified macro"));
620
621static llvm::cl::list<std::string>
622ImplicitIncludes("include", llvm::cl::value_desc("file"),
623 llvm::cl::desc("Include file before parsing"));
624static llvm::cl::list<std::string>
625ImplicitMacroIncludes("imacros", llvm::cl::value_desc("file"),
626 llvm::cl::desc("Include macros from file before parsing"));
627
628static llvm::cl::opt<std::string>
629ImplicitIncludePCH("include-pch", llvm::cl::value_desc("file"),
630 llvm::cl::desc("Include precompiled header file"));
631
632static llvm::cl::opt<std::string>
633ImplicitIncludePTH("include-pth", llvm::cl::value_desc("file"),
634 llvm::cl::desc("Include file before parsing"));
635
Daniel Dunbarb3cb98e2009-11-12 02:53:59 +0000636static llvm::cl::opt<std::string>
637TokenCache("token-cache", llvm::cl::value_desc("path"),
638 llvm::cl::desc("Use specified token cache file"));
639
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000640static llvm::cl::list<std::string>
641U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
642 llvm::cl::desc("Undefine the specified macro"));
643
644static llvm::cl::opt<bool>
645UndefMacros("undef", llvm::cl::value_desc("macro"),
646 llvm::cl::desc("undef all system defines"));
647
648}
649
650//===----------------------------------------------------------------------===//
Daniel Dunbarf7973292009-11-11 08:13:32 +0000651// Header Search Options
652//===----------------------------------------------------------------------===//
653
654namespace headersearchoptions {
655
656static llvm::cl::opt<bool>
657nostdinc("nostdinc", llvm::cl::desc("Disable standard #include directories"));
658
659static llvm::cl::opt<bool>
660nobuiltininc("nobuiltininc",
661 llvm::cl::desc("Disable builtin #include directories"));
662
663// Various command line options. These four add directories to each chain.
664static llvm::cl::list<std::string>
665F_dirs("F", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
666 llvm::cl::desc("Add directory to framework include search path"));
667
668static llvm::cl::list<std::string>
669I_dirs("I", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
670 llvm::cl::desc("Add directory to include search path"));
671
672static llvm::cl::list<std::string>
673idirafter_dirs("idirafter", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
674 llvm::cl::desc("Add directory to AFTER include search path"));
675
676static llvm::cl::list<std::string>
677iquote_dirs("iquote", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
678 llvm::cl::desc("Add directory to QUOTE include search path"));
679
680static llvm::cl::list<std::string>
681isystem_dirs("isystem", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
682 llvm::cl::desc("Add directory to SYSTEM include search path"));
683
684// These handle -iprefix/-iwithprefix/-iwithprefixbefore.
685static llvm::cl::list<std::string>
686iprefix_vals("iprefix", llvm::cl::value_desc("prefix"), llvm::cl::Prefix,
687 llvm::cl::desc("Set the -iwithprefix/-iwithprefixbefore prefix"));
688static llvm::cl::list<std::string>
689iwithprefix_vals("iwithprefix", llvm::cl::value_desc("dir"), llvm::cl::Prefix,
690 llvm::cl::desc("Set directory to SYSTEM include search path with prefix"));
691static llvm::cl::list<std::string>
692iwithprefixbefore_vals("iwithprefixbefore", llvm::cl::value_desc("dir"),
693 llvm::cl::Prefix,
694 llvm::cl::desc("Set directory to include search path with prefix"));
695
696static llvm::cl::opt<std::string>
697isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::init("/"),
698 llvm::cl::desc("Set the system root directory (usually /)"));
699
Daniel Dunbar1417c742009-11-12 23:52:46 +0000700static llvm::cl::opt<bool>
701Verbose("v", llvm::cl::desc("Enable verbose output"));
702
Daniel Dunbarf7973292009-11-11 08:13:32 +0000703}
704
705//===----------------------------------------------------------------------===//
Daniel Dunbar29cf7462009-11-11 10:07:44 +0000706// Preprocessed Output Options
707//===----------------------------------------------------------------------===//
708
709namespace preprocessoroutputoptions {
710
711static llvm::cl::opt<bool>
712DisableLineMarkers("P", llvm::cl::desc("Disable linemarker output in -E mode"));
713
714static llvm::cl::opt<bool>
715EnableCommentOutput("C", llvm::cl::desc("Enable comment output in -E mode"));
716
717static llvm::cl::opt<bool>
718EnableMacroCommentOutput("CC",
719 llvm::cl::desc("Enable comment output in -E mode, "
720 "even from macro expansions"));
721static llvm::cl::opt<bool>
722DumpMacros("dM", llvm::cl::desc("Print macro definitions in -E mode instead of"
723 " normal output"));
724static llvm::cl::opt<bool>
725DumpDefines("dD", llvm::cl::desc("Print macro definitions in -E mode in "
726 "addition to normal output"));
727
728}
729
730//===----------------------------------------------------------------------===//
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000731// Option Object Construction
732//===----------------------------------------------------------------------===//
733
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000734void clang::InitializeCodeGenOptions(CodeGenOptions &Opts,
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000735 const TargetInfo &Target) {
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000736 using namespace codegenoptions;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000737
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000738 // Compute the target features, we need the target to handle this because
739 // features may have dependencies on one another.
740 llvm::StringMap<bool> Features;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000741 Target.getDefaultFeatures(TargetCPU, Features);
742
743 // Apply the user specified deltas.
744 for (llvm::cl::list<std::string>::iterator it = TargetFeatures.begin(),
745 ie = TargetFeatures.end(); it != ie; ++it) {
746 const char *Name = it->c_str();
747
748 // FIXME: Don't handle errors like this.
749 if (Name[0] != '-' && Name[0] != '+') {
750 fprintf(stderr, "error: clang-cc: invalid target feature string: %s\n",
751 Name);
752 exit(1);
753 }
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000754
755 // Apply the feature via the target.
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000756 if (!Target.setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) {
757 fprintf(stderr, "error: clang-cc: invalid target feature name: %s\n",
758 Name + 1);
759 exit(1);
760 }
761 }
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000762
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000763 // Add the features to the compile options.
764 //
765 // FIXME: If we are completely confident that we have the right set, we only
766 // need to pass the minuses.
767 for (llvm::StringMap<bool>::const_iterator it = Features.begin(),
768 ie = Features.end(); it != ie; ++it)
769 Opts.Features.push_back(std::string(it->second ? "+" : "-") + it->first());
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000770
771 // -Os implies -O2
772 Opts.OptimizationLevel = OptSize ? 2 : OptLevel;
773
774 // We must always run at least the always inlining pass.
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000775 Opts.Inlining = (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining
776 : CodeGenOptions::OnlyAlwaysInlining;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000777
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000778 Opts.CPU = TargetCPU;
779 Opts.DebugInfo = GenerateDebugInfo;
780 Opts.DisableLLVMOpts = DisableLLVMOptimizations;
781 Opts.DisableRedZone = DisableRedZone;
782 Opts.MergeAllConstants = !NoMergeConstants;
783 Opts.NoCommon = NoCommon;
784 Opts.NoImplicitFloat = NoImplicitFloat;
785 Opts.OptimizeSize = OptSize;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000786 Opts.SimplifyLibCalls = 1;
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000787 Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize);
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000788
789#ifdef NDEBUG
790 Opts.VerifyModule = 0;
791#endif
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000792}
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000793
Daniel Dunbar0e0bae82009-11-11 21:43:12 +0000794void clang::InitializeDependencyOutputOptions(DependencyOutputOptions &Opts) {
795 using namespace dependencyoutputoptions;
796
797 Opts.OutputFile = DependencyFile;
Daniel Dunbar26266882009-11-12 23:52:32 +0000798 Opts.Targets = DependencyTargets;
Daniel Dunbar0e0bae82009-11-11 21:43:12 +0000799 Opts.IncludeSystemHeaders = DependenciesIncludeSystemHeaders;
800 Opts.UsePhonyTargets = PhonyDependencyTarget;
801}
802
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000803void clang::InitializeDiagnosticOptions(DiagnosticOptions &Opts) {
804 using namespace diagnosticoptions;
805
Daniel Dunbar26266882009-11-12 23:52:32 +0000806 Opts.Warnings = OptWarnings;
Daniel Dunbar11e729d2009-11-12 07:28:21 +0000807 Opts.DumpBuildInformation = DumpBuildInformation;
Daniel Dunbar69079432009-11-12 07:28:44 +0000808 Opts.IgnoreWarnings = OptNoWarnings;
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000809 Opts.MessageLength = MessageLength;
Daniel Dunbar69079432009-11-12 07:28:44 +0000810 Opts.NoRewriteMacros = SilenceRewriteMacroWarning;
811 Opts.Pedantic = OptPedantic;
812 Opts.PedanticErrors = OptPedanticErrors;
Daniel Dunbar11e729d2009-11-12 07:28:21 +0000813 Opts.ShowCarets = !NoCaretDiagnostics;
814 Opts.ShowColors = PrintColorDiagnostic;
815 Opts.ShowColumn = !NoShowColumn;
816 Opts.ShowFixits = !NoDiagnosticsFixIt;
817 Opts.ShowLocation = !NoShowLocation;
818 Opts.ShowOptionNames = PrintDiagnosticOption;
819 Opts.ShowSourceRanges = PrintSourceRangeInfo;
Daniel Dunbar26266882009-11-12 23:52:32 +0000820 Opts.VerifyDiagnostics = VerifyDiagnostics;
821}
822
823void clang::InitializeFrontendOptions(FrontendOptions &Opts) {
824 using namespace frontendoptions;
825
Daniel Dunbar914474c2009-11-13 01:02:10 +0000826 Opts.CodeCompletionAt = CodeCompletionAt;
827 Opts.DebugCodeCompletionPrinter = CodeCompletionDebugPrinter;
Daniel Dunbar26266882009-11-12 23:52:32 +0000828 Opts.DisableFree = DisableFree;
829 Opts.EmptyInputOnly = EmptyInputOnly;
830 Opts.FixItAll = FixItAll;
Daniel Dunbarc86804b2009-11-12 23:52:56 +0000831 Opts.FixItLocations = FixItAtLocations;
Daniel Dunbar26266882009-11-12 23:52:32 +0000832 Opts.OutputFile = OutputFile;
Daniel Dunbar914474c2009-11-13 01:02:10 +0000833 Opts.RelocatablePCH = RelocatablePCH;
834 Opts.ShowMacrosInCodeCompletion = CodeCompletionWantsMacros;
835 Opts.ShowStats = Stats;
836 Opts.ShowTimers = TimeReport;
Daniel Dunbar21dac5e2009-11-13 01:02:19 +0000837 Opts.TargetABI = TargetABI;
838 Opts.TargetTriple = TargetTriple;
Daniel Dunbar26266882009-11-12 23:52:32 +0000839 Opts.ViewClassInheritance = InheritanceViewCls;
840
841 // '-' is the default input if none is given.
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +0000842 if (InputFilenames.empty()) {
843 FrontendOptions::InputKind IK = InputType;
844 if (IK == FrontendOptions::IK_None) IK = FrontendOptions::IK_C;
845 Opts.Inputs.push_back(std::make_pair(IK, "-"));
846 } else {
847 for (unsigned i = 0, e = InputFilenames.size(); i != e; ++i) {
848 FrontendOptions::InputKind IK = InputType;
849 llvm::StringRef Ext =
850 llvm::StringRef(InputFilenames[i]).rsplit('.').second;
851 if (IK == FrontendOptions::IK_None)
852 IK = FrontendOptions::getInputKindForExtension(Ext);
853 Opts.Inputs.push_back(std::make_pair(IK, InputFilenames[i]));
854
855 }
856 }
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000857}
858
Daniel Dunbarf7973292009-11-11 08:13:32 +0000859void clang::InitializeHeaderSearchOptions(HeaderSearchOptions &Opts,
860 llvm::StringRef BuiltinIncludePath,
Daniel Dunbarf7973292009-11-11 08:13:32 +0000861 const LangOptions &Lang) {
862 using namespace headersearchoptions;
863
864 Opts.Sysroot = isysroot;
865 Opts.Verbose = Verbose;
866
867 // Handle -I... and -F... options, walking the lists in parallel.
868 unsigned Iidx = 0, Fidx = 0;
869 while (Iidx < I_dirs.size() && Fidx < F_dirs.size()) {
870 if (I_dirs.getPosition(Iidx) < F_dirs.getPosition(Fidx)) {
871 Opts.AddPath(I_dirs[Iidx], frontend::Angled, false, true, false);
872 ++Iidx;
873 } else {
874 Opts.AddPath(F_dirs[Fidx], frontend::Angled, false, true, true);
875 ++Fidx;
876 }
877 }
878
879 // Consume what's left from whatever list was longer.
880 for (; Iidx != I_dirs.size(); ++Iidx)
881 Opts.AddPath(I_dirs[Iidx], frontend::Angled, false, true, false);
882 for (; Fidx != F_dirs.size(); ++Fidx)
883 Opts.AddPath(F_dirs[Fidx], frontend::Angled, false, true, true);
884
885 // Handle -idirafter... options.
886 for (unsigned i = 0, e = idirafter_dirs.size(); i != e; ++i)
887 Opts.AddPath(idirafter_dirs[i], frontend::After,
888 false, true, false);
889
890 // Handle -iquote... options.
891 for (unsigned i = 0, e = iquote_dirs.size(); i != e; ++i)
892 Opts.AddPath(iquote_dirs[i], frontend::Quoted, false, true, false);
893
894 // Handle -isystem... options.
895 for (unsigned i = 0, e = isystem_dirs.size(); i != e; ++i)
896 Opts.AddPath(isystem_dirs[i], frontend::System, false, true, false);
897
898 // Walk the -iprefix/-iwithprefix/-iwithprefixbefore argument lists in
899 // parallel, processing the values in order of occurance to get the right
900 // prefixes.
901 {
902 std::string Prefix = ""; // FIXME: this isn't the correct default prefix.
903 unsigned iprefix_idx = 0;
904 unsigned iwithprefix_idx = 0;
905 unsigned iwithprefixbefore_idx = 0;
906 bool iprefix_done = iprefix_vals.empty();
907 bool iwithprefix_done = iwithprefix_vals.empty();
908 bool iwithprefixbefore_done = iwithprefixbefore_vals.empty();
909 while (!iprefix_done || !iwithprefix_done || !iwithprefixbefore_done) {
910 if (!iprefix_done &&
911 (iwithprefix_done ||
912 iprefix_vals.getPosition(iprefix_idx) <
913 iwithprefix_vals.getPosition(iwithprefix_idx)) &&
914 (iwithprefixbefore_done ||
915 iprefix_vals.getPosition(iprefix_idx) <
916 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
917 Prefix = iprefix_vals[iprefix_idx];
918 ++iprefix_idx;
919 iprefix_done = iprefix_idx == iprefix_vals.size();
920 } else if (!iwithprefix_done &&
921 (iwithprefixbefore_done ||
922 iwithprefix_vals.getPosition(iwithprefix_idx) <
923 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
924 Opts.AddPath(Prefix+iwithprefix_vals[iwithprefix_idx],
925 frontend::System, false, false, false);
926 ++iwithprefix_idx;
927 iwithprefix_done = iwithprefix_idx == iwithprefix_vals.size();
928 } else {
929 Opts.AddPath(Prefix+iwithprefixbefore_vals[iwithprefixbefore_idx],
930 frontend::Angled, false, false, false);
931 ++iwithprefixbefore_idx;
932 iwithprefixbefore_done =
933 iwithprefixbefore_idx == iwithprefixbefore_vals.size();
934 }
935 }
936 }
937
938 // Add CPATH environment paths.
939 if (const char *Env = getenv("CPATH"))
940 Opts.EnvIncPath = Env;
941
942 // Add language specific environment paths.
943 if (Lang.CPlusPlus && Lang.ObjC1) {
944 if (const char *Env = getenv("OBJCPLUS_INCLUDE_PATH"))
945 Opts.LangEnvIncPath = Env;
946 } else if (Lang.CPlusPlus) {
947 if (const char *Env = getenv("CPLUS_INCLUDE_PATH"))
948 Opts.LangEnvIncPath = Env;
949 } else if (Lang.ObjC1) {
950 if (const char *Env = getenv("OBJC_INCLUDE_PATH"))
951 Opts.LangEnvIncPath = Env;
952 } else {
953 if (const char *Env = getenv("C_INCLUDE_PATH"))
954 Opts.LangEnvIncPath = Env;
955 }
956
957 if (!nobuiltininc)
958 Opts.BuiltinIncludePath = BuiltinIncludePath;
959
960 Opts.UseStandardIncludes = !nostdinc;
961}
962
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000963void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) {
964 using namespace preprocessoroptions;
965
966 Opts.setImplicitPCHInclude(ImplicitIncludePCH);
967 Opts.setImplicitPTHInclude(ImplicitIncludePTH);
968
Daniel Dunbarb3cb98e2009-11-12 02:53:59 +0000969 // Select the token cache file, we don't support more than one currently so we
970 // can't have both an implicit-pth and a token cache file.
971 if (TokenCache.getPosition() && ImplicitIncludePTH.getPosition()) {
972 // FIXME: Don't fail like this.
973 fprintf(stderr, "error: cannot use both -token-cache and -include-pth "
974 "options\n");
975 exit(1);
976 }
977 if (TokenCache.getPosition())
978 Opts.setTokenCache(TokenCache);
979 else
980 Opts.setTokenCache(ImplicitIncludePTH);
981
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000982 // Use predefines?
983 Opts.setUsePredefines(!UndefMacros);
984
985 // Add macros from the command line.
986 unsigned d = 0, D = D_macros.size();
987 unsigned u = 0, U = U_macros.size();
988 while (d < D || u < U) {
989 if (u == U || (d < D && D_macros.getPosition(d) < U_macros.getPosition(u)))
990 Opts.addMacroDef(D_macros[d++]);
991 else
992 Opts.addMacroUndef(U_macros[u++]);
993 }
994
995 // If -imacros are specified, include them now. These are processed before
996 // any -include directives.
997 for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i)
998 Opts.addMacroInclude(ImplicitMacroIncludes[i]);
999
1000 // Add the ordered list of -includes, sorting in the implicit include options
1001 // at the appropriate location.
1002 llvm::SmallVector<std::pair<unsigned, std::string*>, 8> OrderedPaths;
1003 std::string OriginalFile;
1004
1005 if (!ImplicitIncludePTH.empty())
1006 OrderedPaths.push_back(std::make_pair(ImplicitIncludePTH.getPosition(),
1007 &ImplicitIncludePTH));
1008 if (!ImplicitIncludePCH.empty()) {
1009 OriginalFile = PCHReader::getOriginalSourceFile(ImplicitIncludePCH);
1010 // FIXME: Don't fail like this.
1011 if (OriginalFile.empty())
1012 exit(1);
1013 OrderedPaths.push_back(std::make_pair(ImplicitIncludePCH.getPosition(),
1014 &OriginalFile));
1015 }
1016 for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i)
1017 OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i),
1018 &ImplicitIncludes[i]));
1019 llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end());
1020
1021 for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i)
1022 Opts.addInclude(*OrderedPaths[i].second);
1023}
Daniel Dunbar56749082009-11-11 07:26:12 +00001024
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001025void clang::InitializeLangOptions(LangOptions &Options,
1026 FrontendOptions::InputKind IK,
Daniel Dunbar56749082009-11-11 07:26:12 +00001027 TargetInfo &Target,
Chandler Carruth2811ccf2009-11-12 17:24:48 +00001028 const CodeGenOptions &CodeGenOpts) {
Daniel Dunbar56749082009-11-11 07:26:12 +00001029 using namespace langoptions;
1030
1031 bool NoPreprocess = false;
1032
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001033 switch (IK) {
1034 case FrontendOptions::IK_None:
1035 case FrontendOptions::IK_AST:
1036 assert(0 && "Invalid input kind!");
1037 case FrontendOptions::IK_Asm:
Daniel Dunbar56749082009-11-11 07:26:12 +00001038 Options.AsmPreprocessor = 1;
1039 // FALLTHROUGH
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001040 case FrontendOptions::IK_PreprocessedC:
Daniel Dunbar56749082009-11-11 07:26:12 +00001041 NoPreprocess = true;
1042 // FALLTHROUGH
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001043 case FrontendOptions::IK_C:
Daniel Dunbar56749082009-11-11 07:26:12 +00001044 // Do nothing.
1045 break;
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001046 case FrontendOptions::IK_PreprocessedCXX:
Daniel Dunbar56749082009-11-11 07:26:12 +00001047 NoPreprocess = true;
1048 // FALLTHROUGH
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001049 case FrontendOptions::IK_CXX:
Daniel Dunbar56749082009-11-11 07:26:12 +00001050 Options.CPlusPlus = 1;
1051 break;
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001052 case FrontendOptions::IK_PreprocessedObjC:
Daniel Dunbar56749082009-11-11 07:26:12 +00001053 NoPreprocess = true;
1054 // FALLTHROUGH
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001055 case FrontendOptions::IK_ObjC:
Daniel Dunbar56749082009-11-11 07:26:12 +00001056 Options.ObjC1 = Options.ObjC2 = 1;
1057 break;
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001058 case FrontendOptions::IK_PreprocessedObjCXX:
Daniel Dunbar56749082009-11-11 07:26:12 +00001059 NoPreprocess = true;
1060 // FALLTHROUGH
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001061 case FrontendOptions::IK_ObjCXX:
Daniel Dunbar56749082009-11-11 07:26:12 +00001062 Options.ObjC1 = Options.ObjC2 = 1;
1063 Options.CPlusPlus = 1;
1064 break;
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001065 case FrontendOptions::IK_OpenCL:
Daniel Dunbar56749082009-11-11 07:26:12 +00001066 Options.OpenCL = 1;
1067 Options.AltiVec = 1;
1068 Options.CXXOperatorNames = 1;
1069 Options.LaxVectorConversions = 1;
1070 break;
1071 }
1072
1073 if (ObjCExclusiveGC)
1074 Options.setGCMode(LangOptions::GCOnly);
1075 else if (ObjCEnableGC)
1076 Options.setGCMode(LangOptions::HybridGC);
1077
1078 if (ObjCEnableGCBitmapPrint)
1079 Options.ObjCGCBitmapPrint = 1;
1080
1081 if (AltiVec)
1082 Options.AltiVec = 1;
1083
1084 if (PThread)
1085 Options.POSIXThreads = 1;
1086
1087 Options.setVisibilityMode(SymbolVisibility);
1088 Options.OverflowChecking = OverflowChecking;
1089
1090
1091 // Allow the target to set the default the language options as it sees fit.
1092 Target.getDefaultLangOptions(Options);
1093
1094 // Pass the map of target features to the target for validation and
1095 // processing.
Chandler Carruth2811ccf2009-11-12 17:24:48 +00001096 Target.HandleTargetFeatures(CodeGenOpts.Features);
Daniel Dunbar56749082009-11-11 07:26:12 +00001097
1098 if (LangStd == lang_unspecified) {
1099 // Based on the base language, pick one.
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001100 switch (IK) {
1101 case FrontendOptions::IK_None:
1102 case FrontendOptions::IK_AST:
1103 assert(0 && "Invalid input kind!");
1104 case FrontendOptions::IK_OpenCL:
Daniel Dunbar56749082009-11-11 07:26:12 +00001105 LangStd = lang_c99;
1106 break;
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001107 case FrontendOptions::IK_Asm:
1108 case FrontendOptions::IK_C:
1109 case FrontendOptions::IK_PreprocessedC:
1110 case FrontendOptions::IK_ObjC:
1111 case FrontendOptions::IK_PreprocessedObjC:
Daniel Dunbar56749082009-11-11 07:26:12 +00001112 LangStd = lang_gnu99;
1113 break;
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001114 case FrontendOptions::IK_CXX:
1115 case FrontendOptions::IK_PreprocessedCXX:
1116 case FrontendOptions::IK_ObjCXX:
1117 case FrontendOptions::IK_PreprocessedObjCXX:
Daniel Dunbar56749082009-11-11 07:26:12 +00001118 LangStd = lang_gnucxx98;
1119 break;
1120 }
1121 }
1122
1123 switch (LangStd) {
1124 default: assert(0 && "Unknown language standard!");
1125
1126 // Fall through from newer standards to older ones. This isn't really right.
1127 // FIXME: Enable specifically the right features based on the language stds.
1128 case lang_gnucxx0x:
1129 case lang_cxx0x:
1130 Options.CPlusPlus0x = 1;
1131 // FALL THROUGH
1132 case lang_gnucxx98:
1133 case lang_cxx98:
1134 Options.CPlusPlus = 1;
1135 Options.CXXOperatorNames = !NoOperatorNames;
1136 // FALL THROUGH.
1137 case lang_gnu99:
1138 case lang_c99:
1139 Options.C99 = 1;
1140 Options.HexFloats = 1;
1141 // FALL THROUGH.
1142 case lang_gnu89:
1143 Options.BCPLComment = 1; // Only for C99/C++.
1144 // FALL THROUGH.
1145 case lang_c94:
1146 Options.Digraphs = 1; // C94, C99, C++.
1147 // FALL THROUGH.
1148 case lang_c89:
1149 break;
1150 }
1151
1152 // GNUMode - Set if we're in gnu99, gnu89, gnucxx98, etc.
1153 switch (LangStd) {
1154 default: assert(0 && "Unknown language standard!");
1155 case lang_gnucxx0x:
1156 case lang_gnucxx98:
1157 case lang_gnu99:
1158 case lang_gnu89:
1159 Options.GNUMode = 1;
1160 break;
1161 case lang_cxx0x:
1162 case lang_cxx98:
1163 case lang_c99:
1164 case lang_c94:
1165 case lang_c89:
1166 Options.GNUMode = 0;
1167 break;
1168 }
1169
1170 if (Options.CPlusPlus) {
1171 Options.C99 = 0;
1172 Options.HexFloats = 0;
1173 }
1174
1175 if (LangStd == lang_c89 || LangStd == lang_c94 || LangStd == lang_gnu89)
1176 Options.ImplicitInt = 1;
1177 else
1178 Options.ImplicitInt = 0;
1179
1180 // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
1181 // is specified, or -std is set to a conforming mode.
1182 Options.Trigraphs = !Options.GNUMode;
1183 if (Trigraphs.getPosition())
1184 Options.Trigraphs = Trigraphs; // Command line option wins if specified.
1185
1186 // If in a conformant language mode (e.g. -std=c99) Blocks defaults to off
1187 // even if they are normally on for the target. In GNU modes (e.g.
1188 // -std=gnu99) the default for blocks depends on the target settings.
1189 // However, blocks are not turned off when compiling Obj-C or Obj-C++ code.
1190 if (!Options.ObjC1 && !Options.GNUMode)
1191 Options.Blocks = 0;
1192
1193 // Default to not accepting '$' in identifiers when preprocessing assembler,
1194 // but do accept when preprocessing C. FIXME: these defaults are right for
1195 // darwin, are they right everywhere?
Daniel Dunbarfbe2faf2009-11-13 02:06:12 +00001196 Options.DollarIdents = IK != FrontendOptions::IK_Asm;
Daniel Dunbar56749082009-11-11 07:26:12 +00001197 if (DollarsInIdents.getPosition()) // Explicit setting overrides default.
1198 Options.DollarIdents = DollarsInIdents;
1199
1200 if (PascalStrings.getPosition())
1201 Options.PascalStrings = PascalStrings;
1202 if (MSExtensions.getPosition())
1203 Options.Microsoft = MSExtensions;
1204 Options.WritableStrings = WritableStrings;
1205 if (NoLaxVectorConversions.getPosition())
1206 Options.LaxVectorConversions = 0;
1207 Options.Exceptions = Exceptions;
1208 Options.Rtti = Rtti;
1209 if (EnableBlocks.getPosition())
1210 Options.Blocks = EnableBlocks;
1211 if (CharIsSigned.getPosition())
1212 Options.CharIsSigned = CharIsSigned;
1213 if (ShortWChar.getPosition())
1214 Options.ShortWChar = ShortWChar;
1215
1216 if (!AllowBuiltins)
1217 Options.NoBuiltin = 1;
1218 if (Freestanding)
1219 Options.Freestanding = Options.NoBuiltin = 1;
1220
1221 if (EnableHeinousExtensions)
1222 Options.HeinousExtensions = 1;
1223
1224 if (AccessControl)
1225 Options.AccessControl = 1;
1226
1227 Options.ElideConstructors = !NoElideConstructors;
1228
1229 // OpenCL and C++ both have bool, true, false keywords.
1230 Options.Bool = Options.OpenCL | Options.CPlusPlus;
1231
1232 Options.MathErrno = MathErrno;
1233
1234 Options.InstantiationDepth = TemplateDepth;
1235
1236 // Override the default runtime if the user requested it.
1237 if (NeXTRuntime)
1238 Options.NeXTRuntime = 1;
1239 else if (GNURuntime)
1240 Options.NeXTRuntime = 0;
1241
1242 if (!ObjCConstantStringClass.empty())
1243 Options.ObjCConstantStringClass = ObjCConstantStringClass.c_str();
1244
1245 if (ObjCNonFragileABI)
1246 Options.ObjCNonFragileABI = 1;
1247
1248 if (EmitAllDecls)
1249 Options.EmitAllDecls = 1;
1250
1251 // The __OPTIMIZE_SIZE__ define is tied to -Oz, which we don't support.
1252 Options.OptimizeSize = 0;
Chandler Carruth2811ccf2009-11-12 17:24:48 +00001253 Options.Optimize = !!CodeGenOpts.OptimizationLevel;
Daniel Dunbar56749082009-11-11 07:26:12 +00001254
1255 assert(PICLevel <= 2 && "Invalid value for -pic-level");
1256 Options.PICLevel = PICLevel;
1257
1258 Options.GNUInline = !Options.C99;
1259 // FIXME: This is affected by other options (-fno-inline).
1260
1261 // This is the __NO_INLINE__ define, which just depends on things like the
1262 // optimization level and -fno-inline, not actually whether the backend has
1263 // inlining enabled.
Chandler Carruth2811ccf2009-11-12 17:24:48 +00001264 Options.NoInline = !CodeGenOpts.OptimizationLevel;
Daniel Dunbar56749082009-11-11 07:26:12 +00001265
1266 Options.Static = StaticDefine;
1267
1268 switch (StackProtector) {
1269 default:
1270 assert(StackProtector <= 2 && "Invalid value for -stack-protector");
1271 case -1: break;
1272 case 0: Options.setStackProtectorMode(LangOptions::SSPOff); break;
1273 case 1: Options.setStackProtectorMode(LangOptions::SSPOn); break;
1274 case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break;
1275 }
1276
1277 if (MainFileName.getPosition())
1278 Options.setMainFileName(MainFileName.c_str());
1279
1280 Target.setForcedLangOptions(Options);
1281}
Daniel Dunbar29cf7462009-11-11 10:07:44 +00001282
1283void
1284clang::InitializePreprocessorOutputOptions(PreprocessorOutputOptions &Opts) {
1285 using namespace preprocessoroutputoptions;
1286
1287 Opts.ShowCPP = !DumpMacros;
1288 Opts.ShowMacros = DumpMacros || DumpDefines;
1289 Opts.ShowLineMarkers = !DisableLineMarkers;
1290 Opts.ShowComments = EnableCommentOutput;
1291 Opts.ShowMacroComments = EnableMacroCommentOutput;
1292}