blob: bd23b7ad47f69645752a8603db4a522dbde52f1b [file] [log] [blame]
Daniel Dunbarf89a32a2009-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"
15#include "clang/Frontend/CompileOptions.h"
Daniel Dunbar999215c2009-11-11 06:10:03 +000016#include "clang/Frontend/PCHReader.h"
17#include "clang/Frontend/PreprocessorOptions.h"
Daniel Dunbarf89a32a2009-11-10 19:51:53 +000018#include "clang/Basic/LangOptions.h"
19#include "clang/Basic/TargetInfo.h"
Daniel Dunbar999215c2009-11-11 06:10:03 +000020#include "llvm/ADT/STLExtras.h"
Daniel Dunbarf89a32a2009-11-10 19:51:53 +000021#include "llvm/ADT/StringMap.h"
22#include "llvm/Support/CommandLine.h"
Dan Gohmanad5ef3d2009-11-10 21:21:27 +000023#include <stdio.h>
Daniel Dunbarf89a32a2009-11-10 19:51:53 +000024
25using namespace clang;
26
27//===----------------------------------------------------------------------===//
28// Code Generation Options
29//===----------------------------------------------------------------------===//
30
31namespace codegenoptions {
32
33static llvm::cl::opt<bool>
34DisableLLVMOptimizations("disable-llvm-optzns",
35 llvm::cl::desc("Don't run LLVM optimization passes"));
36
37static llvm::cl::opt<bool>
38DisableRedZone("disable-red-zone",
39 llvm::cl::desc("Do not emit code that uses the red zone."),
40 llvm::cl::init(false));
41
42static llvm::cl::opt<bool>
43GenerateDebugInfo("g",
44 llvm::cl::desc("Generate source level debug information"));
45
46static llvm::cl::opt<bool>
47NoCommon("fno-common",
48 llvm::cl::desc("Compile common globals like normal definitions"),
49 llvm::cl::ValueDisallowed);
50
51static llvm::cl::opt<bool>
52NoImplicitFloat("no-implicit-float",
53 llvm::cl::desc("Don't generate implicit floating point instructions (x86-only)"),
54 llvm::cl::init(false));
55
56static llvm::cl::opt<bool>
57NoMergeConstants("fno-merge-all-constants",
58 llvm::cl::desc("Disallow merging of constants."));
59
60// It might be nice to add bounds to the CommandLine library directly.
61struct OptLevelParser : public llvm::cl::parser<unsigned> {
62 bool parse(llvm::cl::Option &O, llvm::StringRef ArgName,
63 llvm::StringRef Arg, unsigned &Val) {
64 if (llvm::cl::parser<unsigned>::parse(O, ArgName, Arg, Val))
65 return true;
66 if (Val > 3)
67 return O.error("'" + Arg + "' invalid optimization level!");
68 return false;
69 }
70};
71static llvm::cl::opt<unsigned, false, OptLevelParser>
72OptLevel("O", llvm::cl::Prefix,
73 llvm::cl::desc("Optimization level"),
74 llvm::cl::init(0));
75
76static llvm::cl::opt<bool>
77OptSize("Os", llvm::cl::desc("Optimize for size"));
78
79static llvm::cl::opt<std::string>
80TargetCPU("mcpu",
81 llvm::cl::desc("Target a specific cpu type (-mcpu=help for details)"));
82
83static llvm::cl::list<std::string>
84TargetFeatures("target-feature", llvm::cl::desc("Target specific attributes"));
85
86}
87
88//===----------------------------------------------------------------------===//
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +000089// Language Options
90//===----------------------------------------------------------------------===//
91
92namespace langoptions {
93
94static llvm::cl::opt<bool>
95AllowBuiltins("fbuiltin", llvm::cl::init(true),
96 llvm::cl::desc("Disable implicit builtin knowledge of functions"));
97
98static llvm::cl::opt<bool>
99AltiVec("faltivec", llvm::cl::desc("Enable AltiVec vector initializer syntax"),
100 llvm::cl::init(false));
101
102static llvm::cl::opt<bool>
103AccessControl("faccess-control",
104 llvm::cl::desc("Enable C++ access control"));
105
106static llvm::cl::opt<bool>
107CharIsSigned("fsigned-char",
108 llvm::cl::desc("Force char to be a signed/unsigned type"));
109
110static llvm::cl::opt<bool>
111DollarsInIdents("fdollars-in-identifiers",
112 llvm::cl::desc("Allow '$' in identifiers"));
113
114static llvm::cl::opt<bool>
115EmitAllDecls("femit-all-decls",
116 llvm::cl::desc("Emit all declarations, even if unused"));
117
118static llvm::cl::opt<bool>
119EnableBlocks("fblocks", llvm::cl::desc("enable the 'blocks' language feature"));
120
121static llvm::cl::opt<bool>
122EnableHeinousExtensions("fheinous-gnu-extensions",
123 llvm::cl::desc("enable GNU extensions that you really really shouldn't use"),
124 llvm::cl::ValueDisallowed, llvm::cl::Hidden);
125
126static llvm::cl::opt<bool>
127Exceptions("fexceptions",
128 llvm::cl::desc("Enable support for exception handling"));
129
130static llvm::cl::opt<bool>
131Freestanding("ffreestanding",
132 llvm::cl::desc("Assert that the compilation takes place in a "
133 "freestanding environment"));
134
135static llvm::cl::opt<bool>
136GNURuntime("fgnu-runtime",
137 llvm::cl::desc("Generate output compatible with the standard GNU "
138 "Objective-C runtime"));
139
140/// LangStds - Language standards we support.
141enum LangStds {
142 lang_unspecified,
143 lang_c89, lang_c94, lang_c99,
144 lang_gnu89, lang_gnu99,
145 lang_cxx98, lang_gnucxx98,
146 lang_cxx0x, lang_gnucxx0x
147};
148static llvm::cl::opt<LangStds>
149LangStd("std", llvm::cl::desc("Language standard to compile for"),
150 llvm::cl::init(lang_unspecified),
151 llvm::cl::values(clEnumValN(lang_c89, "c89", "ISO C 1990"),
152 clEnumValN(lang_c89, "c90", "ISO C 1990"),
153 clEnumValN(lang_c89, "iso9899:1990", "ISO C 1990"),
154 clEnumValN(lang_c94, "iso9899:199409",
155 "ISO C 1990 with amendment 1"),
156 clEnumValN(lang_c99, "c99", "ISO C 1999"),
157 clEnumValN(lang_c99, "c9x", "ISO C 1999"),
158 clEnumValN(lang_c99, "iso9899:1999", "ISO C 1999"),
159 clEnumValN(lang_c99, "iso9899:199x", "ISO C 1999"),
160 clEnumValN(lang_gnu89, "gnu89",
161 "ISO C 1990 with GNU extensions"),
162 clEnumValN(lang_gnu99, "gnu99",
163 "ISO C 1999 with GNU extensions (default for C)"),
164 clEnumValN(lang_gnu99, "gnu9x",
165 "ISO C 1999 with GNU extensions"),
166 clEnumValN(lang_cxx98, "c++98",
167 "ISO C++ 1998 with amendments"),
168 clEnumValN(lang_gnucxx98, "gnu++98",
169 "ISO C++ 1998 with amendments and GNU "
170 "extensions (default for C++)"),
171 clEnumValN(lang_cxx0x, "c++0x",
172 "Upcoming ISO C++ 200x with amendments"),
173 clEnumValN(lang_gnucxx0x, "gnu++0x",
174 "Upcoming ISO C++ 200x with amendments and GNU "
175 "extensions"),
176 clEnumValEnd));
177
178static llvm::cl::opt<bool>
179MSExtensions("fms-extensions",
180 llvm::cl::desc("Accept some non-standard constructs used in "
181 "Microsoft header files "));
182
183static llvm::cl::opt<std::string>
184MainFileName("main-file-name",
185 llvm::cl::desc("Main file name to use for debug info"));
186
187static llvm::cl::opt<bool>
188MathErrno("fmath-errno", llvm::cl::init(true),
189 llvm::cl::desc("Require math functions to respect errno"));
190
191static llvm::cl::opt<bool>
192NeXTRuntime("fnext-runtime",
193 llvm::cl::desc("Generate output compatible with the NeXT "
194 "runtime"));
195
196static llvm::cl::opt<bool>
197NoElideConstructors("fno-elide-constructors",
198 llvm::cl::desc("Disable C++ copy constructor elision"));
199
200static llvm::cl::opt<bool>
201NoLaxVectorConversions("fno-lax-vector-conversions",
202 llvm::cl::desc("Disallow implicit conversions between "
203 "vectors with a different number of "
204 "elements or different element types"));
205
206
207static llvm::cl::opt<bool>
208NoOperatorNames("fno-operator-names",
209 llvm::cl::desc("Do not treat C++ operator name keywords as "
210 "synonyms for operators"));
211
212static llvm::cl::opt<std::string>
213ObjCConstantStringClass("fconstant-string-class",
214 llvm::cl::value_desc("class name"),
215 llvm::cl::desc("Specify the class to use for constant "
216 "Objective-C string objects."));
217
218static llvm::cl::opt<bool>
219ObjCEnableGC("fobjc-gc",
220 llvm::cl::desc("Enable Objective-C garbage collection"));
221
222static llvm::cl::opt<bool>
223ObjCExclusiveGC("fobjc-gc-only",
224 llvm::cl::desc("Use GC exclusively for Objective-C related "
225 "memory management"));
226
227static llvm::cl::opt<bool>
228ObjCEnableGCBitmapPrint("print-ivar-layout",
229 llvm::cl::desc("Enable Objective-C Ivar layout bitmap print trace"));
230
231static llvm::cl::opt<bool>
232ObjCNonFragileABI("fobjc-nonfragile-abi",
233 llvm::cl::desc("enable objective-c's nonfragile abi"));
234
235static llvm::cl::opt<bool>
236OverflowChecking("ftrapv",
237 llvm::cl::desc("Trap on integer overflow"),
238 llvm::cl::init(false));
239
240static llvm::cl::opt<unsigned>
241PICLevel("pic-level", llvm::cl::desc("Value for __PIC__"));
242
243static llvm::cl::opt<bool>
244PThread("pthread", llvm::cl::desc("Support POSIX threads in generated code"),
245 llvm::cl::init(false));
246
247static llvm::cl::opt<bool>
248PascalStrings("fpascal-strings",
249 llvm::cl::desc("Recognize and construct Pascal-style "
250 "string literals"));
251
252// FIXME: Move to CompileOptions.
253static llvm::cl::opt<bool>
254Rtti("frtti", llvm::cl::init(true),
255 llvm::cl::desc("Enable generation of rtti information"));
256
257static llvm::cl::opt<bool>
258ShortWChar("fshort-wchar",
259 llvm::cl::desc("Force wchar_t to be a short unsigned int"));
260
261static llvm::cl::opt<bool>
262StaticDefine("static-define", llvm::cl::desc("Should __STATIC__ be defined"));
263
264static llvm::cl::opt<int>
265StackProtector("stack-protector",
266 llvm::cl::desc("Enable stack protectors"),
267 llvm::cl::init(-1));
268
269static llvm::cl::opt<LangOptions::VisibilityMode>
270SymbolVisibility("fvisibility",
271 llvm::cl::desc("Set the default symbol visibility:"),
272 llvm::cl::init(LangOptions::Default),
273 llvm::cl::values(clEnumValN(LangOptions::Default, "default",
274 "Use default symbol visibility"),
275 clEnumValN(LangOptions::Hidden, "hidden",
276 "Use hidden symbol visibility"),
277 clEnumValN(LangOptions::Protected,"protected",
278 "Use protected symbol visibility"),
279 clEnumValEnd));
280
281static llvm::cl::opt<unsigned>
282TemplateDepth("ftemplate-depth", llvm::cl::init(99),
283 llvm::cl::desc("Maximum depth of recursive template "
284 "instantiation"));
285
286static llvm::cl::opt<bool>
287Trigraphs("trigraphs", llvm::cl::desc("Process trigraph sequences"));
288
289static llvm::cl::opt<bool>
290WritableStrings("fwritable-strings",
291 llvm::cl::desc("Store string literals as writable data"));
292
293}
294
295//===----------------------------------------------------------------------===//
Daniel Dunbar999215c2009-11-11 06:10:03 +0000296// General Preprocessor Options
297//===----------------------------------------------------------------------===//
298
299namespace preprocessoroptions {
300
301static llvm::cl::list<std::string>
302D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
303 llvm::cl::desc("Predefine the specified macro"));
304
305static llvm::cl::list<std::string>
306ImplicitIncludes("include", llvm::cl::value_desc("file"),
307 llvm::cl::desc("Include file before parsing"));
308static llvm::cl::list<std::string>
309ImplicitMacroIncludes("imacros", llvm::cl::value_desc("file"),
310 llvm::cl::desc("Include macros from file before parsing"));
311
312static llvm::cl::opt<std::string>
313ImplicitIncludePCH("include-pch", llvm::cl::value_desc("file"),
314 llvm::cl::desc("Include precompiled header file"));
315
316static llvm::cl::opt<std::string>
317ImplicitIncludePTH("include-pth", llvm::cl::value_desc("file"),
318 llvm::cl::desc("Include file before parsing"));
319
320static llvm::cl::list<std::string>
321U_macros("U", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
322 llvm::cl::desc("Undefine the specified macro"));
323
324static llvm::cl::opt<bool>
325UndefMacros("undef", llvm::cl::value_desc("macro"),
326 llvm::cl::desc("undef all system defines"));
327
328}
329
330//===----------------------------------------------------------------------===//
Daniel Dunbarf89a32a2009-11-10 19:51:53 +0000331// Option Object Construction
332//===----------------------------------------------------------------------===//
333
334/// ComputeTargetFeatures - Recompute the target feature list to only
335/// be the list of things that are enabled, based on the target cpu
336/// and feature list.
337void clang::ComputeFeatureMap(TargetInfo &Target,
338 llvm::StringMap<bool> &Features) {
339 using namespace codegenoptions;
340 assert(Features.empty() && "invalid map");
341
342 // Initialize the feature map based on the target.
343 Target.getDefaultFeatures(TargetCPU, Features);
344
345 // Apply the user specified deltas.
346 for (llvm::cl::list<std::string>::iterator it = TargetFeatures.begin(),
347 ie = TargetFeatures.end(); it != ie; ++it) {
348 const char *Name = it->c_str();
349
350 // FIXME: Don't handle errors like this.
351 if (Name[0] != '-' && Name[0] != '+') {
352 fprintf(stderr, "error: clang-cc: invalid target feature string: %s\n",
353 Name);
354 exit(1);
355 }
356 if (!Target.setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) {
357 fprintf(stderr, "error: clang-cc: invalid target feature name: %s\n",
358 Name + 1);
359 exit(1);
360 }
361 }
362}
363
364void clang::InitializeCompileOptions(CompileOptions &Opts,
365 const llvm::StringMap<bool> &Features) {
366 using namespace codegenoptions;
367 Opts.OptimizeSize = OptSize;
368 Opts.DebugInfo = GenerateDebugInfo;
369 Opts.DisableLLVMOpts = DisableLLVMOptimizations;
370
371 // -Os implies -O2
372 Opts.OptimizationLevel = OptSize ? 2 : OptLevel;
373
374 // We must always run at least the always inlining pass.
375 Opts.Inlining = (Opts.OptimizationLevel > 1) ? CompileOptions::NormalInlining
376 : CompileOptions::OnlyAlwaysInlining;
377
378 Opts.UnrollLoops = (Opts.OptimizationLevel > 1 && !OptSize);
379 Opts.SimplifyLibCalls = 1;
380
381#ifdef NDEBUG
382 Opts.VerifyModule = 0;
383#endif
384
385 Opts.CPU = TargetCPU;
386 Opts.Features.clear();
387 for (llvm::StringMap<bool>::const_iterator it = Features.begin(),
388 ie = Features.end(); it != ie; ++it) {
389 // FIXME: If we are completely confident that we have the right set, we only
390 // need to pass the minuses.
391 std::string Name(it->second ? "+" : "-");
392 Name += it->first();
393 Opts.Features.push_back(Name);
394 }
395
396 Opts.NoCommon = NoCommon;
397
398 Opts.DisableRedZone = DisableRedZone;
399 Opts.NoImplicitFloat = NoImplicitFloat;
400
401 Opts.MergeAllConstants = !NoMergeConstants;
402}
Daniel Dunbar999215c2009-11-11 06:10:03 +0000403
404void clang::InitializePreprocessorOptions(PreprocessorOptions &Opts) {
405 using namespace preprocessoroptions;
406
407 Opts.setImplicitPCHInclude(ImplicitIncludePCH);
408 Opts.setImplicitPTHInclude(ImplicitIncludePTH);
409
410 // Use predefines?
411 Opts.setUsePredefines(!UndefMacros);
412
413 // Add macros from the command line.
414 unsigned d = 0, D = D_macros.size();
415 unsigned u = 0, U = U_macros.size();
416 while (d < D || u < U) {
417 if (u == U || (d < D && D_macros.getPosition(d) < U_macros.getPosition(u)))
418 Opts.addMacroDef(D_macros[d++]);
419 else
420 Opts.addMacroUndef(U_macros[u++]);
421 }
422
423 // If -imacros are specified, include them now. These are processed before
424 // any -include directives.
425 for (unsigned i = 0, e = ImplicitMacroIncludes.size(); i != e; ++i)
426 Opts.addMacroInclude(ImplicitMacroIncludes[i]);
427
428 // Add the ordered list of -includes, sorting in the implicit include options
429 // at the appropriate location.
430 llvm::SmallVector<std::pair<unsigned, std::string*>, 8> OrderedPaths;
431 std::string OriginalFile;
432
433 if (!ImplicitIncludePTH.empty())
434 OrderedPaths.push_back(std::make_pair(ImplicitIncludePTH.getPosition(),
435 &ImplicitIncludePTH));
436 if (!ImplicitIncludePCH.empty()) {
437 OriginalFile = PCHReader::getOriginalSourceFile(ImplicitIncludePCH);
438 // FIXME: Don't fail like this.
439 if (OriginalFile.empty())
440 exit(1);
441 OrderedPaths.push_back(std::make_pair(ImplicitIncludePCH.getPosition(),
442 &OriginalFile));
443 }
444 for (unsigned i = 0, e = ImplicitIncludes.size(); i != e; ++i)
445 OrderedPaths.push_back(std::make_pair(ImplicitIncludes.getPosition(i),
446 &ImplicitIncludes[i]));
447 llvm::array_pod_sort(OrderedPaths.begin(), OrderedPaths.end());
448
449 for (unsigned i = 0, e = OrderedPaths.size(); i != e; ++i)
450 Opts.addInclude(*OrderedPaths[i].second);
451}
Daniel Dunbar84dfbfd2009-11-11 07:26:12 +0000452
453void clang::InitializeLangOptions(LangOptions &Options, LangKind LK,
454 TargetInfo &Target,
455 const CompileOptions &CompileOpts,
456 const llvm::StringMap<bool> &Features) {
457 using namespace langoptions;
458
459 bool NoPreprocess = false;
460
461 switch (LK) {
462 default: assert(0 && "Unknown language kind!");
463 case langkind_asm_cpp:
464 Options.AsmPreprocessor = 1;
465 // FALLTHROUGH
466 case langkind_c_cpp:
467 NoPreprocess = true;
468 // FALLTHROUGH
469 case langkind_c:
470 // Do nothing.
471 break;
472 case langkind_cxx_cpp:
473 NoPreprocess = true;
474 // FALLTHROUGH
475 case langkind_cxx:
476 Options.CPlusPlus = 1;
477 break;
478 case langkind_objc_cpp:
479 NoPreprocess = true;
480 // FALLTHROUGH
481 case langkind_objc:
482 Options.ObjC1 = Options.ObjC2 = 1;
483 break;
484 case langkind_objcxx_cpp:
485 NoPreprocess = true;
486 // FALLTHROUGH
487 case langkind_objcxx:
488 Options.ObjC1 = Options.ObjC2 = 1;
489 Options.CPlusPlus = 1;
490 break;
491 case langkind_ocl:
492 Options.OpenCL = 1;
493 Options.AltiVec = 1;
494 Options.CXXOperatorNames = 1;
495 Options.LaxVectorConversions = 1;
496 break;
497 }
498
499 if (ObjCExclusiveGC)
500 Options.setGCMode(LangOptions::GCOnly);
501 else if (ObjCEnableGC)
502 Options.setGCMode(LangOptions::HybridGC);
503
504 if (ObjCEnableGCBitmapPrint)
505 Options.ObjCGCBitmapPrint = 1;
506
507 if (AltiVec)
508 Options.AltiVec = 1;
509
510 if (PThread)
511 Options.POSIXThreads = 1;
512
513 Options.setVisibilityMode(SymbolVisibility);
514 Options.OverflowChecking = OverflowChecking;
515
516
517 // Allow the target to set the default the language options as it sees fit.
518 Target.getDefaultLangOptions(Options);
519
520 // Pass the map of target features to the target for validation and
521 // processing.
522 Target.HandleTargetFeatures(Features);
523
524 if (LangStd == lang_unspecified) {
525 // Based on the base language, pick one.
526 switch (LK) {
527 case langkind_ast: assert(0 && "Invalid call for AST inputs");
528 case lang_unspecified: assert(0 && "Unknown base language");
529 case langkind_ocl:
530 LangStd = lang_c99;
531 break;
532 case langkind_c:
533 case langkind_asm_cpp:
534 case langkind_c_cpp:
535 case langkind_objc:
536 case langkind_objc_cpp:
537 LangStd = lang_gnu99;
538 break;
539 case langkind_cxx:
540 case langkind_cxx_cpp:
541 case langkind_objcxx:
542 case langkind_objcxx_cpp:
543 LangStd = lang_gnucxx98;
544 break;
545 }
546 }
547
548 switch (LangStd) {
549 default: assert(0 && "Unknown language standard!");
550
551 // Fall through from newer standards to older ones. This isn't really right.
552 // FIXME: Enable specifically the right features based on the language stds.
553 case lang_gnucxx0x:
554 case lang_cxx0x:
555 Options.CPlusPlus0x = 1;
556 // FALL THROUGH
557 case lang_gnucxx98:
558 case lang_cxx98:
559 Options.CPlusPlus = 1;
560 Options.CXXOperatorNames = !NoOperatorNames;
561 // FALL THROUGH.
562 case lang_gnu99:
563 case lang_c99:
564 Options.C99 = 1;
565 Options.HexFloats = 1;
566 // FALL THROUGH.
567 case lang_gnu89:
568 Options.BCPLComment = 1; // Only for C99/C++.
569 // FALL THROUGH.
570 case lang_c94:
571 Options.Digraphs = 1; // C94, C99, C++.
572 // FALL THROUGH.
573 case lang_c89:
574 break;
575 }
576
577 // GNUMode - Set if we're in gnu99, gnu89, gnucxx98, etc.
578 switch (LangStd) {
579 default: assert(0 && "Unknown language standard!");
580 case lang_gnucxx0x:
581 case lang_gnucxx98:
582 case lang_gnu99:
583 case lang_gnu89:
584 Options.GNUMode = 1;
585 break;
586 case lang_cxx0x:
587 case lang_cxx98:
588 case lang_c99:
589 case lang_c94:
590 case lang_c89:
591 Options.GNUMode = 0;
592 break;
593 }
594
595 if (Options.CPlusPlus) {
596 Options.C99 = 0;
597 Options.HexFloats = 0;
598 }
599
600 if (LangStd == lang_c89 || LangStd == lang_c94 || LangStd == lang_gnu89)
601 Options.ImplicitInt = 1;
602 else
603 Options.ImplicitInt = 0;
604
605 // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
606 // is specified, or -std is set to a conforming mode.
607 Options.Trigraphs = !Options.GNUMode;
608 if (Trigraphs.getPosition())
609 Options.Trigraphs = Trigraphs; // Command line option wins if specified.
610
611 // If in a conformant language mode (e.g. -std=c99) Blocks defaults to off
612 // even if they are normally on for the target. In GNU modes (e.g.
613 // -std=gnu99) the default for blocks depends on the target settings.
614 // However, blocks are not turned off when compiling Obj-C or Obj-C++ code.
615 if (!Options.ObjC1 && !Options.GNUMode)
616 Options.Blocks = 0;
617
618 // Default to not accepting '$' in identifiers when preprocessing assembler,
619 // but do accept when preprocessing C. FIXME: these defaults are right for
620 // darwin, are they right everywhere?
621 Options.DollarIdents = LK != langkind_asm_cpp;
622 if (DollarsInIdents.getPosition()) // Explicit setting overrides default.
623 Options.DollarIdents = DollarsInIdents;
624
625 if (PascalStrings.getPosition())
626 Options.PascalStrings = PascalStrings;
627 if (MSExtensions.getPosition())
628 Options.Microsoft = MSExtensions;
629 Options.WritableStrings = WritableStrings;
630 if (NoLaxVectorConversions.getPosition())
631 Options.LaxVectorConversions = 0;
632 Options.Exceptions = Exceptions;
633 Options.Rtti = Rtti;
634 if (EnableBlocks.getPosition())
635 Options.Blocks = EnableBlocks;
636 if (CharIsSigned.getPosition())
637 Options.CharIsSigned = CharIsSigned;
638 if (ShortWChar.getPosition())
639 Options.ShortWChar = ShortWChar;
640
641 if (!AllowBuiltins)
642 Options.NoBuiltin = 1;
643 if (Freestanding)
644 Options.Freestanding = Options.NoBuiltin = 1;
645
646 if (EnableHeinousExtensions)
647 Options.HeinousExtensions = 1;
648
649 if (AccessControl)
650 Options.AccessControl = 1;
651
652 Options.ElideConstructors = !NoElideConstructors;
653
654 // OpenCL and C++ both have bool, true, false keywords.
655 Options.Bool = Options.OpenCL | Options.CPlusPlus;
656
657 Options.MathErrno = MathErrno;
658
659 Options.InstantiationDepth = TemplateDepth;
660
661 // Override the default runtime if the user requested it.
662 if (NeXTRuntime)
663 Options.NeXTRuntime = 1;
664 else if (GNURuntime)
665 Options.NeXTRuntime = 0;
666
667 if (!ObjCConstantStringClass.empty())
668 Options.ObjCConstantStringClass = ObjCConstantStringClass.c_str();
669
670 if (ObjCNonFragileABI)
671 Options.ObjCNonFragileABI = 1;
672
673 if (EmitAllDecls)
674 Options.EmitAllDecls = 1;
675
676 // The __OPTIMIZE_SIZE__ define is tied to -Oz, which we don't support.
677 Options.OptimizeSize = 0;
678 Options.Optimize = !!CompileOpts.OptimizationLevel;
679
680 assert(PICLevel <= 2 && "Invalid value for -pic-level");
681 Options.PICLevel = PICLevel;
682
683 Options.GNUInline = !Options.C99;
684 // FIXME: This is affected by other options (-fno-inline).
685
686 // This is the __NO_INLINE__ define, which just depends on things like the
687 // optimization level and -fno-inline, not actually whether the backend has
688 // inlining enabled.
689 Options.NoInline = !CompileOpts.OptimizationLevel;
690
691 Options.Static = StaticDefine;
692
693 switch (StackProtector) {
694 default:
695 assert(StackProtector <= 2 && "Invalid value for -stack-protector");
696 case -1: break;
697 case 0: Options.setStackProtectorMode(LangOptions::SSPOff); break;
698 case 1: Options.setStackProtectorMode(LangOptions::SSPOn); break;
699 case 2: Options.setStackProtectorMode(LangOptions::SSPReq); break;
700 }
701
702 if (MainFileName.getPosition())
703 Options.setMainFileName(MainFileName.c_str());
704
705 Target.setForcedLangOptions(Options);
706}