14 #include "clang/Config/config.h"
25 #include "llvm/ADT/Hashing.h"
26 #include "llvm/ADT/STLExtras.h"
27 #include "llvm/ADT/SmallVector.h"
28 #include "llvm/ADT/StringExtras.h"
29 #include "llvm/ADT/StringSwitch.h"
30 #include "llvm/ADT/Triple.h"
31 #include "llvm/Linker/Linker.h"
32 #include "llvm/Option/Arg.h"
33 #include "llvm/Option/ArgList.h"
34 #include "llvm/Option/OptTable.h"
35 #include "llvm/Option/Option.h"
36 #include "llvm/ProfileData/InstrProfReader.h"
37 #include "llvm/Support/CodeGen.h"
38 #include "llvm/Support/ErrorHandling.h"
39 #include "llvm/Support/FileSystem.h"
40 #include "llvm/Support/Host.h"
41 #include "llvm/Support/Path.h"
42 #include "llvm/Support/Process.h"
43 #include "llvm/Target/TargetOptions.h"
44 #include "llvm/Support/ScopedPrinter.h"
48 #include <system_error>
49 using namespace clang;
75 using namespace clang::driver;
76 using namespace clang::driver::options;
77 using namespace llvm::opt;
83 unsigned DefaultOpt = 0;
84 if (IK ==
IK_OpenCL && !Args.hasArg(OPT_cl_opt_disable))
87 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
88 if (A->getOption().matches(options::OPT_O0))
91 if (A->getOption().matches(options::OPT_Ofast))
94 assert (A->getOption().matches(options::OPT_O));
96 StringRef
S(A->getValue());
97 if (
S ==
"s" ||
S ==
"z" ||
S.empty())
107 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
108 if (A->getOption().matches(options::OPT_O)) {
109 switch (A->getValue()[0]) {
123 OptSpecifier GroupWithValue,
124 std::vector<std::string> &Diagnostics) {
125 for (Arg *A : Args.filtered(Group)) {
126 if (A->getOption().getKind() == Option::FlagClass) {
129 Diagnostics.push_back(A->getOption().getName().drop_front(1));
130 }
else if (A->getOption().matches(GroupWithValue)) {
132 Diagnostics.push_back(A->getOption().getName().drop_front(1).rtrim(
"=-"));
135 for (
const char *Arg : A->getValues())
136 Diagnostics.emplace_back(Arg);
142 std::vector<std::string> &Funcs) {
144 for (
const auto &Arg : Args) {
145 const Option &O = Arg->getOption();
146 if (O.matches(options::OPT_fno_builtin_)) {
147 const char *FuncName = Arg->getValue();
149 Values.push_back(FuncName);
152 Funcs.insert(Funcs.end(), Values.begin(), Values.end());
157 using namespace options;
159 if (Arg *A = Args.getLastArg(OPT_analyzer_store)) {
160 StringRef
Name = A->getValue();
163 .Case(CMDFLAG, NAME##Model)
164 #include "clang/StaticAnalyzer/Core/Analyses.def"
167 Diags.
Report(diag::err_drv_invalid_value)
168 << A->getAsString(Args) <<
Name;
175 if (Arg *A = Args.getLastArg(OPT_analyzer_constraints)) {
176 StringRef
Name = A->getValue();
179 .Case(CMDFLAG, NAME##Model)
180 #include "clang/StaticAnalyzer/Core/Analyses.def"
183 Diags.
Report(diag::err_drv_invalid_value)
184 << A->getAsString(Args) <<
Name;
191 if (Arg *A = Args.getLastArg(OPT_analyzer_output)) {
192 StringRef
Name = A->getValue();
195 .Case(CMDFLAG, PD_##NAME)
196 #include "clang/StaticAnalyzer/Core/Analyses.def"
199 Diags.
Report(diag::err_drv_invalid_value)
200 << A->getAsString(Args) <<
Name;
207 if (Arg *A = Args.getLastArg(OPT_analyzer_purge)) {
208 StringRef
Name = A->getValue();
212 #include "clang/StaticAnalyzer/Core/Analyses.def"
215 Diags.
Report(diag::err_drv_invalid_value)
216 << A->getAsString(Args) <<
Name;
223 if (Arg *A = Args.getLastArg(OPT_analyzer_inlining_mode)) {
224 StringRef
Name = A->getValue();
228 #include "clang/StaticAnalyzer/Core/Analyses.def"
231 Diags.
Report(diag::err_drv_invalid_value)
232 << A->getAsString(Args) <<
Name;
243 Args.hasArg(OPT_analyzer_viz_egraph_graphviz);
245 Args.hasArg(OPT_analyzer_viz_egraph_ubigraph);
247 Opts.
AnalyzeAll = Args.hasArg(OPT_analyzer_opt_analyze_headers);
250 Args.hasArg(OPT_analyzer_opt_analyze_nested_blocks);
254 Opts.
TrimGraph = Args.hasArg(OPT_trim_egraph);
257 Opts.
PrintStats = Args.hasArg(OPT_analyzer_stats);
264 Args.filtered(OPT_analyzer_checker, OPT_analyzer_disable_checker)) {
266 bool enable = (A->getOption().getID() == OPT_analyzer_checker);
269 StringRef checkerList = A->getValue();
271 checkerList.split(checkers,
",");
272 for (StringRef checker : checkers)
277 for (
const Arg *A : Args.filtered(OPT_analyzer_config)) {
281 StringRef configList = A->getValue();
283 configList.split(configVals,
",");
284 for (
unsigned i = 0, e = configVals.size(); i != e; ++i) {
286 std::tie(key, val) = configVals[i].split(
"=");
289 diag::err_analyzer_config_no_value) << configVals[i];
293 if (val.find(
'=') != StringRef::npos) {
295 diag::err_analyzer_config_multiple_values)
319 if (Arg *A = Args.getLastArg(OPT_mcode_model)) {
320 StringRef
Value = A->getValue();
321 if (Value ==
"small" || Value ==
"kernel" || Value ==
"medium" ||
324 Diags.
Report(diag::err_drv_invalid_value) << A->getAsString(Args) <<
Value;
331 static std::shared_ptr<llvm::Regex>
334 StringRef Val = RpassArg->getValue();
335 std::string RegexError;
336 std::shared_ptr<llvm::Regex> Pattern = std::make_shared<llvm::Regex>(Val);
337 if (!Pattern->isValid(RegexError)) {
338 Diags.
Report(diag::err_drv_optimization_remark_pattern)
339 << RegexError << RpassArg->getAsString(Args);
346 const std::vector<std::string> &Levels,
350 for (
const auto &
Level : Levels) {
352 llvm::StringSwitch<DiagnosticLevelMask>(
Level)
361 Diags->
Report(diag::err_drv_invalid_value) << FlagName <<
Level;
369 const std::vector<std::string> &Sanitizers,
371 for (
const auto &Sanitizer : Sanitizers) {
374 Diags.
Report(diag::err_drv_invalid_value) << FlagName << Sanitizer;
383 Arg *A = Args.getLastArg(OPT_fprofile_instrument_EQ);
386 StringRef
S = A->getValue();
387 unsigned I = llvm::StringSwitch<unsigned>(
S)
393 Diags.
Report(diag::err_drv_invalid_pgo_instrumentor) << A->getAsString(Args)
399 Opts.setProfileInstr(Instrumentor);
404 const Twine &ProfileName) {
407 if (
auto E = ReaderOrErr.takeError()) {
408 llvm::consumeError(std::move(
E));
412 std::unique_ptr<llvm::IndexedInstrProfReader> PGOReader =
413 std::move(ReaderOrErr.get());
414 if (PGOReader->isIRLevelProfile())
423 using namespace options;
425 llvm::Triple Triple = llvm::Triple(TargetOpts.
Triple);
429 unsigned MaxOptLevel = 3;
430 if (OptimizationLevel > MaxOptLevel) {
433 Diags.
Report(diag::warn_drv_optimization_value)
434 << Args.getLastArg(OPT_O)->getAsString(Args) <<
"-O" << MaxOptLevel;
435 OptimizationLevel = MaxOptLevel;
437 Opts.OptimizationLevel = OptimizationLevel;
444 Opts.NoInline = Args.hasArg(OPT_fno_inline);
445 if (Arg* InlineArg = Args.getLastArg(options::OPT_finline_functions,
446 options::OPT_finline_hint_functions,
447 options::OPT_fno_inline_functions)) {
448 const Option& InlineOpt = InlineArg->getOption();
449 if (InlineOpt.matches(options::OPT_finline_functions))
451 else if (InlineOpt.matches(options::OPT_finline_hint_functions))
454 Opts.setInlining(CodeGenOptions::OnlyAlwaysInlining);
457 if (Arg *A = Args.getLastArg(OPT_fveclib)) {
458 StringRef
Name = A->getValue();
459 if (Name ==
"Accelerate")
461 else if (Name ==
"none")
464 Diags.
Report(diag::err_drv_invalid_value) << A->getAsString(Args) <<
Name;
467 if (Arg *A = Args.getLastArg(OPT_debug_info_kind_EQ)) {
469 llvm::StringSwitch<unsigned>(A->getValue())
475 Diags.
Report(diag::err_drv_invalid_value) << A->getAsString(Args)
478 Opts.setDebugInfo(static_cast<codegenoptions::DebugInfoKind>(Val));
480 if (Arg *A = Args.getLastArg(OPT_debugger_tuning_EQ)) {
481 unsigned Val = llvm::StringSwitch<unsigned>(A->getValue())
482 .Case(
"gdb",
unsigned(llvm::DebuggerKind::GDB))
483 .Case(
"lldb",
unsigned(llvm::DebuggerKind::LLDB))
484 .Case(
"sce",
unsigned(llvm::DebuggerKind::SCE))
487 Diags.
Report(diag::err_drv_invalid_value) << A->getAsString(Args)
490 Opts.setDebuggerTuning(static_cast<llvm::DebuggerKind>(Val));
493 Opts.DebugColumnInfo = Args.hasArg(OPT_dwarf_column_info);
494 Opts.EmitCodeView = Args.hasArg(OPT_gcodeview);
495 Opts.WholeProgramVTables = Args.hasArg(OPT_fwhole_program_vtables);
496 Opts.LTOVisibilityPublicStd = Args.hasArg(OPT_flto_visibility_public_std);
498 Opts.DebugTypeExtRefs = Args.hasArg(OPT_dwarf_ext_refs);
499 Opts.DebugExplicitImport = Triple.isPS4CPU();
501 for (
const auto &Arg : Args.getAllArgValues(OPT_fdebug_prefix_map_EQ))
505 Args.getLastArg(OPT_emit_llvm_uselists, OPT_no_emit_llvm_uselists))
506 Opts.EmitLLVMUseLists = A->getOption().getID() == OPT_emit_llvm_uselists;
508 Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns);
509 Opts.DisableLLVMPasses = Args.hasArg(OPT_disable_llvm_passes);
510 Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
511 Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables);
512 Opts.UseRegisterSizedBitfieldAccess = Args.hasArg(
513 OPT_fuse_register_sized_bitfield_access);
514 Opts.RelaxedAliasing = Args.hasArg(OPT_relaxed_aliasing);
515 Opts.StructPathTBAA = !Args.hasArg(OPT_no_struct_path_tbaa);
517 Opts.MergeAllConstants = !Args.hasArg(OPT_fno_merge_all_constants);
518 Opts.NoCommon = Args.hasArg(OPT_fno_common);
519 Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float);
521 Opts.SimplifyLibCalls = !(Args.hasArg(OPT_fno_builtin) ||
522 Args.hasArg(OPT_ffreestanding));
523 if (Opts.SimplifyLibCalls)
526 Args.hasFlag(OPT_funroll_loops, OPT_fno_unroll_loops,
527 (Opts.OptimizationLevel > 1));
528 Opts.RerollLoops = Args.hasArg(OPT_freroll_loops);
530 Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as);
531 Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
536 Args.getLastArgValue(OPT_fprofile_instrument_path_EQ);
538 Args.getLastArgValue(OPT_fprofile_instrument_use_path_EQ);
542 Opts.CoverageMapping =
543 Args.hasFlag(OPT_fcoverage_mapping, OPT_fno_coverage_mapping,
false);
544 Opts.DumpCoverageMapping = Args.hasArg(OPT_dump_coverage_mapping);
545 Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose);
546 Opts.AssumeSaneOperatorNew = !Args.hasArg(OPT_fno_assume_sane_operator_new);
547 Opts.ObjCAutoRefCountExceptions = Args.hasArg(OPT_fobjc_arc_exceptions);
548 Opts.CXAAtExit = !Args.hasArg(OPT_fno_use_cxa_atexit);
549 Opts.CXXCtorDtorAliases = Args.hasArg(OPT_mconstructor_aliases);
551 Opts.
DebugPass = Args.getLastArgValue(OPT_mdebug_pass);
553 (Args.hasArg(OPT_mdisable_fp_elim) || Args.hasArg(OPT_pg));
554 Opts.DisableFree = Args.hasArg(OPT_disable_free);
555 Opts.DiscardValueNames = Args.hasArg(OPT_discard_value_names);
556 Opts.DisableTailCalls = Args.hasArg(OPT_mdisable_tail_calls);
557 Opts.
FloatABI = Args.getLastArgValue(OPT_mfloat_abi);
558 Opts.LessPreciseFPMAD = Args.hasArg(OPT_cl_mad_enable);
560 Opts.NoInfsFPMath = (Args.hasArg(OPT_menable_no_infinities) ||
561 Args.hasArg(OPT_cl_finite_math_only) ||
562 Args.hasArg(OPT_cl_fast_relaxed_math));
563 Opts.NoNaNsFPMath = (Args.hasArg(OPT_menable_no_nans) ||
564 Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
565 Args.hasArg(OPT_cl_finite_math_only) ||
566 Args.hasArg(OPT_cl_fast_relaxed_math));
567 Opts.NoSignedZeros = (Args.hasArg(OPT_fno_signed_zeros) ||
568 Args.hasArg(OPT_cl_no_signed_zeros));
569 Opts.ReciprocalMath = Args.hasArg(OPT_freciprocal_math);
570 Opts.NoZeroInitializedInBSS = Args.hasArg(OPT_mno_zero_initialized_in_bss);
573 Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack);
574 Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings);
575 Opts.EnableSegmentedStacks = Args.hasArg(OPT_split_stacks);
576 Opts.RelaxAll = Args.hasArg(OPT_mrelax_all);
577 Opts.IncrementalLinkerCompatible =
578 Args.hasArg(OPT_mincremental_linker_compatible);
579 Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer);
580 Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels);
581 Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm);
582 Opts.SoftFloat = Args.hasArg(OPT_msoft_float);
583 Opts.StrictEnums = Args.hasArg(OPT_fstrict_enums);
584 Opts.StrictVTablePointers = Args.hasArg(OPT_fstrict_vtable_pointers);
585 Opts.UnsafeFPMath = Args.hasArg(OPT_menable_unsafe_fp_math) ||
586 Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
587 Args.hasArg(OPT_cl_fast_relaxed_math);
588 Opts.UnwindTables = Args.hasArg(OPT_munwind_tables);
589 Opts.
RelocationModel = Args.getLastArgValue(OPT_mrelocation_model,
"pic");
590 Opts.
ThreadModel = Args.getLastArgValue(OPT_mthread_model,
"posix");
592 Diags.
Report(diag::err_drv_invalid_value)
593 << Args.getLastArg(OPT_mthread_model)->getAsString(Args)
595 Opts.
TrapFuncName = Args.getLastArgValue(OPT_ftrap_function_EQ);
596 Opts.UseInitArray = Args.hasArg(OPT_fuse_init_array);
598 Opts.FunctionSections = Args.hasFlag(OPT_ffunction_sections,
599 OPT_fno_function_sections,
false);
600 Opts.DataSections = Args.hasFlag(OPT_fdata_sections,
601 OPT_fno_data_sections,
false);
602 Opts.UniqueSectionNames = Args.hasFlag(OPT_funique_section_names,
603 OPT_fno_unique_section_names,
true);
605 Opts.MergeFunctions = Args.hasArg(OPT_fmerge_functions);
607 Opts.NoUseJumpTables = Args.hasArg(OPT_fno_jump_tables);
609 Opts.PrepareForLTO = Args.hasArg(OPT_flto, OPT_flto_EQ);
610 const Arg *A = Args.getLastArg(OPT_flto, OPT_flto_EQ);
611 Opts.EmitSummaryIndex = A && A->containsValue(
"thin");
612 if (Arg *A = Args.getLastArg(OPT_fthinlto_index_EQ)) {
614 Diags.
Report(diag::err_drv_argument_only_allowed_with)
615 << A->getAsString(Args) <<
"-x ir";
619 Opts.MSVolatile = Args.hasArg(OPT_fms_volatile);
621 Opts.VectorizeBB = Args.hasArg(OPT_vectorize_slp_aggressive);
622 Opts.VectorizeLoop = Args.hasArg(OPT_vectorize_loops);
623 Opts.VectorizeSLP = Args.hasArg(OPT_vectorize_slp);
625 Opts.
MainFileName = Args.getLastArgValue(OPT_main_file_name);
626 Opts.VerifyModule = !Args.hasArg(OPT_disable_llvm_verifier);
628 Opts.DisableGCov = Args.hasArg(OPT_test_coverage);
629 Opts.EmitGcovArcs = Args.hasArg(OPT_femit_coverage_data);
630 Opts.EmitGcovNotes = Args.hasArg(OPT_femit_coverage_notes);
631 if (Opts.EmitGcovArcs || Opts.EmitGcovNotes) {
632 Opts.
CoverageFile = Args.getLastArgValue(OPT_coverage_file);
633 Opts.CoverageExtraChecksum = Args.hasArg(OPT_coverage_cfg_checksum);
634 Opts.CoverageNoFunctionNamesInData =
635 Args.hasArg(OPT_coverage_no_function_names_in_data);
636 Opts.CoverageExitBlockBeforeBody =
637 Args.hasArg(OPT_coverage_exit_block_before_body);
638 if (Args.hasArg(OPT_coverage_version_EQ)) {
639 StringRef CoverageVersion = Args.getLastArgValue(OPT_coverage_version_EQ);
640 if (CoverageVersion.size() != 4) {
641 Diags.
Report(diag::err_drv_invalid_value)
642 << Args.getLastArg(OPT_coverage_version_EQ)->getAsString(Args)
650 if (Arg *A = Args.getLastArg(OPT_fembed_bitcode_EQ)) {
651 StringRef
Name = A->getValue();
652 unsigned Model = llvm::StringSwitch<unsigned>(
Name)
659 Diags.
Report(diag::err_drv_invalid_value) << A->getAsString(Args) <<
Name;
662 Opts.setEmbedBitcode(
663 static_cast<CodeGenOptions::EmbedBitcodeKind>(Model));
669 for (
const auto &A : Args) {
671 if (A->getOption().getID() == options::OPT_o ||
672 A->getOption().getID() == options::OPT_INPUT ||
673 A->getOption().getID() == options::OPT_x ||
674 A->getOption().getID() == options::OPT_fembed_bitcode ||
675 (A->getOption().getGroup().isValid() &&
676 A->getOption().getGroup().getID() == options::OPT_W_Group))
679 A->render(Args, ASL);
680 for (
const auto &arg : ASL) {
681 StringRef ArgStr(arg);
682 Opts.
CmdArgs.insert(Opts.
CmdArgs.end(), ArgStr.begin(), ArgStr.end());
689 Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions);
690 Opts.XRayInstrumentFunctions = Args.hasArg(OPT_fxray_instrument);
691 Opts.XRayInstructionThreshold =
693 Opts.InstrumentForProfiling = Args.hasArg(OPT_pg);
694 Opts.EmitOpenCLArgMetadata = Args.hasArg(OPT_cl_kernel_arg_info);
695 Opts.CompressDebugSections = Args.hasArg(OPT_compress_debug_sections);
696 Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations);
698 for (
auto A : Args.filtered(OPT_mlink_bitcode_file, OPT_mlink_cuda_bitcode)) {
699 unsigned LinkFlags = llvm::Linker::Flags::None;
700 if (A->getOption().matches(OPT_mlink_cuda_bitcode))
701 LinkFlags = llvm::Linker::Flags::LinkOnlyNeeded |
702 llvm::Linker::Flags::InternalizeLinkedSymbols;
705 Opts.SanitizeCoverageType =
707 Opts.SanitizeCoverageIndirectCalls =
708 Args.hasArg(OPT_fsanitize_coverage_indirect_calls);
709 Opts.SanitizeCoverageTraceBB = Args.hasArg(OPT_fsanitize_coverage_trace_bb);
710 Opts.SanitizeCoverageTraceCmp = Args.hasArg(OPT_fsanitize_coverage_trace_cmp);
711 Opts.SanitizeCoverage8bitCounters =
712 Args.hasArg(OPT_fsanitize_coverage_8bit_counters);
713 Opts.SanitizeCoverageTracePC = Args.hasArg(OPT_fsanitize_coverage_trace_pc);
714 Opts.SanitizeMemoryTrackOrigins =
716 Opts.SanitizeMemoryUseAfterDtor =
717 Args.hasArg(OPT_fsanitize_memory_use_after_dtor);
718 Opts.SanitizeCfiCrossDso = Args.hasArg(OPT_fsanitize_cfi_cross_dso);
719 Opts.SanitizeStats = Args.hasArg(OPT_fsanitize_stats);
720 Opts.SanitizeAddressUseAfterScope =
721 Args.hasArg(OPT_fsanitize_address_use_after_scope);
724 Opts.StackRealignment = Args.hasArg(OPT_mstackrealign);
725 if (Arg *A = Args.getLastArg(OPT_mstack_alignment)) {
726 StringRef Val = A->getValue();
727 unsigned StackAlignment = Opts.StackAlignment;
728 Val.getAsInteger(10, StackAlignment);
729 Opts.StackAlignment = StackAlignment;
732 if (Arg *A = Args.getLastArg(OPT_mstack_probe_size)) {
733 StringRef Val = A->getValue();
734 unsigned StackProbeSize = Opts.StackProbeSize;
735 Val.getAsInteger(0, StackProbeSize);
736 Opts.StackProbeSize = StackProbeSize;
739 if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) {
740 StringRef
Name = A->getValue();
741 unsigned Method = llvm::StringSwitch<unsigned>(
Name)
747 Diags.
Report(diag::err_drv_invalid_value) << A->getAsString(Args) <<
Name;
750 Opts.setObjCDispatchMethod(
751 static_cast<CodeGenOptions::ObjCDispatchMethodKind>(Method));
756 Args.hasFlag(OPT_femulated_tls, OPT_fno_emulated_tls,
false);
758 if (Arg *A = Args.getLastArg(OPT_ftlsmodel_EQ)) {
759 StringRef
Name = A->getValue();
760 unsigned Model = llvm::StringSwitch<unsigned>(
Name)
767 Diags.
Report(diag::err_drv_invalid_value) << A->getAsString(Args) <<
Name;
770 Opts.setDefaultTLSModel(static_cast<CodeGenOptions::TLSModel>(Model));
774 if (Arg *A = Args.getLastArg(OPT_ffp_contract)) {
775 StringRef Val = A->getValue();
778 else if (Val ==
"on")
780 else if (Val ==
"off")
783 Diags.
Report(diag::err_drv_invalid_value) << A->getAsString(Args) << Val;
786 if (Arg *A = Args.getLastArg(OPT_fpcc_struct_return, OPT_freg_struct_return)) {
787 if (A->getOption().matches(OPT_fpcc_struct_return)) {
790 assert(A->getOption().matches(OPT_freg_struct_return));
796 Opts.
LinkerOptions = Args.getAllArgValues(OPT_linker_option);
797 bool NeedLocTracking =
false;
799 if (Arg *A = Args.getLastArg(OPT_Rpass_EQ)) {
802 NeedLocTracking =
true;
805 if (Arg *A = Args.getLastArg(OPT_Rpass_missed_EQ)) {
808 NeedLocTracking =
true;
811 if (Arg *A = Args.getLastArg(OPT_Rpass_analysis_EQ)) {
814 NeedLocTracking =
true;
821 NeedLocTracking =
true;
833 Args.getAllArgValues(OPT_fsanitize_recover_EQ), Diags,
836 Args.getAllArgValues(OPT_fsanitize_trap_EQ), Diags,
840 Args.getAllArgValues(OPT_fcuda_include_gpubinary);
842 Opts.Backchain = Args.hasArg(OPT_mbackchain);
845 Args, OPT_fsanitize_undefined_strip_path_components_EQ, 0, Diags);
852 using namespace options;
853 Opts.
OutputFile = Args.getLastArgValue(OPT_dependency_file);
854 Opts.
Targets = Args.getAllArgValues(OPT_MT);
862 Opts.
DOTOutputFile = Args.getLastArgValue(OPT_dependency_dot);
864 Args.getLastArgValue(OPT_module_dependency_dir);
865 if (Args.hasArg(OPT_MV))
870 Opts.
ExtraDeps = Args.getAllArgValues(OPT_fdepfile_entry);
871 auto ModuleFiles = Args.getAllArgValues(OPT_fmodule_file);
885 } ShowColors = DefaultColor ? Colors_Auto : Colors_Off;
886 for (Arg *A : Args) {
887 const Option &O = A->getOption();
888 if (!O.matches(options::OPT_fcolor_diagnostics) &&
889 !O.matches(options::OPT_fdiagnostics_color) &&
890 !O.matches(options::OPT_fno_color_diagnostics) &&
891 !O.matches(options::OPT_fno_diagnostics_color) &&
892 !O.matches(options::OPT_fdiagnostics_color_EQ))
895 if (O.matches(options::OPT_fcolor_diagnostics) ||
896 O.matches(options::OPT_fdiagnostics_color)) {
897 ShowColors = Colors_On;
898 }
else if (O.matches(options::OPT_fno_color_diagnostics) ||
899 O.matches(options::OPT_fno_diagnostics_color)) {
900 ShowColors = Colors_Off;
902 assert(O.matches(options::OPT_fdiagnostics_color_EQ));
903 StringRef
Value(A->getValue());
904 if (
Value ==
"always")
905 ShowColors = Colors_On;
906 else if (
Value ==
"never")
907 ShowColors = Colors_Off;
908 else if (
Value ==
"auto")
909 ShowColors = Colors_Auto;
912 if (ShowColors == Colors_On ||
913 (ShowColors == Colors_Auto && llvm::sys::Process::StandardErrHasColors()))
920 bool DefaultDiagColor) {
921 using namespace options;
926 Args.getLastArg(OPT_diagnostic_serialized_file, OPT__serialize_diags))
928 Opts.IgnoreWarnings = Args.hasArg(OPT_w);
929 Opts.NoRewriteMacros = Args.hasArg(OPT_Wno_rewrite_macros);
930 Opts.Pedantic = Args.hasArg(OPT_pedantic);
931 Opts.PedanticErrors = Args.hasArg(OPT_pedantic_errors);
932 Opts.ShowCarets = !Args.hasArg(OPT_fno_caret_diagnostics);
934 Opts.ShowColumn = Args.hasFlag(OPT_fshow_column,
937 Opts.ShowFixits = !Args.hasArg(OPT_fno_diagnostics_fixit_info);
938 Opts.ShowLocation = !Args.hasArg(OPT_fno_show_source_location);
939 Opts.ShowOptionNames = Args.hasArg(OPT_fdiagnostics_show_option);
941 llvm::sys::Process::UseANSIEscapeCodes(Args.hasArg(OPT_fansi_escape_codes));
944 Opts.ShowNoteIncludeStack =
false;
945 if (Arg *A = Args.getLastArg(OPT_fdiagnostics_show_note_include_stack,
946 OPT_fno_diagnostics_show_note_include_stack))
947 if (A->getOption().matches(OPT_fdiagnostics_show_note_include_stack))
948 Opts.ShowNoteIncludeStack =
true;
950 StringRef ShowOverloads =
951 Args.getLastArgValue(OPT_fshow_overloads_EQ,
"all");
952 if (ShowOverloads ==
"best")
954 else if (ShowOverloads ==
"all")
955 Opts.setShowOverloads(
Ovl_All);
959 Diags->
Report(diag::err_drv_invalid_value)
960 << Args.getLastArg(OPT_fshow_overloads_EQ)->getAsString(Args)
964 StringRef ShowCategory =
965 Args.getLastArgValue(OPT_fdiagnostics_show_category,
"none");
966 if (ShowCategory ==
"none")
967 Opts.ShowCategories = 0;
968 else if (ShowCategory ==
"id")
969 Opts.ShowCategories = 1;
970 else if (ShowCategory ==
"name")
971 Opts.ShowCategories = 2;
975 Diags->
Report(diag::err_drv_invalid_value)
976 << Args.getLastArg(OPT_fdiagnostics_show_category)->getAsString(Args)
981 Args.getLastArgValue(OPT_fdiagnostics_format,
"clang");
982 if (Format ==
"clang")
984 else if (Format ==
"msvc")
986 else if (Format ==
"msvc-fallback") {
988 Opts.CLFallbackMode =
true;
989 }
else if (Format ==
"vi")
994 Diags->
Report(diag::err_drv_invalid_value)
995 << Args.getLastArg(OPT_fdiagnostics_format)->getAsString(Args)
999 Opts.ShowSourceRanges = Args.hasArg(OPT_fdiagnostics_print_source_range_info);
1000 Opts.ShowParseableFixits = Args.hasArg(OPT_fdiagnostics_parseable_fixits);
1001 Opts.ShowPresumedLoc = !Args.hasArg(OPT_fno_diagnostics_use_presumed_location);
1002 Opts.VerifyDiagnostics = Args.hasArg(OPT_verify);
1005 Args.getAllArgValues(OPT_verify_ignore_unexpected_EQ),
1007 if (Args.hasArg(OPT_verify_ignore_unexpected))
1009 Opts.setVerifyIgnoreUnexpected(DiagMask);
1010 Opts.ElideType = !Args.hasArg(OPT_fno_elide_type);
1011 Opts.ShowTemplateTree = Args.hasArg(OPT_fdiagnostics_show_template_tree);
1013 Opts.MacroBacktraceLimit =
1017 Args, OPT_ftemplate_backtrace_limit,
1020 Args, OPT_fconstexpr_backtrace_limit,
1023 Args, OPT_fspell_checking_limit,
1030 Diags->
Report(diag::warn_ignoring_ftabstop_value)
1041 Opts.
WorkingDir = Args.getLastArgValue(OPT_working_directory);
1049 std::string &BlockName,
1050 unsigned &MajorVersion,
1051 unsigned &MinorVersion,
1053 std::string &UserInfo) {
1055 Arg.split(Args,
':', 5);
1056 if (Args.size() < 5)
1059 BlockName = Args[0];
1060 if (Args[1].getAsInteger(10, MajorVersion))
return true;
1061 if (Args[2].getAsInteger(10, MinorVersion))
return true;
1062 if (Args[3].getAsInteger(2, Hashed))
return true;
1063 if (Args.size() > 4)
1070 using namespace options;
1072 if (
const Arg *A = Args.getLastArg(OPT_Action_Group)) {
1073 switch (A->getOption().getID()) {
1075 llvm_unreachable(
"Invalid option in group!");
1079 case OPT_ast_dump_lookups:
1085 case OPT_dump_raw_tokens:
1087 case OPT_dump_tokens:
1091 case OPT_emit_llvm_bc:
1097 case OPT_emit_llvm_only:
1099 case OPT_emit_codegen_only:
1108 case OPT_emit_module:
1116 case OPT_fsyntax_only:
1118 case OPT_module_file_info:
1120 case OPT_verify_pch:
1122 case OPT_print_decl_contexts:
1124 case OPT_print_preamble:
1128 case OPT_rewrite_macros:
1130 case OPT_rewrite_objc:
1132 case OPT_rewrite_test:
1143 if (
const Arg* A = Args.getLastArg(OPT_plugin)) {
1144 Opts.
Plugins.emplace_back(A->getValue(0));
1149 for (
const Arg *AA : Args.filtered(OPT_plugin_arg))
1150 Opts.
PluginArgs[AA->getValue(0)].emplace_back(AA->getValue(1));
1152 for (
const std::string &Arg :
1153 Args.getAllArgValues(OPT_ftest_module_file_extension_EQ)) {
1154 std::string BlockName;
1155 unsigned MajorVersion;
1156 unsigned MinorVersion;
1158 std::string UserInfo;
1160 MinorVersion, Hashed, UserInfo)) {
1161 Diags.
Report(diag::err_test_module_file_extension_format) << Arg;
1172 if (
const Arg *A = Args.getLastArg(OPT_code_completion_at)) {
1176 Diags.
Report(diag::err_drv_invalid_value)
1177 << A->getAsString(Args) << A->getValue();
1181 Opts.
OutputFile = Args.getLastArgValue(OPT_o);
1182 Opts.
Plugins = Args.getAllArgValues(OPT_load);
1184 Opts.
ShowHelp = Args.hasArg(OPT_help);
1185 Opts.
ShowStats = Args.hasArg(OPT_print_stats);
1186 Opts.
ShowTimers = Args.hasArg(OPT_ftime_report);
1189 Opts.
LLVMArgs = Args.getAllArgValues(OPT_mllvm);
1195 Opts.
ASTDumpFilter = Args.getLastArgValue(OPT_ast_dump_filter);
1199 Opts.
ModuleMapFiles = Args.getAllArgValues(OPT_fmodule_map_file);
1200 Opts.
ModuleFiles = Args.getAllArgValues(OPT_fmodule_file);
1206 = Args.hasArg(OPT_code_completion_macros);
1208 = Args.hasArg(OPT_code_completion_patterns);
1210 = !Args.hasArg(OPT_no_code_completion_globals);
1212 = Args.hasArg(OPT_code_completion_brief_comments);
1215 = Args.getLastArgValue(OPT_foverride_record_layout_EQ);
1218 Opts.
FindPchSource = Args.getLastArgValue(OPT_find_pch_source_EQ);
1220 if (
const Arg *A = Args.getLastArg(OPT_arcmt_check,
1222 OPT_arcmt_migrate)) {
1223 switch (A->getOption().getID()) {
1225 llvm_unreachable(
"missed a case");
1226 case OPT_arcmt_check:
1229 case OPT_arcmt_modify:
1232 case OPT_arcmt_migrate:
1237 Opts.
MTMigrateDir = Args.getLastArgValue(OPT_mt_migrate_directory);
1239 = Args.getLastArgValue(OPT_arcmt_migrate_report_output);
1241 = Args.hasArg(OPT_arcmt_migrate_emit_arc_errors);
1243 if (Args.hasArg(OPT_objcmt_migrate_literals))
1245 if (Args.hasArg(OPT_objcmt_migrate_subscripting))
1247 if (Args.hasArg(OPT_objcmt_migrate_property_dot_syntax))
1249 if (Args.hasArg(OPT_objcmt_migrate_property))
1251 if (Args.hasArg(OPT_objcmt_migrate_readonly_property))
1253 if (Args.hasArg(OPT_objcmt_migrate_readwrite_property))
1255 if (Args.hasArg(OPT_objcmt_migrate_annotation))
1257 if (Args.hasArg(OPT_objcmt_returns_innerpointer_property))
1259 if (Args.hasArg(OPT_objcmt_migrate_instancetype))
1261 if (Args.hasArg(OPT_objcmt_migrate_nsmacros))
1263 if (Args.hasArg(OPT_objcmt_migrate_protocol_conformance))
1265 if (Args.hasArg(OPT_objcmt_atomic_property))
1267 if (Args.hasArg(OPT_objcmt_ns_nonatomic_iosonly))
1269 if (Args.hasArg(OPT_objcmt_migrate_designated_init))
1271 if (Args.hasArg(OPT_objcmt_migrate_all))
1278 Diags.
Report(diag::err_drv_argument_not_allowed_with)
1279 <<
"ARC migration" <<
"ObjC migration";
1283 if (
const Arg *A = Args.getLastArg(OPT_x)) {
1284 DashX = llvm::StringSwitch<InputKind>(A->getValue())
1292 .Case(
"assembler-with-cpp",
IK_Asm)
1299 .Case(
"c-header",
IK_C)
1301 .Case(
"objective-c-header",
IK_ObjC)
1302 .Case(
"c++-header",
IK_CXX)
1303 .Case(
"objective-c++-header",
IK_ObjCXX)
1304 .Cases(
"ast",
"pcm",
IK_AST)
1309 Diags.
Report(diag::err_drv_invalid_value)
1310 << A->getAsString(Args) << A->getValue();
1314 std::vector<std::string> Inputs = Args.getAllArgValues(OPT_INPUT);
1317 Inputs.push_back(
"-");
1318 for (
unsigned i = 0, e = Inputs.size(); i != e; ++i) {
1322 StringRef(Inputs[i]).rsplit(
'.').second);
1327 Opts.
Inputs.emplace_back(std::move(Inputs[i]), IK);
1335 std::string ClangExecutable =
1336 llvm::sys::fs::getMainExecutable(Argv0, MainAddr);
1337 StringRef Dir = llvm::sys::path::parent_path(ClangExecutable);
1340 StringRef ClangResourceDir(CLANG_RESOURCE_DIR);
1342 if (ClangResourceDir !=
"")
1343 llvm::sys::path::append(P, ClangResourceDir);
1345 llvm::sys::path::append(P,
"..", Twine(
"lib") + CLANG_LIBDIR_SUFFIX,
1352 using namespace options;
1353 Opts.
Sysroot = Args.getLastArgValue(OPT_isysroot,
"/");
1354 Opts.
Verbose = Args.hasArg(OPT_v);
1358 if (
const Arg *A = Args.getLastArg(OPT_stdlib_EQ))
1359 Opts.
UseLibcxx = (strcmp(A->getValue(),
"libc++") == 0);
1360 Opts.
ResourceDir = Args.getLastArgValue(OPT_resource_dir);
1371 Args.hasArg(OPT_fmodules_validate_once_per_build_session);
1375 Args.hasArg(OPT_fmodules_validate_system_headers);
1376 if (
const Arg *A = Args.getLastArg(OPT_fmodule_format_EQ))
1379 for (
const Arg *A : Args.filtered(OPT_fmodules_ignore_macro)) {
1380 StringRef MacroDef = A->getValue();
1385 bool IsIndexHeaderMap =
false;
1386 bool IsSysrootSpecified =
1387 Args.hasArg(OPT__sysroot_EQ) || Args.hasArg(OPT_isysroot);
1388 for (
const Arg *A : Args.filtered(OPT_I, OPT_F, OPT_index_header_map)) {
1389 if (A->getOption().matches(OPT_index_header_map)) {
1391 IsIndexHeaderMap =
true;
1398 bool IsFramework = A->getOption().matches(OPT_F);
1399 std::string Path = A->getValue();
1401 if (IsSysrootSpecified && !IsFramework && A->getValue()[0] ==
'=') {
1403 llvm::sys::path::append(Buffer, Opts.
Sysroot,
1404 llvm::StringRef(A->getValue()).substr(1));
1405 Path = Buffer.str();
1408 Opts.
AddPath(Path.c_str(), Group, IsFramework,
1410 IsIndexHeaderMap =
false;
1414 StringRef Prefix =
"";
1416 Args.filtered(OPT_iprefix, OPT_iwithprefix, OPT_iwithprefixbefore)) {
1417 if (A->getOption().matches(OPT_iprefix))
1418 Prefix = A->getValue();
1419 else if (A->getOption().matches(OPT_iwithprefix))
1425 for (
const Arg *A : Args.filtered(OPT_idirafter))
1427 for (
const Arg *A : Args.filtered(OPT_iquote))
1429 for (
const Arg *A : Args.filtered(OPT_isystem, OPT_iwithsysroot))
1431 !A->getOption().matches(OPT_iwithsysroot));
1432 for (
const Arg *A : Args.filtered(OPT_iframework))
1436 for (
const Arg *A : Args.filtered(OPT_c_isystem))
1438 for (
const Arg *A : Args.filtered(OPT_cxx_isystem))
1440 for (
const Arg *A : Args.filtered(OPT_objc_isystem))
1442 for (
const Arg *A : Args.filtered(OPT_objcxx_isystem))
1447 Args.filtered(OPT_internal_isystem, OPT_internal_externc_isystem)) {
1449 if (A->getOption().matches(OPT_internal_externc_isystem))
1451 Opts.
AddPath(A->getValue(), Group,
false,
true);
1456 Args.filtered(OPT_system_header_prefix, OPT_no_system_header_prefix))
1458 A->getValue(), A->getOption().matches(OPT_system_header_prefix));
1460 for (
const Arg *A : Args.filtered(OPT_ivfsoverlay))
1465 return LangStd == LangStandard::lang_opencl ||
1466 LangStd == LangStandard::lang_opencl11 ||
1467 LangStd == LangStandard::lang_opencl12 ||
1468 LangStd == LangStandard::lang_opencl20;
1472 const llvm::Triple &T,
1479 Opts.AsmPreprocessor = 1;
1484 Opts.ObjC1 = Opts.ObjC2 = 1;
1493 llvm_unreachable(
"Invalid input kind!");
1495 LangStd = LangStandard::lang_opencl;
1499 LangStd = LangStandard::lang_cuda;
1508 LangStd = LangStandard::lang_gnu99;
1510 LangStd = LangStandard::lang_gnu11;
1516 LangStd = LangStandard::lang_gnucxx98;
1519 LangStd = LangStandard::lang_c99;
1526 Opts.C99 = Std.
isC99();
1527 Opts.C11 = Std.
isC11();
1534 Opts.GNUInline = Std.
isC89();
1540 if (LangStd == LangStandard::lang_opencl)
1541 Opts.OpenCLVersion = 100;
1542 else if (LangStd == LangStandard::lang_opencl11)
1543 Opts.OpenCLVersion = 110;
1544 else if (LangStd == LangStandard::lang_opencl12)
1545 Opts.OpenCLVersion = 120;
1546 else if (LangStd == LangStandard::lang_opencl20)
1547 Opts.OpenCLVersion = 200;
1553 Opts.CXXOperatorNames = 1;
1554 Opts.LaxVectorConversions = 0;
1555 Opts.DefaultFPContract = 1;
1556 Opts.NativeHalfType = 1;
1557 Opts.NativeHalfArgsAndReturns = 1;
1559 if (Opts.IncludeDefaultHeader) {
1560 PPOpts.
Includes.push_back(
"opencl-c.h");
1565 LangStd == LangStandard::lang_cuda;
1568 if (Opts.RenderScript) {
1569 Opts.NativeHalfType = 1;
1570 Opts.NativeHalfArgsAndReturns = 1;
1574 Opts.Bool = Opts.OpenCL || Opts.CPlusPlus;
1577 Opts.Half = Opts.OpenCL;
1580 Opts.WChar = Opts.CPlusPlus;
1582 Opts.GNUKeywords = Opts.GNUMode;
1583 Opts.CXXOperatorNames = Opts.CPlusPlus;
1585 Opts.DollarIdents = !Opts.AsmPreprocessor;
1591 StringRef value = arg->getValue();
1592 if (value ==
"default") {
1594 }
else if (value ==
"hidden" || value ==
"internal") {
1596 }
else if (value ==
"protected") {
1601 diags.
Report(diag::err_drv_invalid_value)
1602 << arg->getAsString(args) << value;
1612 if (
const Arg *A = Args.getLastArg(OPT_std_EQ)) {
1613 LangStd = llvm::StringSwitch<LangStandard::Kind>(A->getValue())
1615 .Case(name, LangStandard::lang_##
id)
1616 #define LANGSTANDARD_ALIAS(id, alias) \
1617 .Case(alias, LangStandard::lang_##id)
1618 #include "clang/Frontend/LangStandards.def"
1621 Diags.
Report(diag::err_drv_invalid_value)
1622 << A->getAsString(Args) << A->getValue();
1633 Diags.
Report(diag::err_drv_argument_not_allowed_with)
1634 << A->getAsString(Args) <<
"C/ObjC";
1641 Diags.
Report(diag::err_drv_argument_not_allowed_with)
1642 << A->getAsString(Args) <<
"C++/ObjC++";
1646 Diags.
Report(diag::err_drv_argument_not_allowed_with)
1647 << A->getAsString(Args) <<
"OpenCL";
1652 Diags.
Report(diag::err_drv_argument_not_allowed_with)
1653 << A->getAsString(Args) <<
"CUDA";
1663 if (
const Arg *A = Args.getLastArg(OPT_cl_std_EQ)) {
1665 = llvm::StringSwitch<LangStandard::Kind>(A->getValue())
1666 .Cases(
"cl",
"CL", LangStandard::lang_opencl)
1667 .Cases(
"cl1.1",
"CL1.1", LangStandard::lang_opencl11)
1668 .Cases(
"cl1.2",
"CL1.2", LangStandard::lang_opencl12)
1669 .Cases(
"cl2.0",
"CL2.0", LangStandard::lang_opencl20)
1673 Diags.
Report(diag::err_drv_invalid_value)
1674 << A->getAsString(Args) << A->getValue();
1677 LangStd = OpenCLLangStd;
1680 Opts.IncludeDefaultHeader = Args.hasArg(OPT_finclude_default_header);
1682 llvm::Triple T(TargetOpts.
Triple);
1688 if (Args.getLastArg(OPT_cl_strict_aliasing)
1689 && Opts.OpenCLVersion > 100) {
1690 std::string VerSpec = llvm::to_string(Opts.OpenCLVersion / 100) +
1692 llvm::to_string((Opts.OpenCLVersion % 100) / 10);
1693 Diags.
Report(diag::warn_option_invalid_ocl_version)
1694 << VerSpec << Args.getLastArg(OPT_cl_strict_aliasing)->getAsString(Args);
1702 Opts.GNUKeywords = Args.hasFlag(OPT_fgnu_keywords, OPT_fno_gnu_keywords,
1705 if (Args.hasArg(OPT_fno_operator_names))
1706 Opts.CXXOperatorNames = 0;
1708 if (Args.hasArg(OPT_fcuda_is_device))
1709 Opts.CUDAIsDevice = 1;
1711 if (Args.hasArg(OPT_fcuda_allow_variadic_functions))
1712 Opts.CUDAAllowVariadicFunctions = 1;
1714 if (Args.hasArg(OPT_fno_cuda_host_device_constexpr))
1715 Opts.CUDAHostDeviceConstexpr = 0;
1717 if (Opts.CUDAIsDevice && Args.hasArg(OPT_fcuda_flush_denormals_to_zero))
1718 Opts.CUDADeviceFlushDenormalsToZero = 1;
1720 if (Opts.CUDAIsDevice && Args.hasArg(OPT_fcuda_approx_transcendentals))
1721 Opts.CUDADeviceApproxTranscendentals = 1;
1724 if (Arg *arg = Args.getLastArg(OPT_fobjc_runtime_EQ)) {
1725 StringRef value = arg->getValue();
1727 Diags.
Report(diag::err_drv_unknown_objc_runtime) << value;
1730 if (Args.hasArg(OPT_fobjc_gc_only))
1732 else if (Args.hasArg(OPT_fobjc_gc))
1734 else if (Args.hasArg(OPT_fobjc_arc)) {
1735 Opts.ObjCAutoRefCount = 1;
1737 Diags.
Report(diag::err_arc_unsupported_on_runtime);
1744 if (Args.hasArg(OPT_fobjc_runtime_has_weak))
1745 Opts.ObjCWeakRuntime = 1;
1751 if (
auto weakArg = Args.getLastArg(OPT_fobjc_weak, OPT_fno_objc_weak)) {
1752 if (!weakArg->getOption().matches(OPT_fobjc_weak)) {
1753 assert(!Opts.ObjCWeak);
1755 Diags.
Report(diag::err_objc_weak_with_gc);
1756 }
else if (!Opts.ObjCWeakRuntime) {
1757 Diags.
Report(diag::err_objc_weak_unsupported);
1761 }
else if (Opts.ObjCAutoRefCount) {
1762 Opts.ObjCWeak = Opts.ObjCWeakRuntime;
1765 if (Args.hasArg(OPT_fno_objc_infer_related_result_type))
1766 Opts.ObjCInferRelatedResultType = 0;
1768 if (Args.hasArg(OPT_fobjc_subscripting_legacy_runtime))
1769 Opts.ObjCSubscriptingLegacyRuntime =
1773 if (Args.hasArg(OPT_fgnu89_inline)) {
1775 Diags.
Report(diag::err_drv_argument_not_allowed_with) <<
"-fgnu89-inline"
1781 if (Args.hasArg(OPT_fapple_kext)) {
1782 if (!Opts.CPlusPlus)
1783 Diags.
Report(diag::warn_c_kext);
1788 if (Args.hasArg(OPT_print_ivar_layout))
1789 Opts.ObjCGCBitmapPrint = 1;
1790 if (Args.hasArg(OPT_fno_constant_cfstrings))
1791 Opts.NoConstantCFStrings = 1;
1793 if (Args.hasArg(OPT_faltivec))
1796 if (Args.hasArg(OPT_fzvector))
1799 if (Args.hasArg(OPT_pthread))
1800 Opts.POSIXThreads = 1;
1803 if (Arg *visOpt = Args.getLastArg(OPT_fvisibility)) {
1810 if (Arg *typeVisOpt = Args.getLastArg(OPT_ftype_visibility)) {
1813 Opts.setTypeVisibilityMode(Opts.getValueVisibilityMode());
1816 if (Args.hasArg(OPT_fvisibility_inlines_hidden))
1817 Opts.InlineVisibilityHidden = 1;
1819 if (Args.hasArg(OPT_ftrapv)) {
1823 Args.getLastArgValue(OPT_ftrapv_handler);
1825 else if (Args.hasArg(OPT_fwrapv))
1828 Opts.MSVCCompat = Args.hasArg(OPT_fms_compatibility);
1829 Opts.MicrosoftExt = Opts.MSVCCompat || Args.hasArg(OPT_fms_extensions);
1830 Opts.AsmBlocks = Args.hasArg(OPT_fasm_blocks) || Opts.MicrosoftExt;
1831 Opts.MSCompatibilityVersion = 0;
1832 if (
const Arg *A = Args.getLastArg(OPT_fms_compatibility_version)) {
1835 Diags.
Report(diag::err_drv_invalid_value) << A->getAsString(Args)
1837 Opts.MSCompatibilityVersion = VT.
getMajor() * 10000000 +
1838 VT.
getMinor().getValueOr(0) * 100000 +
1845 Opts.Trigraphs = !Opts.GNUMode && !Opts.MSVCCompat && !Opts.CPlusPlus1z;
1847 Args.hasFlag(OPT_ftrigraphs, OPT_fno_trigraphs, Opts.Trigraphs);
1849 Opts.DollarIdents = Args.hasFlag(OPT_fdollars_in_identifiers,
1850 OPT_fno_dollars_in_identifiers,
1852 Opts.PascalStrings = Args.hasArg(OPT_fpascal_strings);
1854 Opts.Borland = Args.hasArg(OPT_fborland_extensions);
1855 Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings);
1856 Opts.ConstStrings = Args.hasFlag(OPT_fconst_strings, OPT_fno_const_strings,
1858 if (Args.hasArg(OPT_fno_lax_vector_conversions))
1859 Opts.LaxVectorConversions = 0;
1860 if (Args.hasArg(OPT_fno_threadsafe_statics))
1861 Opts.ThreadsafeStatics = 0;
1862 Opts.Exceptions = Args.hasArg(OPT_fexceptions);
1863 Opts.ObjCExceptions = Args.hasArg(OPT_fobjc_exceptions);
1864 Opts.CXXExceptions = Args.hasArg(OPT_fcxx_exceptions);
1865 Opts.SjLjExceptions = Args.hasArg(OPT_fsjlj_exceptions);
1866 Opts.ExternCNoUnwind = Args.hasArg(OPT_fexternc_nounwind);
1867 Opts.TraditionalCPP = Args.hasArg(OPT_traditional_cpp);
1869 Opts.RTTI = Opts.CPlusPlus && !Args.hasArg(OPT_fno_rtti);
1870 Opts.RTTIData = Opts.RTTI && !Args.hasArg(OPT_fno_rtti_data);
1871 Opts.Blocks = Args.hasArg(OPT_fblocks) || (Opts.OpenCL
1872 && Opts.OpenCLVersion >= 200);
1873 Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional);
1874 Opts.Coroutines = Args.hasArg(OPT_fcoroutines);
1875 Opts.Modules = Args.hasArg(OPT_fmodules);
1876 Opts.ModulesStrictDeclUse = Args.hasArg(OPT_fmodules_strict_decluse);
1877 Opts.ModulesDeclUse =
1878 Args.hasArg(OPT_fmodules_decluse) || Opts.ModulesStrictDeclUse;
1879 Opts.ModulesLocalVisibility =
1880 Args.hasArg(OPT_fmodules_local_submodule_visibility);
1881 Opts.ModulesSearchAll = Opts.Modules &&
1882 !Args.hasArg(OPT_fno_modules_search_all) &&
1883 Args.hasArg(OPT_fmodules_search_all);
1884 Opts.ModulesErrorRecovery = !Args.hasArg(OPT_fno_modules_error_recovery);
1885 Opts.ImplicitModules = !Args.hasArg(OPT_fno_implicit_modules);
1886 Opts.CharIsSigned = Opts.OpenCL || !Args.hasArg(OPT_fno_signed_char);
1887 Opts.WChar = Opts.CPlusPlus && !Args.hasArg(OPT_fno_wchar);
1888 Opts.ShortWChar = Args.hasFlag(OPT_fshort_wchar, OPT_fno_short_wchar,
false);
1889 Opts.ShortEnums = Args.hasArg(OPT_fshort_enums);
1890 Opts.Freestanding = Args.hasArg(OPT_ffreestanding);
1891 Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding;
1892 if (!Opts.NoBuiltin)
1894 Opts.NoMathBuiltin = Args.hasArg(OPT_fno_math_builtin);
1895 Opts.SizedDeallocation = Args.hasArg(OPT_fsized_deallocation);
1896 Opts.ConceptsTS = Args.hasArg(OPT_fconcepts_ts);
1897 Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions);
1898 Opts.AccessControl = !Args.hasArg(OPT_fno_access_control);
1899 Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors);
1900 Opts.MathErrno = !Opts.OpenCL && Args.hasArg(OPT_fmath_errno);
1901 Opts.InstantiationDepth =
1905 Opts.ConstexprCallDepth =
1907 Opts.ConstexprStepLimit =
1910 Opts.DelayedTemplateParsing = Args.hasArg(OPT_fdelayed_template_parsing);
1911 Opts.NumLargeByValueCopy =
1913 Opts.MSBitfields = Args.hasArg(OPT_mms_bitfields);
1915 Args.getLastArgValue(OPT_fconstant_string_class);
1916 Opts.ObjCDefaultSynthProperties =
1917 !Args.hasArg(OPT_disable_objc_default_synthesize_properties);
1918 Opts.EncodeExtendedBlockSig =
1919 Args.hasArg(OPT_fencode_extended_block_signature);
1920 Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls);
1923 Opts.AlignDouble = Args.hasArg(OPT_malign_double);
1925 Opts.PIE = Args.hasArg(OPT_pic_is_pie);
1926 Opts.Static = Args.hasArg(OPT_static_define);
1927 Opts.DumpRecordLayoutsSimple = Args.hasArg(OPT_fdump_record_layouts_simple);
1928 Opts.DumpRecordLayouts = Opts.DumpRecordLayoutsSimple
1929 || Args.hasArg(OPT_fdump_record_layouts);
1930 Opts.DumpVTableLayouts = Args.hasArg(OPT_fdump_vtable_layouts);
1931 Opts.SpellChecking = !Args.hasArg(OPT_fno_spell_checking);
1932 Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align);
1933 Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant);
1934 Opts.FastRelaxedMath = Args.hasArg(OPT_cl_fast_relaxed_math);
1935 Opts.HexagonQdsp6Compat = Args.hasArg(OPT_mqdsp6_compat);
1936 Opts.FakeAddressSpaceMap = Args.hasArg(OPT_ffake_address_space_map);
1937 Opts.ParseUnknownAnytype = Args.hasArg(OPT_funknown_anytype);
1938 Opts.DebuggerSupport = Args.hasArg(OPT_fdebugger_support);
1939 Opts.DebuggerCastResultToId = Args.hasArg(OPT_fdebugger_cast_result_to_id);
1940 Opts.DebuggerObjCLiteral = Args.hasArg(OPT_fdebugger_objc_literal);
1941 Opts.ApplePragmaPack = Args.hasArg(OPT_fapple_pragma_pack);
1942 Opts.
CurrentModule = Args.getLastArgValue(OPT_fmodule_name_EQ);
1943 Opts.AppExt = Args.hasArg(OPT_fapplication_extension);
1946 Opts.NativeHalfType |= Args.hasArg(OPT_fnative_half_type);
1947 Opts.NativeHalfArgsAndReturns |= Args.hasArg(OPT_fnative_half_arguments_and_returns);
1950 Opts.HalfArgsAndReturns = Args.hasArg(OPT_fallow_half_arguments_and_returns)
1951 | Opts.NativeHalfArgsAndReturns;
1952 Opts.GNUAsm = !Args.hasArg(OPT_fno_gnu_inline_asm);
1961 Opts.DeclSpecKeyword =
1962 Args.hasFlag(OPT_fdeclspec, OPT_fno_declspec,
1963 (Opts.MicrosoftExt || Opts.Borland || Opts.CUDA));
1967 if (Opts.ModulesLocalVisibility && !Opts.CPlusPlus)
1968 Diags.
Report(diag::err_drv_argument_not_allowed_with)
1969 <<
"-fmodules-local-submodule-visibility" <<
"C";
1971 if (Arg *A = Args.getLastArg(OPT_faddress_space_map_mangling_EQ)) {
1972 switch (llvm::StringSwitch<unsigned>(A->getValue())
1978 Diags.
Report(diag::err_drv_invalid_value)
1979 <<
"-faddress-space-map-mangling=" << A->getValue();
1993 if (Arg *A = Args.getLastArg(OPT_fms_memptr_rep_EQ)) {
1995 llvm::StringSwitch<LangOptions::PragmaMSPointersToMembersKind>(
2005 Diags.
Report(diag::err_drv_invalid_value)
2006 <<
"-fms-memptr-rep=" << A->getValue();
2008 Opts.setMSPointerToMemberRepresentationMethod(InheritanceModel);
2012 if (Arg *A = Args.getLastArg(OPT_fdefault_calling_conv_EQ)) {
2014 llvm::StringSwitch<LangOptions::DefaultCallingConvention>(
2022 Diags.
Report(diag::err_drv_invalid_value)
2023 <<
"-fdefault-calling-conv=" << A->getValue();
2025 llvm::Triple T(TargetOpts.
Triple);
2026 llvm::Triple::ArchType Arch = T.getArch();
2029 Arch != llvm::Triple::x86;
2031 !(Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64);
2033 Diags.
Report(diag::err_drv_argument_not_allowed_with)
2034 << A->getSpelling() << T.getTriple();
2036 Opts.setDefaultCallingConv(DefaultCC);
2040 if (Arg *A = Args.getLastArg(OPT_mrtd)) {
2042 Diags.
Report(diag::err_drv_argument_not_allowed_with)
2043 << A->getSpelling() <<
"-fdefault-calling-conv";
2045 llvm::Triple T(TargetOpts.
Triple);
2046 if (T.getArch() != llvm::Triple::x86)
2047 Diags.
Report(diag::err_drv_argument_not_allowed_with)
2048 << A->getSpelling() << T.getTriple();
2055 Opts.OpenMP = Args.hasArg(options::OPT_fopenmp) ? 1 : 0;
2057 Opts.OpenMP && !Args.hasArg(options::OPT_fnoopenmp_use_tls);
2058 Opts.OpenMPIsDevice =
2059 Opts.OpenMP && Args.hasArg(options::OPT_fopenmp_is_device);
2065 Opts.OpenMP = Version;
2068 if (!Opts.OpenMPIsDevice) {
2069 switch (T.getArch()) {
2073 case llvm::Triple::nvptx:
2074 case llvm::Triple::nvptx64:
2075 Diags.
Report(clang::diag::err_drv_omp_host_target_not_supported)
2083 if (Arg *A = Args.getLastArg(options::OPT_fopenmp_targets_EQ)) {
2085 for (
unsigned i = 0; i < A->getNumValues(); ++i) {
2086 llvm::Triple TT(A->getValue(i));
2088 if (TT.getArch() == llvm::Triple::UnknownArch)
2089 Diags.
Report(clang::diag::err_drv_invalid_omp_target) << A->getValue(i);
2097 if (Arg *A = Args.getLastArg(options::OPT_fopenmp_host_ir_file_path)) {
2100 Diags.
Report(clang::diag::err_drv_omp_host_ir_file_not_found)
2105 Opts.Deprecated = Args.hasFlag(OPT_fdeprecated_macro,
2106 OPT_fno_deprecated_macro,
2112 Opts.Optimize = Opt != 0;
2113 Opts.OptimizeSize = OptSize != 0;
2118 Opts.NoInlineDefine = !Opt || Args.hasArg(OPT_fno_inline);
2120 Opts.FastMath = Args.hasArg(OPT_ffast_math) ||
2121 Args.hasArg(OPT_cl_fast_relaxed_math);
2122 Opts.FiniteMathOnly = Args.hasArg(OPT_ffinite_math_only) ||
2123 Args.hasArg(OPT_cl_finite_math_only) ||
2124 Args.hasArg(OPT_cl_fast_relaxed_math);
2125 Opts.UnsafeFPMath = Args.hasArg(OPT_menable_unsafe_fp_math) ||
2126 Args.hasArg(OPT_cl_unsafe_math_optimizations) ||
2127 Args.hasArg(OPT_cl_fast_relaxed_math);
2129 Opts.RetainCommentsFromSystemHeaders =
2130 Args.hasArg(OPT_fretain_comments_from_system_headers);
2135 Diags.
Report(diag::err_drv_invalid_value)
2136 << Args.getLastArg(OPT_stack_protector)->getAsString(Args) << SSP;
2148 Opts.SanitizeAddressFieldPadding =
2156 using namespace options;
2159 if (
const Arg *A = Args.getLastArg(OPT_token_cache))
2164 Opts.
DetailedRecord = Args.hasArg(OPT_detailed_preprocessing_record);
2168 for (
const Arg *A : Args.filtered(OPT_error_on_deserialized_pch_decl))
2171 if (
const Arg *A = Args.getLastArg(OPT_preamble_bytes_EQ)) {
2172 StringRef
Value(A->getValue());
2175 unsigned EndOfLine = 0;
2177 if (Comma == StringRef::npos ||
2178 Value.substr(0, Comma).getAsInteger(10, Bytes) ||
2179 Value.substr(Comma + 1).getAsInteger(10, EndOfLine))
2180 Diags.
Report(diag::err_drv_preamble_format);
2188 for (
const Arg *A : Args.filtered(OPT_D, OPT_U)) {
2189 if (A->getOption().matches(OPT_D))
2198 for (
const Arg *A : Args.filtered(OPT_include))
2199 Opts.
Includes.emplace_back(A->getValue());
2201 for (
const Arg *A : Args.filtered(OPT_chain_include))
2204 for (
const Arg *A : Args.filtered(OPT_remap_file)) {
2205 std::pair<StringRef, StringRef> Split = StringRef(A->getValue()).split(
';');
2207 if (Split.second.empty()) {
2208 Diags.
Report(diag::err_drv_invalid_remap_file) << A->getAsString(Args);
2215 if (Arg *A = Args.getLastArg(OPT_fobjc_arc_cxxlib_EQ)) {
2216 StringRef
Name = A->getValue();
2217 unsigned Library = llvm::StringSwitch<unsigned>(
Name)
2223 Diags.
Report(diag::err_drv_invalid_value) << A->getAsString(Args) <<
Name;
2232 using namespace options;
2269 Opts.
ShowCPP = !Args.hasArg(OPT_dM);
2276 Opts.
ShowMacros = Args.hasArg(OPT_dM) || Args.hasArg(OPT_dD);
2283 using namespace options;
2284 Opts.
ABI = Args.getLastArgValue(OPT_target_abi);
2285 if (Arg *A = Args.getLastArg(OPT_meabi)) {
2286 StringRef
Value = A->getValue();
2287 llvm::EABI EABIVersion = llvm::StringSwitch<llvm::EABI>(
Value)
2288 .Case(
"default", llvm::EABI::Default)
2289 .Case(
"4", llvm::EABI::EABI4)
2290 .Case(
"5", llvm::EABI::EABI5)
2291 .Case(
"gnu", llvm::EABI::GNU)
2294 Diags.
Report(diag::err_drv_invalid_value) << A->getAsString(Args)
2299 Opts.
CPU = Args.getLastArgValue(OPT_target_cpu);
2300 Opts.
FPMath = Args.getLastArgValue(OPT_mfpmath);
2302 Opts.
LinkerVersion = Args.getLastArgValue(OPT_target_linker_version);
2304 Opts.
Reciprocals = Args.getAllArgValues(OPT_mrecip_EQ);
2307 Opts.
Triple = llvm::sys::getDefaultTargetTriple();
2311 const char *
const *ArgBegin,
2312 const char *
const *ArgEnd,
2314 bool Success =
true;
2319 unsigned MissingArgIndex, MissingArgCount;
2321 Opts->ParseArgs(llvm::makeArrayRef(ArgBegin, ArgEnd), MissingArgIndex,
2322 MissingArgCount, IncludedFlagsBitmask);
2326 if (MissingArgCount) {
2327 Diags.
Report(diag::err_drv_missing_argument)
2328 << Args.getArgString(MissingArgIndex) << MissingArgCount;
2333 for (
const Arg *A : Args.filtered(OPT_UNKNOWN)) {
2334 Diags.
Report(diag::err_drv_unknown_argument) << A->getAsString(Args);
2355 if (Args.hasArg(OPT_fobjc_arc))
2356 LangOpts.ObjCAutoRefCount = 1;
2360 LangOpts.PIE = Args.hasArg(OPT_pic_is_pie);
2368 LangOpts.ObjCExceptions = 1;
2371 if (LangOpts.CUDA) {
2374 if (LangOpts.CUDAIsDevice)
2378 if (!Args.hasArg(OPT_ffp_contract))
2403 using llvm::hash_code;
2404 using llvm::hash_value;
2405 using llvm::hash_combine;
2413 #define LANGOPT(Name, Bits, Default, Description) \
2414 code = hash_combine(code, LangOpts->Name);
2415 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
2416 code = hash_combine(code, static_cast<unsigned>(LangOpts->get##Name()));
2417 #define BENIGN_LANGOPT(Name, Bits, Default, Description)
2418 #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description)
2419 #include "clang/Basic/LangOptions.def"
2421 for (StringRef Feature : LangOpts->ModuleFeatures)
2422 code = hash_combine(code, Feature);
2425 code = hash_combine(code, TargetOpts->Triple, TargetOpts->CPU,
2427 for (
unsigned i = 0, n = TargetOpts->FeaturesAsWritten.size(); i != n; ++i)
2428 code = hash_combine(code, TargetOpts->FeaturesAsWritten[i]);
2435 for (std::vector<std::pair<std::string, bool/*isUndef*/>>::const_iterator
2436 I = getPreprocessorOpts().Macros.begin(),
2437 IEnd = getPreprocessorOpts().Macros.end();
2443 StringRef MacroDef =
I->first;
2448 code = hash_combine(code,
I->first,
I->second);
2452 code = hash_combine(code, hsOpts.
Sysroot,
2467 code = ext->hashExtension(code);
2474 if (!hsOpts.
Sysroot.empty()) {
2476 systemVersionFile += hsOpts.
Sysroot;
2477 llvm::sys::path::append(systemVersionFile,
"System");
2478 llvm::sys::path::append(systemVersionFile,
"Library");
2479 llvm::sys::path::append(systemVersionFile,
"CoreServices");
2480 llvm::sys::path::append(systemVersionFile,
"SystemVersion.plist");
2482 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> buffer =
2483 llvm::MemoryBuffer::getFile(systemVersionFile);
2485 code = hash_combine(code, buffer.get()->getBuffer());
2487 struct stat statBuf;
2488 if (stat(systemVersionFile.c_str(), &statBuf) == 0)
2489 code = hash_combine(code, statBuf.st_mtime);
2493 return llvm::APInt(64, code).toString(36,
false);
2498 template<
typename IntTy>
2502 IntTy Res = Default;
2503 if (Arg *A = Args.getLastArg(Id)) {
2504 if (StringRef(A->getValue()).getAsInteger(10, Res)) {
2506 Diags->
Report(diag::err_drv_invalid_int_value) << A->getAsString(Args)
2517 return getLastArgIntValueImpl<int>(Args, Id, Default, Diags);
2523 return getLastArgIntValueImpl<uint64_t>(Args, Id, Default, Diags);
2532 static const size_t kGraveYardMaxSize = 16;
2533 LLVM_ATTRIBUTE_UNUSED
static const void *GraveYard[kGraveYardMaxSize];
2534 static std::atomic<unsigned> GraveYardSize;
2535 unsigned Idx = GraveYardSize++;
2536 if (Idx >= kGraveYardMaxSize)
2538 GraveYard[Idx] = Ptr;
2551 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
Buffer =
2552 llvm::MemoryBuffer::getFile(File);
2554 Diags.
Report(diag::err_missing_vfs_overlay_file) << File;
2559 std::move(Buffer.get()),
nullptr, File);
2561 Diags.
Report(diag::err_invalid_vfs_overlay) << File;
2564 Overlay->pushOverlay(FS);
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 ProfileInstrumentUsePath
Name of the profile file to use as input for -fprofile-instr-use.
std::string OutputFile
The output file, if any.
static void ParseFileSystemArgs(FileSystemOptions &Opts, ArgList &Args)
unsigned NoFinalizeRemoval
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
The string to embed in the debug information for the compile unit, if non-empty.
std::string DOTOutputFile
The file to write GraphViz-formatted header dependencies to.
void addMacroUndef(StringRef Name)
Generate pre-compiled module.
Represents a version number in the form major[.minor[.subminor[.build]]].
unsigned IncludeBriefComments
Show brief documentation comments in code completion results.
static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, const TargetOptions &TargetOpts, PreprocessorOptions &PPOpts, DiagnosticsEngine &Diags)
Implements support for file system lookup, file system caching, and directory search management...
TargetOptions & getTargetOpts()
Defines the clang::FileManager interface and associated types.
Parse and perform semantic analysis.
ObjCXXARCStandardLibraryKind
Enumerate the kinds of standard library that.
static StringRef getCodeModel(ArgList &Args, DiagnosticsEngine &Diags)
unsigned IncludeGlobals
Show top-level decls in code completion results.
SanitizerSet Sanitize
Set of enabled sanitizers.
Like System, but headers are implicitly wrapped in extern "C".
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
Regular expression to select optimizations for which we should enable missed optimization remarks...
bool ParseDiagnosticArgs(DiagnosticOptions &Opts, llvm::opt::ArgList &Args, DiagnosticsEngine *Diags=nullptr, bool DefaultDiagColor=true)
Fill out Opts based on the options given in Args.
static unsigned getOptimizationLevel(ArgList &Args, InputKind IK, DiagnosticsEngine &Diags)
LangStandard - Information about the properties of a particular language standard.
static bool isBuiltinFunc(const char *Name)
Returns true if this is a libc/libm function without the '__builtin_' prefix.
bool isGNUMode() const
isGNUMode - Language includes GNU extensions.
unsigned IncludeModuleFiles
Include module file dependencies.
Parse ASTs and print them.
Like System, but only used for C++.
std::string HeaderIncludeOutputFile
The file to write header include output to.
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.
unsigned visualizeExplodedGraphWithGraphViz
std::string SampleProfileFile
Name of the profile file to use with -fprofile-sample-use.
Like System, but only used for ObjC++.
std::unique_ptr< llvm::MemoryBuffer > Buffer
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
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?
#define ANALYSIS_STORE(NAME, CMDFLAG, DESC, CREATFN)
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
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.
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...
Objects with "hidden" visibility are not seen by the dynamic linker.
std::string ImplicitPTHInclude
The implicit PTH input included at the start of the translation unit, or empty.
static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, DiagnosticsEngine &Diags)
Options for controlling the target.
bool allowsARC() const
Does this runtime allow ARC at all?
void addRemappedFile(StringRef From, StringRef To)
std::string CoverageFile
The filename with path we use for coverage files.
std::string FixItSuffix
If given, the new suffix for fix-it rewritten files.
std::string HostTriple
When compiling for the device side, contains the triple used to compile for the host.
std::string SplitDwarfFile
The name for the split debug info file that we'll break out.
Like System, but searched after the system directories.
std::string DebugPass
Enable additional debugging information.
float __ovld __cnfn normalize(float p)
Returns a vector in the same direction as p but with a length of 1.
SanitizerSet SanitizeRecover
Set of sanitizer checks that are non-fatal (i.e.
Parse and apply any fixits to the source.
std::vector< std::string > Reciprocals
std::vector< std::string > CudaGpuBinaryFileNames
A list of file names passed with -fcuda-include-gpubinary options to forward to CUDA runtime back-end...
std::string FindPchSource
If non-empty, search the pch input file as it was a header.
static void setPGOInstrumentor(CodeGenOptions &Opts, ArgList &Args, DiagnosticsEngine &Diags)
'macosx-fragile' is the Apple-provided NeXT-derived runtime on Mac OS X platforms that use the fragil...
std::map< std::string, std::string > DebugPrefixMap
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
std::string FPMath
If given, the unit to use for floating point math.
bool isCPlusPlus11() const
isCPlusPlus11 - Language is a C++11 variant (or later).
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.
bool isCPlusPlus() const
isCPlusPlus - Language is a C++ variant.
unsigned IncludeSystemHeaders
Include system header dependencies.
IntrusiveRefCntPtr< FileSystem > getVFSFromYAML(std::unique_ptr< llvm::MemoryBuffer > Buffer, llvm::SourceMgr::DiagHandlerTy DiagHandler, StringRef YAMLFilePath, void *DiagContext=nullptr, IntrusiveRefCntPtr< FileSystem > ExternalFS=getRealFileSystem())
Gets a FileSystem for a virtual file system described in YAML format.
Translate input source into HTML.
unsigned DetailedRecord
Whether we should maintain a detailed record of all macro definitions and expansions.
std::vector< uint8_t > CmdArgs
List of backend command-line options for -fembed-bitcode.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
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.
std::vector< std::string > ModulesEmbedFiles
The list of files to embed into the compiled module file.
unsigned RelocatablePCH
When generating PCH files, instruct the AST writer to create relocatable PCH files.
Objects with "default" visibility are seen by the dynamic linker and act like normal objects...
unsigned IncludeCodePatterns
Show code patterns in code completion results.
A module file extension used for testing purposes.
Action - Represent an abstract compilation step to perform.
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()
unsigned ShowStats
Show frontend performance metrics and statistics.
Enable annotation of ObjCMethods of all kinds.
static void ParseDependencyOutputArgs(DependencyOutputOptions &Opts, ArgList &Args)
static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args, DiagnosticsEngine &Diags)
Visibility
Describes the different kinds of visibility that a declaration may have.
Concrete class used by the front-end to report problems and issues.
unsigned FixWhatYouCan
Apply fixes even if there are unfixable errors.
std::vector< std::string > Warnings
The list of -W...
std::vector< std::pair< std::string, bool > > CheckersControlList
Pair of checker name and enable/disable.
AnalysisStores
AnalysisStores - Set of available analysis store models.
detail::InMemoryDirectory::const_iterator I
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)
static void setPGOUseInstrumentor(CodeGenOptions &Opts, const Twine &ProfileName)
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 ...
PreprocessorOutputOptions & getPreprocessorOutputOpts()
std::string ThreadModel
The thread model to use.
FrontendOptions & getFrontendOpts()
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, of which the main source file is a part.
AnalysisDiagClients AnalysisDiagOpt
std::vector< std::string > NoBuiltinFuncs
A list of all -fno-builtin-* function names (e.g., memset).
Enable migration to modern ObjC literals.
std::vector< std::string > ChainedIncludes
Headers that will be converted to chained PCHs in memory.
PreprocessorOutputOptions - Options for controlling the C preprocessor output (e.g., -E).
std::string LimitFloatPrecision
The float precision limit to use, if non-empty.
bool isCPlusPlus14() const
isCPlusPlus14 - Language is a C++14 variant (or later).
uint64_t getLastArgUInt64Value(const llvm::opt::ArgList &Args, llvm::opt::OptSpecifier Id, uint64_t Default, DiagnosticsEngine *Diags=nullptr)
static void setLangDefaults(LangOptions &Opts, InputKind IK, const llvm::Triple &T, PreprocessorOptions &PPOpts, LangStandard::Kind LangStd=LangStandard::lang_unspecified)
Set language defaults for the given input language and language standard in the given LangOptions obj...
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.
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...
bool hasDigraphs() const
hasDigraphs - Language supports digraphs.
std::vector< std::string > Plugins
The list of plugins to load.
Show just the "best" overload candidates.
IncludeDirGroup
IncludeDirGroup - Identifies the group an include Entry belongs to, representing its relative positiv...
Emit only debug info necessary for generating line number tables (-gline-tables-only).
std::string WorkingDir
If set, paths are resolved as if the working directory was set to the value of WorkingDir.
std::string OMPHostIRFile
Name of the IR file that contains the result of the OpenMP target host code generation.
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.
unsigned ShowTimers
Show timers for individual actions.
std::string LinkerVersion
If given, the version string of the linker in use.
Only execute frontend initialization.
bool isCPlusPlus1z() const
isCPlusPlus1z - Language is a C++17 variant (or later).
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.
bool tryParse(StringRef input)
Try to parse an Objective-C runtime specification from the given string.
unsigned ShowHeaderIncludes
Show header inclusions (-H).
std::shared_ptr< llvm::Regex > OptimizationRemarkPattern
Regular expression to select optimizations for which we should enable optimization remarks...
unsigned ModulesEmbedAllFiles
Whether we should embed all used files into the PCM file.
AnalysisInliningMode
AnalysisInlineFunctionSelection - Set of inlining function selection heuristics.
Objects with "protected" visibility are seen by the dynamic linker but always dynamically resolve to ...
unsigned ShowMacros
Print macro definitions.
clang::ObjCRuntime ObjCRuntime
static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts, ArgList &Args, frontend::ActionKind Action)
unsigned FixOnlyWarnings
Apply fixes only for warnings.
Enable migration to modern ObjC readwrite property.
bool hasImplicitInt() const
hasImplicitInt - Language allows variables to be typed as int implicitly.
unsigned NoNSAllocReallocError
std::string EABIVersion
The EABI version to use.
static void addDiagnosticArgs(ArgList &Args, OptSpecifier Group, OptSpecifier GroupWithValue, std::vector< std::string > &Diagnostics)
bool isOpenCL(LangStandard::Kind LangStd)
std::string AuxTriple
Auxiliary triple for CUDA compilation.
std::string CPU
If given, the name of the target CPU to generate code for.
unsigned ARCMTMigrateEmitARCErrors
bool isC99() const
isC99 - Language is a superset of C99.
void set(SanitizerMask K, bool Value)
Enable or disable a certain (single) sanitizer.
Enable inferring NS_DESIGNATED_INITIALIZER for ObjC methods.
std::string ABI
If given, the name of the target ABI to use.
AnalysisConstraints
AnalysisConstraints - Set of available constraint models.
bool isC11() const
isC11 - Language is a superset of C11.
AnalysisStores AnalysisStoreOpt
Encodes a location in the source.
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.
Limit generated debug info to reduce size (-fno-standalone-debug).
Options for controlling the compiler diagnostics engine.
std::vector< FrontendInputFile > Inputs
The input files and their types.
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)
unsigned IncludeTimestamps
Whether timestamps should be written to the produced PCH file.
Parse ASTs and view them in Graphviz.
std::vector< std::string > Remarks
The list of -R...
annotate property with NS_RETURNS_INNER_POINTER
Enable migration to modern ObjC readonly property.
unsigned visualizeExplodedGraphWithUbiGraph
Parse ASTs and list Decl nodes.
std::string getClangFullRepositoryVersion()
Retrieves the full repository version that is an amalgamation of the information in getClangRepositor...
static void getAllNoBuiltinFuncValues(ArgList &Args, std::vector< std::string > &Funcs)
std::unordered_map< std::string, std::vector< std::string > > PluginArgs
Args to pass to the plugins.
DependencyOutputOptions - Options for controlling the compiler dependency file generation.
unsigned getMajor() const
Retrieve the major version number.
unsigned ASTDumpLookups
Whether we include lookup table dumps in AST dumps.
Enable migration to modern ObjC subscripting.
std::vector< std::string > ExtraDeps
A list of filenames to be used as extra dependencies for every target.
Load and verify that a PCH file is usable.
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::shared_ptr< llvm::Regex > OptimizationRemarkAnalysisPattern
Regular expression to select optimizations for which we should enable optimization analyses...
std::vector< std::string > FeaturesAsWritten
The list of target specific features to enable or disable, as written on the command line...
PragmaMSPointersToMembersKind
unsigned GenerateGlobalModuleIndex
Whether we can generate the global module index if needed.
void addMacroDef(StringRef Name)
'#include ""' paths, added by 'gcc -iquote'.
std::string ThinLTOIndexFile
Name of the function summary index file to use for ThinLTO function importing.
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.
unsigned ShowComments
Show comments.
static bool parseTestModuleFileExtensionArg(StringRef Arg, std::string &BlockName, unsigned &MajorVersion, unsigned &MinorVersion, bool &Hashed, std::string &UserInfo)
Parse the argument to the -ftest-module-file-extension command-line argument.
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.
std::string OverflowHandler
The name of the handler function to be called when -ftrapv is specified.
bool tryParse(StringRef string)
Try to parse the given string as a version number.
static ParsedSourceLocation FromString(StringRef Str)
Construct a parsed source location from a string; the Filename is empty on error. ...
PreprocessorOptions & getPreprocessorOpts()
frontend::ActionKind ProgramAction
The frontend action to perform.
Enable migration to NS_ENUM/NS_OPTIONS macros.
std::vector< llvm::Triple > OMPTargetTriples
Triples of the OpenMP targets that the host code codegen should take into account in order to generat...
std::string ARCMTMigrateReportOut
Emit location information but do not generate debug info in the output.
std::unique_ptr< DiagnosticConsumer > create(StringRef OutputFile, DiagnosticOptions *Diags, bool MergeChildRecords=false)
Returns a DiagnosticConsumer that serializes diagnostics to a bitcode file.
Like System, but only used for C.
unsigned UseGlobalModuleIndex
Whether we can use the global module index if available.
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.
unsigned UsePhonyTargets
Include phony targets for each dependency, which can avoid some 'make' problems.
std::string AnalyzeSpecificFunction
detail::InMemoryDirectory::const_iterator E
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)
Parse a single value from a -fsanitize= or -fno-sanitize= value list.
static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args)
void BuryPointer(const void *Ptr)
Parse ASTs and dump them.
Don't generate debug info.
std::vector< std::string > LinkerOptions
A list of linker options to embed in the object file.
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
CodeCompleteOptions CodeCompleteOpts
static bool parseShowColorsArgs(const ArgList &Args, bool DefaultColor)
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.
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()
unsigned AnalyzerDisplayProgress
~CompilerInvocationBase()
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)
Return the value of the last argument as an integer, or a default.
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
unsigned ShowMacroComments
Show comments, even in macros.
Enable converting setter/getter expressions to property-dot syntx.
unsigned AnalyzeNestedBlocks
unsigned NoRetryExhausted
Do not re-analyze paths leading to exhausted nodes with a different strategy.
std::string MainFileName
The user provided name for the "main file", if non-empty.
std::vector< std::string > NoBuiltinFuncs
A list of all -fno-builtin-* function names (e.g., memset).
unsigned ASTDumpDecls
Whether we include declaration dumps in AST dumps.
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...
std::vector< IntrusiveRefCntPtr< ModuleFileExtension > > ModuleFileExtensions
The list of module file extensions.
#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
A list of names to use as the targets in the dependency file; this list must contain at least one ent...
std::vector< std::pair< unsigned, std::string > > LinkBitcodeFiles
The name of the bitcode file to link before optzns.
std::string InstrProfileOutput
Name of the profile file to use as output for -fprofile-instr-generate and -fprofile-generate.
std::string TrapFuncName
If not an empty string, trap intrinsics are lowered to calls to this function instead of to trap inst...
DiagnosticLevelMask
A bitmask representing the diagnostic levels used by VerifyDiagnosticConsumer.
Dump information about a module file.
#define CLANG_VERSION_STRING
A string that describes the Clang version number, e.g., "1.0".
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...
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'.
Like Angled, but marks header maps used when.
Generate pre-tokenized header.
static InputKind getInputKindForExtension(StringRef Extension)
getInputKindForExtension - Return the appropriate input kind for a file extension.
std::string ObjCConstantStringClass
use NS_NONATOMIC_IOSONLY for property 'atomic' attribute
#define ANALYSIS_INLINING_MODE(NAME, CMDFLAG, DESC)
unsigned IncludeMacros
Show macros in code completion results.
AnalysisPurgeMode AnalysisPurgeOpt
LangOptions * getLangOpts()
unsigned PrintShowIncludes
Print cl.exe style /showIncludes info.
bool DumpDeserializedPCHDecls
Dump declarations that are deserialized from PCH, for testing.
AnalysisDiagClients
AnalysisDiagClients - Set of available diagnostic clients for rendering analysis results.
std::string Triple
If given, the name of the target triple to compile for.
#define ANALYSIS_PURGE(NAME, CMDFLAG, DESC)
Defines enum values for all the target-independent builtin functions.
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 hasHexFloats() const
hasHexFloats - Language supports hexadecimal float constants.
std::vector< std::string > ModuleMapFiles
The list of module map files to load before processing the input.