35#include "clang/Config/config.h"
44#include "llvm/ADT/SmallSet.h"
45#include "llvm/ADT/StringExtras.h"
46#include "llvm/BinaryFormat/Magic.h"
47#include "llvm/Config/llvm-config.h"
48#include "llvm/Frontend/Debug/Options.h"
49#include "llvm/Object/ObjectFile.h"
50#include "llvm/Option/ArgList.h"
51#include "llvm/Support/CodeGen.h"
52#include "llvm/Support/Compiler.h"
53#include "llvm/Support/Compression.h"
54#include "llvm/Support/Error.h"
55#include "llvm/Support/FileSystem.h"
56#include "llvm/Support/Path.h"
57#include "llvm/Support/Process.h"
58#include "llvm/Support/YAMLParser.h"
59#include "llvm/TargetParser/AArch64TargetParser.h"
60#include "llvm/TargetParser/ARMTargetParserCommon.h"
61#include "llvm/TargetParser/Host.h"
62#include "llvm/TargetParser/LoongArchTargetParser.h"
63#include "llvm/TargetParser/PPCTargetParser.h"
64#include "llvm/TargetParser/RISCVISAInfo.h"
65#include "llvm/TargetParser/RISCVTargetParser.h"
74 if (Arg *A = Args.getLastArg(clang::driver::options::OPT_C, options::OPT_CC,
75 options::OPT_fminimize_whitespace,
76 options::OPT_fno_minimize_whitespace,
77 options::OPT_fkeep_system_includes,
78 options::OPT_fno_keep_system_includes)) {
79 if (!Args.hasArg(options::OPT_E) && !Args.hasArg(options::OPT__SLASH_P) &&
80 !Args.hasArg(options::OPT__SLASH_EP) && !
D.CCCIsCPP()) {
81 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
82 << A->getBaseArg().getAsString(Args)
83 << (
D.IsCLMode() ?
"/E, /P or /EP" :
"-E");
90 if (Args.hasArg(options::OPT_static))
92 Args.getLastArg(options::OPT_dynamic, options::OPT_mdynamic_no_pic))
93 D.Diag(diag::err_drv_argument_not_allowed_with) << A->getAsString(Args)
102 for (; *Arg; ++Arg) {
120 llvm::function_ref<
void(
const ToolChain &)> Work) {
122 Work(RegularToolChain);
137 for (
auto II = TCs.first, IE = TCs.second; II != IE; ++II)
152 const Arg &A,
size_t &Position) {
153 const char RefinementStepToken =
':';
154 Position = In.find(RefinementStepToken);
155 if (Position != StringRef::npos) {
156 StringRef Option = A.getOption().getName();
157 StringRef RefStep = In.substr(Position + 1);
165 if (RefStep.size() != 1) {
166 D.Diag(diag::err_drv_invalid_value) << Option << RefStep;
169 char RefStepChar = RefStep[0];
170 if (RefStepChar <
'0' || RefStepChar >
'9') {
171 D.Diag(diag::err_drv_invalid_value) << Option << RefStep;
180 ArgStringList &OutStrings) {
181 StringRef DisabledPrefixIn =
"!";
182 StringRef DisabledPrefixOut =
"!";
183 StringRef EnabledPrefixOut =
"";
184 StringRef Out =
"-mrecip=";
186 Arg *A = Args.getLastArg(options::OPT_mrecip, options::OPT_mrecip_EQ);
190 unsigned NumOptions = A->getNumValues();
191 if (NumOptions == 0) {
193 OutStrings.push_back(Args.MakeArgString(Out +
"all"));
198 if (NumOptions == 1) {
199 StringRef Val = A->getValue(0);
203 StringRef ValBase = Val.slice(0, RefStepLoc);
204 if (ValBase ==
"all" || ValBase ==
"none" || ValBase ==
"default") {
205 OutStrings.push_back(Args.MakeArgString(Out + Val));
214 llvm::StringMap<bool> OptionStrings;
215 OptionStrings.insert(std::make_pair(
"divd",
false));
216 OptionStrings.insert(std::make_pair(
"divf",
false));
217 OptionStrings.insert(std::make_pair(
"divh",
false));
218 OptionStrings.insert(std::make_pair(
"vec-divd",
false));
219 OptionStrings.insert(std::make_pair(
"vec-divf",
false));
220 OptionStrings.insert(std::make_pair(
"vec-divh",
false));
221 OptionStrings.insert(std::make_pair(
"sqrtd",
false));
222 OptionStrings.insert(std::make_pair(
"sqrtf",
false));
223 OptionStrings.insert(std::make_pair(
"sqrth",
false));
224 OptionStrings.insert(std::make_pair(
"vec-sqrtd",
false));
225 OptionStrings.insert(std::make_pair(
"vec-sqrtf",
false));
226 OptionStrings.insert(std::make_pair(
"vec-sqrth",
false));
228 for (
unsigned i = 0; i != NumOptions; ++i) {
229 StringRef Val = A->getValue(i);
231 bool IsDisabled = Val.starts_with(DisabledPrefixIn);
240 StringRef ValBase = Val.slice(0, RefStep);
241 llvm::StringMap<bool>::iterator OptionIter = OptionStrings.find(ValBase);
242 if (OptionIter == OptionStrings.end()) {
244 OptionIter = OptionStrings.find(ValBase.str() +
'f');
245 if (OptionIter == OptionStrings.end()) {
247 D.Diag(diag::err_drv_unknown_argument) << Val;
253 if (OptionStrings[ValBase.str() +
'd'] ||
254 OptionStrings[ValBase.str() +
'h']) {
255 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Val;
260 if (OptionIter->second ==
true) {
262 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Val;
267 OptionIter->second =
true;
271 if (ValBase.back() !=
'f' && ValBase.back() !=
'd' && ValBase.back() !=
'h') {
272 OptionStrings[ValBase.str() +
'd'] =
true;
273 OptionStrings[ValBase.str() +
'h'] =
true;
277 StringRef Prefix = IsDisabled ? DisabledPrefixOut : EnabledPrefixOut;
278 Out = Args.MakeArgString(Out + Prefix + Val);
279 if (i != NumOptions - 1)
280 Out = Args.MakeArgString(Out +
",");
283 OutStrings.push_back(Args.MakeArgString(Out));
289 ArgStringList &CmdArgs) {
290 Arg *A = Args.getLastArg(options::OPT_mprefer_vector_width_EQ);
294 StringRef
Value = A->getValue();
295 if (
Value ==
"none") {
296 CmdArgs.push_back(
"-mprefer-vector-width=none");
299 if (
Value.getAsInteger(10, Width)) {
300 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() <<
Value;
303 CmdArgs.push_back(Args.MakeArgString(
"-mprefer-vector-width=" +
Value));
309 const llvm::Triple &Triple) {
316 if (!Triple.isMacOSX())
319 return (!Triple.isMacOSXVersionLT(10, 5) &&
320 (Triple.getArch() == llvm::Triple::x86_64 ||
321 Triple.getArch() == llvm::Triple::arm));
331 ArgStringList &CmdArgs) {
332 const llvm::Triple &Triple = TC.
getTriple();
337 Args.ClaimAllArgs(options::OPT_fexceptions);
338 Args.ClaimAllArgs(options::OPT_fno_exceptions);
339 Args.ClaimAllArgs(options::OPT_fobjc_exceptions);
340 Args.ClaimAllArgs(options::OPT_fno_objc_exceptions);
341 Args.ClaimAllArgs(options::OPT_fcxx_exceptions);
342 Args.ClaimAllArgs(options::OPT_fno_cxx_exceptions);
343 Args.ClaimAllArgs(options::OPT_fasync_exceptions);
344 Args.ClaimAllArgs(options::OPT_fno_async_exceptions);
349 bool EH = Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
353 if (Triple.isWindowsMSVCEnvironment()) {
354 bool EHa = Args.hasFlag(options::OPT_fasync_exceptions,
355 options::OPT_fno_async_exceptions,
false);
357 CmdArgs.push_back(
"-fasync-exceptions");
365 Args.hasFlag(options::OPT_fobjc_exceptions,
366 options::OPT_fno_objc_exceptions,
true)) {
367 CmdArgs.push_back(
"-fobjc-exceptions");
374 bool CXXExceptionsEnabled = Triple.getArch() != llvm::Triple::xcore &&
375 !Triple.isPS() && !Triple.isDriverKit();
376 Arg *ExceptionArg = Args.getLastArg(
377 options::OPT_fcxx_exceptions, options::OPT_fno_cxx_exceptions,
378 options::OPT_fexceptions, options::OPT_fno_exceptions);
380 CXXExceptionsEnabled =
381 ExceptionArg->getOption().matches(options::OPT_fcxx_exceptions) ||
382 ExceptionArg->getOption().matches(options::OPT_fexceptions);
384 if (CXXExceptionsEnabled) {
385 CmdArgs.push_back(
"-fcxx-exceptions");
394 Args.AddLastArg(CmdArgs, options::OPT_fignore_exceptions);
396 Args.addOptInFlag(CmdArgs, options::OPT_fassume_nothrow_exception_dtor,
397 options::OPT_fno_assume_nothrow_exception_dtor);
400 CmdArgs.push_back(
"-fexceptions");
416 return Args.hasFlag(options::OPT_fautolink, options::OPT_fno_autolink,
422 ArgStringList &CmdArgs,
423 const llvm::vfs::FileSystem &VFS) {
424 if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ,
425 options::OPT_fdebug_compilation_dir_EQ)) {
426 if (A->getOption().matches(options::OPT_ffile_compilation_dir_EQ))
427 CmdArgs.push_back(Args.MakeArgString(Twine(
"-fdebug-compilation-dir=") +
430 A->render(Args, CmdArgs);
431 }
else if (llvm::ErrorOr<std::string> CWD =
432 VFS.getCurrentWorkingDirectory()) {
433 CmdArgs.push_back(Args.MakeArgString(
"-fdebug-compilation-dir=" + *CWD));
435 StringRef
Path(CmdArgs.back());
436 return Path.substr(
Path.find(
'=') + 1).data();
440 const char *DebugCompilationDir,
441 const char *OutputFileName) {
443 for (
auto *Arg : Args.filtered(options::OPT_Xclang))
444 if (StringRef(Arg->getValue()).starts_with(
"-object-file-name"))
447 if (Args.hasArg(options::OPT_object_file_name_EQ))
451 if (ObjFileNameForDebug !=
"-" &&
452 !llvm::sys::path::is_absolute(ObjFileNameForDebug) &&
453 (!DebugCompilationDir ||
454 llvm::sys::path::is_absolute(DebugCompilationDir))) {
456 llvm::sys::fs::make_absolute(ObjFileNameForDebug);
462 llvm::sys::path::Style Style =
463 llvm::sys::path::is_absolute(ObjFileNameForDebug)
464 ? llvm::sys::path::Style::native
465 : llvm::sys::path::Style::windows_backslash;
466 llvm::sys::path::remove_dots(ObjFileNameForDebug,
true,
469 Args.MakeArgString(Twine(
"-object-file-name=") + ObjFileNameForDebug));
474 const ArgList &Args, ArgStringList &CmdArgs) {
475 auto AddOneArg = [&](StringRef Map, StringRef Name) {
476 if (!Map.contains(
'='))
477 D.Diag(diag::err_drv_invalid_argument_to_option) << Map << Name;
479 CmdArgs.push_back(Args.MakeArgString(
"-fdebug-prefix-map=" + Map));
482 for (
const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
483 options::OPT_fdebug_prefix_map_EQ)) {
484 AddOneArg(A->getValue(), A->getOption().getName());
488 if (GlobalRemapEntry.empty())
490 AddOneArg(GlobalRemapEntry,
"environment");
495 ArgStringList &CmdArgs) {
496 for (
const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
497 options::OPT_fmacro_prefix_map_EQ)) {
498 StringRef Map = A->getValue();
499 if (!Map.contains(
'='))
500 D.Diag(diag::err_drv_invalid_argument_to_option)
501 << Map << A->getOption().getName();
503 CmdArgs.push_back(Args.MakeArgString(
"-fmacro-prefix-map=" + Map));
510 ArgStringList &CmdArgs) {
511 for (
const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
512 options::OPT_fcoverage_prefix_map_EQ)) {
513 StringRef Map = A->getValue();
514 if (!Map.contains(
'='))
515 D.Diag(diag::err_drv_invalid_argument_to_option)
516 << Map << A->getOption().getName();
518 CmdArgs.push_back(Args.MakeArgString(
"-fcoverage-prefix-map=" + Map));
527 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
528 if (A->getOption().matches(options::OPT_O4) ||
529 A->getOption().matches(options::OPT_Ofast))
532 if (A->getOption().matches(options::OPT_O0))
535 assert(A->getOption().matches(options::OPT_O) &&
"Must have a -O flag");
538 StringRef S(A->getValue());
546 unsigned OptLevel = 0;
547 if (S.getAsInteger(10, OptLevel))
558 ArgStringList &CmdArgs) {
561 if (Args.hasArg(options::OPT_verify_pch) && Input.
getType() == types::TY_PCH)
564 CmdArgs.push_back(
"-x");
565 if (Args.hasArg(options::OPT_rewrite_objc))
571 const char *ClangType;
573 case types::TY_CXXModule:
576 case types::TY_PP_CXXModule:
577 ClangType =
"c++-cpp-output";
583 CmdArgs.push_back(ClangType);
590 ArgStringList &CmdArgs) {
592 auto *PGOGenerateArg = Args.getLastArg(options::OPT_fprofile_generate,
593 options::OPT_fprofile_generate_EQ,
594 options::OPT_fno_profile_generate);
595 if (PGOGenerateArg &&
596 PGOGenerateArg->getOption().matches(options::OPT_fno_profile_generate))
597 PGOGenerateArg =
nullptr;
601 auto *ProfileGenerateArg = Args.getLastArg(
602 options::OPT_fprofile_instr_generate,
603 options::OPT_fprofile_instr_generate_EQ,
604 options::OPT_fno_profile_instr_generate);
605 if (ProfileGenerateArg &&
606 ProfileGenerateArg->getOption().matches(
607 options::OPT_fno_profile_instr_generate))
608 ProfileGenerateArg =
nullptr;
610 if (PGOGenerateArg && ProfileGenerateArg)
611 D.Diag(diag::err_drv_argument_not_allowed_with)
612 << PGOGenerateArg->getSpelling() << ProfileGenerateArg->getSpelling();
616 if (PGOGenerateArg && ProfileUseArg)
617 D.Diag(diag::err_drv_argument_not_allowed_with)
618 << ProfileUseArg->getSpelling() << PGOGenerateArg->getSpelling();
620 if (ProfileGenerateArg && ProfileUseArg)
621 D.Diag(diag::err_drv_argument_not_allowed_with)
622 << ProfileGenerateArg->getSpelling() << ProfileUseArg->getSpelling();
624 if (CSPGOGenerateArg && PGOGenerateArg) {
625 D.Diag(diag::err_drv_argument_not_allowed_with)
626 << CSPGOGenerateArg->getSpelling() << PGOGenerateArg->getSpelling();
627 PGOGenerateArg =
nullptr;
632 D.Diag(diag::err_drv_unsupported_opt_for_target)
633 << ProfileSampleUseArg->getSpelling() << TC.
getTriple().str();
636 if (ProfileGenerateArg) {
637 if (ProfileGenerateArg->getOption().matches(
638 options::OPT_fprofile_instr_generate_EQ))
639 CmdArgs.push_back(Args.MakeArgString(Twine(
"-fprofile-instrument-path=") +
640 ProfileGenerateArg->getValue()));
642 CmdArgs.push_back(
"-fprofile-instrument=clang");
643 if (TC.
getTriple().isWindowsMSVCEnvironment() &&
644 Args.hasFlag(options::OPT_frtlib_defaultlib,
645 options::OPT_fno_rtlib_defaultlib,
true)) {
647 CmdArgs.push_back(Args.MakeArgString(
652 Arg *PGOGenArg =
nullptr;
653 if (PGOGenerateArg) {
654 assert(!CSPGOGenerateArg);
655 PGOGenArg = PGOGenerateArg;
656 CmdArgs.push_back(
"-fprofile-instrument=llvm");
658 if (CSPGOGenerateArg) {
659 assert(!PGOGenerateArg);
660 PGOGenArg = CSPGOGenerateArg;
661 CmdArgs.push_back(
"-fprofile-instrument=csllvm");
664 if (TC.
getTriple().isWindowsMSVCEnvironment() &&
665 Args.hasFlag(options::OPT_frtlib_defaultlib,
666 options::OPT_fno_rtlib_defaultlib,
true)) {
668 CmdArgs.push_back(Args.MakeArgString(
671 if (PGOGenArg->getOption().matches(
672 PGOGenerateArg ? options::OPT_fprofile_generate_EQ
673 : options::OPT_fcs_profile_generate_EQ)) {
675 llvm::sys::path::append(
Path,
"default_%m.profraw");
677 Args.MakeArgString(Twine(
"-fprofile-instrument-path=") +
Path));
682 if (ProfileUseArg->getOption().matches(options::OPT_fprofile_instr_use_EQ))
683 CmdArgs.push_back(Args.MakeArgString(
684 Twine(
"-fprofile-instrument-use-path=") + ProfileUseArg->getValue()));
685 else if ((ProfileUseArg->getOption().matches(
686 options::OPT_fprofile_use_EQ) ||
687 ProfileUseArg->getOption().matches(
688 options::OPT_fprofile_instr_use))) {
690 ProfileUseArg->getNumValues() == 0 ?
"" : ProfileUseArg->getValue());
691 if (
Path.empty() || llvm::sys::fs::is_directory(
Path))
692 llvm::sys::path::append(
Path,
"default.profdata");
694 Args.MakeArgString(Twine(
"-fprofile-instrument-use-path=") +
Path));
698 bool EmitCovNotes = Args.hasFlag(options::OPT_ftest_coverage,
699 options::OPT_fno_test_coverage,
false) ||
700 Args.hasArg(options::OPT_coverage);
703 if (Args.hasFlag(options::OPT_fcoverage_mapping,
704 options::OPT_fno_coverage_mapping,
false)) {
705 if (!ProfileGenerateArg)
706 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
707 <<
"-fcoverage-mapping"
708 <<
"-fprofile-instr-generate";
710 CmdArgs.push_back(
"-fcoverage-mapping");
713 if (Args.hasFlag(options::OPT_fmcdc_coverage, options::OPT_fno_mcdc_coverage,
715 if (!Args.hasFlag(options::OPT_fcoverage_mapping,
716 options::OPT_fno_coverage_mapping,
false))
717 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
719 <<
"-fcoverage-mapping";
721 CmdArgs.push_back(
"-fcoverage-mcdc");
724 if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ,
725 options::OPT_fcoverage_compilation_dir_EQ)) {
726 if (A->getOption().matches(options::OPT_ffile_compilation_dir_EQ))
727 CmdArgs.push_back(Args.MakeArgString(
728 Twine(
"-fcoverage-compilation-dir=") + A->getValue()));
730 A->render(Args, CmdArgs);
731 }
else if (llvm::ErrorOr<std::string> CWD =
732 D.getVFS().getCurrentWorkingDirectory()) {
733 CmdArgs.push_back(Args.MakeArgString(
"-fcoverage-compilation-dir=" + *CWD));
736 if (Args.hasArg(options::OPT_fprofile_exclude_files_EQ)) {
737 auto *Arg = Args.getLastArg(options::OPT_fprofile_exclude_files_EQ);
738 if (!Args.hasArg(options::OPT_coverage))
739 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
740 <<
"-fprofile-exclude-files="
743 StringRef
v = Arg->getValue();
745 Args.MakeArgString(Twine(
"-fprofile-exclude-files=" +
v)));
748 if (Args.hasArg(options::OPT_fprofile_filter_files_EQ)) {
749 auto *Arg = Args.getLastArg(options::OPT_fprofile_filter_files_EQ);
750 if (!Args.hasArg(options::OPT_coverage))
751 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
752 <<
"-fprofile-filter-files="
755 StringRef
v = Arg->getValue();
756 CmdArgs.push_back(Args.MakeArgString(Twine(
"-fprofile-filter-files=" +
v)));
759 if (
const auto *A = Args.getLastArg(options::OPT_fprofile_update_EQ)) {
760 StringRef Val = A->getValue();
761 if (Val ==
"atomic" || Val ==
"prefer-atomic")
762 CmdArgs.push_back(
"-fprofile-update=atomic");
763 else if (Val !=
"single")
764 D.Diag(diag::err_drv_unsupported_option_argument)
765 << A->getSpelling() << Val;
768 int FunctionGroups = 1;
769 int SelectedFunctionGroup = 0;
770 if (
const auto *A = Args.getLastArg(options::OPT_fprofile_function_groups)) {
771 StringRef Val = A->getValue();
772 if (Val.getAsInteger(0, FunctionGroups) || FunctionGroups < 1)
773 D.Diag(diag::err_drv_invalid_int_value) << A->getAsString(Args) << Val;
776 Args.getLastArg(options::OPT_fprofile_selected_function_group)) {
777 StringRef Val = A->getValue();
778 if (Val.getAsInteger(0, SelectedFunctionGroup) ||
779 SelectedFunctionGroup < 0 || SelectedFunctionGroup >= FunctionGroups)
780 D.Diag(diag::err_drv_invalid_int_value) << A->getAsString(Args) << Val;
782 if (FunctionGroups != 1)
783 CmdArgs.push_back(Args.MakeArgString(
"-fprofile-function-groups=" +
784 Twine(FunctionGroups)));
785 if (SelectedFunctionGroup != 0)
786 CmdArgs.push_back(Args.MakeArgString(
"-fprofile-selected-function-group=" +
787 Twine(SelectedFunctionGroup)));
793 Arg *FProfileDir =
nullptr;
794 if (Args.hasArg(options::OPT_fprofile_arcs) ||
795 Args.hasArg(options::OPT_coverage))
796 FProfileDir = Args.getLastArg(options::OPT_fprofile_dir);
801 if (EmitCovNotes || EmitCovData) {
803 if (Arg *DumpDir = Args.getLastArgNoClaim(options::OPT_dumpdir)) {
806 CoverageFilename = DumpDir->getValue();
807 CoverageFilename += llvm::sys::path::filename(Output.
getBaseInput());
808 }
else if (Arg *FinalOutput =
809 C.getArgs().getLastArg(options::OPT__SLASH_Fo)) {
810 CoverageFilename = FinalOutput->getValue();
811 }
else if (Arg *FinalOutput =
C.getArgs().getLastArg(options::OPT_o)) {
812 CoverageFilename = FinalOutput->getValue();
814 CoverageFilename = llvm::sys::path::filename(Output.
getBaseInput());
816 if (llvm::sys::path::is_relative(CoverageFilename))
817 (void)
D.getVFS().makeAbsolute(CoverageFilename);
818 llvm::sys::path::replace_extension(CoverageFilename,
"gcno");
821 Args.MakeArgString(
"-coverage-notes-file=" + CoverageFilename));
827 CoverageFilename = FProfileDir->getValue();
828 llvm::sys::path::append(CoverageFilename, Gcno);
830 llvm::sys::path::replace_extension(CoverageFilename,
"gcda");
832 Args.MakeArgString(
"-coverage-data-file=" + CoverageFilename));
839 llvm::codegenoptions::DebugInfoKind DebugInfoKind,
840 unsigned DwarfVersion,
841 llvm::DebuggerKind DebuggerTuning) {
843 if (DwarfVersion > 0)
845 Args.MakeArgString(
"-dwarf-version=" + Twine(DwarfVersion)));
846 switch (DebuggerTuning) {
847 case llvm::DebuggerKind::GDB:
848 CmdArgs.push_back(
"-debugger-tuning=gdb");
850 case llvm::DebuggerKind::LLDB:
851 CmdArgs.push_back(
"-debugger-tuning=lldb");
853 case llvm::DebuggerKind::SCE:
854 CmdArgs.push_back(
"-debugger-tuning=sce");
856 case llvm::DebuggerKind::DBX:
857 CmdArgs.push_back(
"-debugger-tuning=dbx");
866 assert(A &&
"Expected non-nullptr argument.");
869 D.Diag(diag::warn_drv_unsupported_debug_info_opt_for_target)
875 ArgStringList &CmdArgs,
878 const Arg *A = Args.getLastArg(options::OPT_gz_EQ);
882 StringRef
Value = A->getValue();
883 if (
Value ==
"none") {
884 CmdArgs.push_back(
"--compress-debug-sections=none");
885 }
else if (
Value ==
"zlib") {
886 if (llvm::compression::zlib::isAvailable()) {
888 Args.MakeArgString(
"--compress-debug-sections=" + Twine(
Value)));
890 D.Diag(diag::warn_debug_compression_unavailable) <<
"zlib";
892 }
else if (
Value ==
"zstd") {
893 if (llvm::compression::zstd::isAvailable()) {
895 Args.MakeArgString(
"--compress-debug-sections=" + Twine(
Value)));
897 D.Diag(diag::warn_debug_compression_unavailable) <<
"zstd";
900 D.Diag(diag::err_drv_unsupported_option_argument)
901 << A->getSpelling() <<
Value;
908 ArgStringList &CmdArgs,
909 bool IsCC1As =
false) {
917 CmdArgs.insert(CmdArgs.begin() + 1,
918 Args.MakeArgString(Twine(
"--amdhsa-code-object-version=") +
920 CmdArgs.insert(CmdArgs.begin() + 1,
"-mllvm");
923 CmdArgs.insert(CmdArgs.begin() + 1,
924 Args.MakeArgString(Twine(
"-mcode-object-version=") +
930 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MemBuf =
931 D.getVFS().getBufferForFile(
Path);
934 llvm::file_magic Magic = llvm::identify_magic((*MemBuf)->getBuffer());
935 if (Magic == llvm::file_magic::unknown)
939 if (Magic == llvm::file_magic::clang_ast)
942 llvm::object::ObjectFile::createObjectFile(**MemBuf, Magic);
943 return !Obj.takeError();
947 llvm::ErrorOr<llvm::vfs::Status> Status =
D.getVFS().status(
Path);
951 if (Status->isDirectory()) {
953 for (llvm::vfs::directory_iterator DI =
D.getVFS().dir_begin(
Path, EC), DE;
954 !EC && DI != DE; DI = DI.increment(EC)) {
958 D.Diag(diag::warn_drv_pch_ignoring_gch_dir) <<
Path;
964 D.Diag(diag::warn_drv_pch_ignoring_gch_file) <<
Path;
969 const Driver &
D,
const ArgList &Args,
970 ArgStringList &CmdArgs,
977 Args.AddLastArg(CmdArgs, options::OPT_C);
978 Args.AddLastArg(CmdArgs, options::OPT_CC);
981 Arg *ArgM = Args.getLastArg(options::OPT_MM);
983 ArgM = Args.getLastArg(options::OPT_M);
984 Arg *ArgMD = Args.getLastArg(options::OPT_MMD);
986 ArgMD = Args.getLastArg(options::OPT_MD);
990 CmdArgs.push_back(
"-w");
997 if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
998 DepFile = MF->getValue();
999 C.addFailureResultFile(DepFile, &JA);
1000 }
else if (Output.
getType() == types::TY_Dependencies) {
1002 }
else if (!ArgMD) {
1006 C.addFailureResultFile(DepFile, &JA);
1008 CmdArgs.push_back(
"-dependency-file");
1009 CmdArgs.push_back(DepFile);
1011 bool HasTarget =
false;
1012 for (
const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) {
1015 if (A->getOption().matches(options::OPT_MT)) {
1016 A->render(Args, CmdArgs);
1018 CmdArgs.push_back(
"-MT");
1021 CmdArgs.push_back(Args.MakeArgString(Quoted));
1027 const char *DepTarget;
1031 Arg *OutputOpt = Args.getLastArg(options::OPT_o, options::OPT__SLASH_Fo);
1032 if (OutputOpt && Output.
getType() != types::TY_Dependencies) {
1033 DepTarget = OutputOpt->getValue();
1039 llvm::sys::path::replace_extension(
P,
"o");
1040 DepTarget = Args.MakeArgString(llvm::sys::path::filename(
P));
1043 CmdArgs.push_back(
"-MT");
1046 CmdArgs.push_back(Args.MakeArgString(Quoted));
1049 if (ArgM->getOption().matches(options::OPT_M) ||
1050 ArgM->getOption().matches(options::OPT_MD))
1051 CmdArgs.push_back(
"-sys-header-deps");
1052 if ((isa<PrecompileJobAction>(JA) &&
1053 !Args.hasArg(options::OPT_fno_module_file_deps)) ||
1054 Args.hasArg(options::OPT_fmodule_file_deps))
1055 CmdArgs.push_back(
"-module-file-deps");
1058 if (Args.hasArg(options::OPT_MG)) {
1059 if (!ArgM || ArgM->getOption().matches(options::OPT_MD) ||
1060 ArgM->getOption().matches(options::OPT_MMD))
1061 D.Diag(diag::err_drv_mg_requires_m_or_mm);
1062 CmdArgs.push_back(
"-MG");
1065 Args.AddLastArg(CmdArgs, options::OPT_MP);
1066 Args.AddLastArg(CmdArgs, options::OPT_MV);
1080 !Args.hasArg(options::OPT_nostdinc) &&
1081 !Args.hasArg(options::OPT_nogpuinc) &&
1084 if (!Args.hasArg(options::OPT_nobuiltininc)) {
1088 llvm::sys::path::append(
P,
"include");
1089 llvm::sys::path::append(
P,
"openmp_wrappers");
1090 CmdArgs.push_back(
"-internal-isystem");
1091 CmdArgs.push_back(Args.MakeArgString(
P));
1094 CmdArgs.push_back(
"-include");
1095 CmdArgs.push_back(
"__clang_openmp_device_functions.h");
1098 if (Args.hasArg(options::OPT_foffload_via_llvm)) {
1102 llvm::sys::path::append(
P,
"include",
"llvm_offload_wrappers");
1103 CmdArgs.append({
"-internal-isystem", Args.MakeArgString(
P),
"-include"});
1105 CmdArgs.push_back(
"__llvm_offload_device.h");
1107 CmdArgs.push_back(
"__llvm_offload_host.h");
1117 const Arg *YcArg = Args.getLastArg(options::OPT__SLASH_Yc);
1118 const Arg *YuArg = Args.getLastArg(options::OPT__SLASH_Yu);
1121 CmdArgs.push_back(Args.MakeArgString(
"-building-pch-with-obj"));
1124 if (Args.hasFlag(options::OPT_fpch_instantiate_templates,
1125 options::OPT_fno_pch_instantiate_templates,
true))
1126 CmdArgs.push_back(Args.MakeArgString(
"-fpch-instantiate-templates"));
1128 if (YcArg || YuArg) {
1129 StringRef ThroughHeader = YcArg ? YcArg->getValue() : YuArg->getValue();
1130 if (!isa<PrecompileJobAction>(JA)) {
1131 CmdArgs.push_back(
"-include-pch");
1132 CmdArgs.push_back(Args.MakeArgString(
D.GetClPchPath(
1133 C, !ThroughHeader.empty()
1135 : llvm::sys::path::filename(Inputs[0].getBaseInput()))));
1138 if (ThroughHeader.empty()) {
1139 CmdArgs.push_back(Args.MakeArgString(
1140 Twine(
"-pch-through-hdrstop-") + (YcArg ?
"create" :
"use")));
1143 Args.MakeArgString(Twine(
"-pch-through-header=") + ThroughHeader));
1148 bool RenderedImplicitInclude =
false;
1149 for (
const Arg *A : Args.filtered(options::OPT_clang_i_Group)) {
1150 if (A->getOption().matches(options::OPT_include) &&
1151 D.getProbePrecompiled()) {
1153 bool IsFirstImplicitInclude = !RenderedImplicitInclude;
1154 RenderedImplicitInclude =
true;
1156 bool FoundPCH =
false;
1161 llvm::sys::path::replace_extension(
P,
"pch");
1162 if (
D.getVFS().exists(
P))
1167 llvm::sys::path::replace_extension(
P,
"gch");
1172 if (IsFirstImplicitInclude) {
1174 CmdArgs.push_back(
"-include-pch");
1175 CmdArgs.push_back(Args.MakeArgString(
P));
1179 D.Diag(diag::warn_drv_pch_not_first_include) <<
P
1180 << A->getAsString(Args);
1183 }
else if (A->getOption().matches(options::OPT_isystem_after)) {
1190 }
else if (A->getOption().matches(options::OPT_stdlibxx_isystem)) {
1193 }
else if (A->getOption().matches(options::OPT_ibuiltininc)) {
1200 A->render(Args, CmdArgs);
1203 Args.addAllArgs(CmdArgs,
1204 {options::OPT_D, options::OPT_U, options::OPT_I_Group,
1205 options::OPT_F, options::OPT_index_header_map,
1206 options::OPT_embed_dir_EQ});
1214 Args.AddAllArgValues(CmdArgs, options::OPT_Wp_COMMA,
1215 options::OPT_Xpreprocessor);
1218 if (Arg *A = Args.getLastArg(options::OPT_I_))
1219 D.Diag(diag::err_drv_I_dash_not_supported) << A->getAsString(Args);
1223 StringRef sysroot =
C.getSysRoot();
1224 if (sysroot !=
"") {
1225 if (!Args.hasArg(options::OPT_isysroot)) {
1226 CmdArgs.push_back(
"-isysroot");
1227 CmdArgs.push_back(
C.getArgs().MakeArgString(sysroot));
1244 addDirectoryList(Args, CmdArgs,
"-objcxx-isystem",
"OBJCPLUS_INCLUDE_PATH");
1252 bool HasStdlibxxIsystem = Args.hasArg(options::OPT_stdlibxx_isystem);
1255 [&Args, &CmdArgs, HasStdlibxxIsystem](
const ToolChain &TC) {
1265 if (!Args.hasArg(options::OPT_nostdinc) &&
1266 !Args.hasArg(options::OPT_nogpuinc) &&
1267 !Args.hasArg(options::OPT_nobuiltininc)) {
1275 llvm::sys::path::append(
P,
"include");
1276 llvm::sys::path::append(
P,
getToolChain().getTripleString());
1277 CmdArgs.push_back(
"-internal-isystem");
1278 CmdArgs.push_back(Args.MakeArgString(
P));
1283 llvm::sys::path::append(
P,
"include");
1284 llvm::sys::path::append(
P,
"llvm_libc_wrappers");
1285 CmdArgs.push_back(
"-internal-isystem");
1286 CmdArgs.push_back(Args.MakeArgString(
P));
1293 [&Args, &CmdArgs](
const ToolChain &TC) {
1304 Args.AddLastArg(CmdArgs, options::OPT_ffile_reproducible,
1305 options::OPT_fno_file_reproducible);
1307 if (
const char *Epoch = std::getenv(
"SOURCE_DATE_EPOCH")) {
1308 CmdArgs.push_back(
"-source-date-epoch");
1309 CmdArgs.push_back(Args.MakeArgString(Epoch));
1312 Args.addOptInFlag(CmdArgs, options::OPT_fdefine_target_os_macros,
1313 options::OPT_fno_define_target_os_macros);
1318 switch (Triple.getArch()) {
1322 case llvm::Triple::aarch64:
1323 case llvm::Triple::aarch64_32:
1324 case llvm::Triple::aarch64_be:
1325 case llvm::Triple::arm:
1326 case llvm::Triple::armeb:
1327 case llvm::Triple::thumb:
1328 case llvm::Triple::thumbeb:
1329 if (Triple.isOSDarwin() || Triple.isOSWindows())
1333 case llvm::Triple::ppc:
1334 case llvm::Triple::ppc64:
1335 if (Triple.isOSDarwin())
1339 case llvm::Triple::hexagon:
1340 case llvm::Triple::ppcle:
1341 case llvm::Triple::ppc64le:
1342 case llvm::Triple::riscv32:
1343 case llvm::Triple::riscv64:
1344 case llvm::Triple::systemz:
1345 case llvm::Triple::xcore:
1351 const ArgList &Args) {
1354 if (!Triple.isOSDarwin())
1358 return Args.getAllArgValues(options::OPT_arch).size() > 1;
1362 const llvm::Triple &Triple) {
1367 bool hasExplicitOutputFile =
1368 Args.getLastArg(options::OPT_foptimization_record_file_EQ);
1370 D.Diag(diag::err_drv_invalid_output_with_multiple_archs)
1371 <<
"-foptimization-record-file";
1378 const llvm::Triple &Triple,
1381 StringRef Format =
"yaml";
1382 if (
const Arg *A = Args.getLastArg(options::OPT_fsave_optimization_record_EQ))
1383 Format = A->getValue();
1385 CmdArgs.push_back(
"-opt-record-file");
1387 const Arg *A = Args.getLastArg(options::OPT_foptimization_record_file_EQ);
1389 CmdArgs.push_back(A->getValue());
1391 bool hasMultipleArchs =
1392 Triple.isOSDarwin() &&
1393 Args.getAllArgValues(options::OPT_arch).size() > 1;
1397 if (Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)) {
1398 if (Arg *FinalOutput = Args.getLastArg(options::OPT_o))
1399 F = FinalOutput->getValue();
1401 if (Format !=
"yaml" &&
1402 Triple.isOSDarwin() &&
1416 llvm::sys::path::replace_extension(F,
"");
1418 Triple.normalize());
1428 if (hasMultipleArchs) {
1432 llvm::sys::path::replace_extension(F,
"");
1435 F += Triple.getArchName();
1437 llvm::sys::path::replace_extension(F, OldExtension);
1441 Extension +=
"opt.";
1442 Extension += Format;
1444 llvm::sys::path::replace_extension(F, Extension);
1445 CmdArgs.push_back(Args.MakeArgString(F));
1449 Args.getLastArg(options::OPT_foptimization_record_passes_EQ)) {
1450 CmdArgs.push_back(
"-opt-record-passes");
1451 CmdArgs.push_back(A->getValue());
1454 if (!Format.empty()) {
1455 CmdArgs.push_back(
"-opt-record-format");
1456 CmdArgs.push_back(Format.data());
1461 if (!Args.hasFlag(options::OPT_faapcs_bitfield_width,
1462 options::OPT_fno_aapcs_bitfield_width,
true))
1463 CmdArgs.push_back(
"-fno-aapcs-bitfield-width");
1465 if (Args.getLastArg(options::OPT_ForceAAPCSBitfieldLoad))
1466 CmdArgs.push_back(
"-faapcs-bitfield-load");
1470void RenderARMABI(
const Driver &
D,
const llvm::Triple &Triple,
1471 const ArgList &Args, ArgStringList &CmdArgs) {
1475 const char *ABIName =
nullptr;
1476 if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
1477 ABIName = A->getValue();
1479 std::string CPU =
getCPUName(
D, Args, Triple,
false);
1480 ABIName = llvm::ARM::computeDefaultTargetABI(Triple, CPU).data();
1483 CmdArgs.push_back(
"-target-abi");
1484 CmdArgs.push_back(ABIName);
1487void AddUnalignedAccessWarning(ArgStringList &CmdArgs) {
1488 auto StrictAlignIter =
1489 llvm::find_if(llvm::reverse(CmdArgs), [](StringRef Arg) {
1490 return Arg ==
"+strict-align" || Arg ==
"-strict-align";
1492 if (StrictAlignIter != CmdArgs.rend() &&
1493 StringRef(*StrictAlignIter) ==
"+strict-align")
1494 CmdArgs.push_back(
"-Wunaligned-access");
1502 if (!DriverArgs.hasArg(options::OPT_fptrauth_intrinsics,
1503 options::OPT_fno_ptrauth_intrinsics))
1504 CC1Args.push_back(
"-fptrauth-intrinsics");
1506 if (!DriverArgs.hasArg(options::OPT_fptrauth_calls,
1507 options::OPT_fno_ptrauth_calls))
1508 CC1Args.push_back(
"-fptrauth-calls");
1510 if (!DriverArgs.hasArg(options::OPT_fptrauth_returns,
1511 options::OPT_fno_ptrauth_returns))
1512 CC1Args.push_back(
"-fptrauth-returns");
1514 if (!DriverArgs.hasArg(options::OPT_fptrauth_auth_traps,
1515 options::OPT_fno_ptrauth_auth_traps))
1516 CC1Args.push_back(
"-fptrauth-auth-traps");
1518 if (!DriverArgs.hasArg(
1519 options::OPT_fptrauth_vtable_pointer_address_discrimination,
1520 options::OPT_fno_ptrauth_vtable_pointer_address_discrimination))
1521 CC1Args.push_back(
"-fptrauth-vtable-pointer-address-discrimination");
1523 if (!DriverArgs.hasArg(
1524 options::OPT_fptrauth_vtable_pointer_type_discrimination,
1525 options::OPT_fno_ptrauth_vtable_pointer_type_discrimination))
1526 CC1Args.push_back(
"-fptrauth-vtable-pointer-type-discrimination");
1528 if (!DriverArgs.hasArg(options::OPT_fptrauth_indirect_gotos,
1529 options::OPT_fno_ptrauth_indirect_gotos))
1530 CC1Args.push_back(
"-fptrauth-indirect-gotos");
1532 if (!DriverArgs.hasArg(options::OPT_fptrauth_init_fini,
1533 options::OPT_fno_ptrauth_init_fini))
1534 CC1Args.push_back(
"-fptrauth-init-fini");
1538 ArgStringList &CmdArgs,
bool isAArch64) {
1539 const Arg *A = isAArch64
1540 ? Args.getLastArg(options::OPT_msign_return_address_EQ,
1541 options::OPT_mbranch_protection_EQ)
1542 : Args.getLastArg(options::OPT_mbranch_protection_EQ);
1548 if (!(isAArch64 || (Triple.isArmT32() && Triple.isArmMClass())))
1549 D.Diag(diag::warn_incompatible_branch_protection_option)
1550 << Triple.getArchName();
1552 StringRef
Scope, Key;
1553 bool IndirectBranches, BranchProtectionPAuthLR, GuardedControlStack;
1555 if (A->getOption().matches(options::OPT_msign_return_address_EQ)) {
1556 Scope = A->getValue();
1558 D.Diag(diag::err_drv_unsupported_option_argument)
1559 << A->getSpelling() <<
Scope;
1561 IndirectBranches =
false;
1562 BranchProtectionPAuthLR =
false;
1563 GuardedControlStack =
false;
1566 llvm::ARM::ParsedBranchProtection PBP;
1567 bool EnablePAuthLR =
false;
1574 auto isPAuthLR = [](
const char *member) {
1575 llvm::AArch64::ExtensionInfo pauthlr_extension =
1576 llvm::AArch64::getExtensionByID(llvm::AArch64::AEK_PAUTHLR);
1577 return pauthlr_extension.PosTargetFeature == member;
1580 if (std::any_of(CmdArgs.begin(), CmdArgs.end(), isPAuthLR))
1581 EnablePAuthLR =
true;
1583 if (!llvm::ARM::parseBranchProtection(A->getValue(), PBP, DiagMsg,
1585 D.Diag(diag::err_drv_unsupported_option_argument)
1586 << A->getSpelling() << DiagMsg;
1587 if (!isAArch64 && PBP.Key ==
"b_key")
1588 D.Diag(diag::warn_unsupported_branch_protection)
1589 <<
"b-key" << A->getAsString(Args);
1592 BranchProtectionPAuthLR = PBP.BranchProtectionPAuthLR;
1593 IndirectBranches = PBP.BranchTargetEnforcement;
1594 GuardedControlStack = PBP.GuardedControlStack;
1598 Args.MakeArgString(Twine(
"-msign-return-address=") +
Scope));
1599 if (
Scope !=
"none") {
1600 if (Triple.getEnvironment() == llvm::Triple::PAuthTest)
1601 D.Diag(diag::err_drv_unsupported_opt_for_target)
1602 << A->getAsString(Args) << Triple.getTriple();
1604 Args.MakeArgString(Twine(
"-msign-return-address-key=") + Key));
1606 if (BranchProtectionPAuthLR) {
1607 if (Triple.getEnvironment() == llvm::Triple::PAuthTest)
1608 D.Diag(diag::err_drv_unsupported_opt_for_target)
1609 << A->getAsString(Args) << Triple.getTriple();
1611 Args.MakeArgString(Twine(
"-mbranch-protection-pauth-lr")));
1613 if (IndirectBranches)
1614 CmdArgs.push_back(
"-mbranch-target-enforce");
1617 if (GuardedControlStack) {
1618 if (Triple.getEnvironment() == llvm::Triple::PAuthTest)
1619 D.Diag(diag::err_drv_unsupported_opt_for_target)
1620 << A->getAsString(Args) << Triple.getTriple();
1621 CmdArgs.push_back(
"-mguarded-control-stack");
1625void Clang::AddARMTargetArgs(
const llvm::Triple &Triple,
const ArgList &Args,
1626 ArgStringList &CmdArgs,
bool KernelOrKext)
const {
1627 RenderARMABI(
getToolChain().getDriver(), Triple, Args, CmdArgs);
1634 CmdArgs.push_back(
"-msoft-float");
1635 CmdArgs.push_back(
"-mfloat-abi");
1636 CmdArgs.push_back(
"soft");
1639 CmdArgs.push_back(
"-mfloat-abi");
1640 CmdArgs.push_back(
"soft");
1644 CmdArgs.push_back(
"-mfloat-abi");
1645 CmdArgs.push_back(
"hard");
1649 if (Arg *A = Args.getLastArg(options::OPT_mglobal_merge,
1650 options::OPT_mno_global_merge)) {
1651 CmdArgs.push_back(
"-mllvm");
1652 if (A->getOption().matches(options::OPT_mno_global_merge))
1653 CmdArgs.push_back(
"-arm-global-merge=false");
1655 CmdArgs.push_back(
"-arm-global-merge=true");
1658 if (!Args.hasFlag(options::OPT_mimplicit_float,
1659 options::OPT_mno_implicit_float,
true))
1660 CmdArgs.push_back(
"-no-implicit-float");
1662 if (Args.getLastArg(options::OPT_mcmse))
1663 CmdArgs.push_back(
"-mcmse");
1670 AddUnalignedAccessWarning(CmdArgs);
1673void Clang::RenderTargetOptions(
const llvm::Triple &EffectiveTriple,
1674 const ArgList &Args,
bool KernelOrKext,
1675 ArgStringList &CmdArgs)
const {
1686 case llvm::Triple::arm:
1687 case llvm::Triple::armeb:
1688 case llvm::Triple::thumb:
1689 case llvm::Triple::thumbeb:
1691 AddARMTargetArgs(EffectiveTriple, Args, CmdArgs, KernelOrKext);
1694 case llvm::Triple::aarch64:
1695 case llvm::Triple::aarch64_32:
1696 case llvm::Triple::aarch64_be:
1697 AddAArch64TargetArgs(Args, CmdArgs);
1700 case llvm::Triple::loongarch32:
1701 case llvm::Triple::loongarch64:
1702 AddLoongArchTargetArgs(Args, CmdArgs);
1705 case llvm::Triple::mips:
1706 case llvm::Triple::mipsel:
1707 case llvm::Triple::mips64:
1708 case llvm::Triple::mips64el:
1709 AddMIPSTargetArgs(Args, CmdArgs);
1712 case llvm::Triple::ppc:
1713 case llvm::Triple::ppcle:
1714 case llvm::Triple::ppc64:
1715 case llvm::Triple::ppc64le:
1716 AddPPCTargetArgs(Args, CmdArgs);
1719 case llvm::Triple::riscv32:
1720 case llvm::Triple::riscv64:
1721 AddRISCVTargetArgs(Args, CmdArgs);
1724 case llvm::Triple::sparc:
1725 case llvm::Triple::sparcel:
1726 case llvm::Triple::sparcv9:
1727 AddSparcTargetArgs(Args, CmdArgs);
1730 case llvm::Triple::systemz:
1731 AddSystemZTargetArgs(Args, CmdArgs);
1734 case llvm::Triple::x86:
1735 case llvm::Triple::x86_64:
1736 AddX86TargetArgs(Args, CmdArgs);
1739 case llvm::Triple::lanai:
1740 AddLanaiTargetArgs(Args, CmdArgs);
1743 case llvm::Triple::hexagon:
1744 AddHexagonTargetArgs(Args, CmdArgs);
1747 case llvm::Triple::wasm32:
1748 case llvm::Triple::wasm64:
1749 AddWebAssemblyTargetArgs(Args, CmdArgs);
1752 case llvm::Triple::ve:
1753 AddVETargetArgs(Args, CmdArgs);
1759void RenderAArch64ABI(
const llvm::Triple &Triple,
const ArgList &Args,
1760 ArgStringList &CmdArgs) {
1761 const char *ABIName =
nullptr;
1762 if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
1763 ABIName = A->getValue();
1764 else if (Triple.isOSDarwin())
1765 ABIName =
"darwinpcs";
1766 else if (Triple.getEnvironment() == llvm::Triple::PAuthTest)
1767 ABIName =
"pauthtest";
1771 CmdArgs.push_back(
"-target-abi");
1772 CmdArgs.push_back(ABIName);
1776void Clang::AddAArch64TargetArgs(
const ArgList &Args,
1777 ArgStringList &CmdArgs)
const {
1780 if (!Args.hasFlag(options::OPT_mred_zone, options::OPT_mno_red_zone,
true) ||
1781 Args.hasArg(options::OPT_mkernel) ||
1782 Args.hasArg(options::OPT_fapple_kext))
1783 CmdArgs.push_back(
"-disable-red-zone");
1785 if (!Args.hasFlag(options::OPT_mimplicit_float,
1786 options::OPT_mno_implicit_float,
true))
1787 CmdArgs.push_back(
"-no-implicit-float");
1789 RenderAArch64ABI(Triple, Args, CmdArgs);
1792 if (Arg *A = Args.getLastArg(options::OPT_mglobal_merge,
1793 options::OPT_mno_global_merge)) {
1794 CmdArgs.push_back(
"-mllvm");
1795 if (A->getOption().matches(options::OPT_mno_global_merge))
1796 CmdArgs.push_back(
"-aarch64-enable-global-merge=false");
1798 CmdArgs.push_back(
"-aarch64-enable-global-merge=true");
1804 if (Triple.getEnvironment() == llvm::Triple::PAuthTest)
1808 if (Arg *A = Args.getLastArg(options::OPT_msve_vector_bits_EQ)) {
1809 StringRef Val = A->getValue();
1811 if (Val ==
"128" || Val ==
"256" || Val ==
"512" || Val ==
"1024" ||
1812 Val ==
"2048" || Val ==
"128+" || Val ==
"256+" || Val ==
"512+" ||
1813 Val ==
"1024+" || Val ==
"2048+") {
1815 if (!Val.consume_back(
"+")) {
1817 assert(!
Invalid &&
"Failed to parse value");
1819 Args.MakeArgString(
"-mvscale-max=" + llvm::Twine(Bits / 128)));
1823 assert(!
Invalid &&
"Failed to parse value");
1825 Args.MakeArgString(
"-mvscale-min=" + llvm::Twine(Bits / 128)));
1827 }
else if (Val !=
"scalable")
1829 D.Diag(diag::err_drv_unsupported_option_argument)
1830 << A->getSpelling() << Val;
1835 if (
const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
1836 CmdArgs.push_back(
"-tune-cpu");
1837 if (strcmp(A->getValue(),
"native") == 0)
1838 CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
1840 CmdArgs.push_back(A->getValue());
1843 AddUnalignedAccessWarning(CmdArgs);
1845 Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_intrinsics,
1846 options::OPT_fno_ptrauth_intrinsics);
1847 Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_calls,
1848 options::OPT_fno_ptrauth_calls);
1849 Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_returns,
1850 options::OPT_fno_ptrauth_returns);
1851 Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_auth_traps,
1852 options::OPT_fno_ptrauth_auth_traps);
1854 CmdArgs, options::OPT_fptrauth_vtable_pointer_address_discrimination,
1855 options::OPT_fno_ptrauth_vtable_pointer_address_discrimination);
1857 CmdArgs, options::OPT_fptrauth_vtable_pointer_type_discrimination,
1858 options::OPT_fno_ptrauth_vtable_pointer_type_discrimination);
1860 CmdArgs, options::OPT_fptrauth_type_info_vtable_pointer_discrimination,
1861 options::OPT_fno_ptrauth_type_info_vtable_pointer_discrimination);
1863 CmdArgs, options::OPT_fptrauth_function_pointer_type_discrimination,
1864 options::OPT_fno_ptrauth_function_pointer_type_discrimination);
1866 Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_indirect_gotos,
1867 options::OPT_fno_ptrauth_indirect_gotos);
1868 Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_init_fini,
1869 options::OPT_fno_ptrauth_init_fini);
1870 Args.addOptInFlag(CmdArgs,
1871 options::OPT_fptrauth_init_fini_address_discrimination,
1872 options::OPT_fno_ptrauth_init_fini_address_discrimination);
1875void Clang::AddLoongArchTargetArgs(
const ArgList &Args,
1876 ArgStringList &CmdArgs)
const {
1879 CmdArgs.push_back(
"-target-abi");
1885 if (
const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
1886 std::string TuneCPU = A->getValue();
1888 CmdArgs.push_back(
"-tune-cpu");
1889 CmdArgs.push_back(Args.MakeArgString(TuneCPU));
1893void Clang::AddMIPSTargetArgs(
const ArgList &Args,
1894 ArgStringList &CmdArgs)
const {
1901 CmdArgs.push_back(
"-target-abi");
1902 CmdArgs.push_back(ABIName.data());
1907 CmdArgs.push_back(
"-msoft-float");
1908 CmdArgs.push_back(
"-mfloat-abi");
1909 CmdArgs.push_back(
"soft");
1913 CmdArgs.push_back(
"-mfloat-abi");
1914 CmdArgs.push_back(
"hard");
1917 if (Arg *A = Args.getLastArg(options::OPT_mldc1_sdc1,
1918 options::OPT_mno_ldc1_sdc1)) {
1919 if (A->getOption().matches(options::OPT_mno_ldc1_sdc1)) {
1920 CmdArgs.push_back(
"-mllvm");
1921 CmdArgs.push_back(
"-mno-ldc1-sdc1");
1925 if (Arg *A = Args.getLastArg(options::OPT_mcheck_zero_division,
1926 options::OPT_mno_check_zero_division)) {
1927 if (A->getOption().matches(options::OPT_mno_check_zero_division)) {
1928 CmdArgs.push_back(
"-mllvm");
1929 CmdArgs.push_back(
"-mno-check-zero-division");
1933 if (Args.getLastArg(options::OPT_mfix4300)) {
1934 CmdArgs.push_back(
"-mllvm");
1935 CmdArgs.push_back(
"-mfix4300");
1938 if (Arg *A = Args.getLastArg(options::OPT_G)) {
1939 StringRef
v = A->getValue();
1940 CmdArgs.push_back(
"-mllvm");
1941 CmdArgs.push_back(Args.MakeArgString(
"-mips-ssection-threshold=" +
v));
1945 Arg *GPOpt = Args.getLastArg(options::OPT_mgpopt, options::OPT_mno_gpopt);
1947 Args.getLastArg(options::OPT_mabicalls, options::OPT_mno_abicalls);
1960 ABICalls && ABICalls->getOption().matches(options::OPT_mno_abicalls);
1962 llvm::Reloc::Model RelocationModel;
1965 std::tie(RelocationModel, PICLevel, IsPIE) =
1968 NoABICalls = NoABICalls ||
1969 (RelocationModel == llvm::Reloc::Static && ABIName ==
"n64");
1971 bool WantGPOpt = GPOpt && GPOpt->getOption().matches(options::OPT_mgpopt);
1973 if (NoABICalls && (!GPOpt || WantGPOpt)) {
1974 CmdArgs.push_back(
"-mllvm");
1975 CmdArgs.push_back(
"-mgpopt");
1977 Arg *LocalSData = Args.getLastArg(options::OPT_mlocal_sdata,
1978 options::OPT_mno_local_sdata);
1979 Arg *ExternSData = Args.getLastArg(options::OPT_mextern_sdata,
1980 options::OPT_mno_extern_sdata);
1981 Arg *EmbeddedData = Args.getLastArg(options::OPT_membedded_data,
1982 options::OPT_mno_embedded_data);
1984 CmdArgs.push_back(
"-mllvm");
1985 if (LocalSData->getOption().matches(options::OPT_mlocal_sdata)) {
1986 CmdArgs.push_back(
"-mlocal-sdata=1");
1988 CmdArgs.push_back(
"-mlocal-sdata=0");
1990 LocalSData->claim();
1994 CmdArgs.push_back(
"-mllvm");
1995 if (ExternSData->getOption().matches(options::OPT_mextern_sdata)) {
1996 CmdArgs.push_back(
"-mextern-sdata=1");
1998 CmdArgs.push_back(
"-mextern-sdata=0");
2000 ExternSData->claim();
2004 CmdArgs.push_back(
"-mllvm");
2005 if (EmbeddedData->getOption().matches(options::OPT_membedded_data)) {
2006 CmdArgs.push_back(
"-membedded-data=1");
2008 CmdArgs.push_back(
"-membedded-data=0");
2010 EmbeddedData->claim();
2013 }
else if ((!ABICalls || (!NoABICalls && ABICalls)) && WantGPOpt)
2014 D.Diag(diag::warn_drv_unsupported_gpopt) << (ABICalls ? 0 : 1);
2019 if (Arg *A = Args.getLastArg(options::OPT_mcompact_branches_EQ)) {
2020 StringRef Val = StringRef(A->getValue());
2022 if (Val ==
"never" || Val ==
"always" || Val ==
"optimal") {
2023 CmdArgs.push_back(
"-mllvm");
2024 CmdArgs.push_back(Args.MakeArgString(
"-mips-compact-branches=" + Val));
2026 D.Diag(diag::err_drv_unsupported_option_argument)
2027 << A->getSpelling() << Val;
2029 D.Diag(diag::warn_target_unsupported_compact_branches) << CPUName;
2032 if (Arg *A = Args.getLastArg(options::OPT_mrelax_pic_calls,
2033 options::OPT_mno_relax_pic_calls)) {
2034 if (A->getOption().matches(options::OPT_mno_relax_pic_calls)) {
2035 CmdArgs.push_back(
"-mllvm");
2036 CmdArgs.push_back(
"-mips-jalr-reloc=0");
2041void Clang::AddPPCTargetArgs(
const ArgList &Args,
2042 ArgStringList &CmdArgs)
const {
2045 if (Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
2046 CmdArgs.push_back(
"-tune-cpu");
2047 StringRef CPU = llvm::PPC::getNormalizedPPCTuneCPU(
T, A->getValue());
2048 CmdArgs.push_back(Args.MakeArgString(CPU.str()));
2052 const char *ABIName =
nullptr;
2053 if (
T.isOSBinFormatELF()) {
2055 case llvm::Triple::ppc64: {
2056 if (
T.isPPC64ELFv2ABI())
2062 case llvm::Triple::ppc64le:
2071 bool VecExtabi =
false;
2072 for (
const Arg *A : Args.filtered(options::OPT_mabi_EQ)) {
2073 StringRef
V = A->getValue();
2074 if (
V ==
"ieeelongdouble") {
2075 IEEELongDouble =
true;
2077 }
else if (
V ==
"ibmlongdouble") {
2078 IEEELongDouble =
false;
2080 }
else if (
V ==
"vec-default") {
2083 }
else if (
V ==
"vec-extabi") {
2086 }
else if (
V ==
"elfv1") {
2089 }
else if (
V ==
"elfv2") {
2092 }
else if (
V !=
"altivec")
2096 ABIName = A->getValue();
2099 CmdArgs.push_back(
"-mabi=ieeelongdouble");
2102 D.Diag(diag::err_drv_unsupported_opt_for_target)
2103 <<
"-mabi=vec-extabi" <<
T.str();
2104 CmdArgs.push_back(
"-mabi=vec-extabi");
2107 if (!Args.hasFlag(options::OPT_mred_zone, options::OPT_mno_red_zone,
true))
2108 CmdArgs.push_back(
"-disable-red-zone");
2113 CmdArgs.push_back(
"-msoft-float");
2114 CmdArgs.push_back(
"-mfloat-abi");
2115 CmdArgs.push_back(
"soft");
2119 CmdArgs.push_back(
"-mfloat-abi");
2120 CmdArgs.push_back(
"hard");
2124 CmdArgs.push_back(
"-target-abi");
2125 CmdArgs.push_back(ABIName);
2129void Clang::AddRISCVTargetArgs(
const ArgList &Args,
2130 ArgStringList &CmdArgs)
const {
2134 CmdArgs.push_back(
"-target-abi");
2135 CmdArgs.push_back(ABIName.data());
2137 if (Arg *A = Args.getLastArg(options::OPT_G)) {
2138 CmdArgs.push_back(
"-msmall-data-limit");
2139 CmdArgs.push_back(A->getValue());
2142 if (!Args.hasFlag(options::OPT_mimplicit_float,
2143 options::OPT_mno_implicit_float,
true))
2144 CmdArgs.push_back(
"-no-implicit-float");
2146 if (
const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
2147 CmdArgs.push_back(
"-tune-cpu");
2148 if (strcmp(A->getValue(),
"native") == 0)
2149 CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
2151 CmdArgs.push_back(A->getValue());
2155 if (Arg *A = Args.getLastArg(options::OPT_mrvv_vector_bits_EQ)) {
2156 StringRef Val = A->getValue();
2160 unsigned MinVLen = 0;
2162 auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
2165 if (!errorToBool(ISAInfo.takeError()))
2166 MinVLen = (*ISAInfo)->getMinVLen();
2171 if (Val ==
"zvl" && MinVLen >= llvm::RISCV::RVVBitsPerBlock) {
2173 }
else if (!Val.getAsInteger(10, Bits)) {
2176 if (Bits < MinVLen || Bits < llvm::RISCV::RVVBitsPerBlock ||
2177 Bits > 65536 || !llvm::isPowerOf2_32(Bits))
2183 unsigned VScaleMin = Bits / llvm::RISCV::RVVBitsPerBlock;
2185 Args.MakeArgString(
"-mvscale-max=" + llvm::Twine(VScaleMin)));
2187 Args.MakeArgString(
"-mvscale-min=" + llvm::Twine(VScaleMin)));
2188 }
else if (Val !=
"scalable") {
2190 D.Diag(diag::err_drv_unsupported_option_argument)
2191 << A->getSpelling() << Val;
2196void Clang::AddSparcTargetArgs(
const ArgList &Args,
2197 ArgStringList &CmdArgs)
const {
2203 CmdArgs.push_back(
"-msoft-float");
2204 CmdArgs.push_back(
"-mfloat-abi");
2205 CmdArgs.push_back(
"soft");
2209 CmdArgs.push_back(
"-mfloat-abi");
2210 CmdArgs.push_back(
"hard");
2213 if (
const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
2214 StringRef Name = A->getValue();
2215 std::string TuneCPU;
2216 if (Name ==
"native")
2217 TuneCPU = std::string(llvm::sys::getHostCPUName());
2219 TuneCPU = std::string(Name);
2221 CmdArgs.push_back(
"-tune-cpu");
2222 CmdArgs.push_back(Args.MakeArgString(TuneCPU));
2226void Clang::AddSystemZTargetArgs(
const ArgList &Args,
2227 ArgStringList &CmdArgs)
const {
2228 if (
const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
2229 CmdArgs.push_back(
"-tune-cpu");
2230 if (strcmp(A->getValue(),
"native") == 0)
2231 CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
2233 CmdArgs.push_back(A->getValue());
2237 Args.hasFlag(options::OPT_mbackchain, options::OPT_mno_backchain,
false);
2238 bool HasPackedStack = Args.hasFlag(options::OPT_mpacked_stack,
2239 options::OPT_mno_packed_stack,
false);
2243 if (HasBackchain && HasPackedStack && !HasSoftFloat) {
2245 D.Diag(diag::err_drv_unsupported_opt)
2246 <<
"-mpacked-stack -mbackchain -mhard-float";
2249 CmdArgs.push_back(
"-mbackchain");
2251 CmdArgs.push_back(
"-mpacked-stack");
2254 CmdArgs.push_back(
"-msoft-float");
2255 CmdArgs.push_back(
"-mfloat-abi");
2256 CmdArgs.push_back(
"soft");
2260void Clang::AddX86TargetArgs(
const ArgList &Args,
2261 ArgStringList &CmdArgs)
const {
2265 if (!Args.hasFlag(options::OPT_mred_zone, options::OPT_mno_red_zone,
true) ||
2266 Args.hasArg(options::OPT_mkernel) ||
2267 Args.hasArg(options::OPT_fapple_kext))
2268 CmdArgs.push_back(
"-disable-red-zone");
2270 if (!Args.hasFlag(options::OPT_mtls_direct_seg_refs,
2271 options::OPT_mno_tls_direct_seg_refs,
true))
2272 CmdArgs.push_back(
"-mno-tls-direct-seg-refs");
2276 bool NoImplicitFloat = (Args.hasArg(options::OPT_mkernel) ||
2277 Args.hasArg(options::OPT_fapple_kext));
2278 if (Arg *A = Args.getLastArg(
2279 options::OPT_msoft_float, options::OPT_mno_soft_float,
2280 options::OPT_mimplicit_float, options::OPT_mno_implicit_float)) {
2281 const Option &O = A->getOption();
2282 NoImplicitFloat = (O.matches(options::OPT_mno_implicit_float) ||
2283 O.matches(options::OPT_msoft_float));
2285 if (NoImplicitFloat)
2286 CmdArgs.push_back(
"-no-implicit-float");
2288 if (Arg *A = Args.getLastArg(options::OPT_masm_EQ)) {
2289 StringRef
Value = A->getValue();
2291 CmdArgs.push_back(
"-mllvm");
2292 CmdArgs.push_back(Args.MakeArgString(
"-x86-asm-syntax=" +
Value));
2293 CmdArgs.push_back(Args.MakeArgString(
"-inline-asm=" +
Value));
2295 D.Diag(diag::err_drv_unsupported_option_argument)
2296 << A->getSpelling() <<
Value;
2298 }
else if (
D.IsCLMode()) {
2299 CmdArgs.push_back(
"-mllvm");
2300 CmdArgs.push_back(
"-x86-asm-syntax=intel");
2303 if (Arg *A = Args.getLastArg(options::OPT_mskip_rax_setup,
2304 options::OPT_mno_skip_rax_setup))
2305 if (A->getOption().matches(options::OPT_mskip_rax_setup))
2306 CmdArgs.push_back(Args.MakeArgString(
"-mskip-rax-setup"));
2309 if (Args.hasFlag(options::OPT_miamcu, options::OPT_mno_iamcu,
false)) {
2310 CmdArgs.push_back(
"-mfloat-abi");
2311 CmdArgs.push_back(
"soft");
2312 CmdArgs.push_back(
"-mstack-alignment=4");
2318 std::string TuneCPU;
2319 if (!Args.hasArg(clang::driver::options::OPT_march_EQ) &&
2321 TuneCPU =
"generic";
2324 if (
const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
2325 StringRef Name = A->getValue();
2327 if (Name ==
"native") {
2328 Name = llvm::sys::getHostCPUName();
2330 TuneCPU = std::string(Name);
2332 TuneCPU = std::string(Name);
2335 if (!TuneCPU.empty()) {
2336 CmdArgs.push_back(
"-tune-cpu");
2337 CmdArgs.push_back(Args.MakeArgString(TuneCPU));
2341void Clang::AddHexagonTargetArgs(
const ArgList &Args,
2342 ArgStringList &CmdArgs)
const {
2343 CmdArgs.push_back(
"-mqdsp6-compat");
2344 CmdArgs.push_back(
"-Wreturn-type");
2347 CmdArgs.push_back(
"-mllvm");
2349 Args.MakeArgString(
"-hexagon-small-data-threshold=" + Twine(*G)));
2352 if (!Args.hasArg(options::OPT_fno_short_enums))
2353 CmdArgs.push_back(
"-fshort-enums");
2354 if (Args.getLastArg(options::OPT_mieee_rnd_near)) {
2355 CmdArgs.push_back(
"-mllvm");
2356 CmdArgs.push_back(
"-enable-hexagon-ieee-rnd-near");
2358 CmdArgs.push_back(
"-mllvm");
2359 CmdArgs.push_back(
"-machine-sink-split=0");
2362void Clang::AddLanaiTargetArgs(
const ArgList &Args,
2363 ArgStringList &CmdArgs)
const {
2364 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
2365 StringRef CPUName = A->getValue();
2367 CmdArgs.push_back(
"-target-cpu");
2368 CmdArgs.push_back(Args.MakeArgString(CPUName));
2370 if (Arg *A = Args.getLastArg(options::OPT_mregparm_EQ)) {
2371 StringRef
Value = A->getValue();
2375 if (
Value.getAsInteger(10, Mregparm)) {
2376 if (Mregparm != 4) {
2378 diag::err_drv_unsupported_option_argument)
2379 << A->getSpelling() <<
Value;
2385void Clang::AddWebAssemblyTargetArgs(
const ArgList &Args,
2386 ArgStringList &CmdArgs)
const {
2388 if (!Args.hasArg(options::OPT_fvisibility_EQ,
2389 options::OPT_fvisibility_ms_compat))
2390 CmdArgs.push_back(
"-fvisibility=hidden");
2393void Clang::AddVETargetArgs(
const ArgList &Args, ArgStringList &CmdArgs)
const {
2395 CmdArgs.push_back(
"-mfloat-abi");
2396 CmdArgs.push_back(
"hard");
2401 const InputInfo &Input,
const ArgList &Args)
const {
2403 if (
C.getArgs().hasArg(options::OPT__HASH_HASH_HASH))
2406 using llvm::yaml::escape;
2409 if (!CompilationDatabase) {
2411 auto File = std::make_unique<llvm::raw_fd_ostream>(
2413 llvm::sys::fs::OF_TextWithCRLF | llvm::sys::fs::OF_Append);
2415 D.Diag(clang::diag::err_drv_compilationdatabase) <<
Filename
2419 CompilationDatabase = std::move(
File);
2421 auto &CDB = *CompilationDatabase;
2422 auto CWD =
D.getVFS().getCurrentWorkingDirectory();
2425 CDB <<
"{ \"directory\": \"" << escape(*CWD) <<
"\"";
2426 CDB <<
", \"file\": \"" << escape(Input.
getFilename()) <<
"\"";
2428 CDB <<
", \"output\": \"" << escape(Output.
getFilename()) <<
"\"";
2429 CDB <<
", \"arguments\": [\"" << escape(
D.ClangExecutable) <<
"\"";
2433 CDB <<
", \"" << escape(Buf) <<
"\"";
2434 if (!
D.SysRoot.empty() && !Args.hasArg(options::OPT__sysroot_EQ)) {
2437 CDB <<
", \"" << escape(Buf) <<
"\"";
2439 CDB <<
", \"" << escape(Input.
getFilename()) <<
"\"";
2441 CDB <<
", \"-o\", \"" << escape(Output.
getFilename()) <<
"\"";
2442 for (
auto &A: Args) {
2443 auto &O = A->getOption();
2445 if (O.getID() == options::OPT_x)
2448 if (O.getGroup().isValid() && O.getGroup().getID() == options::OPT_M_Group)
2450 if (O.getID() == options::OPT_gen_cdb_fragment_path)
2453 if (O.getKind() == Option::InputClass)
2456 if (O.getID() == options::OPT_o)
2460 A->render(Args, ASL);
2462 CDB <<
", \"" << escape(it) <<
"\"";
2466 CDB <<
", \"" << escape(Buf) <<
"\"]},\n";
2469void Clang::DumpCompilationDatabaseFragmentToDir(
2471 const InputInfo &Input,
const llvm::opt::ArgList &Args)
const {
2473 if (
C.getArgs().hasArg(options::OPT__HASH_HASH_HASH))
2476 if (CompilationDatabase)
2477 DumpCompilationDatabase(
C,
"",
Target, Output, Input, Args);
2480 const auto &
Driver =
C.getDriver();
2482 auto Err = llvm::sys::fs::create_directory(
Path,
true);
2484 Driver.
Diag(diag::err_drv_compilationdatabase) << Dir << Err.message();
2488 llvm::sys::path::append(
2490 Twine(llvm::sys::path::filename(Input.
getFilename())) +
".%%%%.json");
2493 Err = llvm::sys::fs::createUniqueFile(
Path, FD, TempPath,
2494 llvm::sys::fs::OF_Text);
2496 Driver.
Diag(diag::err_drv_compilationdatabase) <<
Path << Err.message();
2499 CompilationDatabase =
2500 std::make_unique<llvm::raw_fd_ostream>(FD,
true);
2501 DumpCompilationDatabase(
C,
"",
Target, Output, Input, Args);
2511 CmdArgs.push_back(
"-mllvm");
2512 CmdArgs.push_back(Args.MakeArgString(
"-arm-implicit-it=" +
Value));
2516 const ArgList &Args,
2517 ArgStringList &CmdArgs,
2527 Args.addOptInFlag(CmdArgs, options::OPT_mrelax_all,
2528 options::OPT_mno_relax_all);
2532 bool DefaultIncrementalLinkerCompatible =
2533 C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment();
2534 if (Args.hasFlag(options::OPT_mincremental_linker_compatible,
2535 options::OPT_mno_incremental_linker_compatible,
2536 DefaultIncrementalLinkerCompatible))
2537 CmdArgs.push_back(
"-mincremental-linker-compatible");
2539 Args.AddLastArg(CmdArgs, options::OPT_femit_dwarf_unwind_EQ);
2541 Args.addOptInFlag(CmdArgs, options::OPT_femit_compact_unwind_non_canonical,
2542 options::OPT_fno_emit_compact_unwind_non_canonical);
2552 bool TakeNextArg =
false;
2554 const llvm::Triple &Triple =
C.getDefaultToolChain().getTriple();
2555 bool IsELF = Triple.isOSBinFormatELF();
2556 bool Crel =
false, ExperimentalCrel =
false;
2557 bool ImplicitMapSyms =
false;
2558 bool UseRelaxRelocations =
C.getDefaultToolChain().useRelaxRelocations();
2559 bool UseNoExecStack =
false;
2561 const char *MipsTargetFeature =
nullptr;
2562 StringRef ImplicitIt;
2564 Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler,
2565 options::OPT_mimplicit_it_EQ)) {
2568 if (A->getOption().getID() == options::OPT_mimplicit_it_EQ) {
2569 switch (
C.getDefaultToolChain().getArch()) {
2570 case llvm::Triple::arm:
2571 case llvm::Triple::armeb:
2572 case llvm::Triple::thumb:
2573 case llvm::Triple::thumbeb:
2575 ImplicitIt = A->getValue();
2577 D.Diag(diag::err_drv_unsupported_option_argument)
2578 << A->getSpelling() << ImplicitIt;
2585 for (StringRef
Value : A->getValues()) {
2587 CmdArgs.push_back(
Value.data());
2588 TakeNextArg =
false;
2592 if (
C.getDefaultToolChain().getTriple().isOSBinFormatCOFF() &&
2593 Value ==
"-mbig-obj")
2597 auto checkArg = [&](
bool ValidTarget,
2598 std::initializer_list<const char *>
Set) {
2600 D.Diag(diag::err_drv_unsupported_opt_for_target)
2601 << (Twine(
"-Wa,") +
Equal.first +
"=").str()
2602 << Triple.getTriple();
2603 }
else if (!llvm::is_contained(
Set,
Equal.second)) {
2604 D.Diag(diag::err_drv_unsupported_option_argument)
2605 << (Twine(
"-Wa,") +
Equal.first +
"=").str() <<
Equal.second;
2608 switch (
C.getDefaultToolChain().getArch()) {
2611 case llvm::Triple::x86:
2612 case llvm::Triple::x86_64:
2613 if (
Equal.first ==
"-mrelax-relocations" ||
2614 Equal.first ==
"--mrelax-relocations") {
2615 UseRelaxRelocations =
Equal.second ==
"yes";
2616 checkArg(IsELF, {
"yes",
"no"});
2619 if (
Value ==
"-msse2avx") {
2620 CmdArgs.push_back(
"-msse2avx");
2624 case llvm::Triple::wasm32:
2625 case llvm::Triple::wasm64:
2626 if (
Value ==
"--no-type-check") {
2627 CmdArgs.push_back(
"-mno-type-check");
2631 case llvm::Triple::thumb:
2632 case llvm::Triple::thumbeb:
2633 case llvm::Triple::arm:
2634 case llvm::Triple::armeb:
2635 if (
Equal.first ==
"-mimplicit-it") {
2637 ImplicitIt =
Equal.second;
2638 checkArg(
true, {
"always",
"never",
"arm",
"thumb"});
2641 if (
Value ==
"-mthumb")
2646 case llvm::Triple::aarch64:
2647 case llvm::Triple::aarch64_be:
2648 case llvm::Triple::aarch64_32:
2649 if (
Equal.first ==
"-mmapsyms") {
2650 ImplicitMapSyms =
Equal.second ==
"implicit";
2651 checkArg(IsELF, {
"default",
"implicit"});
2655 case llvm::Triple::mips:
2656 case llvm::Triple::mipsel:
2657 case llvm::Triple::mips64:
2658 case llvm::Triple::mips64el:
2659 if (
Value ==
"--trap") {
2660 CmdArgs.push_back(
"-target-feature");
2661 CmdArgs.push_back(
"+use-tcc-in-div");
2664 if (
Value ==
"--break") {
2665 CmdArgs.push_back(
"-target-feature");
2666 CmdArgs.push_back(
"-use-tcc-in-div");
2669 if (
Value.starts_with(
"-msoft-float")) {
2670 CmdArgs.push_back(
"-target-feature");
2671 CmdArgs.push_back(
"+soft-float");
2674 if (
Value.starts_with(
"-mhard-float")) {
2675 CmdArgs.push_back(
"-target-feature");
2676 CmdArgs.push_back(
"-soft-float");
2679 if (
Value ==
"-mmsa") {
2683 if (
Value ==
"-mno-msa") {
2687 MipsTargetFeature = llvm::StringSwitch<const char *>(
Value)
2688 .Case(
"-mips1",
"+mips1")
2689 .Case(
"-mips2",
"+mips2")
2690 .Case(
"-mips3",
"+mips3")
2691 .Case(
"-mips4",
"+mips4")
2692 .Case(
"-mips5",
"+mips5")
2693 .Case(
"-mips32",
"+mips32")
2694 .Case(
"-mips32r2",
"+mips32r2")
2695 .Case(
"-mips32r3",
"+mips32r3")
2696 .Case(
"-mips32r5",
"+mips32r5")
2697 .Case(
"-mips32r6",
"+mips32r6")
2698 .Case(
"-mips64",
"+mips64")
2699 .Case(
"-mips64r2",
"+mips64r2")
2700 .Case(
"-mips64r3",
"+mips64r3")
2701 .Case(
"-mips64r5",
"+mips64r5")
2702 .Case(
"-mips64r6",
"+mips64r6")
2704 if (MipsTargetFeature)
2709 if (
Value ==
"-force_cpusubtype_ALL") {
2711 }
else if (
Value ==
"-L") {
2712 CmdArgs.push_back(
"-msave-temp-labels");
2713 }
else if (
Value ==
"--fatal-warnings") {
2714 CmdArgs.push_back(
"-massembler-fatal-warnings");
2715 }
else if (
Value ==
"--no-warn" ||
Value ==
"-W") {
2716 CmdArgs.push_back(
"-massembler-no-warn");
2717 }
else if (
Value ==
"--noexecstack") {
2718 UseNoExecStack =
true;
2719 }
else if (
Value.starts_with(
"-compress-debug-sections") ||
2720 Value.starts_with(
"--compress-debug-sections") ||
2721 Value ==
"-nocompress-debug-sections" ||
2722 Value ==
"--nocompress-debug-sections") {
2723 CmdArgs.push_back(
Value.data());
2724 }
else if (
Value ==
"--crel") {
2726 }
else if (
Value ==
"--no-crel") {
2728 }
else if (
Value ==
"--allow-experimental-crel") {
2729 ExperimentalCrel =
true;
2730 }
else if (
Value.starts_with(
"-I")) {
2731 CmdArgs.push_back(
Value.data());
2736 }
else if (
Value.starts_with(
"-gdwarf-")) {
2739 if (DwarfVersion == 0) {
2740 CmdArgs.push_back(
Value.data());
2743 llvm::codegenoptions::DebugInfoConstructor,
2744 DwarfVersion, llvm::DebuggerKind::Default);
2746 }
else if (
Value.starts_with(
"-mcpu") ||
Value.starts_with(
"-mfpu") ||
2747 Value.starts_with(
"-mhwdiv") ||
Value.starts_with(
"-march")) {
2749 }
else if (
Value ==
"-defsym" ||
Value ==
"--defsym") {
2750 if (A->getNumValues() != 2) {
2751 D.Diag(diag::err_drv_defsym_invalid_format) <<
Value;
2754 const char *S = A->getValue(1);
2755 auto Pair = StringRef(S).split(
'=');
2756 auto Sym = Pair.first;
2757 auto SVal = Pair.second;
2759 if (Sym.empty() || SVal.empty()) {
2760 D.Diag(diag::err_drv_defsym_invalid_format) << S;
2764 if (SVal.getAsInteger(0, IVal)) {
2765 D.Diag(diag::err_drv_defsym_invalid_symval) << SVal;
2768 CmdArgs.push_back(
"--defsym");
2770 }
else if (
Value ==
"-fdebug-compilation-dir") {
2771 CmdArgs.push_back(
"-fdebug-compilation-dir");
2773 }
else if (
Value.consume_front(
"-fdebug-compilation-dir=")) {
2777 CmdArgs.push_back(
"-fdebug-compilation-dir");
2778 CmdArgs.push_back(
Value.data());
2779 }
else if (
Value ==
"--version") {
2780 D.PrintVersion(
C, llvm::outs());
2782 D.Diag(diag::err_drv_unsupported_option_argument)
2783 << A->getSpelling() <<
Value;
2787 if (ImplicitIt.size())
2790 if (!ExperimentalCrel)
2791 D.Diag(diag::err_drv_experimental_crel);
2792 if (Triple.isOSBinFormatELF() && !Triple.isMIPS()) {
2793 CmdArgs.push_back(
"--crel");
2795 D.Diag(diag::err_drv_unsupported_opt_for_target)
2796 <<
"-Wa,--crel" <<
D.getTargetTriple();
2799 if (ImplicitMapSyms)
2800 CmdArgs.push_back(
"-mmapsyms=implicit");
2802 CmdArgs.push_back(
"-mmsa");
2803 if (!UseRelaxRelocations)
2804 CmdArgs.push_back(
"-mrelax-relocations=no");
2806 CmdArgs.push_back(
"-mnoexecstack");
2807 if (MipsTargetFeature !=
nullptr) {
2808 CmdArgs.push_back(
"-target-feature");
2809 CmdArgs.push_back(MipsTargetFeature);
2813 if (
C.getDriver().embedBitcodeEnabled() ||
2814 C.getDriver().embedBitcodeMarkerOnly())
2815 Args.AddLastArg(CmdArgs, options::OPT_fembed_bitcode_EQ);
2817 if (
const char *AsSecureLogFile = getenv(
"AS_SECURE_LOG_FILE")) {
2818 CmdArgs.push_back(
"-as-secure-log-file");
2819 CmdArgs.push_back(Args.MakeArgString(AsSecureLogFile));
2850 if ((str1.compare(str2) != 0) && !str2.empty() && !str1.empty()) {
2851 D.Diag(clang::diag::warn_drv_overriding_option) << str1 << str2;
2858 if (!ComplexRangeStr.empty())
2859 return "-complex-range=" + ComplexRangeStr;
2860 return ComplexRangeStr;
2864 bool OFastEnabled,
const ArgList &Args,
2865 ArgStringList &CmdArgs,
2872 bool HonorINFs =
true;
2873 bool HonorNaNs =
true;
2874 bool ApproxFunc =
false;
2877 bool AssociativeMath =
false;
2878 bool ReciprocalMath =
false;
2879 bool SignedZeros =
true;
2880 bool TrappingMath =
false;
2881 bool TrappingMathPresent =
false;
2883 bool RoundingFPMath =
false;
2885 StringRef FPModel =
"";
2887 StringRef FPExceptionBehavior =
"";
2889 StringRef FPEvalMethod =
"";
2890 llvm::DenormalMode DenormalFPMath =
2892 llvm::DenormalMode DenormalFP32Math =
2897 StringRef FPContract;
2898 StringRef LastSeenFfpContractOption;
2899 StringRef LastFpContractOverrideOption;
2900 bool SeenUnsafeMathModeOption =
false;
2904 bool StrictFPModel =
false;
2905 StringRef Float16ExcessPrecision =
"";
2906 StringRef BFloat16ExcessPrecision =
"";
2908 std::string ComplexRangeStr =
"";
2909 std::string GccRangeComplexOption =
"";
2914 if (
Range != NewRange)
2916 !GccRangeComplexOption.empty()
2917 ? GccRangeComplexOption
2924 auto applyFastMath = [&](
bool Aggressive) {
2935 AssociativeMath =
true;
2936 ReciprocalMath =
true;
2938 SignedZeros =
false;
2939 TrappingMath =
false;
2940 RoundingFPMath =
false;
2941 FPExceptionBehavior =
"";
2942 FPContract =
"fast";
2943 SeenUnsafeMathModeOption =
true;
2947 auto restoreFPContractState = [&]() {
2957 if (LastSeenFfpContractOption !=
"")
2958 FPContract = LastSeenFfpContractOption;
2959 else if (SeenUnsafeMathModeOption)
2964 LastFpContractOverrideOption =
"";
2967 if (
const Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) {
2968 CmdArgs.push_back(
"-mlimit-float-precision");
2969 CmdArgs.push_back(A->getValue());
2972 for (
const Arg *A : Args) {
2973 switch (A->getOption().getID()) {
2977 case options::OPT_fcx_limited_range:
2978 if (GccRangeComplexOption.empty()) {
2981 "-fcx-limited-range");
2983 if (GccRangeComplexOption !=
"-fno-cx-limited-range")
2986 GccRangeComplexOption =
"-fcx-limited-range";
2989 case options::OPT_fno_cx_limited_range:
2990 if (GccRangeComplexOption.empty()) {
2992 "-fno-cx-limited-range");
2994 if (GccRangeComplexOption.compare(
"-fcx-limited-range") != 0 &&
2995 GccRangeComplexOption.compare(
"-fno-cx-fortran-rules") != 0)
2997 "-fno-cx-limited-range");
2999 GccRangeComplexOption =
"-fno-cx-limited-range";
3002 case options::OPT_fcx_fortran_rules:
3003 if (GccRangeComplexOption.empty())
3005 "-fcx-fortran-rules");
3008 GccRangeComplexOption =
"-fcx-fortran-rules";
3011 case options::OPT_fno_cx_fortran_rules:
3012 if (GccRangeComplexOption.empty()) {
3014 "-fno-cx-fortran-rules");
3016 if (GccRangeComplexOption !=
"-fno-cx-limited-range")
3018 "-fno-cx-fortran-rules");
3020 GccRangeComplexOption =
"-fno-cx-fortran-rules";
3023 case options::OPT_fcomplex_arithmetic_EQ: {
3025 StringRef Val = A->getValue();
3028 else if (Val ==
"improved")
3030 else if (Val ==
"promoted")
3032 else if (Val ==
"basic")
3035 D.Diag(diag::err_drv_unsupported_option_argument)
3036 << A->getSpelling() << Val;
3039 if (!GccRangeComplexOption.empty()) {
3040 if (GccRangeComplexOption.compare(
"-fcx-limited-range") != 0) {
3041 if (GccRangeComplexOption.compare(
"-fcx-fortran-rules") != 0) {
3058 case options::OPT_ffp_model_EQ: {
3065 AssociativeMath =
false;
3066 ReciprocalMath =
false;
3069 StringRef Val = A->getValue();
3070 if (OFastEnabled && Val !=
"aggressive") {
3072 D.Diag(clang::diag::warn_drv_overriding_option)
3073 << Args.MakeArgString(
"-ffp-model=" + Val) <<
"-Ofast";
3076 StrictFPModel =
false;
3077 if (!FPModel.empty() && FPModel != Val)
3078 D.Diag(clang::diag::warn_drv_overriding_option)
3079 << Args.MakeArgString(
"-ffp-model=" + FPModel)
3080 << Args.MakeArgString(
"-ffp-model=" + Val);
3081 if (Val ==
"fast") {
3083 applyFastMath(
false);
3085 LastFpContractOverrideOption =
"-ffp-model=fast";
3086 }
else if (Val ==
"aggressive") {
3088 applyFastMath(
true);
3090 LastFpContractOverrideOption =
"-ffp-model=aggressive";
3091 }
else if (Val ==
"precise") {
3094 LastFpContractOverrideOption =
"-ffp-model=precise";
3096 }
else if (Val ==
"strict") {
3097 StrictFPModel =
true;
3098 FPExceptionBehavior =
"strict";
3101 LastFpContractOverrideOption =
"-ffp-model=strict";
3102 TrappingMath =
true;
3103 RoundingFPMath =
true;
3106 D.Diag(diag::err_drv_unsupported_option_argument)
3107 << A->getSpelling() << Val;
3112 case options::OPT_fhonor_infinities: HonorINFs =
true;
break;
3113 case options::OPT_fno_honor_infinities: HonorINFs =
false;
break;
3114 case options::OPT_fhonor_nans: HonorNaNs =
true;
break;
3115 case options::OPT_fno_honor_nans: HonorNaNs =
false;
break;
3116 case options::OPT_fapprox_func: ApproxFunc =
true;
break;
3117 case options::OPT_fno_approx_func: ApproxFunc =
false;
break;
3118 case options::OPT_fmath_errno: MathErrno =
true;
break;
3119 case options::OPT_fno_math_errno: MathErrno =
false;
break;
3120 case options::OPT_fassociative_math: AssociativeMath =
true;
break;
3121 case options::OPT_fno_associative_math: AssociativeMath =
false;
break;
3122 case options::OPT_freciprocal_math: ReciprocalMath =
true;
break;
3123 case options::OPT_fno_reciprocal_math: ReciprocalMath =
false;
break;
3124 case options::OPT_fsigned_zeros: SignedZeros =
true;
break;
3125 case options::OPT_fno_signed_zeros: SignedZeros =
false;
break;
3126 case options::OPT_ftrapping_math:
3127 if (!TrappingMathPresent && !FPExceptionBehavior.empty() &&
3128 FPExceptionBehavior !=
"strict")
3130 D.Diag(clang::diag::warn_drv_overriding_option)
3131 << Args.MakeArgString(
"-ffp-exception-behavior=" +
3132 FPExceptionBehavior)
3133 <<
"-ftrapping-math";
3134 TrappingMath =
true;
3135 TrappingMathPresent =
true;
3136 FPExceptionBehavior =
"strict";
3138 case options::OPT_fno_trapping_math:
3139 if (!TrappingMathPresent && !FPExceptionBehavior.empty() &&
3140 FPExceptionBehavior !=
"ignore")
3142 D.Diag(clang::diag::warn_drv_overriding_option)
3143 << Args.MakeArgString(
"-ffp-exception-behavior=" +
3144 FPExceptionBehavior)
3145 <<
"-fno-trapping-math";
3146 TrappingMath =
false;
3147 TrappingMathPresent =
true;
3148 FPExceptionBehavior =
"ignore";
3151 case options::OPT_frounding_math:
3152 RoundingFPMath =
true;
3155 case options::OPT_fno_rounding_math:
3156 RoundingFPMath =
false;
3159 case options::OPT_fdenormal_fp_math_EQ:
3160 DenormalFPMath = llvm::parseDenormalFPAttribute(A->getValue());
3161 DenormalFP32Math = DenormalFPMath;
3162 if (!DenormalFPMath.isValid()) {
3163 D.Diag(diag::err_drv_invalid_value)
3164 << A->getAsString(Args) << A->getValue();
3168 case options::OPT_fdenormal_fp_math_f32_EQ:
3169 DenormalFP32Math = llvm::parseDenormalFPAttribute(A->getValue());
3170 if (!DenormalFP32Math.isValid()) {
3171 D.Diag(diag::err_drv_invalid_value)
3172 << A->getAsString(Args) << A->getValue();
3177 case options::OPT_ffp_contract: {
3178 StringRef Val = A->getValue();
3179 if (Val ==
"fast" || Val ==
"on" || Val ==
"off" ||
3180 Val ==
"fast-honor-pragmas") {
3181 if (Val != FPContract && LastFpContractOverrideOption !=
"") {
3182 D.Diag(clang::diag::warn_drv_overriding_option)
3183 << LastFpContractOverrideOption
3184 << Args.MakeArgString(
"-ffp-contract=" + Val);
3188 LastSeenFfpContractOption = Val;
3189 LastFpContractOverrideOption =
"";
3191 D.Diag(diag::err_drv_unsupported_option_argument)
3192 << A->getSpelling() << Val;
3197 case options::OPT_ffp_exception_behavior_EQ: {
3198 StringRef Val = A->getValue();
3199 if (!TrappingMathPresent && !FPExceptionBehavior.empty() &&
3200 FPExceptionBehavior != Val)
3202 D.Diag(clang::diag::warn_drv_overriding_option)
3203 << Args.MakeArgString(
"-ffp-exception-behavior=" +
3204 FPExceptionBehavior)
3205 << Args.MakeArgString(
"-ffp-exception-behavior=" + Val);
3206 TrappingMath = TrappingMathPresent =
false;
3207 if (Val ==
"ignore" || Val ==
"maytrap")
3208 FPExceptionBehavior = Val;
3209 else if (Val ==
"strict") {
3210 FPExceptionBehavior = Val;
3211 TrappingMath = TrappingMathPresent =
true;
3213 D.Diag(diag::err_drv_unsupported_option_argument)
3214 << A->getSpelling() << Val;
3219 case options::OPT_ffp_eval_method_EQ: {
3220 StringRef Val = A->getValue();
3221 if (Val ==
"double" || Val ==
"extended" || Val ==
"source")
3224 D.Diag(diag::err_drv_unsupported_option_argument)
3225 << A->getSpelling() << Val;
3229 case options::OPT_fexcess_precision_EQ: {
3230 StringRef Val = A->getValue();
3231 const llvm::Triple::ArchType Arch = TC.
getArch();
3232 if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) {
3233 if (Val ==
"standard" || Val ==
"fast")
3234 Float16ExcessPrecision = Val;
3238 else if (Val ==
"16")
3239 Float16ExcessPrecision =
"none";
3241 D.Diag(diag::err_drv_unsupported_option_argument)
3242 << A->getSpelling() << Val;
3244 if (!(Val ==
"standard" || Val ==
"fast"))
3245 D.Diag(diag::err_drv_unsupported_option_argument)
3246 << A->getSpelling() << Val;
3248 BFloat16ExcessPrecision = Float16ExcessPrecision;
3251 case options::OPT_ffinite_math_only:
3255 case options::OPT_fno_finite_math_only:
3260 case options::OPT_funsafe_math_optimizations:
3261 AssociativeMath =
true;
3262 ReciprocalMath =
true;
3263 SignedZeros =
false;
3265 TrappingMath =
false;
3266 FPExceptionBehavior =
"";
3267 FPContract =
"fast";
3268 LastFpContractOverrideOption =
"-funsafe-math-optimizations";
3269 SeenUnsafeMathModeOption =
true;
3271 case options::OPT_fno_unsafe_math_optimizations:
3272 AssociativeMath =
false;
3273 ReciprocalMath =
false;
3276 restoreFPContractState();
3279 case options::OPT_Ofast:
3284 case options::OPT_ffast_math:
3285 applyFastMath(
true);
3286 if (A->getOption().getID() == options::OPT_Ofast)
3287 LastFpContractOverrideOption =
"-Ofast";
3289 LastFpContractOverrideOption =
"-ffast-math";
3291 case options::OPT_fno_fast_math:
3298 AssociativeMath =
false;
3299 ReciprocalMath =
false;
3302 restoreFPContractState();
3303 LastFpContractOverrideOption =
"";
3313 if (StrictFPModel) {
3316 if (HonorINFs && HonorNaNs && !AssociativeMath && !ReciprocalMath &&
3317 SignedZeros && TrappingMath && RoundingFPMath && !ApproxFunc &&
3318 FPContract ==
"off")
3322 StrictFPModel =
false;
3327 auto RHS = (A->getNumValues() == 0)
3329 : Args.MakeArgString(A->getSpelling() + A->getValue());
3330 if (A->getSpelling() !=
"-ffp-contract=") {
3331 if (RHS !=
"-ffp-model=strict")
3332 D.Diag(clang::diag::warn_drv_overriding_option)
3333 <<
"-ffp-model=strict" << RHS;
3343 CmdArgs.push_back(
"-menable-no-infs");
3346 CmdArgs.push_back(
"-menable-no-nans");
3349 CmdArgs.push_back(
"-fapprox-func");
3352 CmdArgs.push_back(
"-fmath-errno");
3354 if (AssociativeMath && ReciprocalMath && !SignedZeros && ApproxFunc &&
3356 CmdArgs.push_back(
"-funsafe-math-optimizations");
3359 CmdArgs.push_back(
"-fno-signed-zeros");
3361 if (AssociativeMath && !SignedZeros && !TrappingMath)
3362 CmdArgs.push_back(
"-mreassociate");
3365 CmdArgs.push_back(
"-freciprocal-math");
3369 assert(FPExceptionBehavior ==
"strict");
3373 if (DenormalFPMath != llvm::DenormalMode::getIEEE()) {
3375 llvm::raw_svector_ostream ArgStr(DenormFlag);
3376 ArgStr <<
"-fdenormal-fp-math=" << DenormalFPMath;
3377 CmdArgs.push_back(Args.MakeArgString(ArgStr.str()));
3381 if (DenormalFP32Math != DenormalFPMath) {
3383 llvm::raw_svector_ostream ArgStr(DenormFlag);
3384 ArgStr <<
"-fdenormal-fp-math-f32=" << DenormalFP32Math;
3385 CmdArgs.push_back(Args.MakeArgString(ArgStr.str()));
3388 if (!FPContract.empty())
3389 CmdArgs.push_back(Args.MakeArgString(
"-ffp-contract=" + FPContract));
3392 CmdArgs.push_back(Args.MakeArgString(
"-frounding-math"));
3394 CmdArgs.push_back(Args.MakeArgString(
"-fno-rounding-math"));
3396 if (!FPExceptionBehavior.empty())
3397 CmdArgs.push_back(Args.MakeArgString(
"-ffp-exception-behavior=" +
3398 FPExceptionBehavior));
3400 if (!FPEvalMethod.empty())
3401 CmdArgs.push_back(Args.MakeArgString(
"-ffp-eval-method=" + FPEvalMethod));
3403 if (!Float16ExcessPrecision.empty())
3404 CmdArgs.push_back(Args.MakeArgString(
"-ffloat16-excess-precision=" +
3405 Float16ExcessPrecision));
3406 if (!BFloat16ExcessPrecision.empty())
3407 CmdArgs.push_back(Args.MakeArgString(
"-fbfloat16-excess-precision=" +
3408 BFloat16ExcessPrecision));
3415 if (!HonorINFs && !HonorNaNs && !MathErrno && AssociativeMath && ApproxFunc &&
3416 ReciprocalMath && !SignedZeros && !TrappingMath && !RoundingFPMath)
3417 CmdArgs.push_back(
"-ffast-math");
3423 bool shouldAddFiniteMathOnly =
false;
3424 if (!HonorINFs && !HonorNaNs) {
3425 shouldAddFiniteMathOnly =
true;
3427 bool InfValues =
true;
3428 bool NanValues =
true;
3429 for (
const auto *Arg : Args.filtered(options::OPT_Xclang)) {
3430 StringRef ArgValue = Arg->getValue();
3431 if (ArgValue ==
"-menable-no-nans")
3433 else if (ArgValue ==
"-menable-no-infs")
3436 if (!NanValues && !InfValues)
3437 shouldAddFiniteMathOnly =
true;
3439 if (shouldAddFiniteMathOnly) {
3440 CmdArgs.push_back(
"-ffinite-math-only");
3442 if (
const Arg *A = Args.getLastArg(options::OPT_mfpmath_EQ)) {
3443 CmdArgs.push_back(
"-mfpmath");
3444 CmdArgs.push_back(A->getValue());
3448 if (Args.hasFlag(options::OPT_fno_strict_float_cast_overflow,
3449 options::OPT_fstrict_float_cast_overflow,
false))
3450 CmdArgs.push_back(
"-fno-strict-float-cast-overflow");
3454 if (!ComplexRangeStr.empty()) {
3455 CmdArgs.push_back(Args.MakeArgString(ComplexRangeStr));
3456 if (Args.hasArg(options::OPT_fcomplex_arithmetic_EQ))
3457 CmdArgs.push_back(Args.MakeArgString(
"-fcomplex-arithmetic=" +
3460 if (Args.hasArg(options::OPT_fcx_limited_range))
3461 CmdArgs.push_back(
"-fcx-limited-range");
3462 if (Args.hasArg(options::OPT_fcx_fortran_rules))
3463 CmdArgs.push_back(
"-fcx-fortran-rules");
3464 if (Args.hasArg(options::OPT_fno_cx_limited_range))
3465 CmdArgs.push_back(
"-fno-cx-limited-range");
3466 if (Args.hasArg(options::OPT_fno_cx_fortran_rules))
3467 CmdArgs.push_back(
"-fno-cx-fortran-rules");
3471 const llvm::Triple &Triple,
3474 if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) {
3475 CmdArgs.push_back(
"-analyzer-checker=core");
3476 CmdArgs.push_back(
"-analyzer-checker=apiModeling");
3478 if (!Triple.isWindowsMSVCEnvironment()) {
3479 CmdArgs.push_back(
"-analyzer-checker=unix");
3482 CmdArgs.push_back(
"-analyzer-checker=unix.API");
3483 CmdArgs.push_back(
"-analyzer-checker=unix.Malloc");
3484 CmdArgs.push_back(
"-analyzer-checker=unix.MallocSizeof");
3485 CmdArgs.push_back(
"-analyzer-checker=unix.MismatchedDeallocator");
3486 CmdArgs.push_back(
"-analyzer-checker=unix.cstring.BadSizeArg");
3487 CmdArgs.push_back(
"-analyzer-checker=unix.cstring.NullArg");
3491 if (Triple.isPS()) {
3492 CmdArgs.push_back(
"-analyzer-disable-checker=unix.API");
3493 CmdArgs.push_back(
"-analyzer-disable-checker=unix.Vfork");
3496 if (Triple.isOSDarwin()) {
3497 CmdArgs.push_back(
"-analyzer-checker=osx");
3499 "-analyzer-checker=security.insecureAPI.decodeValueOfObjCType");
3501 else if (Triple.isOSFuchsia())
3502 CmdArgs.push_back(
"-analyzer-checker=fuchsia");
3504 CmdArgs.push_back(
"-analyzer-checker=deadcode");
3507 CmdArgs.push_back(
"-analyzer-checker=cplusplus");
3509 if (!Triple.isPS()) {
3510 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.UncheckedReturn");
3511 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.getpw");
3512 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.gets");
3513 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.mktemp");
3514 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.mkstemp");
3515 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.vfork");
3519 CmdArgs.push_back(
"-analyzer-checker=nullability.NullPassedToNonnull");
3520 CmdArgs.push_back(
"-analyzer-checker=nullability.NullReturnedFromNonnull");
3524 CmdArgs.push_back(
"-analyzer-output");
3525 if (Arg *A = Args.getLastArg(options::OPT__analyzer_output))
3526 CmdArgs.push_back(A->getValue());
3528 CmdArgs.push_back(
"plist");
3533 CmdArgs.push_back(
"-w");
3536 Args.AddAllArgValues(CmdArgs, options::OPT_Xanalyzer);
3543 if (std::isdigit(S[0]))
3546 return llvm::all_of(S, [](
char C) {
return std::isalnum(
C) ||
C ==
'_'; });
3550 const ArgList &Args, ArgStringList &CmdArgs,
3551 bool KernelOrKext) {
3556 if (EffectiveTriple.isNVPTX())
3564 if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector,
3565 options::OPT_fstack_protector_all,
3566 options::OPT_fstack_protector_strong,
3567 options::OPT_fstack_protector)) {
3568 if (A->getOption().matches(options::OPT_fstack_protector))
3569 StackProtectorLevel =
3571 else if (A->getOption().matches(options::OPT_fstack_protector_strong))
3573 else if (A->getOption().matches(options::OPT_fstack_protector_all))
3577 D.Diag(diag::warn_drv_unsupported_option_for_target)
3578 << A->getSpelling() << EffectiveTriple.getTriple();
3579 StackProtectorLevel = DefaultStackProtectorLevel;
3582 StackProtectorLevel = DefaultStackProtectorLevel;
3585 if (StackProtectorLevel) {
3586 CmdArgs.push_back(
"-stack-protector");
3587 CmdArgs.push_back(Args.MakeArgString(Twine(StackProtectorLevel)));
3591 for (
const Arg *A : Args.filtered(options::OPT__param)) {
3592 StringRef Str(A->getValue());
3593 if (Str.starts_with(
"ssp-buffer-size=")) {
3594 if (StackProtectorLevel) {
3595 CmdArgs.push_back(
"-stack-protector-buffer-size");
3597 CmdArgs.push_back(Args.MakeArgString(Str.drop_front(16)));
3603 const std::string &TripleStr = EffectiveTriple.getTriple();
3604 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_EQ)) {
3605 StringRef
Value = A->getValue();
3606 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
3607 !EffectiveTriple.isARM() && !EffectiveTriple.isThumb())
3608 D.Diag(diag::err_drv_unsupported_opt_for_target)
3609 << A->getAsString(Args) << TripleStr;
3610 if ((EffectiveTriple.isX86() || EffectiveTriple.isARM() ||
3611 EffectiveTriple.isThumb()) &&
3613 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3614 << A->getOption().getName() <<
Value <<
"tls global";
3617 if ((EffectiveTriple.isARM() || EffectiveTriple.isThumb()) &&
3619 if (!Args.hasArg(options::OPT_mstack_protector_guard_offset_EQ)) {
3620 D.Diag(diag::err_drv_ssp_missing_offset_argument)
3621 << A->getAsString(Args);
3626 D.Diag(diag::err_target_unsupported_tp_hard)
3627 << EffectiveTriple.getArchName();
3631 if (Arg *A = Args.getLastArg(options::OPT_mtp_mode_EQ)) {
3632 StringRef
Value = A->getValue();
3633 if (
Value !=
"cp15") {
3634 D.Diag(diag::err_drv_argument_not_allowed_with)
3635 << A->getAsString(Args) <<
"-mstack-protector-guard=tls";
3639 CmdArgs.push_back(
"-target-feature");
3640 CmdArgs.push_back(
"+read-tp-tpidruro");
3642 if (EffectiveTriple.isAArch64() &&
Value !=
"sysreg" &&
Value !=
"global") {
3643 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3644 << A->getOption().getName() <<
Value <<
"sysreg global";
3647 A->render(Args, CmdArgs);
3650 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_offset_EQ)) {
3651 StringRef
Value = A->getValue();
3652 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
3653 !EffectiveTriple.isARM() && !EffectiveTriple.isThumb())
3654 D.Diag(diag::err_drv_unsupported_opt_for_target)
3655 << A->getAsString(Args) << TripleStr;
3657 if (
Value.getAsInteger(10, Offset)) {
3658 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() <<
Value;
3661 if ((EffectiveTriple.isARM() || EffectiveTriple.isThumb()) &&
3662 (Offset < 0 || Offset > 0xfffff)) {
3663 D.Diag(diag::err_drv_invalid_int_value)
3664 << A->getOption().getName() <<
Value;
3667 A->render(Args, CmdArgs);
3670 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_reg_EQ)) {
3671 StringRef
Value = A->getValue();
3672 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64())
3673 D.Diag(diag::err_drv_unsupported_opt_for_target)
3674 << A->getAsString(Args) << TripleStr;
3675 if (EffectiveTriple.isX86() && (
Value !=
"fs" &&
Value !=
"gs")) {
3676 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3677 << A->getOption().getName() <<
Value <<
"fs gs";
3680 if (EffectiveTriple.isAArch64() &&
Value !=
"sp_el0") {
3681 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() <<
Value;
3684 A->render(Args, CmdArgs);
3687 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_symbol_EQ)) {
3688 StringRef
Value = A->getValue();
3690 D.Diag(diag::err_drv_argument_only_allowed_with)
3691 << A->getOption().getName() <<
"legal symbol name";
3694 A->render(Args, CmdArgs);
3699 ArgStringList &CmdArgs) {
3702 if (!EffectiveTriple.isOSFreeBSD() && !EffectiveTriple.isOSLinux())
3705 if (!EffectiveTriple.isX86() && !EffectiveTriple.isSystemZ() &&
3706 !EffectiveTriple.isPPC64() && !EffectiveTriple.isAArch64())
3709 Args.addOptInFlag(CmdArgs, options::OPT_fstack_clash_protection,
3710 options::OPT_fno_stack_clash_protection);
3715 const ArgList &Args,
3716 ArgStringList &CmdArgs) {
3718 StringRef TrivialAutoVarInit =
"";
3720 for (
const Arg *A : Args) {
3721 switch (A->getOption().getID()) {
3724 case options::OPT_ftrivial_auto_var_init: {
3726 StringRef Val = A->getValue();
3727 if (Val ==
"uninitialized" || Val ==
"zero" || Val ==
"pattern")
3728 TrivialAutoVarInit = Val;
3730 D.Diag(diag::err_drv_unsupported_option_argument)
3731 << A->getSpelling() << Val;
3737 if (TrivialAutoVarInit.empty())
3738 switch (DefaultTrivialAutoVarInit) {
3742 TrivialAutoVarInit =
"pattern";
3745 TrivialAutoVarInit =
"zero";
3749 if (!TrivialAutoVarInit.empty()) {
3751 Args.MakeArgString(
"-ftrivial-auto-var-init=" + TrivialAutoVarInit));
3755 Args.getLastArg(options::OPT_ftrivial_auto_var_init_stop_after)) {
3756 if (!Args.hasArg(options::OPT_ftrivial_auto_var_init) ||
3758 Args.getLastArg(options::OPT_ftrivial_auto_var_init)->getValue()) ==
3760 D.Diag(diag::err_drv_trivial_auto_var_init_stop_after_missing_dependency);
3762 StringRef Val = A->getValue();
3763 if (std::stoi(Val.str()) <= 0)
3764 D.Diag(diag::err_drv_trivial_auto_var_init_stop_after_invalid_value);
3766 Args.MakeArgString(
"-ftrivial-auto-var-init-stop-after=" + Val));
3769 if (Arg *A = Args.getLastArg(options::OPT_ftrivial_auto_var_init_max_size)) {
3770 if (!Args.hasArg(options::OPT_ftrivial_auto_var_init) ||
3772 Args.getLastArg(options::OPT_ftrivial_auto_var_init)->getValue()) ==
3774 D.Diag(diag::err_drv_trivial_auto_var_init_max_size_missing_dependency);
3776 StringRef Val = A->getValue();
3777 if (std::stoi(Val.str()) <= 0)
3778 D.Diag(diag::err_drv_trivial_auto_var_init_max_size_invalid_value);
3780 Args.MakeArgString(
"-ftrivial-auto-var-init-max-size=" + Val));
3788 const unsigned ForwardedArguments[] = {
3789 options::OPT_cl_opt_disable,
3790 options::OPT_cl_strict_aliasing,
3791 options::OPT_cl_single_precision_constant,
3792 options::OPT_cl_finite_math_only,
3793 options::OPT_cl_kernel_arg_info,
3794 options::OPT_cl_unsafe_math_optimizations,
3795 options::OPT_cl_fast_relaxed_math,
3796 options::OPT_cl_mad_enable,
3797 options::OPT_cl_no_signed_zeros,
3798 options::OPT_cl_fp32_correctly_rounded_divide_sqrt,
3799 options::OPT_cl_uniform_work_group_size
3802 if (Arg *A = Args.getLastArg(options::OPT_cl_std_EQ)) {
3803 std::string CLStdStr = std::string(
"-cl-std=") + A->getValue();
3804 CmdArgs.push_back(Args.MakeArgString(CLStdStr));
3805 }
else if (Arg *A = Args.getLastArg(options::OPT_cl_ext_EQ)) {
3806 std::string CLExtStr = std::string(
"-cl-ext=") + A->getValue();
3807 CmdArgs.push_back(Args.MakeArgString(CLExtStr));
3810 if (Args.hasArg(options::OPT_cl_finite_math_only)) {
3811 CmdArgs.push_back(
"-menable-no-infs");
3812 CmdArgs.push_back(
"-menable-no-nans");
3815 for (
const auto &Arg : ForwardedArguments)
3816 if (
const auto *A = Args.getLastArg(Arg))
3817 CmdArgs.push_back(Args.MakeArgString(A->getOption().getPrefixedName()));
3822 !Args.hasArg(options::OPT_cl_no_stdinc)) {
3823 CmdArgs.push_back(
"-finclude-default-header");
3824 CmdArgs.push_back(
"-fdeclare-opencl-builtins");
3830 const unsigned ForwardedArguments[] = {options::OPT_dxil_validator_version,
3834 options::OPT_emit_llvm,
3835 options::OPT_emit_obj,
3836 options::OPT_disable_llvm_passes,
3837 options::OPT_fnative_half_type,
3838 options::OPT_hlsl_entrypoint};
3841 for (
const auto &Arg : ForwardedArguments)
3842 if (
const auto *A = Args.getLastArg(Arg))
3843 A->renderAsInput(Args, CmdArgs);
3845 if (!Args.hasArg(options::OPT_dxc_no_stdinc) &&
3846 !Args.hasArg(options::OPT_nostdinc))
3847 CmdArgs.push_back(
"-finclude-default-header");
3851 ArgStringList &CmdArgs,
types::ID InputType) {
3852 if (!Args.hasArg(options::OPT_fopenacc))
3855 CmdArgs.push_back(
"-fopenacc");
3857 if (Arg *A = Args.getLastArg(options::OPT_openacc_macro_override)) {
3858 StringRef
Value = A->getValue();
3860 if (!
Value.getAsInteger(10, Version))
3861 A->renderAsInput(Args, CmdArgs);
3863 D.Diag(diag::err_drv_clang_unsupported) <<
Value;
3868 ArgStringList &CmdArgs) {
3869 bool ARCMTEnabled =
false;
3870 if (!Args.hasArg(options::OPT_fno_objc_arc, options::OPT_fobjc_arc)) {
3871 if (
const Arg *A = Args.getLastArg(options::OPT_ccc_arcmt_check,
3872 options::OPT_ccc_arcmt_modify,
3873 options::OPT_ccc_arcmt_migrate)) {
3874 ARCMTEnabled =
true;
3875 switch (A->getOption().getID()) {
3876 default: llvm_unreachable(
"missed a case");
3877 case options::OPT_ccc_arcmt_check:
3878 CmdArgs.push_back(
"-arcmt-action=check");
3880 case options::OPT_ccc_arcmt_modify:
3881 CmdArgs.push_back(
"-arcmt-action=modify");
3883 case options::OPT_ccc_arcmt_migrate:
3884 CmdArgs.push_back(
"-arcmt-action=migrate");
3885 CmdArgs.push_back(
"-mt-migrate-directory");
3886 CmdArgs.push_back(A->getValue());
3888 Args.AddLastArg(CmdArgs, options::OPT_arcmt_migrate_report_output);
3889 Args.AddLastArg(CmdArgs, options::OPT_arcmt_migrate_emit_arc_errors);
3894 Args.ClaimAllArgs(options::OPT_ccc_arcmt_check);
3895 Args.ClaimAllArgs(options::OPT_ccc_arcmt_modify);
3896 Args.ClaimAllArgs(options::OPT_ccc_arcmt_migrate);
3899 if (
const Arg *A = Args.getLastArg(options::OPT_ccc_objcmt_migrate)) {
3901 D.Diag(diag::err_drv_argument_not_allowed_with)
3902 << A->getAsString(Args) <<
"-ccc-arcmt-migrate";
3904 CmdArgs.push_back(
"-mt-migrate-directory");
3905 CmdArgs.push_back(A->getValue());
3907 if (!Args.hasArg(options::OPT_objcmt_migrate_literals,
3908 options::OPT_objcmt_migrate_subscripting,
3909 options::OPT_objcmt_migrate_property)) {
3911 CmdArgs.push_back(
"-objcmt-migrate-literals");
3912 CmdArgs.push_back(
"-objcmt-migrate-subscripting");
3913 CmdArgs.push_back(
"-objcmt-migrate-property");
3915 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_literals);
3916 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_subscripting);
3917 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_property);
3920 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_literals);
3921 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_subscripting);
3922 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_property);
3923 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_all);
3924 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_readonly_property);
3925 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_readwrite_property);
3926 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_property_dot_syntax);
3927 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_annotation);
3928 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_instancetype);
3929 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_nsmacros);
3930 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_protocol_conformance);
3931 Args.AddLastArg(CmdArgs, options::OPT_objcmt_atomic_property);
3932 Args.AddLastArg(CmdArgs, options::OPT_objcmt_returns_innerpointer_property);
3933 Args.AddLastArg(CmdArgs, options::OPT_objcmt_ns_nonatomic_iosonly);
3934 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_designated_init);
3935 Args.AddLastArg(CmdArgs, options::OPT_objcmt_allowlist_dir_path);
3940 const ArgList &Args, ArgStringList &CmdArgs) {
3943 Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin,
3944 !Args.hasArg(options::OPT_mkernel));
3946 CmdArgs.push_back(
"-fno-builtin");
3949 if (Args.hasArg(options::OPT_ffreestanding))
3950 UseBuiltins =
false;
3953 for (
const Arg *A : Args.filtered(options::OPT_fno_builtin_)) {
3959 A->render(Args, CmdArgs);
3964 if (
const char *Str = std::getenv(
"CLANG_MODULE_CACHE_PATH")) {
3967 return Path.getSingleStringRef() !=
"";
3969 if (llvm::sys::path::cache_directory(
Result)) {
3970 llvm::sys::path::append(
Result,
"clang");
3971 llvm::sys::path::append(
Result,
"ModuleCache");
3979 const char *BaseInput) {
3980 if (Arg *ModuleOutputEQ = Args.getLastArg(options::OPT_fmodule_output_EQ))
3981 return StringRef(ModuleOutputEQ->getValue());
3984 if (Arg *FinalOutput = Args.getLastArg(options::OPT_o);
3985 FinalOutput && Args.hasArg(options::OPT_c))
3986 OutputPath = FinalOutput->getValue();
3988 OutputPath = BaseInput;
3991 llvm::sys::path::replace_extension(OutputPath, Extension);
3996 const ArgList &Args,
const InputInfo &Input,
3997 const InputInfo &Output,
bool HaveStd20,
3998 ArgStringList &CmdArgs) {
4000 bool HaveStdCXXModules = IsCXX && HaveStd20;
4001 bool HaveModules = HaveStdCXXModules;
4006 bool HaveClangModules =
false;
4007 if (Args.hasFlag(options::OPT_fmodules, options::OPT_fno_modules,
false)) {
4008 bool AllowedInCXX = Args.hasFlag(options::OPT_fcxx_modules,
4009 options::OPT_fno_cxx_modules,
true);
4010 if (AllowedInCXX || !IsCXX) {
4011 CmdArgs.push_back(
"-fmodules");
4012 HaveClangModules =
true;
4016 HaveModules |= HaveClangModules;
4020 if (Args.hasFlag(options::OPT_fimplicit_module_maps,
4021 options::OPT_fno_implicit_module_maps, HaveClangModules))
4022 CmdArgs.push_back(
"-fimplicit-module-maps");
4025 Args.addOptInFlag(CmdArgs, options::OPT_fmodules_decluse,
4026 options::OPT_fno_modules_decluse);
4030 if (Args.hasFlag(options::OPT_fmodules_strict_decluse,
4031 options::OPT_fno_modules_strict_decluse,
false))
4032 CmdArgs.push_back(
"-fmodules-strict-decluse");
4034 Args.addOptOutFlag(CmdArgs, options::OPT_fmodulemap_allow_subdirectory_search,
4035 options::OPT_fno_modulemap_allow_subdirectory_search);
4038 bool ImplicitModules =
false;
4039 if (!Args.hasFlag(options::OPT_fimplicit_modules,
4040 options::OPT_fno_implicit_modules, HaveClangModules)) {
4042 CmdArgs.push_back(
"-fno-implicit-modules");
4043 }
else if (HaveModules) {
4044 ImplicitModules =
true;
4048 if (Arg *A = Args.getLastArg(options::OPT_fmodules_cache_path))
4049 Path = A->getValue();
4051 bool HasPath =
true;
4052 if (
C.isForDiagnostics()) {
4056 llvm::sys::path::replace_extension(
Path,
".cache");
4057 llvm::sys::path::append(
Path,
"modules");
4058 }
else if (
Path.empty()) {
4066 const char Arg[] =
"-fmodules-cache-path=";
4067 Path.insert(
Path.begin(), Arg, Arg + strlen(Arg));
4068 CmdArgs.push_back(Args.MakeArgString(
Path));
4073 if (Args.hasFlag(options::OPT_fprebuilt_implicit_modules,
4074 options::OPT_fno_prebuilt_implicit_modules,
false))
4075 CmdArgs.push_back(
"-fprebuilt-implicit-modules");
4076 if (Args.hasFlag(options::OPT_fmodules_validate_input_files_content,
4077 options::OPT_fno_modules_validate_input_files_content,
4079 CmdArgs.push_back(
"-fvalidate-ast-input-files-content");
4084 Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
4088 Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
4092 if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
4094 llvm::sys::path::append(BuiltinModuleMap,
"include");
4095 llvm::sys::path::append(BuiltinModuleMap,
"module.modulemap");
4096 if (llvm::sys::fs::exists(BuiltinModuleMap))
4098 Args.MakeArgString(
"-fmodule-map-file=" + BuiltinModuleMap));
4105 if (HaveModules || Input.
getType() == clang::driver::types::TY_ModuleFile) {
4106 Args.AddAllArgs(CmdArgs, options::OPT_fmodule_file);
4109 for (
const Arg *A : Args.filtered(options::OPT_fprebuilt_module_path)) {
4110 CmdArgs.push_back(Args.MakeArgString(
4111 std::string(
"-fprebuilt-module-path=") + A->getValue()));
4115 Args.ClaimAllArgs(options::OPT_fmodule_file);
4119 if (HaveClangModules &&
C.isForDiagnostics()) {
4121 llvm::sys::path::replace_extension(VFSDir,
".cache");
4123 C.addTempFile(Args.MakeArgString(VFSDir));
4125 llvm::sys::path::append(VFSDir,
"vfs");
4126 CmdArgs.push_back(
"-module-dependency-dir");
4127 CmdArgs.push_back(Args.MakeArgString(VFSDir));
4130 if (HaveClangModules)
4131 Args.AddLastArg(CmdArgs, options::OPT_fmodules_user_build_path);
4134 Args.AddAllArgs(CmdArgs, options::OPT_fmodules_ignore_macro);
4135 Args.AddLastArg(CmdArgs, options::OPT_fmodules_prune_interval);
4136 Args.AddLastArg(CmdArgs, options::OPT_fmodules_prune_after);
4138 if (HaveClangModules) {
4139 Args.AddLastArg(CmdArgs, options::OPT_fbuild_session_timestamp);
4141 if (Arg *A = Args.getLastArg(options::OPT_fbuild_session_file)) {
4142 if (Args.hasArg(options::OPT_fbuild_session_timestamp))
4143 D.Diag(diag::err_drv_argument_not_allowed_with)
4144 << A->getAsString(Args) <<
"-fbuild-session-timestamp";
4146 llvm::sys::fs::file_status Status;
4147 if (llvm::sys::fs::status(A->getValue(), Status))
4148 D.Diag(diag::err_drv_no_such_file) << A->getValue();
4149 CmdArgs.push_back(Args.MakeArgString(
4150 "-fbuild-session-timestamp=" +
4151 Twine((uint64_t)std::chrono::duration_cast<std::chrono::seconds>(
4152 Status.getLastModificationTime().time_since_epoch())
4156 if (Args.getLastArg(
4157 options::OPT_fmodules_validate_once_per_build_session)) {
4158 if (!Args.getLastArg(options::OPT_fbuild_session_timestamp,
4159 options::OPT_fbuild_session_file))
4160 D.Diag(diag::err_drv_modules_validate_once_requires_timestamp);
4162 Args.AddLastArg(CmdArgs,
4163 options::OPT_fmodules_validate_once_per_build_session);
4166 if (Args.hasFlag(options::OPT_fmodules_validate_system_headers,
4167 options::OPT_fno_modules_validate_system_headers,
4169 CmdArgs.push_back(
"-fmodules-validate-system-headers");
4171 Args.AddLastArg(CmdArgs,
4172 options::OPT_fmodules_disable_diagnostic_validation);
4174 Args.ClaimAllArgs(options::OPT_fbuild_session_timestamp);
4175 Args.ClaimAllArgs(options::OPT_fbuild_session_file);
4176 Args.ClaimAllArgs(options::OPT_fmodules_validate_once_per_build_session);
4177 Args.ClaimAllArgs(options::OPT_fmodules_validate_system_headers);
4178 Args.ClaimAllArgs(options::OPT_fno_modules_validate_system_headers);
4179 Args.ClaimAllArgs(options::OPT_fmodules_disable_diagnostic_validation);
4184 CmdArgs.push_back(
"-fskip-odr-check-in-gmf");
4186 if (Args.hasArg(options::OPT_modules_reduced_bmi) &&
4187 (Input.
getType() == driver::types::TY_CXXModule ||
4188 Input.
getType() == driver::types::TY_PP_CXXModule)) {
4189 CmdArgs.push_back(
"-fexperimental-modules-reduced-bmi");
4191 if (Args.hasArg(options::OPT_fmodule_output_EQ))
4192 Args.AddLastArg(CmdArgs, options::OPT_fmodule_output_EQ);
4194 CmdArgs.push_back(Args.MakeArgString(
4195 "-fmodule-output=" +
4202 Args.ClaimAllArgs(options::OPT_modules_reduced_bmi);
4210 if (Input.
getType() == driver::types::TY_CXXModule ||
4211 Input.
getType() == driver::types::TY_PP_CXXModule ||
4212 Input.
getType() == driver::types::TY_ModuleFile) {
4213 Args.ClaimAllArgs(options::OPT_fmodule_output);
4214 Args.ClaimAllArgs(options::OPT_fmodule_output_EQ);
4221 ArgStringList &CmdArgs) {
4223 if (
const Arg *A = Args.getLastArg(options::OPT_fsigned_char,
4224 options::OPT_fno_signed_char,
4225 options::OPT_funsigned_char,
4226 options::OPT_fno_unsigned_char)) {
4227 if (A->getOption().matches(options::OPT_funsigned_char) ||
4228 A->getOption().matches(options::OPT_fno_signed_char)) {
4229 CmdArgs.push_back(
"-fno-signed-char");
4232 CmdArgs.push_back(
"-fno-signed-char");
4236 Args.AddLastArg(CmdArgs, options::OPT_fchar8__t, options::OPT_fno_char8__t);
4238 if (
const Arg *A = Args.getLastArg(options::OPT_fshort_wchar,
4239 options::OPT_fno_short_wchar)) {
4240 if (A->getOption().matches(options::OPT_fshort_wchar)) {
4241 CmdArgs.push_back(
"-fwchar-type=short");
4242 CmdArgs.push_back(
"-fno-signed-wchar");
4244 bool IsARM =
T.isARM() ||
T.isThumb() ||
T.isAArch64();
4245 CmdArgs.push_back(
"-fwchar-type=int");
4247 (IsARM && !(
T.isOSWindows() ||
T.isOSNetBSD() ||
T.isOSOpenBSD())))
4248 CmdArgs.push_back(
"-fno-signed-wchar");
4250 CmdArgs.push_back(
"-fsigned-wchar");
4252 }
else if (
T.isOSzOS())
4253 CmdArgs.push_back(
"-fno-signed-wchar");
4257 const llvm::Triple &
T,
const ArgList &Args,
4259 const InputInfo &Input, ArgStringList &CmdArgs) {
4260 const llvm::Triple::ArchType Arch = TC.
getArch();
4266 if (!Args.hasFlag(options::OPT_fobjc_legacy_dispatch,
4267 options::OPT_fno_objc_legacy_dispatch,
4270 CmdArgs.push_back(
"-fobjc-dispatch-method=mixed");
4272 CmdArgs.push_back(
"-fobjc-dispatch-method=non-legacy");
4278 if (Arch == llvm::Triple::x86 &&
T.isMacOSX() &&
4280 CmdArgs.push_back(
"-fobjc-subscripting-legacy-runtime");
4287 CmdArgs.push_back(
"-fobjc-arc");
4294 CmdArgs.push_back(
"-fobjc-arc-cxxlib=libc++");
4296 CmdArgs.push_back(
"-fobjc-arc-cxxlib=libstdc++");
4301 if (Args.hasFlag(options::OPT_fobjc_arc_exceptions,
4302 options::OPT_fno_objc_arc_exceptions,
4304 CmdArgs.push_back(
"-fobjc-arc-exceptions");
4309 if (Args.hasArg(options::OPT_fno_objc_arc)) {
4310 Args.ClaimAllArgs(options::OPT_fobjc_arc_exceptions);
4311 Args.ClaimAllArgs(options::OPT_fno_objc_arc_exceptions);
4317 auto *Arg = Args.getLastArg(
4318 options::OPT_fobjc_convert_messages_to_runtime_calls,
4319 options::OPT_fno_objc_convert_messages_to_runtime_calls);
4321 Arg->getOption().matches(
4322 options::OPT_fno_objc_convert_messages_to_runtime_calls))
4323 CmdArgs.push_back(
"-fno-objc-convert-messages-to-runtime-calls");
4328 if (InferCovariantReturns)
4329 CmdArgs.push_back(
"-fno-objc-infer-related-result-type");
4334 Args.getLastArg(options::OPT_fobjc_weak, options::OPT_fno_objc_weak);
4338 if (WeakArg->getOption().matches(options::OPT_fobjc_weak))
4339 D.Diag(diag::err_objc_weak_unsupported);
4341 WeakArg->render(Args, CmdArgs);
4345 if (Args.hasArg(options::OPT_fobjc_disable_direct_methods_for_testing))
4346 CmdArgs.push_back(
"-fobjc-disable-direct-methods-for-testing");
4350 ArgStringList &CmdArgs) {
4351 bool CaretDefault =
true;
4352 bool ColumnDefault =
true;
4354 if (
const Arg *A = Args.getLastArg(options::OPT__SLASH_diagnostics_classic,
4355 options::OPT__SLASH_diagnostics_column,
4356 options::OPT__SLASH_diagnostics_caret)) {
4357 switch (A->getOption().getID()) {
4358 case options::OPT__SLASH_diagnostics_caret:
4359 CaretDefault =
true;
4360 ColumnDefault =
true;
4362 case options::OPT__SLASH_diagnostics_column:
4363 CaretDefault =
false;
4364 ColumnDefault =
true;
4366 case options::OPT__SLASH_diagnostics_classic:
4367 CaretDefault =
false;
4368 ColumnDefault =
false;
4374 if (!Args.hasFlag(options::OPT_fcaret_diagnostics,
4375 options::OPT_fno_caret_diagnostics, CaretDefault))
4376 CmdArgs.push_back(
"-fno-caret-diagnostics");
4378 Args.addOptOutFlag(CmdArgs, options::OPT_fdiagnostics_fixit_info,
4379 options::OPT_fno_diagnostics_fixit_info);
4380 Args.addOptOutFlag(CmdArgs, options::OPT_fdiagnostics_show_option,
4381 options::OPT_fno_diagnostics_show_option);
4384 Args.getLastArg(options::OPT_fdiagnostics_show_category_EQ)) {
4385 CmdArgs.push_back(
"-fdiagnostics-show-category");
4386 CmdArgs.push_back(A->getValue());
4389 Args.addOptInFlag(CmdArgs, options::OPT_fdiagnostics_show_hotness,
4390 options::OPT_fno_diagnostics_show_hotness);
4393 Args.getLastArg(options::OPT_fdiagnostics_hotness_threshold_EQ)) {
4395 std::string(
"-fdiagnostics-hotness-threshold=") + A->getValue();
4396 CmdArgs.push_back(Args.MakeArgString(Opt));
4400 Args.getLastArg(options::OPT_fdiagnostics_misexpect_tolerance_EQ)) {
4402 std::string(
"-fdiagnostics-misexpect-tolerance=") + A->getValue();
4403 CmdArgs.push_back(Args.MakeArgString(Opt));
4406 if (
const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) {
4407 CmdArgs.push_back(
"-fdiagnostics-format");
4408 CmdArgs.push_back(A->getValue());
4409 if (StringRef(A->getValue()) ==
"sarif" ||
4410 StringRef(A->getValue()) ==
"SARIF")
4411 D.Diag(diag::warn_drv_sarif_format_unstable);
4414 if (
const Arg *A = Args.getLastArg(
4415 options::OPT_fdiagnostics_show_note_include_stack,
4416 options::OPT_fno_diagnostics_show_note_include_stack)) {
4417 const Option &O = A->getOption();
4418 if (O.matches(options::OPT_fdiagnostics_show_note_include_stack))
4419 CmdArgs.push_back(
"-fdiagnostics-show-note-include-stack");
4421 CmdArgs.push_back(
"-fno-diagnostics-show-note-include-stack");
4428 Args.getLastArg(options::OPT_fcolor_diagnostics,
4429 options::OPT_fno_color_diagnostics);
4430 if (
const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_color_EQ)) {
4431 StringRef
Value(A->getValue());
4433 D.Diag(diag::err_drv_invalid_argument_to_option)
4434 <<
Value << A->getOption().getName();
4437 if (
D.getDiags().getDiagnosticOptions().ShowColors)
4438 CmdArgs.push_back(
"-fcolor-diagnostics");
4440 if (Args.hasArg(options::OPT_fansi_escape_codes))
4441 CmdArgs.push_back(
"-fansi-escape-codes");
4443 Args.addOptOutFlag(CmdArgs, options::OPT_fshow_source_location,
4444 options::OPT_fno_show_source_location);
4446 Args.addOptOutFlag(CmdArgs, options::OPT_fdiagnostics_show_line_numbers,
4447 options::OPT_fno_diagnostics_show_line_numbers);
4449 if (Args.hasArg(options::OPT_fdiagnostics_absolute_paths))
4450 CmdArgs.push_back(
"-fdiagnostics-absolute-paths");
4452 if (!Args.hasFlag(options::OPT_fshow_column, options::OPT_fno_show_column,
4454 CmdArgs.push_back(
"-fno-show-column");
4456 Args.addOptOutFlag(CmdArgs, options::OPT_fspell_checking,
4457 options::OPT_fno_spell_checking);
4461 const ArgList &Args, Arg *&Arg) {
4462 Arg = Args.getLastArg(options::OPT_gsplit_dwarf, options::OPT_gsplit_dwarf_EQ,
4463 options::OPT_gno_split_dwarf);
4464 if (!Arg || Arg->getOption().matches(options::OPT_gno_split_dwarf))
4467 if (Arg->getOption().matches(options::OPT_gsplit_dwarf))
4470 StringRef
Value = Arg->getValue();
4471 if (
Value ==
"split")
4473 if (
Value ==
"single")
4476 D.Diag(diag::err_drv_unsupported_option_argument)
4477 << Arg->getSpelling() << Arg->getValue();
4482 const ArgList &Args, ArgStringList &CmdArgs,
4483 unsigned DwarfVersion) {
4484 auto *DwarfFormatArg =
4485 Args.getLastArg(options::OPT_gdwarf64, options::OPT_gdwarf32);
4486 if (!DwarfFormatArg)
4489 if (DwarfFormatArg->getOption().matches(options::OPT_gdwarf64)) {
4490 if (DwarfVersion < 3)
4491 D.Diag(diag::err_drv_argument_only_allowed_with)
4492 << DwarfFormatArg->getAsString(Args) <<
"DWARFv3 or greater";
4493 else if (!
T.isArch64Bit())
4494 D.Diag(diag::err_drv_argument_only_allowed_with)
4495 << DwarfFormatArg->getAsString(Args) <<
"64 bit architecture";
4496 else if (!
T.isOSBinFormatELF())
4497 D.Diag(diag::err_drv_argument_only_allowed_with)
4498 << DwarfFormatArg->getAsString(Args) <<
"ELF platforms";
4501 DwarfFormatArg->render(Args, CmdArgs);
4506 const ArgList &Args,
bool IRInput, ArgStringList &CmdArgs,
4508 llvm::codegenoptions::DebugInfoKind &DebugInfoKind,
4510 if (Args.hasFlag(options::OPT_fdebug_info_for_profiling,
4511 options::OPT_fno_debug_info_for_profiling,
false) &&
4513 Args.getLastArg(options::OPT_fdebug_info_for_profiling), Args,
D, TC))
4514 CmdArgs.push_back(
"-fdebug-info-for-profiling");
4527 bool SplitDWARFInlining =
4528 Args.hasFlag(options::OPT_fsplit_dwarf_inlining,
4529 options::OPT_fno_split_dwarf_inlining,
false);
4534 if (IRInput || Args.hasArg(options::OPT_g_Group)) {
4540 SplitDWARFInlining =
false;
4543 if (
const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
4544 DebugInfoKind = llvm::codegenoptions::DebugInfoConstructor;
4548 A->getOption().matches(options::OPT_gN_Group)) {
4554 if (DebugInfoKind == llvm::codegenoptions::NoDebugInfo ||
4555 DebugInfoKind == llvm::codegenoptions::DebugDirectivesOnly ||
4556 (DebugInfoKind == llvm::codegenoptions::DebugLineTablesOnly &&
4557 SplitDWARFInlining))
4563 bool HasDebuggerTuning =
false;
4565 Args.getLastArg(options::OPT_gTune_Group, options::OPT_ggdbN_Group)) {
4566 HasDebuggerTuning =
true;
4568 if (A->getOption().matches(options::OPT_glldb))
4569 DebuggerTuning = llvm::DebuggerKind::LLDB;
4570 else if (A->getOption().matches(options::OPT_gsce))
4571 DebuggerTuning = llvm::DebuggerKind::SCE;
4572 else if (A->getOption().matches(options::OPT_gdbx))
4573 DebuggerTuning = llvm::DebuggerKind::DBX;
4575 DebuggerTuning = llvm::DebuggerKind::GDB;
4580 bool EmitDwarf =
false;
4584 bool EmitCodeView =
false;
4585 if (
const Arg *A = Args.getLastArg(options::OPT_gcodeview))
4590 if (!EmitCodeView && !EmitDwarf &&
4591 DebugInfoKind != llvm::codegenoptions::NoDebugInfo) {
4593 case llvm::codegenoptions::DIF_CodeView:
4594 EmitCodeView =
true;
4596 case llvm::codegenoptions::DIF_DWARF:
4602 unsigned RequestedDWARFVersion = 0;
4603 unsigned EffectiveDWARFVersion = 0;
4608 EffectiveDWARFVersion =
4611 Args.ClaimAllArgs(options::OPT_fdebug_default_version);
4615 if (RequestedDWARFVersion == 0 &&
4616 DebugInfoKind == llvm::codegenoptions::DebugDirectivesOnly)
4617 DebugInfoKind = llvm::codegenoptions::NoDebugInfo;
4621 if (
const Arg *A = Args.getLastArg(options::OPT_gstrict_dwarf))
4623 if (Args.hasFlag(options::OPT_gstrict_dwarf, options::OPT_gno_strict_dwarf,
4624 DebuggerTuning == llvm::DebuggerKind::DBX))
4625 CmdArgs.push_back(
"-gstrict-dwarf");
4628 Args.ClaimAllArgs(options::OPT_g_flags_Group);
4636 if (
const Arg *A = Args.getLastArg(options::OPT_gcolumn_info))
4638 if (!Args.hasFlag(options::OPT_gcolumn_info, options::OPT_gno_column_info,
4640 (DebuggerTuning != llvm::DebuggerKind::SCE &&
4641 DebuggerTuning != llvm::DebuggerKind::DBX)))
4642 CmdArgs.push_back(
"-gno-column-info");
4645 if (Args.hasFlag(options::OPT_gmodules, options::OPT_gno_modules,
false)) {
4650 if (DebugInfoKind != llvm::codegenoptions::DebugLineTablesOnly &&
4651 DebugInfoKind != llvm::codegenoptions::DebugDirectivesOnly) {
4652 DebugInfoKind = llvm::codegenoptions::DebugInfoConstructor;
4653 CmdArgs.push_back(
"-dwarf-ext-refs");
4654 CmdArgs.push_back(
"-fmodule-format=obj");
4659 if (
T.isOSBinFormatELF() && SplitDWARFInlining)
4660 CmdArgs.push_back(
"-fsplit-dwarf-inlining");
4667 bool NeedFullDebug = Args.hasFlag(
4668 options::OPT_fstandalone_debug, options::OPT_fno_standalone_debug,
4669 DebuggerTuning == llvm::DebuggerKind::LLDB ||
4671 if (
const Arg *A = Args.getLastArg(options::OPT_fstandalone_debug))
4674 if (DebugInfoKind == llvm::codegenoptions::LimitedDebugInfo ||
4675 DebugInfoKind == llvm::codegenoptions::DebugInfoConstructor) {
4676 if (Args.hasFlag(options::OPT_fno_eliminate_unused_debug_types,
4677 options::OPT_feliminate_unused_debug_types,
false))
4678 DebugInfoKind = llvm::codegenoptions::UnusedTypeInfo;
4679 else if (NeedFullDebug)
4680 DebugInfoKind = llvm::codegenoptions::FullDebugInfo;
4683 if (Args.hasFlag(options::OPT_gembed_source, options::OPT_gno_embed_source,
4689 const Arg *A = Args.getLastArg(options::OPT_gembed_source);
4690 if (RequestedDWARFVersion < 5)
4691 D.Diag(diag::err_drv_argument_only_allowed_with)
4692 << A->getAsString(Args) <<
"-gdwarf-5";
4693 else if (EffectiveDWARFVersion < 5)
4696 D.Diag(diag::warn_drv_dwarf_version_limited_by_target)
4698 << EffectiveDWARFVersion;
4700 CmdArgs.push_back(
"-gembed-source");
4704 CmdArgs.push_back(
"-gcodeview");
4706 Args.addOptInFlag(CmdArgs, options::OPT_gcodeview_ghash,
4707 options::OPT_gno_codeview_ghash);
4709 Args.addOptOutFlag(CmdArgs, options::OPT_gcodeview_command_line,
4710 options::OPT_gno_codeview_command_line);
4713 Args.addOptOutFlag(CmdArgs, options::OPT_ginline_line_tables,
4714 options::OPT_gno_inline_line_tables);
4718 DebugInfoKind <= llvm::codegenoptions::DebugDirectivesOnly)
4719 DebugInfoKind = llvm::codegenoptions::DebugLineTablesOnly;
4727 T.isOSAIX() && !HasDebuggerTuning
4728 ? llvm::DebuggerKind::Default
4732 if (Args.hasFlag(options::OPT_fdebug_macro, options::OPT_fno_debug_macro,
4736 CmdArgs.push_back(
"-debug-info-macro");
4739 const auto *PubnamesArg =
4740 Args.getLastArg(options::OPT_ggnu_pubnames, options::OPT_gno_gnu_pubnames,
4741 options::OPT_gpubnames, options::OPT_gno_pubnames);
4744 const bool OptionSet =
4746 (PubnamesArg->getOption().matches(options::OPT_gpubnames) ||
4747 PubnamesArg->getOption().matches(options::OPT_ggnu_pubnames)));
4748 if ((DebuggerTuning != llvm::DebuggerKind::LLDB || OptionSet) &&
4750 (!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) &&
4751 !PubnamesArg->getOption().matches(options::OPT_gno_pubnames))))
4752 CmdArgs.push_back(PubnamesArg && PubnamesArg->getOption().matches(
4753 options::OPT_gpubnames)
4755 :
"-ggnu-pubnames");
4757 const auto *SimpleTemplateNamesArg =
4758 Args.getLastArg(options::OPT_gsimple_template_names,
4759 options::OPT_gno_simple_template_names);
4760 bool ForwardTemplateParams = DebuggerTuning == llvm::DebuggerKind::SCE;
4761 if (SimpleTemplateNamesArg &&
4763 const auto &Opt = SimpleTemplateNamesArg->getOption();
4764 if (Opt.matches(options::OPT_gsimple_template_names)) {
4765 ForwardTemplateParams =
true;
4766 CmdArgs.push_back(
"-gsimple-template-names=simple");
4771 bool UseDebugTemplateAlias =
4772 DebuggerTuning == llvm::DebuggerKind::SCE && RequestedDWARFVersion >= 4;
4773 if (
const auto *DebugTemplateAlias = Args.getLastArg(
4774 options::OPT_gtemplate_alias, options::OPT_gno_template_alias)) {
4778 const auto &Opt = DebugTemplateAlias->getOption();
4779 UseDebugTemplateAlias = Opt.matches(options::OPT_gtemplate_alias);
4782 if (UseDebugTemplateAlias)
4783 CmdArgs.push_back(
"-gtemplate-alias");
4785 if (
const Arg *A = Args.getLastArg(options::OPT_gsrc_hash_EQ)) {
4786 StringRef
v = A->getValue();
4787 CmdArgs.push_back(Args.MakeArgString(
"-gsrc-hash=" +
v));
4790 Args.addOptInFlag(CmdArgs, options::OPT_fdebug_ranges_base_address,
4791 options::OPT_fno_debug_ranges_base_address);
4795 if (
const Arg *A = Args.getLastArg(options::OPT_gdwarf_aranges);
4797 CmdArgs.push_back(
"-mllvm");
4798 CmdArgs.push_back(
"-generate-arange-section");
4801 Args.addOptInFlag(CmdArgs, options::OPT_fforce_dwarf_frame,
4802 options::OPT_fno_force_dwarf_frame);
4804 bool EnableTypeUnits =
false;
4805 if (Args.hasFlag(options::OPT_fdebug_types_section,
4806 options::OPT_fno_debug_types_section,
false)) {
4807 if (!(
T.isOSBinFormatELF() ||
T.isOSBinFormatWasm())) {
4808 D.Diag(diag::err_drv_unsupported_opt_for_target)
4809 << Args.getLastArg(options::OPT_fdebug_types_section)
4813 Args.getLastArg(options::OPT_fdebug_types_section), Args,
D,
4815 EnableTypeUnits =
true;
4816 CmdArgs.push_back(
"-mllvm");
4817 CmdArgs.push_back(
"-generate-type-units");
4822 Args.getLastArg(options::OPT_gomit_unreferenced_methods,
4823 options::OPT_gno_omit_unreferenced_methods))
4825 if (Args.hasFlag(options::OPT_gomit_unreferenced_methods,
4826 options::OPT_gno_omit_unreferenced_methods,
false) &&
4827 (DebugInfoKind == llvm::codegenoptions::DebugInfoConstructor ||
4828 DebugInfoKind == llvm::codegenoptions::LimitedDebugInfo) &&
4830 CmdArgs.push_back(
"-gomit-unreferenced-methods");
4836 if (!Args.hasFlag(options::OPT_fdwarf_directory_asm,
4837 options::OPT_fno_dwarf_directory_asm,
4839 CmdArgs.push_back(
"-fno-dwarf-directory-asm");
4843 if (ForwardTemplateParams)
4844 CmdArgs.push_back(
"-debug-forward-template-params");
4848 if (DebuggerTuning == llvm::DebuggerKind::SCE)
4849 CmdArgs.push_back(
"-dwarf-explicit-import");
4855 if (Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc,
false)) {
4856 if (TC.
getTriple().isOSBinFormatELF() ||
D.IsCLMode()) {
4857 if (DebugInfoKind >= llvm::codegenoptions::DebugInfoConstructor)
4858 CmdArgs.push_back(
"-fjmc");
4859 else if (
D.IsCLMode())
4860 D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo) <<
"/JMC"
4863 D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo) <<
"-fjmc"
4866 D.Diag(clang::diag::warn_drv_fjmc_for_elf_only);
4871 const char *DebugCompilationDir =
4883 ArgStringList &CmdArgs) {
4884 unsigned RTOptionID = options::OPT__SLASH_MT;
4886 if (Args.hasArg(options::OPT__SLASH_LDd))
4889 RTOptionID = options::OPT__SLASH_MTd;
4891 if (Arg *A = Args.getLastArg(options::OPT__SLASH_M_Group))
4892 RTOptionID = A->getOption().getID();
4894 if (Arg *A = Args.getLastArg(options::OPT_fms_runtime_lib_EQ)) {
4895 RTOptionID = llvm::StringSwitch<unsigned>(A->getValue())
4896 .Case(
"static", options::OPT__SLASH_MT)
4897 .Case(
"static_dbg", options::OPT__SLASH_MTd)
4898 .Case(
"dll", options::OPT__SLASH_MD)
4899 .Case(
"dll_dbg", options::OPT__SLASH_MDd)
4900 .Default(options::OPT__SLASH_MT);
4903 StringRef FlagForCRT;
4904 switch (RTOptionID) {
4905 case options::OPT__SLASH_MD:
4906 if (Args.hasArg(options::OPT__SLASH_LDd))
4907 CmdArgs.push_back(
"-D_DEBUG");
4908 CmdArgs.push_back(
"-D_MT");
4909 CmdArgs.push_back(
"-D_DLL");
4910 FlagForCRT =
"--dependent-lib=msvcrt";
4912 case options::OPT__SLASH_MDd:
4913 CmdArgs.push_back(
"-D_DEBUG");
4914 CmdArgs.push_back(
"-D_MT");
4915 CmdArgs.push_back(
"-D_DLL");
4916 FlagForCRT =
"--dependent-lib=msvcrtd";
4918 case options::OPT__SLASH_MT:
4919 if (Args.hasArg(options::OPT__SLASH_LDd))
4920 CmdArgs.push_back(
"-D_DEBUG");
4921 CmdArgs.push_back(
"-D_MT");
4922 CmdArgs.push_back(
"-flto-visibility-public-std");
4923 FlagForCRT =
"--dependent-lib=libcmt";
4925 case options::OPT__SLASH_MTd:
4926 CmdArgs.push_back(
"-D_DEBUG");
4927 CmdArgs.push_back(
"-D_MT");
4928 CmdArgs.push_back(
"-flto-visibility-public-std");
4929 FlagForCRT =
"--dependent-lib=libcmtd";
4932 llvm_unreachable(
"Unexpected option ID.");
4935 if (Args.hasArg(options::OPT_fms_omit_default_lib)) {
4936 CmdArgs.push_back(
"-D_VC_NODEFAULTLIB");
4938 CmdArgs.push_back(FlagForCRT.data());
4943 CmdArgs.push_back(
"--dependent-lib=oldnames");
4950 CmdArgs.push_back(
"--dependent-lib=softintrin");
4955 const ArgList &Args,
const char *LinkingOutput)
const {
4957 const llvm::Triple &RawTriple = TC.
getTriple();
4959 const std::string &TripleStr = Triple.getTriple();
4962 Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
4964 ArgStringList CmdArgs;
4966 assert(Inputs.size() >= 1 &&
"Must have at least one input.");
4978 bool IsExtractAPI = isa<ExtractAPIJobAction>(JA);
4981 bool IsHostOffloadingAction =
4984 Args.hasFlag(options::OPT_offload_new_driver,
4985 options::OPT_no_offload_new_driver,
false));
4988 Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
false);
4990 auto LTOMode = IsDeviceOffloadAction ?
D.getOffloadLTOMode() :
D.getLTOMode();
4995 InputInfo ExtractAPIPlaceholderInput(Inputs[0].getType(),
"extract-api",
4999 IsExtractAPI ? ExtractAPIPlaceholderInput : Inputs[0];
5003 const InputInfo *CudaDeviceInput =
nullptr;
5004 const InputInfo *OpenMPDeviceInput =
nullptr;
5006 if (&I == &Input || I.
getType() == types::TY_Nothing) {
5008 }
else if (IsExtractAPI) {
5009 auto ExpectedInputType = ExtractAPIPlaceholderInput.
getType();
5010 if (I.getType() != ExpectedInputType) {
5011 D.Diag(diag::err_drv_extract_api_wrong_kind)
5015 ExtractAPIInputs.push_back(I);
5016 }
else if (IsHostOffloadingAction) {
5017 HostOffloadingInputs.push_back(I);
5018 }
else if ((IsCuda || IsHIP) && !CudaDeviceInput) {
5019 CudaDeviceInput = &I;
5020 }
else if (IsOpenMPDevice && !OpenMPDeviceInput) {
5021 OpenMPDeviceInput = &I;
5023 llvm_unreachable(
"unexpectedly given multiple inputs");
5027 const llvm::Triple *AuxTriple =
5029 bool IsWindowsMSVC = RawTriple.isWindowsMSVCEnvironment();
5030 bool IsIAMCU = RawTriple.isOSIAMCU();
5035 if (IsCuda || IsHIP)
5036 IsWindowsMSVC |= AuxTriple && AuxTriple->isWindowsMSVCEnvironment();
5040 D.Diag(diag::err_drv_clang_unsupported) <<
"C++ for IAMCU";
5045 CmdArgs.push_back(
"-cc1");
5048 CmdArgs.push_back(
"-triple");
5049 CmdArgs.push_back(Args.MakeArgString(TripleStr));
5051 if (
const Arg *MJ = Args.getLastArg(options::OPT_MJ)) {
5052 DumpCompilationDatabase(
C, MJ->getValue(), TripleStr, Output, Input, Args);
5053 Args.ClaimAllArgs(options::OPT_MJ);
5054 }
else if (
const Arg *GenCDBFragment =
5055 Args.getLastArg(options::OPT_gen_cdb_fragment_path)) {
5056 DumpCompilationDatabaseFragmentToDir(GenCDBFragment->getValue(),
C,
5057 TripleStr, Output, Input, Args);
5058 Args.ClaimAllArgs(options::OPT_gen_cdb_fragment_path);
5061 if (IsCuda || IsHIP) {
5064 std::string NormalizedTriple;
5082 assert(CTC &&
"Expected valid CUDA Toolchain.");
5084 CmdArgs.push_back(Args.MakeArgString(
5085 Twine(
"-target-sdk-version=") +
5093 CmdArgs.push_back(
"-fcuda-allow-variadic-functions");
5096 CmdArgs.push_back(
"-aux-triple");
5097 CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
5102 getToolChain().getTriple().getVendor() == llvm::Triple::AMD))) {
5104 if (Args.getLastArg(options::OPT_mprintf_kind_EQ)) {
5105 CmdArgs.push_back(Args.MakeArgString(
5107 Args.getLastArgValue(options::OPT_mprintf_kind_EQ)));
5110 Args.MakeArgString(
"-Werror=format-invalid-specifier"));
5116 if (
const Arg *PF = Args.getLastArg(options::OPT_mprintf_kind_EQ))
5119 if (Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl,
false)) {
5120 CmdArgs.push_back(
"-fsycl-is-device");
5122 if (Arg *A = Args.getLastArg(options::OPT_sycl_std_EQ)) {
5123 A->render(Args, CmdArgs);
5126 CmdArgs.push_back(
"-sycl-std=2020");
5130 if (IsOpenMPDevice) {
5132 std::string NormalizedTriple =
5136 CmdArgs.push_back(
"-aux-triple");
5137 CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
5140 if (Triple.isOSWindows() && (Triple.getArch() == llvm::Triple::arm ||
5141 Triple.getArch() == llvm::Triple::thumb)) {
5142 unsigned Offset = Triple.getArch() == llvm::Triple::arm ? 4 : 6;
5143 unsigned Version = 0;
5145 Triple.getArchName().substr(Offset).consumeInteger(10, Version);
5146 if (Failure || Version < 7)
5147 D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName()
5157 if (Triple.isSPIR() || Triple.isSPIRV())
5158 CmdArgs.push_back(
"-Wspir-compat");
5161 RewriteKind rewriteKind = RK_None;
5163 bool UnifiedLTO =
false;
5165 UnifiedLTO = Args.hasFlag(options::OPT_funified_lto,
5166 options::OPT_fno_unified_lto, Triple.isPS());
5168 CmdArgs.push_back(
"-funified-lto");
5178 if (!isa<AssembleJobAction>(JA)) {
5182 Args.ClaimAllArgs(options::OPT_mrelax_all);
5183 Args.ClaimAllArgs(options::OPT_mno_relax_all);
5184 Args.ClaimAllArgs(options::OPT_mincremental_linker_compatible);
5185 Args.ClaimAllArgs(options::OPT_mno_incremental_linker_compatible);
5186 switch (
C.getDefaultToolChain().getArch()) {
5187 case llvm::Triple::arm:
5188 case llvm::Triple::armeb:
5189 case llvm::Triple::thumb:
5190 case llvm::Triple::thumbeb:
5191 Args.ClaimAllArgs(options::OPT_mimplicit_it_EQ);
5197 Args.ClaimAllArgs(options::OPT_Wa_COMMA);
5198 Args.ClaimAllArgs(options::OPT_Xassembler);
5199 Args.ClaimAllArgs(options::OPT_femit_dwarf_unwind_EQ);
5202 if (isa<AnalyzeJobAction>(JA)) {
5203 assert(JA.
getType() == types::TY_Plist &&
"Invalid output type.");
5204 CmdArgs.push_back(
"-analyze");
5205 }
else if (isa<MigrateJobAction>(JA)) {
5206 CmdArgs.push_back(
"-migrate");
5207 }
else if (isa<PreprocessJobAction>(JA)) {
5208 if (Output.
getType() == types::TY_Dependencies)
5209 CmdArgs.push_back(
"-Eonly");
5211 CmdArgs.push_back(
"-E");
5212 if (Args.hasArg(options::OPT_rewrite_objc) &&
5213 !Args.hasArg(options::OPT_g_Group))
5214 CmdArgs.push_back(
"-P");
5215 else if (JA.
getType() == types::TY_PP_CXXHeaderUnit)
5216 CmdArgs.push_back(
"-fdirectives-only");
5218 }
else if (isa<AssembleJobAction>(JA)) {
5219 CmdArgs.push_back(
"-emit-obj");
5224 (void)Args.hasArg(options::OPT_force__cpusubtype__ALL);
5225 }
else if (isa<PrecompileJobAction>(JA)) {
5226 if (JA.
getType() == types::TY_Nothing)
5227 CmdArgs.push_back(
"-fsyntax-only");
5228 else if (JA.
getType() == types::TY_ModuleFile)
5229 CmdArgs.push_back(
"-emit-module-interface");
5230 else if (JA.
getType() == types::TY_HeaderUnit)
5231 CmdArgs.push_back(
"-emit-header-unit");
5233 CmdArgs.push_back(
"-emit-pch");
5234 }
else if (isa<VerifyPCHJobAction>(JA)) {
5235 CmdArgs.push_back(
"-verify-pch");
5236 }
else if (isa<ExtractAPIJobAction>(JA)) {
5237 assert(JA.
getType() == types::TY_API_INFO &&
5238 "Extract API actions must generate a API information.");
5239 CmdArgs.push_back(
"-extract-api");
5241 if (Arg *PrettySGFArg = Args.getLastArg(options::OPT_emit_pretty_sgf))
5242 PrettySGFArg->render(Args, CmdArgs);
5244 Arg *SymbolGraphDirArg = Args.getLastArg(options::OPT_symbol_graph_dir_EQ);
5246 if (Arg *ProductNameArg = Args.getLastArg(options::OPT_product_name_EQ))
5247 ProductNameArg->render(Args, CmdArgs);
5248 if (Arg *ExtractAPIIgnoresFileArg =
5249 Args.getLastArg(options::OPT_extract_api_ignores_EQ))
5250 ExtractAPIIgnoresFileArg->render(Args, CmdArgs);
5251 if (Arg *EmitExtensionSymbolGraphs =
5252 Args.getLastArg(options::OPT_emit_extension_symbol_graphs)) {
5253 if (!SymbolGraphDirArg)
5254 D.Diag(diag::err_drv_missing_symbol_graph_dir);
5256 EmitExtensionSymbolGraphs->render(Args, CmdArgs);
5258 if (SymbolGraphDirArg)
5259 SymbolGraphDirArg->render(Args, CmdArgs);
5261 assert((isa<CompileJobAction>(JA) || isa<BackendJobAction>(JA)) &&
5262 "Invalid action for clang tool.");
5263 if (JA.
getType() == types::TY_Nothing) {
5264 CmdArgs.push_back(
"-fsyntax-only");
5265 }
else if (JA.
getType() == types::TY_LLVM_IR ||
5266 JA.
getType() == types::TY_LTO_IR) {
5267 CmdArgs.push_back(
"-emit-llvm");
5268 }
else if (JA.
getType() == types::TY_LLVM_BC ||
5269 JA.
getType() == types::TY_LTO_BC) {
5271 if (Triple.isAMDGCN() && IsOpenMPDevice && Args.hasArg(options::OPT_S) &&
5272 Args.hasArg(options::OPT_emit_llvm)) {
5273 CmdArgs.push_back(
"-emit-llvm");
5275 CmdArgs.push_back(
"-emit-llvm-bc");
5277 }
else if (JA.
getType() == types::TY_IFS ||
5278 JA.
getType() == types::TY_IFS_CPP) {
5280 Args.hasArg(options::OPT_interface_stub_version_EQ)
5281 ? Args.getLastArgValue(options::OPT_interface_stub_version_EQ)
5283 CmdArgs.push_back(
"-emit-interface-stubs");
5285 Args.MakeArgString(Twine(
"-interface-stub-version=") + ArgStr.str()));
5286 }
else if (JA.
getType() == types::TY_PP_Asm) {
5287 CmdArgs.push_back(
"-S");
5288 }
else if (JA.
getType() == types::TY_AST) {
5289 CmdArgs.push_back(
"-emit-pch");
5290 }
else if (JA.
getType() == types::TY_ModuleFile) {
5291 CmdArgs.push_back(
"-module-file-info");
5292 }
else if (JA.
getType() == types::TY_RewrittenObjC) {
5293 CmdArgs.push_back(
"-rewrite-objc");
5294 rewriteKind = RK_NonFragile;
5295 }
else if (JA.
getType() == types::TY_RewrittenLegacyObjC) {
5296 CmdArgs.push_back(
"-rewrite-objc");
5297 rewriteKind = RK_Fragile;
5299 assert(JA.
getType() == types::TY_PP_Asm &&
"Unexpected output type!");
5306 if (JA.
getType() == types::TY_LLVM_BC)
5307 CmdArgs.push_back(
"-emit-llvm-uselists");
5311 !Args.hasFlag(options::OPT_offload_new_driver,
5312 options::OPT_no_offload_new_driver,
false) &&
5313 !Triple.isAMDGPU()) {
5314 D.Diag(diag::err_drv_unsupported_opt_for_target)
5315 << Args.getLastArg(options::OPT_foffload_lto,
5316 options::OPT_foffload_lto_EQ)
5318 << Triple.getTriple();
5319 }
else if (Triple.isNVPTX() && !IsRDCMode &&
5321 D.Diag(diag::err_drv_unsupported_opt_for_language_mode)
5322 << Args.getLastArg(options::OPT_foffload_lto,
5323 options::OPT_foffload_lto_EQ)
5328 CmdArgs.push_back(Args.MakeArgString(
5329 Twine(
"-flto=") + (LTOMode ==
LTOK_Thin ?
"thin" :
"full")));
5332 if (!RawTriple.isPS4() ||
5333 (
D.getLTOMode() ==
LTOK_Full) || !UnifiedLTO)
5334 CmdArgs.push_back(
"-flto-unit");
5339 Args.AddLastArg(CmdArgs, options::OPT_dumpdir);
5341 if (
const Arg *A = Args.getLastArg(options::OPT_fthinlto_index_EQ)) {
5343 D.Diag(diag::err_drv_arg_requires_bitcode_input) << A->getAsString(Args);
5344 Args.AddLastArg(CmdArgs, options::OPT_fthinlto_index_EQ);
5348 Args.addOptInFlag(CmdArgs, options::OPT_mregnames,
5349 options::OPT_mno_regnames);
5351 if (Args.getLastArg(options::OPT_fthin_link_bitcode_EQ))
5352 Args.AddLastArg(CmdArgs, options::OPT_fthin_link_bitcode_EQ);
5354 if (Args.getLastArg(options::OPT_save_temps_EQ))
5355 Args.AddLastArg(CmdArgs, options::OPT_save_temps_EQ);
5357 auto *MemProfArg = Args.getLastArg(options::OPT_fmemory_profile,
5358 options::OPT_fmemory_profile_EQ,
5359 options::OPT_fno_memory_profile);
5361 !MemProfArg->getOption().matches(options::OPT_fno_memory_profile))
5362 MemProfArg->render(Args, CmdArgs);
5364 if (
auto *MemProfUseArg =
5365 Args.getLastArg(options::OPT_fmemory_profile_use_EQ)) {
5367 D.Diag(diag::err_drv_argument_not_allowed_with)
5368 << MemProfUseArg->getAsString(Args) << MemProfArg->getAsString(Args);
5369 if (
auto *PGOInstrArg = Args.getLastArg(options::OPT_fprofile_generate,
5370 options::OPT_fprofile_generate_EQ))
5371 D.Diag(diag::err_drv_argument_not_allowed_with)
5372 << MemProfUseArg->getAsString(Args) << PGOInstrArg->getAsString(Args);
5373 MemProfUseArg->render(Args, CmdArgs);
5378 if (
C.getDriver().embedBitcodeInObject() && !IsUsingLTO &&
5379 (isa<BackendJobAction>(JA) || isa<AssembleJobAction>(JA))) {
5381 Args.AddLastArg(CmdArgs, options::OPT_fembed_bitcode_EQ);
5383 CmdArgs.push_back(
"-disable-llvm-passes");
5390 static const constexpr unsigned kBitcodeOptionIgnorelist[] = {
5391 options::OPT_mkernel,
5392 options::OPT_fapple_kext,
5393 options::OPT_ffunction_sections,
5394 options::OPT_fno_function_sections,
5395 options::OPT_fdata_sections,
5396 options::OPT_fno_data_sections,
5397 options::OPT_fbasic_block_sections_EQ,
5398 options::OPT_funique_internal_linkage_names,
5399 options::OPT_fno_unique_internal_linkage_names,
5400 options::OPT_funique_section_names,
5401 options::OPT_fno_unique_section_names,
5402 options::OPT_funique_basic_block_section_names,
5403 options::OPT_fno_unique_basic_block_section_names,
5404 options::OPT_mrestrict_it,
5405 options::OPT_mno_restrict_it,
5406 options::OPT_mstackrealign,
5407 options::OPT_mno_stackrealign,
5408 options::OPT_mstack_alignment,
5409 options::OPT_mcmodel_EQ,
5410 options::OPT_mlong_calls,
5411 options::OPT_mno_long_calls,
5412 options::OPT_ggnu_pubnames,
5413 options::OPT_gdwarf_aranges,
5414 options::OPT_fdebug_types_section,
5415 options::OPT_fno_debug_types_section,
5416 options::OPT_fdwarf_directory_asm,
5417 options::OPT_fno_dwarf_directory_asm,
5418 options::OPT_mrelax_all,
5419 options::OPT_mno_relax_all,
5420 options::OPT_ftrap_function_EQ,
5421 options::OPT_ffixed_r9,
5422 options::OPT_mfix_cortex_a53_835769,
5423 options::OPT_mno_fix_cortex_a53_835769,
5424 options::OPT_ffixed_x18,
5425 options::OPT_mglobal_merge,
5426 options::OPT_mno_global_merge,
5427 options::OPT_mred_zone,
5428 options::OPT_mno_red_zone,
5429 options::OPT_Wa_COMMA,
5430 options::OPT_Xassembler,
5433 for (
const auto &A : Args)
5434 if (llvm::is_contained(kBitcodeOptionIgnorelist, A->getOption().getID()))
5435 D.Diag(diag::err_drv_unsupported_embed_bitcode) << A->getSpelling();
5438 Args.addOptOutFlag(CmdArgs, options::OPT_foptimize_sibling_calls,
5439 options::OPT_fno_optimize_sibling_calls);
5447 case llvm::Triple::arm:
5448 case llvm::Triple::armeb:
5449 case llvm::Triple::thumbeb:
5450 RenderARMABI(
D, Triple, Args, CmdArgs);
5452 case llvm::Triple::aarch64:
5453 case llvm::Triple::aarch64_32:
5454 case llvm::Triple::aarch64_be:
5455 RenderAArch64ABI(Triple, Args, CmdArgs);
5460 if (
const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
5461 if (A->getOption().matches(options::OPT_O4)) {
5462 CmdArgs.push_back(
"-O3");
5463 D.Diag(diag::warn_O4_is_O3);
5465 A->render(Args, CmdArgs);
5470 if (Output.
getType() == types::TY_Dependencies) {
5473 CmdArgs.push_back(
"-o");
5476 assert(Output.
isNothing() &&
"Input output.");
5479 for (
const auto &II : Inputs) {
5481 if (II.isFilename())
5482 CmdArgs.push_back(II.getFilename());
5484 II.getInputArg().renderAsInput(Args, CmdArgs);
5487 C.addCommand(std::make_unique<Command>(
5489 CmdArgs, Inputs, Output,
D.getPrependArg()));
5493 if (
C.getDriver().embedBitcodeMarkerOnly() && !IsUsingLTO)
5494 CmdArgs.push_back(
"-fembed-bitcode=marker");
5499 if (!
C.isForDiagnostics())
5500 CmdArgs.push_back(
"-disable-free");
5501 CmdArgs.push_back(
"-clear-ast-before-backend");
5504 const bool IsAssertBuild =
false;
5506 const bool IsAssertBuild =
true;
5510 if (Args.hasFlag(options::OPT_fno_verify_intermediate_code,
5511 options::OPT_fverify_intermediate_code, !IsAssertBuild)) {
5512 CmdArgs.push_back(
"-disable-llvm-verifier");
5516 if (Args.hasFlag(options::OPT_fdiscard_value_names,
5517 options::OPT_fno_discard_value_names, !IsAssertBuild)) {
5518 if (Args.hasArg(options::OPT_fdiscard_value_names) &&
5520 return types::isLLVMIR(II.getType());
5522 D.Diag(diag::warn_ignoring_fdiscard_for_bitcode);
5524 CmdArgs.push_back(
"-discard-value-names");
5529 CmdArgs.push_back(
"-main-file-name");
5534 if (Args.hasArg(options::OPT_static))
5535 CmdArgs.push_back(
"-static-define");
5537 if (Args.hasArg(options::OPT_municode))
5538 CmdArgs.push_back(
"-DUNICODE");
5540 if (isa<AnalyzeJobAction>(JA))
5543 if (isa<AnalyzeJobAction>(JA) ||
5544 (isa<PreprocessJobAction>(JA) && Args.hasArg(options::OPT__analyze)))
5545 CmdArgs.push_back(
"-setup-static-analyzer");
5550 bool FoundAnalyzerConfig =
false;
5551 for (
auto *Arg : Args.filtered(options::OPT_Xclang))
5552 if (StringRef(Arg->getValue()) ==
"-analyzer-config") {
5553 FoundAnalyzerConfig =
true;
5556 if (!FoundAnalyzerConfig)
5557 for (
auto *Arg : Args.filtered(options::OPT_Xanalyzer))
5558 if (StringRef(Arg->getValue()) ==
"-analyzer-config") {
5559 FoundAnalyzerConfig =
true;
5562 if (FoundAnalyzerConfig)
5563 CmdArgs.push_back(
"-analyzer-config-compatibility-mode=true");
5568 assert(FunctionAlignment <= 31 &&
"function alignment will be truncated!");
5569 if (FunctionAlignment) {
5570 CmdArgs.push_back(
"-function-alignment");
5571 CmdArgs.push_back(Args.MakeArgString(std::to_string(FunctionAlignment)));
5576 if (
const Arg *A = Args.getLastArg(options::OPT_falign_loops_EQ)) {
5578 if (StringRef(A->getValue()).getAsInteger(10,
Value) ||
Value > 65536)
5580 << A->getAsString(Args) << A->getValue();
5582 TC.
getDriver().
Diag(diag::err_drv_alignment_not_power_of_two)
5583 << A->getAsString(Args) << A->getValue();
5586 CmdArgs.push_back(Args.MakeArgString(
"-falign-loops=" +
5587 Twine(std::min(
Value, 65536u))));
5590 if (Triple.isOSzOS()) {
5599 auto findMacroDefinition = [&](
const std::string &Macro) {
5600 auto MacroDefs = Args.getAllArgValues(options::OPT_D);
5601 return llvm::any_of(MacroDefs, [&](
const std::string &M) {
5602 return M == Macro || M.find(Macro +
'=') != std::string::npos;
5607 if (!findMacroDefinition(
"_UNIX03_WITHDRAWN"))
5608 CmdArgs.push_back(
"-D_UNIX03_WITHDRAWN");
5610 if (!findMacroDefinition(
"_OPEN_DEFAULT"))
5611 CmdArgs.push_back(
"-D_OPEN_DEFAULT");
5614 if (!findMacroDefinition(
"_XOPEN_SOURCE"))
5615 CmdArgs.push_back(
"-D_XOPEN_SOURCE=600");
5619 llvm::Reloc::Model RelocationModel;
5622 std::tie(RelocationModel, PICLevel, IsPIE) =
ParsePICArgs(TC, Args);
5623 Arg *LastPICDataRelArg =
5624 Args.getLastArg(options::OPT_mno_pic_data_is_text_relative,
5625 options::OPT_mpic_data_is_text_relative);
5626 bool NoPICDataIsTextRelative =
false;
5627 if (LastPICDataRelArg) {
5628 if (LastPICDataRelArg->getOption().matches(
5629 options::OPT_mno_pic_data_is_text_relative)) {
5630 NoPICDataIsTextRelative =
true;
5632 D.Diag(diag::err_drv_argument_only_allowed_with)
5633 <<
"-mno-pic-data-is-text-relative"
5636 if (!Triple.isSystemZ())
5637 D.Diag(diag::err_drv_unsupported_opt_for_target)
5638 << (NoPICDataIsTextRelative ?
"-mno-pic-data-is-text-relative"
5639 :
"-mpic-data-is-text-relative")
5643 bool IsROPI = RelocationModel == llvm::Reloc::ROPI ||
5644 RelocationModel == llvm::Reloc::ROPI_RWPI;
5645 bool IsRWPI = RelocationModel == llvm::Reloc::RWPI ||
5646 RelocationModel == llvm::Reloc::ROPI_RWPI;
5648 if (Args.hasArg(options::OPT_mcmse) &&
5649 !Args.hasArg(options::OPT_fallow_unsupported)) {
5651 D.Diag(diag::err_cmse_pi_are_incompatible) << IsROPI;
5653 D.Diag(diag::err_cmse_pi_are_incompatible) << !IsRWPI;
5657 !Args.hasArg(options::OPT_fallow_unsupported))
5658 D.Diag(diag::err_drv_ropi_incompatible_with_cxx);
5662 CmdArgs.push_back(
"-mrelocation-model");
5663 CmdArgs.push_back(RMName);
5666 CmdArgs.push_back(
"-pic-level");
5667 CmdArgs.push_back(PICLevel == 1 ?
"1" :
"2");
5669 CmdArgs.push_back(
"-pic-is-pie");
5670 if (NoPICDataIsTextRelative)
5671 CmdArgs.push_back(
"-mcmodel=medium");
5674 if (RelocationModel == llvm::Reloc::ROPI ||
5675 RelocationModel == llvm::Reloc::ROPI_RWPI)
5676 CmdArgs.push_back(
"-fropi");
5677 if (RelocationModel == llvm::Reloc::RWPI ||
5678 RelocationModel == llvm::Reloc::ROPI_RWPI)
5679 CmdArgs.push_back(
"-frwpi");
5681 if (Arg *A = Args.getLastArg(options::OPT_meabi)) {
5682 CmdArgs.push_back(
"-meabi");
5683 CmdArgs.push_back(A->getValue());
5697 if (Triple.isOSBinFormatELF()) {
5698 Arg *A = Args.getLastArg(options::OPT_fsemantic_interposition,
5699 options::OPT_fno_semantic_interposition);
5700 if (RelocationModel != llvm::Reloc::Static && !IsPIE) {
5702 bool SupportsLocalAlias =
5703 Triple.isAArch64() || Triple.isRISCV() || Triple.isX86();
5705 CmdArgs.push_back(
"-fhalf-no-semantic-interposition");
5706 else if (A->getOption().matches(options::OPT_fsemantic_interposition))
5707 A->render(Args, CmdArgs);
5708 else if (!SupportsLocalAlias)
5709 CmdArgs.push_back(
"-fhalf-no-semantic-interposition");
5715 if (Arg *A = Args.getLastArg(options::OPT_mthread_model)) {
5717 D.Diag(diag::err_drv_invalid_thread_model_for_target)
5718 << A->getValue() << A->getAsString(Args);
5719 Model = A->getValue();
5722 if (Model !=
"posix") {
5723 CmdArgs.push_back(
"-mthread-model");
5724 CmdArgs.push_back(Args.MakeArgString(Model));
5728 if (Arg *A = Args.getLastArg(options::OPT_fveclib)) {
5729 StringRef Name = A->getValue();
5730 if (Name ==
"SVML") {
5731 if (Triple.getArch() != llvm::Triple::x86 &&
5732 Triple.getArch() != llvm::Triple::x86_64)
5733 D.Diag(diag::err_drv_unsupported_opt_for_target)
5734 << Name << Triple.getArchName();
5735 }
else if (Name ==
"LIBMVEC-X86") {
5736 if (Triple.getArch() != llvm::Triple::x86 &&
5737 Triple.getArch() != llvm::Triple::x86_64)
5738 D.Diag(diag::err_drv_unsupported_opt_for_target)
5739 << Name << Triple.getArchName();
5740 }
else if (Name ==
"SLEEF" || Name ==
"ArmPL") {
5741 if (Triple.getArch() != llvm::Triple::aarch64 &&
5742 Triple.getArch() != llvm::Triple::aarch64_be)
5743 D.Diag(diag::err_drv_unsupported_opt_for_target)
5744 << Name << Triple.getArchName();
5746 A->render(Args, CmdArgs);
5749 if (Args.hasFlag(options::OPT_fmerge_all_constants,
5750 options::OPT_fno_merge_all_constants,
false))
5751 CmdArgs.push_back(
"-fmerge-all-constants");
5753 Args.addOptOutFlag(CmdArgs, options::OPT_fdelete_null_pointer_checks,
5754 options::OPT_fno_delete_null_pointer_checks);
5758 if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ_quadword_atomics)) {
5759 if (!Triple.isOSAIX() || Triple.isPPC32())
5760 D.Diag(diag::err_drv_unsupported_opt_for_target)
5761 << A->getSpelling() << RawTriple.str();
5762 CmdArgs.push_back(
"-mabi=quadword-atomics");
5765 if (Arg *A = Args.getLastArg(options::OPT_mlong_double_128)) {
5768 if (Triple.isOSAIX())
5769 D.Diag(diag::err_drv_unsupported_opt_for_target)
5770 << A->getSpelling() << RawTriple.str();
5773 if (Arg *A = Args.getLastArg(options::OPT_Wframe_larger_than_EQ)) {
5774 StringRef
V = A->getValue(), V1 =
V;
5776 if (V1.consumeInteger(10, Size) || !V1.empty())
5777 D.Diag(diag::err_drv_invalid_argument_to_option)
5778 <<
V << A->getOption().getName();
5780 CmdArgs.push_back(Args.MakeArgString(
"-fwarn-stack-size=" +
V));
5783 Args.addOptOutFlag(CmdArgs, options::OPT_fjump_tables,
5784 options::OPT_fno_jump_tables);
5785 Args.addOptInFlag(CmdArgs, options::OPT_fprofile_sample_accurate,
5786 options::OPT_fno_profile_sample_accurate);
5787 Args.addOptOutFlag(CmdArgs, options::OPT_fpreserve_as_comments,
5788 options::OPT_fno_preserve_as_comments);
5790 if (Arg *A = Args.getLastArg(options::OPT_mregparm_EQ)) {
5791 CmdArgs.push_back(
"-mregparm");
5792 CmdArgs.push_back(A->getValue());
5795 if (Arg *A = Args.getLastArg(options::OPT_maix_struct_return,
5796 options::OPT_msvr4_struct_return)) {
5798 D.Diag(diag::err_drv_unsupported_opt_for_target)
5799 << A->getSpelling() << RawTriple.str();
5800 }
else if (A->getOption().matches(options::OPT_maix_struct_return)) {
5801 CmdArgs.push_back(
"-maix-struct-return");
5803 assert(A->getOption().matches(options::OPT_msvr4_struct_return));
5804 CmdArgs.push_back(
"-msvr4-struct-return");
5808 if (Arg *A = Args.getLastArg(options::OPT_fpcc_struct_return,
5809 options::OPT_freg_struct_return)) {
5810 if (TC.
getArch() != llvm::Triple::x86) {
5811 D.Diag(diag::err_drv_unsupported_opt_for_target)
5812 << A->getSpelling() << RawTriple.str();
5813 }
else if (A->getOption().matches(options::OPT_fpcc_struct_return)) {
5814 CmdArgs.push_back(
"-fpcc-struct-return");
5816 assert(A->getOption().matches(options::OPT_freg_struct_return));
5817 CmdArgs.push_back(
"-freg-struct-return");
5821 if (Args.hasFlag(options::OPT_mrtd, options::OPT_mno_rtd,
false)) {
5822 if (Triple.getArch() == llvm::Triple::m68k)
5823 CmdArgs.push_back(
"-fdefault-calling-conv=rtdcall");
5825 CmdArgs.push_back(
"-fdefault-calling-conv=stdcall");
5828 if (Args.hasArg(options::OPT_fenable_matrix)) {
5830 CmdArgs.push_back(
"-fenable-matrix");
5831 CmdArgs.push_back(
"-mllvm");
5832 CmdArgs.push_back(
"-enable-matrix");
5837 const char *FPKeepKindStr =
nullptr;
5838 switch (FPKeepKind) {
5840 FPKeepKindStr =
"-mframe-pointer=none";
5843 FPKeepKindStr =
"-mframe-pointer=reserved";
5846 FPKeepKindStr =
"-mframe-pointer=non-leaf";
5849 FPKeepKindStr =
"-mframe-pointer=all";
5852 assert(FPKeepKindStr &&
"unknown FramePointerKind");
5853 CmdArgs.push_back(FPKeepKindStr);
5855 Args.addOptOutFlag(CmdArgs, options::OPT_fzero_initialized_in_bss,
5856 options::OPT_fno_zero_initialized_in_bss);
5860 D.Diag(diag::warn_drv_deprecated_arg_ofast);
5863 OptSpecifier StrictAliasingAliasOption =
5864 OFastEnabled ? options::OPT_Ofast : options::OPT_fstrict_aliasing;
5867 if (!Args.hasFlag(options::OPT_fstrict_aliasing, StrictAliasingAliasOption,
5868 options::OPT_fno_strict_aliasing, !IsWindowsMSVC))
5869 CmdArgs.push_back(
"-relaxed-aliasing");
5870 if (Args.hasFlag(options::OPT_fpointer_tbaa, options::OPT_fno_pointer_tbaa,
5872 CmdArgs.push_back(
"-pointer-tbaa");
5873 if (!Args.hasFlag(options::OPT_fstruct_path_tbaa,
5874 options::OPT_fno_struct_path_tbaa,
true))
5875 CmdArgs.push_back(
"-no-struct-path-tbaa");
5876 Args.addOptInFlag(CmdArgs, options::OPT_fstrict_enums,
5877 options::OPT_fno_strict_enums);
5878 Args.addOptOutFlag(CmdArgs, options::OPT_fstrict_return,
5879 options::OPT_fno_strict_return);
5880 Args.addOptInFlag(CmdArgs, options::OPT_fallow_editor_placeholders,
5881 options::OPT_fno_allow_editor_placeholders);
5882 Args.addOptInFlag(CmdArgs, options::OPT_fstrict_vtable_pointers,
5883 options::OPT_fno_strict_vtable_pointers);
5884 Args.addOptInFlag(CmdArgs, options::OPT_fforce_emit_vtables,
5885 options::OPT_fno_force_emit_vtables);
5886 Args.addOptOutFlag(CmdArgs, options::OPT_foptimize_sibling_calls,
5887 options::OPT_fno_optimize_sibling_calls);
5888 Args.addOptOutFlag(CmdArgs, options::OPT_fescaping_block_tail_calls,
5889 options::OPT_fno_escaping_block_tail_calls);
5891 Args.AddLastArg(CmdArgs, options::OPT_ffine_grained_bitfield_accesses,
5892 options::OPT_fno_fine_grained_bitfield_accesses);
5894 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_relative_cxx_abi_vtables,
5895 options::OPT_fno_experimental_relative_cxx_abi_vtables);
5897 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_omit_vtable_rtti,
5898 options::OPT_fno_experimental_omit_vtable_rtti);
5900 Args.AddLastArg(CmdArgs, options::OPT_fdisable_block_signature_string,
5901 options::OPT_fno_disable_block_signature_string);
5904 Args.addOptInFlag(CmdArgs, options::OPT_fsplit_stack,
5905 options::OPT_fno_split_stack);
5908 if (Args.hasFlag(options::OPT_fprotect_parens,
5909 options::OPT_fno_protect_parens,
false))
5910 CmdArgs.push_back(
"-fprotect-parens");
5914 if (Arg *A = Args.getLastArg(options::OPT_fextend_args_EQ)) {
5915 const llvm::Triple::ArchType Arch = TC.
getArch();
5916 if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) {
5917 StringRef
V = A->getValue();
5919 CmdArgs.push_back(
"-fextend-arguments=64");
5921 D.Diag(diag::err_drv_invalid_argument_to_option)
5922 << A->getValue() << A->getOption().getName();
5924 D.Diag(diag::err_drv_unsupported_opt_for_target)
5925 << A->getOption().getName() << TripleStr;
5928 if (Arg *A = Args.getLastArg(options::OPT_mdouble_EQ)) {
5929 if (TC.
getArch() == llvm::Triple::avr)
5930 A->render(Args, CmdArgs);
5932 D.Diag(diag::err_drv_unsupported_opt_for_target)
5933 << A->getAsString(Args) << TripleStr;
5936 if (Arg *A = Args.getLastArg(options::OPT_LongDouble_Group)) {
5938 A->render(Args, CmdArgs);
5940 (A->getOption().getID() != options::OPT_mlong_double_80))
5941 A->render(Args, CmdArgs);
5943 D.Diag(diag::err_drv_unsupported_opt_for_target)
5944 << A->getAsString(Args) << TripleStr;
5950 if (!Args.hasFlag(options::OPT_fverbose_asm, options::OPT_fno_verbose_asm,
5951 IsIntegratedAssemblerDefault))
5952 CmdArgs.push_back(
"-fno-verbose-asm");
5956 if (Arg *A = Args.getLastArg(options::OPT_fbinutils_version_EQ)) {
5957 StringRef
V = A->getValue();
5960 A->render(Args, CmdArgs);
5961 else if (!
V.consumeInteger(10, Num) && Num > 0 &&
5962 (
V.empty() || (
V.consume_front(
".") &&
5963 !
V.consumeInteger(10, Num) &&
V.empty())))
5964 A->render(Args, CmdArgs);
5966 D.Diag(diag::err_drv_invalid_argument_to_option)
5967 << A->getValue() << A->getOption().getName();
5973 CmdArgs.push_back(
"-no-integrated-as");
5975 if (Args.hasArg(options::OPT_fdebug_pass_structure)) {
5976 CmdArgs.push_back(
"-mdebug-pass");
5977 CmdArgs.push_back(
"Structure");
5979 if (Args.hasArg(options::OPT_fdebug_pass_arguments)) {
5980 CmdArgs.push_back(
"-mdebug-pass");
5981 CmdArgs.push_back(
"Arguments");
5987 if (!RawTriple.isOSDarwin() && !RawTriple.isNVPTX())
5988 CmdArgs.push_back(
"-mconstructor-aliases");
5992 if (KernelOrKext && RawTriple.isOSDarwin())
5993 CmdArgs.push_back(
"-fforbid-guard-variables");
5995 if (Args.hasFlag(options::OPT_mms_bitfields, options::OPT_mno_ms_bitfields,
5996 Triple.isWindowsGNUEnvironment())) {
5997 CmdArgs.push_back(
"-mms-bitfields");
6000 if (Triple.isWindowsGNUEnvironment()) {
6001 Args.addOptOutFlag(CmdArgs, options::OPT_fauto_import,
6002 options::OPT_fno_auto_import);
6005 if (Args.hasFlag(options::OPT_fms_volatile, options::OPT_fno_ms_volatile,
6006 Triple.isX86() &&
D.IsCLMode()))
6007 CmdArgs.push_back(
"-fms-volatile");
6012 if (Arg *A = Args.getLastArg(options::OPT_fdirect_access_external_data,
6013 options::OPT_fno_direct_access_external_data)) {
6014 if (A->getOption().matches(options::OPT_fdirect_access_external_data) !=
6016 A->render(Args, CmdArgs);
6017 }
else if (PICLevel == 0 && Triple.isLoongArch()) {
6020 CmdArgs.push_back(
"-fno-direct-access-external-data");
6023 if (Args.hasFlag(options::OPT_fno_plt, options::OPT_fplt,
false)) {
6024 CmdArgs.push_back(
"-fno-plt");
6031 Args.hasFlag(options::OPT_ffreestanding, options::OPT_fhosted,
false) ||
6034 CmdArgs.push_back(
"-ffreestanding");
6036 Args.AddLastArg(CmdArgs, options::OPT_fno_knr_functions);
6043 bool IsAsyncUnwindTablesDefault =
6045 bool IsSyncUnwindTablesDefault =
6048 bool AsyncUnwindTables = Args.hasFlag(
6049 options::OPT_fasynchronous_unwind_tables,
6050 options::OPT_fno_asynchronous_unwind_tables,
6051 (IsAsyncUnwindTablesDefault || SanitizeArgs.needsUnwindTables()) &&
6054 Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables,
6055 IsSyncUnwindTablesDefault && !Freestanding);
6056 if (AsyncUnwindTables)
6057 CmdArgs.push_back(
"-funwind-tables=2");
6058 else if (UnwindTables)
6059 CmdArgs.push_back(
"-funwind-tables=1");
6063 if (!Args.getLastArg(options::OPT_gpu_use_aux_triple_only) &&
6064 (IsCudaDevice || IsHIPDevice)) {
6065 const ArgList &HostArgs =
6067 std::string HostCPU =
6069 if (!HostCPU.empty()) {
6070 CmdArgs.push_back(
"-aux-target-cpu");
6071 CmdArgs.push_back(Args.MakeArgString(HostCPU));
6079 addMCModel(
D, Args, Triple, RelocationModel, CmdArgs);
6081 if (Arg *A = Args.getLastArg(options::OPT_mtls_size_EQ)) {
6082 StringRef
Value = A->getValue();
6083 unsigned TLSSize = 0;
6084 Value.getAsInteger(10, TLSSize);
6085 if (!Triple.isAArch64() || !Triple.isOSBinFormatELF())
6086 D.Diag(diag::err_drv_unsupported_opt_for_target)
6087 << A->getOption().getName() << TripleStr;
6088 if (TLSSize != 12 && TLSSize != 24 && TLSSize != 32 && TLSSize != 48)
6089 D.Diag(diag::err_drv_invalid_int_value)
6090 << A->getOption().getName() <<
Value;
6091 Args.AddLastArg(CmdArgs, options::OPT_mtls_size_EQ);
6095 CmdArgs.push_back(
"-enable-tlsdesc");
6098 std::string CPU =
getCPUName(
D, Args, Triple,
false);
6100 CmdArgs.push_back(
"-target-cpu");
6101 CmdArgs.push_back(Args.MakeArgString(CPU));
6104 RenderTargetOptions(Triple, Args, KernelOrKext, CmdArgs);
6109 AddClangCLArgs(Args, InputType, CmdArgs);
6111 llvm::codegenoptions::DebugInfoKind DebugInfoKind =
6112 llvm::codegenoptions::NoDebugInfo;
6115 CmdArgs, Output, DebugInfoKind, DwarfFission);
6123 (isa<AssembleJobAction>(JA) || isa<CompileJobAction>(JA) ||
6124 isa<BackendJobAction>(JA));
6126 const char *SplitDWARFOut =
SplitDebugName(JA, Args, Input, Output);
6127 CmdArgs.push_back(
"-split-dwarf-file");
6128 CmdArgs.push_back(SplitDWARFOut);
6130 CmdArgs.push_back(
"-split-dwarf-output");
6131 CmdArgs.push_back(SplitDWARFOut);
6136 if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) {
6137 CmdArgs.push_back(
"-target-linker-version");
6138 CmdArgs.push_back(A->getValue());
6143 if (!Args.hasArg(options::OPT_fallow_unsupported)) {
6145 if (
types::isCXX(InputType) && RawTriple.isOSDarwin() &&
6146 TC.
getArch() == llvm::Triple::x86) {
6147 if ((Unsupported = Args.getLastArg(options::OPT_fapple_kext)) ||
6148 (Unsupported = Args.getLastArg(options::OPT_mkernel)))
6149 D.Diag(diag::err_drv_clang_unsupported_opt_cxx_darwin_i386)
6150 << Unsupported->getOption().getName();
6153 if ((Unsupported = Args.getLastArg(options::OPT_faltivec)))
6154 D.Diag(diag::err_drv_clang_unsupported_opt_faltivec)
6155 << Unsupported->getOption().getName()
6156 <<
"please use -maltivec and include altivec.h explicitly";
6157 if ((Unsupported = Args.getLastArg(options::OPT_fno_altivec)))
6158 D.Diag(diag::err_drv_clang_unsupported_opt_faltivec)
6159 << Unsupported->getOption().getName() <<
"please use -mno-altivec";
6162 Args.AddAllArgs(CmdArgs, options::OPT_v);
6164 if (Args.getLastArg(options::OPT_H)) {
6165 CmdArgs.push_back(
"-H");
6166 CmdArgs.push_back(
"-sys-header-deps");
6168 Args.AddAllArgs(CmdArgs, options::OPT_fshow_skipped_includes);
6170 if (
D.CCPrintHeadersFormat && !
D.CCGenDiagnostics) {
6171 CmdArgs.push_back(
"-header-include-file");
6172 CmdArgs.push_back(!
D.CCPrintHeadersFilename.empty()
6173 ?
D.CCPrintHeadersFilename.c_str()
6175 CmdArgs.push_back(
"-sys-header-deps");
6176 CmdArgs.push_back(Args.MakeArgString(
6177 "-header-include-format=" +
6180 Args.MakeArgString(
"-header-include-filtering=" +
6182 D.CCPrintHeadersFiltering))));
6184 Args.AddLastArg(CmdArgs, options::OPT_P);
6185 Args.AddLastArg(CmdArgs, options::OPT_print_ivar_layout);
6187 if (
D.CCLogDiagnostics && !
D.CCGenDiagnostics) {
6188 CmdArgs.push_back(
"-diagnostic-log-file");
6189 CmdArgs.push_back(!
D.CCLogDiagnosticsFilename.empty()
6190 ?
D.CCLogDiagnosticsFilename.c_str()
6196 if (
D.CCGenDiagnostics)
6197 CmdArgs.push_back(
"-disable-pragma-debug-crash");
6201 if (Args.hasArg(options::OPT_fcrash_diagnostics_dir)) {
6202 StringRef Dir = Args.getLastArgValue(options::OPT_fcrash_diagnostics_dir);
6203 CmdArgs.push_back(
"-mllvm");
6204 CmdArgs.push_back(Args.MakeArgString(
"-crash-diagnostics-dir=" + Dir));
6209 if (Args.hasFlag(options::OPT_ffunction_sections,
6210 options::OPT_fno_function_sections, UseSeparateSections)) {
6211 CmdArgs.push_back(
"-ffunction-sections");
6214 if (Arg *A = Args.getLastArg(options::OPT_fbasic_block_address_map,
6215 options::OPT_fno_basic_block_address_map)) {
6216 if ((Triple.isX86() || Triple.isAArch64()) && Triple.isOSBinFormatELF()) {
6217 if (A->getOption().matches(options::OPT_fbasic_block_address_map))
6218 A->render(Args, CmdArgs);
6220 D.Diag(diag::err_drv_unsupported_opt_for_target)
6221 << A->getAsString(Args) << TripleStr;
6225 if (Arg *A = Args.getLastArg(options::OPT_fbasic_block_sections_EQ)) {
6226 StringRef Val = A->getValue();
6227 if (Triple.isX86() && Triple.isOSBinFormatELF()) {
6228 if (Val !=
"all" && Val !=
"labels" && Val !=
"none" &&
6229 !Val.starts_with(
"list="))
6230 D.Diag(diag::err_drv_invalid_value)
6231 << A->getAsString(Args) << A->getValue();
6233 A->render(Args, CmdArgs);
6234 }
else if (Triple.isAArch64() && Triple.isOSBinFormatELF()) {
6237 if (Val !=
"labels" && Val !=
"none" && !Val.starts_with(
"list="))
6238 D.Diag(diag::err_drv_invalid_value)
6239 << A->getAsString(Args) << A->getValue();
6241 A->render(Args, CmdArgs);
6242 }
else if (Triple.isNVPTX()) {
6245 }
else if (Val !=
"none") {
6248 D.Diag(diag::err_drv_unsupported_opt_for_target)
6249 << A->getAsString(Args) << TripleStr;
6253 bool HasDefaultDataSections = Triple.isOSBinFormatXCOFF();
6254 if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
6255 UseSeparateSections || HasDefaultDataSections)) {
6256 CmdArgs.push_back(
"-fdata-sections");
6259 Args.addOptOutFlag(CmdArgs, options::OPT_funique_section_names,
6260 options::OPT_fno_unique_section_names);
6261 Args.addOptInFlag(CmdArgs, options::OPT_fseparate_named_sections,
6262 options::OPT_fno_separate_named_sections);
6263 Args.addOptInFlag(CmdArgs, options::OPT_funique_internal_linkage_names,
6264 options::OPT_fno_unique_internal_linkage_names);
6265 Args.addOptInFlag(CmdArgs, options::OPT_funique_basic_block_section_names,
6266 options::OPT_fno_unique_basic_block_section_names);
6267 Args.addOptInFlag(CmdArgs, options::OPT_fconvergent_functions,
6268 options::OPT_fno_convergent_functions);
6270 if (Arg *A = Args.getLastArg(options::OPT_fsplit_machine_functions,
6271 options::OPT_fno_split_machine_functions)) {
6272 if (!A->getOption().matches(options::OPT_fno_split_machine_functions)) {
6274 if ((Triple.isX86() || Triple.isAArch64()) && Triple.isOSBinFormatELF())
6275 A->render(Args, CmdArgs);
6277 D.Diag(diag::err_drv_unsupported_opt_for_target)
6278 << A->getAsString(Args) << TripleStr;
6282 Args.AddLastArg(CmdArgs, options::OPT_finstrument_functions,
6283 options::OPT_finstrument_functions_after_inlining,
6284 options::OPT_finstrument_function_entry_bare);
6289 if (!Triple.isNVPTX() && !Triple.isAMDGCN())
6292 Args.AddLastArg(CmdArgs, options::OPT_fclang_abi_compat_EQ);
6295 Args.hasArg(options::OPT_fsample_profile_use_profi)) {
6296 CmdArgs.push_back(
"-mllvm");
6297 CmdArgs.push_back(
"-sample-profile-use-profi");
6301 if (RawTriple.isPS() &&
6302 !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
6308 if (Args.hasArg(options::OPT_nostdinc)) {
6309 CmdArgs.push_back(
"-nostdsysteminc");
6310 CmdArgs.push_back(
"-nobuiltininc");
6312 if (Args.hasArg(options::OPT_nostdlibinc))
6313 CmdArgs.push_back(
"-nostdsysteminc");
6314 Args.AddLastArg(CmdArgs, options::OPT_nostdincxx);
6315 Args.AddLastArg(CmdArgs, options::OPT_nobuiltininc);
6319 CmdArgs.push_back(
"-resource-dir");
6320 CmdArgs.push_back(
D.ResourceDir.c_str());
6322 Args.AddLastArg(CmdArgs, options::OPT_working_directory);
6331 AddPreprocessingOptions(
C, JA,
D, Args, CmdArgs, Output, Inputs);
6337 Args.ClaimAllArgs(options::OPT_D);
6340 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
6341 if (A->getOption().matches(options::OPT_O4)) {
6342 CmdArgs.push_back(
"-O3");
6343 D.Diag(diag::warn_O4_is_O3);
6345 A->render(Args, CmdArgs);
6351 Args.filtered(options::OPT_clang_ignored_gcc_optimization_f_Group)) {
6352 D.Diag(diag::warn_ignored_gcc_optimization) << A->getAsString(Args);
6357 Args.filtered(options::OPT_clang_ignored_legacy_options_Group)) {
6358 D.Diag(diag::warn_ignored_clang_option) << A->getAsString(Args);
6364 Args.AddAllArgs(CmdArgs, options::OPT_R_Group);
6367 Args.filtered(options::OPT_W_Group, options::OPT__SLASH_wd)) {
6369 if (A->getOption().getID() == options::OPT__SLASH_wd) {
6370 unsigned WarningNumber;
6371 if (StringRef(A->getValue()).getAsInteger(10, WarningNumber)) {
6372 D.Diag(diag::err_drv_invalid_int_value)
6373 << A->getAsString(Args) << A->getValue();
6378 CmdArgs.push_back(Args.MakeArgString(
6383 A->render(Args, CmdArgs);
6386 Args.AddAllArgs(CmdArgs, options::OPT_Wsystem_headers_in_module_EQ);
6388 if (Args.hasFlag(options::OPT_pedantic, options::OPT_no_pedantic,
false))
6389 CmdArgs.push_back(
"-pedantic");
6390 Args.AddLastArg(CmdArgs, options::OPT_pedantic_errors);
6391 Args.AddLastArg(CmdArgs, options::OPT_w);
6393 Args.addOptInFlag(CmdArgs, options::OPT_ffixed_point,
6394 options::OPT_fno_fixed_point);
6396 if (Arg *A = Args.getLastArg(options::OPT_fcxx_abi_EQ))
6397 A->render(Args, CmdArgs);
6399 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_relative_cxx_abi_vtables,
6400 options::OPT_fno_experimental_relative_cxx_abi_vtables);
6402 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_omit_vtable_rtti,
6403 options::OPT_fno_experimental_omit_vtable_rtti);
6405 if (Arg *A = Args.getLastArg(options::OPT_ffuchsia_api_level_EQ))
6406 A->render(Args, CmdArgs);
6413 bool ImplyVCPPCVer =
false;
6414 bool ImplyVCPPCXXVer =
false;
6415 const Arg *
Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi);
6417 if (
Std->getOption().matches(options::OPT_ansi))
6419 CmdArgs.push_back(
"-std=c++98");
6421 CmdArgs.push_back(
"-std=c89");
6423 Std->render(Args, CmdArgs);
6426 if (Arg *A = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi,
6427 options::OPT_ftrigraphs,
6428 options::OPT_fno_trigraphs))
6430 A->render(Args, CmdArgs);
6439 if (!Args.hasArg(options::OPT__SLASH_std)) {
6440 Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ,
"-std=",
6443 ImplyVCPPCVer =
true;
6445 else if (IsWindowsMSVC)
6446 ImplyVCPPCXXVer =
true;
6448 Args.AddLastArg(CmdArgs, options::OPT_ftrigraphs,
6449 options::OPT_fno_trigraphs);
6465 Args.getLastArg(options::OPT_Wwrite_strings,
6466 options::OPT_Wno_write_strings, options::OPT_w);
6468 WriteStrings->getOption().matches(options::OPT_Wwrite_strings))
6469 CmdArgs.push_back(
"-fconst-strings");
6476 Args.hasFlag(options::OPT_Wdeprecated, options::OPT_Wno_deprecated,
6478 CmdArgs.push_back(
"-fdeprecated-macro");
6482 if (Arg *
Asm = Args.getLastArg(options::OPT_fasm, options::OPT_fno_asm)) {
6483 if (
Asm->getOption().matches(options::OPT_fasm))
6484 CmdArgs.push_back(
"-fgnu-keywords");
6486 CmdArgs.push_back(
"-fno-gnu-keywords");
6490 CmdArgs.push_back(
"-fno-autolink");
6492 Args.AddLastArg(CmdArgs, options::OPT_ftemplate_depth_EQ);
6493 Args.AddLastArg(CmdArgs, options::OPT_foperator_arrow_depth_EQ);
6494 Args.AddLastArg(CmdArgs, options::OPT_fconstexpr_depth_EQ);
6495 Args.AddLastArg(CmdArgs, options::OPT_fconstexpr_steps_EQ);
6497 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_library);
6499 if (Args.hasArg(options::OPT_fexperimental_new_constant_interpreter))
6500 CmdArgs.push_back(
"-fexperimental-new-constant-interpreter");
6502 if (Arg *A = Args.getLastArg(options::OPT_fbracket_depth_EQ)) {
6503 CmdArgs.push_back(
"-fbracket-depth");
6504 CmdArgs.push_back(A->getValue());
6507 if (Arg *A = Args.getLastArg(options::OPT_Wlarge_by_value_copy_EQ,
6508 options::OPT_Wlarge_by_value_copy_def)) {
6509 if (A->getNumValues()) {
6510 StringRef
bytes = A->getValue();
6511 CmdArgs.push_back(Args.MakeArgString(
"-Wlarge-by-value-copy=" +
bytes));
6513 CmdArgs.push_back(
"-Wlarge-by-value-copy=64");
6516 if (Args.hasArg(options::OPT_relocatable_pch))
6517 CmdArgs.push_back(
"-relocatable-pch");
6519 if (
const Arg *A = Args.getLastArg(options::OPT_fcf_runtime_abi_EQ)) {
6520 static const char *kCFABIs[] = {
6521 "standalone",
"objc",
"swift",
"swift-5.0",
"swift-4.2",
"swift-4.1",
6524 if (!llvm::is_contained(kCFABIs, StringRef(A->getValue())))
6525 D.Diag(diag::err_drv_invalid_cf_runtime_abi) << A->getValue();
6527 A->render(Args, CmdArgs);
6530 if (Arg *A = Args.getLastArg(options::OPT_fconstant_string_class_EQ)) {
6531 CmdArgs.push_back(
"-fconstant-string-class");
6532 CmdArgs.push_back(A->getValue());
6535 if (Arg *A = Args.getLastArg(options::OPT_ftabstop_EQ)) {
6536 CmdArgs.push_back(
"-ftabstop");
6537 CmdArgs.push_back(A->getValue());
6540 Args.addOptInFlag(CmdArgs, options::OPT_fstack_size_section,
6541 options::OPT_fno_stack_size_section);
6543 if (Args.hasArg(options::OPT_fstack_usage)) {
6544 CmdArgs.push_back(
"-stack-usage-file");
6546 if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) {
6548 llvm::sys::path::replace_extension(OutputFilename,
"su");
6549 CmdArgs.push_back(Args.MakeArgString(OutputFilename));
6555 CmdArgs.push_back(
"-ferror-limit");
6556 if (Arg *A = Args.getLastArg(options::OPT_ferror_limit_EQ))
6557 CmdArgs.push_back(A->getValue());
6559 CmdArgs.push_back(
"19");
6561 Args.AddLastArg(CmdArgs, options::OPT_fconstexpr_backtrace_limit_EQ);
6562 Args.AddLastArg(CmdArgs, options::OPT_fmacro_backtrace_limit_EQ);
6563 Args.AddLastArg(CmdArgs, options::OPT_ftemplate_backtrace_limit_EQ);
6564 Args.AddLastArg(CmdArgs, options::OPT_fspell_checking_limit_EQ);
6565 Args.AddLastArg(CmdArgs, options::OPT_fcaret_diagnostics_max_lines_EQ);
6568 unsigned MessageLength = 0;
6569 if (Arg *A = Args.getLastArg(options::OPT_fmessage_length_EQ)) {
6570 StringRef
V(A->getValue());
6571 if (
V.getAsInteger(0, MessageLength))
6572 D.Diag(diag::err_drv_invalid_argument_to_option)
6573 <<
V << A->getOption().getName();
6577 MessageLength = llvm::sys::Process::StandardErrColumns();
6579 if (MessageLength != 0)
6581 Args.MakeArgString(
"-fmessage-length=" + Twine(MessageLength)));
6583 if (Arg *A = Args.getLastArg(options::OPT_frandomize_layout_seed_EQ))
6585 Args.MakeArgString(
"-frandomize-layout-seed=" + Twine(A->getValue(0))));
6587 if (Arg *A = Args.getLastArg(options::OPT_frandomize_layout_seed_file_EQ))
6588 CmdArgs.push_back(Args.MakeArgString(
"-frandomize-layout-seed-file=" +
6589 Twine(A->getValue(0))));
6592 if (
const Arg *A = Args.getLastArg(options::OPT_fvisibility_EQ,
6593 options::OPT_fvisibility_ms_compat)) {
6594 if (A->getOption().matches(options::OPT_fvisibility_EQ)) {
6595 A->render(Args, CmdArgs);
6597 assert(A->getOption().matches(options::OPT_fvisibility_ms_compat));
6598 CmdArgs.push_back(
"-fvisibility=hidden");
6599 CmdArgs.push_back(
"-ftype-visibility=default");
6601 }
else if (IsOpenMPDevice) {
6605 CmdArgs.push_back(
"-fvisibility=protected");
6609 if (!RawTriple.isPS()) {
6611 Args.getLastArg(options::OPT_fvisibility_from_dllstorageclass,
6612 options::OPT_fno_visibility_from_dllstorageclass)) {
6613 if (A->getOption().matches(
6614 options::OPT_fvisibility_from_dllstorageclass)) {
6615 CmdArgs.push_back(
"-fvisibility-from-dllstorageclass");
6616 Args.AddLastArg(CmdArgs, options::OPT_fvisibility_dllexport_EQ);
6617 Args.AddLastArg(CmdArgs, options::OPT_fvisibility_nodllstorageclass_EQ);
6618 Args.AddLastArg(CmdArgs, options::OPT_fvisibility_externs_dllimport_EQ);
6619 Args.AddLastArg(CmdArgs,
6620 options::OPT_fvisibility_externs_nodllstorageclass_EQ);
6625 if (Args.hasFlag(options::OPT_fvisibility_inlines_hidden,
6626 options::OPT_fno_visibility_inlines_hidden,
false))
6627 CmdArgs.push_back(
"-fvisibility-inlines-hidden");
6629 Args.AddLastArg(CmdArgs, options::OPT_fvisibility_inlines_hidden_static_local_var,
6630 options::OPT_fno_visibility_inlines_hidden_static_local_var);
6635 Args.getLastArg(options::OPT_fvisibility_global_new_delete_hidden)) {
6636 D.Diag(diag::warn_drv_deprecated_arg)
6637 << A->getAsString(Args) <<
true
6638 <<
"-fvisibility-global-new-delete=force-hidden";
6642 Args.getLastArg(options::OPT_fvisibility_global_new_delete_EQ,
6643 options::OPT_fvisibility_global_new_delete_hidden)) {
6644 if (A->getOption().matches(options::OPT_fvisibility_global_new_delete_EQ)) {
6645 A->render(Args, CmdArgs);
6647 assert(A->getOption().matches(
6648 options::OPT_fvisibility_global_new_delete_hidden));
6649 CmdArgs.push_back(
"-fvisibility-global-new-delete=force-hidden");
6653 Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ);
6655 if (Args.hasFlag(options::OPT_fnew_infallible,
6656 options::OPT_fno_new_infallible,
false))
6657 CmdArgs.push_back(
"-fnew-infallible");
6659 if (Args.hasFlag(options::OPT_fno_operator_names,
6660 options::OPT_foperator_names,
false))
6661 CmdArgs.push_back(
"-fno-operator-names");
6664 Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
6665 Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
6666 Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs);
6667 Args.AddLastArg(CmdArgs, options::OPT_fzero_call_used_regs_EQ);
6668 Args.AddLastArg(CmdArgs, options::OPT_fraw_string_literals,
6669 options::OPT_fno_raw_string_literals);
6671 if (Args.hasFlag(options::OPT_femulated_tls, options::OPT_fno_emulated_tls,
6672 Triple.hasDefaultEmulatedTLS()))
6673 CmdArgs.push_back(
"-femulated-tls");
6675 Args.addOptInFlag(CmdArgs, options::OPT_fcheck_new,
6676 options::OPT_fno_check_new);
6678 if (Arg *A = Args.getLastArg(options::OPT_fzero_call_used_regs_EQ)) {
6682 if (!Triple.isX86() && !Triple.isAArch64())
6683 D.Diag(diag::err_drv_unsupported_opt_for_target)
6684 << A->getAsString(Args) << TripleStr;
6688 if (!isa<PreprocessJobAction>(JA) || Output.
getType() != types::TY_PP_Asm)
6689 Args.AddLastArg(CmdArgs, options::OPT_fzvector);
6691 Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_show_template_tree);
6692 Args.AddLastArg(CmdArgs, options::OPT_fno_elide_type);
6696 if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
6697 options::OPT_fno_openmp,
false) &&
6698 !Args.hasFlag(options::OPT_foffload_via_llvm,
6699 options::OPT_fno_offload_via_llvm,
false) &&
6702 switch (
D.getOpenMPRuntime(Args)) {
6706 CmdArgs.push_back(
"-fopenmp");
6711 if (!Args.hasFlag(options::OPT_fopenmp_use_tls,
6712 options::OPT_fnoopenmp_use_tls,
true))
6713 CmdArgs.push_back(
"-fnoopenmp-use-tls");
6714 Args.AddLastArg(CmdArgs, options::OPT_fopenmp_simd,
6715 options::OPT_fno_openmp_simd);
6716 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_enable_irbuilder);
6717 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
6718 if (!Args.hasFlag(options::OPT_fopenmp_extensions,
6719 options::OPT_fno_openmp_extensions,
true))
6720 CmdArgs.push_back(
"-fno-openmp-extensions");
6721 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_cuda_number_of_sm_EQ);
6722 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_cuda_blocks_per_sm_EQ);
6723 Args.AddAllArgs(CmdArgs,
6724 options::OPT_fopenmp_cuda_teams_reduction_recs_num_EQ);
6725 if (Args.hasFlag(options::OPT_fopenmp_optimistic_collapse,
6726 options::OPT_fno_openmp_optimistic_collapse,
6728 CmdArgs.push_back(
"-fopenmp-optimistic-collapse");
6732 if (Args.hasFlag(options::OPT_fopenmp_cuda_mode,
6733 options::OPT_fno_openmp_cuda_mode,
false))
6734 CmdArgs.push_back(
"-fopenmp-cuda-mode");
6737 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_target_debug_EQ);
6738 if (Args.hasFlag(options::OPT_fopenmp_target_debug,
6739 options::OPT_fno_openmp_target_debug,
false))
6740 CmdArgs.push_back(
"-fopenmp-target-debug");
6744 if (Args.hasFlag(options::OPT_fopenmp_assume_teams_oversubscription,
6745 options::OPT_fno_openmp_assume_teams_oversubscription,
6747 CmdArgs.push_back(
"-fopenmp-assume-teams-oversubscription");
6748 if (Args.hasFlag(options::OPT_fopenmp_assume_threads_oversubscription,
6749 options::OPT_fno_openmp_assume_threads_oversubscription,
6751 CmdArgs.push_back(
"-fopenmp-assume-threads-oversubscription");
6752 if (Args.hasArg(options::OPT_fopenmp_assume_no_thread_state))
6753 CmdArgs.push_back(
"-fopenmp-assume-no-thread-state");
6754 if (Args.hasArg(options::OPT_fopenmp_assume_no_nested_parallelism))
6755 CmdArgs.push_back(
"-fopenmp-assume-no-nested-parallelism");
6756 if (Args.hasArg(options::OPT_fopenmp_offload_mandatory))
6757 CmdArgs.push_back(
"-fopenmp-offload-mandatory");
6758 if (Args.hasArg(options::OPT_fopenmp_force_usm))
6759 CmdArgs.push_back(
"-fopenmp-force-usm");
6771 Args.AddLastArg(CmdArgs, options::OPT_fopenmp_simd,
6772 options::OPT_fno_openmp_simd);
6773 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
6774 Args.addOptOutFlag(CmdArgs, options::OPT_fopenmp_extensions,
6775 options::OPT_fno_openmp_extensions);
6780 if (Args.hasFlag(options::OPT_foffload_via_llvm,
6781 options::OPT_fno_offload_via_llvm,
false)) {
6782 CmdArgs.append({
"--offload-new-driver",
"-foffload-via-llvm"});
6783 }
else if (Args.hasFlag(options::OPT_offload_new_driver,
6784 options::OPT_no_offload_new_driver,
false)) {
6785 CmdArgs.push_back(
"--offload-new-driver");
6788 SanitizeArgs.addArgs(TC, Args, CmdArgs, InputType);
6791 XRay.
addArgs(TC, Args, CmdArgs, InputType);
6794 Args.getAllArgValues(options::OPT_fprofile_list_EQ)) {
6796 CmdArgs.push_back(Args.MakeArgString(
"-fprofile-list=" +
Filename));
6798 D.Diag(clang::diag::err_drv_no_such_file) <<
Filename;
6801 if (Arg *A = Args.getLastArg(options::OPT_fpatchable_function_entry_EQ)) {
6802 StringRef S0 = A->getValue(), S = S0;
6803 unsigned Size, Offset = 0;
6804 if (!Triple.isAArch64() && !Triple.isLoongArch() && !Triple.isRISCV() &&
6806 !(!Triple.isOSAIX() && (Triple.getArch() == llvm::Triple::ppc ||
6807 Triple.getArch() == llvm::Triple::ppc64)))
6808 D.Diag(diag::err_drv_unsupported_opt_for_target)
6809 << A->getAsString(Args) << TripleStr;
6810 else if (S.consumeInteger(10, Size) ||
6811 (!S.empty() && (!S.consume_front(
",") ||
6812 S.consumeInteger(10, Offset) || !S.empty())))
6813 D.Diag(diag::err_drv_invalid_argument_to_option)
6814 << S0 << A->getOption().getName();
6815 else if (Size < Offset)
6816 D.Diag(diag::err_drv_unsupported_fpatchable_function_entry_argument);
6818 CmdArgs.push_back(Args.MakeArgString(A->getSpelling() + Twine(Size)));
6819 CmdArgs.push_back(Args.MakeArgString(
6820 "-fpatchable-function-entry-offset=" + Twine(Offset)));
6824 Args.AddLastArg(CmdArgs, options::OPT_fms_hotpatch);
6827 Args.AddLastArg(CmdArgs, options::OPT_pg);
6829 llvm::Triple::ArchType Arch = TC.
getArch();
6830 if (Arg *A = Args.getLastArg(options::OPT_mfentry)) {
6831 if (Arch == llvm::Triple::systemz || TC.
getTriple().isX86())
6832 A->render(Args, CmdArgs);
6834 D.Diag(diag::err_drv_unsupported_opt_for_target)
6835 << A->getAsString(Args) << TripleStr;
6837 if (Arg *A = Args.getLastArg(options::OPT_mnop_mcount)) {
6838 if (Arch == llvm::Triple::systemz)
6839 A->render(Args, CmdArgs);
6841 D.Diag(diag::err_drv_unsupported_opt_for_target)
6842 << A->getAsString(Args) << TripleStr;
6844 if (Arg *A = Args.getLastArg(options::OPT_mrecord_mcount)) {
6845 if (Arch == llvm::Triple::systemz)
6846 A->render(Args, CmdArgs);
6848 D.Diag(diag::err_drv_unsupported_opt_for_target)
6849 << A->getAsString(Args) << TripleStr;
6853 if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) {
6855 D.Diag(diag::err_drv_unsupported_opt_for_target)
6856 << A->getAsString(Args) << TripleStr;
6859 if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
6861 D.Diag(diag::err_drv_unsupported_opt_for_target)
6862 << A->getAsString(Args) << TripleStr;
6865 if (Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg)) {
6866 if (A->getOption().matches(options::OPT_p)) {
6868 if (TC.
getTriple().isOSAIX() && !Args.hasArgNoClaim(options::OPT_pg))
6869 CmdArgs.push_back(
"-pg");
6875 for (
const Arg *A : Args.filtered(options::OPT_b, options::OPT_K,
6876 options::OPT_mxcoff_build_id_EQ)) {
6877 D.Diag(diag::err_drv_unsupported_opt_for_target)
6878 << A->getSpelling() << TripleStr;
6882 if (Args.getLastArg(options::OPT_fapple_kext) ||
6883 (Args.hasArg(options::OPT_mkernel) &&
types::isCXX(InputType)))
6884 CmdArgs.push_back(
"-fapple-kext");
6886 Args.AddLastArg(CmdArgs, options::OPT_altivec_src_compat);
6887 Args.AddLastArg(CmdArgs, options::OPT_flax_vector_conversions_EQ);
6888 Args.AddLastArg(CmdArgs, options::OPT_fobjc_sender_dependent_dispatch);
6889 Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_print_source_range_info);
6890 Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_parseable_fixits);
6891 Args.AddLastArg(CmdArgs, options::OPT_ftime_report);
6892 Args.AddLastArg(CmdArgs, options::OPT_ftime_report_EQ);
6893 Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
6894 Args.AddLastArg(CmdArgs, options::OPT_malign_double);
6895 Args.AddLastArg(CmdArgs, options::OPT_fno_temp_file);
6897 if (
const char *Name =
C.getTimeTraceFile(&JA)) {
6898 CmdArgs.push_back(Args.MakeArgString(
"-ftime-trace=" + Twine(Name)));
6899 Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
6900 Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_verbose);
6903 if (Arg *A = Args.getLastArg(options::OPT_ftrapv_handler_EQ)) {
6904 CmdArgs.push_back(
"-ftrapv-handler");
6905 CmdArgs.push_back(A->getValue());
6908 Args.AddLastArg(CmdArgs, options::OPT_ftrap_function_EQ);
6912 if (Arg *A = Args.getLastArg(options::OPT_fwrapv, options::OPT_fno_wrapv)) {
6913 if (A->getOption().matches(options::OPT_fwrapv))
6914 CmdArgs.push_back(
"-fwrapv");
6915 }
else if (Arg *A = Args.getLastArg(options::OPT_fstrict_overflow,
6916 options::OPT_fno_strict_overflow)) {
6917 if (A->getOption().matches(options::OPT_fno_strict_overflow))
6918 CmdArgs.push_back(
"-fwrapv");
6921 Args.AddLastArg(CmdArgs, options::OPT_ffinite_loops,
6922 options::OPT_fno_finite_loops);
6924 Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings);
6925 Args.AddLastArg(CmdArgs, options::OPT_funroll_loops,
6926 options::OPT_fno_unroll_loops);
6928 Args.AddLastArg(CmdArgs, options::OPT_fstrict_flex_arrays_EQ);
6930 Args.AddLastArg(CmdArgs, options::OPT_pthread);
6932 Args.addOptInFlag(CmdArgs, options::OPT_mspeculative_load_hardening,
6933 options::OPT_mno_speculative_load_hardening);
6939 Args.AddLastArg(CmdArgs, options::OPT_fswift_async_fp_EQ);
6941 Args.addOptInFlag(CmdArgs, options::OPT_mstackrealign,
6942 options::OPT_mno_stackrealign);
6944 if (Args.hasArg(options::OPT_mstack_alignment)) {
6945 StringRef alignment = Args.getLastArgValue(options::OPT_mstack_alignment);
6946 CmdArgs.push_back(Args.MakeArgString(
"-mstack-alignment=" + alignment));
6949 if (Args.hasArg(options::OPT_mstack_probe_size)) {
6950 StringRef Size = Args.getLastArgValue(options::OPT_mstack_probe_size);
6953 CmdArgs.push_back(Args.MakeArgString(
"-mstack-probe-size=" + Size));
6955 CmdArgs.push_back(
"-mstack-probe-size=0");
6958 Args.addOptOutFlag(CmdArgs, options::OPT_mstack_arg_probe,
6959 options::OPT_mno_stack_arg_probe);
6961 if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it,
6962 options::OPT_mno_restrict_it)) {
6963 if (A->getOption().matches(options::OPT_mrestrict_it)) {
6964 CmdArgs.push_back(
"-mllvm");
6965 CmdArgs.push_back(
"-arm-restrict-it");
6967 CmdArgs.push_back(
"-mllvm");
6968 CmdArgs.push_back(
"-arm-default-it");
6982 if (Args.hasFlag(options::OPT_fhip_new_launch_api,
6983 options::OPT_fno_hip_new_launch_api,
true))
6984 CmdArgs.push_back(
"-fhip-new-launch-api");
6985 Args.addOptInFlag(CmdArgs, options::OPT_fgpu_allow_device_init,
6986 options::OPT_fno_gpu_allow_device_init);
6987 Args.AddLastArg(CmdArgs, options::OPT_hipstdpar);
6988 Args.AddLastArg(CmdArgs, options::OPT_hipstdpar_interpose_alloc);
6989 Args.addOptInFlag(CmdArgs, options::OPT_fhip_kernel_arg_name,
6990 options::OPT_fno_hip_kernel_arg_name);
6993 if (IsCuda || IsHIP) {
6995 CmdArgs.push_back(
"-fgpu-rdc");
6996 Args.addOptInFlag(CmdArgs, options::OPT_fgpu_defer_diag,
6997 options::OPT_fno_gpu_defer_diag);
6998 if (Args.hasFlag(options::OPT_fgpu_exclude_wrong_side_overloads,
6999 options::OPT_fno_gpu_exclude_wrong_side_overloads,
7001 CmdArgs.push_back(
"-fgpu-exclude-wrong-side-overloads");
7002 CmdArgs.push_back(
"-fgpu-defer-diag");
7007 if (Args.hasArg(options::OPT_nogpulib))
7008 CmdArgs.push_back(
"-nogpulib");
7010 if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
7012 Args.MakeArgString(Twine(
"-fcf-protection=") + A->getValue()));
7015 if (Arg *A = Args.getLastArg(options::OPT_mfunction_return_EQ))
7017 Args.MakeArgString(Twine(
"-mfunction-return=") + A->getValue()));
7019 Args.AddLastArg(CmdArgs, options::OPT_mindirect_branch_cs_prefix);
7024 if (!(IsCudaDevice || IsHIPDevice)) {
7026 auto *PGOArg = Args.getLastArg(
7027 options::OPT_fprofile_generate, options::OPT_fprofile_generate_EQ,
7028 options::OPT_fcs_profile_generate,
7029 options::OPT_fcs_profile_generate_EQ, options::OPT_fprofile_use,
7030 options::OPT_fprofile_use_EQ);
7032 D.Diag(diag::err_drv_argument_not_allowed_with)
7033 <<
"SampleUse with PGO options";
7035 StringRef fname = A->getValue();
7036 if (!llvm::sys::fs::exists(fname))
7037 D.Diag(diag::err_drv_no_such_file) << fname;
7039 A->render(Args, CmdArgs);
7041 Args.AddLastArg(CmdArgs, options::OPT_fprofile_remapping_file_EQ);
7043 if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
7044 options::OPT_fno_pseudo_probe_for_profiling,
false)) {
7045 CmdArgs.push_back(
"-fpseudo-probe-for-profiling");
7048 if (Args.hasFlag(options::OPT_funique_internal_linkage_names,
7049 options::OPT_fno_unique_internal_linkage_names,
true))
7050 CmdArgs.push_back(
"-funique-internal-linkage-names");
7055 Args.addOptOutFlag(CmdArgs, options::OPT_fassume_sane_operator_new,
7056 options::OPT_fno_assume_sane_operator_new);
7058 if (Args.hasFlag(options::OPT_fapinotes, options::OPT_fno_apinotes,
false))
7059 CmdArgs.push_back(
"-fapinotes");
7060 if (Args.hasFlag(options::OPT_fapinotes_modules,
7061 options::OPT_fno_apinotes_modules,
false))
7062 CmdArgs.push_back(
"-fapinotes-modules");
7063 Args.AddLastArg(CmdArgs, options::OPT_fapinotes_swift_version);
7066 if (Args.hasFlag(options::OPT_fblocks, options::OPT_fno_blocks,
7068 (Args.hasArg(options::OPT_fgnu_runtime) &&
7069 Args.hasArg(options::OPT_fobjc_nonfragile_abi) &&
7070 !Args.hasArg(options::OPT_fno_blocks))) {
7071 CmdArgs.push_back(
"-fblocks");
7074 CmdArgs.push_back(
"-fblocks-runtime-optional");
7079 CmdArgs.push_back(
"-fencode-extended-block-signature");
7081 if (Args.hasFlag(options::OPT_fcoro_aligned_allocation,
7082 options::OPT_fno_coro_aligned_allocation,
false) &&
7084 CmdArgs.push_back(
"-fcoro-aligned-allocation");
7086 Args.AddLastArg(CmdArgs, options::OPT_fdouble_square_bracket_attributes,
7087 options::OPT_fno_double_square_bracket_attributes);
7089 Args.addOptOutFlag(CmdArgs, options::OPT_faccess_control,
7090 options::OPT_fno_access_control);
7091 Args.addOptOutFlag(CmdArgs, options::OPT_felide_constructors,
7092 options::OPT_fno_elide_constructors);
7098 CmdArgs.push_back(
"-fno-rtti");
7101 if (Args.hasFlag(options::OPT_fshort_enums, options::OPT_fno_short_enums,
7102 TC.
getArch() == llvm::Triple::hexagon || Triple.isOSzOS()))
7103 CmdArgs.push_back(
"-fshort-enums");
7109 options::OPT_fuse_cxa_atexit, options::OPT_fno_use_cxa_atexit,
7110 !RawTriple.isOSAIX() && !RawTriple.isOSWindows() &&
7111 ((RawTriple.getVendor() != llvm::Triple::MipsTechnologies) ||
7112 RawTriple.hasEnvironment())) ||
7114 CmdArgs.push_back(
"-fno-use-cxa-atexit");
7116 if (Args.hasFlag(options::OPT_fregister_global_dtors_with_atexit,
7117 options::OPT_fno_register_global_dtors_with_atexit,
7118 RawTriple.isOSDarwin() && !KernelOrKext))
7119 CmdArgs.push_back(
"-fregister-global-dtors-with-atexit");
7121 Args.addOptInFlag(CmdArgs, options::OPT_fuse_line_directives,
7122 options::OPT_fno_use_line_directives);
7125 if (Args.hasFlag(options::OPT_fminimize_whitespace,
7126 options::OPT_fno_minimize_whitespace,
false)) {
7127 types::ID InputType = Inputs[0].getType();
7128 if (!isDerivedFromC(InputType))
7129 D.Diag(diag::err_drv_opt_unsupported_input_type)
7131 CmdArgs.push_back(
"-fminimize-whitespace");
7135 if (Args.hasFlag(options::OPT_fkeep_system_includes,
7136 options::OPT_fno_keep_system_includes,
false)) {
7137 types::ID InputType = Inputs[0].getType();
7138 if (!isDerivedFromC(InputType))
7139 D.Diag(diag::err_drv_opt_unsupported_input_type)
7141 CmdArgs.push_back(
"-fkeep-system-includes");
7145 if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
7147 CmdArgs.push_back(
"-fms-extensions");
7150 bool IsMSVCCompat = Args.hasFlag(
7151 options::OPT_fms_compatibility, options::OPT_fno_ms_compatibility,
7152 (IsWindowsMSVC && Args.hasFlag(options::OPT_fms_extensions,
7153 options::OPT_fno_ms_extensions,
true)));
7155 CmdArgs.push_back(
"-fms-compatibility");
7157 Args.hasArg(options::OPT_fms_define_stdc))
7158 CmdArgs.push_back(
"-fms-define-stdc");
7161 if (Triple.isWindowsMSVCEnvironment() && !
D.IsCLMode() &&
7162 Args.hasArg(options::OPT_fms_runtime_lib_EQ))
7166 VersionTuple GNUCVer;
7167 if (Arg *A = Args.getLastArg(options::OPT_fgnuc_version_EQ)) {
7170 StringRef Val = A->getValue();
7171 Val = Val.empty() ?
"0" : Val;
7172 bool Invalid = GNUCVer.tryParse(Val);
7173 unsigned Minor = GNUCVer.getMinor().value_or(0);
7174 unsigned Patch = GNUCVer.getSubminor().value_or(0);
7175 if (
Invalid || GNUCVer.getBuild() || Minor >= 100 || Patch >= 100) {
7176 D.Diag(diag::err_drv_invalid_value)
7177 << A->getAsString(Args) << A->getValue();
7179 }
else if (!IsMSVCCompat) {
7181 GNUCVer = VersionTuple(4, 2, 1);
7183 if (!GNUCVer.empty()) {
7185 Args.MakeArgString(
"-fgnuc-version=" + GNUCVer.getAsString()));
7191 Args.MakeArgString(
"-fms-compatibility-version=" + MSVT.getAsString()));
7193 bool IsMSVC2015Compatible = MSVT.getMajor() >= 19;
7194 if (ImplyVCPPCVer) {
7195 StringRef LanguageStandard;
7196 if (
const Arg *StdArg = Args.getLastArg(options::OPT__SLASH_std)) {
7198 LanguageStandard = llvm::StringSwitch<StringRef>(StdArg->getValue())
7199 .Case(
"c11",
"-std=c11")
7200 .Case(
"c17",
"-std=c17")
7202 if (LanguageStandard.empty())
7203 D.Diag(clang::diag::warn_drv_unused_argument)
7204 << StdArg->getAsString(Args);
7206 CmdArgs.push_back(LanguageStandard.data());
7208 if (ImplyVCPPCXXVer) {
7209 StringRef LanguageStandard;
7210 if (
const Arg *StdArg = Args.getLastArg(options::OPT__SLASH_std)) {
7212 LanguageStandard = llvm::StringSwitch<StringRef>(StdArg->getValue())
7213 .Case(
"c++14",
"-std=c++14")
7214 .Case(
"c++17",
"-std=c++17")
7215 .Case(
"c++20",
"-std=c++20")
7217 .Case(
"c++latest",
"-std=c++26")
7219 if (LanguageStandard.empty())
7220 D.Diag(clang::diag::warn_drv_unused_argument)
7221 << StdArg->getAsString(Args);
7224 if (LanguageStandard.empty()) {
7225 if (IsMSVC2015Compatible)
7226 LanguageStandard =
"-std=c++14";
7228 LanguageStandard =
"-std=c++11";
7231 CmdArgs.push_back(LanguageStandard.data());
7234 Args.addOptInFlag(CmdArgs, options::OPT_fborland_extensions,
7235 options::OPT_fno_borland_extensions);
7238 if (Args.hasFlag(options::OPT_fdeclspec, options::OPT_fno_declspec,
7240 CmdArgs.push_back(
"-fdeclspec");
7241 else if (Args.hasArg(options::OPT_fno_declspec))
7242 CmdArgs.push_back(
"-fno-declspec");
7246 if (!Args.hasFlag(options::OPT_fthreadsafe_statics,
7247 options::OPT_fno_threadsafe_statics,
7249 (!IsWindowsMSVC || IsMSVC2015Compatible)))
7250 CmdArgs.push_back(
"-fno-threadsafe-statics");
7253 if (!Args.hasFlag(options::OPT_fassumptions, options::OPT_fno_assumptions,
7255 CmdArgs.push_back(
"-fno-assumptions");
7259 Args.AddLastArg(CmdArgs, options::OPT_fgnu_keywords,
7260 options::OPT_fno_gnu_keywords);
7262 Args.addOptInFlag(CmdArgs, options::OPT_fgnu89_inline,
7263 options::OPT_fno_gnu89_inline);
7265 const Arg *InlineArg = Args.getLastArg(options::OPT_finline_functions,
7266 options::OPT_finline_hint_functions,
7267 options::OPT_fno_inline_functions);
7268 if (Arg *A = Args.getLastArg(options::OPT_finline, options::OPT_fno_inline)) {
7269 if (A->getOption().matches(options::OPT_fno_inline))
7270 A->render(Args, CmdArgs);
7271 }
else if (InlineArg) {
7272 InlineArg->render(Args, CmdArgs);
7275 Args.AddLastArg(CmdArgs, options::OPT_finline_max_stacksize_EQ);
7280 (
Std->containsValue(
"c++2a") ||
Std->containsValue(
"gnu++2a") ||
7281 Std->containsValue(
"c++20") ||
Std->containsValue(
"gnu++20") ||
7282 Std->containsValue(
"c++2b") ||
Std->containsValue(
"gnu++2b") ||
7283 Std->containsValue(
"c++23") ||
Std->containsValue(
"gnu++23") ||
7284 Std->containsValue(
"c++2c") ||
Std->containsValue(
"gnu++2c") ||
7285 Std->containsValue(
"c++26") ||
Std->containsValue(
"gnu++26") ||
7286 Std->containsValue(
"c++latest") ||
Std->containsValue(
"gnu++latest"));
7301 if (Args.hasFlag(options::OPT_fdelayed_template_parsing,
7302 options::OPT_fno_delayed_template_parsing,
7303 IsWindowsMSVC && !HaveCxx20)) {
7305 D.Diag(clang::diag::warn_drv_delayed_template_parsing_after_cxx20);
7307 CmdArgs.push_back(
"-fdelayed-template-parsing");
7310 if (Args.hasFlag(options::OPT_fpch_validate_input_files_content,
7311 options::OPT_fno_pch_validate_input_files_content,
false))
7312 CmdArgs.push_back(
"-fvalidate-ast-input-files-content");
7313 if (Args.hasFlag(options::OPT_fpch_instantiate_templates,
7314 options::OPT_fno_pch_instantiate_templates,
false))
7315 CmdArgs.push_back(
"-fpch-instantiate-templates");
7316 if (Args.hasFlag(options::OPT_fpch_codegen, options::OPT_fno_pch_codegen,
7318 CmdArgs.push_back(
"-fmodules-codegen");
7319 if (Args.hasFlag(options::OPT_fpch_debuginfo, options::OPT_fno_pch_debuginfo,
7321 CmdArgs.push_back(
"-fmodules-debuginfo");
7323 ObjCRuntime Runtime = AddObjCRuntimeArgs(Args, Inputs, CmdArgs, rewriteKind);
7328 Args.hasFlag(options::OPT_fobjc_encode_cxx_class_template_spec,
7329 options::OPT_fno_objc_encode_cxx_class_template_spec,
7331 CmdArgs.push_back(
"-fobjc-encode-cxx-class-template-spec");
7333 if (Args.hasFlag(options::OPT_fapplication_extension,
7334 options::OPT_fno_application_extension,
false))
7335 CmdArgs.push_back(
"-fapplication-extension");
7339 if (!
C.getDriver().IsCLMode())
7340 EH =
addExceptionArgs(Args, InputType, TC, KernelOrKext, Runtime, CmdArgs);
7343 Arg *A = Args.getLastArg(
7344 options::OPT_fsjlj_exceptions, options::OPT_fseh_exceptions,
7345 options::OPT_fdwarf_exceptions, options::OPT_fwasm_exceptions);
7347 const Option &Opt = A->getOption();
7348 if (Opt.matches(options::OPT_fsjlj_exceptions))
7349 CmdArgs.push_back(
"-exception-model=sjlj");
7350 if (Opt.matches(options::OPT_fseh_exceptions))
7351 CmdArgs.push_back(
"-exception-model=seh");
7352 if (Opt.matches(options::OPT_fdwarf_exceptions))
7353 CmdArgs.push_back(
"-exception-model=dwarf");
7354 if (Opt.matches(options::OPT_fwasm_exceptions))
7355 CmdArgs.push_back(
"-exception-model=wasm");
7360 case llvm::ExceptionHandling::DwarfCFI:
7361 CmdArgs.push_back(
"-exception-model=dwarf");
7363 case llvm::ExceptionHandling::SjLj:
7364 CmdArgs.push_back(
"-exception-model=sjlj");
7366 case llvm::ExceptionHandling::WinEH:
7367 CmdArgs.push_back(
"-exception-model=seh");
7373 Args.addOptOutFlag(CmdArgs, options::OPT_fassume_sane_operator_new,
7374 options::OPT_fno_assume_sane_operator_new);
7377 Args.addOptOutFlag(CmdArgs, options::OPT_fassume_unique_vtables,
7378 options::OPT_fno_assume_unique_vtables);
7382 Args.getLastArg(options::OPT_frelaxed_template_template_args,
7383 options::OPT_fno_relaxed_template_template_args)) {
7384 if (A->getOption().matches(
7385 options::OPT_fno_relaxed_template_template_args)) {
7386 D.Diag(diag::warn_drv_deprecated_arg_no_relaxed_template_template_args);
7387 CmdArgs.push_back(
"-fno-relaxed-template-template-args");
7389 D.Diag(diag::warn_drv_deprecated_arg)
7390 << A->getAsString(Args) <<
false;
7396 Args.addLastArg(CmdArgs, options::OPT_fsized_deallocation,
7397 options::OPT_fno_sized_deallocation);
7401 if (Arg *A = Args.getLastArg(options::OPT_faligned_allocation,
7402 options::OPT_fno_aligned_allocation,
7403 options::OPT_faligned_new_EQ)) {
7404 if (A->getOption().matches(options::OPT_fno_aligned_allocation))
7405 CmdArgs.push_back(
"-fno-aligned-allocation");
7407 CmdArgs.push_back(
"-faligned-allocation");
7412 if (Arg *A = Args.getLastArg(options::OPT_fnew_alignment_EQ,
7413 options::OPT_faligned_new_EQ))
7415 Args.MakeArgString(Twine(
"-fnew-alignment=") + A->getValue()));
7419 if (!Args.hasFlag(options::OPT_fconstant_cfstrings,
7420 options::OPT_fno_constant_cfstrings,
true) ||
7421 !Args.hasFlag(options::OPT_mconstant_cfstrings,
7422 options::OPT_mno_constant_cfstrings,
true))
7423 CmdArgs.push_back(
"-fno-constant-cfstrings");
7425 Args.addOptInFlag(CmdArgs, options::OPT_fpascal_strings,
7426 options::OPT_fno_pascal_strings);
7430 if (Arg *A = Args.getLastArg(options::OPT_fpack_struct_EQ)) {
7431 std::string PackStructStr =
"-fpack-struct=";
7432 PackStructStr += A->getValue();
7433 CmdArgs.push_back(Args.MakeArgString(PackStructStr));
7434 }
else if (Args.hasFlag(options::OPT_fpack_struct,
7435 options::OPT_fno_pack_struct,
false)) {
7436 CmdArgs.push_back(
"-fpack-struct=1");
7440 bool SkipMaxTypeAlign = Args.hasArg(options::OPT_fno_max_type_align);
7441 if (Arg *A = Args.getLastArg(options::OPT_fmax_type_align_EQ)) {
7442 if (!SkipMaxTypeAlign) {
7443 std::string MaxTypeAlignStr =
"-fmax-type-align=";
7444 MaxTypeAlignStr += A->getValue();
7445 CmdArgs.push_back(Args.MakeArgString(MaxTypeAlignStr));
7447 }
else if (RawTriple.isOSDarwin()) {
7448 if (!SkipMaxTypeAlign) {
7449 std::string MaxTypeAlignStr =
"-fmax-type-align=16";
7450 CmdArgs.push_back(Args.MakeArgString(MaxTypeAlignStr));
7454 if (!Args.hasFlag(options::OPT_Qy, options::OPT_Qn,
true))
7455 CmdArgs.push_back(
"-Qn");
7458 Args.addOptInFlag(CmdArgs, options::OPT_fcommon, options::OPT_fno_common);
7462 if (!Args.hasFlag(options::OPT_fsigned_bitfields,
7463 options::OPT_funsigned_bitfields,
true))
7464 D.Diag(diag::warn_drv_clang_unsupported)
7465 << Args.getLastArg(options::OPT_funsigned_bitfields)->getAsString(Args);
7468 if (!Args.hasFlag(options::OPT_ffor_scope, options::OPT_fno_for_scope,
true))
7469 D.Diag(diag::err_drv_clang_unsupported)
7470 << Args.getLastArg(options::OPT_fno_for_scope)->getAsString(Args);
7473 if (Arg *inputCharset = Args.getLastArg(options::OPT_finput_charset_EQ)) {
7474 StringRef value = inputCharset->getValue();
7475 if (!value.equals_insensitive(
"utf-8"))
7476 D.Diag(diag::err_drv_invalid_value) << inputCharset->getAsString(Args)
7481 if (Arg *execCharset = Args.getLastArg(options::OPT_fexec_charset_EQ)) {
7482 StringRef value = execCharset->getValue();
7483 if (!value.equals_insensitive(
"utf-8"))
7484 D.Diag(diag::err_drv_invalid_value) << execCharset->getAsString(Args)
7490 Args.addOptInFlag(CmdArgs, options::OPT_fasm_blocks,
7491 options::OPT_fno_asm_blocks);
7493 Args.addOptOutFlag(CmdArgs, options::OPT_fgnu_inline_asm,
7494 options::OPT_fno_gnu_inline_asm);
7500 OptSpecifier VectorizeAliasOption =
7501 EnableVec ? options::OPT_O_Group : options::OPT_fvectorize;
7502 if (Args.hasFlag(options::OPT_fvectorize, VectorizeAliasOption,
7503 options::OPT_fno_vectorize, EnableVec))
7504 CmdArgs.push_back(
"-vectorize-loops");
7508 OptSpecifier SLPVectAliasOption =
7509 EnableSLPVec ? options::OPT_O_Group : options::OPT_fslp_vectorize;
7510 if (Args.hasFlag(options::OPT_fslp_vectorize, SLPVectAliasOption,
7511 options::OPT_fno_slp_vectorize, EnableSLPVec))
7512 CmdArgs.push_back(
"-vectorize-slp");
7516 Args.AddLastArg(CmdArgs, options::OPT_fshow_overloads_EQ);
7517 Args.AddLastArg(CmdArgs,
7518 options::OPT_fsanitize_undefined_strip_path_components_EQ);
7522 if (Arg *A = Args.getLastArg(options::OPT_fdollars_in_identifiers,
7523 options::OPT_fno_dollars_in_identifiers)) {
7524 if (A->getOption().matches(options::OPT_fdollars_in_identifiers))
7525 CmdArgs.push_back(
"-fdollars-in-identifiers");
7527 CmdArgs.push_back(
"-fno-dollars-in-identifiers");
7530 Args.addOptInFlag(CmdArgs, options::OPT_fapple_pragma_pack,
7531 options::OPT_fno_apple_pragma_pack);
7537 bool RewriteImports = Args.hasFlag(options::OPT_frewrite_imports,
7538 options::OPT_fno_rewrite_imports,
false);
7540 CmdArgs.push_back(
"-frewrite-imports");
7542 Args.addOptInFlag(CmdArgs, options::OPT_fdirectives_only,
7543 options::OPT_fno_directives_only);
7549 if (Args.hasFlag(options::OPT_frewrite_includes,
7550 options::OPT_fno_rewrite_includes,
false) ||
7551 (
C.isForDiagnostics() && !HaveModules))
7552 CmdArgs.push_back(
"-frewrite-includes");
7554 if (Args.hasFlag(options::OPT_fzos_extensions,
7555 options::OPT_fno_zos_extensions,
false))
7556 CmdArgs.push_back(
"-fzos-extensions");
7557 else if (Args.hasArg(options::OPT_fno_zos_extensions))
7558 CmdArgs.push_back(
"-fno-zos-extensions");
7561 if (Arg *A = Args.getLastArg(options::OPT_traditional,
7562 options::OPT_traditional_cpp)) {
7563 if (isa<PreprocessJobAction>(JA))
7564 CmdArgs.push_back(
"-traditional-cpp");
7566 D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
7569 Args.AddLastArg(CmdArgs, options::OPT_dM);
7570 Args.AddLastArg(CmdArgs, options::OPT_dD);
7571 Args.AddLastArg(CmdArgs, options::OPT_dI);
7573 Args.AddLastArg(CmdArgs, options::OPT_fmax_tokens_EQ);
7576 if (Arg *A = Args.getLastArg(options::OPT__serialize_diags)) {
7577 CmdArgs.push_back(
"-serialize-diagnostic-file");
7578 CmdArgs.push_back(Args.MakeArgString(A->getValue()));
7581 if (Args.hasArg(options::OPT_fretain_comments_from_system_headers))
7582 CmdArgs.push_back(
"-fretain-comments-from-system-headers");
7585 Args.AddAllArgs(CmdArgs, options::OPT_fcomment_block_commands);
7587 Args.AddAllArgs(CmdArgs, options::OPT_fparse_all_comments);
7590 for (
const Arg *A : Args.filtered(options::OPT_fplugin_EQ)) {
7591 CmdArgs.push_back(
"-load");
7592 CmdArgs.push_back(A->getValue());
7604 for (
const Arg *A : Args.filtered(options::OPT_fplugin_arg)) {
7605 auto ArgValue = StringRef(A->getValue());
7606 auto FirstDashIndex = ArgValue.find(
'-');
7607 StringRef PluginName = ArgValue.substr(0, FirstDashIndex);
7608 StringRef Arg = ArgValue.substr(FirstDashIndex + 1);
7611 if (FirstDashIndex == StringRef::npos || Arg.empty()) {
7612 if (PluginName.empty()) {
7613 D.Diag(diag::warn_drv_missing_plugin_name) << A->getAsString(Args);
7615 D.Diag(diag::warn_drv_missing_plugin_arg)
7616 << PluginName << A->getAsString(Args);
7621 CmdArgs.push_back(Args.MakeArgString(Twine(
"-plugin-arg-") + PluginName));
7622 CmdArgs.push_back(Args.MakeArgString(Arg));
7626 for (
const Arg *A : Args.filtered(options::OPT_fpass_plugin_EQ)) {
7628 Args.MakeArgString(Twine(
"-fpass-plugin=") + A->getValue()));
7633 for (
const Arg *A : Args.filtered(options::OPT_vfsoverlay)) {
7634 CmdArgs.push_back(
"--vfsoverlay");
7635 CmdArgs.push_back(A->getValue());
7639 Args.addOptInFlag(CmdArgs, options::OPT_fsafe_buffer_usage_suggestions,
7640 options::OPT_fno_safe_buffer_usage_suggestions);
7642 Args.addOptInFlag(CmdArgs, options::OPT_fexperimental_late_parse_attributes,
7643 options::OPT_fno_experimental_late_parse_attributes);
7647 if (!StatsFile.empty()) {
7648 CmdArgs.push_back(Args.MakeArgString(Twine(
"-stats-file=") + StatsFile));
7649 if (
D.CCPrintInternalStats)
7650 CmdArgs.push_back(
"-stats-file-append");
7655 for (
auto Arg : Args.filtered(options::OPT_Xclang)) {
7659 if (
C.getDriver().isSaveTempsEnabled() &&
7660 !isa<PreprocessJobAction>(JA)) {
7661 if (StringRef(Arg->getValue()) ==
"-finclude-default-header")
7664 CmdArgs.push_back(Arg->getValue());
7666 for (
const Arg *A : Args.filtered(options::OPT_mllvm)) {
7672 if (StringRef(A->getValue(0)) ==
"-disable-llvm-optzns") {
7673 CmdArgs.push_back(
"-disable-llvm-optzns");
7675 A->render(Args, CmdArgs);
7687 if ((
C.getDriver().isSaveTempsEnabled() ||
7689 !(
C.getDriver().embedBitcodeInObject() && !IsUsingLTO) &&
7690 isa<CompileJobAction>(JA))
7691 CmdArgs.push_back(
"-disable-llvm-passes");
7693 Args.AddAllArgs(CmdArgs, options::OPT_undef);
7695 const char *Exec =
D.getClangProgramPath();
7702 auto GRecordSwitches =
7703 Args.hasFlag(options::OPT_grecord_command_line,
7704 options::OPT_gno_record_command_line,
false);
7705 auto FRecordSwitches =
7706 Args.hasFlag(options::OPT_frecord_command_line,
7707 options::OPT_fno_record_command_line,
false);
7708 if (FRecordSwitches && !Triple.isOSBinFormatELF() &&
7709 !Triple.isOSBinFormatXCOFF() && !Triple.isOSBinFormatMachO())
7710 D.Diag(diag::err_drv_unsupported_opt_for_target)
7711 << Args.getLastArg(options::OPT_frecord_command_line)->getAsString(Args)
7714 ArgStringList OriginalArgs;
7715 for (
const auto &Arg : Args)
7716 Arg->render(Args, OriginalArgs);
7720 for (
const char *OriginalArg : OriginalArgs) {
7724 Flags += EscapedArg;
7726 auto FlagsArgString = Args.MakeArgString(Flags);
7728 CmdArgs.push_back(
"-dwarf-debug-flags");
7729 CmdArgs.push_back(FlagsArgString);
7731 if (FRecordSwitches) {
7732 CmdArgs.push_back(
"-record-command-line");
7733 CmdArgs.push_back(FlagsArgString);
7740 if ((IsCuda || IsHIP) && CudaDeviceInput) {
7741 CmdArgs.push_back(
"-fcuda-include-gpubinary");
7742 CmdArgs.push_back(CudaDeviceInput->
getFilename());
7743 }
else if (!HostOffloadingInputs.empty()) {
7744 if ((IsCuda || IsHIP) && !IsRDCMode) {
7745 assert(HostOffloadingInputs.size() == 1 &&
"Only one input expected");
7746 CmdArgs.push_back(
"-fcuda-include-gpubinary");
7747 CmdArgs.push_back(HostOffloadingInputs.front().getFilename());
7749 for (
const InputInfo Input : HostOffloadingInputs)
7750 CmdArgs.push_back(Args.MakeArgString(
"-fembed-offload-object=" +
7756 if (Args.hasFlag(options::OPT_fcuda_short_ptr,
7757 options::OPT_fno_cuda_short_ptr,
false))
7758 CmdArgs.push_back(
"-fcuda-short-ptr");
7761 if (IsCuda || IsHIP) {
7763 const Action *SourceAction = &JA;
7765 assert(!SourceAction->
getInputs().empty() &&
"unexpected root action!");
7766 SourceAction = SourceAction->
getInputs()[0];
7768 auto CUID = cast<InputAction>(SourceAction)->getId();
7770 CmdArgs.push_back(Args.MakeArgString(Twine(
"-cuid=") + Twine(CUID)));
7774 bool UseApproxTranscendentals = Args.hasFlag(
7775 options::OPT_ffast_math, options::OPT_fno_fast_math,
false);
7776 if (Args.hasFlag(options::OPT_fgpu_approx_transcendentals,
7777 options::OPT_fno_gpu_approx_transcendentals,
7778 UseApproxTranscendentals))
7779 CmdArgs.push_back(
"-fgpu-approx-transcendentals");
7781 Args.claimAllArgs(options::OPT_fgpu_approx_transcendentals,
7782 options::OPT_fno_gpu_approx_transcendentals);
7786 CmdArgs.push_back(
"-fcuda-allow-variadic-functions");
7787 Args.AddLastArg(CmdArgs, options::OPT_fgpu_default_stream_EQ);
7790 Args.AddAllArgs(CmdArgs,
7791 options::OPT_fsanitize_undefined_ignore_overflow_pattern_EQ);
7793 Args.AddLastArg(CmdArgs, options::OPT_foffload_uniform_block,
7794 options::OPT_fno_offload_uniform_block);
7796 Args.AddLastArg(CmdArgs, options::OPT_foffload_implicit_host_device_templates,
7797 options::OPT_fno_offload_implicit_host_device_templates);
7799 if (IsCudaDevice || IsHIPDevice) {
7800 StringRef InlineThresh =
7801 Args.getLastArgValue(options::OPT_fgpu_inline_threshold_EQ);
7802 if (!InlineThresh.empty()) {
7803 std::string ArgStr =
7804 std::string(
"-inline-threshold=") + InlineThresh.str();
7805 CmdArgs.append({
"-mllvm", Args.MakeArgStringRef(ArgStr)});
7810 Args.addOptOutFlag(CmdArgs,
7811 options::OPT_fhip_fp32_correctly_rounded_divide_sqrt,
7812 options::OPT_fno_hip_fp32_correctly_rounded_divide_sqrt);
7819 if (IsOpenMPDevice) {
7820 CmdArgs.push_back(
"-fopenmp-is-target-device");
7822 if (Args.hasArg(options::OPT_foffload_via_llvm))
7823 CmdArgs.push_back(
"-fcuda-is-device");
7825 if (OpenMPDeviceInput) {
7826 CmdArgs.push_back(
"-fopenmp-host-ir-file-path");
7827 CmdArgs.push_back(Args.MakeArgString(OpenMPDeviceInput->
getFilename()));
7831 if (Triple.isAMDGPU()) {
7834 Args.addOptInFlag(CmdArgs, options::OPT_munsafe_fp_atomics,
7835 options::OPT_mno_unsafe_fp_atomics);
7836 Args.addOptOutFlag(CmdArgs, options::OPT_mamdgpu_ieee,
7837 options::OPT_mno_amdgpu_ieee);
7842 bool VirtualFunctionElimination =
7843 Args.hasFlag(options::OPT_fvirtual_function_elimination,
7844 options::OPT_fno_virtual_function_elimination,
false);
7845 if (VirtualFunctionElimination) {
7849 D.Diag(diag::err_drv_argument_only_allowed_with)
7850 <<
"-fvirtual-function-elimination"
7853 CmdArgs.push_back(
"-fvirtual-function-elimination");
7857 bool WholeProgramVTables = Args.hasFlag(
7858 options::OPT_fwhole_program_vtables,
7859 options::OPT_fno_whole_program_vtables, VirtualFunctionElimination);
7860 if (VirtualFunctionElimination && !WholeProgramVTables) {
7861 D.Diag(diag::err_drv_argument_not_allowed_with)
7862 <<
"-fno-whole-program-vtables"
7863 <<
"-fvirtual-function-elimination";
7866 if (WholeProgramVTables) {
7878 IsDeviceOffloadAction ?
D.getLTOMode() :
D.getOffloadLTOMode();
7879 auto OtherIsUsingLTO = OtherLTOMode !=
LTOK_None;
7881 if ((!IsUsingLTO && !OtherIsUsingLTO) ||
7882 (IsPS4 && !UnifiedLTO && (
D.getLTOMode() !=
LTOK_Full)))
7883 D.Diag(diag::err_drv_argument_only_allowed_with)
7884 <<
"-fwhole-program-vtables"
7885 << ((IsPS4 && !UnifiedLTO) ?
"-flto=full" :
"-flto");
7889 CmdArgs.push_back(
"-fwhole-program-vtables");
7892 bool DefaultsSplitLTOUnit =
7893 ((WholeProgramVTables || SanitizeArgs.needsLTO()) &&
7895 (!Triple.isPS4() && UnifiedLTO);
7897 Args.hasFlag(options::OPT_fsplit_lto_unit,
7898 options::OPT_fno_split_lto_unit, DefaultsSplitLTOUnit);
7899 if (SanitizeArgs.needsLTO() && !SplitLTOUnit)
7900 D.Diag(diag::err_drv_argument_not_allowed_with) <<
"-fno-split-lto-unit"
7901 <<
"-fsanitize=cfi";
7903 CmdArgs.push_back(
"-fsplit-lto-unit");
7905 if (Arg *A = Args.getLastArg(options::OPT_ffat_lto_objects,
7906 options::OPT_fno_fat_lto_objects)) {
7907 if (IsUsingLTO && A->getOption().matches(options::OPT_ffat_lto_objects)) {
7909 if (!Triple.isOSBinFormatELF()) {
7910 D.Diag(diag::err_drv_unsupported_opt_for_target)
7913 CmdArgs.push_back(Args.MakeArgString(
7914 Twine(
"-flto=") + (LTOMode ==
LTOK_Thin ?
"thin" :
"full")));
7915 CmdArgs.push_back(
"-flto-unit");
7916 CmdArgs.push_back(
"-ffat-lto-objects");
7917 A->render(Args, CmdArgs);
7921 if (Arg *A = Args.getLastArg(options::OPT_fglobal_isel,
7922 options::OPT_fno_global_isel)) {
7923 CmdArgs.push_back(
"-mllvm");
7924 if (A->getOption().matches(options::OPT_fglobal_isel)) {
7925 CmdArgs.push_back(
"-global-isel=1");
7930 bool IsArchSupported = Triple.getArch() == llvm::Triple::aarch64;
7931 bool IsOptLevelSupported =
false;
7933 Arg *A = Args.getLastArg(options::OPT_O_Group);
7934 if (Triple.getArch() == llvm::Triple::aarch64) {
7935 if (!A || A->getOption().matches(options::OPT_O0))
7936 IsOptLevelSupported =
true;
7938 if (!IsArchSupported || !IsOptLevelSupported) {
7939 CmdArgs.push_back(
"-mllvm");
7940 CmdArgs.push_back(
"-global-isel-abort=2");
7942 if (!IsArchSupported)
7943 D.Diag(diag::warn_drv_global_isel_incomplete) << Triple.getArchName();
7945 D.Diag(diag::warn_drv_global_isel_incomplete_opt);
7948 CmdArgs.push_back(
"-global-isel=0");
7952 if (Args.hasArg(options::OPT_forder_file_instrumentation)) {
7953 CmdArgs.push_back(
"-forder-file-instrumentation");
7958 CmdArgs.push_back(
"-mllvm");
7959 CmdArgs.push_back(
"-enable-order-file-instrumentation");
7963 if (Arg *A = Args.getLastArg(options::OPT_fforce_enable_int128,
7964 options::OPT_fno_force_enable_int128)) {
7965 if (A->getOption().matches(options::OPT_fforce_enable_int128))
7966 CmdArgs.push_back(
"-fforce-enable-int128");
7969 Args.addOptInFlag(CmdArgs, options::OPT_fkeep_static_consts,
7970 options::OPT_fno_keep_static_consts);
7971 Args.addOptInFlag(CmdArgs, options::OPT_fkeep_persistent_storage_variables,
7972 options::OPT_fno_keep_persistent_storage_variables);
7973 Args.addOptInFlag(CmdArgs, options::OPT_fcomplete_member_pointers,
7974 options::OPT_fno_complete_member_pointers);
7975 Args.addOptOutFlag(CmdArgs, options::OPT_fcxx_static_destructors,
7976 options::OPT_fno_cxx_static_destructors);
7982 if (Triple.isAArch64() &&
7983 (Args.hasArg(options::OPT_mno_fmv) ||
7984 (Triple.isAndroid() && Triple.isAndroidVersionLT(23)) ||
7987 CmdArgs.push_back(
"-target-feature");
7988 CmdArgs.push_back(
"-fmv");
7991 if (Args.hasFlag(options::OPT_faddrsig, options::OPT_fno_addrsig,
7998 CmdArgs.push_back(
"-faddrsig");
8000 if ((Triple.isOSBinFormatELF() || Triple.isOSBinFormatMachO()) &&
8001 (EH || UnwindTables || AsyncUnwindTables ||
8002 DebugInfoKind != llvm::codegenoptions::NoDebugInfo))
8003 CmdArgs.push_back(
"-D__GCC_HAVE_DWARF2_CFI_ASM=1");
8005 if (Arg *A = Args.getLastArg(options::OPT_fsymbol_partition_EQ)) {
8006 std::string Str = A->getAsString(Args);
8008 D.Diag(diag::err_drv_unsupported_opt_for_target)
8010 CmdArgs.push_back(Args.MakeArgString(Str));
8015 if (Output.
getType() == types::TY_Dependencies) {
8018 if (Output.
getType() == clang::driver::types::TY_IFS_CPP ||
8019 Output.
getType() == clang::driver::types::TY_IFS) {
8021 llvm::sys::path::replace_extension(OutputFilename,
"ifs");
8022 CmdArgs.push_back(
"-o");
8023 CmdArgs.push_back(Args.MakeArgString(OutputFilename));
8025 CmdArgs.push_back(
"-o");
8029 assert(Output.
isNothing() &&
"Invalid output.");
8036 FrontendInputs = ExtractAPIInputs;
8038 FrontendInputs = {};
8040 for (
const InputInfo &Input : FrontendInputs) {
8047 if (
D.CC1Main && !
D.CCGenDiagnostics) {
8049 C.addCommand(std::make_unique<CC1Command>(
8051 Output,
D.getPrependArg()));
8053 C.addCommand(std::make_unique<Command>(
8055 Output,
D.getPrependArg()));
8059 if (Output.
getType() == types::TY_Object &&
8060 Args.hasFlag(options::OPT__SLASH_showFilenames,
8061 options::OPT__SLASH_showFilenames_,
false)) {
8062 C.getJobs().getJobs().back()->PrintInputFilenames =
true;
8065 if (Arg *A = Args.getLastArg(options::OPT_pg))
8067 !Args.hasArg(options::OPT_mfentry))
8068 D.Diag(diag::err_drv_argument_not_allowed_with) <<
"-fomit-frame-pointer"
8069 << A->getAsString(Args);
8075 Args.ClaimAllArgs(options::OPT_fpch_preprocess);
8079 Args.ClaimAllArgs(options::OPT_clang_ignored_f_Group);
8080 Args.ClaimAllArgs(options::OPT_clang_ignored_m_Group);
8083 Args.ClaimAllArgs(options::OPT_emit_llvm);
8090 :
Tool(
"clang",
"clang frontend", TC), HasBackend(HasIntegratedBackend) {}
8097ObjCRuntime Clang::AddObjCRuntimeArgs(
const ArgList &args,
8099 ArgStringList &cmdArgs,
8100 RewriteKind rewriteKind)
const {
8103 args.getLastArg(options::OPT_fnext_runtime, options::OPT_fgnu_runtime,
8104 options::OPT_fobjc_runtime_EQ);
8109 runtimeArg->getOption().matches(options::OPT_fobjc_runtime_EQ)) {
8111 StringRef value = runtimeArg->getValue();
8117 (runtime.
getVersion() >= VersionTuple(2, 0)))
8121 diag::err_drv_gnustep_objc_runtime_incompatible_binary)
8125 runtimeArg->render(args, cmdArgs);
8134 unsigned objcABIVersion = 1;
8136 if (Arg *abiArg = args.getLastArg(options::OPT_fobjc_abi_version_EQ)) {
8137 StringRef value = abiArg->getValue();
8140 else if (value ==
"2")
8142 else if (value ==
"3")
8148 bool nonFragileABIIsDefault =
8149 (rewriteKind == RK_NonFragile ||
8150 (rewriteKind == RK_None &&
8152 if (args.hasFlag(options::OPT_fobjc_nonfragile_abi,
8153 options::OPT_fno_objc_nonfragile_abi,
8154 nonFragileABIIsDefault)) {
8156#ifdef DISABLE_DEFAULT_NONFRAGILEABI_TWO
8157 unsigned nonFragileABIVersion = 1;
8159 unsigned nonFragileABIVersion = 2;
8163 args.getLastArg(options::OPT_fobjc_nonfragile_abi_version_EQ)) {
8164 StringRef value = abiArg->getValue();
8166 nonFragileABIVersion = 1;
8167 else if (value ==
"2")
8168 nonFragileABIVersion = 2;
8174 objcABIVersion = 1 + nonFragileABIVersion;
8182 bool isNonFragile = objcABIVersion != 1;
8188 switch (rewriteKind) {
8201 }
else if (runtimeArg->getOption().matches(options::OPT_fnext_runtime)) {
8213 assert(runtimeArg->getOption().matches(options::OPT_fgnu_runtime));
8222 if (llvm::any_of(inputs, [](
const InputInfo &input) {
8226 args.MakeArgString(
"-fobjc-runtime=" + runtime.
getAsString()));
8231 bool HaveDash = (I + 1 < EH.size() && EH[I + 1] ==
'-');
8239 bool Asynch =
false;
8240 bool NoUnwindC =
false;
8252 bool isWindowsMSVC) {
8255 std::vector<std::string> EHArgs =
8256 Args.getAllArgValues(options::OPT__SLASH_EH);
8257 for (
const auto &EHVal : EHArgs) {
8258 for (
size_t I = 0,
E = EHVal.size(); I !=
E; ++I) {
8264 if (!isWindowsMSVC) {
8266 D.Diag(clang::diag::warn_drv_unused_argument) <<
"/EHa" << EHVal;
8283 D.Diag(clang::diag::err_drv_invalid_value) <<
"/EH" << EHVal;
8289 if (EHArgs.empty() &&
8290 Args.hasFlag(options::OPT__SLASH_GX, options::OPT__SLASH_GX_,
8293 EH.NoUnwindC =
true;
8296 if (Args.hasArg(options::OPT__SLASH_kernel)) {
8298 EH.NoUnwindC =
false;
8305void Clang::AddClangCLArgs(
const ArgList &Args,
types::ID InputType,
8306 ArgStringList &CmdArgs)
const {
8311 if (Arg *ShowIncludes =
8312 Args.getLastArg(options::OPT__SLASH_showIncludes,
8313 options::OPT__SLASH_showIncludes_user)) {
8314 CmdArgs.push_back(
"--show-includes");
8315 if (ShowIncludes->getOption().matches(options::OPT__SLASH_showIncludes))
8316 CmdArgs.push_back(
"-sys-header-deps");
8320 if (Args.hasFlag(options::OPT__SLASH_GR_, options::OPT__SLASH_GR,
8322 CmdArgs.push_back(
"-fno-rtti-data");
8326 if (!isNVPTX && Args.hasFlag(options::OPT__SLASH_GS, options::OPT__SLASH_GS_,
8328 CmdArgs.push_back(
"-stack-protector");
8336 if (!isNVPTX && (EH.Synch || EH.Asynch)) {
8338 CmdArgs.push_back(
"-fcxx-exceptions");
8339 CmdArgs.push_back(
"-fexceptions");
8341 CmdArgs.push_back(
"-fasync-exceptions");
8343 if (
types::isCXX(InputType) && EH.Synch && EH.NoUnwindC)
8344 CmdArgs.push_back(
"-fexternc-nounwind");
8347 if (Args.hasArg(options::OPT__SLASH_EP)) {
8348 CmdArgs.push_back(
"-E");
8349 CmdArgs.push_back(
"-P");
8352 if (Args.hasFlag(options::OPT__SLASH_Zc_dllexportInlines_,
8353 options::OPT__SLASH_Zc_dllexportInlines,
8355 CmdArgs.push_back(
"-fno-dllexport-inlines");
8358 if (Args.hasFlag(options::OPT__SLASH_Zc_wchar_t_,
8359 options::OPT__SLASH_Zc_wchar_t,
false)) {
8360 CmdArgs.push_back(
"-fno-wchar");
8363 if (Args.hasArg(options::OPT__SLASH_kernel)) {
8365 std::vector<std::string> Values =
8366 Args.getAllArgValues(options::OPT__SLASH_arch);
8367 if (!Values.empty()) {
8368 llvm::SmallSet<std::string, 4> SupportedArches;
8369 if (Arch == llvm::Triple::x86)
8370 SupportedArches.insert(
"IA32");
8372 for (
auto &
V : Values)
8373 if (!SupportedArches.contains(
V))
8374 D.Diag(diag::err_drv_argument_not_allowed_with)
8375 << std::string(
"/arch:").append(
V) <<
"/kernel";
8378 CmdArgs.push_back(
"-fno-rtti");
8379 if (Args.hasFlag(options::OPT__SLASH_GR, options::OPT__SLASH_GR_,
false))
8380 D.Diag(diag::err_drv_argument_not_allowed_with) <<
"/GR"
8384 Arg *MostGeneralArg = Args.getLastArg(options::OPT__SLASH_vmg);
8385 Arg *BestCaseArg = Args.getLastArg(options::OPT__SLASH_vmb);
8386 if (MostGeneralArg && BestCaseArg)
8387 D.Diag(clang::diag::err_drv_argument_not_allowed_with)
8388 << MostGeneralArg->getAsString(Args) << BestCaseArg->getAsString(Args);
8390 if (MostGeneralArg) {
8391 Arg *SingleArg = Args.getLastArg(options::OPT__SLASH_vms);
8392 Arg *MultipleArg = Args.getLastArg(options::OPT__SLASH_vmm);
8393 Arg *VirtualArg = Args.getLastArg(options::OPT__SLASH_vmv);
8395 Arg *FirstConflict = SingleArg ? SingleArg : MultipleArg;
8396 Arg *SecondConflict = VirtualArg ? VirtualArg : MultipleArg;
8397 if (FirstConflict && SecondConflict && FirstConflict != SecondConflict)
8398 D.Diag(clang::diag::err_drv_argument_not_allowed_with)
8399 << FirstConflict->getAsString(Args)
8400 << SecondConflict->getAsString(Args);
8403 CmdArgs.push_back(
"-fms-memptr-rep=single");
8404 else if (MultipleArg)
8405 CmdArgs.push_back(
"-fms-memptr-rep=multiple");
8407 CmdArgs.push_back(
"-fms-memptr-rep=virtual");
8410 if (Args.hasArg(options::OPT_regcall4))
8411 CmdArgs.push_back(
"-regcall4");
8415 Args.getLastArg(options::OPT__SLASH_Gd, options::OPT__SLASH_Gr,
8416 options::OPT__SLASH_Gz, options::OPT__SLASH_Gv,
8417 options::OPT__SLASH_Gregcall)) {
8418 unsigned DCCOptId = CCArg->getOption().
getID();
8419 const char *DCCFlag =
nullptr;
8420 bool ArchSupported = !isNVPTX;
8423 case options::OPT__SLASH_Gd:
8424 DCCFlag =
"-fdefault-calling-conv=cdecl";
8426 case options::OPT__SLASH_Gr:
8427 ArchSupported = Arch == llvm::Triple::x86;
8428 DCCFlag =
"-fdefault-calling-conv=fastcall";
8430 case options::OPT__SLASH_Gz:
8431 ArchSupported = Arch == llvm::Triple::x86;
8432 DCCFlag =
"-fdefault-calling-conv=stdcall";
8434 case options::OPT__SLASH_Gv:
8435 ArchSupported = Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64;
8436 DCCFlag =
"-fdefault-calling-conv=vectorcall";
8438 case options::OPT__SLASH_Gregcall:
8439 ArchSupported = Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64;
8440 DCCFlag =
"-fdefault-calling-conv=regcall";
8445 if (ArchSupported && DCCFlag)
8446 CmdArgs.push_back(DCCFlag);
8449 if (Args.hasArg(options::OPT__SLASH_Gregcall4))
8450 CmdArgs.push_back(
"-regcall4");
8452 Args.AddLastArg(CmdArgs, options::OPT_vtordisp_mode_EQ);
8454 if (!Args.hasArg(options::OPT_fdiagnostics_format_EQ)) {
8455 CmdArgs.push_back(
"-fdiagnostics-format");
8456 CmdArgs.push_back(
"msvc");
8459 if (Args.hasArg(options::OPT__SLASH_kernel))
8460 CmdArgs.push_back(
"-fms-kernel");
8462 for (
const Arg *A : Args.filtered(options::OPT__SLASH_guard)) {
8463 StringRef GuardArgs = A->getValue();
8466 if (GuardArgs.equals_insensitive(
"cf")) {
8468 CmdArgs.push_back(
"-cfguard");
8469 }
else if (GuardArgs.equals_insensitive(
"cf,nochecks")) {
8471 CmdArgs.push_back(
"-cfguard-no-checks");
8472 }
else if (GuardArgs.equals_insensitive(
"ehcont")) {
8474 CmdArgs.push_back(
"-ehcontguard");
8475 }
else if (GuardArgs.equals_insensitive(
"cf-") ||
8476 GuardArgs.equals_insensitive(
"ehcont-")) {
8479 D.Diag(diag::err_drv_invalid_value) << A->getSpelling() << GuardArgs;
8487 return Args.MakeArgString(llvm::sys::path::filename(Input.
getBaseInput()));
8494 if (
const char *End = strrchr(Str,
'.'))
8495 return Args.MakeArgString(std::string(Str, End));
8504 if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) {
8506 llvm::sys::path::replace_extension(OutputFilename, llvm::Twine(
'd'));
8507 return Args.MakeArgString(OutputFilename);
8516 ArgStringList &CmdArgs)
const {
8522 CmdArgs.push_back(
"-target-abi");
8523 CmdArgs.push_back(ABIName.data());
8527 ArgStringList &CmdArgs)
const {
8531 if (Arg *A = Args.getLastArg(options::OPT_masm_EQ)) {
8532 StringRef
Value = A->getValue();
8534 CmdArgs.push_back(
"-mllvm");
8535 CmdArgs.push_back(Args.MakeArgString(
"-x86-asm-syntax=" +
Value));
8538 << A->getSpelling() <<
Value;
8544 ArgStringList &CmdArgs)
const {
8545 CmdArgs.push_back(
"-target-abi");
8552 ArgStringList &CmdArgs)
const {
8556 CmdArgs.push_back(
"-target-abi");
8557 CmdArgs.push_back(ABIName.data());
8559 if (Args.hasFlag(options::OPT_mdefault_build_attributes,
8560 options::OPT_mno_default_build_attributes,
true)) {
8561 CmdArgs.push_back(
"-mllvm");
8562 CmdArgs.push_back(
"-riscv-add-build-attributes");
8568 const ArgList &Args,
8569 const char *LinkingOutput)
const {
8570 ArgStringList CmdArgs;
8572 assert(Inputs.size() == 1 &&
"Unexpected number of inputs.");
8576 const std::string &TripleStr = Triple.getTriple();
8580 Args.ClaimAllArgs(options::OPT_w);
8582 Args.ClaimAllArgs(options::OPT_emit_llvm);
8589 CmdArgs.push_back(
"-cc1as");
8592 CmdArgs.push_back(
"-triple");
8593 CmdArgs.push_back(Args.MakeArgString(TripleStr));
8599 CmdArgs.push_back(
"-filetype");
8600 CmdArgs.push_back(
"obj");
8604 CmdArgs.push_back(
"-main-file-name");
8608 std::string CPU =
getCPUName(
D, Args, Triple,
true);
8610 CmdArgs.push_back(
"-target-cpu");
8611 CmdArgs.push_back(Args.MakeArgString(CPU));
8618 (void)Args.hasArg(options::OPT_force__cpusubtype__ALL);
8621 Args.AddAllArgs(CmdArgs, options::OPT_I_Group);
8624 Args.AddAllArgs(CmdArgs, options::OPT_embed_dir_EQ);
8627 auto FindSource = [](
const Action *S) ->
const Action * {
8629 assert(!S->getInputs().empty() &&
"unexpected root action!");
8630 S = S->getInputs()[0];
8634 const Action *SourceAction = FindSource(&JA);
8638 bool WantDebug =
false;
8639 Args.ClaimAllArgs(options::OPT_g_Group);
8640 if (Arg *A = Args.getLastArg(options::OPT_g_Group))
8641 WantDebug = !A->getOption().matches(options::OPT_g0) &&
8642 !A->getOption().matches(options::OPT_ggdb0);
8644 llvm::codegenoptions::DebugInfoKind DebugInfoKind =
8645 llvm::codegenoptions::NoDebugInfo;
8648 const char *DebugCompilationDir =
8651 if (SourceAction->
getType() == types::TY_Asm ||
8652 SourceAction->
getType() == types::TY_PP_Asm) {
8657 DebugInfoKind = (WantDebug ? llvm::codegenoptions::DebugInfoConstructor
8658 : llvm::codegenoptions::NoDebugInfo);
8665 CmdArgs.push_back(
"-dwarf-debug-producer");
8669 Args.AddAllArgs(CmdArgs, options::OPT_I);
8673 llvm::DebuggerKind::Default);
8679 llvm::Reloc::Model RelocationModel;
8682 std::tie(RelocationModel, PICLevel, IsPIE) =
8687 CmdArgs.push_back(
"-mrelocation-model");
8688 CmdArgs.push_back(RMName);
8694 ArgStringList OriginalArgs;
8695 for (
const auto &Arg : Args)
8696 Arg->render(Args, OriginalArgs);
8701 for (
const char *OriginalArg : OriginalArgs) {
8705 Flags += EscapedArg;
8707 CmdArgs.push_back(
"-dwarf-debug-flags");
8708 CmdArgs.push_back(Args.MakeArgString(Flags));
8718 case llvm::Triple::mips:
8719 case llvm::Triple::mipsel:
8720 case llvm::Triple::mips64:
8721 case llvm::Triple::mips64el:
8725 case llvm::Triple::x86:
8726 case llvm::Triple::x86_64:
8730 case llvm::Triple::arm:
8731 case llvm::Triple::armeb:
8732 case llvm::Triple::thumb:
8733 case llvm::Triple::thumbeb:
8736 if (Args.hasFlag(options::OPT_mdefault_build_attributes,
8737 options::OPT_mno_default_build_attributes,
true)) {
8738 CmdArgs.push_back(
"-mllvm");
8739 CmdArgs.push_back(
"-arm-add-build-attributes");
8743 case llvm::Triple::aarch64:
8744 case llvm::Triple::aarch64_32:
8745 case llvm::Triple::aarch64_be:
8746 if (Args.hasArg(options::OPT_mmark_bti_property)) {
8747 CmdArgs.push_back(
"-mllvm");
8748 CmdArgs.push_back(
"-aarch64-mark-bti-property");
8752 case llvm::Triple::loongarch32:
8753 case llvm::Triple::loongarch64:
8757 case llvm::Triple::riscv32:
8758 case llvm::Triple::riscv64:
8762 case llvm::Triple::hexagon:
8763 if (Args.hasFlag(options::OPT_mdefault_build_attributes,
8764 options::OPT_mno_default_build_attributes,
true)) {
8765 CmdArgs.push_back(
"-mllvm");
8766 CmdArgs.push_back(
"-hexagon-add-build-attributes");
8776 Args.ClaimAllArgs(options::OPT_W_Group);
8781 Args.AddAllArgs(CmdArgs, options::OPT_mllvm);
8783 if (DebugInfoKind > llvm::codegenoptions::NoDebugInfo && Output.
isFilename())
8790 if (SourceAction != FindSource(&J.getSource()))
8792 auto &JArgs = J.getArguments();
8793 for (
unsigned I = 0; I < JArgs.size(); ++I) {
8794 if (StringRef(JArgs[I]).starts_with(
"-object-file-name=") &&
8796 ArgStringList NewArgs(JArgs.begin(), JArgs.begin() + I);
8799 NewArgs.append(JArgs.begin() + I + 1, JArgs.end());
8800 J.replaceArguments(NewArgs);
8806 assert(Output.
isFilename() &&
"Unexpected lipo output.");
8807 CmdArgs.push_back(
"-o");
8813 T.isOSBinFormatELF()) {
8814 CmdArgs.push_back(
"-split-dwarf-output");
8818 if (Triple.isAMDGPU())
8821 assert(Input.
isFilename() &&
"Invalid input.");
8825 if (
D.CC1Main && !
D.CCGenDiagnostics) {
8827 C.addCommand(std::make_unique<CC1Command>(
8829 Output,
D.getPrependArg()));
8831 C.addCommand(std::make_unique<Command>(
8833 Output,
D.getPrependArg()));
8841 const llvm::opt::ArgList &TCArgs,
8842 const char *LinkingOutput)
const {
8844 assert(isa<OffloadBundlingJobAction>(JA) &&
"Expecting bundling job!");
8854 ArgStringList CmdArgs;
8857 CmdArgs.push_back(TCArgs.MakeArgString(
8860 assert(JA.
getInputs().size() == Inputs.size() &&
8861 "Not have inputs for all dependence actions??");
8865 Triples +=
"-targets=";
8866 for (
unsigned I = 0; I < Inputs.size(); ++I) {
8875 if (
const auto *OA = dyn_cast<OffloadAction>(CurDep)) {
8877 OA->doOnEachDependence([&](
Action *A,
const ToolChain *TC,
const char *) {
8878 assert(CurTC ==
nullptr &&
"Expected one dependence!");
8885 Triples += CurTC->
getTriple().normalize();
8894 StringRef GPUArchName;
8897 for (
unsigned ArgIndex = 0; ArgIndex < TCArgs.size(); ArgIndex++) {
8898 auto ArchStr = StringRef(TCArgs.getArgString(ArgIndex));
8899 auto Arch = ArchStr.starts_with_insensitive(
"-march=");
8901 GPUArchName = ArchStr.substr(7);
8906 Triples += GPUArchName.str();
8909 CmdArgs.push_back(TCArgs.MakeArgString(Triples));
8913 TCArgs.MakeArgString(Twine(
"-output=") + Output.
getFilename()));
8916 for (
unsigned I = 0; I < Inputs.size(); ++I) {
8922 if (
const auto *OA = dyn_cast<OffloadAction>(JA.
getInputs()[I])) {
8924 OA->doOnEachDependence([&](
Action *,
const ToolChain *TC,
const char *) {
8925 assert(CurTC ==
nullptr &&
"Expected one dependence!");
8928 UB +=
C.addTempFile(
8933 CmdArgs.push_back(TCArgs.MakeArgString(UB));
8937 C.addCommand(std::make_unique<Command>(
8940 CmdArgs, std::nullopt, Output));
8945 const InputInfoList &Inputs,
const llvm::opt::ArgList &TCArgs,
8946 const char *LinkingOutput)
const {
8948 auto &UA = cast<OffloadUnbundlingJobAction>(JA);
8959 ArgStringList CmdArgs;
8961 assert(Inputs.size() == 1 &&
"Expecting to unbundle a single file!");
8965 CmdArgs.push_back(TCArgs.MakeArgString(
8970 Triples +=
"-targets=";
8971 auto DepInfo = UA.getDependentActionsInfo();
8972 for (
unsigned I = 0; I < DepInfo.size(); ++I) {
8976 auto &Dep = DepInfo[I];
8979 Triples += Dep.DependentToolChain->getTriple().normalize();
8982 !Dep.DependentBoundArch.empty()) {
8984 Triples += Dep.DependentBoundArch;
8988 StringRef GPUArchName;
8991 for (
unsigned ArgIndex = 0; ArgIndex < TCArgs.size(); ArgIndex++) {
8992 StringRef ArchStr = StringRef(TCArgs.getArgString(ArgIndex));
8993 auto Arch = ArchStr.starts_with_insensitive(
"-march=");
8995 GPUArchName = ArchStr.substr(7);
9000 Triples += GPUArchName.str();
9004 CmdArgs.push_back(TCArgs.MakeArgString(Triples));
9008 TCArgs.MakeArgString(Twine(
"-input=") + Input.
getFilename()));
9011 for (
unsigned I = 0; I < Outputs.size(); ++I) {
9014 UB += DepInfo[I].DependentToolChain->getInputFilename(Outputs[I]);
9015 CmdArgs.push_back(TCArgs.MakeArgString(UB));
9017 CmdArgs.push_back(
"-unbundle");
9018 CmdArgs.push_back(
"-allow-missing-bundles");
9019 if (TCArgs.hasArg(options::OPT_v))
9020 CmdArgs.push_back(
"-verbose");
9023 C.addCommand(std::make_unique<Command>(
9026 CmdArgs, std::nullopt, Outputs));
9032 const llvm::opt::ArgList &Args,
9033 const char *LinkingOutput)
const {
9034 ArgStringList CmdArgs;
9037 assert(Output.
isFilename() &&
"Invalid output.");
9038 CmdArgs.push_back(
"-o");
9045 const ArgList &TCArgs =
9051 : TCArgs.getLastArgValue(options::OPT_march_EQ);
9055 ArgStringList Features;
9059 llvm::copy_if(Features, std::back_inserter(FeatureArgs),
9060 [](StringRef Arg) {
return !Arg.starts_with(
"-target"); });
9063 for (StringRef Feature : llvm::split(Arch.split(
':').second,
':')) {
9064 FeatureArgs.emplace_back(
9065 Args.MakeArgString(Feature.take_back() + Feature.drop_back()));
9072 "file=" +
File.str(),
9074 "arch=" + Arch.str(),
9075 "kind=" + Kind.str(),
9079 for (StringRef Feature : FeatureArgs)
9080 Parts.emplace_back(
"feature=" + Feature.str());
9082 CmdArgs.push_back(Args.MakeArgString(
"--image=" + llvm::join(Parts,
",")));
9085 C.addCommand(std::make_unique<Command>(
9088 CmdArgs, Inputs, Output));
9094 const ArgList &Args,
9095 const char *LinkingOutput)
const {
9098 ArgStringList CmdArgs;
9102 auto TCRange =
C.getOffloadToolChains(Kind);
9103 for (
auto &I : llvm::make_range(TCRange)) {
9107 if (CudaInstallation.
isValid())
9108 CmdArgs.push_back(Args.MakeArgString(
9116 if (
const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
9118 if (A->getOption().matches(options::OPT_O4) ||
9119 A->getOption().matches(options::OPT_Ofast))
9121 else if (A->getOption().matches(options::OPT_O)) {
9122 OOpt = A->getValue();
9125 else if (OOpt ==
"s" || OOpt ==
"z")
9127 }
else if (A->getOption().matches(options::OPT_O0))
9130 CmdArgs.push_back(Args.MakeArgString(Twine(
"--opt-level=O") + OOpt));
9134 Args.MakeArgString(
"--host-triple=" + TheTriple.getTriple()));
9135 if (Args.hasArg(options::OPT_v))
9136 CmdArgs.push_back(
"--wrapper-verbose");
9138 if (
const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
9139 if (!A->getOption().matches(options::OPT_g0))
9140 CmdArgs.push_back(
"--device-debug");
9145 if (
const Arg *A = Args.getLastArg(options::OPT_mcode_object_version_EQ)) {
9146 CmdArgs.push_back(Args.MakeArgString(
"-mllvm"));
9147 CmdArgs.push_back(Args.MakeArgString(
9148 Twine(
"--amdhsa-code-object-version=") + A->getValue()));
9151 for (
const auto &A : Args.getAllArgValues(options::OPT_Xcuda_ptxas))
9152 CmdArgs.push_back(Args.MakeArgString(
"--ptxas-arg=" + A));
9155 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_EQ))
9156 CmdArgs.push_back(Args.MakeArgString(Twine(
"--offload-opt=-pass-remarks=") +
9158 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_missed_EQ))
9159 CmdArgs.push_back(Args.MakeArgString(
9160 Twine(
"--offload-opt=-pass-remarks-missed=") + A->getValue()));
9161 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_analysis_EQ))
9162 CmdArgs.push_back(Args.MakeArgString(
9163 Twine(
"--offload-opt=-pass-remarks-analysis=") + A->getValue()));
9164 if (Args.getLastArg(options::OPT_save_temps_EQ))
9165 CmdArgs.push_back(
"--save-temps");
9168 Linker->
ConstructJob(
C, JA, Output, Inputs, Args, LinkingOutput);
9169 const auto &LinkCommand =
C.getJobs().getJobs().back();
9172 for (Arg *A : Args.filtered(options::OPT_Xoffload_linker)) {
9173 StringRef Val = A->getValue(0);
9176 Args.MakeArgString(Twine(
"--device-linker=") + A->getValue(1)));
9178 CmdArgs.push_back(Args.MakeArgString(
9179 "--device-linker=" +
9183 Args.ClaimAllArgs(options::OPT_Xoffload_linker);
9186 if (Args.hasFlag(options::OPT_fopenmp_target_jit,
9187 options::OPT_fno_openmp_target_jit,
false))
9188 CmdArgs.push_back(
"--embed-bitcode");
9191 for (Arg *A : Args.filtered(options::OPT_mllvm)) {
9192 CmdArgs.push_back(
"-mllvm");
9193 CmdArgs.push_back(A->getValue());
9199 if (!Args.hasFlag(options::OPT_gpulibc, options::OPT_nogpulibc,
true))
9200 CmdArgs.push_back(
"--device-compiler=-nolibc");
9203 CmdArgs.push_back(Args.MakeArgString(Twine(
"--linker-path=") +
9204 LinkCommand->getExecutable()));
9205 for (
const char *LinkArg : LinkCommand->getArguments())
9206 CmdArgs.push_back(LinkArg);
9211 Args.MakeArgString(
getToolChain().GetProgramPath(
"clang-linker-wrapper"));
9215 LinkCommand->replaceExecutable(Exec);
9216 LinkCommand->replaceArguments(CmdArgs);
static StringRef bytes(const std::vector< T, Allocator > &v)
static std::string ComplexRangeKindToStr(LangOptions::ComplexRangeKind Range)
static void ParseMPreferVectorWidth(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs)
The -mprefer-vector-width option accepts either a positive integer or the string "none".
static void RenderDebugInfoCompressionArgs(const ArgList &Args, ArgStringList &CmdArgs, const Driver &D, const ToolChain &TC)
static bool checkDebugInfoOption(const Arg *A, const ArgList &Args, const Driver &D, const ToolChain &TC)
static void RenderOpenCLOptions(const ArgList &Args, ArgStringList &CmdArgs, types::ID InputType)
static bool shouldUseExceptionTablesForObjCExceptions(const ObjCRuntime &runtime, const llvm::Triple &Triple)
static void RenderCharacterOptions(const ArgList &Args, const llvm::Triple &T, ArgStringList &CmdArgs)
static std::string RenderComplexRangeOption(LangOptions::ComplexRangeKind Range)
static void RenderDebugEnablingArgs(const ArgList &Args, ArgStringList &CmdArgs, llvm::codegenoptions::DebugInfoKind DebugInfoKind, unsigned DwarfVersion, llvm::DebuggerKind DebuggerTuning)
static void ProcessVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs)
static void renderDebugOptions(const ToolChain &TC, const Driver &D, const llvm::Triple &T, const ArgList &Args, bool IRInput, ArgStringList &CmdArgs, const InputInfo &Output, llvm::codegenoptions::DebugInfoKind &DebugInfoKind, DwarfFissionKind &DwarfFission)
static bool shouldEnableVectorizerAtOLevel(const ArgList &Args, bool isSlpVec)
Vectorize at all optimization levels greater than 1 except for -Oz.
static void RenderDiagnosticsOptions(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs)
static bool maybeHasClangPchSignature(const Driver &D, StringRef Path)
static bool addExceptionArgs(const ArgList &Args, types::ID InputType, const ToolChain &TC, bool KernelOrKext, const ObjCRuntime &objcRuntime, ArgStringList &CmdArgs)
Adds exception related arguments to the driver command arguments.
static void CheckPreprocessingOptions(const Driver &D, const ArgList &Args)
void AddAAPCSVolatileBitfieldArgs(const ArgList &Args, ArgStringList &CmdArgs)
static bool isSignedCharDefault(const llvm::Triple &Triple)
static EHFlags parseClangCLEHFlags(const Driver &D, const ArgList &Args, bool isWindowsMSVC)
/EH controls whether to run destructor cleanups when exceptions are thrown.
static bool gchProbe(const Driver &D, StringRef Path)
static void RenderOpenACCOptions(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs, types::ID InputType)
static void EmitComplexRangeDiag(const Driver &D, std::string str1, std::string str2)
static bool CheckARMImplicitITArg(StringRef Value)
static bool hasMultipleInvocations(const llvm::Triple &Triple, const ArgList &Args)
static void handleAMDGPUCodeObjectVersionOptions(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs, bool IsCC1As=false)
static void RenderARCMigrateToolOptions(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs)
static void addDashXForInput(const ArgList &Args, const InputInfo &Input, ArgStringList &CmdArgs)
Add -x lang to CmdArgs for Input.
static void ParseMRecip(const Driver &D, const ArgList &Args, ArgStringList &OutStrings)
The -mrecip flag requires processing of many optional parameters.
static void RenderHLSLOptions(const ArgList &Args, ArgStringList &CmdArgs, types::ID InputType)
static void renderDwarfFormat(const Driver &D, const llvm::Triple &T, const ArgList &Args, ArgStringList &CmdArgs, unsigned DwarfVersion)
static void RenderObjCOptions(const ToolChain &TC, const Driver &D, const llvm::Triple &T, const ArgList &Args, ObjCRuntime &Runtime, bool InferCovariantReturns, const InputInfo &Input, ArgStringList &CmdArgs)
static void addCoveragePrefixMapArg(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs)
Add a CC1 and CC1AS option to specify the coverage file path prefix map.
static void AddARMImplicitITArgs(const ArgList &Args, ArgStringList &CmdArgs, StringRef Value)
static bool checkRemarksOptions(const Driver &D, const ArgList &Args, const llvm::Triple &Triple)
static void CollectArgsForIntegratedAssembler(Compilation &C, const ArgList &Args, ArgStringList &CmdArgs, const Driver &D)
static bool RenderModulesOptions(Compilation &C, const Driver &D, const ArgList &Args, const InputInfo &Input, const InputInfo &Output, bool HaveStd20, ArgStringList &CmdArgs)
static void forAllAssociatedToolChains(Compilation &C, const JobAction &JA, const ToolChain &RegularToolChain, llvm::function_ref< void(const ToolChain &)> Work)
Apply Work on the current tool chain RegularToolChain and any other offloading tool chain that is ass...
static bool isValidSymbolName(StringRef S)
static void addMacroPrefixMapArg(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs)
Add a CC1 and CC1AS option to specify the macro file path prefix map.
static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple, const InputInfo &Input, const InputInfo &Output, const JobAction &JA)
static std::string ComplexArithmeticStr(LangOptions::ComplexRangeKind Range)
static void addDebugObjectName(const ArgList &Args, ArgStringList &CmdArgs, const char *DebugCompilationDir, const char *OutputFileName)
static bool getRefinementStep(StringRef In, const Driver &D, const Arg &A, size_t &Position)
This is a helper function for validating the optional refinement step parameter in reciprocal argumen...
static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, bool isAArch64)
static void RenderSSPOptions(const Driver &D, const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, bool KernelOrKext)
static void RenderBuiltinOptions(const ToolChain &TC, const llvm::Triple &T, const ArgList &Args, ArgStringList &CmdArgs)
static void RenderSCPOptions(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs)
static void RenderTrivialAutoVarInitOptions(const Driver &D, const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs)
static bool maybeConsumeDash(const std::string &EH, size_t &I)
static const char * addDebugCompDirArg(const ArgList &Args, ArgStringList &CmdArgs, const llvm::vfs::FileSystem &VFS)
Add a CC1 option to specify the debug compilation directory.
static void CheckCodeGenerationOptions(const Driver &D, const ArgList &Args)
static bool ShouldEnableAutolink(const ArgList &Args, const ToolChain &TC, const JobAction &JA)
static void EscapeSpacesAndBackslashes(const char *Arg, SmallVectorImpl< char > &Res)
static void addDebugPrefixMapArg(const Driver &D, const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs)
Add a CC1 and CC1AS option to specify the debug file path prefix map.
static void RenderAnalyzerOptions(const ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple, const InputInfo &Input)
static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, bool OFastEnabled, const ArgList &Args, ArgStringList &CmdArgs, const JobAction &JA)
static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C, const JobAction &JA, const InputInfo &Output, const ArgList &Args, SanitizerArgs &SanArgs, ArgStringList &CmdArgs)
static void handlePAuthABI(const ArgList &DriverArgs, ArgStringList &CC1Args)
clang::CodeGenOptions::FramePointerKind getFramePointerKind(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
Defines the clang::LangOptions interface.
llvm::MachO::Target Target
Defines types useful for describing an Objective-C runtime.
Defines version macros and version-related utility functions for Clang.
static StringRef getWarningOptionForGroup(diag::Group)
Given a group ID, returns the flag that toggles the group.
ComplexRangeKind
Controls the various implementations for complex multiplication and.
@ CX_Full
Implementation of complex division and multiplication using a call to runtime library functions(gener...
@ CX_Basic
Implementation of complex division and multiplication using algebraic formulas at source precision.
@ CX_Promoted
Implementation of complex division using algebraic formulas at higher precision.
@ CX_None
No range rule is enabled.
@ CX_Improved
Implementation of complex division offering an improved handling for overflow in intermediate calcula...
The basic abstraction for the target Objective-C runtime.
bool allowsWeak() const
Does this runtime allow the use of __weak?
bool isLegacyDispatchDefaultForArch(llvm::Triple::ArchType Arch)
The default dispatch mechanism to use for the specified architecture.
bool isNeXTFamily() const
Is this runtime basically of the NeXT family of runtimes?
const VersionTuple & getVersion() const
bool tryParse(StringRef input)
Try to parse an Objective-C runtime specification from the given string.
bool isNonFragile() const
Does this runtime follow the set of implied behaviors for a "non-fragile" ABI?
std::string getAsString() const
@ MacOSX
'macosx' is the Apple-provided NeXT-derived runtime on Mac OS X platforms that use the non-fragile AB...
@ FragileMacOSX
'macosx-fragile' is the Apple-provided NeXT-derived runtime on Mac OS X platforms that use the fragil...
@ GNUstep
'gnustep' is the modern non-fragile GNUstep runtime.
@ GCC
'gcc' is the Objective-C runtime shipped with GCC, implementing a fragile Objective-C ABI
Scope - A scope is a transient data structure that is used while parsing the program.
Scope(Scope *Parent, unsigned ScopeFlags, DiagnosticsEngine &Diag)
Action - Represent an abstract compilation step to perform.
const char * getOffloadingArch() const
types::ID getType() const
const ToolChain * getOffloadingToolChain() const
static std::string GetOffloadingFileNamePrefix(OffloadKind Kind, StringRef NormalizedTriple, bool CreatePrefixForHost=false)
Return a string that can be used as prefix in order to generate unique files for each offloading kind...
ActionClass getKind() const
static StringRef GetOffloadKindName(OffloadKind Kind)
Return a string containing a offload kind name.
OffloadKind getOffloadingDeviceKind() const
bool isHostOffloading(unsigned int OKind) const
Check if this action have any offload kinds.
bool isDeviceOffloading(OffloadKind OKind) const
bool isOffloading(OffloadKind OKind) const
Command - An executable path/name and argument vector to execute.
Compilation - A set of tasks to perform for a single driver invocation.
A class to find a viable CUDA installation.
StringRef getInstallPath() const
Get the detected Cuda installation path.
bool isValid() const
Check whether we detected a valid Cuda install.
Distro - Helper class for detecting and classifying Linux distributions.
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
static bool getDefaultModuleCachePath(SmallVectorImpl< char > &Result)
Compute the default -fmodule-cache-path.
const char * getClangProgramPath() const
Get the path to the main clang executable.
DiagnosticBuilder Diag(unsigned DiagID) const
bool isUsingOffloadLTO() const
Returns true if we are performing any kind of offload LTO.
llvm::vfs::FileSystem & getVFS() const
@ OMPRT_IOMP5
The legacy name for the LLVM OpenMP runtime from when it was the Intel OpenMP runtime.
@ OMPRT_OMP
The LLVM OpenMP runtime.
An offload action combines host or/and device actions according to the programming model implementati...
void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const
bool isHLSL(ID Id)
isHLSL - Is this an HLSL input.
bool isObjC(ID Id)
isObjC - Is this an "ObjC" input (Obj-C and Obj-C++ sources and headers).
ID getPreprocessedType(ID Id)
getPreprocessedType - Get the ID of the type for this input when it has been preprocessed,...
bool isLLVMIR(ID Id)
Is this LLVM IR.
const char * getTypeName(ID Id)
getTypeName - Return the name of the type for Id.
bool isOpenCL(ID Id)
isOpenCL - Is this an "OpenCL" input.
bool isSrcFile(ID Id)
isSrcFile - Is this a source file, i.e.
const char * getTypeTempSuffix(ID Id, bool CLStyle=false)
getTypeTempSuffix - Return the suffix to use when creating a temp file of this type,...
bool isCXX(ID Id)
isCXX - Is this a "C++" input (C++ and Obj-C++ sources and headers).
bool isOptimizationLevelFast(const llvm::opt::ArgList &Args)
bool willEmitRemarks(const llvm::opt::ArgList &Args)
@ Quoted
'#include ""' paths, added by 'gcc -iquote'.
The JSON file list parser is used to communicate input to InstallAPI.
std::optional< diag::Group > diagGroupFromCLWarningID(unsigned)
For cl.exe warning IDs that cleany map to clang diagnostic groups, returns the corresponding group.
void quoteMakeTarget(StringRef Target, SmallVectorImpl< char > &Res)
Quote target names for inclusion in GNU Make dependency files.
const char * headerIncludeFormatKindToString(HeaderIncludeFormatKind K)
const char * headerIncludeFilteringKindToString(HeaderIncludeFilteringKind K)
@ Asm
Assembly: we accept this only so that we can preprocess it.
@ Result
The result type of a method or function.
const char * CudaVersionToString(CudaVersion V)
const FunctionProtoType * T
std::string getClangFullVersion()
Retrieves a string representing the complete clang version, which includes the clang version number,...
static constexpr ResponseFileSupport None()
Returns a ResponseFileSupport indicating that response files are not supported.
static constexpr ResponseFileSupport AtFileUTF8()