clang  3.7.0
CompilerInvocation.cpp
Go to the documentation of this file.
1 //===--- CompilerInvocation.cpp -------------------------------------------===//
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 
12 #include "clang/Basic/Version.h"
13 #include "clang/Config/config.h"
15 #include "clang/Driver/Options.h"
16 #include "clang/Driver/Util.h"
19 #include "clang/Frontend/Utils.h"
22 #include "llvm/ADT/Hashing.h"
23 #include "llvm/ADT/STLExtras.h"
24 #include "llvm/ADT/SmallVector.h"
25 #include "llvm/ADT/StringExtras.h"
26 #include "llvm/ADT/StringSwitch.h"
27 #include "llvm/ADT/Triple.h"
28 #include "llvm/Option/Arg.h"
29 #include "llvm/Option/ArgList.h"
30 #include "llvm/Option/OptTable.h"
31 #include "llvm/Option/Option.h"
32 #include "llvm/Support/CodeGen.h"
33 #include "llvm/Support/ErrorHandling.h"
34 #include "llvm/Support/FileSystem.h"
35 #include "llvm/Support/Host.h"
36 #include "llvm/Support/Path.h"
37 #include "llvm/Support/Process.h"
38 #include <atomic>
39 #include <memory>
40 #include <sys/stat.h>
41 #include <system_error>
42 using namespace clang;
43 
44 //===----------------------------------------------------------------------===//
45 // Initialization.
46 //===----------------------------------------------------------------------===//
47 
49  : LangOpts(new LangOptions()), TargetOpts(new TargetOptions()),
50  DiagnosticOpts(new DiagnosticOptions()),
51  HeaderSearchOpts(new HeaderSearchOptions()),
52  PreprocessorOpts(new PreprocessorOptions()) {}
53 
56  LangOpts(new LangOptions(*X.getLangOpts())),
57  TargetOpts(new TargetOptions(X.getTargetOpts())),
58  DiagnosticOpts(new DiagnosticOptions(X.getDiagnosticOpts())),
59  HeaderSearchOpts(new HeaderSearchOptions(X.getHeaderSearchOpts())),
60  PreprocessorOpts(new PreprocessorOptions(X.getPreprocessorOpts())) {}
61 
63 
64 //===----------------------------------------------------------------------===//
65 // Deserialization (from args)
66 //===----------------------------------------------------------------------===//
67 
68 using namespace clang::driver;
69 using namespace clang::driver::options;
70 using namespace llvm::opt;
71 
72 //
73 
74 static unsigned getOptimizationLevel(ArgList &Args, InputKind IK,
75  DiagnosticsEngine &Diags) {
76  unsigned DefaultOpt = 0;
77  if (IK == IK_OpenCL && !Args.hasArg(OPT_cl_opt_disable))
78  DefaultOpt = 2;
79 
80  if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
81  if (A->getOption().matches(options::OPT_O0))
82  return 0;
83 
84  if (A->getOption().matches(options::OPT_Ofast))
85  return 3;
86 
87  assert (A->getOption().matches(options::OPT_O));
88 
89  StringRef S(A->getValue());
90  if (S == "s" || S == "z" || S.empty())
91  return 2;
92 
93  return getLastArgIntValue(Args, OPT_O, DefaultOpt, Diags);
94  }
95 
96  return DefaultOpt;
97 }
98 
99 static unsigned getOptimizationLevelSize(ArgList &Args) {
100  if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
101  if (A->getOption().matches(options::OPT_O)) {
102  switch (A->getValue()[0]) {
103  default:
104  return 0;
105  case 's':
106  return 1;
107  case 'z':
108  return 2;
109  }
110  }
111  }
112  return 0;
113 }
114 
115 static void addDiagnosticArgs(ArgList &Args, OptSpecifier Group,
116  OptSpecifier GroupWithValue,
117  std::vector<std::string> &Diagnostics) {
118  for (Arg *A : Args.filtered(Group)) {
119  if (A->getOption().getKind() == Option::FlagClass) {
120  // The argument is a pure flag (such as OPT_Wall or OPT_Wdeprecated). Add
121  // its name (minus the "W" or "R" at the beginning) to the warning list.
122  Diagnostics.push_back(A->getOption().getName().drop_front(1));
123  } else if (A->getOption().matches(GroupWithValue)) {
124  // This is -Wfoo= or -Rfoo=, where foo is the name of the diagnostic group.
125  Diagnostics.push_back(A->getOption().getName().drop_front(1).rtrim("=-"));
126  } else {
127  // Otherwise, add its value (for OPT_W_Joined and similar).
128  for (const char *Arg : A->getValues())
129  Diagnostics.emplace_back(Arg);
130  }
131  }
132 }
133 
134 static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args,
135  DiagnosticsEngine &Diags) {
136  using namespace options;
137  bool Success = true;
138  if (Arg *A = Args.getLastArg(OPT_analyzer_store)) {
139  StringRef Name = A->getValue();
140  AnalysisStores Value = llvm::StringSwitch<AnalysisStores>(Name)
141 #define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN) \
142  .Case(CMDFLAG, NAME##Model)
143 #include "clang/StaticAnalyzer/Core/Analyses.def"
144  .Default(NumStores);
145  if (Value == NumStores) {
146  Diags.Report(diag::err_drv_invalid_value)
147  << A->getAsString(Args) << Name;
148  Success = false;
149  } else {
150  Opts.AnalysisStoreOpt = Value;
151  }
152  }
153 
154  if (Arg *A = Args.getLastArg(OPT_analyzer_constraints)) {
155  StringRef Name = A->getValue();
156  AnalysisConstraints Value = llvm::StringSwitch<AnalysisConstraints>(Name)
157 #define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN) \
158  .Case(CMDFLAG, NAME##Model)
159 #include "clang/StaticAnalyzer/Core/Analyses.def"
160  .Default(NumConstraints);
161  if (Value == NumConstraints) {
162  Diags.Report(diag::err_drv_invalid_value)
163  << A->getAsString(Args) << Name;
164  Success = false;
165  } else {
167  }
168  }
169 
170  if (Arg *A = Args.getLastArg(OPT_analyzer_output)) {
171  StringRef Name = A->getValue();
172  AnalysisDiagClients Value = llvm::StringSwitch<AnalysisDiagClients>(Name)
173 #define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN) \
174  .Case(CMDFLAG, PD_##NAME)
175 #include "clang/StaticAnalyzer/Core/Analyses.def"
176  .Default(NUM_ANALYSIS_DIAG_CLIENTS);
177  if (Value == NUM_ANALYSIS_DIAG_CLIENTS) {
178  Diags.Report(diag::err_drv_invalid_value)
179  << A->getAsString(Args) << Name;
180  Success = false;
181  } else {
182  Opts.AnalysisDiagOpt = Value;
183  }
184  }
185 
186  if (Arg *A = Args.getLastArg(OPT_analyzer_purge)) {
187  StringRef Name = A->getValue();
188  AnalysisPurgeMode Value = llvm::StringSwitch<AnalysisPurgeMode>(Name)
189 #define ANALYSIS_PURGE(NAME, CMDFLAG, DESC) \
190  .Case(CMDFLAG, NAME)
191 #include "clang/StaticAnalyzer/Core/Analyses.def"
192  .Default(NumPurgeModes);
193  if (Value == NumPurgeModes) {
194  Diags.Report(diag::err_drv_invalid_value)
195  << A->getAsString(Args) << Name;
196  Success = false;
197  } else {
198  Opts.AnalysisPurgeOpt = Value;
199  }
200  }
201 
202  if (Arg *A = Args.getLastArg(OPT_analyzer_inlining_mode)) {
203  StringRef Name = A->getValue();
204  AnalysisInliningMode Value = llvm::StringSwitch<AnalysisInliningMode>(Name)
205 #define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC) \
206  .Case(CMDFLAG, NAME)
207 #include "clang/StaticAnalyzer/Core/Analyses.def"
208  .Default(NumInliningModes);
209  if (Value == NumInliningModes) {
210  Diags.Report(diag::err_drv_invalid_value)
211  << A->getAsString(Args) << Name;
212  Success = false;
213  } else {
214  Opts.InliningMode = Value;
215  }
216  }
217 
218  Opts.ShowCheckerHelp = Args.hasArg(OPT_analyzer_checker_help);
219  Opts.DisableAllChecks = Args.hasArg(OPT_analyzer_disable_all_checks);
220 
222  Args.hasArg(OPT_analyzer_viz_egraph_graphviz);
224  Args.hasArg(OPT_analyzer_viz_egraph_ubigraph);
225  Opts.NoRetryExhausted = Args.hasArg(OPT_analyzer_disable_retry_exhausted);
226  Opts.AnalyzeAll = Args.hasArg(OPT_analyzer_opt_analyze_headers);
227  Opts.AnalyzerDisplayProgress = Args.hasArg(OPT_analyzer_display_progress);
228  Opts.AnalyzeNestedBlocks =
229  Args.hasArg(OPT_analyzer_opt_analyze_nested_blocks);
230  Opts.eagerlyAssumeBinOpBifurcation = Args.hasArg(OPT_analyzer_eagerly_assume);
231  Opts.AnalyzeSpecificFunction = Args.getLastArgValue(OPT_analyze_function);
232  Opts.UnoptimizedCFG = Args.hasArg(OPT_analysis_UnoptimizedCFG);
233  Opts.TrimGraph = Args.hasArg(OPT_trim_egraph);
234  Opts.maxBlockVisitOnPath =
235  getLastArgIntValue(Args, OPT_analyzer_max_loop, 4, Diags);
236  Opts.PrintStats = Args.hasArg(OPT_analyzer_stats);
237  Opts.InlineMaxStackDepth =
238  getLastArgIntValue(Args, OPT_analyzer_inline_max_stack_depth,
239  Opts.InlineMaxStackDepth, Diags);
240 
241  Opts.CheckersControlList.clear();
242  for (const Arg *A :
243  Args.filtered(OPT_analyzer_checker, OPT_analyzer_disable_checker)) {
244  A->claim();
245  bool enable = (A->getOption().getID() == OPT_analyzer_checker);
246  // We can have a list of comma separated checker names, e.g:
247  // '-analyzer-checker=cocoa,unix'
248  StringRef checkerList = A->getValue();
249  SmallVector<StringRef, 4> checkers;
250  checkerList.split(checkers, ",");
251  for (StringRef checker : checkers)
252  Opts.CheckersControlList.emplace_back(checker, enable);
253  }
254 
255  // Go through the analyzer configuration options.
256  for (const Arg *A : Args.filtered(OPT_analyzer_config)) {
257  A->claim();
258  // We can have a list of comma separated config names, e.g:
259  // '-analyzer-config key1=val1,key2=val2'
260  StringRef configList = A->getValue();
261  SmallVector<StringRef, 4> configVals;
262  configList.split(configVals, ",");
263  for (unsigned i = 0, e = configVals.size(); i != e; ++i) {
264  StringRef key, val;
265  std::tie(key, val) = configVals[i].split("=");
266  if (val.empty()) {
267  Diags.Report(SourceLocation(),
268  diag::err_analyzer_config_no_value) << configVals[i];
269  Success = false;
270  break;
271  }
272  if (val.find('=') != StringRef::npos) {
273  Diags.Report(SourceLocation(),
274  diag::err_analyzer_config_multiple_values)
275  << configVals[i];
276  Success = false;
277  break;
278  }
279  Opts.Config[key] = val;
280  }
281  }
282 
283  return Success;
284 }
285 
286 static bool ParseMigratorArgs(MigratorOptions &Opts, ArgList &Args) {
287  Opts.NoNSAllocReallocError = Args.hasArg(OPT_migrator_no_nsalloc_error);
288  Opts.NoFinalizeRemoval = Args.hasArg(OPT_migrator_no_finalize_removal);
289  return true;
290 }
291 
292 static void ParseCommentArgs(CommentOptions &Opts, ArgList &Args) {
293  Opts.BlockCommandNames = Args.getAllArgValues(OPT_fcomment_block_commands);
294  Opts.ParseAllComments = Args.hasArg(OPT_fparse_all_comments);
295 }
296 
297 static StringRef getCodeModel(ArgList &Args, DiagnosticsEngine &Diags) {
298  if (Arg *A = Args.getLastArg(OPT_mcode_model)) {
299  StringRef Value = A->getValue();
300  if (Value == "small" || Value == "kernel" || Value == "medium" ||
301  Value == "large")
302  return Value;
303  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Value;
304  }
305  return "default";
306 }
307 
308 /// \brief Create a new Regex instance out of the string value in \p RpassArg.
309 /// It returns a pointer to the newly generated Regex instance.
310 static std::shared_ptr<llvm::Regex>
312  Arg *RpassArg) {
313  StringRef Val = RpassArg->getValue();
314  std::string RegexError;
315  std::shared_ptr<llvm::Regex> Pattern = std::make_shared<llvm::Regex>(Val);
316  if (!Pattern->isValid(RegexError)) {
317  Diags.Report(diag::err_drv_optimization_remark_pattern)
318  << RegexError << RpassArg->getAsString(Args);
319  Pattern.reset();
320  }
321  return Pattern;
322 }
323 
324 static bool parseDiagnosticLevelMask(StringRef FlagName,
325  const std::vector<std::string> &Levels,
326  DiagnosticsEngine *Diags,
327  DiagnosticLevelMask &M) {
328  bool Success = true;
329  for (const auto &Level : Levels) {
330  DiagnosticLevelMask const PM =
331  llvm::StringSwitch<DiagnosticLevelMask>(Level)
332  .Case("note", DiagnosticLevelMask::Note)
333  .Case("remark", DiagnosticLevelMask::Remark)
334  .Case("warning", DiagnosticLevelMask::Warning)
335  .Case("error", DiagnosticLevelMask::Error)
336  .Default(DiagnosticLevelMask::None);
337  if (PM == DiagnosticLevelMask::None) {
338  Success = false;
339  if (Diags)
340  Diags->Report(diag::err_drv_invalid_value) << FlagName << Level;
341  }
342  M = M | PM;
343  }
344  return Success;
345 }
346 
347 static void parseSanitizerKinds(StringRef FlagName,
348  const std::vector<std::string> &Sanitizers,
349  DiagnosticsEngine &Diags, SanitizerSet &S) {
350  for (const auto &Sanitizer : Sanitizers) {
351  SanitizerMask K = parseSanitizerValue(Sanitizer, /*AllowGroups=*/false);
352  if (K == 0)
353  Diags.Report(diag::err_drv_invalid_value) << FlagName << Sanitizer;
354  else
355  S.set(K, true);
356  }
357 }
358 
359 static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
360  DiagnosticsEngine &Diags,
361  const TargetOptions &TargetOpts) {
362  using namespace options;
363  bool Success = true;
364 
365  unsigned OptimizationLevel = getOptimizationLevel(Args, IK, Diags);
366  // TODO: This could be done in Driver
367  unsigned MaxOptLevel = 3;
368  if (OptimizationLevel > MaxOptLevel) {
369  // If the optimization level is not supported, fall back on the default
370  // optimization
371  Diags.Report(diag::warn_drv_optimization_value)
372  << Args.getLastArg(OPT_O)->getAsString(Args) << "-O" << MaxOptLevel;
373  OptimizationLevel = MaxOptLevel;
374  }
375  Opts.OptimizationLevel = OptimizationLevel;
376 
377  // We must always run at least the always inlining pass.
378  Opts.setInlining(
379  (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining
381  // -fno-inline-functions overrides OptimizationLevel > 1.
382  Opts.NoInline = Args.hasArg(OPT_fno_inline);
383  Opts.setInlining(Args.hasArg(OPT_fno_inline_functions) ?
384  CodeGenOptions::OnlyAlwaysInlining : Opts.getInlining());
385 
386  if (Arg *A = Args.getLastArg(OPT_fveclib)) {
387  StringRef Name = A->getValue();
388  if (Name == "Accelerate")
389  Opts.setVecLib(CodeGenOptions::Accelerate);
390  else if (Name == "none")
391  Opts.setVecLib(CodeGenOptions::NoLibrary);
392  else
393  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name;
394  }
395 
396  if (Args.hasArg(OPT_gline_tables_only)) {
397  Opts.setDebugInfo(CodeGenOptions::DebugLineTablesOnly);
398  } else if (Args.hasArg(OPT_g_Flag) || Args.hasArg(OPT_gdwarf_2) ||
399  Args.hasArg(OPT_gdwarf_3) || Args.hasArg(OPT_gdwarf_4)) {
400  bool Default = false;
401  // Until dtrace (via CTF) and LLDB can deal with distributed debug info,
402  // Darwin and FreeBSD default to standalone/full debug info.
403  if (llvm::Triple(TargetOpts.Triple).isOSDarwin() ||
404  llvm::Triple(TargetOpts.Triple).isOSFreeBSD())
405  Default = true;
406 
407  if (Args.hasFlag(OPT_fstandalone_debug, OPT_fno_standalone_debug, Default))
408  Opts.setDebugInfo(CodeGenOptions::FullDebugInfo);
409  else
410  Opts.setDebugInfo(CodeGenOptions::LimitedDebugInfo);
411  }
412  Opts.DebugColumnInfo = Args.hasArg(OPT_dwarf_column_info);
413  Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file);
414  if (Args.hasArg(OPT_gdwarf_2))
415  Opts.DwarfVersion = 2;
416  else if (Args.hasArg(OPT_gdwarf_3))
417  Opts.DwarfVersion = 3;
418  else if (Args.hasArg(OPT_gdwarf_4))
419  Opts.DwarfVersion = 4;
420  else if (Opts.getDebugInfo() != CodeGenOptions::NoDebugInfo)
421  // Default Dwarf version is 4 if we are generating debug information.
422  Opts.DwarfVersion = 4;
423 
424  if (const Arg *A =
425  Args.getLastArg(OPT_emit_llvm_uselists, OPT_no_emit_llvm_uselists))
426  Opts.EmitLLVMUseLists = A->getOption().getID() == OPT_emit_llvm_uselists;
427 
428  Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns);
429  Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
430  Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables);
431  Opts.UseRegisterSizedBitfieldAccess = Args.hasArg(
432  OPT_fuse_register_sized_bitfield_access);
433  Opts.RelaxedAliasing = Args.hasArg(OPT_relaxed_aliasing);
434  Opts.StructPathTBAA = !Args.hasArg(OPT_no_struct_path_tbaa);
435  Opts.DwarfDebugFlags = Args.getLastArgValue(OPT_dwarf_debug_flags);
436  Opts.MergeAllConstants = !Args.hasArg(OPT_fno_merge_all_constants);
437  Opts.NoCommon = Args.hasArg(OPT_fno_common);
438  Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float);
439  Opts.OptimizeSize = getOptimizationLevelSize(Args);
440  Opts.SimplifyLibCalls = !(Args.hasArg(OPT_fno_builtin) ||
441  Args.hasArg(OPT_ffreestanding));
442  Opts.UnrollLoops =
443  Args.hasFlag(OPT_funroll_loops, OPT_fno_unroll_loops,
444  (Opts.OptimizationLevel > 1 && !Opts.OptimizeSize));
445  Opts.RerollLoops = Args.hasArg(OPT_freroll_loops);
446 
447  Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as);
448  Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
449  Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
450  Opts.ProfileInstrGenerate = Args.hasArg(OPT_fprofile_instr_generate) ||
451  Args.hasArg(OPT_fprofile_instr_generate_EQ);
452  Opts.InstrProfileOutput = Args.getLastArgValue(OPT_fprofile_instr_generate_EQ);
453  Opts.InstrProfileInput = Args.getLastArgValue(OPT_fprofile_instr_use_EQ);
454  Opts.CoverageMapping = Args.hasArg(OPT_fcoverage_mapping);
455  Opts.DumpCoverageMapping = Args.hasArg(OPT_dump_coverage_mapping);
456  Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose);
457  Opts.ObjCAutoRefCountExceptions = Args.hasArg(OPT_fobjc_arc_exceptions);
458  Opts.CXAAtExit = !Args.hasArg(OPT_fno_use_cxa_atexit);
459  Opts.CXXCtorDtorAliases = Args.hasArg(OPT_mconstructor_aliases);
460  Opts.CodeModel = getCodeModel(Args, Diags);
461  Opts.DebugPass = Args.getLastArgValue(OPT_mdebug_pass);
462  Opts.DisableFPElim = Args.hasArg(OPT_mdisable_fp_elim);
463  Opts.DisableFree = Args.hasArg(OPT_disable_free);
464  Opts.DisableTailCalls = Args.hasArg(OPT_mdisable_tail_calls);
465  Opts.FloatABI = Args.getLastArgValue(OPT_mfloat_abi);
466  Opts.LessPreciseFPMAD = Args.hasArg(OPT_cl_mad_enable);
467  Opts.LimitFloatPrecision = Args.getLastArgValue(OPT_mlimit_float_precision);
468  Opts.NoInfsFPMath = (Args.hasArg(OPT_menable_no_infinities) ||
469  Args.hasArg(OPT_cl_finite_math_only) ||
470  Args.hasArg(OPT_cl_fast_relaxed_math));
471  Opts.NoNaNsFPMath = (Args.hasArg(OPT_menable_no_nans) ||
472  Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
473  Args.hasArg(OPT_cl_finite_math_only) ||
474  Args.hasArg(OPT_cl_fast_relaxed_math));
475  Opts.NoSignedZeros = Args.hasArg(OPT_fno_signed_zeros);
476  Opts.ReciprocalMath = Args.hasArg(OPT_freciprocal_math);
477  Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss);
478  Opts.BackendOptions = Args.getAllArgValues(OPT_backend_option);
479  Opts.NumRegisterParameters = getLastArgIntValue(Args, OPT_mregparm, 0, Diags);
480  Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack);
481  Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings);
482  Opts.EnableSegmentedStacks = Args.hasArg(OPT_split_stacks);
483  Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
484  Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer);
485  Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels);
486  Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm);
487  Opts.SoftFloat = Args.hasArg(OPT_msoft_float);
488  Opts.StrictEnums = Args.hasArg(OPT_fstrict_enums);
489  Opts.UnsafeFPMath = Args.hasArg(OPT_menable_unsafe_fp_math) ||
490  Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
491  Args.hasArg(OPT_cl_fast_relaxed_math);
492  Opts.UnwindTables = Args.hasArg(OPT_munwind_tables);
493  Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic");
494  Opts.ThreadModel = Args.getLastArgValue(OPT_mthread_model, "posix");
495  if (Opts.ThreadModel != "posix" && Opts.ThreadModel != "single")
496  Diags.Report(diag::err_drv_invalid_value)
497  << Args.getLastArg(OPT_mthread_model)->getAsString(Args)
498  << Opts.ThreadModel;
499  Opts.TrapFuncName = Args.getLastArgValue(OPT_ftrap_function_EQ);
500  Opts.UseInitArray = Args.hasArg(OPT_fuse_init_array);
501 
502  Opts.FunctionSections = Args.hasFlag(OPT_ffunction_sections,
503  OPT_fno_function_sections, false);
504  Opts.DataSections = Args.hasFlag(OPT_fdata_sections,
505  OPT_fno_data_sections, false);
506  Opts.UniqueSectionNames = Args.hasFlag(OPT_funique_section_names,
507  OPT_fno_unique_section_names, true);
508 
509  Opts.MergeFunctions = Args.hasArg(OPT_fmerge_functions);
510 
511  Opts.PrepareForLTO = Args.hasArg(OPT_flto);
512 
513  Opts.MSVolatile = Args.hasArg(OPT_fms_volatile);
514 
515  Opts.VectorizeBB = Args.hasArg(OPT_vectorize_slp_aggressive);
516  Opts.VectorizeLoop = Args.hasArg(OPT_vectorize_loops);
517  Opts.VectorizeSLP = Args.hasArg(OPT_vectorize_slp);
518 
519  Opts.MainFileName = Args.getLastArgValue(OPT_main_file_name);
520  Opts.VerifyModule = !Args.hasArg(OPT_disable_llvm_verifier);
521 
522  Opts.DisableGCov = Args.hasArg(OPT_test_coverage);
523  Opts.EmitGcovArcs = Args.hasArg(OPT_femit_coverage_data);
524  Opts.EmitGcovNotes = Args.hasArg(OPT_femit_coverage_notes);
525  if (Opts.EmitGcovArcs || Opts.EmitGcovNotes) {
526  Opts.CoverageFile = Args.getLastArgValue(OPT_coverage_file);
527  Opts.CoverageExtraChecksum = Args.hasArg(OPT_coverage_cfg_checksum);
528  Opts.CoverageNoFunctionNamesInData =
529  Args.hasArg(OPT_coverage_no_function_names_in_data);
530  Opts.CoverageExitBlockBeforeBody =
531  Args.hasArg(OPT_coverage_exit_block_before_body);
532  if (Args.hasArg(OPT_coverage_version_EQ)) {
533  StringRef CoverageVersion = Args.getLastArgValue(OPT_coverage_version_EQ);
534  if (CoverageVersion.size() != 4) {
535  Diags.Report(diag::err_drv_invalid_value)
536  << Args.getLastArg(OPT_coverage_version_EQ)->getAsString(Args)
537  << CoverageVersion;
538  } else {
539  memcpy(Opts.CoverageVersion, CoverageVersion.data(), 4);
540  }
541  }
542  }
543 
544  Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions);
545  Opts.InstrumentForProfiling = Args.hasArg(OPT_pg);
546  Opts.EmitOpenCLArgMetadata = Args.hasArg(OPT_cl_kernel_arg_info);
547  Opts.CompressDebugSections = Args.hasArg(OPT_compress_debug_sections);
548  Opts.DebugCompilationDir = Args.getLastArgValue(OPT_fdebug_compilation_dir);
549  Opts.LinkBitcodeFile = Args.getLastArgValue(OPT_mlink_bitcode_file);
550  Opts.SanitizeCoverageType =
551  getLastArgIntValue(Args, OPT_fsanitize_coverage_type, 0, Diags);
552  Opts.SanitizeCoverageIndirectCalls =
553  Args.hasArg(OPT_fsanitize_coverage_indirect_calls);
554  Opts.SanitizeCoverageTraceBB = Args.hasArg(OPT_fsanitize_coverage_trace_bb);
555  Opts.SanitizeCoverageTraceCmp = Args.hasArg(OPT_fsanitize_coverage_trace_cmp);
556  Opts.SanitizeCoverage8bitCounters =
557  Args.hasArg(OPT_fsanitize_coverage_8bit_counters);
558  Opts.SanitizeMemoryTrackOrigins =
559  getLastArgIntValue(Args, OPT_fsanitize_memory_track_origins_EQ, 0, Diags);
560  Opts.SanitizeMemoryUseAfterDtor =
561  Args.hasArg(OPT_fsanitize_memory_use_after_dtor);
562  Opts.SSPBufferSize =
563  getLastArgIntValue(Args, OPT_stack_protector_buffer_size, 8, Diags);
564  Opts.StackRealignment = Args.hasArg(OPT_mstackrealign);
565  if (Arg *A = Args.getLastArg(OPT_mstack_alignment)) {
566  StringRef Val = A->getValue();
567  unsigned StackAlignment = Opts.StackAlignment;
568  Val.getAsInteger(10, StackAlignment);
569  Opts.StackAlignment = StackAlignment;
570  }
571 
572  if (Arg *A = Args.getLastArg(OPT_mstack_probe_size)) {
573  StringRef Val = A->getValue();
574  unsigned StackProbeSize = Opts.StackProbeSize;
575  Val.getAsInteger(0, StackProbeSize);
576  Opts.StackProbeSize = StackProbeSize;
577  }
578 
579  if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) {
580  StringRef Name = A->getValue();
581  unsigned Method = llvm::StringSwitch<unsigned>(Name)
582  .Case("legacy", CodeGenOptions::Legacy)
583  .Case("non-legacy", CodeGenOptions::NonLegacy)
584  .Case("mixed", CodeGenOptions::Mixed)
585  .Default(~0U);
586  if (Method == ~0U) {
587  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name;
588  Success = false;
589  } else {
590  Opts.setObjCDispatchMethod(
591  static_cast<CodeGenOptions::ObjCDispatchMethodKind>(Method));
592  }
593  }
594 
595  if (Arg *A = Args.getLastArg(OPT_ftlsmodel_EQ)) {
596  StringRef Name = A->getValue();
597  unsigned Model = llvm::StringSwitch<unsigned>(Name)
598  .Case("global-dynamic", CodeGenOptions::GeneralDynamicTLSModel)
599  .Case("local-dynamic", CodeGenOptions::LocalDynamicTLSModel)
600  .Case("initial-exec", CodeGenOptions::InitialExecTLSModel)
601  .Case("local-exec", CodeGenOptions::LocalExecTLSModel)
602  .Default(~0U);
603  if (Model == ~0U) {
604  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name;
605  Success = false;
606  } else {
607  Opts.setDefaultTLSModel(static_cast<CodeGenOptions::TLSModel>(Model));
608  }
609  }
610 
611  if (Arg *A = Args.getLastArg(OPT_ffp_contract)) {
612  StringRef Val = A->getValue();
613  if (Val == "fast")
614  Opts.setFPContractMode(CodeGenOptions::FPC_Fast);
615  else if (Val == "on")
616  Opts.setFPContractMode(CodeGenOptions::FPC_On);
617  else if (Val == "off")
618  Opts.setFPContractMode(CodeGenOptions::FPC_Off);
619  else
620  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val;
621  }
622 
623  if (Arg *A = Args.getLastArg(OPT_fpcc_struct_return, OPT_freg_struct_return)) {
624  if (A->getOption().matches(OPT_fpcc_struct_return)) {
625  Opts.setStructReturnConvention(CodeGenOptions::SRCK_OnStack);
626  } else {
627  assert(A->getOption().matches(OPT_freg_struct_return));
628  Opts.setStructReturnConvention(CodeGenOptions::SRCK_InRegs);
629  }
630  }
631 
632  Opts.DependentLibraries = Args.getAllArgValues(OPT_dependent_lib);
633  bool NeedLocTracking = false;
634 
635  if (Arg *A = Args.getLastArg(OPT_Rpass_EQ)) {
637  GenerateOptimizationRemarkRegex(Diags, Args, A);
638  NeedLocTracking = true;
639  }
640 
641  if (Arg *A = Args.getLastArg(OPT_Rpass_missed_EQ)) {
643  GenerateOptimizationRemarkRegex(Diags, Args, A);
644  NeedLocTracking = true;
645  }
646 
647  if (Arg *A = Args.getLastArg(OPT_Rpass_analysis_EQ)) {
649  GenerateOptimizationRemarkRegex(Diags, Args, A);
650  NeedLocTracking = true;
651  }
652 
653  // If the user requested to use a sample profile for PGO, then the
654  // backend will need to track source location information so the profile
655  // can be incorporated into the IR.
656  if (!Opts.SampleProfileFile.empty())
657  NeedLocTracking = true;
658 
659  // If the user requested a flag that requires source locations available in
660  // the backend, make sure that the backend tracks source location information.
661  if (NeedLocTracking && Opts.getDebugInfo() == CodeGenOptions::NoDebugInfo)
662  Opts.setDebugInfo(CodeGenOptions::LocTrackingOnly);
663 
664  Opts.RewriteMapFiles = Args.getAllArgValues(OPT_frewrite_map_file);
665 
666  // Parse -fsanitize-recover= arguments.
667  // FIXME: Report unrecoverable sanitizers incorrectly specified here.
668  parseSanitizerKinds("-fsanitize-recover=",
669  Args.getAllArgValues(OPT_fsanitize_recover_EQ), Diags,
670  Opts.SanitizeRecover);
671  parseSanitizerKinds("-fsanitize-trap=",
672  Args.getAllArgValues(OPT_fsanitize_trap_EQ), Diags,
673  Opts.SanitizeTrap);
674 
676  Args.getAllArgValues(OPT_fcuda_include_gpubinary);
677 
678  return Success;
679 }
680 
682  ArgList &Args) {
683  using namespace options;
684  Opts.OutputFile = Args.getLastArgValue(OPT_dependency_file);
685  Opts.Targets = Args.getAllArgValues(OPT_MT);
686  Opts.IncludeSystemHeaders = Args.hasArg(OPT_sys_header_deps);
687  Opts.IncludeModuleFiles = Args.hasArg(OPT_module_file_deps);
688  Opts.UsePhonyTargets = Args.hasArg(OPT_MP);
689  Opts.ShowHeaderIncludes = Args.hasArg(OPT_H);
690  Opts.HeaderIncludeOutputFile = Args.getLastArgValue(OPT_header_include_file);
691  Opts.AddMissingHeaderDeps = Args.hasArg(OPT_MG);
692  Opts.PrintShowIncludes = Args.hasArg(OPT_show_includes);
693  Opts.DOTOutputFile = Args.getLastArgValue(OPT_dependency_dot);
695  Args.getLastArgValue(OPT_module_dependency_dir);
696  if (Args.hasArg(OPT_MV))
698 }
699 
700 bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
701  DiagnosticsEngine *Diags) {
702  using namespace options;
703  bool Success = true;
704 
705  Opts.DiagnosticLogFile = Args.getLastArgValue(OPT_diagnostic_log_file);
706  if (Arg *A =
707  Args.getLastArg(OPT_diagnostic_serialized_file, OPT__serialize_diags))
708  Opts.DiagnosticSerializationFile = A->getValue();
709  Opts.IgnoreWarnings = Args.hasArg(OPT_w);
710  Opts.NoRewriteMacros = Args.hasArg(OPT_Wno_rewrite_macros);
711  Opts.Pedantic = Args.hasArg(OPT_pedantic);
712  Opts.PedanticErrors = Args.hasArg(OPT_pedantic_errors);
713  Opts.ShowCarets = !Args.hasArg(OPT_fno_caret_diagnostics);
714  Opts.ShowColors = Args.hasArg(OPT_fcolor_diagnostics);
715  Opts.ShowColumn = Args.hasFlag(OPT_fshow_column,
716  OPT_fno_show_column,
717  /*Default=*/true);
718  Opts.ShowFixits = !Args.hasArg(OPT_fno_diagnostics_fixit_info);
719  Opts.ShowLocation = !Args.hasArg(OPT_fno_show_source_location);
720  Opts.ShowOptionNames = Args.hasArg(OPT_fdiagnostics_show_option);
721 
722  llvm::sys::Process::UseANSIEscapeCodes(Args.hasArg(OPT_fansi_escape_codes));
723 
724  // Default behavior is to not to show note include stacks.
725  Opts.ShowNoteIncludeStack = false;
726  if (Arg *A = Args.getLastArg(OPT_fdiagnostics_show_note_include_stack,
727  OPT_fno_diagnostics_show_note_include_stack))
728  if (A->getOption().matches(OPT_fdiagnostics_show_note_include_stack))
729  Opts.ShowNoteIncludeStack = true;
730 
731  StringRef ShowOverloads =
732  Args.getLastArgValue(OPT_fshow_overloads_EQ, "all");
733  if (ShowOverloads == "best")
734  Opts.setShowOverloads(Ovl_Best);
735  else if (ShowOverloads == "all")
736  Opts.setShowOverloads(Ovl_All);
737  else {
738  Success = false;
739  if (Diags)
740  Diags->Report(diag::err_drv_invalid_value)
741  << Args.getLastArg(OPT_fshow_overloads_EQ)->getAsString(Args)
742  << ShowOverloads;
743  }
744 
745  StringRef ShowCategory =
746  Args.getLastArgValue(OPT_fdiagnostics_show_category, "none");
747  if (ShowCategory == "none")
748  Opts.ShowCategories = 0;
749  else if (ShowCategory == "id")
750  Opts.ShowCategories = 1;
751  else if (ShowCategory == "name")
752  Opts.ShowCategories = 2;
753  else {
754  Success = false;
755  if (Diags)
756  Diags->Report(diag::err_drv_invalid_value)
757  << Args.getLastArg(OPT_fdiagnostics_show_category)->getAsString(Args)
758  << ShowCategory;
759  }
760 
761  StringRef Format =
762  Args.getLastArgValue(OPT_fdiagnostics_format, "clang");
763  if (Format == "clang")
764  Opts.setFormat(DiagnosticOptions::Clang);
765  else if (Format == "msvc")
766  Opts.setFormat(DiagnosticOptions::MSVC);
767  else if (Format == "msvc-fallback") {
768  Opts.setFormat(DiagnosticOptions::MSVC);
769  Opts.CLFallbackMode = true;
770  } else if (Format == "vi")
771  Opts.setFormat(DiagnosticOptions::Vi);
772  else {
773  Success = false;
774  if (Diags)
775  Diags->Report(diag::err_drv_invalid_value)
776  << Args.getLastArg(OPT_fdiagnostics_format)->getAsString(Args)
777  << Format;
778  }
779 
780  Opts.ShowSourceRanges = Args.hasArg(OPT_fdiagnostics_print_source_range_info);
781  Opts.ShowParseableFixits = Args.hasArg(OPT_fdiagnostics_parseable_fixits);
782  Opts.ShowPresumedLoc = !Args.hasArg(OPT_fno_diagnostics_use_presumed_location);
783  Opts.VerifyDiagnostics = Args.hasArg(OPT_verify);
785  Success &= parseDiagnosticLevelMask("-verify-ignore-unexpected=",
786  Args.getAllArgValues(OPT_verify_ignore_unexpected_EQ),
787  Diags, DiagMask);
788  if (Args.hasArg(OPT_verify_ignore_unexpected))
789  DiagMask = DiagnosticLevelMask::All;
790  Opts.setVerifyIgnoreUnexpected(DiagMask);
791  Opts.ElideType = !Args.hasArg(OPT_fno_elide_type);
792  Opts.ShowTemplateTree = Args.hasArg(OPT_fdiagnostics_show_template_tree);
793  Opts.ErrorLimit = getLastArgIntValue(Args, OPT_ferror_limit, 0, Diags);
794  Opts.MacroBacktraceLimit =
795  getLastArgIntValue(Args, OPT_fmacro_backtrace_limit,
797  Opts.TemplateBacktraceLimit = getLastArgIntValue(
798  Args, OPT_ftemplate_backtrace_limit,
800  Opts.ConstexprBacktraceLimit = getLastArgIntValue(
801  Args, OPT_fconstexpr_backtrace_limit,
803  Opts.SpellCheckingLimit = getLastArgIntValue(
804  Args, OPT_fspell_checking_limit,
806  Opts.TabStop = getLastArgIntValue(Args, OPT_ftabstop,
808  if (Opts.TabStop == 0 || Opts.TabStop > DiagnosticOptions::MaxTabStop) {
809  Opts.TabStop = DiagnosticOptions::DefaultTabStop;
810  if (Diags)
811  Diags->Report(diag::warn_ignoring_ftabstop_value)
812  << Opts.TabStop << DiagnosticOptions::DefaultTabStop;
813  }
814  Opts.MessageLength = getLastArgIntValue(Args, OPT_fmessage_length, 0, Diags);
815  addDiagnosticArgs(Args, OPT_W_Group, OPT_W_value_Group, Opts.Warnings);
816  addDiagnosticArgs(Args, OPT_R_Group, OPT_R_value_Group, Opts.Remarks);
817 
818  return Success;
819 }
820 
821 static void ParseFileSystemArgs(FileSystemOptions &Opts, ArgList &Args) {
822  Opts.WorkingDir = Args.getLastArgValue(OPT_working_directory);
823 }
824 
825 static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
826  DiagnosticsEngine &Diags) {
827  using namespace options;
829  if (const Arg *A = Args.getLastArg(OPT_Action_Group)) {
830  switch (A->getOption().getID()) {
831  default:
832  llvm_unreachable("Invalid option in group!");
833  case OPT_ast_list:
834  Opts.ProgramAction = frontend::ASTDeclList; break;
835  case OPT_ast_dump:
836  case OPT_ast_dump_lookups:
837  Opts.ProgramAction = frontend::ASTDump; break;
838  case OPT_ast_print:
839  Opts.ProgramAction = frontend::ASTPrint; break;
840  case OPT_ast_view:
841  Opts.ProgramAction = frontend::ASTView; break;
842  case OPT_dump_raw_tokens:
844  case OPT_dump_tokens:
845  Opts.ProgramAction = frontend::DumpTokens; break;
846  case OPT_S:
848  case OPT_emit_llvm_bc:
849  Opts.ProgramAction = frontend::EmitBC; break;
850  case OPT_emit_html:
851  Opts.ProgramAction = frontend::EmitHTML; break;
852  case OPT_emit_llvm:
853  Opts.ProgramAction = frontend::EmitLLVM; break;
854  case OPT_emit_llvm_only:
856  case OPT_emit_codegen_only:
858  case OPT_emit_obj:
859  Opts.ProgramAction = frontend::EmitObj; break;
860  case OPT_fixit_EQ:
861  Opts.FixItSuffix = A->getValue();
862  // fall-through!
863  case OPT_fixit:
864  Opts.ProgramAction = frontend::FixIt; break;
865  case OPT_emit_module:
867  case OPT_emit_pch:
868  Opts.ProgramAction = frontend::GeneratePCH; break;
869  case OPT_emit_pth:
870  Opts.ProgramAction = frontend::GeneratePTH; break;
871  case OPT_init_only:
872  Opts.ProgramAction = frontend::InitOnly; break;
873  case OPT_fsyntax_only:
875  case OPT_module_file_info:
877  case OPT_verify_pch:
878  Opts.ProgramAction = frontend::VerifyPCH; break;
879  case OPT_print_decl_contexts:
881  case OPT_print_preamble:
883  case OPT_E:
885  case OPT_rewrite_macros:
887  case OPT_rewrite_objc:
888  Opts.ProgramAction = frontend::RewriteObjC; break;
889  case OPT_rewrite_test:
890  Opts.ProgramAction = frontend::RewriteTest; break;
891  case OPT_analyze:
892  Opts.ProgramAction = frontend::RunAnalysis; break;
893  case OPT_migrate:
895  case OPT_Eonly:
897  }
898  }
899 
900  if (const Arg* A = Args.getLastArg(OPT_plugin)) {
901  Opts.Plugins.emplace_back(A->getValue(0));
903  Opts.ActionName = A->getValue();
904 
905  for (const Arg *AA : Args.filtered(OPT_plugin_arg))
906  if (AA->getValue(0) == Opts.ActionName)
907  Opts.PluginArgs.emplace_back(AA->getValue(1));
908  }
909 
910  Opts.AddPluginActions = Args.getAllArgValues(OPT_add_plugin);
911  Opts.AddPluginArgs.resize(Opts.AddPluginActions.size());
912  for (int i = 0, e = Opts.AddPluginActions.size(); i != e; ++i)
913  for (const Arg *A : Args.filtered(OPT_plugin_arg))
914  if (A->getValue(0) == Opts.AddPluginActions[i])
915  Opts.AddPluginArgs[i].emplace_back(A->getValue(1));
916 
917  if (const Arg *A = Args.getLastArg(OPT_code_completion_at)) {
918  Opts.CodeCompletionAt =
919  ParsedSourceLocation::FromString(A->getValue());
920  if (Opts.CodeCompletionAt.FileName.empty())
921  Diags.Report(diag::err_drv_invalid_value)
922  << A->getAsString(Args) << A->getValue();
923  }
924  Opts.DisableFree = Args.hasArg(OPT_disable_free);
925 
926  Opts.OutputFile = Args.getLastArgValue(OPT_o);
927  Opts.Plugins = Args.getAllArgValues(OPT_load);
928  Opts.RelocatablePCH = Args.hasArg(OPT_relocatable_pch);
929  Opts.ShowHelp = Args.hasArg(OPT_help);
930  Opts.ShowStats = Args.hasArg(OPT_print_stats);
931  Opts.ShowTimers = Args.hasArg(OPT_ftime_report);
932  Opts.ShowVersion = Args.hasArg(OPT_version);
933  Opts.ASTMergeFiles = Args.getAllArgValues(OPT_ast_merge);
934  Opts.LLVMArgs = Args.getAllArgValues(OPT_mllvm);
935  Opts.FixWhatYouCan = Args.hasArg(OPT_fix_what_you_can);
936  Opts.FixOnlyWarnings = Args.hasArg(OPT_fix_only_warnings);
937  Opts.FixAndRecompile = Args.hasArg(OPT_fixit_recompile);
938  Opts.FixToTemporaries = Args.hasArg(OPT_fixit_to_temp);
939  Opts.ASTDumpDecls = Args.hasArg(OPT_ast_dump);
940  Opts.ASTDumpFilter = Args.getLastArgValue(OPT_ast_dump_filter);
941  Opts.ASTDumpLookups = Args.hasArg(OPT_ast_dump_lookups);
942  Opts.UseGlobalModuleIndex = !Args.hasArg(OPT_fno_modules_global_index);
944  Opts.ModuleMapFiles = Args.getAllArgValues(OPT_fmodule_map_file);
945  Opts.ModuleFiles = Args.getAllArgValues(OPT_fmodule_file);
946 
948  = Args.hasArg(OPT_code_completion_macros);
950  = Args.hasArg(OPT_code_completion_patterns);
952  = !Args.hasArg(OPT_no_code_completion_globals);
954  = Args.hasArg(OPT_code_completion_brief_comments);
955 
957  = Args.getLastArgValue(OPT_foverride_record_layout_EQ);
958  if (const Arg *A = Args.getLastArg(OPT_arcmt_check,
959  OPT_arcmt_modify,
960  OPT_arcmt_migrate)) {
961  switch (A->getOption().getID()) {
962  default:
963  llvm_unreachable("missed a case");
964  case OPT_arcmt_check:
966  break;
967  case OPT_arcmt_modify:
969  break;
970  case OPT_arcmt_migrate:
972  break;
973  }
974  }
975  Opts.MTMigrateDir = Args.getLastArgValue(OPT_mt_migrate_directory);
977  = Args.getLastArgValue(OPT_arcmt_migrate_report_output);
979  = Args.hasArg(OPT_arcmt_migrate_emit_arc_errors);
980 
981  if (Args.hasArg(OPT_objcmt_migrate_literals))
983  if (Args.hasArg(OPT_objcmt_migrate_subscripting))
985  if (Args.hasArg(OPT_objcmt_migrate_property_dot_syntax))
987  if (Args.hasArg(OPT_objcmt_migrate_property))
989  if (Args.hasArg(OPT_objcmt_migrate_readonly_property))
991  if (Args.hasArg(OPT_objcmt_migrate_readwrite_property))
993  if (Args.hasArg(OPT_objcmt_migrate_annotation))
995  if (Args.hasArg(OPT_objcmt_returns_innerpointer_property))
997  if (Args.hasArg(OPT_objcmt_migrate_instancetype))
999  if (Args.hasArg(OPT_objcmt_migrate_nsmacros))
1001  if (Args.hasArg(OPT_objcmt_migrate_protocol_conformance))
1003  if (Args.hasArg(OPT_objcmt_atomic_property))
1005  if (Args.hasArg(OPT_objcmt_ns_nonatomic_iosonly))
1007  if (Args.hasArg(OPT_objcmt_migrate_designated_init))
1009  if (Args.hasArg(OPT_objcmt_migrate_all))
1011 
1012  Opts.ObjCMTWhiteListPath = Args.getLastArgValue(OPT_objcmt_whitelist_dir_path);
1013 
1016  Diags.Report(diag::err_drv_argument_not_allowed_with)
1017  << "ARC migration" << "ObjC migration";
1018  }
1019 
1020  InputKind DashX = IK_None;
1021  if (const Arg *A = Args.getLastArg(OPT_x)) {
1022  DashX = llvm::StringSwitch<InputKind>(A->getValue())
1023  .Case("c", IK_C)
1024  .Case("cl", IK_OpenCL)
1025  .Case("cuda", IK_CUDA)
1026  .Case("c++", IK_CXX)
1027  .Case("objective-c", IK_ObjC)
1028  .Case("objective-c++", IK_ObjCXX)
1029  .Case("cpp-output", IK_PreprocessedC)
1030  .Case("assembler-with-cpp", IK_Asm)
1031  .Case("c++-cpp-output", IK_PreprocessedCXX)
1032  .Case("cuda-cpp-output", IK_PreprocessedCuda)
1033  .Case("objective-c-cpp-output", IK_PreprocessedObjC)
1034  .Case("objc-cpp-output", IK_PreprocessedObjC)
1035  .Case("objective-c++-cpp-output", IK_PreprocessedObjCXX)
1036  .Case("objc++-cpp-output", IK_PreprocessedObjCXX)
1037  .Case("c-header", IK_C)
1038  .Case("cl-header", IK_OpenCL)
1039  .Case("objective-c-header", IK_ObjC)
1040  .Case("c++-header", IK_CXX)
1041  .Case("objective-c++-header", IK_ObjCXX)
1042  .Cases("ast", "pcm", IK_AST)
1043  .Case("ir", IK_LLVM_IR)
1044  .Default(IK_None);
1045  if (DashX == IK_None)
1046  Diags.Report(diag::err_drv_invalid_value)
1047  << A->getAsString(Args) << A->getValue();
1048  }
1049 
1050  // '-' is the default input if none is given.
1051  std::vector<std::string> Inputs = Args.getAllArgValues(OPT_INPUT);
1052  Opts.Inputs.clear();
1053  if (Inputs.empty())
1054  Inputs.push_back("-");
1055  for (unsigned i = 0, e = Inputs.size(); i != e; ++i) {
1056  InputKind IK = DashX;
1057  if (IK == IK_None) {
1059  StringRef(Inputs[i]).rsplit('.').second);
1060  // FIXME: Remove this hack.
1061  if (i == 0)
1062  DashX = IK;
1063  }
1064  Opts.Inputs.emplace_back(std::move(Inputs[i]), IK);
1065  }
1066 
1067  return DashX;
1068 }
1069 
1070 std::string CompilerInvocation::GetResourcesPath(const char *Argv0,
1071  void *MainAddr) {
1072  std::string ClangExecutable =
1073  llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
1074  StringRef Dir = llvm::sys::path::parent_path(ClangExecutable);
1075 
1076  // Compute the path to the resource directory.
1077  StringRef ClangResourceDir(CLANG_RESOURCE_DIR);
1078  SmallString<128> P(Dir);
1079  if (ClangResourceDir != "") {
1080  llvm::sys::path::append(P, ClangResourceDir);
1081  } else {
1082  StringRef ClangLibdirSuffix(CLANG_LIBDIR_SUFFIX);
1083  llvm::sys::path::append(P, "..", Twine("lib") + ClangLibdirSuffix, "clang",
1085  }
1086 
1087  return P.str();
1088 }
1089 
1090 static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) {
1091  using namespace options;
1092  Opts.Sysroot = Args.getLastArgValue(OPT_isysroot, "/");
1093  Opts.Verbose = Args.hasArg(OPT_v);
1094  Opts.UseBuiltinIncludes = !Args.hasArg(OPT_nobuiltininc);
1095  Opts.UseStandardSystemIncludes = !Args.hasArg(OPT_nostdsysteminc);
1096  Opts.UseStandardCXXIncludes = !Args.hasArg(OPT_nostdincxx);
1097  if (const Arg *A = Args.getLastArg(OPT_stdlib_EQ))
1098  Opts.UseLibcxx = (strcmp(A->getValue(), "libc++") == 0);
1099  Opts.ResourceDir = Args.getLastArgValue(OPT_resource_dir);
1100  Opts.ModuleCachePath = Args.getLastArgValue(OPT_fmodules_cache_path);
1101  Opts.ModuleUserBuildPath = Args.getLastArgValue(OPT_fmodules_user_build_path);
1102  Opts.DisableModuleHash = Args.hasArg(OPT_fdisable_module_hash);
1103  Opts.ImplicitModuleMaps = Args.hasArg(OPT_fimplicit_module_maps);
1104  Opts.ModuleMapFileHomeIsCwd = Args.hasArg(OPT_fmodule_map_file_home_is_cwd);
1106  getLastArgIntValue(Args, OPT_fmodules_prune_interval, 7 * 24 * 60 * 60);
1107  Opts.ModuleCachePruneAfter =
1108  getLastArgIntValue(Args, OPT_fmodules_prune_after, 31 * 24 * 60 * 60);
1110  Args.hasArg(OPT_fmodules_validate_once_per_build_session);
1111  Opts.BuildSessionTimestamp =
1112  getLastArgUInt64Value(Args, OPT_fbuild_session_timestamp, 0);
1114  Args.hasArg(OPT_fmodules_validate_system_headers);
1115  if (const Arg *A = Args.getLastArg(OPT_fmodule_format_EQ))
1116  Opts.ModuleFormat = A->getValue();
1117 
1118  for (const Arg *A : Args.filtered(OPT_fmodules_ignore_macro)) {
1119  StringRef MacroDef = A->getValue();
1120  Opts.ModulesIgnoreMacros.insert(MacroDef.split('=').first);
1121  }
1122 
1123  // Add -I..., -F..., and -index-header-map options in order.
1124  bool IsIndexHeaderMap = false;
1125  for (const Arg *A : Args.filtered(OPT_I, OPT_F, OPT_index_header_map)) {
1126  if (A->getOption().matches(OPT_index_header_map)) {
1127  // -index-header-map applies to the next -I or -F.
1128  IsIndexHeaderMap = true;
1129  continue;
1130  }
1131 
1133  IsIndexHeaderMap ? frontend::IndexHeaderMap : frontend::Angled;
1134 
1135  Opts.AddPath(A->getValue(), Group,
1136  /*IsFramework=*/A->getOption().matches(OPT_F), true);
1137  IsIndexHeaderMap = false;
1138  }
1139 
1140  // Add -iprefix/-iwithprefix/-iwithprefixbefore options.
1141  StringRef Prefix = ""; // FIXME: This isn't the correct default prefix.
1142  for (const Arg *A :
1143  Args.filtered(OPT_iprefix, OPT_iwithprefix, OPT_iwithprefixbefore)) {
1144  if (A->getOption().matches(OPT_iprefix))
1145  Prefix = A->getValue();
1146  else if (A->getOption().matches(OPT_iwithprefix))
1147  Opts.AddPath(Prefix.str() + A->getValue(), frontend::After, false, true);
1148  else
1149  Opts.AddPath(Prefix.str() + A->getValue(), frontend::Angled, false, true);
1150  }
1151 
1152  for (const Arg *A : Args.filtered(OPT_idirafter))
1153  Opts.AddPath(A->getValue(), frontend::After, false, true);
1154  for (const Arg *A : Args.filtered(OPT_iquote))
1155  Opts.AddPath(A->getValue(), frontend::Quoted, false, true);
1156  for (const Arg *A : Args.filtered(OPT_isystem, OPT_iwithsysroot))
1157  Opts.AddPath(A->getValue(), frontend::System, false,
1158  !A->getOption().matches(OPT_iwithsysroot));
1159  for (const Arg *A : Args.filtered(OPT_iframework))
1160  Opts.AddPath(A->getValue(), frontend::System, true, true);
1161 
1162  // Add the paths for the various language specific isystem flags.
1163  for (const Arg *A : Args.filtered(OPT_c_isystem))
1164  Opts.AddPath(A->getValue(), frontend::CSystem, false, true);
1165  for (const Arg *A : Args.filtered(OPT_cxx_isystem))
1166  Opts.AddPath(A->getValue(), frontend::CXXSystem, false, true);
1167  for (const Arg *A : Args.filtered(OPT_objc_isystem))
1168  Opts.AddPath(A->getValue(), frontend::ObjCSystem, false,true);
1169  for (const Arg *A : Args.filtered(OPT_objcxx_isystem))
1170  Opts.AddPath(A->getValue(), frontend::ObjCXXSystem, false, true);
1171 
1172  // Add the internal paths from a driver that detects standard include paths.
1173  for (const Arg *A :
1174  Args.filtered(OPT_internal_isystem, OPT_internal_externc_isystem)) {
1176  if (A->getOption().matches(OPT_internal_externc_isystem))
1177  Group = frontend::ExternCSystem;
1178  Opts.AddPath(A->getValue(), Group, false, true);
1179  }
1180 
1181  // Add the path prefixes which are implicitly treated as being system headers.
1182  for (const Arg *A :
1183  Args.filtered(OPT_system_header_prefix, OPT_no_system_header_prefix))
1184  Opts.AddSystemHeaderPrefix(
1185  A->getValue(), A->getOption().matches(OPT_system_header_prefix));
1186 
1187  for (const Arg *A : Args.filtered(OPT_ivfsoverlay))
1188  Opts.AddVFSOverlayFile(A->getValue());
1189 }
1190 
1192  LangStandard::Kind LangStd) {
1193  // Set some properties which depend solely on the input kind; it would be nice
1194  // to move these to the language standard, and have the driver resolve the
1195  // input kind + language standard.
1196  if (IK == IK_Asm) {
1197  Opts.AsmPreprocessor = 1;
1198  } else if (IK == IK_ObjC ||
1199  IK == IK_ObjCXX ||
1200  IK == IK_PreprocessedObjC ||
1201  IK == IK_PreprocessedObjCXX) {
1202  Opts.ObjC1 = Opts.ObjC2 = 1;
1203  }
1204 
1205  if (LangStd == LangStandard::lang_unspecified) {
1206  // Based on the base language, pick one.
1207  switch (IK) {
1208  case IK_None:
1209  case IK_AST:
1210  case IK_LLVM_IR:
1211  llvm_unreachable("Invalid input kind!");
1212  case IK_OpenCL:
1213  LangStd = LangStandard::lang_opencl;
1214  break;
1215  case IK_CUDA:
1216  case IK_PreprocessedCuda:
1217  LangStd = LangStandard::lang_cuda;
1218  break;
1219  case IK_Asm:
1220  case IK_C:
1221  case IK_PreprocessedC:
1222  case IK_ObjC:
1223  case IK_PreprocessedObjC:
1224  LangStd = LangStandard::lang_gnu11;
1225  break;
1226  case IK_CXX:
1227  case IK_PreprocessedCXX:
1228  case IK_ObjCXX:
1229  case IK_PreprocessedObjCXX:
1230  LangStd = LangStandard::lang_gnucxx98;
1231  break;
1232  }
1233  }
1234 
1235  const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd);
1236  Opts.LineComment = Std.hasLineComments();
1237  Opts.C99 = Std.isC99();
1238  Opts.C11 = Std.isC11();
1239  Opts.CPlusPlus = Std.isCPlusPlus();
1240  Opts.CPlusPlus11 = Std.isCPlusPlus11();
1241  Opts.CPlusPlus14 = Std.isCPlusPlus14();
1242  Opts.CPlusPlus1z = Std.isCPlusPlus1z();
1243  Opts.Digraphs = Std.hasDigraphs();
1244  Opts.GNUMode = Std.isGNUMode();
1245  Opts.GNUInline = Std.isC89();
1246  Opts.HexFloats = Std.hasHexFloats();
1247  Opts.ImplicitInt = Std.hasImplicitInt();
1248 
1249  // Set OpenCL Version.
1250  Opts.OpenCL = LangStd == LangStandard::lang_opencl || IK == IK_OpenCL;
1251  if (LangStd == LangStandard::lang_opencl)
1252  Opts.OpenCLVersion = 100;
1253  else if (LangStd == LangStandard::lang_opencl11)
1254  Opts.OpenCLVersion = 110;
1255  else if (LangStd == LangStandard::lang_opencl12)
1256  Opts.OpenCLVersion = 120;
1257  else if (LangStd == LangStandard::lang_opencl20)
1258  Opts.OpenCLVersion = 200;
1259 
1260  // OpenCL has some additional defaults.
1261  if (Opts.OpenCL) {
1262  Opts.AltiVec = 0;
1263  Opts.ZVector = 0;
1264  Opts.CXXOperatorNames = 1;
1265  Opts.LaxVectorConversions = 0;
1266  Opts.DefaultFPContract = 1;
1267  Opts.NativeHalfType = 1;
1268  }
1269 
1270  Opts.CUDA = IK == IK_CUDA || IK == IK_PreprocessedCuda ||
1271  LangStd == LangStandard::lang_cuda;
1272 
1273  // OpenCL and C++ both have bool, true, false keywords.
1274  Opts.Bool = Opts.OpenCL || Opts.CPlusPlus;
1275 
1276  // OpenCL has half keyword
1277  Opts.Half = Opts.OpenCL;
1278 
1279  // C++ has wchar_t keyword.
1280  Opts.WChar = Opts.CPlusPlus;
1281 
1282  Opts.GNUKeywords = Opts.GNUMode;
1283  Opts.CXXOperatorNames = Opts.CPlusPlus;
1284 
1285  Opts.DollarIdents = !Opts.AsmPreprocessor;
1286 }
1287 
1288 /// Attempt to parse a visibility value out of the given argument.
1289 static Visibility parseVisibility(Arg *arg, ArgList &args,
1290  DiagnosticsEngine &diags) {
1291  StringRef value = arg->getValue();
1292  if (value == "default") {
1293  return DefaultVisibility;
1294  } else if (value == "hidden") {
1295  return HiddenVisibility;
1296  } else if (value == "protected") {
1297  // FIXME: diagnose if target does not support protected visibility
1298  return ProtectedVisibility;
1299  }
1300 
1301  diags.Report(diag::err_drv_invalid_value)
1302  << arg->getAsString(args) << value;
1303  return DefaultVisibility;
1304 }
1305 
1306 static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
1307  DiagnosticsEngine &Diags) {
1308  // FIXME: Cleanup per-file based stuff.
1310  if (const Arg *A = Args.getLastArg(OPT_std_EQ)) {
1311  LangStd = llvm::StringSwitch<LangStandard::Kind>(A->getValue())
1312 #define LANGSTANDARD(id, name, desc, features) \
1313  .Case(name, LangStandard::lang_##id)
1314 #include "clang/Frontend/LangStandards.def"
1316  if (LangStd == LangStandard::lang_unspecified)
1317  Diags.Report(diag::err_drv_invalid_value)
1318  << A->getAsString(Args) << A->getValue();
1319  else {
1320  // Valid standard, check to make sure language and standard are
1321  // compatible.
1322  const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd);
1323  switch (IK) {
1324  case IK_C:
1325  case IK_ObjC:
1326  case IK_PreprocessedC:
1327  case IK_PreprocessedObjC:
1328  if (!(Std.isC89() || Std.isC99()))
1329  Diags.Report(diag::err_drv_argument_not_allowed_with)
1330  << A->getAsString(Args) << "C/ObjC";
1331  break;
1332  case IK_CXX:
1333  case IK_ObjCXX:
1334  case IK_PreprocessedCXX:
1335  case IK_PreprocessedObjCXX:
1336  if (!Std.isCPlusPlus())
1337  Diags.Report(diag::err_drv_argument_not_allowed_with)
1338  << A->getAsString(Args) << "C++/ObjC++";
1339  break;
1340  case IK_OpenCL:
1341  if (!Std.isC99())
1342  Diags.Report(diag::err_drv_argument_not_allowed_with)
1343  << A->getAsString(Args) << "OpenCL";
1344  break;
1345  case IK_CUDA:
1346  case IK_PreprocessedCuda:
1347  if (!Std.isCPlusPlus())
1348  Diags.Report(diag::err_drv_argument_not_allowed_with)
1349  << A->getAsString(Args) << "CUDA";
1350  break;
1351  default:
1352  break;
1353  }
1354  }
1355  }
1356 
1357  // -cl-std only applies for OpenCL language standards.
1358  // Override the -std option in this case.
1359  if (const Arg *A = Args.getLastArg(OPT_cl_std_EQ)) {
1360  LangStandard::Kind OpenCLLangStd
1361  = llvm::StringSwitch<LangStandard::Kind>(A->getValue())
1362  .Case("CL", LangStandard::lang_opencl)
1363  .Case("CL1.1", LangStandard::lang_opencl11)
1364  .Case("CL1.2", LangStandard::lang_opencl12)
1365  .Case("CL2.0", LangStandard::lang_opencl20)
1367 
1368  if (OpenCLLangStd == LangStandard::lang_unspecified) {
1369  Diags.Report(diag::err_drv_invalid_value)
1370  << A->getAsString(Args) << A->getValue();
1371  }
1372  else
1373  LangStd = OpenCLLangStd;
1374  }
1375 
1376  CompilerInvocation::setLangDefaults(Opts, IK, LangStd);
1377 
1378  // We abuse '-f[no-]gnu-keywords' to force overriding all GNU-extension
1379  // keywords. This behavior is provided by GCC's poorly named '-fasm' flag,
1380  // while a subset (the non-C++ GNU keywords) is provided by GCC's
1381  // '-fgnu-keywords'. Clang conflates the two for simplicity under the single
1382  // name, as it doesn't seem a useful distinction.
1383  Opts.GNUKeywords = Args.hasFlag(OPT_fgnu_keywords, OPT_fno_gnu_keywords,
1384  Opts.GNUKeywords);
1385 
1386  if (Args.hasArg(OPT_fno_operator_names))
1387  Opts.CXXOperatorNames = 0;
1388 
1389  if (Args.hasArg(OPT_fcuda_is_device))
1390  Opts.CUDAIsDevice = 1;
1391 
1392  if (Args.hasArg(OPT_fcuda_allow_host_calls_from_host_device))
1393  Opts.CUDAAllowHostCallsFromHostDevice = 1;
1394 
1395  if (Args.hasArg(OPT_fcuda_disable_target_call_checks))
1396  Opts.CUDADisableTargetCallChecks = 1;
1397 
1398  if (Opts.ObjC1) {
1399  if (Arg *arg = Args.getLastArg(OPT_fobjc_runtime_EQ)) {
1400  StringRef value = arg->getValue();
1401  if (Opts.ObjCRuntime.tryParse(value))
1402  Diags.Report(diag::err_drv_unknown_objc_runtime) << value;
1403  }
1404 
1405  if (Args.hasArg(OPT_fobjc_gc_only))
1406  Opts.setGC(LangOptions::GCOnly);
1407  else if (Args.hasArg(OPT_fobjc_gc))
1408  Opts.setGC(LangOptions::HybridGC);
1409  else if (Args.hasArg(OPT_fobjc_arc)) {
1410  Opts.ObjCAutoRefCount = 1;
1411  if (!Opts.ObjCRuntime.allowsARC())
1412  Diags.Report(diag::err_arc_unsupported_on_runtime);
1413 
1414  // Only set ObjCARCWeak if ARC is enabled.
1415  if (Args.hasArg(OPT_fobjc_runtime_has_weak))
1416  Opts.ObjCARCWeak = 1;
1417  else
1418  Opts.ObjCARCWeak = Opts.ObjCRuntime.allowsWeak();
1419  }
1420 
1421  if (Args.hasArg(OPT_fno_objc_infer_related_result_type))
1422  Opts.ObjCInferRelatedResultType = 0;
1423 
1424  if (Args.hasArg(OPT_fobjc_subscripting_legacy_runtime))
1425  Opts.ObjCSubscriptingLegacyRuntime =
1427  }
1428 
1429  if (Args.hasArg(OPT_fgnu89_inline)) {
1430  if (Opts.CPlusPlus)
1431  Diags.Report(diag::err_drv_argument_not_allowed_with) << "-fgnu89-inline"
1432  << "C++/ObjC++";
1433  else
1434  Opts.GNUInline = 1;
1435  }
1436 
1437  if (Args.hasArg(OPT_fapple_kext)) {
1438  if (!Opts.CPlusPlus)
1439  Diags.Report(diag::warn_c_kext);
1440  else
1441  Opts.AppleKext = 1;
1442  }
1443 
1444  if (Args.hasArg(OPT_print_ivar_layout))
1445  Opts.ObjCGCBitmapPrint = 1;
1446  if (Args.hasArg(OPT_fno_constant_cfstrings))
1447  Opts.NoConstantCFStrings = 1;
1448 
1449  if (Args.hasArg(OPT_faltivec))
1450  Opts.AltiVec = 1;
1451 
1452  if (Args.hasArg(OPT_fzvector))
1453  Opts.ZVector = 1;
1454 
1455  if (Args.hasArg(OPT_pthread))
1456  Opts.POSIXThreads = 1;
1457 
1458  // The value-visibility mode defaults to "default".
1459  if (Arg *visOpt = Args.getLastArg(OPT_fvisibility)) {
1460  Opts.setValueVisibilityMode(parseVisibility(visOpt, Args, Diags));
1461  } else {
1462  Opts.setValueVisibilityMode(DefaultVisibility);
1463  }
1464 
1465  // The type-visibility mode defaults to the value-visibility mode.
1466  if (Arg *typeVisOpt = Args.getLastArg(OPT_ftype_visibility)) {
1467  Opts.setTypeVisibilityMode(parseVisibility(typeVisOpt, Args, Diags));
1468  } else {
1469  Opts.setTypeVisibilityMode(Opts.getValueVisibilityMode());
1470  }
1471 
1472  if (Args.hasArg(OPT_fvisibility_inlines_hidden))
1473  Opts.InlineVisibilityHidden = 1;
1474 
1475  if (Args.hasArg(OPT_ftrapv)) {
1476  Opts.setSignedOverflowBehavior(LangOptions::SOB_Trapping);
1477  // Set the handler, if one is specified.
1478  Opts.OverflowHandler =
1479  Args.getLastArgValue(OPT_ftrapv_handler);
1480  }
1481  else if (Args.hasArg(OPT_fwrapv))
1482  Opts.setSignedOverflowBehavior(LangOptions::SOB_Defined);
1483 
1484  Opts.MSVCCompat = Args.hasArg(OPT_fms_compatibility);
1485  Opts.MicrosoftExt = Opts.MSVCCompat || Args.hasArg(OPT_fms_extensions);
1486  Opts.AsmBlocks = Args.hasArg(OPT_fasm_blocks) || Opts.MicrosoftExt;
1487  Opts.MSCompatibilityVersion = 0;
1488  if (const Arg *A = Args.getLastArg(OPT_fms_compatibility_version)) {
1489  VersionTuple VT;
1490  if (VT.tryParse(A->getValue()))
1491  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args)
1492  << A->getValue();
1493  Opts.MSCompatibilityVersion = VT.getMajor() * 10000000 +
1494  VT.getMinor().getValueOr(0) * 100000 +
1495  VT.getSubminor().getValueOr(0);
1496  }
1497 
1498  // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs
1499  // is specified, or -std is set to a conforming mode.
1500  // Trigraphs are disabled by default in c++1z onwards.
1501  Opts.Trigraphs = !Opts.GNUMode && !Opts.MSVCCompat && !Opts.CPlusPlus1z;
1502  Opts.Trigraphs =
1503  Args.hasFlag(OPT_ftrigraphs, OPT_fno_trigraphs, Opts.Trigraphs);
1504 
1505  Opts.DollarIdents = Args.hasFlag(OPT_fdollars_in_identifiers,
1506  OPT_fno_dollars_in_identifiers,
1507  Opts.DollarIdents);
1508  Opts.PascalStrings = Args.hasArg(OPT_fpascal_strings);
1509  Opts.VtorDispMode = getLastArgIntValue(Args, OPT_vtordisp_mode_EQ, 1, Diags);
1510  Opts.Borland = Args.hasArg(OPT_fborland_extensions);
1511  Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings);
1512  Opts.ConstStrings = Args.hasFlag(OPT_fconst_strings, OPT_fno_const_strings,
1513  Opts.ConstStrings);
1514  if (Args.hasArg(OPT_fno_lax_vector_conversions))
1515  Opts.LaxVectorConversions = 0;
1516  if (Args.hasArg(OPT_fno_threadsafe_statics))
1517  Opts.ThreadsafeStatics = 0;
1518  Opts.Exceptions = Args.hasArg(OPT_fexceptions);
1519  Opts.ObjCExceptions = Args.hasArg(OPT_fobjc_exceptions);
1520  Opts.CXXExceptions = Args.hasArg(OPT_fcxx_exceptions);
1521  Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions);
1522  Opts.TraditionalCPP = Args.hasArg(OPT_traditional_cpp);
1523 
1524  Opts.RTTI = !Args.hasArg(OPT_fno_rtti);
1525  Opts.RTTIData = Opts.RTTI && !Args.hasArg(OPT_fno_rtti_data);
1526  Opts.Blocks = Args.hasArg(OPT_fblocks);
1527  Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional);
1528  Opts.Modules = Args.hasArg(OPT_fmodules);
1529  Opts.ModulesStrictDeclUse = Args.hasArg(OPT_fmodules_strict_decluse);
1530  Opts.ModulesDeclUse =
1531  Args.hasArg(OPT_fmodules_decluse) || Opts.ModulesStrictDeclUse;
1532  Opts.ModulesLocalVisibility =
1533  Args.hasArg(OPT_fmodules_local_submodule_visibility);
1534  Opts.ModulesHideInternalLinkage =
1535  !Args.hasArg(OPT_fno_modules_hide_internal_linkage);
1536  Opts.ModulesSearchAll = Opts.Modules &&
1537  !Args.hasArg(OPT_fno_modules_search_all) &&
1538  Args.hasArg(OPT_fmodules_search_all);
1539  Opts.ModulesErrorRecovery = !Args.hasArg(OPT_fno_modules_error_recovery);
1540  Opts.ImplicitModules = !Args.hasArg(OPT_fno_implicit_modules);
1541  Opts.CharIsSigned = Opts.OpenCL || !Args.hasArg(OPT_fno_signed_char);
1542  Opts.WChar = Opts.CPlusPlus && !Args.hasArg(OPT_fno_wchar);
1543  Opts.ShortWChar = Args.hasFlag(OPT_fshort_wchar, OPT_fno_short_wchar, false);
1544  Opts.ShortEnums = Args.hasArg(OPT_fshort_enums);
1545  Opts.Freestanding = Args.hasArg(OPT_ffreestanding);
1546  Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding;
1547  Opts.NoMathBuiltin = Args.hasArg(OPT_fno_math_builtin);
1548  Opts.AssumeSaneOperatorNew = !Args.hasArg(OPT_fno_assume_sane_operator_new);
1549  Opts.SizedDeallocation = Args.hasArg(OPT_fsized_deallocation);
1550  Opts.ConceptsTS = Args.hasArg(OPT_fconcepts_ts);
1551  Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions);
1552  Opts.AccessControl = !Args.hasArg(OPT_fno_access_control);
1553  Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors);
1554  Opts.MathErrno = !Opts.OpenCL && Args.hasArg(OPT_fmath_errno);
1555  Opts.InstantiationDepth =
1556  getLastArgIntValue(Args, OPT_ftemplate_depth, 256, Diags);
1557  Opts.ArrowDepth =
1558  getLastArgIntValue(Args, OPT_foperator_arrow_depth, 256, Diags);
1559  Opts.ConstexprCallDepth =
1560  getLastArgIntValue(Args, OPT_fconstexpr_depth, 512, Diags);
1561  Opts.ConstexprStepLimit =
1562  getLastArgIntValue(Args, OPT_fconstexpr_steps, 1048576, Diags);
1563  Opts.BracketDepth = getLastArgIntValue(Args, OPT_fbracket_depth, 256, Diags);
1564  Opts.DelayedTemplateParsing = Args.hasArg(OPT_fdelayed_template_parsing);
1565  Opts.NumLargeByValueCopy =
1566  getLastArgIntValue(Args, OPT_Wlarge_by_value_copy_EQ, 0, Diags);
1567  Opts.MSBitfields = Args.hasArg(OPT_mms_bitfields);
1569  Args.getLastArgValue(OPT_fconstant_string_class);
1570  Opts.ObjCDefaultSynthProperties =
1571  !Args.hasArg(OPT_disable_objc_default_synthesize_properties);
1572  Opts.EncodeExtendedBlockSig =
1573  Args.hasArg(OPT_fencode_extended_block_signature);
1574  Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls);
1575  Opts.PackStruct = getLastArgIntValue(Args, OPT_fpack_struct_EQ, 0, Diags);
1576  Opts.MaxTypeAlign = getLastArgIntValue(Args, OPT_fmax_type_align_EQ, 0, Diags);
1577  Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags);
1578  Opts.PIELevel = getLastArgIntValue(Args, OPT_pie_level, 0, Diags);
1579  Opts.Static = Args.hasArg(OPT_static_define);
1580  Opts.DumpRecordLayoutsSimple = Args.hasArg(OPT_fdump_record_layouts_simple);
1581  Opts.DumpRecordLayouts = Opts.DumpRecordLayoutsSimple
1582  || Args.hasArg(OPT_fdump_record_layouts);
1583  Opts.DumpVTableLayouts = Args.hasArg(OPT_fdump_vtable_layouts);
1584  Opts.SpellChecking = !Args.hasArg(OPT_fno_spell_checking);
1585  Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align);
1586  Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant);
1587  Opts.FastRelaxedMath = Args.hasArg(OPT_cl_fast_relaxed_math);
1588  Opts.MRTD = Args.hasArg(OPT_mrtd);
1589  Opts.HexagonQdsp6Compat = Args.hasArg(OPT_mqdsp6_compat);
1590  Opts.FakeAddressSpaceMap = Args.hasArg(OPT_ffake_address_space_map);
1591  Opts.ParseUnknownAnytype = Args.hasArg(OPT_funknown_anytype);
1592  Opts.DebuggerSupport = Args.hasArg(OPT_fdebugger_support);
1593  Opts.DebuggerCastResultToId = Args.hasArg(OPT_fdebugger_cast_result_to_id);
1594  Opts.DebuggerObjCLiteral = Args.hasArg(OPT_fdebugger_objc_literal);
1595  Opts.ApplePragmaPack = Args.hasArg(OPT_fapple_pragma_pack);
1596  Opts.CurrentModule = Args.getLastArgValue(OPT_fmodule_name);
1597  Opts.AppExt = Args.hasArg(OPT_fapplication_extension);
1598  Opts.ImplementationOfModule =
1599  Args.getLastArgValue(OPT_fmodule_implementation_of);
1600  Opts.ModuleFeatures = Args.getAllArgValues(OPT_fmodule_feature);
1601  std::sort(Opts.ModuleFeatures.begin(), Opts.ModuleFeatures.end());
1602  Opts.NativeHalfType |= Args.hasArg(OPT_fnative_half_type);
1603  Opts.HalfArgsAndReturns = Args.hasArg(OPT_fallow_half_arguments_and_returns);
1604  Opts.GNUAsm = !Args.hasArg(OPT_fno_gnu_inline_asm);
1605 
1606  if (!Opts.CurrentModule.empty() && !Opts.ImplementationOfModule.empty() &&
1607  Opts.CurrentModule != Opts.ImplementationOfModule) {
1608  Diags.Report(diag::err_conflicting_module_names)
1609  << Opts.CurrentModule << Opts.ImplementationOfModule;
1610  }
1611 
1612  // For now, we only support local submodule visibility in C++ (because we
1613  // heavily depend on the ODR for merging redefinitions).
1614  if (Opts.ModulesLocalVisibility && !Opts.CPlusPlus)
1615  Diags.Report(diag::err_drv_argument_not_allowed_with)
1616  << "-fmodules-local-submodule-visibility" << "C";
1617 
1618  if (Arg *A = Args.getLastArg(OPT_faddress_space_map_mangling_EQ)) {
1619  switch (llvm::StringSwitch<unsigned>(A->getValue())
1620  .Case("target", LangOptions::ASMM_Target)
1621  .Case("no", LangOptions::ASMM_Off)
1622  .Case("yes", LangOptions::ASMM_On)
1623  .Default(255)) {
1624  default:
1625  Diags.Report(diag::err_drv_invalid_value)
1626  << "-faddress-space-map-mangling=" << A->getValue();
1627  break;
1629  Opts.setAddressSpaceMapMangling(LangOptions::ASMM_Target);
1630  break;
1631  case LangOptions::ASMM_On:
1632  Opts.setAddressSpaceMapMangling(LangOptions::ASMM_On);
1633  break;
1634  case LangOptions::ASMM_Off:
1635  Opts.setAddressSpaceMapMangling(LangOptions::ASMM_Off);
1636  break;
1637  }
1638  }
1639 
1640  if (Arg *A = Args.getLastArg(OPT_fms_memptr_rep_EQ)) {
1642  llvm::StringSwitch<LangOptions::PragmaMSPointersToMembersKind>(
1643  A->getValue())
1644  .Case("single",
1646  .Case("multiple",
1648  .Case("virtual",
1650  .Default(LangOptions::PPTMK_BestCase);
1651  if (InheritanceModel == LangOptions::PPTMK_BestCase)
1652  Diags.Report(diag::err_drv_invalid_value)
1653  << "-fms-memptr-rep=" << A->getValue();
1654 
1655  Opts.setMSPointerToMemberRepresentationMethod(InheritanceModel);
1656  }
1657 
1658  // Check if -fopenmp is specified.
1659  Opts.OpenMP = Args.hasArg(options::OPT_fopenmp);
1660  Opts.OpenMPUseTLS =
1661  Opts.OpenMP && !Args.hasArg(options::OPT_fnoopenmp_use_tls);
1662 
1663  // Record whether the __DEPRECATED define was requested.
1664  Opts.Deprecated = Args.hasFlag(OPT_fdeprecated_macro,
1665  OPT_fno_deprecated_macro,
1666  Opts.Deprecated);
1667 
1668  // FIXME: Eliminate this dependency.
1669  unsigned Opt = getOptimizationLevel(Args, IK, Diags),
1670  OptSize = getOptimizationLevelSize(Args);
1671  Opts.Optimize = Opt != 0;
1672  Opts.OptimizeSize = OptSize != 0;
1673 
1674  // This is the __NO_INLINE__ define, which just depends on things like the
1675  // optimization level and -fno-inline, not actually whether the backend has
1676  // inlining enabled.
1677  Opts.NoInlineDefine = !Opt || Args.hasArg(OPT_fno_inline);
1678 
1679  Opts.FastMath = Args.hasArg(OPT_ffast_math) ||
1680  Args.hasArg(OPT_cl_fast_relaxed_math);
1681  Opts.FiniteMathOnly = Args.hasArg(OPT_ffinite_math_only) ||
1682  Args.hasArg(OPT_cl_finite_math_only) ||
1683  Args.hasArg(OPT_cl_fast_relaxed_math);
1684 
1685  Opts.RetainCommentsFromSystemHeaders =
1686  Args.hasArg(OPT_fretain_comments_from_system_headers);
1687 
1688  unsigned SSP = getLastArgIntValue(Args, OPT_stack_protector, 0, Diags);
1689  switch (SSP) {
1690  default:
1691  Diags.Report(diag::err_drv_invalid_value)
1692  << Args.getLastArg(OPT_stack_protector)->getAsString(Args) << SSP;
1693  break;
1694  case 0: Opts.setStackProtector(LangOptions::SSPOff); break;
1695  case 1: Opts.setStackProtector(LangOptions::SSPOn); break;
1696  case 2: Opts.setStackProtector(LangOptions::SSPStrong); break;
1697  case 3: Opts.setStackProtector(LangOptions::SSPReq); break;
1698  }
1699 
1700  // Parse -fsanitize= arguments.
1701  parseSanitizerKinds("-fsanitize=", Args.getAllArgValues(OPT_fsanitize_EQ),
1702  Diags, Opts.Sanitize);
1703  // -fsanitize-address-field-padding=N has to be a LangOpt, parse it here.
1704  Opts.SanitizeAddressFieldPadding =
1705  getLastArgIntValue(Args, OPT_fsanitize_address_field_padding, 0, Diags);
1706  Opts.SanitizerBlacklistFiles = Args.getAllArgValues(OPT_fsanitize_blacklist);
1707 }
1708 
1709 static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
1710  FileManager &FileMgr,
1711  DiagnosticsEngine &Diags) {
1712  using namespace options;
1713  Opts.ImplicitPCHInclude = Args.getLastArgValue(OPT_include_pch);
1714  Opts.ImplicitPTHInclude = Args.getLastArgValue(OPT_include_pth);
1715  if (const Arg *A = Args.getLastArg(OPT_token_cache))
1716  Opts.TokenCache = A->getValue();
1717  else
1718  Opts.TokenCache = Opts.ImplicitPTHInclude;
1719  Opts.UsePredefines = !Args.hasArg(OPT_undef);
1720  Opts.DetailedRecord = Args.hasArg(OPT_detailed_preprocessing_record);
1721  Opts.DisablePCHValidation = Args.hasArg(OPT_fno_validate_pch);
1722 
1723  Opts.DumpDeserializedPCHDecls = Args.hasArg(OPT_dump_deserialized_pch_decls);
1724  for (const Arg *A : Args.filtered(OPT_error_on_deserialized_pch_decl))
1725  Opts.DeserializedPCHDeclsToErrorOn.insert(A->getValue());
1726 
1727  if (const Arg *A = Args.getLastArg(OPT_preamble_bytes_EQ)) {
1728  StringRef Value(A->getValue());
1729  size_t Comma = Value.find(',');
1730  unsigned Bytes = 0;
1731  unsigned EndOfLine = 0;
1732 
1733  if (Comma == StringRef::npos ||
1734  Value.substr(0, Comma).getAsInteger(10, Bytes) ||
1735  Value.substr(Comma + 1).getAsInteger(10, EndOfLine))
1736  Diags.Report(diag::err_drv_preamble_format);
1737  else {
1738  Opts.PrecompiledPreambleBytes.first = Bytes;
1739  Opts.PrecompiledPreambleBytes.second = (EndOfLine != 0);
1740  }
1741  }
1742 
1743  // Add macros from the command line.
1744  for (const Arg *A : Args.filtered(OPT_D, OPT_U)) {
1745  if (A->getOption().matches(OPT_D))
1746  Opts.addMacroDef(A->getValue());
1747  else
1748  Opts.addMacroUndef(A->getValue());
1749  }
1750 
1751  Opts.MacroIncludes = Args.getAllArgValues(OPT_imacros);
1752 
1753  // Add the ordered list of -includes.
1754  for (const Arg *A : Args.filtered(OPT_include))
1755  Opts.Includes.emplace_back(A->getValue());
1756 
1757  for (const Arg *A : Args.filtered(OPT_chain_include))
1758  Opts.ChainedIncludes.emplace_back(A->getValue());
1759 
1760  // Include 'altivec.h' if -faltivec option present
1761  if (Args.hasArg(OPT_faltivec))
1762  Opts.Includes.emplace_back("altivec.h");
1763 
1764  for (const Arg *A : Args.filtered(OPT_remap_file)) {
1765  std::pair<StringRef, StringRef> Split = StringRef(A->getValue()).split(';');
1766 
1767  if (Split.second.empty()) {
1768  Diags.Report(diag::err_drv_invalid_remap_file) << A->getAsString(Args);
1769  continue;
1770  }
1771 
1772  Opts.addRemappedFile(Split.first, Split.second);
1773  }
1774 
1775  if (Arg *A = Args.getLastArg(OPT_fobjc_arc_cxxlib_EQ)) {
1776  StringRef Name = A->getValue();
1777  unsigned Library = llvm::StringSwitch<unsigned>(Name)
1778  .Case("libc++", ARCXX_libcxx)
1779  .Case("libstdc++", ARCXX_libstdcxx)
1780  .Case("none", ARCXX_nolib)
1781  .Default(~0U);
1782  if (Library == ~0U)
1783  Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Name;
1784  else
1786  }
1787 }
1788 
1790  ArgList &Args,
1792  using namespace options;
1793 
1794  switch (Action) {
1795  case frontend::ASTDeclList:
1796  case frontend::ASTDump:
1797  case frontend::ASTPrint:
1798  case frontend::ASTView:
1800  case frontend::EmitBC:
1801  case frontend::EmitHTML:
1802  case frontend::EmitLLVM:
1805  case frontend::EmitObj:
1806  case frontend::FixIt:
1808  case frontend::GeneratePCH:
1809  case frontend::GeneratePTH:
1812  case frontend::VerifyPCH:
1815  case frontend::RewriteObjC:
1816  case frontend::RewriteTest:
1817  case frontend::RunAnalysis:
1819  Opts.ShowCPP = 0;
1820  break;
1821 
1823  case frontend::DumpTokens:
1824  case frontend::InitOnly:
1829  Opts.ShowCPP = !Args.hasArg(OPT_dM);
1830  break;
1831  }
1832 
1833  Opts.ShowComments = Args.hasArg(OPT_C);
1834  Opts.ShowLineMarkers = !Args.hasArg(OPT_P);
1835  Opts.ShowMacroComments = Args.hasArg(OPT_CC);
1836  Opts.ShowMacros = Args.hasArg(OPT_dM) || Args.hasArg(OPT_dD);
1837  Opts.RewriteIncludes = Args.hasArg(OPT_frewrite_includes);
1838  Opts.UseLineDirectives = Args.hasArg(OPT_fuse_line_directives);
1839 }
1840 
1841 static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args) {
1842  using namespace options;
1843  Opts.ABI = Args.getLastArgValue(OPT_target_abi);
1844  Opts.CPU = Args.getLastArgValue(OPT_target_cpu);
1845  Opts.FPMath = Args.getLastArgValue(OPT_mfpmath);
1846  Opts.FeaturesAsWritten = Args.getAllArgValues(OPT_target_feature);
1847  Opts.LinkerVersion = Args.getLastArgValue(OPT_target_linker_version);
1848  Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple));
1849  Opts.Reciprocals = Args.getAllArgValues(OPT_mrecip_EQ);
1850  // Use the default target triple if unspecified.
1851  if (Opts.Triple.empty())
1852  Opts.Triple = llvm::sys::getDefaultTargetTriple();
1853 }
1854 
1856  const char *const *ArgBegin,
1857  const char *const *ArgEnd,
1858  DiagnosticsEngine &Diags) {
1859  bool Success = true;
1860 
1861  // Parse the arguments.
1862  std::unique_ptr<OptTable> Opts(createDriverOptTable());
1863  const unsigned IncludedFlagsBitmask = options::CC1Option;
1864  unsigned MissingArgIndex, MissingArgCount;
1865  InputArgList Args =
1866  Opts->ParseArgs(llvm::makeArrayRef(ArgBegin, ArgEnd), MissingArgIndex,
1867  MissingArgCount, IncludedFlagsBitmask);
1868 
1869  // Check for missing argument error.
1870  if (MissingArgCount) {
1871  Diags.Report(diag::err_drv_missing_argument)
1872  << Args.getArgString(MissingArgIndex) << MissingArgCount;
1873  Success = false;
1874  }
1875 
1876  // Issue errors on unknown arguments.
1877  for (const Arg *A : Args.filtered(OPT_UNKNOWN)) {
1878  Diags.Report(diag::err_drv_unknown_argument) << A->getAsString(Args);
1879  Success = false;
1880  }
1881 
1882  Success &= ParseAnalyzerArgs(*Res.getAnalyzerOpts(), Args, Diags);
1883  Success &= ParseMigratorArgs(Res.getMigratorOpts(), Args);
1885  Success &= ParseDiagnosticArgs(Res.getDiagnosticOpts(), Args, &Diags);
1888  // FIXME: We shouldn't have to pass the DashX option around here
1889  InputKind DashX = ParseFrontendArgs(Res.getFrontendOpts(), Args, Diags);
1890  ParseTargetArgs(Res.getTargetOpts(), Args);
1891  Success &= ParseCodeGenArgs(Res.getCodeGenOpts(), Args, DashX, Diags,
1892  Res.getTargetOpts());
1894  if (DashX != IK_AST && DashX != IK_LLVM_IR) {
1895  ParseLangArgs(*Res.getLangOpts(), Args, DashX, Diags);
1897  Res.getLangOpts()->ObjCExceptions = 1;
1898  }
1899  // FIXME: ParsePreprocessorArgs uses the FileManager to read the contents of
1900  // PCH file and find the original header name. Remove the need to do that in
1901  // ParsePreprocessorArgs and remove the FileManager
1902  // parameters from the function and the "FileManager.h" #include.
1903  FileManager FileMgr(Res.getFileSystemOpts());
1904  ParsePreprocessorArgs(Res.getPreprocessorOpts(), Args, FileMgr, Diags);
1907  return Success;
1908 }
1909 
1910 namespace {
1911 
1912  class ModuleSignature {
1914  unsigned CurBit;
1915  uint64_t CurValue;
1916 
1917  public:
1918  ModuleSignature() : CurBit(0), CurValue(0) { }
1919 
1920  void add(uint64_t Value, unsigned Bits);
1921  void add(StringRef Value);
1922  void flush();
1923 
1924  llvm::APInt getAsInteger() const;
1925  };
1926 }
1927 
1928 void ModuleSignature::add(uint64_t Value, unsigned int NumBits) {
1929  CurValue |= Value << CurBit;
1930  if (CurBit + NumBits < 64) {
1931  CurBit += NumBits;
1932  return;
1933  }
1934 
1935  // Add the current word.
1936  Data.push_back(CurValue);
1937 
1938  if (CurBit)
1939  CurValue = Value >> (64-CurBit);
1940  else
1941  CurValue = 0;
1942  CurBit = (CurBit+NumBits) & 63;
1943 }
1944 
1945 void ModuleSignature::flush() {
1946  if (CurBit == 0)
1947  return;
1948 
1949  Data.push_back(CurValue);
1950  CurBit = 0;
1951  CurValue = 0;
1952 }
1953 
1954 void ModuleSignature::add(StringRef Value) {
1955  for (StringRef::iterator I = Value.begin(), IEnd = Value.end(); I != IEnd;++I)
1956  add(*I, 8);
1957 }
1958 
1959 llvm::APInt ModuleSignature::getAsInteger() const {
1960  return llvm::APInt(Data.size() * 64, Data);
1961 }
1962 
1964  // Note: For QoI reasons, the things we use as a hash here should all be
1965  // dumped via the -module-info flag.
1966  using llvm::hash_code;
1967  using llvm::hash_value;
1968  using llvm::hash_combine;
1969 
1970  // Start the signature with the compiler version.
1971  // FIXME: We'd rather use something more cryptographically sound than
1972  // CityHash, but this will do for now.
1973  hash_code code = hash_value(getClangFullRepositoryVersion());
1974 
1975  // Extend the signature with the language options
1976 #define LANGOPT(Name, Bits, Default, Description) \
1977  code = hash_combine(code, LangOpts->Name);
1978 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
1979  code = hash_combine(code, static_cast<unsigned>(LangOpts->get##Name()));
1980 #define BENIGN_LANGOPT(Name, Bits, Default, Description)
1981 #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description)
1982 #include "clang/Basic/LangOptions.def"
1983 
1984  for (StringRef Feature : LangOpts->ModuleFeatures)
1985  code = hash_combine(code, Feature);
1986 
1987  // Extend the signature with the target options.
1988  code = hash_combine(code, TargetOpts->Triple, TargetOpts->CPU,
1989  TargetOpts->ABI);
1990  for (unsigned i = 0, n = TargetOpts->FeaturesAsWritten.size(); i != n; ++i)
1991  code = hash_combine(code, TargetOpts->FeaturesAsWritten[i]);
1992 
1993  // Extend the signature with preprocessor options.
1994  const PreprocessorOptions &ppOpts = getPreprocessorOpts();
1995  const HeaderSearchOptions &hsOpts = getHeaderSearchOpts();
1996  code = hash_combine(code, ppOpts.UsePredefines, ppOpts.DetailedRecord);
1997 
1998  for (std::vector<std::pair<std::string, bool/*isUndef*/> >::const_iterator
1999  I = getPreprocessorOpts().Macros.begin(),
2000  IEnd = getPreprocessorOpts().Macros.end();
2001  I != IEnd; ++I) {
2002  // If we're supposed to ignore this macro for the purposes of modules,
2003  // don't put it into the hash.
2004  if (!hsOpts.ModulesIgnoreMacros.empty()) {
2005  // Check whether we're ignoring this macro.
2006  StringRef MacroDef = I->first;
2007  if (hsOpts.ModulesIgnoreMacros.count(MacroDef.split('=').first))
2008  continue;
2009  }
2010 
2011  code = hash_combine(code, I->first, I->second);
2012  }
2013 
2014  // Extend the signature with the sysroot.
2015  code = hash_combine(code, hsOpts.Sysroot, hsOpts.UseBuiltinIncludes,
2017  hsOpts.UseStandardCXXIncludes,
2018  hsOpts.UseLibcxx);
2019  code = hash_combine(code, hsOpts.ResourceDir);
2020 
2021  // Extend the signature with the user build path.
2022  code = hash_combine(code, hsOpts.ModuleUserBuildPath);
2023 
2024  // Darwin-specific hack: if we have a sysroot, use the contents and
2025  // modification time of
2026  // $sysroot/System/Library/CoreServices/SystemVersion.plist
2027  // as part of the module hash.
2028  if (!hsOpts.Sysroot.empty()) {
2029  SmallString<128> systemVersionFile;
2030  systemVersionFile += hsOpts.Sysroot;
2031  llvm::sys::path::append(systemVersionFile, "System");
2032  llvm::sys::path::append(systemVersionFile, "Library");
2033  llvm::sys::path::append(systemVersionFile, "CoreServices");
2034  llvm::sys::path::append(systemVersionFile, "SystemVersion.plist");
2035 
2036  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer =
2037  llvm::MemoryBuffer::getFile(systemVersionFile);
2038  if (buffer) {
2039  code = hash_combine(code, buffer.get()->getBuffer());
2040 
2041  struct stat statBuf;
2042  if (stat(systemVersionFile.c_str(), &statBuf) == 0)
2043  code = hash_combine(code, statBuf.st_mtime);
2044  }
2045  }
2046 
2047  return llvm::APInt(64, code).toString(36, /*Signed=*/false);
2048 }
2049 
2050 namespace clang {
2051 
2052 template<typename IntTy>
2053 static IntTy getLastArgIntValueImpl(const ArgList &Args, OptSpecifier Id,
2054  IntTy Default,
2055  DiagnosticsEngine *Diags) {
2056  IntTy Res = Default;
2057  if (Arg *A = Args.getLastArg(Id)) {
2058  if (StringRef(A->getValue()).getAsInteger(10, Res)) {
2059  if (Diags)
2060  Diags->Report(diag::err_drv_invalid_int_value) << A->getAsString(Args)
2061  << A->getValue();
2062  }
2063  }
2064  return Res;
2065 }
2066 
2067 
2068 // Declared in clang/Frontend/Utils.h.
2069 int getLastArgIntValue(const ArgList &Args, OptSpecifier Id, int Default,
2070  DiagnosticsEngine *Diags) {
2071  return getLastArgIntValueImpl<int>(Args, Id, Default, Diags);
2072 }
2073 
2074 uint64_t getLastArgUInt64Value(const ArgList &Args, OptSpecifier Id,
2075  uint64_t Default,
2076  DiagnosticsEngine *Diags) {
2077  return getLastArgIntValueImpl<uint64_t>(Args, Id, Default, Diags);
2078 }
2079 
2080 void BuryPointer(const void *Ptr) {
2081  // This function may be called only a small fixed amount of times per each
2082  // invocation, otherwise we do actually have a leak which we want to report.
2083  // If this function is called more than kGraveYardMaxSize times, the pointers
2084  // will not be properly buried and a leak detector will report a leak, which
2085  // is what we want in such case.
2086  static const size_t kGraveYardMaxSize = 16;
2087  LLVM_ATTRIBUTE_UNUSED static const void *GraveYard[kGraveYardMaxSize];
2088  static std::atomic<unsigned> GraveYardSize;
2089  unsigned Idx = GraveYardSize++;
2090  if (Idx >= kGraveYardMaxSize)
2091  return;
2092  GraveYard[Idx] = Ptr;
2093 }
2094 
2097  DiagnosticsEngine &Diags) {
2098  if (CI.getHeaderSearchOpts().VFSOverlayFiles.empty())
2099  return vfs::getRealFileSystem();
2100 
2103  // earlier vfs files are on the bottom
2104  for (const std::string &File : CI.getHeaderSearchOpts().VFSOverlayFiles) {
2105  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> Buffer =
2106  llvm::MemoryBuffer::getFile(File);
2107  if (!Buffer) {
2108  Diags.Report(diag::err_missing_vfs_overlay_file) << File;
2110  }
2111 
2113  vfs::getVFSFromYAML(std::move(Buffer.get()), /*DiagHandler*/ nullptr);
2114  if (!FS.get()) {
2115  Diags.Report(diag::err_invalid_vfs_overlay) << File;
2117  }
2118  Overlay->pushOverlay(FS);
2119  }
2120  return Overlay;
2121 }
2122 } // end namespace clang
HeaderSearchOptions & getHeaderSearchOpts()
static Visibility parseVisibility(Arg *arg, ArgList &args, DiagnosticsEngine &diags)
Attempt to parse a visibility value out of the given argument.
Expand macros but not #includes.
std::string OutputFile
The output file, if any.
static void ParseFileSystemArgs(FileSystemOptions &Opts, ArgList &Args)
static void ParseCommentArgs(CommentOptions &Opts, ArgList &Args)
unsigned InlineMaxStackDepth
The inlining stack depth limit.
Paths for '#include <>' added by '-I'.
std::string ModuleDependencyOutputDir
The directory to copy module dependencies to when collecting them.
std::string ObjCMTWhiteListPath
std::string DwarfDebugFlags
std::string DOTOutputFile
The file to write GraphViz-formatted header dependencies to.
void addMacroUndef(StringRef Name)
std::vector< std::vector< std::string > > AddPluginArgs
Args to pass to the additional plugins.
Generate pre-compiled module.
unsigned UseLibcxx
Use libc++ instead of the default libstdc++.
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:26
unsigned ImplicitModuleMaps
Implicit module maps. This option is enabld by default when modules is enabled.
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:115
static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args)
Defines the clang::FileManager interface and associated types.
Parse and perform semantic analysis.
ObjCXXARCStandardLibraryKind
Enumerate the kinds of standard library that.
std::string ModuleUserBuildPath
The directory used for a user build.
static StringRef getCodeModel(ArgList &Args, DiagnosticsEngine &Diags)
Emit a .bc file.
SanitizerSet Sanitize
Set of enabled sanitizers.
Definition: LangOptions.h:79
DependencyOutputOptions & getDependencyOutputOpts()
IntrusiveRefCntPtr< FileSystem > getRealFileSystem()
Gets an vfs::FileSystem for the 'real' file system, as seen by the operating system.
std::shared_ptr< llvm::Regex > OptimizationRemarkMissedPattern
static unsigned getOptimizationLevel(ArgList &Args, InputKind IK, DiagnosticsEngine &Diags)
bool isGNUMode() const
isGNUMode - Language includes GNU extensions.
Definition: LangStandard.h:86
unsigned IncludeModuleFiles
Include module file dependencies.
Parse ASTs and print them.
Like System, but only used for C++.
std::vector< std::string > Includes
static bool parseDiagnosticLevelMask(StringRef FlagName, const std::vector< std::string > &Levels, DiagnosticsEngine *Diags, DiagnosticLevelMask &M)
Optional< unsigned > getMinor() const
Retrieve the minor version number, if provided.
Definition: VersionTuple.h:72
unsigned visualizeExplodedGraphWithGraphViz
std::string SampleProfileFile
Name of the profile file to use with -fprofile-sample-use.
Show all overloads.
Like System, but only used for ObjC++.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1118
static bool CreateFromArgs(CompilerInvocation &Res, const char *const *ArgBegin, const char *const *ArgEnd, DiagnosticsEngine &Diags)
Create a compiler invocation from a list of input options.
Enable migration of ObjC methods to 'instancetype'.
bool allowsWeak() const
Does this runtime allow the use of __weak?
Definition: ObjCRuntime.h:180
#define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN)
static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, DiagnosticsEngine &Diags, const TargetOptions &TargetOpts)
std::vector< std::string > RewriteMapFiles
Set of files definining the rules for the symbol rewriting.
bool hasLineComments() const
Language supports '//' comments.
Definition: LangStandard.h:59
Options for controlling comment parsing.
static const LangStandard & getLangStandardForKind(Kind K)
std::string ASTDumpFilter
If given, filter dumped AST Decl nodes by this substring.
std::string getModuleHash() const
Retrieve a module hash string that is suitable for uniquely identifying the conditions under which th...
static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, DiagnosticsEngine &Diags)
Options for controlling the target.
Definition: TargetOptions.h:24
void AddPath(StringRef Path, frontend::IncludeDirGroup Group, bool IsFramework, bool IgnoreSysRoot)
AddPath - Add the Path path to the specified Group list.
bool allowsARC() const
Does this runtime allow ARC at all?
Definition: ObjCRuntime.h:134
void addRemappedFile(StringRef From, StringRef To)
std::vector< std::string > PluginArgs
Args to pass to the plugin.
std::string FixItSuffix
If given, the new suffix for fix-it rewritten files.
std::string SplitDwarfFile
Like System, but searched after the system directories.
BlockCommandNamesTy BlockCommandNames
Command names to treat as block commands in comments. Should not include the leading backslash...
std::string ModuleCachePath
The directory used for the module cache.
std::string DebugPass
Enable additional debugging information.
SanitizerSet SanitizeRecover
Parse and apply any fixits to the source.
std::vector< std::string > Reciprocals
Definition: TargetOptions.h:49
std::vector< std::string > CudaGpuBinaryFileNames
void AddSystemHeaderPrefix(StringRef Prefix, bool IsSystemHeader)
IntrusiveRefCntPtr< FileSystem > getVFSFromYAML(std::unique_ptr< llvm::MemoryBuffer > Buffer, llvm::SourceMgr::DiagHandlerTy DiagHandler, void *DiagContext=nullptr, IntrusiveRefCntPtr< FileSystem > ExternalFS=getRealFileSystem())
Gets a FileSystem for a virtual file system described in YAML format.
std::string FPMath
If given, the unit to use for floating point math.
Definition: TargetOptions.h:34
bool isCPlusPlus11() const
isCPlusPlus11 - Language is a C++11 variant (or later).
Definition: LangStandard.h:74
static std::shared_ptr< llvm::Regex > GenerateOptimizationRemarkRegex(DiagnosticsEngine &Diags, ArgList &Args, Arg *RpassArg)
Create a new Regex instance out of the string value in RpassArg. It returns a pointer to the newly ge...
bool isCPlusPlus() const
isCPlusPlus - Language is a C++ variant.
Definition: LangStandard.h:71
unsigned IncludeSystemHeaders
Include system header dependencies.
llvm::SetVector< std::string > ModulesIgnoreMacros
The set of macro names that should be ignored for the purposes of computing the module hash...
Don't generate debug info.
Translate input source into HTML.
unsigned DetailedRecord
Whether we should maintain a detailed record of all macro definitions and expansions.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
unsigned eagerlyAssumeBinOpBifurcation
The flag regulates if we should eagerly assume evaluations of conditionals, thus, bifurcating the pat...
std::vector< std::string > ASTMergeFiles
The list of AST files to merge.
Enable migration to add conforming protocols.
std::string CodeModel
The code model to use (-mcmodel).
Print DeclContext and their Decls.
A file system that allows overlaying one AbstractFileSystem on top of another.
Generate LLVM IR, but do not emit anything.
static bool ParseAnalyzerArgs(AnalyzerOptions &Opts, ArgList &Args, DiagnosticsEngine &Diags)
CodeGenOptions & getCodeGenOpts()
Enable annotation of ObjCMethods of all kinds.
static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts, ArgList &Args)
Visibility
Describes the different kinds of visibility that a declaration may have.
Definition: Visibility.h:32
std::vector< std::string > VFSOverlayFiles
The set of user-provided virtual filesystem overlay files.
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:135
std::vector< std::string > Warnings
std::vector< std::pair< std::string, bool > > CheckersControlList
Pair of checker name and enable/disable.
unsigned DisableModuleHash
Whether we should disable the use of the hash string within the module cache.
AnalysisStores
AnalysisStores - Set of available analysis store models.
bool DisablePCHValidation
When true, disables most of the normal validation performed on precompiled headers.
static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args, FileManager &FileMgr, DiagnosticsEngine &Diags)
unsigned FixAndRecompile
Apply fixes and recompile.
std::string FloatABI
The ABI to use for passing floating point arguments.
std::vector< std::string > ModuleFeatures
The names of any features to enable in module 'requires' decls in addition to the hard-coded list in ...
Definition: LangOptions.h:107
PreprocessorOutputOptions & getPreprocessorOutputOpts()
std::string ThreadModel
The thread model to use.
FrontendOptions & getFrontendOpts()
AnnotatingParser & P
std::vector< std::string > DependentLibraries
A list of dependent libraries.
static IntTy getLastArgIntValueImpl(const ArgList &Args, OptSpecifier Id, IntTy Default, DiagnosticsEngine *Diags)
MigratorOptions & getMigratorOpts()
char CoverageVersion[4]
The version string to put into coverage files.
Dump out preprocessed tokens.
std::string CurrentModule
The name of the current module.
Definition: LangOptions.h:96
AnalysisDiagClients AnalysisDiagOpt
Enable migration to modern ObjC literals.
std::vector< std::string > ChainedIncludes
Headers that will be converted to chained PCHs in memory.
void AddVFSOverlayFile(StringRef Name)
std::string LimitFloatPrecision
The float precision limit to use, if non-empty.
bool isCPlusPlus14() const
isCPlusPlus14 - Language is a C++14 variant (or later).
Definition: LangStandard.h:77
uint64_t getLastArgUInt64Value(const llvm::opt::ArgList &Args, llvm::opt::OptSpecifier Id, uint64_t Default, DiagnosticsEngine *Diags=nullptr)
unsigned UsePredefines
Initialize the preprocessor with the compiler and target specific predefines.
AnalysisInliningMode InliningMode
The mode of function selection used during inlining.
CommentOptions CommentOpts
Options for parsing comments.
Definition: LangOptions.h:110
static std::string GetResourcesPath(const char *Argv0, void *MainAddr)
Get the directory where the compiler headers reside, relative to the compiler binary (found by the pa...
unsigned ModuleCachePruneInterval
The interval (in seconds) between pruning operations.
bool hasDigraphs() const
hasDigraphs - Language supports digraphs.
Definition: LangStandard.h:83
std::vector< std::string > Plugins
The list of plugins to load.
Show just the "best" overload candidates.
unsigned IncludeCodePatterns
Show code patterns in code completion results.
std::string WorkingDir
If set, paths are resolved as if the working directory was set to the value of WorkingDir.
std::set< std::string > DeserializedPCHDeclsToErrorOn
This is a set of names for decls that we do not want to be deserialized, and we emit an error if they...
unsigned RewriteIncludes
Preprocess include directives only.
std::string LinkerVersion
If given, the version string of the linker in use.
Definition: TargetOptions.h:40
Only execute frontend initialization.
bool isCPlusPlus1z() const
isCPlusPlus1z - Language is a C++17 variant (or later).
Definition: LangStandard.h:80
Defines version macros and version-related utility functions for Clang.
std::string RelocationModel
The name of the relocation model to use.
Print the "preamble" of the input file.
Enable migration to modern ObjC property.
IntrusiveRefCntPtr< vfs::FileSystem > createVFSFromCompilerInvocation(const CompilerInvocation &CI, DiagnosticsEngine &Diags)
bool isC89() const
isC89 - Language is a superset of C89.
Definition: LangStandard.h:62
bool tryParse(StringRef input)
Try to parse an Objective-C runtime specification from the given string.
Definition: ObjCRuntime.cpp:43
unsigned ShowHeaderIncludes
Show header inclusions (-H).
std::shared_ptr< llvm::Regex > OptimizationRemarkPattern
Rewriter playground.
unsigned UseBuiltinIncludes
Include the compiler builtin includes.
AnalysisInliningMode
AnalysisInlineFunctionSelection - Set of inlining function selection heuristics.
unsigned ShowMacros
Print macro definitions.
clang::ObjCRuntime ObjCRuntime
Definition: LangOptions.h:85
static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts, ArgList &Args, frontend::ActionKind Action)
unsigned FixOnlyWarnings
Apply fixes only for warnings.
unsigned ModulesValidateOncePerBuildSession
If true, skip verifying input files used by modules if the module was already verified during this bu...
Enable migration to modern ObjC readwrite property.
bool hasImplicitInt() const
hasImplicitInt - Language allows variables to be typed as int implicitly.
Definition: LangStandard.h:92
static void addDiagnosticArgs(ArgList &Args, OptSpecifier Group, OptSpecifier GroupWithValue, std::vector< std::string > &Diagnostics)
uint64_t BuildSessionTimestamp
The time in seconds when the build session started.
std::string CPU
If given, the name of the target CPU to generate code for.
Definition: TargetOptions.h:31
bool isC99() const
isC99 - Language is a superset of C99.
Definition: LangStandard.h:65
void set(SanitizerMask K, bool Value)
Enable or disable a certain (single) sanitizer.
Definition: Sanitizers.h:61
Enable inferring NS_DESIGNATED_INITIALIZER for ObjC methods.
bool ParseDiagnosticArgs(DiagnosticOptions &Opts, llvm::opt::ArgList &Args, DiagnosticsEngine *Diags=nullptr)
Fill out Opts based on the options given in Args.
std::string ABI
If given, the name of the target ABI to use.
Definition: TargetOptions.h:37
AnalysisConstraints
AnalysisConstraints - Set of available constraint models.
bool isC11() const
isC11 - Language is a superset of C11.
Definition: LangStandard.h:68
AnalysisStores AnalysisStoreOpt
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
unsigned UseStandardSystemIncludes
Include the system standard include search directories.
Generate machine code, but don't emit anything.
std::vector< std::string > ModuleFiles
The list of additional prebuilt module files to load before processing the input. ...
ParsedSourceLocation CodeCompletionAt
If given, enable code completion at the provided location.
std::string ImplicitPCHInclude
The implicit PCH included at the start of the translation unit, or empty.
Options for controlling the compiler diagnostics engine.
std::vector< FrontendInputFile > Inputs
The input files and their types.
unsigned ModulesValidateSystemHeaders
Whether to validate system input files when a module is loaded.
AnalyzerOptionsRef getAnalyzerOpts() const
ConfigTable Config
A key-value table of use-specified configuration values.
std::string DiagnosticSerializationFile
The file to serialize diagnostics to (non-appending).
#define ANALYSIS_CONSTRAINTS(NAME, CMDFLAG, DESC, CREATFN)
Parse ASTs and view them in Graphviz.
std::vector< std::string > Remarks
annotate property with NS_RETURNS_INNER_POINTER
Enable migration to modern ObjC readonly property.
unsigned visualizeExplodedGraphWithUbiGraph
Parse ASTs and list Decl nodes.
unsigned Verbose
Whether header search information should be output as for -v.
std::string getClangFullRepositoryVersion()
Retrieves the full repository version that is an amalgamation of the information in getClangRepositor...
Definition: Version.cpp:90
std::string InstrProfileInput
Name of the profile file to use as input for -fprofile-instr-use.
unsigned getMajor() const
Retrieve the major version number.
Definition: VersionTuple.h:69
Enable migration to modern ObjC subscripting.
Load and verify that a PCH file is usable.
static void setLangDefaults(LangOptions &Opts, InputKind IK, LangStandard::Kind LangStd=LangStandard::lang_unspecified)
Set language defaults for the given input language and language standard in the given LangOptions obj...
SanitizerSet SanitizeTrap
Set of sanitizer checks that trap rather than diagnose.
unsigned UseLineDirectives
Use #line instead of GCC-style # N.
Like System, but only used for ObjC.
unsigned ShowVersion
Show the -version text.
std::string LinkBitcodeFile
The name of the bitcode file to link before optzns.
std::shared_ptr< llvm::Regex > OptimizationRemarkAnalysisPattern
std::vector< std::string > FeaturesAsWritten
The list of target specific features to enable or disable, as written on the command line...
Definition: TargetOptions.h:43
void addMacroDef(StringRef Name)
'#include ""' paths, added by 'gcc -iquote'.
std::vector< std::string > MacroIncludes
unsigned ShowHelp
Show the -help text.
std::string OverrideRecordLayoutsFile
File name of the file that will provide record layouts (in the format produced by -fdump-record-layou...
unsigned FixToTemporaries
Apply fixes to temporary files.
building frameworks.
unsigned maxBlockVisitOnPath
The maximum number of times the analyzer visits a block.
unsigned DisableAllChecks
Disable all analyzer checks.
std::string OutputFile
The file to write dependency output to.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T-> getSizeExpr()))
DependencyOutputFormat OutputFormat
The format for the dependency file.
uint64_t SanitizerMask
Definition: Sanitizers.h:24
unsigned IncludeGlobals
Show top-level decls in code completion results.
std::string OverflowHandler
The name of the handler function to be called when -ftrapv is specified.
Definition: LangOptions.h:93
bool tryParse(StringRef string)
Try to parse the given string as a version number.
static ParsedSourceLocation FromString(StringRef Str)
PreprocessorOptions & getPreprocessorOpts()
frontend::ActionKind ProgramAction
The frontend action to perform.
Enable migration to NS_ENUM/NS_OPTIONS macros.
std::string ARCMTMigrateReportOut
Like System, but only used for C.
AnalysisConstraints AnalysisConstraintsOpt
Helper class for holding the data necessary to invoke the compiler.
DiagnosticOptions & getDiagnosticOpts() const
std::string DebugCompilationDir
The string to embed in debug information as the current working directory.
std::string AnalyzeSpecificFunction
enum clang::FrontendOptions::@156 ARCMTAction
FrontendOptions - Options for controlling the behavior of the frontend.
static bool ParseMigratorArgs(MigratorOptions &Opts, ArgList &Args)
SanitizerMask parseSanitizerValue(StringRef Value, bool AllowGroups)
Definition: Sanitizers.cpp:20
std::string ImplementationOfModule
The name of the module that the translation unit is an implementation of. Prevents semantic imports...
Definition: LangOptions.h:101
Run a plugin action,.
static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args)
unsigned IncludeBriefComments
Show brief documentation comments in code completion results.
void BuryPointer(const void *Ptr)
Parse ASTs and dump them.
CodeCompleteOptions CodeCompleteOpts
std::vector< std::string > AddPluginActions
The list of plugin actions to run in addition to the normal action.
Optional< unsigned > getSubminor() const
Retrieve the subminor version number, if provided.
Definition: VersionTuple.h:79
ObjCXXARCStandardLibraryKind ObjCXXARCStandardLibrary
The Objective-C++ ARC standard library that we should support, by providing appropriate definitions t...
AnalysisPurgeMode
AnalysisPurgeModes - Set of available strategies for dead symbol removal.
llvm::opt::OptTable * createDriverOptTable()
Keeps track of options that affect how file operations are performed.
unsigned DisableFree
Disable memory freeing on exit.
Generate pre-compiled header.
int getLastArgIntValue(const llvm::opt::ArgList &Args, llvm::opt::OptSpecifier Id, int Default, DiagnosticsEngine *Diags=nullptr)
X
Definition: SemaDecl.cpp:11429
Kind getKind() const
Definition: ObjCRuntime.h:71
unsigned ShowMacroComments
Show comments, even in macros.
Enable converting setter/getter expressions to property-dot syntx.
unsigned NoRetryExhausted
Do not re-analyze paths leading to exhausted nodes with a different strategy. We get better code cove...
unsigned ModuleCachePruneAfter
The time (in seconds) after which an unused module file will be considered unused and will...
unsigned IncludeMacros
Show macros in code completion results.
std::string ActionName
The name of the action to run when using a plugin action.
unsigned ShowLineMarkers
Show #line markers.
FileSystemOptions & getFileSystemOpts()
static unsigned getOptimizationLevelSize(ArgList &Args)
Run one or more source code analyses.
#define LANGSTANDARD(id, name, desc, features)
std::pair< unsigned, bool > PrecompiledPreambleBytes
If non-zero, the implicit PCH include is actually a precompiled preamble that covers this number of b...
#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN)
std::vector< std::string > LLVMArgs
A list of arguments to forward to LLVM's option processing; this should only be used for debugging an...
std::vector< std::string > Targets
std::string InstrProfileOutput
DiagnosticLevelMask
A bitmask representing the diagnostic levels used by VerifyDiagnosticConsumer.
Generate complete debug info.
Dump information about a module file.
unsigned ModuleMapFileHomeIsCwd
Set the 'home directory' of a module map file to the current working directory (or the home directory...
#define CLANG_VERSION_STRING
A string that describes the Clang version number, e.g., "1.0".
Definition: Version.h:30
unsigned AddMissingHeaderDeps
Add missing headers to dependency list.
std::vector< std::string > SanitizerBlacklistFiles
Paths to blacklist files specifying which objects (files, functions, variables) should not be instrum...
Definition: LangOptions.h:83
unsigned ShowCPP
Print normal preprocessed output.
std::vector< std::string > BackendOptions
A list of command-line options to forward to the LLVM backend.
prefer 'atomic' property over 'nonatomic'.
Generate pre-tokenized header.
static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, DiagnosticsEngine &Diags)
static InputKind getInputKindForExtension(StringRef Extension)
std::string ObjCConstantStringClass
Definition: LangOptions.h:87
use NS_NONATOMIC_IOSONLY for property 'atomic' attribute
#define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC)
AnalysisPurgeMode AnalysisPurgeOpt
unsigned PrintShowIncludes
Print cl.exe style /showIncludes info.
bool DumpDeserializedPCHDecls
Dump declarations that are deserialized from PCH, for testing.
unsigned UseStandardCXXIncludes
Include the system standard C++ library include search directories.
AnalysisDiagClients
#define ANALYSIS_PURGE(NAME, CMDFLAG, DESC)
std::string ModuleFormat
The module/pch container format.
static void parseSanitizerKinds(StringRef FlagName, const std::vector< std::string > &Sanitizers, DiagnosticsEngine &Diags, SanitizerSet &S)
std::string DiagnosticLogFile
The file to log diagnostic output to.
std::string TokenCache
If given, a PTH cache file to use for speeding up header parsing.
bool ParseAllComments
Treat ordinary comments as documentation comments.
bool hasHexFloats() const
hasHexFloats - Language supports hexadecimal float constants.
Definition: LangStandard.h:89
std::vector< std::string > ModuleMapFiles
The list of module map files to load before processing the input.