blob: f6d7aa7857de889baa94f8a00e16c72db7ff85ec [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 Dunbarf7973292009-11-11 08:13:32 +000021#include "clang/Frontend/HeaderSearchOptions.h"
Daniel Dunbarb52d2432009-11-11 06:10:03 +000022#include "clang/Frontend/PCHReader.h"
23#include "clang/Frontend/PreprocessorOptions.h"
Daniel Dunbar29cf7462009-11-11 10:07:44 +000024#include "clang/Frontend/PreprocessorOutputOptions.h"
Daniel Dunbarb52d2432009-11-11 06:10:03 +000025#include "llvm/ADT/STLExtras.h"
Daniel Dunbar0498cfc2009-11-10 19:51:53 +000026#include "llvm/ADT/StringMap.h"
27#include "llvm/Support/CommandLine.h"
Dan Gohman0063e982009-11-10 21:21:27 +000028#include <stdio.h>
Daniel Dunbar0498cfc2009-11-10 19:51:53 +000029
30using namespace clang;
31
32//===----------------------------------------------------------------------===//
Daniel Dunbar339c1342009-11-11 08:13:55 +000033// Analyzer Options
34//===----------------------------------------------------------------------===//
35
36namespace analyzeroptions {
37
38static llvm::cl::list<Analyses>
39AnalysisList(llvm::cl::desc("Source Code Analysis - Checks and Analyses"),
40llvm::cl::values(
41#define ANALYSIS(NAME, CMDFLAG, DESC, SCOPE)\
42clEnumValN(NAME, CMDFLAG, DESC),
43#include "clang/Frontend/Analyses.def"
44clEnumValEnd));
45
46static llvm::cl::opt<AnalysisStores>
47AnalysisStoreOpt("analyzer-store",
48 llvm::cl::desc("Source Code Analysis - Abstract Memory Store Models"),
49 llvm::cl::init(BasicStoreModel),
50 llvm::cl::values(
51#define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN)\
52clEnumValN(NAME##Model, CMDFLAG, DESC),
53#include "clang/Frontend/Analyses.def"
54clEnumValEnd));
55
56static llvm::cl::opt<AnalysisConstraints>
57AnalysisConstraintsOpt("analyzer-constraints",
58 llvm::cl::desc("Source Code Analysis - Symbolic Constraint Engines"),
59 llvm::cl::init(RangeConstraintsModel),
60 llvm::cl::values(
61#define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN)\
62clEnumValN(NAME##Model, CMDFLAG, DESC),
63#include "clang/Frontend/Analyses.def"
64clEnumValEnd));
65
66static llvm::cl::opt<AnalysisDiagClients>
67AnalysisDiagOpt("analyzer-output",
68 llvm::cl::desc("Source Code Analysis - Output Options"),
69 llvm::cl::init(PD_HTML),
70 llvm::cl::values(
71#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN, AUTOCREATE)\
72clEnumValN(PD_##NAME, CMDFLAG, DESC),
73#include "clang/Frontend/Analyses.def"
74clEnumValEnd));
75
76static llvm::cl::opt<bool>
77AnalyzeAll("analyzer-opt-analyze-headers",
78 llvm::cl::desc("Force the static analyzer to analyze "
79 "functions defined in header files"));
80
81static llvm::cl::opt<bool>
82AnalyzerDisplayProgress("analyzer-display-progress",
83 llvm::cl::desc("Emit verbose output about the analyzer's progress."));
84
85static llvm::cl::opt<std::string>
86AnalyzeSpecificFunction("analyze-function",
87 llvm::cl::desc("Run analysis on specific function"));
88
89static llvm::cl::opt<bool>
90EagerlyAssume("analyzer-eagerly-assume",
91 llvm::cl::init(false),
92 llvm::cl::desc("Eagerly assume the truth/falseness of some "
93 "symbolic constraints."));
94
95static llvm::cl::opt<bool>
96PurgeDead("analyzer-purge-dead",
97 llvm::cl::init(true),
98 llvm::cl::desc("Remove dead symbols, bindings, and constraints before"
99 " processing a statement."));
100
101static llvm::cl::opt<bool>
102TrimGraph("trim-egraph",
103 llvm::cl::desc("Only show error-related paths in the analysis graph"));
104
105static llvm::cl::opt<bool>
106VisualizeEGDot("analyzer-viz-egraph-graphviz",
107 llvm::cl::desc("Display exploded graph using GraphViz"));
108
109static llvm::cl::opt<bool>
110VisualizeEGUbi("analyzer-viz-egraph-ubigraph",
111 llvm::cl::desc("Display exploded graph using Ubigraph"));
112
113}
114
115void clang::InitializeAnalyzerOptions(AnalyzerOptions &Opts) {
116 using namespace analyzeroptions;
117 Opts.AnalysisList = AnalysisList;
118 Opts.AnalysisStoreOpt = AnalysisStoreOpt;
119 Opts.AnalysisConstraintsOpt = AnalysisConstraintsOpt;
120 Opts.AnalysisDiagOpt = AnalysisDiagOpt;
121 Opts.VisualizeEGDot = VisualizeEGDot;
122 Opts.VisualizeEGUbi = VisualizeEGUbi;
123 Opts.AnalyzeAll = AnalyzeAll;
124 Opts.AnalyzerDisplayProgress = AnalyzerDisplayProgress;
125 Opts.PurgeDead = PurgeDead;
126 Opts.EagerlyAssume = EagerlyAssume;
127 Opts.AnalyzeSpecificFunction = AnalyzeSpecificFunction;
128 Opts.TrimGraph = TrimGraph;
129}
130
131
132//===----------------------------------------------------------------------===//
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000133// Code Generation Options
134//===----------------------------------------------------------------------===//
135
136namespace codegenoptions {
137
138static llvm::cl::opt<bool>
139DisableLLVMOptimizations("disable-llvm-optzns",
140 llvm::cl::desc("Don't run LLVM optimization passes"));
141
142static llvm::cl::opt<bool>
143DisableRedZone("disable-red-zone",
144 llvm::cl::desc("Do not emit code that uses the red zone."),
145 llvm::cl::init(false));
146
147static llvm::cl::opt<bool>
148GenerateDebugInfo("g",
149 llvm::cl::desc("Generate source level debug information"));
150
151static llvm::cl::opt<bool>
152NoCommon("fno-common",
153 llvm::cl::desc("Compile common globals like normal definitions"),
154 llvm::cl::ValueDisallowed);
155
156static llvm::cl::opt<bool>
157NoImplicitFloat("no-implicit-float",
158 llvm::cl::desc("Don't generate implicit floating point instructions (x86-only)"),
159 llvm::cl::init(false));
160
161static llvm::cl::opt<bool>
162NoMergeConstants("fno-merge-all-constants",
163 llvm::cl::desc("Disallow merging of constants."));
164
165// It might be nice to add bounds to the CommandLine library directly.
166struct OptLevelParser : public llvm::cl::parser<unsigned> {
167 bool parse(llvm::cl::Option &O, llvm::StringRef ArgName,
168 llvm::StringRef Arg, unsigned &Val) {
169 if (llvm::cl::parser<unsigned>::parse(O, ArgName, Arg, Val))
170 return true;
171 if (Val > 3)
172 return O.error("'" + Arg + "' invalid optimization level!");
173 return false;
174 }
175};
176static llvm::cl::opt<unsigned, false, OptLevelParser>
177OptLevel("O", llvm::cl::Prefix,
178 llvm::cl::desc("Optimization level"),
179 llvm::cl::init(0));
180
181static llvm::cl::opt<bool>
182OptSize("Os", llvm::cl::desc("Optimize for size"));
183
184static llvm::cl::opt<std::string>
185TargetCPU("mcpu",
186 llvm::cl::desc("Target a specific cpu type (-mcpu=help for details)"));
187
188static llvm::cl::list<std::string>
189TargetFeatures("target-feature", llvm::cl::desc("Target specific attributes"));
190
191}
192
193//===----------------------------------------------------------------------===//
Daniel Dunbar0e0bae82009-11-11 21:43:12 +0000194// Dependency Output Options
195//===----------------------------------------------------------------------===//
196
197namespace dependencyoutputoptions {
198
199static llvm::cl::opt<std::string>
200DependencyFile("dependency-file",
201 llvm::cl::desc("Filename (or -) to write dependency output to"));
202
203static llvm::cl::opt<bool>
204DependenciesIncludeSystemHeaders("sys-header-deps",
205 llvm::cl::desc("Include system headers in dependency output"));
206
207static llvm::cl::list<std::string>
208DependencyTargets("MT",
209 llvm::cl::desc("Specify target for dependency"));
210
211static llvm::cl::opt<bool>
212PhonyDependencyTarget("MP",
213 llvm::cl::desc("Create phony target for each dependency "
214 "(other than main file)"));
215
216}
217
218//===----------------------------------------------------------------------===//
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000219// Diagnostic Options
220//===----------------------------------------------------------------------===//
221
222namespace diagnosticoptions {
223
Daniel Dunbar11e729d2009-11-12 07:28:21 +0000224static llvm::cl::opt<std::string>
225DumpBuildInformation("dump-build-information",
226 llvm::cl::value_desc("filename"),
227 llvm::cl::desc("output a dump of some build information to a file"));
228
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000229static llvm::cl::opt<bool>
230NoShowColumn("fno-show-column",
231 llvm::cl::desc("Do not include column number on diagnostics"));
232
233static llvm::cl::opt<bool>
234NoShowLocation("fno-show-source-location",
235 llvm::cl::desc("Do not include source location information with"
236 " diagnostics"));
237
238static llvm::cl::opt<bool>
239NoCaretDiagnostics("fno-caret-diagnostics",
240 llvm::cl::desc("Do not include source line and caret with"
241 " diagnostics"));
242
243static llvm::cl::opt<bool>
244NoDiagnosticsFixIt("fno-diagnostics-fixit-info",
245 llvm::cl::desc("Do not include fixit information in"
246 " diagnostics"));
247
Daniel Dunbar69079432009-11-12 07:28:44 +0000248static llvm::cl::opt<bool> OptNoWarnings("w");
249
250static llvm::cl::opt<bool> OptPedantic("pedantic");
251
252static llvm::cl::opt<bool> OptPedanticErrors("pedantic-errors");
253
254// This gets all -W options, including -Werror, -W[no-]system-headers, etc. The
255// driver has stripped off -Wa,foo etc. The driver has also translated -W to
256// -Wextra, so we don't need to worry about it.
257static llvm::cl::list<std::string>
258OptWarnings("W", llvm::cl::Prefix, llvm::cl::ValueOptional);
259
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000260static llvm::cl::opt<bool>
261PrintSourceRangeInfo("fdiagnostics-print-source-range-info",
262 llvm::cl::desc("Print source range spans in numeric form"));
263
264static llvm::cl::opt<bool>
265PrintDiagnosticOption("fdiagnostics-show-option",
266 llvm::cl::desc("Print diagnostic name with mappable diagnostics"));
267
268static llvm::cl::opt<unsigned>
269MessageLength("fmessage-length",
270 llvm::cl::desc("Format message diagnostics so that they fit "
271 "within N columns or fewer, when possible."),
272 llvm::cl::value_desc("N"));
273
274static llvm::cl::opt<bool>
275PrintColorDiagnostic("fcolor-diagnostics",
276 llvm::cl::desc("Use colors in diagnostics"));
277
Daniel Dunbar69079432009-11-12 07:28:44 +0000278static llvm::cl::opt<bool>
279SilenceRewriteMacroWarning("Wno-rewrite-macros", llvm::cl::init(false),
280 llvm::cl::desc("Silence ObjC rewriting warnings"));
281
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000282}
283
284//===----------------------------------------------------------------------===//
Daniel Dunbar56749082009-11-11 07:26:12 +0000285// Language Options
286//===----------------------------------------------------------------------===//
287
288namespace langoptions {
289
290static llvm::cl::opt<bool>
291AllowBuiltins("fbuiltin", llvm::cl::init(true),
292 llvm::cl::desc("Disable implicit builtin knowledge of functions"));
293
294static llvm::cl::opt<bool>
295AltiVec("faltivec", llvm::cl::desc("Enable AltiVec vector initializer syntax"),
296 llvm::cl::init(false));
297
298static llvm::cl::opt<bool>
299AccessControl("faccess-control",
300 llvm::cl::desc("Enable C++ access control"));
301
302static llvm::cl::opt<bool>
303CharIsSigned("fsigned-char",
304 llvm::cl::desc("Force char to be a signed/unsigned type"));
305
306static llvm::cl::opt<bool>
307DollarsInIdents("fdollars-in-identifiers",
308 llvm::cl::desc("Allow '$' in identifiers"));
309
310static llvm::cl::opt<bool>
311EmitAllDecls("femit-all-decls",
312 llvm::cl::desc("Emit all declarations, even if unused"));
313
314static llvm::cl::opt<bool>
315EnableBlocks("fblocks", llvm::cl::desc("enable the 'blocks' language feature"));
316
317static llvm::cl::opt<bool>
318EnableHeinousExtensions("fheinous-gnu-extensions",
319 llvm::cl::desc("enable GNU extensions that you really really shouldn't use"),
320 llvm::cl::ValueDisallowed, llvm::cl::Hidden);
321
322static llvm::cl::opt<bool>
323Exceptions("fexceptions",
324 llvm::cl::desc("Enable support for exception handling"));
325
326static llvm::cl::opt<bool>
327Freestanding("ffreestanding",
328 llvm::cl::desc("Assert that the compilation takes place in a "
329 "freestanding environment"));
330
331static llvm::cl::opt<bool>
332GNURuntime("fgnu-runtime",
333 llvm::cl::desc("Generate output compatible with the standard GNU "
334 "Objective-C runtime"));
335
336/// LangStds - Language standards we support.
337enum LangStds {
338 lang_unspecified,
339 lang_c89, lang_c94, lang_c99,
340 lang_gnu89, lang_gnu99,
341 lang_cxx98, lang_gnucxx98,
342 lang_cxx0x, lang_gnucxx0x
343};
344static llvm::cl::opt<LangStds>
345LangStd("std", llvm::cl::desc("Language standard to compile for"),
346 llvm::cl::init(lang_unspecified),
347 llvm::cl::values(clEnumValN(lang_c89, "c89", "ISO C 1990"),
348 clEnumValN(lang_c89, "c90", "ISO C 1990"),
349 clEnumValN(lang_c89, "iso9899:1990", "ISO C 1990"),
350 clEnumValN(lang_c94, "iso9899:199409",
351 "ISO C 1990 with amendment 1"),
352 clEnumValN(lang_c99, "c99", "ISO C 1999"),
353 clEnumValN(lang_c99, "c9x", "ISO C 1999"),
354 clEnumValN(lang_c99, "iso9899:1999", "ISO C 1999"),
355 clEnumValN(lang_c99, "iso9899:199x", "ISO C 1999"),
356 clEnumValN(lang_gnu89, "gnu89",
357 "ISO C 1990 with GNU extensions"),
358 clEnumValN(lang_gnu99, "gnu99",
359 "ISO C 1999 with GNU extensions (default for C)"),
360 clEnumValN(lang_gnu99, "gnu9x",
361 "ISO C 1999 with GNU extensions"),
362 clEnumValN(lang_cxx98, "c++98",
363 "ISO C++ 1998 with amendments"),
364 clEnumValN(lang_gnucxx98, "gnu++98",
365 "ISO C++ 1998 with amendments and GNU "
366 "extensions (default for C++)"),
367 clEnumValN(lang_cxx0x, "c++0x",
368 "Upcoming ISO C++ 200x with amendments"),
369 clEnumValN(lang_gnucxx0x, "gnu++0x",
370 "Upcoming ISO C++ 200x with amendments and GNU "
371 "extensions"),
372 clEnumValEnd));
373
374static llvm::cl::opt<bool>
375MSExtensions("fms-extensions",
376 llvm::cl::desc("Accept some non-standard constructs used in "
377 "Microsoft header files "));
378
379static llvm::cl::opt<std::string>
380MainFileName("main-file-name",
381 llvm::cl::desc("Main file name to use for debug info"));
382
383static llvm::cl::opt<bool>
384MathErrno("fmath-errno", llvm::cl::init(true),
385 llvm::cl::desc("Require math functions to respect errno"));
386
387static llvm::cl::opt<bool>
388NeXTRuntime("fnext-runtime",
389 llvm::cl::desc("Generate output compatible with the NeXT "
390 "runtime"));
391
392static llvm::cl::opt<bool>
393NoElideConstructors("fno-elide-constructors",
394 llvm::cl::desc("Disable C++ copy constructor elision"));
395
396static llvm::cl::opt<bool>
397NoLaxVectorConversions("fno-lax-vector-conversions",
398 llvm::cl::desc("Disallow implicit conversions between "
399 "vectors with a different number of "
400 "elements or different element types"));
401
402
403static llvm::cl::opt<bool>
404NoOperatorNames("fno-operator-names",
405 llvm::cl::desc("Do not treat C++ operator name keywords as "
406 "synonyms for operators"));
407
408static llvm::cl::opt<std::string>
409ObjCConstantStringClass("fconstant-string-class",
410 llvm::cl::value_desc("class name"),
411 llvm::cl::desc("Specify the class to use for constant "
412 "Objective-C string objects."));
413
414static llvm::cl::opt<bool>
415ObjCEnableGC("fobjc-gc",
416 llvm::cl::desc("Enable Objective-C garbage collection"));
417
418static llvm::cl::opt<bool>
419ObjCExclusiveGC("fobjc-gc-only",
420 llvm::cl::desc("Use GC exclusively for Objective-C related "
421 "memory management"));
422
423static llvm::cl::opt<bool>
424ObjCEnableGCBitmapPrint("print-ivar-layout",
425 llvm::cl::desc("Enable Objective-C Ivar layout bitmap print trace"));
426
427static llvm::cl::opt<bool>
428ObjCNonFragileABI("fobjc-nonfragile-abi",
429 llvm::cl::desc("enable objective-c's nonfragile abi"));
430
431static llvm::cl::opt<bool>
432OverflowChecking("ftrapv",
433 llvm::cl::desc("Trap on integer overflow"),
434 llvm::cl::init(false));
435
436static llvm::cl::opt<unsigned>
437PICLevel("pic-level", llvm::cl::desc("Value for __PIC__"));
438
439static llvm::cl::opt<bool>
440PThread("pthread", llvm::cl::desc("Support POSIX threads in generated code"),
441 llvm::cl::init(false));
442
443static llvm::cl::opt<bool>
444PascalStrings("fpascal-strings",
445 llvm::cl::desc("Recognize and construct Pascal-style "
446 "string literals"));
447
Daniel Dunbar56749082009-11-11 07:26:12 +0000448static llvm::cl::opt<bool>
449Rtti("frtti", llvm::cl::init(true),
450 llvm::cl::desc("Enable generation of rtti information"));
451
452static llvm::cl::opt<bool>
453ShortWChar("fshort-wchar",
454 llvm::cl::desc("Force wchar_t to be a short unsigned int"));
455
456static llvm::cl::opt<bool>
457StaticDefine("static-define", llvm::cl::desc("Should __STATIC__ be defined"));
458
459static llvm::cl::opt<int>
460StackProtector("stack-protector",
461 llvm::cl::desc("Enable stack protectors"),
462 llvm::cl::init(-1));
463
464static llvm::cl::opt<LangOptions::VisibilityMode>
465SymbolVisibility("fvisibility",
466 llvm::cl::desc("Set the default symbol visibility:"),
467 llvm::cl::init(LangOptions::Default),
468 llvm::cl::values(clEnumValN(LangOptions::Default, "default",
469 "Use default symbol visibility"),
470 clEnumValN(LangOptions::Hidden, "hidden",
471 "Use hidden symbol visibility"),
472 clEnumValN(LangOptions::Protected,"protected",
473 "Use protected symbol visibility"),
474 clEnumValEnd));
475
476static llvm::cl::opt<unsigned>
477TemplateDepth("ftemplate-depth", llvm::cl::init(99),
478 llvm::cl::desc("Maximum depth of recursive template "
479 "instantiation"));
480
481static llvm::cl::opt<bool>
482Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences"));
483
484static llvm::cl::opt<bool>
485WritableStrings("fwritable-strings",
486 llvm::cl::desc("Store string literals as writable data"));
487
488}
489
490//===----------------------------------------------------------------------===//
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000491// General Preprocessor Options
492//===----------------------------------------------------------------------===//
493
494namespace preprocessoroptions {
495
496static llvm::cl::list<std::string>
497D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
498 llvm::cl::desc("Predefine the specified macro"));
499
500static llvm::cl::list<std::string>
501ImplicitIncludes("include", llvm::cl::value_desc("file"),
502 llvm::cl::desc("Include file before parsing"));
503static llvm::cl::list<std::string>
504ImplicitMacroIncludes("imacros", llvm::cl::value_desc("file"),
505 llvm::cl::desc("Include macros from file before parsing"));
506
507static llvm::cl::opt<std::string>
508ImplicitIncludePCH("include-pch", llvm::cl::value_desc("file"),
509 llvm::cl::desc("Include precompiled header file"));
510
511static llvm::cl::opt<std::string>
512ImplicitIncludePTH("include-pth", llvm::cl::value_desc("file"),
513 llvm::cl::desc("Include file before parsing"));
514
Daniel Dunbarb3cb98e2009-11-12 02:53:59 +0000515static llvm::cl::opt<std::string>
516TokenCache("token-cache", llvm::cl::value_desc("path"),
517 llvm::cl::desc("Use specified token cache file"));
518
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000519static llvm::cl::list<std::string>
520U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
521 llvm::cl::desc("Undefine the specified macro"));
522
523static llvm::cl::opt<bool>
524UndefMacros("undef", llvm::cl::value_desc("macro"),
525 llvm::cl::desc("undef all system defines"));
526
527}
528
529//===----------------------------------------------------------------------===//
Daniel Dunbarf7973292009-11-11 08:13:32 +0000530// Header Search Options
531//===----------------------------------------------------------------------===//
532
533namespace headersearchoptions {
534
535static llvm::cl::opt<bool>
536nostdinc("nostdinc", llvm::cl::desc("Disable standard #include directories"));
537
538static llvm::cl::opt<bool>
539nobuiltininc("nobuiltininc",
540 llvm::cl::desc("Disable builtin #include directories"));
541
542// Various command line options. These four add directories to each chain.
543static llvm::cl::list<std::string>
544F_dirs("F", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
545 llvm::cl::desc("Add directory to framework include search path"));
546
547static llvm::cl::list<std::string>
548I_dirs("I", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
549 llvm::cl::desc("Add directory to include search path"));
550
551static llvm::cl::list<std::string>
552idirafter_dirs("idirafter", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
553 llvm::cl::desc("Add directory to AFTER include search path"));
554
555static llvm::cl::list<std::string>
556iquote_dirs("iquote", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
557 llvm::cl::desc("Add directory to QUOTE include search path"));
558
559static llvm::cl::list<std::string>
560isystem_dirs("isystem", llvm::cl::value_desc("directory"), llvm::cl::Prefix,
561 llvm::cl::desc("Add directory to SYSTEM include search path"));
562
563// These handle -iprefix/-iwithprefix/-iwithprefixbefore.
564static llvm::cl::list<std::string>
565iprefix_vals("iprefix", llvm::cl::value_desc("prefix"), llvm::cl::Prefix,
566 llvm::cl::desc("Set the -iwithprefix/-iwithprefixbefore prefix"));
567static llvm::cl::list<std::string>
568iwithprefix_vals("iwithprefix", llvm::cl::value_desc("dir"), llvm::cl::Prefix,
569 llvm::cl::desc("Set directory to SYSTEM include search path with prefix"));
570static llvm::cl::list<std::string>
571iwithprefixbefore_vals("iwithprefixbefore", llvm::cl::value_desc("dir"),
572 llvm::cl::Prefix,
573 llvm::cl::desc("Set directory to include search path with prefix"));
574
575static llvm::cl::opt<std::string>
576isysroot("isysroot", llvm::cl::value_desc("dir"), llvm::cl::init("/"),
577 llvm::cl::desc("Set the system root directory (usually /)"));
578
579}
580
581//===----------------------------------------------------------------------===//
Daniel Dunbar29cf7462009-11-11 10:07:44 +0000582// Preprocessed Output Options
583//===----------------------------------------------------------------------===//
584
585namespace preprocessoroutputoptions {
586
587static llvm::cl::opt<bool>
588DisableLineMarkers("P", llvm::cl::desc("Disable linemarker output in -E mode"));
589
590static llvm::cl::opt<bool>
591EnableCommentOutput("C", llvm::cl::desc("Enable comment output in -E mode"));
592
593static llvm::cl::opt<bool>
594EnableMacroCommentOutput("CC",
595 llvm::cl::desc("Enable comment output in -E mode, "
596 "even from macro expansions"));
597static llvm::cl::opt<bool>
598DumpMacros("dM", llvm::cl::desc("Print macro definitions in -E mode instead of"
599 " normal output"));
600static llvm::cl::opt<bool>
601DumpDefines("dD", llvm::cl::desc("Print macro definitions in -E mode in "
602 "addition to normal output"));
603
604}
605
606//===----------------------------------------------------------------------===//
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000607// Option Object Construction
608//===----------------------------------------------------------------------===//
609
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000610void clang::InitializeCodeGenOptions(CodeGenOptions &Opts,
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000611 const TargetInfo &Target) {
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000612 using namespace codegenoptions;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000613
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000614 // Compute the target features, we need the target to handle this because
615 // features may have dependencies on one another.
616 llvm::StringMap<bool> Features;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000617 Target.getDefaultFeatures(TargetCPU, Features);
618
619 // Apply the user specified deltas.
620 for (llvm::cl::list<std::string>::iterator it = TargetFeatures.begin(),
621 ie = TargetFeatures.end(); it != ie; ++it) {
622 const char *Name = it->c_str();
623
624 // FIXME: Don't handle errors like this.
625 if (Name[0] != '-' && Name[0] != '+') {
626 fprintf(stderr, "error: clang-cc: invalid target feature string: %s\n",
627 Name);
628 exit(1);
629 }
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000630
631 // Apply the feature via the target.
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000632 if (!Target.setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) {
633 fprintf(stderr, "error: clang-cc: invalid target feature name: %s\n",
634 Name + 1);
635 exit(1);
636 }
637 }
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000638
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000639 // Add the features to the compile options.
640 //
641 // FIXME: If we are completely confident that we have the right set, we only
642 // need to pass the minuses.
643 for (llvm::StringMap<bool>::const_iterator it = Features.begin(),
644 ie = Features.end(); it != ie; ++it)
645 Opts.Features.push_back(std::string(it->second ? "+" : "-") + it->first());
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000646
647 // -Os implies -O2
648 Opts.OptimizationLevel = OptSize ? 2 : OptLevel;
649
650 // We must always run at least the always inlining pass.
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000651 Opts.Inlining = (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining
652 : CodeGenOptions::OnlyAlwaysInlining;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000653
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000654 Opts.CPU = TargetCPU;
655 Opts.DebugInfo = GenerateDebugInfo;
656 Opts.DisableLLVMOpts = DisableLLVMOptimizations;
657 Opts.DisableRedZone = DisableRedZone;
658 Opts.MergeAllConstants = !NoMergeConstants;
659 Opts.NoCommon = NoCommon;
660 Opts.NoImplicitFloat = NoImplicitFloat;
661 Opts.OptimizeSize = OptSize;
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000662 Opts.SimplifyLibCalls = 1;
Daniel Dunbar29a790b2009-11-11 09:38:56 +0000663 Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize);
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000664
665#ifdef NDEBUG
666 Opts.VerifyModule = 0;
667#endif
Daniel Dunbar0498cfc2009-11-10 19:51:53 +0000668}
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000669
Daniel Dunbar0e0bae82009-11-11 21:43:12 +0000670void clang::InitializeDependencyOutputOptions(DependencyOutputOptions &Opts) {
671 using namespace dependencyoutputoptions;
672
673 Opts.OutputFile = DependencyFile;
674 Opts.Targets.insert(Opts.Targets.begin(), DependencyTargets.begin(),
675 DependencyTargets.end());
676 Opts.IncludeSystemHeaders = DependenciesIncludeSystemHeaders;
677 Opts.UsePhonyTargets = PhonyDependencyTarget;
678}
679
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000680void clang::InitializeDiagnosticOptions(DiagnosticOptions &Opts) {
681 using namespace diagnosticoptions;
682
Daniel Dunbar69079432009-11-12 07:28:44 +0000683 Opts.Warnings.insert(Opts.Warnings.begin(),
684 OptWarnings.begin(), OptWarnings.end());
Daniel Dunbar11e729d2009-11-12 07:28:21 +0000685 Opts.DumpBuildInformation = DumpBuildInformation;
Daniel Dunbar69079432009-11-12 07:28:44 +0000686 Opts.IgnoreWarnings = OptNoWarnings;
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000687 Opts.MessageLength = MessageLength;
Daniel Dunbar69079432009-11-12 07:28:44 +0000688 Opts.NoRewriteMacros = SilenceRewriteMacroWarning;
689 Opts.Pedantic = OptPedantic;
690 Opts.PedanticErrors = OptPedanticErrors;
Daniel Dunbar11e729d2009-11-12 07:28:21 +0000691 Opts.ShowCarets = !NoCaretDiagnostics;
692 Opts.ShowColors = PrintColorDiagnostic;
693 Opts.ShowColumn = !NoShowColumn;
694 Opts.ShowFixits = !NoDiagnosticsFixIt;
695 Opts.ShowLocation = !NoShowLocation;
696 Opts.ShowOptionNames = PrintDiagnosticOption;
697 Opts.ShowSourceRanges = PrintSourceRangeInfo;
Daniel Dunbar0db4b762009-11-11 08:13:40 +0000698}
699
Daniel Dunbarf7973292009-11-11 08:13:32 +0000700void clang::InitializeHeaderSearchOptions(HeaderSearchOptions &Opts,
701 llvm::StringRef BuiltinIncludePath,
702 bool Verbose,
703 const LangOptions &Lang) {
704 using namespace headersearchoptions;
705
706 Opts.Sysroot = isysroot;
707 Opts.Verbose = Verbose;
708
709 // Handle -I... and -F... options, walking the lists in parallel.
710 unsigned Iidx = 0, Fidx = 0;
711 while (Iidx < I_dirs.size() && Fidx < F_dirs.size()) {
712 if (I_dirs.getPosition(Iidx) < F_dirs.getPosition(Fidx)) {
713 Opts.AddPath(I_dirs[Iidx], frontend::Angled, false, true, false);
714 ++Iidx;
715 } else {
716 Opts.AddPath(F_dirs[Fidx], frontend::Angled, false, true, true);
717 ++Fidx;
718 }
719 }
720
721 // Consume what's left from whatever list was longer.
722 for (; Iidx != I_dirs.size(); ++Iidx)
723 Opts.AddPath(I_dirs[Iidx], frontend::Angled, false, true, false);
724 for (; Fidx != F_dirs.size(); ++Fidx)
725 Opts.AddPath(F_dirs[Fidx], frontend::Angled, false, true, true);
726
727 // Handle -idirafter... options.
728 for (unsigned i = 0, e = idirafter_dirs.size(); i != e; ++i)
729 Opts.AddPath(idirafter_dirs[i], frontend::After,
730 false, true, false);
731
732 // Handle -iquote... options.
733 for (unsigned i = 0, e = iquote_dirs.size(); i != e; ++i)
734 Opts.AddPath(iquote_dirs[i], frontend::Quoted, false, true, false);
735
736 // Handle -isystem... options.
737 for (unsigned i = 0, e = isystem_dirs.size(); i != e; ++i)
738 Opts.AddPath(isystem_dirs[i], frontend::System, false, true, false);
739
740 // Walk the -iprefix/-iwithprefix/-iwithprefixbefore argument lists in
741 // parallel, processing the values in order of occurance to get the right
742 // prefixes.
743 {
744 std::string Prefix = ""; // FIXME: this isn't the correct default prefix.
745 unsigned iprefix_idx = 0;
746 unsigned iwithprefix_idx = 0;
747 unsigned iwithprefixbefore_idx = 0;
748 bool iprefix_done = iprefix_vals.empty();
749 bool iwithprefix_done = iwithprefix_vals.empty();
750 bool iwithprefixbefore_done = iwithprefixbefore_vals.empty();
751 while (!iprefix_done || !iwithprefix_done || !iwithprefixbefore_done) {
752 if (!iprefix_done &&
753 (iwithprefix_done ||
754 iprefix_vals.getPosition(iprefix_idx) <
755 iwithprefix_vals.getPosition(iwithprefix_idx)) &&
756 (iwithprefixbefore_done ||
757 iprefix_vals.getPosition(iprefix_idx) <
758 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
759 Prefix = iprefix_vals[iprefix_idx];
760 ++iprefix_idx;
761 iprefix_done = iprefix_idx == iprefix_vals.size();
762 } else if (!iwithprefix_done &&
763 (iwithprefixbefore_done ||
764 iwithprefix_vals.getPosition(iwithprefix_idx) <
765 iwithprefixbefore_vals.getPosition(iwithprefixbefore_idx))) {
766 Opts.AddPath(Prefix+iwithprefix_vals[iwithprefix_idx],
767 frontend::System, false, false, false);
768 ++iwithprefix_idx;
769 iwithprefix_done = iwithprefix_idx == iwithprefix_vals.size();
770 } else {
771 Opts.AddPath(Prefix+iwithprefixbefore_vals[iwithprefixbefore_idx],
772 frontend::Angled, false, false, false);
773 ++iwithprefixbefore_idx;
774 iwithprefixbefore_done =
775 iwithprefixbefore_idx == iwithprefixbefore_vals.size();
776 }
777 }
778 }
779
780 // Add CPATH environment paths.
781 if (const char *Env = getenv("CPATH"))
782 Opts.EnvIncPath = Env;
783
784 // Add language specific environment paths.
785 if (Lang.CPlusPlus && Lang.ObjC1) {
786 if (const char *Env = getenv("OBJCPLUS_INCLUDE_PATH"))
787 Opts.LangEnvIncPath = Env;
788 } else if (Lang.CPlusPlus) {
789 if (const char *Env = getenv("CPLUS_INCLUDE_PATH"))
790 Opts.LangEnvIncPath = Env;
791 } else if (Lang.ObjC1) {
792 if (const char *Env = getenv("OBJC_INCLUDE_PATH"))
793 Opts.LangEnvIncPath = Env;
794 } else {
795 if (const char *Env = getenv("C_INCLUDE_PATH"))
796 Opts.LangEnvIncPath = Env;
797 }
798
799 if (!nobuiltininc)
800 Opts.BuiltinIncludePath = BuiltinIncludePath;
801
802 Opts.UseStandardIncludes = !nostdinc;
803}
804
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000805void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) {
806 using namespace preprocessoroptions;
807
808 Opts.setImplicitPCHInclude(ImplicitIncludePCH);
809 Opts.setImplicitPTHInclude(ImplicitIncludePTH);
810
Daniel Dunbarb3cb98e2009-11-12 02:53:59 +0000811 // Select the token cache file, we don't support more than one currently so we
812 // can't have both an implicit-pth and a token cache file.
813 if (TokenCache.getPosition() && ImplicitIncludePTH.getPosition()) {
814 // FIXME: Don't fail like this.
815 fprintf(stderr, "error: cannot use both -token-cache and -include-pth "
816 "options\n");
817 exit(1);
818 }
819 if (TokenCache.getPosition())
820 Opts.setTokenCache(TokenCache);
821 else
822 Opts.setTokenCache(ImplicitIncludePTH);
823
Daniel Dunbarb52d2432009-11-11 06:10:03 +0000824 // Use predefines?
825 Opts.setUsePredefines(!UndefMacros);
826
827 // Add macros from the command line.
828 unsigned d = 0, D = D_macros.size();
829 unsigned u = 0, U = U_macros.size();
830 while (d < D || u < U) {
831 if (u == U || (d < D && D_macros.getPosition(d) < U_macros.getPosition(u)))
832 Opts.addMacroDef(D_macros[d++]);
833 else
834 Opts.addMacroUndef(U_macros[u++]);
835 }
836
837 // If -imacros are specified, include them now. These are processed before
838 // any -include directives.
839 for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i)
840 Opts.addMacroInclude(ImplicitMacroIncludes[i]);
841
842 // Add the ordered list of -includes, sorting in the implicit include options
843 // at the appropriate location.
844 llvm::SmallVector<std::pair<unsigned, std::string*>, 8> OrderedPaths;
845 std::string OriginalFile;
846
847 if (!ImplicitIncludePTH.empty())
848 OrderedPaths.push_back(std::make_pair(ImplicitIncludePTH.getPosition(),
849 &ImplicitIncludePTH));
850 if (!ImplicitIncludePCH.empty()) {
851 OriginalFile = PCHReader::getOriginalSourceFile(ImplicitIncludePCH);
852 // FIXME: Don't fail like this.
853 if (OriginalFile.empty())
854 exit(1);
855 OrderedPaths.push_back(std::make_pair(ImplicitIncludePCH.getPosition(),
856 &OriginalFile));
857 }
858 for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i)
859 OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i),
860 &ImplicitIncludes[i]));
861 llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end());
862
863 for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i)
864 Opts.addInclude(*OrderedPaths[i].second);
865}
Daniel Dunbar56749082009-11-11 07:26:12 +0000866
867void clang::InitializeLangOptions(LangOptions &Options, LangKind LK,
868 TargetInfo &Target,
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000869 const CodeGenOptions &CodeGenOpts) {
Daniel Dunbar56749082009-11-11 07:26:12 +0000870 using namespace langoptions;
871
872 bool NoPreprocess = false;
873
874 switch (LK) {
875 default: assert(0 && "Unknown language kind!");
876 case langkind_asm_cpp:
877 Options.AsmPreprocessor = 1;
878 // FALLTHROUGH
879 case langkind_c_cpp:
880 NoPreprocess = true;
881 // FALLTHROUGH
882 case langkind_c:
883 // Do nothing.
884 break;
885 case langkind_cxx_cpp:
886 NoPreprocess = true;
887 // FALLTHROUGH
888 case langkind_cxx:
889 Options.CPlusPlus = 1;
890 break;
891 case langkind_objc_cpp:
892 NoPreprocess = true;
893 // FALLTHROUGH
894 case langkind_objc:
895 Options.ObjC1 = Options.ObjC2 = 1;
896 break;
897 case langkind_objcxx_cpp:
898 NoPreprocess = true;
899 // FALLTHROUGH
900 case langkind_objcxx:
901 Options.ObjC1 = Options.ObjC2 = 1;
902 Options.CPlusPlus = 1;
903 break;
904 case langkind_ocl:
905 Options.OpenCL = 1;
906 Options.AltiVec = 1;
907 Options.CXXOperatorNames = 1;
908 Options.LaxVectorConversions = 1;
909 break;
910 }
911
912 if (ObjCExclusiveGC)
913 Options.setGCMode(LangOptions::GCOnly);
914 else if (ObjCEnableGC)
915 Options.setGCMode(LangOptions::HybridGC);
916
917 if (ObjCEnableGCBitmapPrint)
918 Options.ObjCGCBitmapPrint = 1;
919
920 if (AltiVec)
921 Options.AltiVec = 1;
922
923 if (PThread)
924 Options.POSIXThreads = 1;
925
926 Options.setVisibilityMode(SymbolVisibility);
927 Options.OverflowChecking = OverflowChecking;
928
929
930 // Allow the target to set the default the language options as it sees fit.
931 Target.getDefaultLangOptions(Options);
932
933 // Pass the map of target features to the target for validation and
934 // processing.
Chandler Carruth2811ccf2009-11-12 17:24:48 +0000935 Target.HandleTargetFeatures(CodeGenOpts.Features);
Daniel Dunbar56749082009-11-11 07:26:12 +0000936
937 if (LangStd == lang_unspecified) {
938 // Based on the base language, pick one.
939 switch (LK) {
940 case langkind_ast: assert(0 && "Invalid call for AST inputs");
941 case lang_unspecified: assert(0 && "Unknown base language");
942 case langkind_ocl:
943 LangStd = lang_c99;
944 break;
945 case langkind_c:
946 case langkind_asm_cpp:
947 case langkind_c_cpp:
948 case langkind_objc:
949 case langkind_objc_cpp:
950 LangStd = lang_gnu99;
951 break;
952 case langkind_cxx:
953 case langkind_cxx_cpp:
954 case langkind_objcxx:
955 case langkind_objcxx_cpp:
956 LangStd = lang_gnucxx98;
957 break;
958 }
959 }
960
961 switch (LangStd) {
962 default: assert(0 && "Unknown language standard!");
963
964 // Fall through from newer standards to older ones. This isn't really right.
965 // FIXME: Enable specifically the right features based on the language stds.
966 case lang_gnucxx0x:
967 case lang_cxx0x:
968 Options.CPlusPlus0x = 1;
969 // FALL THROUGH
970 case lang_gnucxx98:
971 case lang_cxx98:
972 Options.CPlusPlus = 1;
973 Options.CXXOperatorNames = !NoOperatorNames;
974 // FALL THROUGH.
975 case lang_gnu99:
976 case lang_c99:
977 Options.C99 = 1;
978 Options.HexFloats = 1;
979 // FALL THROUGH.
980 case lang_gnu89:
981 Options.BCPLComment = 1; // Only for C99/C++.
982 // FALL THROUGH.
983 case lang_c94:
984 Options.Digraphs = 1; // C94, C99, C++.
985 // FALL THROUGH.
986 case lang_c89:
987 break;
988 }
989
990 // GNUMode - Set if we're in gnu99, gnu89, gnucxx98, etc.
991 switch (LangStd) {
992 default: assert(0 && "Unknown language standard!");
993 case lang_gnucxx0x:
994 case lang_gnucxx98:
995 case lang_gnu99:
996 case lang_gnu89:
997 Options.GNUMode = 1;
998 break;
999 case lang_cxx0x:
1000 case lang_cxx98:
1001 case lang_c99:
1002 case lang_c94:
1003 case lang_c89:
1004 Options.GNUMode = 0;
1005 break;
1006 }
1007
1008 if (Options.CPlusPlus) {
1009 Options.C99 = 0;
1010 Options.HexFloats = 0;
1011 }
1012
1013 if (LangStd == lang_c89 || LangStd == lang_c94 || LangStd == lang_gnu89)
1014 Options.ImplicitInt = 1;
1015 else
1016 Options.ImplicitInt = 0;
1017
1018 // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
1019 // is specified, or -std is set to a conforming mode.
1020 Options.Trigraphs = !Options.GNUMode;
1021 if (Trigraphs.getPosition())
1022 Options.Trigraphs = Trigraphs; // Command line option wins if specified.
1023
1024 // If in a conformant language mode (e.g. -std=c99) Blocks defaults to off
1025 // even if they are normally on for the target. In GNU modes (e.g.
1026 // -std=gnu99) the default for blocks depends on the target settings.
1027 // However, blocks are not turned off when compiling Obj-C or Obj-C++ code.
1028 if (!Options.ObjC1 && !Options.GNUMode)
1029 Options.Blocks = 0;
1030
1031 // Default to not accepting '$' in identifiers when preprocessing assembler,
1032 // but do accept when preprocessing C. FIXME: these defaults are right for
1033 // darwin, are they right everywhere?
1034 Options.DollarIdents = LK != langkind_asm_cpp;
1035 if (DollarsInIdents.getPosition()) // Explicit setting overrides default.
1036 Options.DollarIdents = DollarsInIdents;
1037
1038 if (PascalStrings.getPosition())
1039 Options.PascalStrings = PascalStrings;
1040 if (MSExtensions.getPosition())
1041 Options.Microsoft = MSExtensions;
1042 Options.WritableStrings = WritableStrings;
1043 if (NoLaxVectorConversions.getPosition())
1044 Options.LaxVectorConversions = 0;
1045 Options.Exceptions = Exceptions;
1046 Options.Rtti = Rtti;
1047 if (EnableBlocks.getPosition())
1048 Options.Blocks = EnableBlocks;
1049 if (CharIsSigned.getPosition())
1050 Options.CharIsSigned = CharIsSigned;
1051 if (ShortWChar.getPosition())
1052 Options.ShortWChar = ShortWChar;
1053
1054 if (!AllowBuiltins)
1055 Options.NoBuiltin = 1;
1056 if (Freestanding)
1057 Options.Freestanding = Options.NoBuiltin = 1;
1058
1059 if (EnableHeinousExtensions)
1060 Options.HeinousExtensions = 1;
1061
1062 if (AccessControl)
1063 Options.AccessControl = 1;
1064
1065 Options.ElideConstructors = !NoElideConstructors;
1066
1067 // OpenCL and C++ both have bool, true, false keywords.
1068 Options.Bool = Options.OpenCL | Options.CPlusPlus;
1069
1070 Options.MathErrno = MathErrno;
1071
1072 Options.InstantiationDepth = TemplateDepth;
1073
1074 // Override the default runtime if the user requested it.
1075 if (NeXTRuntime)
1076 Options.NeXTRuntime = 1;
1077 else if (GNURuntime)
1078 Options.NeXTRuntime = 0;
1079
1080 if (!ObjCConstantStringClass.empty())
1081 Options.ObjCConstantStringClass = ObjCConstantStringClass.c_str();
1082
1083 if (ObjCNonFragileABI)
1084 Options.ObjCNonFragileABI = 1;
1085
1086 if (EmitAllDecls)
1087 Options.EmitAllDecls = 1;
1088
1089 // The __OPTIMIZE_SIZE__ define is tied to -Oz, which we don't support.
1090 Options.OptimizeSize = 0;
Chandler Carruth2811ccf2009-11-12 17:24:48 +00001091 Options.Optimize = !!CodeGenOpts.OptimizationLevel;
Daniel Dunbar56749082009-11-11 07:26:12 +00001092
1093 assert(PICLevel <= 2 && "Invalid value for -pic-level");
1094 Options.PICLevel = PICLevel;
1095
1096 Options.GNUInline = !Options.C99;
1097 // FIXME: This is affected by other options (-fno-inline).
1098
1099 // This is the __NO_INLINE__ define, which just depends on things like the
1100 // optimization level and -fno-inline, not actually whether the backend has
1101 // inlining enabled.
Chandler Carruth2811ccf2009-11-12 17:24:48 +00001102 Options.NoInline = !CodeGenOpts.OptimizationLevel;
Daniel Dunbar56749082009-11-11 07:26:12 +00001103
1104 Options.Static = StaticDefine;
1105
1106 switch (StackProtector) {
1107 default:
1108 assert(StackProtector <= 2 && "Invalid value for -stack-protector");
1109 case -1: break;
1110 case 0: Options.setStackProtectorMode(LangOptions::SSPOff); break;
1111 case 1: Options.setStackProtectorMode(LangOptions::SSPOn); break;
1112 case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break;
1113 }
1114
1115 if (MainFileName.getPosition())
1116 Options.setMainFileName(MainFileName.c_str());
1117
1118 Target.setForcedLangOptions(Options);
1119}
Daniel Dunbar29cf7462009-11-11 10:07:44 +00001120
1121void
1122clang::InitializePreprocessorOutputOptions(PreprocessorOutputOptions &Opts) {
1123 using namespace preprocessoroutputoptions;
1124
1125 Opts.ShowCPP = !DumpMacros;
1126 Opts.ShowMacros = DumpMacros || DumpDefines;
1127 Opts.ShowLineMarkers = !DisableLineMarkers;
1128 Opts.ShowComments = EnableCommentOutput;
1129 Opts.ShowMacroComments = EnableMacroCommentOutput;
1130}