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 UseRelaxRelocations =
C.getDefaultToolChain().useRelaxRelocations();
2558 bool UseNoExecStack =
false;
2560 const char *MipsTargetFeature =
nullptr;
2561 StringRef ImplicitIt;
2563 Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler,
2564 options::OPT_mimplicit_it_EQ)) {
2567 if (A->getOption().getID() == options::OPT_mimplicit_it_EQ) {
2568 switch (
C.getDefaultToolChain().getArch()) {
2569 case llvm::Triple::arm:
2570 case llvm::Triple::armeb:
2571 case llvm::Triple::thumb:
2572 case llvm::Triple::thumbeb:
2574 ImplicitIt = A->getValue();
2576 D.Diag(diag::err_drv_unsupported_option_argument)
2577 << A->getSpelling() << ImplicitIt;
2584 for (StringRef
Value : A->getValues()) {
2586 CmdArgs.push_back(
Value.data());
2587 TakeNextArg =
false;
2591 if (
C.getDefaultToolChain().getTriple().isOSBinFormatCOFF() &&
2592 Value ==
"-mbig-obj")
2596 auto checkArg = [&](
bool ValidTarget,
2597 std::initializer_list<const char *>
Set) {
2599 D.Diag(diag::err_drv_unsupported_opt_for_target)
2600 << (Twine(
"-Wa,") +
Equal.first +
"=").str()
2601 << Triple.getTriple();
2602 }
else if (!llvm::is_contained(
Set,
Equal.second)) {
2603 D.Diag(diag::err_drv_unsupported_option_argument)
2604 << (Twine(
"-Wa,") +
Equal.first +
"=").str() <<
Equal.second;
2607 switch (
C.getDefaultToolChain().getArch()) {
2610 case llvm::Triple::x86:
2611 case llvm::Triple::x86_64:
2612 if (
Equal.first ==
"-mrelax-relocations" ||
2613 Equal.first ==
"--mrelax-relocations") {
2614 UseRelaxRelocations =
Equal.second ==
"yes";
2615 checkArg(IsELF, {
"yes",
"no"});
2618 if (
Value ==
"-msse2avx") {
2619 CmdArgs.push_back(
"-msse2avx");
2623 case llvm::Triple::wasm32:
2624 case llvm::Triple::wasm64:
2625 if (
Value ==
"--no-type-check") {
2626 CmdArgs.push_back(
"-mno-type-check");
2630 case llvm::Triple::thumb:
2631 case llvm::Triple::thumbeb:
2632 case llvm::Triple::arm:
2633 case llvm::Triple::armeb:
2634 if (
Equal.first ==
"-mimplicit-it") {
2636 ImplicitIt =
Equal.second;
2637 checkArg(
true, {
"always",
"never",
"arm",
"thumb"});
2640 if (
Value ==
"-mthumb")
2645 case llvm::Triple::mips:
2646 case llvm::Triple::mipsel:
2647 case llvm::Triple::mips64:
2648 case llvm::Triple::mips64el:
2649 if (
Value ==
"--trap") {
2650 CmdArgs.push_back(
"-target-feature");
2651 CmdArgs.push_back(
"+use-tcc-in-div");
2654 if (
Value ==
"--break") {
2655 CmdArgs.push_back(
"-target-feature");
2656 CmdArgs.push_back(
"-use-tcc-in-div");
2659 if (
Value.starts_with(
"-msoft-float")) {
2660 CmdArgs.push_back(
"-target-feature");
2661 CmdArgs.push_back(
"+soft-float");
2664 if (
Value.starts_with(
"-mhard-float")) {
2665 CmdArgs.push_back(
"-target-feature");
2666 CmdArgs.push_back(
"-soft-float");
2669 if (
Value ==
"-mmsa") {
2673 if (
Value ==
"-mno-msa") {
2677 MipsTargetFeature = llvm::StringSwitch<const char *>(
Value)
2678 .Case(
"-mips1",
"+mips1")
2679 .Case(
"-mips2",
"+mips2")
2680 .Case(
"-mips3",
"+mips3")
2681 .Case(
"-mips4",
"+mips4")
2682 .Case(
"-mips5",
"+mips5")
2683 .Case(
"-mips32",
"+mips32")
2684 .Case(
"-mips32r2",
"+mips32r2")
2685 .Case(
"-mips32r3",
"+mips32r3")
2686 .Case(
"-mips32r5",
"+mips32r5")
2687 .Case(
"-mips32r6",
"+mips32r6")
2688 .Case(
"-mips64",
"+mips64")
2689 .Case(
"-mips64r2",
"+mips64r2")
2690 .Case(
"-mips64r3",
"+mips64r3")
2691 .Case(
"-mips64r5",
"+mips64r5")
2692 .Case(
"-mips64r6",
"+mips64r6")
2694 if (MipsTargetFeature)
2699 if (
Value ==
"-force_cpusubtype_ALL") {
2701 }
else if (
Value ==
"-L") {
2702 CmdArgs.push_back(
"-msave-temp-labels");
2703 }
else if (
Value ==
"--fatal-warnings") {
2704 CmdArgs.push_back(
"-massembler-fatal-warnings");
2705 }
else if (
Value ==
"--no-warn" ||
Value ==
"-W") {
2706 CmdArgs.push_back(
"-massembler-no-warn");
2707 }
else if (
Value ==
"--noexecstack") {
2708 UseNoExecStack =
true;
2709 }
else if (
Value.starts_with(
"-compress-debug-sections") ||
2710 Value.starts_with(
"--compress-debug-sections") ||
2711 Value ==
"-nocompress-debug-sections" ||
2712 Value ==
"--nocompress-debug-sections") {
2713 CmdArgs.push_back(
Value.data());
2714 }
else if (
Value ==
"--crel") {
2716 }
else if (
Value ==
"--no-crel") {
2718 }
else if (
Value ==
"--allow-experimental-crel") {
2719 ExperimentalCrel =
true;
2720 }
else if (
Value.starts_with(
"-I")) {
2721 CmdArgs.push_back(
Value.data());
2726 }
else if (
Value.starts_with(
"-gdwarf-")) {
2729 if (DwarfVersion == 0) {
2730 CmdArgs.push_back(
Value.data());
2733 llvm::codegenoptions::DebugInfoConstructor,
2734 DwarfVersion, llvm::DebuggerKind::Default);
2736 }
else if (
Value.starts_with(
"-mcpu") ||
Value.starts_with(
"-mfpu") ||
2737 Value.starts_with(
"-mhwdiv") ||
Value.starts_with(
"-march")) {
2739 }
else if (
Value ==
"-defsym" ||
Value ==
"--defsym") {
2740 if (A->getNumValues() != 2) {
2741 D.Diag(diag::err_drv_defsym_invalid_format) <<
Value;
2744 const char *S = A->getValue(1);
2745 auto Pair = StringRef(S).split(
'=');
2746 auto Sym = Pair.first;
2747 auto SVal = Pair.second;
2749 if (Sym.empty() || SVal.empty()) {
2750 D.Diag(diag::err_drv_defsym_invalid_format) << S;
2754 if (SVal.getAsInteger(0, IVal)) {
2755 D.Diag(diag::err_drv_defsym_invalid_symval) << SVal;
2758 CmdArgs.push_back(
"--defsym");
2760 }
else if (
Value ==
"-fdebug-compilation-dir") {
2761 CmdArgs.push_back(
"-fdebug-compilation-dir");
2763 }
else if (
Value.consume_front(
"-fdebug-compilation-dir=")) {
2767 CmdArgs.push_back(
"-fdebug-compilation-dir");
2768 CmdArgs.push_back(
Value.data());
2769 }
else if (
Value ==
"--version") {
2770 D.PrintVersion(
C, llvm::outs());
2772 D.Diag(diag::err_drv_unsupported_option_argument)
2773 << A->getSpelling() <<
Value;
2777 if (ImplicitIt.size())
2780 if (!ExperimentalCrel)
2781 D.Diag(diag::err_drv_experimental_crel);
2782 if (Triple.isOSBinFormatELF() && !Triple.isMIPS()) {
2783 CmdArgs.push_back(
"--crel");
2785 D.Diag(diag::err_drv_unsupported_opt_for_target)
2786 <<
"-Wa,--crel" <<
D.getTargetTriple();
2790 CmdArgs.push_back(
"-mmsa");
2791 if (!UseRelaxRelocations)
2792 CmdArgs.push_back(
"-mrelax-relocations=no");
2794 CmdArgs.push_back(
"-mnoexecstack");
2795 if (MipsTargetFeature !=
nullptr) {
2796 CmdArgs.push_back(
"-target-feature");
2797 CmdArgs.push_back(MipsTargetFeature);
2801 if (
C.getDriver().embedBitcodeEnabled() ||
2802 C.getDriver().embedBitcodeMarkerOnly())
2803 Args.AddLastArg(CmdArgs, options::OPT_fembed_bitcode_EQ);
2805 if (
const char *AsSecureLogFile = getenv(
"AS_SECURE_LOG_FILE")) {
2806 CmdArgs.push_back(
"-as-secure-log-file");
2807 CmdArgs.push_back(Args.MakeArgString(AsSecureLogFile));
2838 if ((str1.compare(str2) != 0) && !str2.empty() && !str1.empty()) {
2839 D.Diag(clang::diag::warn_drv_overriding_option) << str1 << str2;
2846 if (!ComplexRangeStr.empty())
2847 return "-complex-range=" + ComplexRangeStr;
2848 return ComplexRangeStr;
2852 bool OFastEnabled,
const ArgList &Args,
2853 ArgStringList &CmdArgs,
2860 bool HonorINFs =
true;
2861 bool HonorNaNs =
true;
2862 bool ApproxFunc =
false;
2865 bool AssociativeMath =
false;
2866 bool ReciprocalMath =
false;
2867 bool SignedZeros =
true;
2868 bool TrappingMath =
false;
2869 bool TrappingMathPresent =
false;
2871 bool RoundingFPMath =
false;
2873 StringRef FPModel =
"";
2875 StringRef FPExceptionBehavior =
"";
2877 StringRef FPEvalMethod =
"";
2878 llvm::DenormalMode DenormalFPMath =
2880 llvm::DenormalMode DenormalFP32Math =
2885 StringRef FPContract;
2886 StringRef LastSeenFfpContractOption;
2887 StringRef LastFpContractOverrideOption;
2888 bool SeenUnsafeMathModeOption =
false;
2892 bool StrictFPModel =
false;
2893 StringRef Float16ExcessPrecision =
"";
2894 StringRef BFloat16ExcessPrecision =
"";
2896 std::string ComplexRangeStr =
"";
2897 std::string GccRangeComplexOption =
"";
2902 if (
Range != NewRange)
2904 !GccRangeComplexOption.empty()
2905 ? GccRangeComplexOption
2912 auto applyFastMath = [&](
bool Aggressive) {
2923 AssociativeMath =
true;
2924 ReciprocalMath =
true;
2926 SignedZeros =
false;
2927 TrappingMath =
false;
2928 RoundingFPMath =
false;
2929 FPExceptionBehavior =
"";
2930 FPContract =
"fast";
2931 SeenUnsafeMathModeOption =
true;
2935 auto restoreFPContractState = [&]() {
2945 if (LastSeenFfpContractOption !=
"")
2946 FPContract = LastSeenFfpContractOption;
2947 else if (SeenUnsafeMathModeOption)
2952 LastFpContractOverrideOption =
"";
2955 if (
const Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) {
2956 CmdArgs.push_back(
"-mlimit-float-precision");
2957 CmdArgs.push_back(A->getValue());
2960 for (
const Arg *A : Args) {
2961 switch (A->getOption().getID()) {
2965 case options::OPT_fcx_limited_range:
2966 if (GccRangeComplexOption.empty()) {
2969 "-fcx-limited-range");
2971 if (GccRangeComplexOption !=
"-fno-cx-limited-range")
2974 GccRangeComplexOption =
"-fcx-limited-range";
2977 case options::OPT_fno_cx_limited_range:
2978 if (GccRangeComplexOption.empty()) {
2980 "-fno-cx-limited-range");
2982 if (GccRangeComplexOption.compare(
"-fcx-limited-range") != 0 &&
2983 GccRangeComplexOption.compare(
"-fno-cx-fortran-rules") != 0)
2985 "-fno-cx-limited-range");
2987 GccRangeComplexOption =
"-fno-cx-limited-range";
2990 case options::OPT_fcx_fortran_rules:
2991 if (GccRangeComplexOption.empty())
2993 "-fcx-fortran-rules");
2996 GccRangeComplexOption =
"-fcx-fortran-rules";
2999 case options::OPT_fno_cx_fortran_rules:
3000 if (GccRangeComplexOption.empty()) {
3002 "-fno-cx-fortran-rules");
3004 if (GccRangeComplexOption !=
"-fno-cx-limited-range")
3006 "-fno-cx-fortran-rules");
3008 GccRangeComplexOption =
"-fno-cx-fortran-rules";
3011 case options::OPT_fcomplex_arithmetic_EQ: {
3013 StringRef Val = A->getValue();
3016 else if (Val ==
"improved")
3018 else if (Val ==
"promoted")
3020 else if (Val ==
"basic")
3023 D.Diag(diag::err_drv_unsupported_option_argument)
3024 << A->getSpelling() << Val;
3027 if (!GccRangeComplexOption.empty()) {
3028 if (GccRangeComplexOption.compare(
"-fcx-limited-range") != 0) {
3029 if (GccRangeComplexOption.compare(
"-fcx-fortran-rules") != 0) {
3046 case options::OPT_ffp_model_EQ: {
3053 AssociativeMath =
false;
3054 ReciprocalMath =
false;
3057 StringRef Val = A->getValue();
3058 if (OFastEnabled && Val !=
"aggressive") {
3060 D.Diag(clang::diag::warn_drv_overriding_option)
3061 << Args.MakeArgString(
"-ffp-model=" + Val) <<
"-Ofast";
3064 StrictFPModel =
false;
3065 if (!FPModel.empty() && FPModel != Val)
3066 D.Diag(clang::diag::warn_drv_overriding_option)
3067 << Args.MakeArgString(
"-ffp-model=" + FPModel)
3068 << Args.MakeArgString(
"-ffp-model=" + Val);
3069 if (Val ==
"fast") {
3071 applyFastMath(
false);
3073 LastFpContractOverrideOption =
"-ffp-model=fast";
3074 }
else if (Val ==
"aggressive") {
3076 applyFastMath(
true);
3078 LastFpContractOverrideOption =
"-ffp-model=aggressive";
3079 }
else if (Val ==
"precise") {
3082 LastFpContractOverrideOption =
"-ffp-model=precise";
3084 }
else if (Val ==
"strict") {
3085 StrictFPModel =
true;
3086 FPExceptionBehavior =
"strict";
3089 LastFpContractOverrideOption =
"-ffp-model=strict";
3090 TrappingMath =
true;
3091 RoundingFPMath =
true;
3094 D.Diag(diag::err_drv_unsupported_option_argument)
3095 << A->getSpelling() << Val;
3100 case options::OPT_fhonor_infinities: HonorINFs =
true;
break;
3101 case options::OPT_fno_honor_infinities: HonorINFs =
false;
break;
3102 case options::OPT_fhonor_nans: HonorNaNs =
true;
break;
3103 case options::OPT_fno_honor_nans: HonorNaNs =
false;
break;
3104 case options::OPT_fapprox_func: ApproxFunc =
true;
break;
3105 case options::OPT_fno_approx_func: ApproxFunc =
false;
break;
3106 case options::OPT_fmath_errno: MathErrno =
true;
break;
3107 case options::OPT_fno_math_errno: MathErrno =
false;
break;
3108 case options::OPT_fassociative_math: AssociativeMath =
true;
break;
3109 case options::OPT_fno_associative_math: AssociativeMath =
false;
break;
3110 case options::OPT_freciprocal_math: ReciprocalMath =
true;
break;
3111 case options::OPT_fno_reciprocal_math: ReciprocalMath =
false;
break;
3112 case options::OPT_fsigned_zeros: SignedZeros =
true;
break;
3113 case options::OPT_fno_signed_zeros: SignedZeros =
false;
break;
3114 case options::OPT_ftrapping_math:
3115 if (!TrappingMathPresent && !FPExceptionBehavior.empty() &&
3116 FPExceptionBehavior !=
"strict")
3118 D.Diag(clang::diag::warn_drv_overriding_option)
3119 << Args.MakeArgString(
"-ffp-exception-behavior=" +
3120 FPExceptionBehavior)
3121 <<
"-ftrapping-math";
3122 TrappingMath =
true;
3123 TrappingMathPresent =
true;
3124 FPExceptionBehavior =
"strict";
3126 case options::OPT_fno_trapping_math:
3127 if (!TrappingMathPresent && !FPExceptionBehavior.empty() &&
3128 FPExceptionBehavior !=
"ignore")
3130 D.Diag(clang::diag::warn_drv_overriding_option)
3131 << Args.MakeArgString(
"-ffp-exception-behavior=" +
3132 FPExceptionBehavior)
3133 <<
"-fno-trapping-math";
3134 TrappingMath =
false;
3135 TrappingMathPresent =
true;
3136 FPExceptionBehavior =
"ignore";
3139 case options::OPT_frounding_math:
3140 RoundingFPMath =
true;
3143 case options::OPT_fno_rounding_math:
3144 RoundingFPMath =
false;
3147 case options::OPT_fdenormal_fp_math_EQ:
3148 DenormalFPMath = llvm::parseDenormalFPAttribute(A->getValue());
3149 DenormalFP32Math = DenormalFPMath;
3150 if (!DenormalFPMath.isValid()) {
3151 D.Diag(diag::err_drv_invalid_value)
3152 << A->getAsString(Args) << A->getValue();
3156 case options::OPT_fdenormal_fp_math_f32_EQ:
3157 DenormalFP32Math = llvm::parseDenormalFPAttribute(A->getValue());
3158 if (!DenormalFP32Math.isValid()) {
3159 D.Diag(diag::err_drv_invalid_value)
3160 << A->getAsString(Args) << A->getValue();
3165 case options::OPT_ffp_contract: {
3166 StringRef Val = A->getValue();
3167 if (Val ==
"fast" || Val ==
"on" || Val ==
"off" ||
3168 Val ==
"fast-honor-pragmas") {
3169 if (Val != FPContract && LastFpContractOverrideOption !=
"") {
3170 D.Diag(clang::diag::warn_drv_overriding_option)
3171 << LastFpContractOverrideOption
3172 << Args.MakeArgString(
"-ffp-contract=" + Val);
3176 LastSeenFfpContractOption = Val;
3177 LastFpContractOverrideOption =
"";
3179 D.Diag(diag::err_drv_unsupported_option_argument)
3180 << A->getSpelling() << Val;
3185 case options::OPT_ffp_exception_behavior_EQ: {
3186 StringRef Val = A->getValue();
3187 if (!TrappingMathPresent && !FPExceptionBehavior.empty() &&
3188 FPExceptionBehavior != Val)
3190 D.Diag(clang::diag::warn_drv_overriding_option)
3191 << Args.MakeArgString(
"-ffp-exception-behavior=" +
3192 FPExceptionBehavior)
3193 << Args.MakeArgString(
"-ffp-exception-behavior=" + Val);
3194 TrappingMath = TrappingMathPresent =
false;
3195 if (Val ==
"ignore" || Val ==
"maytrap")
3196 FPExceptionBehavior = Val;
3197 else if (Val ==
"strict") {
3198 FPExceptionBehavior = Val;
3199 TrappingMath = TrappingMathPresent =
true;
3201 D.Diag(diag::err_drv_unsupported_option_argument)
3202 << A->getSpelling() << Val;
3207 case options::OPT_ffp_eval_method_EQ: {
3208 StringRef Val = A->getValue();
3209 if (Val ==
"double" || Val ==
"extended" || Val ==
"source")
3212 D.Diag(diag::err_drv_unsupported_option_argument)
3213 << A->getSpelling() << Val;
3217 case options::OPT_fexcess_precision_EQ: {
3218 StringRef Val = A->getValue();
3219 const llvm::Triple::ArchType Arch = TC.
getArch();
3220 if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) {
3221 if (Val ==
"standard" || Val ==
"fast")
3222 Float16ExcessPrecision = Val;
3226 else if (Val ==
"16")
3227 Float16ExcessPrecision =
"none";
3229 D.Diag(diag::err_drv_unsupported_option_argument)
3230 << A->getSpelling() << Val;
3232 if (!(Val ==
"standard" || Val ==
"fast"))
3233 D.Diag(diag::err_drv_unsupported_option_argument)
3234 << A->getSpelling() << Val;
3236 BFloat16ExcessPrecision = Float16ExcessPrecision;
3239 case options::OPT_ffinite_math_only:
3243 case options::OPT_fno_finite_math_only:
3248 case options::OPT_funsafe_math_optimizations:
3249 AssociativeMath =
true;
3250 ReciprocalMath =
true;
3251 SignedZeros =
false;
3253 TrappingMath =
false;
3254 FPExceptionBehavior =
"";
3255 FPContract =
"fast";
3256 LastFpContractOverrideOption =
"-funsafe-math-optimizations";
3257 SeenUnsafeMathModeOption =
true;
3259 case options::OPT_fno_unsafe_math_optimizations:
3260 AssociativeMath =
false;
3261 ReciprocalMath =
false;
3264 restoreFPContractState();
3267 case options::OPT_Ofast:
3272 case options::OPT_ffast_math:
3273 applyFastMath(
true);
3274 if (A->getOption().getID() == options::OPT_Ofast)
3275 LastFpContractOverrideOption =
"-Ofast";
3277 LastFpContractOverrideOption =
"-ffast-math";
3279 case options::OPT_fno_fast_math:
3286 AssociativeMath =
false;
3287 ReciprocalMath =
false;
3290 restoreFPContractState();
3291 LastFpContractOverrideOption =
"";
3301 if (StrictFPModel) {
3304 if (HonorINFs && HonorNaNs && !AssociativeMath && !ReciprocalMath &&
3305 SignedZeros && TrappingMath && RoundingFPMath && !ApproxFunc &&
3306 FPContract ==
"off")
3310 StrictFPModel =
false;
3315 auto RHS = (A->getNumValues() == 0)
3317 : Args.MakeArgString(A->getSpelling() + A->getValue());
3318 if (A->getSpelling() !=
"-ffp-contract=") {
3319 if (RHS !=
"-ffp-model=strict")
3320 D.Diag(clang::diag::warn_drv_overriding_option)
3321 <<
"-ffp-model=strict" << RHS;
3331 CmdArgs.push_back(
"-menable-no-infs");
3334 CmdArgs.push_back(
"-menable-no-nans");
3337 CmdArgs.push_back(
"-fapprox-func");
3340 CmdArgs.push_back(
"-fmath-errno");
3342 if (AssociativeMath && ReciprocalMath && !SignedZeros && ApproxFunc &&
3344 CmdArgs.push_back(
"-funsafe-math-optimizations");
3347 CmdArgs.push_back(
"-fno-signed-zeros");
3349 if (AssociativeMath && !SignedZeros && !TrappingMath)
3350 CmdArgs.push_back(
"-mreassociate");
3353 CmdArgs.push_back(
"-freciprocal-math");
3357 assert(FPExceptionBehavior ==
"strict");
3361 if (DenormalFPMath != llvm::DenormalMode::getIEEE()) {
3363 llvm::raw_svector_ostream ArgStr(DenormFlag);
3364 ArgStr <<
"-fdenormal-fp-math=" << DenormalFPMath;
3365 CmdArgs.push_back(Args.MakeArgString(ArgStr.str()));
3369 if (DenormalFP32Math != DenormalFPMath) {
3371 llvm::raw_svector_ostream ArgStr(DenormFlag);
3372 ArgStr <<
"-fdenormal-fp-math-f32=" << DenormalFP32Math;
3373 CmdArgs.push_back(Args.MakeArgString(ArgStr.str()));
3376 if (!FPContract.empty())
3377 CmdArgs.push_back(Args.MakeArgString(
"-ffp-contract=" + FPContract));
3380 CmdArgs.push_back(Args.MakeArgString(
"-frounding-math"));
3382 CmdArgs.push_back(Args.MakeArgString(
"-fno-rounding-math"));
3384 if (!FPExceptionBehavior.empty())
3385 CmdArgs.push_back(Args.MakeArgString(
"-ffp-exception-behavior=" +
3386 FPExceptionBehavior));
3388 if (!FPEvalMethod.empty())
3389 CmdArgs.push_back(Args.MakeArgString(
"-ffp-eval-method=" + FPEvalMethod));
3391 if (!Float16ExcessPrecision.empty())
3392 CmdArgs.push_back(Args.MakeArgString(
"-ffloat16-excess-precision=" +
3393 Float16ExcessPrecision));
3394 if (!BFloat16ExcessPrecision.empty())
3395 CmdArgs.push_back(Args.MakeArgString(
"-fbfloat16-excess-precision=" +
3396 BFloat16ExcessPrecision));
3403 if (!HonorINFs && !HonorNaNs && !MathErrno && AssociativeMath && ApproxFunc &&
3404 ReciprocalMath && !SignedZeros && !TrappingMath && !RoundingFPMath)
3405 CmdArgs.push_back(
"-ffast-math");
3411 bool shouldAddFiniteMathOnly =
false;
3412 if (!HonorINFs && !HonorNaNs) {
3413 shouldAddFiniteMathOnly =
true;
3415 bool InfValues =
true;
3416 bool NanValues =
true;
3417 for (
const auto *Arg : Args.filtered(options::OPT_Xclang)) {
3418 StringRef ArgValue = Arg->getValue();
3419 if (ArgValue ==
"-menable-no-nans")
3421 else if (ArgValue ==
"-menable-no-infs")
3424 if (!NanValues && !InfValues)
3425 shouldAddFiniteMathOnly =
true;
3427 if (shouldAddFiniteMathOnly) {
3428 CmdArgs.push_back(
"-ffinite-math-only");
3430 if (
const Arg *A = Args.getLastArg(options::OPT_mfpmath_EQ)) {
3431 CmdArgs.push_back(
"-mfpmath");
3432 CmdArgs.push_back(A->getValue());
3436 if (Args.hasFlag(options::OPT_fno_strict_float_cast_overflow,
3437 options::OPT_fstrict_float_cast_overflow,
false))
3438 CmdArgs.push_back(
"-fno-strict-float-cast-overflow");
3442 if (!ComplexRangeStr.empty()) {
3443 CmdArgs.push_back(Args.MakeArgString(ComplexRangeStr));
3444 if (Args.hasArg(options::OPT_fcomplex_arithmetic_EQ))
3445 CmdArgs.push_back(Args.MakeArgString(
"-fcomplex-arithmetic=" +
3448 if (Args.hasArg(options::OPT_fcx_limited_range))
3449 CmdArgs.push_back(
"-fcx-limited-range");
3450 if (Args.hasArg(options::OPT_fcx_fortran_rules))
3451 CmdArgs.push_back(
"-fcx-fortran-rules");
3452 if (Args.hasArg(options::OPT_fno_cx_limited_range))
3453 CmdArgs.push_back(
"-fno-cx-limited-range");
3454 if (Args.hasArg(options::OPT_fno_cx_fortran_rules))
3455 CmdArgs.push_back(
"-fno-cx-fortran-rules");
3459 const llvm::Triple &Triple,
3462 if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) {
3463 CmdArgs.push_back(
"-analyzer-checker=core");
3464 CmdArgs.push_back(
"-analyzer-checker=apiModeling");
3466 if (!Triple.isWindowsMSVCEnvironment()) {
3467 CmdArgs.push_back(
"-analyzer-checker=unix");
3470 CmdArgs.push_back(
"-analyzer-checker=unix.API");
3471 CmdArgs.push_back(
"-analyzer-checker=unix.Malloc");
3472 CmdArgs.push_back(
"-analyzer-checker=unix.MallocSizeof");
3473 CmdArgs.push_back(
"-analyzer-checker=unix.MismatchedDeallocator");
3474 CmdArgs.push_back(
"-analyzer-checker=unix.cstring.BadSizeArg");
3475 CmdArgs.push_back(
"-analyzer-checker=unix.cstring.NullArg");
3479 if (Triple.isPS()) {
3480 CmdArgs.push_back(
"-analyzer-disable-checker=unix.API");
3481 CmdArgs.push_back(
"-analyzer-disable-checker=unix.Vfork");
3484 if (Triple.isOSDarwin()) {
3485 CmdArgs.push_back(
"-analyzer-checker=osx");
3487 "-analyzer-checker=security.insecureAPI.decodeValueOfObjCType");
3489 else if (Triple.isOSFuchsia())
3490 CmdArgs.push_back(
"-analyzer-checker=fuchsia");
3492 CmdArgs.push_back(
"-analyzer-checker=deadcode");
3495 CmdArgs.push_back(
"-analyzer-checker=cplusplus");
3497 if (!Triple.isPS()) {
3498 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.UncheckedReturn");
3499 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.getpw");
3500 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.gets");
3501 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.mktemp");
3502 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.mkstemp");
3503 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.vfork");
3507 CmdArgs.push_back(
"-analyzer-checker=nullability.NullPassedToNonnull");
3508 CmdArgs.push_back(
"-analyzer-checker=nullability.NullReturnedFromNonnull");
3512 CmdArgs.push_back(
"-analyzer-output");
3513 if (Arg *A = Args.getLastArg(options::OPT__analyzer_output))
3514 CmdArgs.push_back(A->getValue());
3516 CmdArgs.push_back(
"plist");
3521 CmdArgs.push_back(
"-w");
3524 Args.AddAllArgValues(CmdArgs, options::OPT_Xanalyzer);
3531 if (std::isdigit(S[0]))
3534 return llvm::all_of(S, [](
char C) {
return std::isalnum(
C) ||
C ==
'_'; });
3538 const ArgList &Args, ArgStringList &CmdArgs,
3539 bool KernelOrKext) {
3544 if (EffectiveTriple.isNVPTX())
3552 if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector,
3553 options::OPT_fstack_protector_all,
3554 options::OPT_fstack_protector_strong,
3555 options::OPT_fstack_protector)) {
3556 if (A->getOption().matches(options::OPT_fstack_protector))
3557 StackProtectorLevel =
3559 else if (A->getOption().matches(options::OPT_fstack_protector_strong))
3561 else if (A->getOption().matches(options::OPT_fstack_protector_all))
3565 D.Diag(diag::warn_drv_unsupported_option_for_target)
3566 << A->getSpelling() << EffectiveTriple.getTriple();
3567 StackProtectorLevel = DefaultStackProtectorLevel;
3570 StackProtectorLevel = DefaultStackProtectorLevel;
3573 if (StackProtectorLevel) {
3574 CmdArgs.push_back(
"-stack-protector");
3575 CmdArgs.push_back(Args.MakeArgString(Twine(StackProtectorLevel)));
3579 for (
const Arg *A : Args.filtered(options::OPT__param)) {
3580 StringRef Str(A->getValue());
3581 if (Str.starts_with(
"ssp-buffer-size=")) {
3582 if (StackProtectorLevel) {
3583 CmdArgs.push_back(
"-stack-protector-buffer-size");
3585 CmdArgs.push_back(Args.MakeArgString(Str.drop_front(16)));
3591 const std::string &TripleStr = EffectiveTriple.getTriple();
3592 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_EQ)) {
3593 StringRef
Value = A->getValue();
3594 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
3595 !EffectiveTriple.isARM() && !EffectiveTriple.isThumb())
3596 D.Diag(diag::err_drv_unsupported_opt_for_target)
3597 << A->getAsString(Args) << TripleStr;
3598 if ((EffectiveTriple.isX86() || EffectiveTriple.isARM() ||
3599 EffectiveTriple.isThumb()) &&
3601 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3602 << A->getOption().getName() <<
Value <<
"tls global";
3605 if ((EffectiveTriple.isARM() || EffectiveTriple.isThumb()) &&
3607 if (!Args.hasArg(options::OPT_mstack_protector_guard_offset_EQ)) {
3608 D.Diag(diag::err_drv_ssp_missing_offset_argument)
3609 << A->getAsString(Args);
3614 D.Diag(diag::err_target_unsupported_tp_hard)
3615 << EffectiveTriple.getArchName();
3619 if (Arg *A = Args.getLastArg(options::OPT_mtp_mode_EQ)) {
3620 StringRef
Value = A->getValue();
3621 if (
Value !=
"cp15") {
3622 D.Diag(diag::err_drv_argument_not_allowed_with)
3623 << A->getAsString(Args) <<
"-mstack-protector-guard=tls";
3627 CmdArgs.push_back(
"-target-feature");
3628 CmdArgs.push_back(
"+read-tp-tpidruro");
3630 if (EffectiveTriple.isAArch64() &&
Value !=
"sysreg" &&
Value !=
"global") {
3631 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3632 << A->getOption().getName() <<
Value <<
"sysreg global";
3635 A->render(Args, CmdArgs);
3638 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_offset_EQ)) {
3639 StringRef
Value = A->getValue();
3640 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
3641 !EffectiveTriple.isARM() && !EffectiveTriple.isThumb())
3642 D.Diag(diag::err_drv_unsupported_opt_for_target)
3643 << A->getAsString(Args) << TripleStr;
3645 if (
Value.getAsInteger(10, Offset)) {
3646 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() <<
Value;
3649 if ((EffectiveTriple.isARM() || EffectiveTriple.isThumb()) &&
3650 (Offset < 0 || Offset > 0xfffff)) {
3651 D.Diag(diag::err_drv_invalid_int_value)
3652 << A->getOption().getName() <<
Value;
3655 A->render(Args, CmdArgs);
3658 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_reg_EQ)) {
3659 StringRef
Value = A->getValue();
3660 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64())
3661 D.Diag(diag::err_drv_unsupported_opt_for_target)
3662 << A->getAsString(Args) << TripleStr;
3663 if (EffectiveTriple.isX86() && (
Value !=
"fs" &&
Value !=
"gs")) {
3664 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3665 << A->getOption().getName() <<
Value <<
"fs gs";
3668 if (EffectiveTriple.isAArch64() &&
Value !=
"sp_el0") {
3669 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() <<
Value;
3672 A->render(Args, CmdArgs);
3675 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_symbol_EQ)) {
3676 StringRef
Value = A->getValue();
3678 D.Diag(diag::err_drv_argument_only_allowed_with)
3679 << A->getOption().getName() <<
"legal symbol name";
3682 A->render(Args, CmdArgs);
3687 ArgStringList &CmdArgs) {
3690 if (!EffectiveTriple.isOSFreeBSD() && !EffectiveTriple.isOSLinux())
3693 if (!EffectiveTriple.isX86() && !EffectiveTriple.isSystemZ() &&
3694 !EffectiveTriple.isPPC64() && !EffectiveTriple.isAArch64())
3697 Args.addOptInFlag(CmdArgs, options::OPT_fstack_clash_protection,
3698 options::OPT_fno_stack_clash_protection);
3703 const ArgList &Args,
3704 ArgStringList &CmdArgs) {
3706 StringRef TrivialAutoVarInit =
"";
3708 for (
const Arg *A : Args) {
3709 switch (A->getOption().getID()) {
3712 case options::OPT_ftrivial_auto_var_init: {
3714 StringRef Val = A->getValue();
3715 if (Val ==
"uninitialized" || Val ==
"zero" || Val ==
"pattern")
3716 TrivialAutoVarInit = Val;
3718 D.Diag(diag::err_drv_unsupported_option_argument)
3719 << A->getSpelling() << Val;
3725 if (TrivialAutoVarInit.empty())
3726 switch (DefaultTrivialAutoVarInit) {
3730 TrivialAutoVarInit =
"pattern";
3733 TrivialAutoVarInit =
"zero";
3737 if (!TrivialAutoVarInit.empty()) {
3739 Args.MakeArgString(
"-ftrivial-auto-var-init=" + TrivialAutoVarInit));
3743 Args.getLastArg(options::OPT_ftrivial_auto_var_init_stop_after)) {
3744 if (!Args.hasArg(options::OPT_ftrivial_auto_var_init) ||
3746 Args.getLastArg(options::OPT_ftrivial_auto_var_init)->getValue()) ==
3748 D.Diag(diag::err_drv_trivial_auto_var_init_stop_after_missing_dependency);
3750 StringRef Val = A->getValue();
3751 if (std::stoi(Val.str()) <= 0)
3752 D.Diag(diag::err_drv_trivial_auto_var_init_stop_after_invalid_value);
3754 Args.MakeArgString(
"-ftrivial-auto-var-init-stop-after=" + Val));
3757 if (Arg *A = Args.getLastArg(options::OPT_ftrivial_auto_var_init_max_size)) {
3758 if (!Args.hasArg(options::OPT_ftrivial_auto_var_init) ||
3760 Args.getLastArg(options::OPT_ftrivial_auto_var_init)->getValue()) ==
3762 D.Diag(diag::err_drv_trivial_auto_var_init_max_size_missing_dependency);
3764 StringRef Val = A->getValue();
3765 if (std::stoi(Val.str()) <= 0)
3766 D.Diag(diag::err_drv_trivial_auto_var_init_max_size_invalid_value);
3768 Args.MakeArgString(
"-ftrivial-auto-var-init-max-size=" + Val));
3776 const unsigned ForwardedArguments[] = {
3777 options::OPT_cl_opt_disable,
3778 options::OPT_cl_strict_aliasing,
3779 options::OPT_cl_single_precision_constant,
3780 options::OPT_cl_finite_math_only,
3781 options::OPT_cl_kernel_arg_info,
3782 options::OPT_cl_unsafe_math_optimizations,
3783 options::OPT_cl_fast_relaxed_math,
3784 options::OPT_cl_mad_enable,
3785 options::OPT_cl_no_signed_zeros,
3786 options::OPT_cl_fp32_correctly_rounded_divide_sqrt,
3787 options::OPT_cl_uniform_work_group_size
3790 if (Arg *A = Args.getLastArg(options::OPT_cl_std_EQ)) {
3791 std::string CLStdStr = std::string(
"-cl-std=") + A->getValue();
3792 CmdArgs.push_back(Args.MakeArgString(CLStdStr));
3793 }
else if (Arg *A = Args.getLastArg(options::OPT_cl_ext_EQ)) {
3794 std::string CLExtStr = std::string(
"-cl-ext=") + A->getValue();
3795 CmdArgs.push_back(Args.MakeArgString(CLExtStr));
3798 if (Args.hasArg(options::OPT_cl_finite_math_only)) {
3799 CmdArgs.push_back(
"-menable-no-infs");
3800 CmdArgs.push_back(
"-menable-no-nans");
3803 for (
const auto &Arg : ForwardedArguments)
3804 if (
const auto *A = Args.getLastArg(Arg))
3805 CmdArgs.push_back(Args.MakeArgString(A->getOption().getPrefixedName()));
3810 !Args.hasArg(options::OPT_cl_no_stdinc)) {
3811 CmdArgs.push_back(
"-finclude-default-header");
3812 CmdArgs.push_back(
"-fdeclare-opencl-builtins");
3818 const unsigned ForwardedArguments[] = {options::OPT_dxil_validator_version,
3822 options::OPT_emit_llvm,
3823 options::OPT_emit_obj,
3824 options::OPT_disable_llvm_passes,
3825 options::OPT_fnative_half_type,
3826 options::OPT_hlsl_entrypoint};
3829 for (
const auto &Arg : ForwardedArguments)
3830 if (
const auto *A = Args.getLastArg(Arg))
3831 A->renderAsInput(Args, CmdArgs);
3833 if (!Args.hasArg(options::OPT_dxc_no_stdinc) &&
3834 !Args.hasArg(options::OPT_nostdinc))
3835 CmdArgs.push_back(
"-finclude-default-header");
3839 ArgStringList &CmdArgs,
types::ID InputType) {
3840 if (!Args.hasArg(options::OPT_fopenacc))
3843 CmdArgs.push_back(
"-fopenacc");
3845 if (Arg *A = Args.getLastArg(options::OPT_openacc_macro_override)) {
3846 StringRef
Value = A->getValue();
3848 if (!
Value.getAsInteger(10, Version))
3849 A->renderAsInput(Args, CmdArgs);
3851 D.Diag(diag::err_drv_clang_unsupported) <<
Value;
3856 ArgStringList &CmdArgs) {
3857 bool ARCMTEnabled =
false;
3858 if (!Args.hasArg(options::OPT_fno_objc_arc, options::OPT_fobjc_arc)) {
3859 if (
const Arg *A = Args.getLastArg(options::OPT_ccc_arcmt_check,
3860 options::OPT_ccc_arcmt_modify,
3861 options::OPT_ccc_arcmt_migrate)) {
3862 ARCMTEnabled =
true;
3863 switch (A->getOption().getID()) {
3864 default: llvm_unreachable(
"missed a case");
3865 case options::OPT_ccc_arcmt_check:
3866 CmdArgs.push_back(
"-arcmt-action=check");
3868 case options::OPT_ccc_arcmt_modify:
3869 CmdArgs.push_back(
"-arcmt-action=modify");
3871 case options::OPT_ccc_arcmt_migrate:
3872 CmdArgs.push_back(
"-arcmt-action=migrate");
3873 CmdArgs.push_back(
"-mt-migrate-directory");
3874 CmdArgs.push_back(A->getValue());
3876 Args.AddLastArg(CmdArgs, options::OPT_arcmt_migrate_report_output);
3877 Args.AddLastArg(CmdArgs, options::OPT_arcmt_migrate_emit_arc_errors);
3882 Args.ClaimAllArgs(options::OPT_ccc_arcmt_check);
3883 Args.ClaimAllArgs(options::OPT_ccc_arcmt_modify);
3884 Args.ClaimAllArgs(options::OPT_ccc_arcmt_migrate);
3887 if (
const Arg *A = Args.getLastArg(options::OPT_ccc_objcmt_migrate)) {
3889 D.Diag(diag::err_drv_argument_not_allowed_with)
3890 << A->getAsString(Args) <<
"-ccc-arcmt-migrate";
3892 CmdArgs.push_back(
"-mt-migrate-directory");
3893 CmdArgs.push_back(A->getValue());
3895 if (!Args.hasArg(options::OPT_objcmt_migrate_literals,
3896 options::OPT_objcmt_migrate_subscripting,
3897 options::OPT_objcmt_migrate_property)) {
3899 CmdArgs.push_back(
"-objcmt-migrate-literals");
3900 CmdArgs.push_back(
"-objcmt-migrate-subscripting");
3901 CmdArgs.push_back(
"-objcmt-migrate-property");
3903 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_literals);
3904 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_subscripting);
3905 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_property);
3908 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_literals);
3909 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_subscripting);
3910 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_property);
3911 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_all);
3912 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_readonly_property);
3913 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_readwrite_property);
3914 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_property_dot_syntax);
3915 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_annotation);
3916 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_instancetype);
3917 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_nsmacros);
3918 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_protocol_conformance);
3919 Args.AddLastArg(CmdArgs, options::OPT_objcmt_atomic_property);
3920 Args.AddLastArg(CmdArgs, options::OPT_objcmt_returns_innerpointer_property);
3921 Args.AddLastArg(CmdArgs, options::OPT_objcmt_ns_nonatomic_iosonly);
3922 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_designated_init);
3923 Args.AddLastArg(CmdArgs, options::OPT_objcmt_allowlist_dir_path);
3928 const ArgList &Args, ArgStringList &CmdArgs) {
3931 Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin,
3932 !Args.hasArg(options::OPT_mkernel));
3934 CmdArgs.push_back(
"-fno-builtin");
3937 if (Args.hasArg(options::OPT_ffreestanding))
3938 UseBuiltins =
false;
3941 for (
const Arg *A : Args.filtered(options::OPT_fno_builtin_)) {
3947 A->render(Args, CmdArgs);
3952 if (
const char *Str = std::getenv(
"CLANG_MODULE_CACHE_PATH")) {
3955 return Path.getSingleStringRef() !=
"";
3957 if (llvm::sys::path::cache_directory(
Result)) {
3958 llvm::sys::path::append(
Result,
"clang");
3959 llvm::sys::path::append(
Result,
"ModuleCache");
3967 const char *BaseInput) {
3968 if (Arg *ModuleOutputEQ = Args.getLastArg(options::OPT_fmodule_output_EQ))
3969 return StringRef(ModuleOutputEQ->getValue());
3972 if (Arg *FinalOutput = Args.getLastArg(options::OPT_o);
3973 FinalOutput && Args.hasArg(options::OPT_c))
3974 OutputPath = FinalOutput->getValue();
3976 OutputPath = BaseInput;
3979 llvm::sys::path::replace_extension(OutputPath, Extension);
3984 const ArgList &Args,
const InputInfo &Input,
3985 const InputInfo &Output,
bool HaveStd20,
3986 ArgStringList &CmdArgs) {
3988 bool HaveStdCXXModules = IsCXX && HaveStd20;
3989 bool HaveModules = HaveStdCXXModules;
3994 bool HaveClangModules =
false;
3995 if (Args.hasFlag(options::OPT_fmodules, options::OPT_fno_modules,
false)) {
3996 bool AllowedInCXX = Args.hasFlag(options::OPT_fcxx_modules,
3997 options::OPT_fno_cxx_modules,
true);
3998 if (AllowedInCXX || !IsCXX) {
3999 CmdArgs.push_back(
"-fmodules");
4000 HaveClangModules =
true;
4004 HaveModules |= HaveClangModules;
4008 if (Args.hasFlag(options::OPT_fimplicit_module_maps,
4009 options::OPT_fno_implicit_module_maps, HaveClangModules))
4010 CmdArgs.push_back(
"-fimplicit-module-maps");
4013 Args.addOptInFlag(CmdArgs, options::OPT_fmodules_decluse,
4014 options::OPT_fno_modules_decluse);
4018 if (Args.hasFlag(options::OPT_fmodules_strict_decluse,
4019 options::OPT_fno_modules_strict_decluse,
false))
4020 CmdArgs.push_back(
"-fmodules-strict-decluse");
4022 Args.addOptOutFlag(CmdArgs, options::OPT_fmodulemap_allow_subdirectory_search,
4023 options::OPT_fno_modulemap_allow_subdirectory_search);
4026 bool ImplicitModules =
false;
4027 if (!Args.hasFlag(options::OPT_fimplicit_modules,
4028 options::OPT_fno_implicit_modules, HaveClangModules)) {
4030 CmdArgs.push_back(
"-fno-implicit-modules");
4031 }
else if (HaveModules) {
4032 ImplicitModules =
true;
4036 if (Arg *A = Args.getLastArg(options::OPT_fmodules_cache_path))
4037 Path = A->getValue();
4039 bool HasPath =
true;
4040 if (
C.isForDiagnostics()) {
4044 llvm::sys::path::replace_extension(
Path,
".cache");
4045 llvm::sys::path::append(
Path,
"modules");
4046 }
else if (
Path.empty()) {
4054 const char Arg[] =
"-fmodules-cache-path=";
4055 Path.insert(
Path.begin(), Arg, Arg + strlen(Arg));
4056 CmdArgs.push_back(Args.MakeArgString(
Path));
4061 if (Args.hasFlag(options::OPT_fprebuilt_implicit_modules,
4062 options::OPT_fno_prebuilt_implicit_modules,
false))
4063 CmdArgs.push_back(
"-fprebuilt-implicit-modules");
4064 if (Args.hasFlag(options::OPT_fmodules_validate_input_files_content,
4065 options::OPT_fno_modules_validate_input_files_content,
4067 CmdArgs.push_back(
"-fvalidate-ast-input-files-content");
4072 Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
4076 Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
4080 if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
4082 llvm::sys::path::append(BuiltinModuleMap,
"include");
4083 llvm::sys::path::append(BuiltinModuleMap,
"module.modulemap");
4084 if (llvm::sys::fs::exists(BuiltinModuleMap))
4086 Args.MakeArgString(
"-fmodule-map-file=" + BuiltinModuleMap));
4093 if (HaveModules || Input.
getType() == clang::driver::types::TY_ModuleFile) {
4094 Args.AddAllArgs(CmdArgs, options::OPT_fmodule_file);
4097 for (
const Arg *A : Args.filtered(options::OPT_fprebuilt_module_path)) {
4098 CmdArgs.push_back(Args.MakeArgString(
4099 std::string(
"-fprebuilt-module-path=") + A->getValue()));
4103 Args.ClaimAllArgs(options::OPT_fmodule_file);
4107 if (HaveClangModules &&
C.isForDiagnostics()) {
4109 llvm::sys::path::replace_extension(VFSDir,
".cache");
4111 C.addTempFile(Args.MakeArgString(VFSDir));
4113 llvm::sys::path::append(VFSDir,
"vfs");
4114 CmdArgs.push_back(
"-module-dependency-dir");
4115 CmdArgs.push_back(Args.MakeArgString(VFSDir));
4118 if (HaveClangModules)
4119 Args.AddLastArg(CmdArgs, options::OPT_fmodules_user_build_path);
4122 Args.AddAllArgs(CmdArgs, options::OPT_fmodules_ignore_macro);
4123 Args.AddLastArg(CmdArgs, options::OPT_fmodules_prune_interval);
4124 Args.AddLastArg(CmdArgs, options::OPT_fmodules_prune_after);
4126 if (HaveClangModules) {
4127 Args.AddLastArg(CmdArgs, options::OPT_fbuild_session_timestamp);
4129 if (Arg *A = Args.getLastArg(options::OPT_fbuild_session_file)) {
4130 if (Args.hasArg(options::OPT_fbuild_session_timestamp))
4131 D.Diag(diag::err_drv_argument_not_allowed_with)
4132 << A->getAsString(Args) <<
"-fbuild-session-timestamp";
4134 llvm::sys::fs::file_status Status;
4135 if (llvm::sys::fs::status(A->getValue(), Status))
4136 D.Diag(diag::err_drv_no_such_file) << A->getValue();
4137 CmdArgs.push_back(Args.MakeArgString(
4138 "-fbuild-session-timestamp=" +
4139 Twine((uint64_t)std::chrono::duration_cast<std::chrono::seconds>(
4140 Status.getLastModificationTime().time_since_epoch())
4144 if (Args.getLastArg(
4145 options::OPT_fmodules_validate_once_per_build_session)) {
4146 if (!Args.getLastArg(options::OPT_fbuild_session_timestamp,
4147 options::OPT_fbuild_session_file))
4148 D.Diag(diag::err_drv_modules_validate_once_requires_timestamp);
4150 Args.AddLastArg(CmdArgs,
4151 options::OPT_fmodules_validate_once_per_build_session);
4154 if (Args.hasFlag(options::OPT_fmodules_validate_system_headers,
4155 options::OPT_fno_modules_validate_system_headers,
4157 CmdArgs.push_back(
"-fmodules-validate-system-headers");
4159 Args.AddLastArg(CmdArgs,
4160 options::OPT_fmodules_disable_diagnostic_validation);
4162 Args.ClaimAllArgs(options::OPT_fbuild_session_timestamp);
4163 Args.ClaimAllArgs(options::OPT_fbuild_session_file);
4164 Args.ClaimAllArgs(options::OPT_fmodules_validate_once_per_build_session);
4165 Args.ClaimAllArgs(options::OPT_fmodules_validate_system_headers);
4166 Args.ClaimAllArgs(options::OPT_fno_modules_validate_system_headers);
4167 Args.ClaimAllArgs(options::OPT_fmodules_disable_diagnostic_validation);
4172 CmdArgs.push_back(
"-fskip-odr-check-in-gmf");
4174 if (Args.hasArg(options::OPT_modules_reduced_bmi) &&
4175 (Input.
getType() == driver::types::TY_CXXModule ||
4176 Input.
getType() == driver::types::TY_PP_CXXModule)) {
4177 CmdArgs.push_back(
"-fexperimental-modules-reduced-bmi");
4179 if (Args.hasArg(options::OPT_fmodule_output_EQ))
4180 Args.AddLastArg(CmdArgs, options::OPT_fmodule_output_EQ);
4182 CmdArgs.push_back(Args.MakeArgString(
4183 "-fmodule-output=" +
4190 Args.ClaimAllArgs(options::OPT_modules_reduced_bmi);
4198 if (Input.
getType() == driver::types::TY_CXXModule ||
4199 Input.
getType() == driver::types::TY_PP_CXXModule ||
4200 Input.
getType() == driver::types::TY_ModuleFile) {
4201 Args.ClaimAllArgs(options::OPT_fmodule_output);
4202 Args.ClaimAllArgs(options::OPT_fmodule_output_EQ);
4209 ArgStringList &CmdArgs) {
4211 if (
const Arg *A = Args.getLastArg(options::OPT_fsigned_char,
4212 options::OPT_fno_signed_char,
4213 options::OPT_funsigned_char,
4214 options::OPT_fno_unsigned_char)) {
4215 if (A->getOption().matches(options::OPT_funsigned_char) ||
4216 A->getOption().matches(options::OPT_fno_signed_char)) {
4217 CmdArgs.push_back(
"-fno-signed-char");
4220 CmdArgs.push_back(
"-fno-signed-char");
4224 Args.AddLastArg(CmdArgs, options::OPT_fchar8__t, options::OPT_fno_char8__t);
4226 if (
const Arg *A = Args.getLastArg(options::OPT_fshort_wchar,
4227 options::OPT_fno_short_wchar)) {
4228 if (A->getOption().matches(options::OPT_fshort_wchar)) {
4229 CmdArgs.push_back(
"-fwchar-type=short");
4230 CmdArgs.push_back(
"-fno-signed-wchar");
4232 bool IsARM =
T.isARM() ||
T.isThumb() ||
T.isAArch64();
4233 CmdArgs.push_back(
"-fwchar-type=int");
4235 (IsARM && !(
T.isOSWindows() ||
T.isOSNetBSD() ||
T.isOSOpenBSD())))
4236 CmdArgs.push_back(
"-fno-signed-wchar");
4238 CmdArgs.push_back(
"-fsigned-wchar");
4240 }
else if (
T.isOSzOS())
4241 CmdArgs.push_back(
"-fno-signed-wchar");
4245 const llvm::Triple &
T,
const ArgList &Args,
4247 const InputInfo &Input, ArgStringList &CmdArgs) {
4248 const llvm::Triple::ArchType Arch = TC.
getArch();
4254 if (!Args.hasFlag(options::OPT_fobjc_legacy_dispatch,
4255 options::OPT_fno_objc_legacy_dispatch,
4258 CmdArgs.push_back(
"-fobjc-dispatch-method=mixed");
4260 CmdArgs.push_back(
"-fobjc-dispatch-method=non-legacy");
4266 if (Arch == llvm::Triple::x86 &&
T.isMacOSX() &&
4268 CmdArgs.push_back(
"-fobjc-subscripting-legacy-runtime");
4275 CmdArgs.push_back(
"-fobjc-arc");
4282 CmdArgs.push_back(
"-fobjc-arc-cxxlib=libc++");
4284 CmdArgs.push_back(
"-fobjc-arc-cxxlib=libstdc++");
4289 if (Args.hasFlag(options::OPT_fobjc_arc_exceptions,
4290 options::OPT_fno_objc_arc_exceptions,
4292 CmdArgs.push_back(
"-fobjc-arc-exceptions");
4297 if (Args.hasArg(options::OPT_fno_objc_arc)) {
4298 Args.ClaimAllArgs(options::OPT_fobjc_arc_exceptions);
4299 Args.ClaimAllArgs(options::OPT_fno_objc_arc_exceptions);
4305 auto *Arg = Args.getLastArg(
4306 options::OPT_fobjc_convert_messages_to_runtime_calls,
4307 options::OPT_fno_objc_convert_messages_to_runtime_calls);
4309 Arg->getOption().matches(
4310 options::OPT_fno_objc_convert_messages_to_runtime_calls))
4311 CmdArgs.push_back(
"-fno-objc-convert-messages-to-runtime-calls");
4316 if (InferCovariantReturns)
4317 CmdArgs.push_back(
"-fno-objc-infer-related-result-type");
4322 Args.getLastArg(options::OPT_fobjc_weak, options::OPT_fno_objc_weak);
4326 if (WeakArg->getOption().matches(options::OPT_fobjc_weak))
4327 D.Diag(diag::err_objc_weak_unsupported);
4329 WeakArg->render(Args, CmdArgs);
4333 if (Args.hasArg(options::OPT_fobjc_disable_direct_methods_for_testing))
4334 CmdArgs.push_back(
"-fobjc-disable-direct-methods-for-testing");
4338 ArgStringList &CmdArgs) {
4339 bool CaretDefault =
true;
4340 bool ColumnDefault =
true;
4342 if (
const Arg *A = Args.getLastArg(options::OPT__SLASH_diagnostics_classic,
4343 options::OPT__SLASH_diagnostics_column,
4344 options::OPT__SLASH_diagnostics_caret)) {
4345 switch (A->getOption().getID()) {
4346 case options::OPT__SLASH_diagnostics_caret:
4347 CaretDefault =
true;
4348 ColumnDefault =
true;
4350 case options::OPT__SLASH_diagnostics_column:
4351 CaretDefault =
false;
4352 ColumnDefault =
true;
4354 case options::OPT__SLASH_diagnostics_classic:
4355 CaretDefault =
false;
4356 ColumnDefault =
false;
4362 if (!Args.hasFlag(options::OPT_fcaret_diagnostics,
4363 options::OPT_fno_caret_diagnostics, CaretDefault))
4364 CmdArgs.push_back(
"-fno-caret-diagnostics");
4366 Args.addOptOutFlag(CmdArgs, options::OPT_fdiagnostics_fixit_info,
4367 options::OPT_fno_diagnostics_fixit_info);
4368 Args.addOptOutFlag(CmdArgs, options::OPT_fdiagnostics_show_option,
4369 options::OPT_fno_diagnostics_show_option);
4372 Args.getLastArg(options::OPT_fdiagnostics_show_category_EQ)) {
4373 CmdArgs.push_back(
"-fdiagnostics-show-category");
4374 CmdArgs.push_back(A->getValue());
4377 Args.addOptInFlag(CmdArgs, options::OPT_fdiagnostics_show_hotness,
4378 options::OPT_fno_diagnostics_show_hotness);
4381 Args.getLastArg(options::OPT_fdiagnostics_hotness_threshold_EQ)) {
4383 std::string(
"-fdiagnostics-hotness-threshold=") + A->getValue();
4384 CmdArgs.push_back(Args.MakeArgString(Opt));
4388 Args.getLastArg(options::OPT_fdiagnostics_misexpect_tolerance_EQ)) {
4390 std::string(
"-fdiagnostics-misexpect-tolerance=") + A->getValue();
4391 CmdArgs.push_back(Args.MakeArgString(Opt));
4394 if (
const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) {
4395 CmdArgs.push_back(
"-fdiagnostics-format");
4396 CmdArgs.push_back(A->getValue());
4397 if (StringRef(A->getValue()) ==
"sarif" ||
4398 StringRef(A->getValue()) ==
"SARIF")
4399 D.Diag(diag::warn_drv_sarif_format_unstable);
4402 if (
const Arg *A = Args.getLastArg(
4403 options::OPT_fdiagnostics_show_note_include_stack,
4404 options::OPT_fno_diagnostics_show_note_include_stack)) {
4405 const Option &O = A->getOption();
4406 if (O.matches(options::OPT_fdiagnostics_show_note_include_stack))
4407 CmdArgs.push_back(
"-fdiagnostics-show-note-include-stack");
4409 CmdArgs.push_back(
"-fno-diagnostics-show-note-include-stack");
4416 Args.getLastArg(options::OPT_fcolor_diagnostics,
4417 options::OPT_fno_color_diagnostics);
4418 if (
const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_color_EQ)) {
4419 StringRef
Value(A->getValue());
4421 D.Diag(diag::err_drv_invalid_argument_to_option)
4422 <<
Value << A->getOption().getName();
4425 if (
D.getDiags().getDiagnosticOptions().ShowColors)
4426 CmdArgs.push_back(
"-fcolor-diagnostics");
4428 if (Args.hasArg(options::OPT_fansi_escape_codes))
4429 CmdArgs.push_back(
"-fansi-escape-codes");
4431 Args.addOptOutFlag(CmdArgs, options::OPT_fshow_source_location,
4432 options::OPT_fno_show_source_location);
4434 Args.addOptOutFlag(CmdArgs, options::OPT_fdiagnostics_show_line_numbers,
4435 options::OPT_fno_diagnostics_show_line_numbers);
4437 if (Args.hasArg(options::OPT_fdiagnostics_absolute_paths))
4438 CmdArgs.push_back(
"-fdiagnostics-absolute-paths");
4440 if (!Args.hasFlag(options::OPT_fshow_column, options::OPT_fno_show_column,
4442 CmdArgs.push_back(
"-fno-show-column");
4444 Args.addOptOutFlag(CmdArgs, options::OPT_fspell_checking,
4445 options::OPT_fno_spell_checking);
4449 const ArgList &Args, Arg *&Arg) {
4450 Arg = Args.getLastArg(options::OPT_gsplit_dwarf, options::OPT_gsplit_dwarf_EQ,
4451 options::OPT_gno_split_dwarf);
4452 if (!Arg || Arg->getOption().matches(options::OPT_gno_split_dwarf))
4455 if (Arg->getOption().matches(options::OPT_gsplit_dwarf))
4458 StringRef
Value = Arg->getValue();
4459 if (
Value ==
"split")
4461 if (
Value ==
"single")
4464 D.Diag(diag::err_drv_unsupported_option_argument)
4465 << Arg->getSpelling() << Arg->getValue();
4470 const ArgList &Args, ArgStringList &CmdArgs,
4471 unsigned DwarfVersion) {
4472 auto *DwarfFormatArg =
4473 Args.getLastArg(options::OPT_gdwarf64, options::OPT_gdwarf32);
4474 if (!DwarfFormatArg)
4477 if (DwarfFormatArg->getOption().matches(options::OPT_gdwarf64)) {
4478 if (DwarfVersion < 3)
4479 D.Diag(diag::err_drv_argument_only_allowed_with)
4480 << DwarfFormatArg->getAsString(Args) <<
"DWARFv3 or greater";
4481 else if (!
T.isArch64Bit())
4482 D.Diag(diag::err_drv_argument_only_allowed_with)
4483 << DwarfFormatArg->getAsString(Args) <<
"64 bit architecture";
4484 else if (!
T.isOSBinFormatELF())
4485 D.Diag(diag::err_drv_argument_only_allowed_with)
4486 << DwarfFormatArg->getAsString(Args) <<
"ELF platforms";
4489 DwarfFormatArg->render(Args, CmdArgs);
4494 const ArgList &Args,
bool IRInput, ArgStringList &CmdArgs,
4496 llvm::codegenoptions::DebugInfoKind &DebugInfoKind,
4498 if (Args.hasFlag(options::OPT_fdebug_info_for_profiling,
4499 options::OPT_fno_debug_info_for_profiling,
false) &&
4501 Args.getLastArg(options::OPT_fdebug_info_for_profiling), Args,
D, TC))
4502 CmdArgs.push_back(
"-fdebug-info-for-profiling");
4515 bool SplitDWARFInlining =
4516 Args.hasFlag(options::OPT_fsplit_dwarf_inlining,
4517 options::OPT_fno_split_dwarf_inlining,
false);
4522 if (IRInput || Args.hasArg(options::OPT_g_Group)) {
4528 SplitDWARFInlining =
false;
4531 if (
const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
4532 DebugInfoKind = llvm::codegenoptions::DebugInfoConstructor;
4536 A->getOption().matches(options::OPT_gN_Group)) {
4542 if (DebugInfoKind == llvm::codegenoptions::NoDebugInfo ||
4543 DebugInfoKind == llvm::codegenoptions::DebugDirectivesOnly ||
4544 (DebugInfoKind == llvm::codegenoptions::DebugLineTablesOnly &&
4545 SplitDWARFInlining))
4551 bool HasDebuggerTuning =
false;
4553 Args.getLastArg(options::OPT_gTune_Group, options::OPT_ggdbN_Group)) {
4554 HasDebuggerTuning =
true;
4556 if (A->getOption().matches(options::OPT_glldb))
4557 DebuggerTuning = llvm::DebuggerKind::LLDB;
4558 else if (A->getOption().matches(options::OPT_gsce))
4559 DebuggerTuning = llvm::DebuggerKind::SCE;
4560 else if (A->getOption().matches(options::OPT_gdbx))
4561 DebuggerTuning = llvm::DebuggerKind::DBX;
4563 DebuggerTuning = llvm::DebuggerKind::GDB;
4568 bool EmitDwarf =
false;
4572 bool EmitCodeView =
false;
4573 if (
const Arg *A = Args.getLastArg(options::OPT_gcodeview))
4578 if (!EmitCodeView && !EmitDwarf &&
4579 DebugInfoKind != llvm::codegenoptions::NoDebugInfo) {
4581 case llvm::codegenoptions::DIF_CodeView:
4582 EmitCodeView =
true;
4584 case llvm::codegenoptions::DIF_DWARF:
4590 unsigned RequestedDWARFVersion = 0;
4591 unsigned EffectiveDWARFVersion = 0;
4596 EffectiveDWARFVersion =
4599 Args.ClaimAllArgs(options::OPT_fdebug_default_version);
4603 if (RequestedDWARFVersion == 0 &&
4604 DebugInfoKind == llvm::codegenoptions::DebugDirectivesOnly)
4605 DebugInfoKind = llvm::codegenoptions::NoDebugInfo;
4609 if (
const Arg *A = Args.getLastArg(options::OPT_gstrict_dwarf))
4611 if (Args.hasFlag(options::OPT_gstrict_dwarf, options::OPT_gno_strict_dwarf,
4612 DebuggerTuning == llvm::DebuggerKind::DBX))
4613 CmdArgs.push_back(
"-gstrict-dwarf");
4616 Args.ClaimAllArgs(options::OPT_g_flags_Group);
4624 if (
const Arg *A = Args.getLastArg(options::OPT_gcolumn_info))
4626 if (!Args.hasFlag(options::OPT_gcolumn_info, options::OPT_gno_column_info,
4628 (DebuggerTuning != llvm::DebuggerKind::SCE &&
4629 DebuggerTuning != llvm::DebuggerKind::DBX)))
4630 CmdArgs.push_back(
"-gno-column-info");
4633 if (Args.hasFlag(options::OPT_gmodules, options::OPT_gno_modules,
false)) {
4638 if (DebugInfoKind != llvm::codegenoptions::DebugLineTablesOnly &&
4639 DebugInfoKind != llvm::codegenoptions::DebugDirectivesOnly) {
4640 DebugInfoKind = llvm::codegenoptions::DebugInfoConstructor;
4641 CmdArgs.push_back(
"-dwarf-ext-refs");
4642 CmdArgs.push_back(
"-fmodule-format=obj");
4647 if (
T.isOSBinFormatELF() && SplitDWARFInlining)
4648 CmdArgs.push_back(
"-fsplit-dwarf-inlining");
4655 bool NeedFullDebug = Args.hasFlag(
4656 options::OPT_fstandalone_debug, options::OPT_fno_standalone_debug,
4657 DebuggerTuning == llvm::DebuggerKind::LLDB ||
4659 if (
const Arg *A = Args.getLastArg(options::OPT_fstandalone_debug))
4662 if (DebugInfoKind == llvm::codegenoptions::LimitedDebugInfo ||
4663 DebugInfoKind == llvm::codegenoptions::DebugInfoConstructor) {
4664 if (Args.hasFlag(options::OPT_fno_eliminate_unused_debug_types,
4665 options::OPT_feliminate_unused_debug_types,
false))
4666 DebugInfoKind = llvm::codegenoptions::UnusedTypeInfo;
4667 else if (NeedFullDebug)
4668 DebugInfoKind = llvm::codegenoptions::FullDebugInfo;
4671 if (Args.hasFlag(options::OPT_gembed_source, options::OPT_gno_embed_source,
4677 const Arg *A = Args.getLastArg(options::OPT_gembed_source);
4678 if (RequestedDWARFVersion < 5)
4679 D.Diag(diag::err_drv_argument_only_allowed_with)
4680 << A->getAsString(Args) <<
"-gdwarf-5";
4681 else if (EffectiveDWARFVersion < 5)
4684 D.Diag(diag::warn_drv_dwarf_version_limited_by_target)
4686 << EffectiveDWARFVersion;
4688 CmdArgs.push_back(
"-gembed-source");
4692 CmdArgs.push_back(
"-gcodeview");
4694 Args.addOptInFlag(CmdArgs, options::OPT_gcodeview_ghash,
4695 options::OPT_gno_codeview_ghash);
4697 Args.addOptOutFlag(CmdArgs, options::OPT_gcodeview_command_line,
4698 options::OPT_gno_codeview_command_line);
4701 Args.addOptOutFlag(CmdArgs, options::OPT_ginline_line_tables,
4702 options::OPT_gno_inline_line_tables);
4706 DebugInfoKind <= llvm::codegenoptions::DebugDirectivesOnly)
4707 DebugInfoKind = llvm::codegenoptions::DebugLineTablesOnly;
4715 T.isOSAIX() && !HasDebuggerTuning
4716 ? llvm::DebuggerKind::Default
4720 if (Args.hasFlag(options::OPT_fdebug_macro, options::OPT_fno_debug_macro,
4724 CmdArgs.push_back(
"-debug-info-macro");
4727 const auto *PubnamesArg =
4728 Args.getLastArg(options::OPT_ggnu_pubnames, options::OPT_gno_gnu_pubnames,
4729 options::OPT_gpubnames, options::OPT_gno_pubnames);
4732 const bool OptionSet =
4734 (PubnamesArg->getOption().matches(options::OPT_gpubnames) ||
4735 PubnamesArg->getOption().matches(options::OPT_ggnu_pubnames)));
4736 if ((DebuggerTuning != llvm::DebuggerKind::LLDB || OptionSet) &&
4738 (!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) &&
4739 !PubnamesArg->getOption().matches(options::OPT_gno_pubnames))))
4740 CmdArgs.push_back(PubnamesArg && PubnamesArg->getOption().matches(
4741 options::OPT_gpubnames)
4743 :
"-ggnu-pubnames");
4745 const auto *SimpleTemplateNamesArg =
4746 Args.getLastArg(options::OPT_gsimple_template_names,
4747 options::OPT_gno_simple_template_names);
4748 bool ForwardTemplateParams = DebuggerTuning == llvm::DebuggerKind::SCE;
4749 if (SimpleTemplateNamesArg &&
4751 const auto &Opt = SimpleTemplateNamesArg->getOption();
4752 if (Opt.matches(options::OPT_gsimple_template_names)) {
4753 ForwardTemplateParams =
true;
4754 CmdArgs.push_back(
"-gsimple-template-names=simple");
4759 bool UseDebugTemplateAlias =
4760 DebuggerTuning == llvm::DebuggerKind::SCE && RequestedDWARFVersion >= 4;
4761 if (
const auto *DebugTemplateAlias = Args.getLastArg(
4762 options::OPT_gtemplate_alias, options::OPT_gno_template_alias)) {
4766 const auto &Opt = DebugTemplateAlias->getOption();
4767 UseDebugTemplateAlias = Opt.matches(options::OPT_gtemplate_alias);
4770 if (UseDebugTemplateAlias)
4771 CmdArgs.push_back(
"-gtemplate-alias");
4773 if (
const Arg *A = Args.getLastArg(options::OPT_gsrc_hash_EQ)) {
4774 StringRef
v = A->getValue();
4775 CmdArgs.push_back(Args.MakeArgString(
"-gsrc-hash=" +
v));
4778 Args.addOptInFlag(CmdArgs, options::OPT_fdebug_ranges_base_address,
4779 options::OPT_fno_debug_ranges_base_address);
4783 if (
const Arg *A = Args.getLastArg(options::OPT_gdwarf_aranges);
4785 CmdArgs.push_back(
"-mllvm");
4786 CmdArgs.push_back(
"-generate-arange-section");
4789 Args.addOptInFlag(CmdArgs, options::OPT_fforce_dwarf_frame,
4790 options::OPT_fno_force_dwarf_frame);
4792 bool EnableTypeUnits =
false;
4793 if (Args.hasFlag(options::OPT_fdebug_types_section,
4794 options::OPT_fno_debug_types_section,
false)) {
4795 if (!(
T.isOSBinFormatELF() ||
T.isOSBinFormatWasm())) {
4796 D.Diag(diag::err_drv_unsupported_opt_for_target)
4797 << Args.getLastArg(options::OPT_fdebug_types_section)
4801 Args.getLastArg(options::OPT_fdebug_types_section), Args,
D,
4803 EnableTypeUnits =
true;
4804 CmdArgs.push_back(
"-mllvm");
4805 CmdArgs.push_back(
"-generate-type-units");
4810 Args.getLastArg(options::OPT_gomit_unreferenced_methods,
4811 options::OPT_gno_omit_unreferenced_methods))
4813 if (Args.hasFlag(options::OPT_gomit_unreferenced_methods,
4814 options::OPT_gno_omit_unreferenced_methods,
false) &&
4815 (DebugInfoKind == llvm::codegenoptions::DebugInfoConstructor ||
4816 DebugInfoKind == llvm::codegenoptions::LimitedDebugInfo) &&
4818 CmdArgs.push_back(
"-gomit-unreferenced-methods");
4824 if (!Args.hasFlag(options::OPT_fdwarf_directory_asm,
4825 options::OPT_fno_dwarf_directory_asm,
4827 CmdArgs.push_back(
"-fno-dwarf-directory-asm");
4831 if (ForwardTemplateParams)
4832 CmdArgs.push_back(
"-debug-forward-template-params");
4836 if (DebuggerTuning == llvm::DebuggerKind::SCE)
4837 CmdArgs.push_back(
"-dwarf-explicit-import");
4843 if (Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc,
false)) {
4844 if (TC.
getTriple().isOSBinFormatELF() ||
D.IsCLMode()) {
4845 if (DebugInfoKind >= llvm::codegenoptions::DebugInfoConstructor)
4846 CmdArgs.push_back(
"-fjmc");
4847 else if (
D.IsCLMode())
4848 D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo) <<
"/JMC"
4851 D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo) <<
"-fjmc"
4854 D.Diag(clang::diag::warn_drv_fjmc_for_elf_only);
4859 const char *DebugCompilationDir =
4871 ArgStringList &CmdArgs) {
4872 unsigned RTOptionID = options::OPT__SLASH_MT;
4874 if (Args.hasArg(options::OPT__SLASH_LDd))
4877 RTOptionID = options::OPT__SLASH_MTd;
4879 if (Arg *A = Args.getLastArg(options::OPT__SLASH_M_Group))
4880 RTOptionID = A->getOption().getID();
4882 if (Arg *A = Args.getLastArg(options::OPT_fms_runtime_lib_EQ)) {
4883 RTOptionID = llvm::StringSwitch<unsigned>(A->getValue())
4884 .Case(
"static", options::OPT__SLASH_MT)
4885 .Case(
"static_dbg", options::OPT__SLASH_MTd)
4886 .Case(
"dll", options::OPT__SLASH_MD)
4887 .Case(
"dll_dbg", options::OPT__SLASH_MDd)
4888 .Default(options::OPT__SLASH_MT);
4891 StringRef FlagForCRT;
4892 switch (RTOptionID) {
4893 case options::OPT__SLASH_MD:
4894 if (Args.hasArg(options::OPT__SLASH_LDd))
4895 CmdArgs.push_back(
"-D_DEBUG");
4896 CmdArgs.push_back(
"-D_MT");
4897 CmdArgs.push_back(
"-D_DLL");
4898 FlagForCRT =
"--dependent-lib=msvcrt";
4900 case options::OPT__SLASH_MDd:
4901 CmdArgs.push_back(
"-D_DEBUG");
4902 CmdArgs.push_back(
"-D_MT");
4903 CmdArgs.push_back(
"-D_DLL");
4904 FlagForCRT =
"--dependent-lib=msvcrtd";
4906 case options::OPT__SLASH_MT:
4907 if (Args.hasArg(options::OPT__SLASH_LDd))
4908 CmdArgs.push_back(
"-D_DEBUG");
4909 CmdArgs.push_back(
"-D_MT");
4910 CmdArgs.push_back(
"-flto-visibility-public-std");
4911 FlagForCRT =
"--dependent-lib=libcmt";
4913 case options::OPT__SLASH_MTd:
4914 CmdArgs.push_back(
"-D_DEBUG");
4915 CmdArgs.push_back(
"-D_MT");
4916 CmdArgs.push_back(
"-flto-visibility-public-std");
4917 FlagForCRT =
"--dependent-lib=libcmtd";
4920 llvm_unreachable(
"Unexpected option ID.");
4923 if (Args.hasArg(options::OPT_fms_omit_default_lib)) {
4924 CmdArgs.push_back(
"-D_VC_NODEFAULTLIB");
4926 CmdArgs.push_back(FlagForCRT.data());
4931 CmdArgs.push_back(
"--dependent-lib=oldnames");
4938 CmdArgs.push_back(
"--dependent-lib=softintrin");
4943 const ArgList &Args,
const char *LinkingOutput)
const {
4945 const llvm::Triple &RawTriple = TC.
getTriple();
4947 const std::string &TripleStr = Triple.getTriple();
4950 Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
4952 ArgStringList CmdArgs;
4954 assert(Inputs.size() >= 1 &&
"Must have at least one input.");
4966 bool IsExtractAPI = isa<ExtractAPIJobAction>(JA);
4969 bool IsHostOffloadingAction =
4972 Args.hasFlag(options::OPT_offload_new_driver,
4973 options::OPT_no_offload_new_driver,
false));
4976 Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
false);
4978 auto LTOMode = IsDeviceOffloadAction ?
D.getOffloadLTOMode() :
D.getLTOMode();
4983 InputInfo ExtractAPIPlaceholderInput(Inputs[0].getType(),
"extract-api",
4987 IsExtractAPI ? ExtractAPIPlaceholderInput : Inputs[0];
4991 const InputInfo *CudaDeviceInput =
nullptr;
4992 const InputInfo *OpenMPDeviceInput =
nullptr;
4994 if (&I == &Input || I.
getType() == types::TY_Nothing) {
4996 }
else if (IsExtractAPI) {
4997 auto ExpectedInputType = ExtractAPIPlaceholderInput.
getType();
4998 if (I.getType() != ExpectedInputType) {
4999 D.Diag(diag::err_drv_extract_api_wrong_kind)
5003 ExtractAPIInputs.push_back(I);
5004 }
else if (IsHostOffloadingAction) {
5005 HostOffloadingInputs.push_back(I);
5006 }
else if ((IsCuda || IsHIP) && !CudaDeviceInput) {
5007 CudaDeviceInput = &I;
5008 }
else if (IsOpenMPDevice && !OpenMPDeviceInput) {
5009 OpenMPDeviceInput = &I;
5011 llvm_unreachable(
"unexpectedly given multiple inputs");
5015 const llvm::Triple *AuxTriple =
5017 bool IsWindowsMSVC = RawTriple.isWindowsMSVCEnvironment();
5018 bool IsIAMCU = RawTriple.isOSIAMCU();
5023 if (IsCuda || IsHIP)
5024 IsWindowsMSVC |= AuxTriple && AuxTriple->isWindowsMSVCEnvironment();
5028 D.Diag(diag::err_drv_clang_unsupported) <<
"C++ for IAMCU";
5033 CmdArgs.push_back(
"-cc1");
5036 CmdArgs.push_back(
"-triple");
5037 CmdArgs.push_back(Args.MakeArgString(TripleStr));
5039 if (
const Arg *MJ = Args.getLastArg(options::OPT_MJ)) {
5040 DumpCompilationDatabase(
C, MJ->getValue(), TripleStr, Output, Input, Args);
5041 Args.ClaimAllArgs(options::OPT_MJ);
5042 }
else if (
const Arg *GenCDBFragment =
5043 Args.getLastArg(options::OPT_gen_cdb_fragment_path)) {
5044 DumpCompilationDatabaseFragmentToDir(GenCDBFragment->getValue(),
C,
5045 TripleStr, Output, Input, Args);
5046 Args.ClaimAllArgs(options::OPT_gen_cdb_fragment_path);
5049 if (IsCuda || IsHIP) {
5052 std::string NormalizedTriple;
5070 assert(CTC &&
"Expected valid CUDA Toolchain.");
5072 CmdArgs.push_back(Args.MakeArgString(
5073 Twine(
"-target-sdk-version=") +
5081 CmdArgs.push_back(
"-fcuda-allow-variadic-functions");
5084 CmdArgs.push_back(
"-aux-triple");
5085 CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
5090 getToolChain().getTriple().getVendor() == llvm::Triple::AMD))) {
5092 if (Args.getLastArg(options::OPT_mprintf_kind_EQ)) {
5093 CmdArgs.push_back(Args.MakeArgString(
5095 Args.getLastArgValue(options::OPT_mprintf_kind_EQ)));
5098 Args.MakeArgString(
"-Werror=format-invalid-specifier"));
5104 if (
const Arg *PF = Args.getLastArg(options::OPT_mprintf_kind_EQ))
5107 if (Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl,
false)) {
5108 CmdArgs.push_back(
"-fsycl-is-device");
5110 if (Arg *A = Args.getLastArg(options::OPT_sycl_std_EQ)) {
5111 A->render(Args, CmdArgs);
5114 CmdArgs.push_back(
"-sycl-std=2020");
5118 if (IsOpenMPDevice) {
5120 std::string NormalizedTriple =
5124 CmdArgs.push_back(
"-aux-triple");
5125 CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
5128 if (Triple.isOSWindows() && (Triple.getArch() == llvm::Triple::arm ||
5129 Triple.getArch() == llvm::Triple::thumb)) {
5130 unsigned Offset = Triple.getArch() == llvm::Triple::arm ? 4 : 6;
5131 unsigned Version = 0;
5133 Triple.getArchName().substr(Offset).consumeInteger(10, Version);
5134 if (Failure || Version < 7)
5135 D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName()
5145 if (Triple.isSPIR() || Triple.isSPIRV())
5146 CmdArgs.push_back(
"-Wspir-compat");
5149 RewriteKind rewriteKind = RK_None;
5151 bool UnifiedLTO =
false;
5153 UnifiedLTO = Args.hasFlag(options::OPT_funified_lto,
5154 options::OPT_fno_unified_lto, Triple.isPS());
5156 CmdArgs.push_back(
"-funified-lto");
5166 if (!isa<AssembleJobAction>(JA)) {
5170 Args.ClaimAllArgs(options::OPT_mrelax_all);
5171 Args.ClaimAllArgs(options::OPT_mno_relax_all);
5172 Args.ClaimAllArgs(options::OPT_mincremental_linker_compatible);
5173 Args.ClaimAllArgs(options::OPT_mno_incremental_linker_compatible);
5174 switch (
C.getDefaultToolChain().getArch()) {
5175 case llvm::Triple::arm:
5176 case llvm::Triple::armeb:
5177 case llvm::Triple::thumb:
5178 case llvm::Triple::thumbeb:
5179 Args.ClaimAllArgs(options::OPT_mimplicit_it_EQ);
5185 Args.ClaimAllArgs(options::OPT_Wa_COMMA);
5186 Args.ClaimAllArgs(options::OPT_Xassembler);
5187 Args.ClaimAllArgs(options::OPT_femit_dwarf_unwind_EQ);
5190 if (isa<AnalyzeJobAction>(JA)) {
5191 assert(JA.
getType() == types::TY_Plist &&
"Invalid output type.");
5192 CmdArgs.push_back(
"-analyze");
5193 }
else if (isa<MigrateJobAction>(JA)) {
5194 CmdArgs.push_back(
"-migrate");
5195 }
else if (isa<PreprocessJobAction>(JA)) {
5196 if (Output.
getType() == types::TY_Dependencies)
5197 CmdArgs.push_back(
"-Eonly");
5199 CmdArgs.push_back(
"-E");
5200 if (Args.hasArg(options::OPT_rewrite_objc) &&
5201 !Args.hasArg(options::OPT_g_Group))
5202 CmdArgs.push_back(
"-P");
5203 else if (JA.
getType() == types::TY_PP_CXXHeaderUnit)
5204 CmdArgs.push_back(
"-fdirectives-only");
5206 }
else if (isa<AssembleJobAction>(JA)) {
5207 CmdArgs.push_back(
"-emit-obj");
5212 (void)Args.hasArg(options::OPT_force__cpusubtype__ALL);
5213 }
else if (isa<PrecompileJobAction>(JA)) {
5214 if (JA.
getType() == types::TY_Nothing)
5215 CmdArgs.push_back(
"-fsyntax-only");
5216 else if (JA.
getType() == types::TY_ModuleFile)
5217 CmdArgs.push_back(
"-emit-module-interface");
5218 else if (JA.
getType() == types::TY_HeaderUnit)
5219 CmdArgs.push_back(
"-emit-header-unit");
5221 CmdArgs.push_back(
"-emit-pch");
5222 }
else if (isa<VerifyPCHJobAction>(JA)) {
5223 CmdArgs.push_back(
"-verify-pch");
5224 }
else if (isa<ExtractAPIJobAction>(JA)) {
5225 assert(JA.
getType() == types::TY_API_INFO &&
5226 "Extract API actions must generate a API information.");
5227 CmdArgs.push_back(
"-extract-api");
5229 if (Arg *PrettySGFArg = Args.getLastArg(options::OPT_emit_pretty_sgf))
5230 PrettySGFArg->render(Args, CmdArgs);
5232 Arg *SymbolGraphDirArg = Args.getLastArg(options::OPT_symbol_graph_dir_EQ);
5234 if (Arg *ProductNameArg = Args.getLastArg(options::OPT_product_name_EQ))
5235 ProductNameArg->render(Args, CmdArgs);
5236 if (Arg *ExtractAPIIgnoresFileArg =
5237 Args.getLastArg(options::OPT_extract_api_ignores_EQ))
5238 ExtractAPIIgnoresFileArg->render(Args, CmdArgs);
5239 if (Arg *EmitExtensionSymbolGraphs =
5240 Args.getLastArg(options::OPT_emit_extension_symbol_graphs)) {
5241 if (!SymbolGraphDirArg)
5242 D.Diag(diag::err_drv_missing_symbol_graph_dir);
5244 EmitExtensionSymbolGraphs->render(Args, CmdArgs);
5246 if (SymbolGraphDirArg)
5247 SymbolGraphDirArg->render(Args, CmdArgs);
5249 assert((isa<CompileJobAction>(JA) || isa<BackendJobAction>(JA)) &&
5250 "Invalid action for clang tool.");
5251 if (JA.
getType() == types::TY_Nothing) {
5252 CmdArgs.push_back(
"-fsyntax-only");
5253 }
else if (JA.
getType() == types::TY_LLVM_IR ||
5254 JA.
getType() == types::TY_LTO_IR) {
5255 CmdArgs.push_back(
"-emit-llvm");
5256 }
else if (JA.
getType() == types::TY_LLVM_BC ||
5257 JA.
getType() == types::TY_LTO_BC) {
5259 if (Triple.isAMDGCN() && IsOpenMPDevice && Args.hasArg(options::OPT_S) &&
5260 Args.hasArg(options::OPT_emit_llvm)) {
5261 CmdArgs.push_back(
"-emit-llvm");
5263 CmdArgs.push_back(
"-emit-llvm-bc");
5265 }
else if (JA.
getType() == types::TY_IFS ||
5266 JA.
getType() == types::TY_IFS_CPP) {
5268 Args.hasArg(options::OPT_interface_stub_version_EQ)
5269 ? Args.getLastArgValue(options::OPT_interface_stub_version_EQ)
5271 CmdArgs.push_back(
"-emit-interface-stubs");
5273 Args.MakeArgString(Twine(
"-interface-stub-version=") + ArgStr.str()));
5274 }
else if (JA.
getType() == types::TY_PP_Asm) {
5275 CmdArgs.push_back(
"-S");
5276 }
else if (JA.
getType() == types::TY_AST) {
5277 CmdArgs.push_back(
"-emit-pch");
5278 }
else if (JA.
getType() == types::TY_ModuleFile) {
5279 CmdArgs.push_back(
"-module-file-info");
5280 }
else if (JA.
getType() == types::TY_RewrittenObjC) {
5281 CmdArgs.push_back(
"-rewrite-objc");
5282 rewriteKind = RK_NonFragile;
5283 }
else if (JA.
getType() == types::TY_RewrittenLegacyObjC) {
5284 CmdArgs.push_back(
"-rewrite-objc");
5285 rewriteKind = RK_Fragile;
5287 assert(JA.
getType() == types::TY_PP_Asm &&
"Unexpected output type!");
5294 if (JA.
getType() == types::TY_LLVM_BC)
5295 CmdArgs.push_back(
"-emit-llvm-uselists");
5299 !Args.hasFlag(options::OPT_offload_new_driver,
5300 options::OPT_no_offload_new_driver,
false) &&
5301 !Triple.isAMDGPU()) {
5302 D.Diag(diag::err_drv_unsupported_opt_for_target)
5303 << Args.getLastArg(options::OPT_foffload_lto,
5304 options::OPT_foffload_lto_EQ)
5306 << Triple.getTriple();
5307 }
else if (Triple.isNVPTX() && !IsRDCMode &&
5309 D.Diag(diag::err_drv_unsupported_opt_for_language_mode)
5310 << Args.getLastArg(options::OPT_foffload_lto,
5311 options::OPT_foffload_lto_EQ)
5316 CmdArgs.push_back(Args.MakeArgString(
5317 Twine(
"-flto=") + (LTOMode ==
LTOK_Thin ?
"thin" :
"full")));
5320 if (!RawTriple.isPS4() ||
5321 (
D.getLTOMode() ==
LTOK_Full) || !UnifiedLTO)
5322 CmdArgs.push_back(
"-flto-unit");
5327 Args.AddLastArg(CmdArgs, options::OPT_dumpdir);
5329 if (
const Arg *A = Args.getLastArg(options::OPT_fthinlto_index_EQ)) {
5331 D.Diag(diag::err_drv_arg_requires_bitcode_input) << A->getAsString(Args);
5332 Args.AddLastArg(CmdArgs, options::OPT_fthinlto_index_EQ);
5336 Args.addOptInFlag(CmdArgs, options::OPT_mregnames,
5337 options::OPT_mno_regnames);
5339 if (Args.getLastArg(options::OPT_fthin_link_bitcode_EQ))
5340 Args.AddLastArg(CmdArgs, options::OPT_fthin_link_bitcode_EQ);
5342 if (Args.getLastArg(options::OPT_save_temps_EQ))
5343 Args.AddLastArg(CmdArgs, options::OPT_save_temps_EQ);
5345 auto *MemProfArg = Args.getLastArg(options::OPT_fmemory_profile,
5346 options::OPT_fmemory_profile_EQ,
5347 options::OPT_fno_memory_profile);
5349 !MemProfArg->getOption().matches(options::OPT_fno_memory_profile))
5350 MemProfArg->render(Args, CmdArgs);
5352 if (
auto *MemProfUseArg =
5353 Args.getLastArg(options::OPT_fmemory_profile_use_EQ)) {
5355 D.Diag(diag::err_drv_argument_not_allowed_with)
5356 << MemProfUseArg->getAsString(Args) << MemProfArg->getAsString(Args);
5357 if (
auto *PGOInstrArg = Args.getLastArg(options::OPT_fprofile_generate,
5358 options::OPT_fprofile_generate_EQ))
5359 D.Diag(diag::err_drv_argument_not_allowed_with)
5360 << MemProfUseArg->getAsString(Args) << PGOInstrArg->getAsString(Args);
5361 MemProfUseArg->render(Args, CmdArgs);
5366 if (
C.getDriver().embedBitcodeInObject() && !IsUsingLTO &&
5367 (isa<BackendJobAction>(JA) || isa<AssembleJobAction>(JA))) {
5369 Args.AddLastArg(CmdArgs, options::OPT_fembed_bitcode_EQ);
5371 CmdArgs.push_back(
"-disable-llvm-passes");
5378 static const constexpr unsigned kBitcodeOptionIgnorelist[] = {
5379 options::OPT_mkernel,
5380 options::OPT_fapple_kext,
5381 options::OPT_ffunction_sections,
5382 options::OPT_fno_function_sections,
5383 options::OPT_fdata_sections,
5384 options::OPT_fno_data_sections,
5385 options::OPT_fbasic_block_sections_EQ,
5386 options::OPT_funique_internal_linkage_names,
5387 options::OPT_fno_unique_internal_linkage_names,
5388 options::OPT_funique_section_names,
5389 options::OPT_fno_unique_section_names,
5390 options::OPT_funique_basic_block_section_names,
5391 options::OPT_fno_unique_basic_block_section_names,
5392 options::OPT_mrestrict_it,
5393 options::OPT_mno_restrict_it,
5394 options::OPT_mstackrealign,
5395 options::OPT_mno_stackrealign,
5396 options::OPT_mstack_alignment,
5397 options::OPT_mcmodel_EQ,
5398 options::OPT_mlong_calls,
5399 options::OPT_mno_long_calls,
5400 options::OPT_ggnu_pubnames,
5401 options::OPT_gdwarf_aranges,
5402 options::OPT_fdebug_types_section,
5403 options::OPT_fno_debug_types_section,
5404 options::OPT_fdwarf_directory_asm,
5405 options::OPT_fno_dwarf_directory_asm,
5406 options::OPT_mrelax_all,
5407 options::OPT_mno_relax_all,
5408 options::OPT_ftrap_function_EQ,
5409 options::OPT_ffixed_r9,
5410 options::OPT_mfix_cortex_a53_835769,
5411 options::OPT_mno_fix_cortex_a53_835769,
5412 options::OPT_ffixed_x18,
5413 options::OPT_mglobal_merge,
5414 options::OPT_mno_global_merge,
5415 options::OPT_mred_zone,
5416 options::OPT_mno_red_zone,
5417 options::OPT_Wa_COMMA,
5418 options::OPT_Xassembler,
5421 for (
const auto &A : Args)
5422 if (llvm::is_contained(kBitcodeOptionIgnorelist, A->getOption().getID()))
5423 D.Diag(diag::err_drv_unsupported_embed_bitcode) << A->getSpelling();
5426 Args.addOptOutFlag(CmdArgs, options::OPT_foptimize_sibling_calls,
5427 options::OPT_fno_optimize_sibling_calls);
5435 case llvm::Triple::arm:
5436 case llvm::Triple::armeb:
5437 case llvm::Triple::thumbeb:
5438 RenderARMABI(
D, Triple, Args, CmdArgs);
5440 case llvm::Triple::aarch64:
5441 case llvm::Triple::aarch64_32:
5442 case llvm::Triple::aarch64_be:
5443 RenderAArch64ABI(Triple, Args, CmdArgs);
5448 if (
const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
5449 if (A->getOption().matches(options::OPT_O4)) {
5450 CmdArgs.push_back(
"-O3");
5451 D.Diag(diag::warn_O4_is_O3);
5453 A->render(Args, CmdArgs);
5458 if (Output.
getType() == types::TY_Dependencies) {
5461 CmdArgs.push_back(
"-o");
5464 assert(Output.
isNothing() &&
"Input output.");
5467 for (
const auto &II : Inputs) {
5469 if (II.isFilename())
5470 CmdArgs.push_back(II.getFilename());
5472 II.getInputArg().renderAsInput(Args, CmdArgs);
5475 C.addCommand(std::make_unique<Command>(
5477 CmdArgs, Inputs, Output,
D.getPrependArg()));
5481 if (
C.getDriver().embedBitcodeMarkerOnly() && !IsUsingLTO)
5482 CmdArgs.push_back(
"-fembed-bitcode=marker");
5487 if (!
C.isForDiagnostics())
5488 CmdArgs.push_back(
"-disable-free");
5489 CmdArgs.push_back(
"-clear-ast-before-backend");
5492 const bool IsAssertBuild =
false;
5494 const bool IsAssertBuild =
true;
5498 if (Args.hasFlag(options::OPT_fno_verify_intermediate_code,
5499 options::OPT_fverify_intermediate_code, !IsAssertBuild)) {
5500 CmdArgs.push_back(
"-disable-llvm-verifier");
5504 if (Args.hasFlag(options::OPT_fdiscard_value_names,
5505 options::OPT_fno_discard_value_names, !IsAssertBuild)) {
5506 if (Args.hasArg(options::OPT_fdiscard_value_names) &&
5508 return types::isLLVMIR(II.getType());
5510 D.Diag(diag::warn_ignoring_fdiscard_for_bitcode);
5512 CmdArgs.push_back(
"-discard-value-names");
5517 CmdArgs.push_back(
"-main-file-name");
5522 if (Args.hasArg(options::OPT_static))
5523 CmdArgs.push_back(
"-static-define");
5525 if (Args.hasArg(options::OPT_municode))
5526 CmdArgs.push_back(
"-DUNICODE");
5528 if (isa<AnalyzeJobAction>(JA))
5531 if (isa<AnalyzeJobAction>(JA) ||
5532 (isa<PreprocessJobAction>(JA) && Args.hasArg(options::OPT__analyze)))
5533 CmdArgs.push_back(
"-setup-static-analyzer");
5538 bool FoundAnalyzerConfig =
false;
5539 for (
auto *Arg : Args.filtered(options::OPT_Xclang))
5540 if (StringRef(Arg->getValue()) ==
"-analyzer-config") {
5541 FoundAnalyzerConfig =
true;
5544 if (!FoundAnalyzerConfig)
5545 for (
auto *Arg : Args.filtered(options::OPT_Xanalyzer))
5546 if (StringRef(Arg->getValue()) ==
"-analyzer-config") {
5547 FoundAnalyzerConfig =
true;
5550 if (FoundAnalyzerConfig)
5551 CmdArgs.push_back(
"-analyzer-config-compatibility-mode=true");
5556 assert(FunctionAlignment <= 31 &&
"function alignment will be truncated!");
5557 if (FunctionAlignment) {
5558 CmdArgs.push_back(
"-function-alignment");
5559 CmdArgs.push_back(Args.MakeArgString(std::to_string(FunctionAlignment)));
5564 if (
const Arg *A = Args.getLastArg(options::OPT_falign_loops_EQ)) {
5566 if (StringRef(A->getValue()).getAsInteger(10,
Value) ||
Value > 65536)
5568 << A->getAsString(Args) << A->getValue();
5570 TC.
getDriver().
Diag(diag::err_drv_alignment_not_power_of_two)
5571 << A->getAsString(Args) << A->getValue();
5574 CmdArgs.push_back(Args.MakeArgString(
"-falign-loops=" +
5575 Twine(std::min(
Value, 65536u))));
5578 if (Triple.isOSzOS()) {
5587 auto findMacroDefinition = [&](
const std::string &Macro) {
5588 auto MacroDefs = Args.getAllArgValues(options::OPT_D);
5589 return llvm::any_of(MacroDefs, [&](
const std::string &M) {
5590 return M == Macro || M.find(Macro +
'=') != std::string::npos;
5595 if (!findMacroDefinition(
"_UNIX03_WITHDRAWN"))
5596 CmdArgs.push_back(
"-D_UNIX03_WITHDRAWN");
5598 if (!findMacroDefinition(
"_OPEN_DEFAULT"))
5599 CmdArgs.push_back(
"-D_OPEN_DEFAULT");
5602 if (!findMacroDefinition(
"_XOPEN_SOURCE"))
5603 CmdArgs.push_back(
"-D_XOPEN_SOURCE=600");
5607 llvm::Reloc::Model RelocationModel;
5610 std::tie(RelocationModel, PICLevel, IsPIE) =
ParsePICArgs(TC, Args);
5611 Arg *LastPICDataRelArg =
5612 Args.getLastArg(options::OPT_mno_pic_data_is_text_relative,
5613 options::OPT_mpic_data_is_text_relative);
5614 bool NoPICDataIsTextRelative =
false;
5615 if (LastPICDataRelArg) {
5616 if (LastPICDataRelArg->getOption().matches(
5617 options::OPT_mno_pic_data_is_text_relative)) {
5618 NoPICDataIsTextRelative =
true;
5620 D.Diag(diag::err_drv_argument_only_allowed_with)
5621 <<
"-mno-pic-data-is-text-relative"
5624 if (!Triple.isSystemZ())
5625 D.Diag(diag::err_drv_unsupported_opt_for_target)
5626 << (NoPICDataIsTextRelative ?
"-mno-pic-data-is-text-relative"
5627 :
"-mpic-data-is-text-relative")
5631 bool IsROPI = RelocationModel == llvm::Reloc::ROPI ||
5632 RelocationModel == llvm::Reloc::ROPI_RWPI;
5633 bool IsRWPI = RelocationModel == llvm::Reloc::RWPI ||
5634 RelocationModel == llvm::Reloc::ROPI_RWPI;
5636 if (Args.hasArg(options::OPT_mcmse) &&
5637 !Args.hasArg(options::OPT_fallow_unsupported)) {
5639 D.Diag(diag::err_cmse_pi_are_incompatible) << IsROPI;
5641 D.Diag(diag::err_cmse_pi_are_incompatible) << !IsRWPI;
5645 !Args.hasArg(options::OPT_fallow_unsupported))
5646 D.Diag(diag::err_drv_ropi_incompatible_with_cxx);
5650 CmdArgs.push_back(
"-mrelocation-model");
5651 CmdArgs.push_back(RMName);
5654 CmdArgs.push_back(
"-pic-level");
5655 CmdArgs.push_back(PICLevel == 1 ?
"1" :
"2");
5657 CmdArgs.push_back(
"-pic-is-pie");
5658 if (NoPICDataIsTextRelative)
5659 CmdArgs.push_back(
"-mcmodel=medium");
5662 if (RelocationModel == llvm::Reloc::ROPI ||
5663 RelocationModel == llvm::Reloc::ROPI_RWPI)
5664 CmdArgs.push_back(
"-fropi");
5665 if (RelocationModel == llvm::Reloc::RWPI ||
5666 RelocationModel == llvm::Reloc::ROPI_RWPI)
5667 CmdArgs.push_back(
"-frwpi");
5669 if (Arg *A = Args.getLastArg(options::OPT_meabi)) {
5670 CmdArgs.push_back(
"-meabi");
5671 CmdArgs.push_back(A->getValue());
5685 if (Triple.isOSBinFormatELF()) {
5686 Arg *A = Args.getLastArg(options::OPT_fsemantic_interposition,
5687 options::OPT_fno_semantic_interposition);
5688 if (RelocationModel != llvm::Reloc::Static && !IsPIE) {
5690 bool SupportsLocalAlias =
5691 Triple.isAArch64() || Triple.isRISCV() || Triple.isX86();
5693 CmdArgs.push_back(
"-fhalf-no-semantic-interposition");
5694 else if (A->getOption().matches(options::OPT_fsemantic_interposition))
5695 A->render(Args, CmdArgs);
5696 else if (!SupportsLocalAlias)
5697 CmdArgs.push_back(
"-fhalf-no-semantic-interposition");
5703 if (Arg *A = Args.getLastArg(options::OPT_mthread_model)) {
5705 D.Diag(diag::err_drv_invalid_thread_model_for_target)
5706 << A->getValue() << A->getAsString(Args);
5707 Model = A->getValue();
5710 if (Model !=
"posix") {
5711 CmdArgs.push_back(
"-mthread-model");
5712 CmdArgs.push_back(Args.MakeArgString(Model));
5716 if (Arg *A = Args.getLastArg(options::OPT_fveclib)) {
5717 StringRef Name = A->getValue();
5718 if (Name ==
"SVML") {
5719 if (Triple.getArch() != llvm::Triple::x86 &&
5720 Triple.getArch() != llvm::Triple::x86_64)
5721 D.Diag(diag::err_drv_unsupported_opt_for_target)
5722 << Name << Triple.getArchName();
5723 }
else if (Name ==
"LIBMVEC-X86") {
5724 if (Triple.getArch() != llvm::Triple::x86 &&
5725 Triple.getArch() != llvm::Triple::x86_64)
5726 D.Diag(diag::err_drv_unsupported_opt_for_target)
5727 << Name << Triple.getArchName();
5728 }
else if (Name ==
"SLEEF" || Name ==
"ArmPL") {
5729 if (Triple.getArch() != llvm::Triple::aarch64 &&
5730 Triple.getArch() != llvm::Triple::aarch64_be)
5731 D.Diag(diag::err_drv_unsupported_opt_for_target)
5732 << Name << Triple.getArchName();
5734 A->render(Args, CmdArgs);
5737 if (Args.hasFlag(options::OPT_fmerge_all_constants,
5738 options::OPT_fno_merge_all_constants,
false))
5739 CmdArgs.push_back(
"-fmerge-all-constants");
5741 Args.addOptOutFlag(CmdArgs, options::OPT_fdelete_null_pointer_checks,
5742 options::OPT_fno_delete_null_pointer_checks);
5746 if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ_quadword_atomics)) {
5747 if (!Triple.isOSAIX() || Triple.isPPC32())
5748 D.Diag(diag::err_drv_unsupported_opt_for_target)
5749 << A->getSpelling() << RawTriple.str();
5750 CmdArgs.push_back(
"-mabi=quadword-atomics");
5753 if (Arg *A = Args.getLastArg(options::OPT_mlong_double_128)) {
5756 if (Triple.isOSAIX())
5757 D.Diag(diag::err_drv_unsupported_opt_for_target)
5758 << A->getSpelling() << RawTriple.str();
5761 if (Arg *A = Args.getLastArg(options::OPT_Wframe_larger_than_EQ)) {
5762 StringRef
V = A->getValue(), V1 =
V;
5764 if (V1.consumeInteger(10, Size) || !V1.empty())
5765 D.Diag(diag::err_drv_invalid_argument_to_option)
5766 <<
V << A->getOption().getName();
5768 CmdArgs.push_back(Args.MakeArgString(
"-fwarn-stack-size=" +
V));
5771 Args.addOptOutFlag(CmdArgs, options::OPT_fjump_tables,
5772 options::OPT_fno_jump_tables);
5773 Args.addOptInFlag(CmdArgs, options::OPT_fprofile_sample_accurate,
5774 options::OPT_fno_profile_sample_accurate);
5775 Args.addOptOutFlag(CmdArgs, options::OPT_fpreserve_as_comments,
5776 options::OPT_fno_preserve_as_comments);
5778 if (Arg *A = Args.getLastArg(options::OPT_mregparm_EQ)) {
5779 CmdArgs.push_back(
"-mregparm");
5780 CmdArgs.push_back(A->getValue());
5783 if (Arg *A = Args.getLastArg(options::OPT_maix_struct_return,
5784 options::OPT_msvr4_struct_return)) {
5786 D.Diag(diag::err_drv_unsupported_opt_for_target)
5787 << A->getSpelling() << RawTriple.str();
5788 }
else if (A->getOption().matches(options::OPT_maix_struct_return)) {
5789 CmdArgs.push_back(
"-maix-struct-return");
5791 assert(A->getOption().matches(options::OPT_msvr4_struct_return));
5792 CmdArgs.push_back(
"-msvr4-struct-return");
5796 if (Arg *A = Args.getLastArg(options::OPT_fpcc_struct_return,
5797 options::OPT_freg_struct_return)) {
5798 if (TC.
getArch() != llvm::Triple::x86) {
5799 D.Diag(diag::err_drv_unsupported_opt_for_target)
5800 << A->getSpelling() << RawTriple.str();
5801 }
else if (A->getOption().matches(options::OPT_fpcc_struct_return)) {
5802 CmdArgs.push_back(
"-fpcc-struct-return");
5804 assert(A->getOption().matches(options::OPT_freg_struct_return));
5805 CmdArgs.push_back(
"-freg-struct-return");
5809 if (Args.hasFlag(options::OPT_mrtd, options::OPT_mno_rtd,
false)) {
5810 if (Triple.getArch() == llvm::Triple::m68k)
5811 CmdArgs.push_back(
"-fdefault-calling-conv=rtdcall");
5813 CmdArgs.push_back(
"-fdefault-calling-conv=stdcall");
5816 if (Args.hasArg(options::OPT_fenable_matrix)) {
5818 CmdArgs.push_back(
"-fenable-matrix");
5819 CmdArgs.push_back(
"-mllvm");
5820 CmdArgs.push_back(
"-enable-matrix");
5825 const char *FPKeepKindStr =
nullptr;
5826 switch (FPKeepKind) {
5828 FPKeepKindStr =
"-mframe-pointer=none";
5831 FPKeepKindStr =
"-mframe-pointer=reserved";
5834 FPKeepKindStr =
"-mframe-pointer=non-leaf";
5837 FPKeepKindStr =
"-mframe-pointer=all";
5840 assert(FPKeepKindStr &&
"unknown FramePointerKind");
5841 CmdArgs.push_back(FPKeepKindStr);
5843 Args.addOptOutFlag(CmdArgs, options::OPT_fzero_initialized_in_bss,
5844 options::OPT_fno_zero_initialized_in_bss);
5848 D.Diag(diag::warn_drv_deprecated_arg_ofast);
5851 OptSpecifier StrictAliasingAliasOption =
5852 OFastEnabled ? options::OPT_Ofast : options::OPT_fstrict_aliasing;
5855 if (!Args.hasFlag(options::OPT_fstrict_aliasing, StrictAliasingAliasOption,
5856 options::OPT_fno_strict_aliasing, !IsWindowsMSVC))
5857 CmdArgs.push_back(
"-relaxed-aliasing");
5858 if (Args.hasFlag(options::OPT_fpointer_tbaa, options::OPT_fno_pointer_tbaa,
5860 CmdArgs.push_back(
"-pointer-tbaa");
5861 if (!Args.hasFlag(options::OPT_fstruct_path_tbaa,
5862 options::OPT_fno_struct_path_tbaa,
true))
5863 CmdArgs.push_back(
"-no-struct-path-tbaa");
5864 Args.addOptInFlag(CmdArgs, options::OPT_fstrict_enums,
5865 options::OPT_fno_strict_enums);
5866 Args.addOptOutFlag(CmdArgs, options::OPT_fstrict_return,
5867 options::OPT_fno_strict_return);
5868 Args.addOptInFlag(CmdArgs, options::OPT_fallow_editor_placeholders,
5869 options::OPT_fno_allow_editor_placeholders);
5870 Args.addOptInFlag(CmdArgs, options::OPT_fstrict_vtable_pointers,
5871 options::OPT_fno_strict_vtable_pointers);
5872 Args.addOptInFlag(CmdArgs, options::OPT_fforce_emit_vtables,
5873 options::OPT_fno_force_emit_vtables);
5874 Args.addOptOutFlag(CmdArgs, options::OPT_foptimize_sibling_calls,
5875 options::OPT_fno_optimize_sibling_calls);
5876 Args.addOptOutFlag(CmdArgs, options::OPT_fescaping_block_tail_calls,
5877 options::OPT_fno_escaping_block_tail_calls);
5879 Args.AddLastArg(CmdArgs, options::OPT_ffine_grained_bitfield_accesses,
5880 options::OPT_fno_fine_grained_bitfield_accesses);
5882 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_relative_cxx_abi_vtables,
5883 options::OPT_fno_experimental_relative_cxx_abi_vtables);
5885 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_omit_vtable_rtti,
5886 options::OPT_fno_experimental_omit_vtable_rtti);
5888 Args.AddLastArg(CmdArgs, options::OPT_fdisable_block_signature_string,
5889 options::OPT_fno_disable_block_signature_string);
5892 Args.addOptInFlag(CmdArgs, options::OPT_fsplit_stack,
5893 options::OPT_fno_split_stack);
5896 if (Args.hasFlag(options::OPT_fprotect_parens,
5897 options::OPT_fno_protect_parens,
false))
5898 CmdArgs.push_back(
"-fprotect-parens");
5902 if (Arg *A = Args.getLastArg(options::OPT_fextend_args_EQ)) {
5903 const llvm::Triple::ArchType Arch = TC.
getArch();
5904 if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) {
5905 StringRef
V = A->getValue();
5907 CmdArgs.push_back(
"-fextend-arguments=64");
5909 D.Diag(diag::err_drv_invalid_argument_to_option)
5910 << A->getValue() << A->getOption().getName();
5912 D.Diag(diag::err_drv_unsupported_opt_for_target)
5913 << A->getOption().getName() << TripleStr;
5916 if (Arg *A = Args.getLastArg(options::OPT_mdouble_EQ)) {
5917 if (TC.
getArch() == llvm::Triple::avr)
5918 A->render(Args, CmdArgs);
5920 D.Diag(diag::err_drv_unsupported_opt_for_target)
5921 << A->getAsString(Args) << TripleStr;
5924 if (Arg *A = Args.getLastArg(options::OPT_LongDouble_Group)) {
5926 A->render(Args, CmdArgs);
5928 (A->getOption().getID() != options::OPT_mlong_double_80))
5929 A->render(Args, CmdArgs);
5931 D.Diag(diag::err_drv_unsupported_opt_for_target)
5932 << A->getAsString(Args) << TripleStr;
5938 if (!Args.hasFlag(options::OPT_fverbose_asm, options::OPT_fno_verbose_asm,
5939 IsIntegratedAssemblerDefault))
5940 CmdArgs.push_back(
"-fno-verbose-asm");
5944 if (Arg *A = Args.getLastArg(options::OPT_fbinutils_version_EQ)) {
5945 StringRef
V = A->getValue();
5948 A->render(Args, CmdArgs);
5949 else if (!
V.consumeInteger(10, Num) && Num > 0 &&
5950 (
V.empty() || (
V.consume_front(
".") &&
5951 !
V.consumeInteger(10, Num) &&
V.empty())))
5952 A->render(Args, CmdArgs);
5954 D.Diag(diag::err_drv_invalid_argument_to_option)
5955 << A->getValue() << A->getOption().getName();
5961 CmdArgs.push_back(
"-no-integrated-as");
5963 if (Args.hasArg(options::OPT_fdebug_pass_structure)) {
5964 CmdArgs.push_back(
"-mdebug-pass");
5965 CmdArgs.push_back(
"Structure");
5967 if (Args.hasArg(options::OPT_fdebug_pass_arguments)) {
5968 CmdArgs.push_back(
"-mdebug-pass");
5969 CmdArgs.push_back(
"Arguments");
5975 if (!RawTriple.isOSDarwin() && !RawTriple.isNVPTX())
5976 CmdArgs.push_back(
"-mconstructor-aliases");
5980 if (KernelOrKext && RawTriple.isOSDarwin())
5981 CmdArgs.push_back(
"-fforbid-guard-variables");
5983 if (Args.hasFlag(options::OPT_mms_bitfields, options::OPT_mno_ms_bitfields,
5984 Triple.isWindowsGNUEnvironment())) {
5985 CmdArgs.push_back(
"-mms-bitfields");
5988 if (Triple.isWindowsGNUEnvironment()) {
5989 Args.addOptOutFlag(CmdArgs, options::OPT_fauto_import,
5990 options::OPT_fno_auto_import);
5993 if (Args.hasFlag(options::OPT_fms_volatile, options::OPT_fno_ms_volatile,
5994 Triple.isX86() &&
D.IsCLMode()))
5995 CmdArgs.push_back(
"-fms-volatile");
6000 if (Arg *A = Args.getLastArg(options::OPT_fdirect_access_external_data,
6001 options::OPT_fno_direct_access_external_data)) {
6002 if (A->getOption().matches(options::OPT_fdirect_access_external_data) !=
6004 A->render(Args, CmdArgs);
6005 }
else if (PICLevel == 0 && Triple.isLoongArch()) {
6008 CmdArgs.push_back(
"-fno-direct-access-external-data");
6011 if (Args.hasFlag(options::OPT_fno_plt, options::OPT_fplt,
false)) {
6012 CmdArgs.push_back(
"-fno-plt");
6019 Args.hasFlag(options::OPT_ffreestanding, options::OPT_fhosted,
false) ||
6022 CmdArgs.push_back(
"-ffreestanding");
6024 Args.AddLastArg(CmdArgs, options::OPT_fno_knr_functions);
6031 bool IsAsyncUnwindTablesDefault =
6033 bool IsSyncUnwindTablesDefault =
6036 bool AsyncUnwindTables = Args.hasFlag(
6037 options::OPT_fasynchronous_unwind_tables,
6038 options::OPT_fno_asynchronous_unwind_tables,
6039 (IsAsyncUnwindTablesDefault || SanitizeArgs.needsUnwindTables()) &&
6042 Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables,
6043 IsSyncUnwindTablesDefault && !Freestanding);
6044 if (AsyncUnwindTables)
6045 CmdArgs.push_back(
"-funwind-tables=2");
6046 else if (UnwindTables)
6047 CmdArgs.push_back(
"-funwind-tables=1");
6051 if (!Args.getLastArg(options::OPT_gpu_use_aux_triple_only) &&
6052 (IsCudaDevice || IsHIPDevice)) {
6053 const ArgList &HostArgs =
6055 std::string HostCPU =
6057 if (!HostCPU.empty()) {
6058 CmdArgs.push_back(
"-aux-target-cpu");
6059 CmdArgs.push_back(Args.MakeArgString(HostCPU));
6067 addMCModel(
D, Args, Triple, RelocationModel, CmdArgs);
6069 if (Arg *A = Args.getLastArg(options::OPT_mtls_size_EQ)) {
6070 StringRef
Value = A->getValue();
6071 unsigned TLSSize = 0;
6072 Value.getAsInteger(10, TLSSize);
6073 if (!Triple.isAArch64() || !Triple.isOSBinFormatELF())
6074 D.Diag(diag::err_drv_unsupported_opt_for_target)
6075 << A->getOption().getName() << TripleStr;
6076 if (TLSSize != 12 && TLSSize != 24 && TLSSize != 32 && TLSSize != 48)
6077 D.Diag(diag::err_drv_invalid_int_value)
6078 << A->getOption().getName() <<
Value;
6079 Args.AddLastArg(CmdArgs, options::OPT_mtls_size_EQ);
6083 CmdArgs.push_back(
"-enable-tlsdesc");
6086 std::string CPU =
getCPUName(
D, Args, Triple,
false);
6088 CmdArgs.push_back(
"-target-cpu");
6089 CmdArgs.push_back(Args.MakeArgString(CPU));
6092 RenderTargetOptions(Triple, Args, KernelOrKext, CmdArgs);
6097 AddClangCLArgs(Args, InputType, CmdArgs);
6099 llvm::codegenoptions::DebugInfoKind DebugInfoKind =
6100 llvm::codegenoptions::NoDebugInfo;
6103 CmdArgs, Output, DebugInfoKind, DwarfFission);
6111 (isa<AssembleJobAction>(JA) || isa<CompileJobAction>(JA) ||
6112 isa<BackendJobAction>(JA));
6114 const char *SplitDWARFOut =
SplitDebugName(JA, Args, Input, Output);
6115 CmdArgs.push_back(
"-split-dwarf-file");
6116 CmdArgs.push_back(SplitDWARFOut);
6118 CmdArgs.push_back(
"-split-dwarf-output");
6119 CmdArgs.push_back(SplitDWARFOut);
6124 if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) {
6125 CmdArgs.push_back(
"-target-linker-version");
6126 CmdArgs.push_back(A->getValue());
6131 if (!Args.hasArg(options::OPT_fallow_unsupported)) {
6133 if (
types::isCXX(InputType) && RawTriple.isOSDarwin() &&
6134 TC.
getArch() == llvm::Triple::x86) {
6135 if ((Unsupported = Args.getLastArg(options::OPT_fapple_kext)) ||
6136 (Unsupported = Args.getLastArg(options::OPT_mkernel)))
6137 D.Diag(diag::err_drv_clang_unsupported_opt_cxx_darwin_i386)
6138 << Unsupported->getOption().getName();
6141 if ((Unsupported = Args.getLastArg(options::OPT_faltivec)))
6142 D.Diag(diag::err_drv_clang_unsupported_opt_faltivec)
6143 << Unsupported->getOption().getName()
6144 <<
"please use -maltivec and include altivec.h explicitly";
6145 if ((Unsupported = Args.getLastArg(options::OPT_fno_altivec)))
6146 D.Diag(diag::err_drv_clang_unsupported_opt_faltivec)
6147 << Unsupported->getOption().getName() <<
"please use -mno-altivec";
6150 Args.AddAllArgs(CmdArgs, options::OPT_v);
6152 if (Args.getLastArg(options::OPT_H)) {
6153 CmdArgs.push_back(
"-H");
6154 CmdArgs.push_back(
"-sys-header-deps");
6156 Args.AddAllArgs(CmdArgs, options::OPT_fshow_skipped_includes);
6158 if (
D.CCPrintHeadersFormat && !
D.CCGenDiagnostics) {
6159 CmdArgs.push_back(
"-header-include-file");
6160 CmdArgs.push_back(!
D.CCPrintHeadersFilename.empty()
6161 ?
D.CCPrintHeadersFilename.c_str()
6163 CmdArgs.push_back(
"-sys-header-deps");
6164 CmdArgs.push_back(Args.MakeArgString(
6165 "-header-include-format=" +
6168 Args.MakeArgString(
"-header-include-filtering=" +
6170 D.CCPrintHeadersFiltering))));
6172 Args.AddLastArg(CmdArgs, options::OPT_P);
6173 Args.AddLastArg(CmdArgs, options::OPT_print_ivar_layout);
6175 if (
D.CCLogDiagnostics && !
D.CCGenDiagnostics) {
6176 CmdArgs.push_back(
"-diagnostic-log-file");
6177 CmdArgs.push_back(!
D.CCLogDiagnosticsFilename.empty()
6178 ?
D.CCLogDiagnosticsFilename.c_str()
6184 if (
D.CCGenDiagnostics)
6185 CmdArgs.push_back(
"-disable-pragma-debug-crash");
6189 if (Args.hasArg(options::OPT_fcrash_diagnostics_dir)) {
6190 StringRef Dir = Args.getLastArgValue(options::OPT_fcrash_diagnostics_dir);
6191 CmdArgs.push_back(
"-mllvm");
6192 CmdArgs.push_back(Args.MakeArgString(
"-crash-diagnostics-dir=" + Dir));
6197 if (Args.hasFlag(options::OPT_ffunction_sections,
6198 options::OPT_fno_function_sections, UseSeparateSections)) {
6199 CmdArgs.push_back(
"-ffunction-sections");
6202 if (Arg *A = Args.getLastArg(options::OPT_fbasic_block_address_map,
6203 options::OPT_fno_basic_block_address_map)) {
6204 if ((Triple.isX86() || Triple.isAArch64()) && Triple.isOSBinFormatELF()) {
6205 if (A->getOption().matches(options::OPT_fbasic_block_address_map))
6206 A->render(Args, CmdArgs);
6208 D.Diag(diag::err_drv_unsupported_opt_for_target)
6209 << A->getAsString(Args) << TripleStr;
6213 if (Arg *A = Args.getLastArg(options::OPT_fbasic_block_sections_EQ)) {
6214 StringRef Val = A->getValue();
6215 if (Triple.isX86() && Triple.isOSBinFormatELF()) {
6216 if (Val !=
"all" && Val !=
"labels" && Val !=
"none" &&
6217 !Val.starts_with(
"list="))
6218 D.Diag(diag::err_drv_invalid_value)
6219 << A->getAsString(Args) << A->getValue();
6221 A->render(Args, CmdArgs);
6222 }
else if (Triple.isAArch64() && Triple.isOSBinFormatELF()) {
6225 if (Val !=
"labels" && Val !=
"none" && !Val.starts_with(
"list="))
6226 D.Diag(diag::err_drv_invalid_value)
6227 << A->getAsString(Args) << A->getValue();
6229 A->render(Args, CmdArgs);
6230 }
else if (Triple.isNVPTX()) {
6233 }
else if (Val !=
"none") {
6236 D.Diag(diag::err_drv_unsupported_opt_for_target)
6237 << A->getAsString(Args) << TripleStr;
6241 bool HasDefaultDataSections = Triple.isOSBinFormatXCOFF();
6242 if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
6243 UseSeparateSections || HasDefaultDataSections)) {
6244 CmdArgs.push_back(
"-fdata-sections");
6247 Args.addOptOutFlag(CmdArgs, options::OPT_funique_section_names,
6248 options::OPT_fno_unique_section_names);
6249 Args.addOptInFlag(CmdArgs, options::OPT_fseparate_named_sections,
6250 options::OPT_fno_separate_named_sections);
6251 Args.addOptInFlag(CmdArgs, options::OPT_funique_internal_linkage_names,
6252 options::OPT_fno_unique_internal_linkage_names);
6253 Args.addOptInFlag(CmdArgs, options::OPT_funique_basic_block_section_names,
6254 options::OPT_fno_unique_basic_block_section_names);
6255 Args.addOptInFlag(CmdArgs, options::OPT_fconvergent_functions,
6256 options::OPT_fno_convergent_functions);
6258 if (Arg *A = Args.getLastArg(options::OPT_fsplit_machine_functions,
6259 options::OPT_fno_split_machine_functions)) {
6260 if (!A->getOption().matches(options::OPT_fno_split_machine_functions)) {
6262 if ((Triple.isX86() || Triple.isAArch64()) && Triple.isOSBinFormatELF())
6263 A->render(Args, CmdArgs);
6265 D.Diag(diag::err_drv_unsupported_opt_for_target)
6266 << A->getAsString(Args) << TripleStr;
6270 Args.AddLastArg(CmdArgs, options::OPT_finstrument_functions,
6271 options::OPT_finstrument_functions_after_inlining,
6272 options::OPT_finstrument_function_entry_bare);
6277 if (!Triple.isNVPTX() && !Triple.isAMDGCN())
6280 Args.AddLastArg(CmdArgs, options::OPT_fclang_abi_compat_EQ);
6283 Args.hasArg(options::OPT_fsample_profile_use_profi)) {
6284 CmdArgs.push_back(
"-mllvm");
6285 CmdArgs.push_back(
"-sample-profile-use-profi");
6289 if (RawTriple.isPS() &&
6290 !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
6296 if (Args.hasArg(options::OPT_nostdinc)) {
6297 CmdArgs.push_back(
"-nostdsysteminc");
6298 CmdArgs.push_back(
"-nobuiltininc");
6300 if (Args.hasArg(options::OPT_nostdlibinc))
6301 CmdArgs.push_back(
"-nostdsysteminc");
6302 Args.AddLastArg(CmdArgs, options::OPT_nostdincxx);
6303 Args.AddLastArg(CmdArgs, options::OPT_nobuiltininc);
6307 CmdArgs.push_back(
"-resource-dir");
6308 CmdArgs.push_back(
D.ResourceDir.c_str());
6310 Args.AddLastArg(CmdArgs, options::OPT_working_directory);
6319 AddPreprocessingOptions(
C, JA,
D, Args, CmdArgs, Output, Inputs);
6325 Args.ClaimAllArgs(options::OPT_D);
6328 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
6329 if (A->getOption().matches(options::OPT_O4)) {
6330 CmdArgs.push_back(
"-O3");
6331 D.Diag(diag::warn_O4_is_O3);
6333 A->render(Args, CmdArgs);
6339 Args.filtered(options::OPT_clang_ignored_gcc_optimization_f_Group)) {
6340 D.Diag(diag::warn_ignored_gcc_optimization) << A->getAsString(Args);
6345 Args.filtered(options::OPT_clang_ignored_legacy_options_Group)) {
6346 D.Diag(diag::warn_ignored_clang_option) << A->getAsString(Args);
6352 Args.AddAllArgs(CmdArgs, options::OPT_R_Group);
6355 Args.filtered(options::OPT_W_Group, options::OPT__SLASH_wd)) {
6357 if (A->getOption().getID() == options::OPT__SLASH_wd) {
6358 unsigned WarningNumber;
6359 if (StringRef(A->getValue()).getAsInteger(10, WarningNumber)) {
6360 D.Diag(diag::err_drv_invalid_int_value)
6361 << A->getAsString(Args) << A->getValue();
6366 CmdArgs.push_back(Args.MakeArgString(
6371 A->render(Args, CmdArgs);
6374 Args.AddAllArgs(CmdArgs, options::OPT_Wsystem_headers_in_module_EQ);
6376 if (Args.hasFlag(options::OPT_pedantic, options::OPT_no_pedantic,
false))
6377 CmdArgs.push_back(
"-pedantic");
6378 Args.AddLastArg(CmdArgs, options::OPT_pedantic_errors);
6379 Args.AddLastArg(CmdArgs, options::OPT_w);
6381 Args.addOptInFlag(CmdArgs, options::OPT_ffixed_point,
6382 options::OPT_fno_fixed_point);
6384 if (Arg *A = Args.getLastArg(options::OPT_fcxx_abi_EQ))
6385 A->render(Args, CmdArgs);
6387 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_relative_cxx_abi_vtables,
6388 options::OPT_fno_experimental_relative_cxx_abi_vtables);
6390 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_omit_vtable_rtti,
6391 options::OPT_fno_experimental_omit_vtable_rtti);
6393 if (Arg *A = Args.getLastArg(options::OPT_ffuchsia_api_level_EQ))
6394 A->render(Args, CmdArgs);
6401 bool ImplyVCPPCVer =
false;
6402 bool ImplyVCPPCXXVer =
false;
6403 const Arg *
Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi);
6405 if (
Std->getOption().matches(options::OPT_ansi))
6407 CmdArgs.push_back(
"-std=c++98");
6409 CmdArgs.push_back(
"-std=c89");
6411 Std->render(Args, CmdArgs);
6414 if (Arg *A = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi,
6415 options::OPT_ftrigraphs,
6416 options::OPT_fno_trigraphs))
6418 A->render(Args, CmdArgs);
6427 if (!Args.hasArg(options::OPT__SLASH_std)) {
6428 Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ,
"-std=",
6431 ImplyVCPPCVer =
true;
6433 else if (IsWindowsMSVC)
6434 ImplyVCPPCXXVer =
true;
6436 Args.AddLastArg(CmdArgs, options::OPT_ftrigraphs,
6437 options::OPT_fno_trigraphs);
6453 Args.getLastArg(options::OPT_Wwrite_strings,
6454 options::OPT_Wno_write_strings, options::OPT_w);
6456 WriteStrings->getOption().matches(options::OPT_Wwrite_strings))
6457 CmdArgs.push_back(
"-fconst-strings");
6464 Args.hasFlag(options::OPT_Wdeprecated, options::OPT_Wno_deprecated,
6466 CmdArgs.push_back(
"-fdeprecated-macro");
6470 if (Arg *
Asm = Args.getLastArg(options::OPT_fasm, options::OPT_fno_asm)) {
6471 if (
Asm->getOption().matches(options::OPT_fasm))
6472 CmdArgs.push_back(
"-fgnu-keywords");
6474 CmdArgs.push_back(
"-fno-gnu-keywords");
6478 CmdArgs.push_back(
"-fno-autolink");
6480 Args.AddLastArg(CmdArgs, options::OPT_ftemplate_depth_EQ);
6481 Args.AddLastArg(CmdArgs, options::OPT_foperator_arrow_depth_EQ);
6482 Args.AddLastArg(CmdArgs, options::OPT_fconstexpr_depth_EQ);
6483 Args.AddLastArg(CmdArgs, options::OPT_fconstexpr_steps_EQ);
6485 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_library);
6487 if (Args.hasArg(options::OPT_fexperimental_new_constant_interpreter))
6488 CmdArgs.push_back(
"-fexperimental-new-constant-interpreter");
6490 if (Arg *A = Args.getLastArg(options::OPT_fbracket_depth_EQ)) {
6491 CmdArgs.push_back(
"-fbracket-depth");
6492 CmdArgs.push_back(A->getValue());
6495 if (Arg *A = Args.getLastArg(options::OPT_Wlarge_by_value_copy_EQ,
6496 options::OPT_Wlarge_by_value_copy_def)) {
6497 if (A->getNumValues()) {
6498 StringRef
bytes = A->getValue();
6499 CmdArgs.push_back(Args.MakeArgString(
"-Wlarge-by-value-copy=" +
bytes));
6501 CmdArgs.push_back(
"-Wlarge-by-value-copy=64");
6504 if (Args.hasArg(options::OPT_relocatable_pch))
6505 CmdArgs.push_back(
"-relocatable-pch");
6507 if (
const Arg *A = Args.getLastArg(options::OPT_fcf_runtime_abi_EQ)) {
6508 static const char *kCFABIs[] = {
6509 "standalone",
"objc",
"swift",
"swift-5.0",
"swift-4.2",
"swift-4.1",
6512 if (!llvm::is_contained(kCFABIs, StringRef(A->getValue())))
6513 D.Diag(diag::err_drv_invalid_cf_runtime_abi) << A->getValue();
6515 A->render(Args, CmdArgs);
6518 if (Arg *A = Args.getLastArg(options::OPT_fconstant_string_class_EQ)) {
6519 CmdArgs.push_back(
"-fconstant-string-class");
6520 CmdArgs.push_back(A->getValue());
6523 if (Arg *A = Args.getLastArg(options::OPT_ftabstop_EQ)) {
6524 CmdArgs.push_back(
"-ftabstop");
6525 CmdArgs.push_back(A->getValue());
6528 Args.addOptInFlag(CmdArgs, options::OPT_fstack_size_section,
6529 options::OPT_fno_stack_size_section);
6531 if (Args.hasArg(options::OPT_fstack_usage)) {
6532 CmdArgs.push_back(
"-stack-usage-file");
6534 if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) {
6536 llvm::sys::path::replace_extension(OutputFilename,
"su");
6537 CmdArgs.push_back(Args.MakeArgString(OutputFilename));
6543 CmdArgs.push_back(
"-ferror-limit");
6544 if (Arg *A = Args.getLastArg(options::OPT_ferror_limit_EQ))
6545 CmdArgs.push_back(A->getValue());
6547 CmdArgs.push_back(
"19");
6549 Args.AddLastArg(CmdArgs, options::OPT_fconstexpr_backtrace_limit_EQ);
6550 Args.AddLastArg(CmdArgs, options::OPT_fmacro_backtrace_limit_EQ);
6551 Args.AddLastArg(CmdArgs, options::OPT_ftemplate_backtrace_limit_EQ);
6552 Args.AddLastArg(CmdArgs, options::OPT_fspell_checking_limit_EQ);
6553 Args.AddLastArg(CmdArgs, options::OPT_fcaret_diagnostics_max_lines_EQ);
6556 unsigned MessageLength = 0;
6557 if (Arg *A = Args.getLastArg(options::OPT_fmessage_length_EQ)) {
6558 StringRef
V(A->getValue());
6559 if (
V.getAsInteger(0, MessageLength))
6560 D.Diag(diag::err_drv_invalid_argument_to_option)
6561 <<
V << A->getOption().getName();
6565 MessageLength = llvm::sys::Process::StandardErrColumns();
6567 if (MessageLength != 0)
6569 Args.MakeArgString(
"-fmessage-length=" + Twine(MessageLength)));
6571 if (Arg *A = Args.getLastArg(options::OPT_frandomize_layout_seed_EQ))
6573 Args.MakeArgString(
"-frandomize-layout-seed=" + Twine(A->getValue(0))));
6575 if (Arg *A = Args.getLastArg(options::OPT_frandomize_layout_seed_file_EQ))
6576 CmdArgs.push_back(Args.MakeArgString(
"-frandomize-layout-seed-file=" +
6577 Twine(A->getValue(0))));
6580 if (
const Arg *A = Args.getLastArg(options::OPT_fvisibility_EQ,
6581 options::OPT_fvisibility_ms_compat)) {
6582 if (A->getOption().matches(options::OPT_fvisibility_EQ)) {
6583 A->render(Args, CmdArgs);
6585 assert(A->getOption().matches(options::OPT_fvisibility_ms_compat));
6586 CmdArgs.push_back(
"-fvisibility=hidden");
6587 CmdArgs.push_back(
"-ftype-visibility=default");
6589 }
else if (IsOpenMPDevice) {
6593 CmdArgs.push_back(
"-fvisibility=protected");
6597 if (!RawTriple.isPS()) {
6599 Args.getLastArg(options::OPT_fvisibility_from_dllstorageclass,
6600 options::OPT_fno_visibility_from_dllstorageclass)) {
6601 if (A->getOption().matches(
6602 options::OPT_fvisibility_from_dllstorageclass)) {
6603 CmdArgs.push_back(
"-fvisibility-from-dllstorageclass");
6604 Args.AddLastArg(CmdArgs, options::OPT_fvisibility_dllexport_EQ);
6605 Args.AddLastArg(CmdArgs, options::OPT_fvisibility_nodllstorageclass_EQ);
6606 Args.AddLastArg(CmdArgs, options::OPT_fvisibility_externs_dllimport_EQ);
6607 Args.AddLastArg(CmdArgs,
6608 options::OPT_fvisibility_externs_nodllstorageclass_EQ);
6613 if (Args.hasFlag(options::OPT_fvisibility_inlines_hidden,
6614 options::OPT_fno_visibility_inlines_hidden,
false))
6615 CmdArgs.push_back(
"-fvisibility-inlines-hidden");
6617 Args.AddLastArg(CmdArgs, options::OPT_fvisibility_inlines_hidden_static_local_var,
6618 options::OPT_fno_visibility_inlines_hidden_static_local_var);
6623 Args.getLastArg(options::OPT_fvisibility_global_new_delete_hidden)) {
6624 D.Diag(diag::warn_drv_deprecated_arg)
6625 << A->getAsString(Args) <<
true
6626 <<
"-fvisibility-global-new-delete=force-hidden";
6630 Args.getLastArg(options::OPT_fvisibility_global_new_delete_EQ,
6631 options::OPT_fvisibility_global_new_delete_hidden)) {
6632 if (A->getOption().matches(options::OPT_fvisibility_global_new_delete_EQ)) {
6633 A->render(Args, CmdArgs);
6635 assert(A->getOption().matches(
6636 options::OPT_fvisibility_global_new_delete_hidden));
6637 CmdArgs.push_back(
"-fvisibility-global-new-delete=force-hidden");
6641 Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ);
6643 if (Args.hasFlag(options::OPT_fnew_infallible,
6644 options::OPT_fno_new_infallible,
false))
6645 CmdArgs.push_back(
"-fnew-infallible");
6647 if (Args.hasFlag(options::OPT_fno_operator_names,
6648 options::OPT_foperator_names,
false))
6649 CmdArgs.push_back(
"-fno-operator-names");
6652 Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
6653 Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
6654 Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs);
6655 Args.AddLastArg(CmdArgs, options::OPT_fzero_call_used_regs_EQ);
6656 Args.AddLastArg(CmdArgs, options::OPT_fraw_string_literals,
6657 options::OPT_fno_raw_string_literals);
6659 if (Args.hasFlag(options::OPT_femulated_tls, options::OPT_fno_emulated_tls,
6660 Triple.hasDefaultEmulatedTLS()))
6661 CmdArgs.push_back(
"-femulated-tls");
6663 Args.addOptInFlag(CmdArgs, options::OPT_fcheck_new,
6664 options::OPT_fno_check_new);
6666 if (Arg *A = Args.getLastArg(options::OPT_fzero_call_used_regs_EQ)) {
6670 if (!Triple.isX86() && !Triple.isAArch64())
6671 D.Diag(diag::err_drv_unsupported_opt_for_target)
6672 << A->getAsString(Args) << TripleStr;
6676 if (!isa<PreprocessJobAction>(JA) || Output.
getType() != types::TY_PP_Asm)
6677 Args.AddLastArg(CmdArgs, options::OPT_fzvector);
6679 Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_show_template_tree);
6680 Args.AddLastArg(CmdArgs, options::OPT_fno_elide_type);
6684 if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
6685 options::OPT_fno_openmp,
false) &&
6686 !Args.hasFlag(options::OPT_foffload_via_llvm,
6687 options::OPT_fno_offload_via_llvm,
false) &&
6690 switch (
D.getOpenMPRuntime(Args)) {
6694 CmdArgs.push_back(
"-fopenmp");
6699 if (!Args.hasFlag(options::OPT_fopenmp_use_tls,
6700 options::OPT_fnoopenmp_use_tls,
true))
6701 CmdArgs.push_back(
"-fnoopenmp-use-tls");
6702 Args.AddLastArg(CmdArgs, options::OPT_fopenmp_simd,
6703 options::OPT_fno_openmp_simd);
6704 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_enable_irbuilder);
6705 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
6706 if (!Args.hasFlag(options::OPT_fopenmp_extensions,
6707 options::OPT_fno_openmp_extensions,
true))
6708 CmdArgs.push_back(
"-fno-openmp-extensions");
6709 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_cuda_number_of_sm_EQ);
6710 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_cuda_blocks_per_sm_EQ);
6711 Args.AddAllArgs(CmdArgs,
6712 options::OPT_fopenmp_cuda_teams_reduction_recs_num_EQ);
6713 if (Args.hasFlag(options::OPT_fopenmp_optimistic_collapse,
6714 options::OPT_fno_openmp_optimistic_collapse,
6716 CmdArgs.push_back(
"-fopenmp-optimistic-collapse");
6720 if (Args.hasFlag(options::OPT_fopenmp_cuda_mode,
6721 options::OPT_fno_openmp_cuda_mode,
false))
6722 CmdArgs.push_back(
"-fopenmp-cuda-mode");
6725 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_target_debug_EQ);
6726 if (Args.hasFlag(options::OPT_fopenmp_target_debug,
6727 options::OPT_fno_openmp_target_debug,
false))
6728 CmdArgs.push_back(
"-fopenmp-target-debug");
6732 if (Args.hasFlag(options::OPT_fopenmp_assume_teams_oversubscription,
6733 options::OPT_fno_openmp_assume_teams_oversubscription,
6735 CmdArgs.push_back(
"-fopenmp-assume-teams-oversubscription");
6736 if (Args.hasFlag(options::OPT_fopenmp_assume_threads_oversubscription,
6737 options::OPT_fno_openmp_assume_threads_oversubscription,
6739 CmdArgs.push_back(
"-fopenmp-assume-threads-oversubscription");
6740 if (Args.hasArg(options::OPT_fopenmp_assume_no_thread_state))
6741 CmdArgs.push_back(
"-fopenmp-assume-no-thread-state");
6742 if (Args.hasArg(options::OPT_fopenmp_assume_no_nested_parallelism))
6743 CmdArgs.push_back(
"-fopenmp-assume-no-nested-parallelism");
6744 if (Args.hasArg(options::OPT_fopenmp_offload_mandatory))
6745 CmdArgs.push_back(
"-fopenmp-offload-mandatory");
6746 if (Args.hasArg(options::OPT_fopenmp_force_usm))
6747 CmdArgs.push_back(
"-fopenmp-force-usm");
6759 Args.AddLastArg(CmdArgs, options::OPT_fopenmp_simd,
6760 options::OPT_fno_openmp_simd);
6761 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
6762 Args.addOptOutFlag(CmdArgs, options::OPT_fopenmp_extensions,
6763 options::OPT_fno_openmp_extensions);
6768 if (Args.hasFlag(options::OPT_foffload_via_llvm,
6769 options::OPT_fno_offload_via_llvm,
false)) {
6770 CmdArgs.append({
"--offload-new-driver",
"-foffload-via-llvm"});
6771 }
else if (Args.hasFlag(options::OPT_offload_new_driver,
6772 options::OPT_no_offload_new_driver,
false)) {
6773 CmdArgs.push_back(
"--offload-new-driver");
6776 SanitizeArgs.addArgs(TC, Args, CmdArgs, InputType);
6779 XRay.
addArgs(TC, Args, CmdArgs, InputType);
6782 Args.getAllArgValues(options::OPT_fprofile_list_EQ)) {
6784 CmdArgs.push_back(Args.MakeArgString(
"-fprofile-list=" +
Filename));
6786 D.Diag(clang::diag::err_drv_no_such_file) <<
Filename;
6789 if (Arg *A = Args.getLastArg(options::OPT_fpatchable_function_entry_EQ)) {
6790 StringRef S0 = A->getValue(), S = S0;
6791 unsigned Size, Offset = 0;
6792 if (!Triple.isAArch64() && !Triple.isLoongArch() && !Triple.isRISCV() &&
6794 !(!Triple.isOSAIX() && (Triple.getArch() == llvm::Triple::ppc ||
6795 Triple.getArch() == llvm::Triple::ppc64)))
6796 D.Diag(diag::err_drv_unsupported_opt_for_target)
6797 << A->getAsString(Args) << TripleStr;
6798 else if (S.consumeInteger(10, Size) ||
6799 (!S.empty() && (!S.consume_front(
",") ||
6800 S.consumeInteger(10, Offset) || !S.empty())))
6801 D.Diag(diag::err_drv_invalid_argument_to_option)
6802 << S0 << A->getOption().getName();
6803 else if (Size < Offset)
6804 D.Diag(diag::err_drv_unsupported_fpatchable_function_entry_argument);
6806 CmdArgs.push_back(Args.MakeArgString(A->getSpelling() + Twine(Size)));
6807 CmdArgs.push_back(Args.MakeArgString(
6808 "-fpatchable-function-entry-offset=" + Twine(Offset)));
6812 Args.AddLastArg(CmdArgs, options::OPT_fms_hotpatch);
6815 Args.AddLastArg(CmdArgs, options::OPT_pg);
6817 llvm::Triple::ArchType Arch = TC.
getArch();
6818 if (Arg *A = Args.getLastArg(options::OPT_mfentry)) {
6819 if (Arch == llvm::Triple::systemz || TC.
getTriple().isX86())
6820 A->render(Args, CmdArgs);
6822 D.Diag(diag::err_drv_unsupported_opt_for_target)
6823 << A->getAsString(Args) << TripleStr;
6825 if (Arg *A = Args.getLastArg(options::OPT_mnop_mcount)) {
6826 if (Arch == llvm::Triple::systemz)
6827 A->render(Args, CmdArgs);
6829 D.Diag(diag::err_drv_unsupported_opt_for_target)
6830 << A->getAsString(Args) << TripleStr;
6832 if (Arg *A = Args.getLastArg(options::OPT_mrecord_mcount)) {
6833 if (Arch == llvm::Triple::systemz)
6834 A->render(Args, CmdArgs);
6836 D.Diag(diag::err_drv_unsupported_opt_for_target)
6837 << A->getAsString(Args) << TripleStr;
6841 if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) {
6843 D.Diag(diag::err_drv_unsupported_opt_for_target)
6844 << A->getAsString(Args) << TripleStr;
6847 if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
6849 D.Diag(diag::err_drv_unsupported_opt_for_target)
6850 << A->getAsString(Args) << TripleStr;
6853 if (Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg)) {
6854 if (A->getOption().matches(options::OPT_p)) {
6856 if (TC.
getTriple().isOSAIX() && !Args.hasArgNoClaim(options::OPT_pg))
6857 CmdArgs.push_back(
"-pg");
6863 for (
const Arg *A : Args.filtered(options::OPT_b, options::OPT_K,
6864 options::OPT_mxcoff_build_id_EQ)) {
6865 D.Diag(diag::err_drv_unsupported_opt_for_target)
6866 << A->getSpelling() << TripleStr;
6870 if (Args.getLastArg(options::OPT_fapple_kext) ||
6871 (Args.hasArg(options::OPT_mkernel) &&
types::isCXX(InputType)))
6872 CmdArgs.push_back(
"-fapple-kext");
6874 Args.AddLastArg(CmdArgs, options::OPT_altivec_src_compat);
6875 Args.AddLastArg(CmdArgs, options::OPT_flax_vector_conversions_EQ);
6876 Args.AddLastArg(CmdArgs, options::OPT_fobjc_sender_dependent_dispatch);
6877 Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_print_source_range_info);
6878 Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_parseable_fixits);
6879 Args.AddLastArg(CmdArgs, options::OPT_ftime_report);
6880 Args.AddLastArg(CmdArgs, options::OPT_ftime_report_EQ);
6881 Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
6882 Args.AddLastArg(CmdArgs, options::OPT_malign_double);
6883 Args.AddLastArg(CmdArgs, options::OPT_fno_temp_file);
6885 if (
const char *Name =
C.getTimeTraceFile(&JA)) {
6886 CmdArgs.push_back(Args.MakeArgString(
"-ftime-trace=" + Twine(Name)));
6887 Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
6888 Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_verbose);
6891 if (Arg *A = Args.getLastArg(options::OPT_ftrapv_handler_EQ)) {
6892 CmdArgs.push_back(
"-ftrapv-handler");
6893 CmdArgs.push_back(A->getValue());
6896 Args.AddLastArg(CmdArgs, options::OPT_ftrap_function_EQ);
6900 if (Arg *A = Args.getLastArg(options::OPT_fwrapv, options::OPT_fno_wrapv)) {
6901 if (A->getOption().matches(options::OPT_fwrapv))
6902 CmdArgs.push_back(
"-fwrapv");
6903 }
else if (Arg *A = Args.getLastArg(options::OPT_fstrict_overflow,
6904 options::OPT_fno_strict_overflow)) {
6905 if (A->getOption().matches(options::OPT_fno_strict_overflow))
6906 CmdArgs.push_back(
"-fwrapv");
6909 Args.AddLastArg(CmdArgs, options::OPT_ffinite_loops,
6910 options::OPT_fno_finite_loops);
6912 Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings);
6913 Args.AddLastArg(CmdArgs, options::OPT_funroll_loops,
6914 options::OPT_fno_unroll_loops);
6916 Args.AddLastArg(CmdArgs, options::OPT_fstrict_flex_arrays_EQ);
6918 Args.AddLastArg(CmdArgs, options::OPT_pthread);
6920 Args.addOptInFlag(CmdArgs, options::OPT_mspeculative_load_hardening,
6921 options::OPT_mno_speculative_load_hardening);
6927 Args.AddLastArg(CmdArgs, options::OPT_fswift_async_fp_EQ);
6929 Args.addOptInFlag(CmdArgs, options::OPT_mstackrealign,
6930 options::OPT_mno_stackrealign);
6932 if (Args.hasArg(options::OPT_mstack_alignment)) {
6933 StringRef alignment = Args.getLastArgValue(options::OPT_mstack_alignment);
6934 CmdArgs.push_back(Args.MakeArgString(
"-mstack-alignment=" + alignment));
6937 if (Args.hasArg(options::OPT_mstack_probe_size)) {
6938 StringRef Size = Args.getLastArgValue(options::OPT_mstack_probe_size);
6941 CmdArgs.push_back(Args.MakeArgString(
"-mstack-probe-size=" + Size));
6943 CmdArgs.push_back(
"-mstack-probe-size=0");
6946 Args.addOptOutFlag(CmdArgs, options::OPT_mstack_arg_probe,
6947 options::OPT_mno_stack_arg_probe);
6949 if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it,
6950 options::OPT_mno_restrict_it)) {
6951 if (A->getOption().matches(options::OPT_mrestrict_it)) {
6952 CmdArgs.push_back(
"-mllvm");
6953 CmdArgs.push_back(
"-arm-restrict-it");
6955 CmdArgs.push_back(
"-mllvm");
6956 CmdArgs.push_back(
"-arm-default-it");
6970 if (Args.hasFlag(options::OPT_fhip_new_launch_api,
6971 options::OPT_fno_hip_new_launch_api,
true))
6972 CmdArgs.push_back(
"-fhip-new-launch-api");
6973 Args.addOptInFlag(CmdArgs, options::OPT_fgpu_allow_device_init,
6974 options::OPT_fno_gpu_allow_device_init);
6975 Args.AddLastArg(CmdArgs, options::OPT_hipstdpar);
6976 Args.AddLastArg(CmdArgs, options::OPT_hipstdpar_interpose_alloc);
6977 Args.addOptInFlag(CmdArgs, options::OPT_fhip_kernel_arg_name,
6978 options::OPT_fno_hip_kernel_arg_name);
6981 if (IsCuda || IsHIP) {
6983 CmdArgs.push_back(
"-fgpu-rdc");
6984 Args.addOptInFlag(CmdArgs, options::OPT_fgpu_defer_diag,
6985 options::OPT_fno_gpu_defer_diag);
6986 if (Args.hasFlag(options::OPT_fgpu_exclude_wrong_side_overloads,
6987 options::OPT_fno_gpu_exclude_wrong_side_overloads,
6989 CmdArgs.push_back(
"-fgpu-exclude-wrong-side-overloads");
6990 CmdArgs.push_back(
"-fgpu-defer-diag");
6995 if (Args.hasArg(options::OPT_nogpulib))
6996 CmdArgs.push_back(
"-nogpulib");
6998 if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
7000 Args.MakeArgString(Twine(
"-fcf-protection=") + A->getValue()));
7003 if (Arg *A = Args.getLastArg(options::OPT_mfunction_return_EQ))
7005 Args.MakeArgString(Twine(
"-mfunction-return=") + A->getValue()));
7007 Args.AddLastArg(CmdArgs, options::OPT_mindirect_branch_cs_prefix);
7012 if (!(IsCudaDevice || IsHIPDevice)) {
7014 auto *PGOArg = Args.getLastArg(
7015 options::OPT_fprofile_generate, options::OPT_fprofile_generate_EQ,
7016 options::OPT_fcs_profile_generate,
7017 options::OPT_fcs_profile_generate_EQ, options::OPT_fprofile_use,
7018 options::OPT_fprofile_use_EQ);
7020 D.Diag(diag::err_drv_argument_not_allowed_with)
7021 <<
"SampleUse with PGO options";
7023 StringRef fname = A->getValue();
7024 if (!llvm::sys::fs::exists(fname))
7025 D.Diag(diag::err_drv_no_such_file) << fname;
7027 A->render(Args, CmdArgs);
7029 Args.AddLastArg(CmdArgs, options::OPT_fprofile_remapping_file_EQ);
7031 if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
7032 options::OPT_fno_pseudo_probe_for_profiling,
false)) {
7033 CmdArgs.push_back(
"-fpseudo-probe-for-profiling");
7036 if (Args.hasFlag(options::OPT_funique_internal_linkage_names,
7037 options::OPT_fno_unique_internal_linkage_names,
true))
7038 CmdArgs.push_back(
"-funique-internal-linkage-names");
7043 Args.addOptOutFlag(CmdArgs, options::OPT_fassume_sane_operator_new,
7044 options::OPT_fno_assume_sane_operator_new);
7046 if (Args.hasFlag(options::OPT_fapinotes, options::OPT_fno_apinotes,
false))
7047 CmdArgs.push_back(
"-fapinotes");
7048 if (Args.hasFlag(options::OPT_fapinotes_modules,
7049 options::OPT_fno_apinotes_modules,
false))
7050 CmdArgs.push_back(
"-fapinotes-modules");
7051 Args.AddLastArg(CmdArgs, options::OPT_fapinotes_swift_version);
7054 if (Args.hasFlag(options::OPT_fblocks, options::OPT_fno_blocks,
7056 (Args.hasArg(options::OPT_fgnu_runtime) &&
7057 Args.hasArg(options::OPT_fobjc_nonfragile_abi) &&
7058 !Args.hasArg(options::OPT_fno_blocks))) {
7059 CmdArgs.push_back(
"-fblocks");
7062 CmdArgs.push_back(
"-fblocks-runtime-optional");
7067 CmdArgs.push_back(
"-fencode-extended-block-signature");
7069 if (Args.hasFlag(options::OPT_fcoro_aligned_allocation,
7070 options::OPT_fno_coro_aligned_allocation,
false) &&
7072 CmdArgs.push_back(
"-fcoro-aligned-allocation");
7074 Args.AddLastArg(CmdArgs, options::OPT_fdouble_square_bracket_attributes,
7075 options::OPT_fno_double_square_bracket_attributes);
7077 Args.addOptOutFlag(CmdArgs, options::OPT_faccess_control,
7078 options::OPT_fno_access_control);
7079 Args.addOptOutFlag(CmdArgs, options::OPT_felide_constructors,
7080 options::OPT_fno_elide_constructors);
7086 CmdArgs.push_back(
"-fno-rtti");
7089 if (Args.hasFlag(options::OPT_fshort_enums, options::OPT_fno_short_enums,
7090 TC.
getArch() == llvm::Triple::hexagon || Triple.isOSzOS()))
7091 CmdArgs.push_back(
"-fshort-enums");
7097 options::OPT_fuse_cxa_atexit, options::OPT_fno_use_cxa_atexit,
7098 !RawTriple.isOSAIX() && !RawTriple.isOSWindows() &&
7099 ((RawTriple.getVendor() != llvm::Triple::MipsTechnologies) ||
7100 RawTriple.hasEnvironment())) ||
7102 CmdArgs.push_back(
"-fno-use-cxa-atexit");
7104 if (Args.hasFlag(options::OPT_fregister_global_dtors_with_atexit,
7105 options::OPT_fno_register_global_dtors_with_atexit,
7106 RawTriple.isOSDarwin() && !KernelOrKext))
7107 CmdArgs.push_back(
"-fregister-global-dtors-with-atexit");
7109 Args.addOptInFlag(CmdArgs, options::OPT_fuse_line_directives,
7110 options::OPT_fno_use_line_directives);
7113 if (Args.hasFlag(options::OPT_fminimize_whitespace,
7114 options::OPT_fno_minimize_whitespace,
false)) {
7115 types::ID InputType = Inputs[0].getType();
7116 if (!isDerivedFromC(InputType))
7117 D.Diag(diag::err_drv_opt_unsupported_input_type)
7119 CmdArgs.push_back(
"-fminimize-whitespace");
7123 if (Args.hasFlag(options::OPT_fkeep_system_includes,
7124 options::OPT_fno_keep_system_includes,
false)) {
7125 types::ID InputType = Inputs[0].getType();
7126 if (!isDerivedFromC(InputType))
7127 D.Diag(diag::err_drv_opt_unsupported_input_type)
7129 CmdArgs.push_back(
"-fkeep-system-includes");
7133 if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
7135 CmdArgs.push_back(
"-fms-extensions");
7138 bool IsMSVCCompat = Args.hasFlag(
7139 options::OPT_fms_compatibility, options::OPT_fno_ms_compatibility,
7140 (IsWindowsMSVC && Args.hasFlag(options::OPT_fms_extensions,
7141 options::OPT_fno_ms_extensions,
true)));
7143 CmdArgs.push_back(
"-fms-compatibility");
7145 Args.hasArg(options::OPT_fms_define_stdc))
7146 CmdArgs.push_back(
"-fms-define-stdc");
7149 if (Triple.isWindowsMSVCEnvironment() && !
D.IsCLMode() &&
7150 Args.hasArg(options::OPT_fms_runtime_lib_EQ))
7154 VersionTuple GNUCVer;
7155 if (Arg *A = Args.getLastArg(options::OPT_fgnuc_version_EQ)) {
7158 StringRef Val = A->getValue();
7159 Val = Val.empty() ?
"0" : Val;
7160 bool Invalid = GNUCVer.tryParse(Val);
7161 unsigned Minor = GNUCVer.getMinor().value_or(0);
7162 unsigned Patch = GNUCVer.getSubminor().value_or(0);
7163 if (
Invalid || GNUCVer.getBuild() || Minor >= 100 || Patch >= 100) {
7164 D.Diag(diag::err_drv_invalid_value)
7165 << A->getAsString(Args) << A->getValue();
7167 }
else if (!IsMSVCCompat) {
7169 GNUCVer = VersionTuple(4, 2, 1);
7171 if (!GNUCVer.empty()) {
7173 Args.MakeArgString(
"-fgnuc-version=" + GNUCVer.getAsString()));
7179 Args.MakeArgString(
"-fms-compatibility-version=" + MSVT.getAsString()));
7181 bool IsMSVC2015Compatible = MSVT.getMajor() >= 19;
7182 if (ImplyVCPPCVer) {
7183 StringRef LanguageStandard;
7184 if (
const Arg *StdArg = Args.getLastArg(options::OPT__SLASH_std)) {
7186 LanguageStandard = llvm::StringSwitch<StringRef>(StdArg->getValue())
7187 .Case(
"c11",
"-std=c11")
7188 .Case(
"c17",
"-std=c17")
7190 if (LanguageStandard.empty())
7191 D.Diag(clang::diag::warn_drv_unused_argument)
7192 << StdArg->getAsString(Args);
7194 CmdArgs.push_back(LanguageStandard.data());
7196 if (ImplyVCPPCXXVer) {
7197 StringRef LanguageStandard;
7198 if (
const Arg *StdArg = Args.getLastArg(options::OPT__SLASH_std)) {
7200 LanguageStandard = llvm::StringSwitch<StringRef>(StdArg->getValue())
7201 .Case(
"c++14",
"-std=c++14")
7202 .Case(
"c++17",
"-std=c++17")
7203 .Case(
"c++20",
"-std=c++20")
7205 .Case(
"c++latest",
"-std=c++26")
7207 if (LanguageStandard.empty())
7208 D.Diag(clang::diag::warn_drv_unused_argument)
7209 << StdArg->getAsString(Args);
7212 if (LanguageStandard.empty()) {
7213 if (IsMSVC2015Compatible)
7214 LanguageStandard =
"-std=c++14";
7216 LanguageStandard =
"-std=c++11";
7219 CmdArgs.push_back(LanguageStandard.data());
7222 Args.addOptInFlag(CmdArgs, options::OPT_fborland_extensions,
7223 options::OPT_fno_borland_extensions);
7226 if (Args.hasFlag(options::OPT_fdeclspec, options::OPT_fno_declspec,
7228 CmdArgs.push_back(
"-fdeclspec");
7229 else if (Args.hasArg(options::OPT_fno_declspec))
7230 CmdArgs.push_back(
"-fno-declspec");
7234 if (!Args.hasFlag(options::OPT_fthreadsafe_statics,
7235 options::OPT_fno_threadsafe_statics,
7237 (!IsWindowsMSVC || IsMSVC2015Compatible)))
7238 CmdArgs.push_back(
"-fno-threadsafe-statics");
7241 if (!Args.hasFlag(options::OPT_fassumptions, options::OPT_fno_assumptions,
7243 CmdArgs.push_back(
"-fno-assumptions");
7247 Args.AddLastArg(CmdArgs, options::OPT_fgnu_keywords,
7248 options::OPT_fno_gnu_keywords);
7250 Args.addOptInFlag(CmdArgs, options::OPT_fgnu89_inline,
7251 options::OPT_fno_gnu89_inline);
7253 const Arg *InlineArg = Args.getLastArg(options::OPT_finline_functions,
7254 options::OPT_finline_hint_functions,
7255 options::OPT_fno_inline_functions);
7256 if (Arg *A = Args.getLastArg(options::OPT_finline, options::OPT_fno_inline)) {
7257 if (A->getOption().matches(options::OPT_fno_inline))
7258 A->render(Args, CmdArgs);
7259 }
else if (InlineArg) {
7260 InlineArg->render(Args, CmdArgs);
7263 Args.AddLastArg(CmdArgs, options::OPT_finline_max_stacksize_EQ);
7268 (
Std->containsValue(
"c++2a") ||
Std->containsValue(
"gnu++2a") ||
7269 Std->containsValue(
"c++20") ||
Std->containsValue(
"gnu++20") ||
7270 Std->containsValue(
"c++2b") ||
Std->containsValue(
"gnu++2b") ||
7271 Std->containsValue(
"c++23") ||
Std->containsValue(
"gnu++23") ||
7272 Std->containsValue(
"c++2c") ||
Std->containsValue(
"gnu++2c") ||
7273 Std->containsValue(
"c++26") ||
Std->containsValue(
"gnu++26") ||
7274 Std->containsValue(
"c++latest") ||
Std->containsValue(
"gnu++latest"));
7289 if (Args.hasFlag(options::OPT_fdelayed_template_parsing,
7290 options::OPT_fno_delayed_template_parsing,
7291 IsWindowsMSVC && !HaveCxx20)) {
7293 D.Diag(clang::diag::warn_drv_delayed_template_parsing_after_cxx20);
7295 CmdArgs.push_back(
"-fdelayed-template-parsing");
7298 if (Args.hasFlag(options::OPT_fpch_validate_input_files_content,
7299 options::OPT_fno_pch_validate_input_files_content,
false))
7300 CmdArgs.push_back(
"-fvalidate-ast-input-files-content");
7301 if (Args.hasFlag(options::OPT_fpch_instantiate_templates,
7302 options::OPT_fno_pch_instantiate_templates,
false))
7303 CmdArgs.push_back(
"-fpch-instantiate-templates");
7304 if (Args.hasFlag(options::OPT_fpch_codegen, options::OPT_fno_pch_codegen,
7306 CmdArgs.push_back(
"-fmodules-codegen");
7307 if (Args.hasFlag(options::OPT_fpch_debuginfo, options::OPT_fno_pch_debuginfo,
7309 CmdArgs.push_back(
"-fmodules-debuginfo");
7311 ObjCRuntime Runtime = AddObjCRuntimeArgs(Args, Inputs, CmdArgs, rewriteKind);
7316 Args.hasFlag(options::OPT_fobjc_encode_cxx_class_template_spec,
7317 options::OPT_fno_objc_encode_cxx_class_template_spec,
7319 CmdArgs.push_back(
"-fobjc-encode-cxx-class-template-spec");
7321 if (Args.hasFlag(options::OPT_fapplication_extension,
7322 options::OPT_fno_application_extension,
false))
7323 CmdArgs.push_back(
"-fapplication-extension");
7327 if (!
C.getDriver().IsCLMode())
7328 EH =
addExceptionArgs(Args, InputType, TC, KernelOrKext, Runtime, CmdArgs);
7331 Arg *A = Args.getLastArg(
7332 options::OPT_fsjlj_exceptions, options::OPT_fseh_exceptions,
7333 options::OPT_fdwarf_exceptions, options::OPT_fwasm_exceptions);
7335 const Option &Opt = A->getOption();
7336 if (Opt.matches(options::OPT_fsjlj_exceptions))
7337 CmdArgs.push_back(
"-exception-model=sjlj");
7338 if (Opt.matches(options::OPT_fseh_exceptions))
7339 CmdArgs.push_back(
"-exception-model=seh");
7340 if (Opt.matches(options::OPT_fdwarf_exceptions))
7341 CmdArgs.push_back(
"-exception-model=dwarf");
7342 if (Opt.matches(options::OPT_fwasm_exceptions))
7343 CmdArgs.push_back(
"-exception-model=wasm");
7348 case llvm::ExceptionHandling::DwarfCFI:
7349 CmdArgs.push_back(
"-exception-model=dwarf");
7351 case llvm::ExceptionHandling::SjLj:
7352 CmdArgs.push_back(
"-exception-model=sjlj");
7354 case llvm::ExceptionHandling::WinEH:
7355 CmdArgs.push_back(
"-exception-model=seh");
7361 Args.addOptOutFlag(CmdArgs, options::OPT_fassume_sane_operator_new,
7362 options::OPT_fno_assume_sane_operator_new);
7365 Args.addOptOutFlag(CmdArgs, options::OPT_fassume_unique_vtables,
7366 options::OPT_fno_assume_unique_vtables);
7370 Args.getLastArg(options::OPT_frelaxed_template_template_args,
7371 options::OPT_fno_relaxed_template_template_args)) {
7372 if (A->getOption().matches(
7373 options::OPT_fno_relaxed_template_template_args)) {
7374 D.Diag(diag::warn_drv_deprecated_arg_no_relaxed_template_template_args);
7375 CmdArgs.push_back(
"-fno-relaxed-template-template-args");
7377 D.Diag(diag::warn_drv_deprecated_arg)
7378 << A->getAsString(Args) <<
false;
7384 Args.addLastArg(CmdArgs, options::OPT_fsized_deallocation,
7385 options::OPT_fno_sized_deallocation);
7389 if (Arg *A = Args.getLastArg(options::OPT_faligned_allocation,
7390 options::OPT_fno_aligned_allocation,
7391 options::OPT_faligned_new_EQ)) {
7392 if (A->getOption().matches(options::OPT_fno_aligned_allocation))
7393 CmdArgs.push_back(
"-fno-aligned-allocation");
7395 CmdArgs.push_back(
"-faligned-allocation");
7400 if (Arg *A = Args.getLastArg(options::OPT_fnew_alignment_EQ,
7401 options::OPT_faligned_new_EQ))
7403 Args.MakeArgString(Twine(
"-fnew-alignment=") + A->getValue()));
7407 if (!Args.hasFlag(options::OPT_fconstant_cfstrings,
7408 options::OPT_fno_constant_cfstrings,
true) ||
7409 !Args.hasFlag(options::OPT_mconstant_cfstrings,
7410 options::OPT_mno_constant_cfstrings,
true))
7411 CmdArgs.push_back(
"-fno-constant-cfstrings");
7413 Args.addOptInFlag(CmdArgs, options::OPT_fpascal_strings,
7414 options::OPT_fno_pascal_strings);
7418 if (Arg *A = Args.getLastArg(options::OPT_fpack_struct_EQ)) {
7419 std::string PackStructStr =
"-fpack-struct=";
7420 PackStructStr += A->getValue();
7421 CmdArgs.push_back(Args.MakeArgString(PackStructStr));
7422 }
else if (Args.hasFlag(options::OPT_fpack_struct,
7423 options::OPT_fno_pack_struct,
false)) {
7424 CmdArgs.push_back(
"-fpack-struct=1");
7428 bool SkipMaxTypeAlign = Args.hasArg(options::OPT_fno_max_type_align);
7429 if (Arg *A = Args.getLastArg(options::OPT_fmax_type_align_EQ)) {
7430 if (!SkipMaxTypeAlign) {
7431 std::string MaxTypeAlignStr =
"-fmax-type-align=";
7432 MaxTypeAlignStr += A->getValue();
7433 CmdArgs.push_back(Args.MakeArgString(MaxTypeAlignStr));
7435 }
else if (RawTriple.isOSDarwin()) {
7436 if (!SkipMaxTypeAlign) {
7437 std::string MaxTypeAlignStr =
"-fmax-type-align=16";
7438 CmdArgs.push_back(Args.MakeArgString(MaxTypeAlignStr));
7442 if (!Args.hasFlag(options::OPT_Qy, options::OPT_Qn,
true))
7443 CmdArgs.push_back(
"-Qn");
7446 Args.addOptInFlag(CmdArgs, options::OPT_fcommon, options::OPT_fno_common);
7450 if (!Args.hasFlag(options::OPT_fsigned_bitfields,
7451 options::OPT_funsigned_bitfields,
true))
7452 D.Diag(diag::warn_drv_clang_unsupported)
7453 << Args.getLastArg(options::OPT_funsigned_bitfields)->getAsString(Args);
7456 if (!Args.hasFlag(options::OPT_ffor_scope, options::OPT_fno_for_scope,
true))
7457 D.Diag(diag::err_drv_clang_unsupported)
7458 << Args.getLastArg(options::OPT_fno_for_scope)->getAsString(Args);
7461 if (Arg *inputCharset = Args.getLastArg(options::OPT_finput_charset_EQ)) {
7462 StringRef value = inputCharset->getValue();
7463 if (!value.equals_insensitive(
"utf-8"))
7464 D.Diag(diag::err_drv_invalid_value) << inputCharset->getAsString(Args)
7469 if (Arg *execCharset = Args.getLastArg(options::OPT_fexec_charset_EQ)) {
7470 StringRef value = execCharset->getValue();
7471 if (!value.equals_insensitive(
"utf-8"))
7472 D.Diag(diag::err_drv_invalid_value) << execCharset->getAsString(Args)
7478 Args.addOptInFlag(CmdArgs, options::OPT_fasm_blocks,
7479 options::OPT_fno_asm_blocks);
7481 Args.addOptOutFlag(CmdArgs, options::OPT_fgnu_inline_asm,
7482 options::OPT_fno_gnu_inline_asm);
7488 OptSpecifier VectorizeAliasOption =
7489 EnableVec ? options::OPT_O_Group : options::OPT_fvectorize;
7490 if (Args.hasFlag(options::OPT_fvectorize, VectorizeAliasOption,
7491 options::OPT_fno_vectorize, EnableVec))
7492 CmdArgs.push_back(
"-vectorize-loops");
7496 OptSpecifier SLPVectAliasOption =
7497 EnableSLPVec ? options::OPT_O_Group : options::OPT_fslp_vectorize;
7498 if (Args.hasFlag(options::OPT_fslp_vectorize, SLPVectAliasOption,
7499 options::OPT_fno_slp_vectorize, EnableSLPVec))
7500 CmdArgs.push_back(
"-vectorize-slp");
7504 Args.AddLastArg(CmdArgs, options::OPT_fshow_overloads_EQ);
7505 Args.AddLastArg(CmdArgs,
7506 options::OPT_fsanitize_undefined_strip_path_components_EQ);
7510 if (Arg *A = Args.getLastArg(options::OPT_fdollars_in_identifiers,
7511 options::OPT_fno_dollars_in_identifiers)) {
7512 if (A->getOption().matches(options::OPT_fdollars_in_identifiers))
7513 CmdArgs.push_back(
"-fdollars-in-identifiers");
7515 CmdArgs.push_back(
"-fno-dollars-in-identifiers");
7518 Args.addOptInFlag(CmdArgs, options::OPT_fapple_pragma_pack,
7519 options::OPT_fno_apple_pragma_pack);
7525 bool RewriteImports = Args.hasFlag(options::OPT_frewrite_imports,
7526 options::OPT_fno_rewrite_imports,
false);
7528 CmdArgs.push_back(
"-frewrite-imports");
7530 Args.addOptInFlag(CmdArgs, options::OPT_fdirectives_only,
7531 options::OPT_fno_directives_only);
7537 if (Args.hasFlag(options::OPT_frewrite_includes,
7538 options::OPT_fno_rewrite_includes,
false) ||
7539 (
C.isForDiagnostics() && !HaveModules))
7540 CmdArgs.push_back(
"-frewrite-includes");
7542 if (Args.hasFlag(options::OPT_fzos_extensions,
7543 options::OPT_fno_zos_extensions,
false))
7544 CmdArgs.push_back(
"-fzos-extensions");
7545 else if (Args.hasArg(options::OPT_fno_zos_extensions))
7546 CmdArgs.push_back(
"-fno-zos-extensions");
7549 if (Arg *A = Args.getLastArg(options::OPT_traditional,
7550 options::OPT_traditional_cpp)) {
7551 if (isa<PreprocessJobAction>(JA))
7552 CmdArgs.push_back(
"-traditional-cpp");
7554 D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
7557 Args.AddLastArg(CmdArgs, options::OPT_dM);
7558 Args.AddLastArg(CmdArgs, options::OPT_dD);
7559 Args.AddLastArg(CmdArgs, options::OPT_dI);
7561 Args.AddLastArg(CmdArgs, options::OPT_fmax_tokens_EQ);
7564 if (Arg *A = Args.getLastArg(options::OPT__serialize_diags)) {
7565 CmdArgs.push_back(
"-serialize-diagnostic-file");
7566 CmdArgs.push_back(Args.MakeArgString(A->getValue()));
7569 if (Args.hasArg(options::OPT_fretain_comments_from_system_headers))
7570 CmdArgs.push_back(
"-fretain-comments-from-system-headers");
7573 Args.AddAllArgs(CmdArgs, options::OPT_fcomment_block_commands);
7575 Args.AddAllArgs(CmdArgs, options::OPT_fparse_all_comments);
7578 for (
const Arg *A : Args.filtered(options::OPT_fplugin_EQ)) {
7579 CmdArgs.push_back(
"-load");
7580 CmdArgs.push_back(A->getValue());
7592 for (
const Arg *A : Args.filtered(options::OPT_fplugin_arg)) {
7593 auto ArgValue = StringRef(A->getValue());
7594 auto FirstDashIndex = ArgValue.find(
'-');
7595 StringRef PluginName = ArgValue.substr(0, FirstDashIndex);
7596 StringRef Arg = ArgValue.substr(FirstDashIndex + 1);
7599 if (FirstDashIndex == StringRef::npos || Arg.empty()) {
7600 if (PluginName.empty()) {
7601 D.Diag(diag::warn_drv_missing_plugin_name) << A->getAsString(Args);
7603 D.Diag(diag::warn_drv_missing_plugin_arg)
7604 << PluginName << A->getAsString(Args);
7609 CmdArgs.push_back(Args.MakeArgString(Twine(
"-plugin-arg-") + PluginName));
7610 CmdArgs.push_back(Args.MakeArgString(Arg));
7614 for (
const Arg *A : Args.filtered(options::OPT_fpass_plugin_EQ)) {
7616 Args.MakeArgString(Twine(
"-fpass-plugin=") + A->getValue()));
7621 for (
const Arg *A : Args.filtered(options::OPT_vfsoverlay)) {
7622 CmdArgs.push_back(
"--vfsoverlay");
7623 CmdArgs.push_back(A->getValue());
7627 Args.addOptInFlag(CmdArgs, options::OPT_fsafe_buffer_usage_suggestions,
7628 options::OPT_fno_safe_buffer_usage_suggestions);
7630 Args.addOptInFlag(CmdArgs, options::OPT_fexperimental_late_parse_attributes,
7631 options::OPT_fno_experimental_late_parse_attributes);
7635 if (!StatsFile.empty()) {
7636 CmdArgs.push_back(Args.MakeArgString(Twine(
"-stats-file=") + StatsFile));
7637 if (
D.CCPrintInternalStats)
7638 CmdArgs.push_back(
"-stats-file-append");
7643 for (
auto Arg : Args.filtered(options::OPT_Xclang)) {
7647 if (
C.getDriver().isSaveTempsEnabled() &&
7648 !isa<PreprocessJobAction>(JA)) {
7649 if (StringRef(Arg->getValue()) ==
"-finclude-default-header")
7652 CmdArgs.push_back(Arg->getValue());
7654 for (
const Arg *A : Args.filtered(options::OPT_mllvm)) {
7660 if (StringRef(A->getValue(0)) ==
"-disable-llvm-optzns") {
7661 CmdArgs.push_back(
"-disable-llvm-optzns");
7663 A->render(Args, CmdArgs);
7675 if ((
C.getDriver().isSaveTempsEnabled() ||
7677 !(
C.getDriver().embedBitcodeInObject() && !IsUsingLTO) &&
7678 isa<CompileJobAction>(JA))
7679 CmdArgs.push_back(
"-disable-llvm-passes");
7681 Args.AddAllArgs(CmdArgs, options::OPT_undef);
7683 const char *Exec =
D.getClangProgramPath();
7690 auto GRecordSwitches =
7691 Args.hasFlag(options::OPT_grecord_command_line,
7692 options::OPT_gno_record_command_line,
false);
7693 auto FRecordSwitches =
7694 Args.hasFlag(options::OPT_frecord_command_line,
7695 options::OPT_fno_record_command_line,
false);
7696 if (FRecordSwitches && !Triple.isOSBinFormatELF() &&
7697 !Triple.isOSBinFormatXCOFF() && !Triple.isOSBinFormatMachO())
7698 D.Diag(diag::err_drv_unsupported_opt_for_target)
7699 << Args.getLastArg(options::OPT_frecord_command_line)->getAsString(Args)
7702 ArgStringList OriginalArgs;
7703 for (
const auto &Arg : Args)
7704 Arg->render(Args, OriginalArgs);
7708 for (
const char *OriginalArg : OriginalArgs) {
7712 Flags += EscapedArg;
7714 auto FlagsArgString = Args.MakeArgString(Flags);
7716 CmdArgs.push_back(
"-dwarf-debug-flags");
7717 CmdArgs.push_back(FlagsArgString);
7719 if (FRecordSwitches) {
7720 CmdArgs.push_back(
"-record-command-line");
7721 CmdArgs.push_back(FlagsArgString);
7728 if ((IsCuda || IsHIP) && CudaDeviceInput) {
7729 CmdArgs.push_back(
"-fcuda-include-gpubinary");
7730 CmdArgs.push_back(CudaDeviceInput->
getFilename());
7731 }
else if (!HostOffloadingInputs.empty()) {
7732 if ((IsCuda || IsHIP) && !IsRDCMode) {
7733 assert(HostOffloadingInputs.size() == 1 &&
"Only one input expected");
7734 CmdArgs.push_back(
"-fcuda-include-gpubinary");
7735 CmdArgs.push_back(HostOffloadingInputs.front().getFilename());
7737 for (
const InputInfo Input : HostOffloadingInputs)
7738 CmdArgs.push_back(Args.MakeArgString(
"-fembed-offload-object=" +
7744 if (Args.hasFlag(options::OPT_fcuda_short_ptr,
7745 options::OPT_fno_cuda_short_ptr,
false))
7746 CmdArgs.push_back(
"-fcuda-short-ptr");
7749 if (IsCuda || IsHIP) {
7751 const Action *SourceAction = &JA;
7753 assert(!SourceAction->
getInputs().empty() &&
"unexpected root action!");
7754 SourceAction = SourceAction->
getInputs()[0];
7756 auto CUID = cast<InputAction>(SourceAction)->getId();
7758 CmdArgs.push_back(Args.MakeArgString(Twine(
"-cuid=") + Twine(CUID)));
7762 bool UseApproxTranscendentals = Args.hasFlag(
7763 options::OPT_ffast_math, options::OPT_fno_fast_math,
false);
7764 if (Args.hasFlag(options::OPT_fgpu_approx_transcendentals,
7765 options::OPT_fno_gpu_approx_transcendentals,
7766 UseApproxTranscendentals))
7767 CmdArgs.push_back(
"-fgpu-approx-transcendentals");
7769 Args.claimAllArgs(options::OPT_fgpu_approx_transcendentals,
7770 options::OPT_fno_gpu_approx_transcendentals);
7774 CmdArgs.push_back(
"-fcuda-allow-variadic-functions");
7775 Args.AddLastArg(CmdArgs, options::OPT_fgpu_default_stream_EQ);
7778 Args.AddAllArgs(CmdArgs,
7779 options::OPT_fsanitize_undefined_ignore_overflow_pattern_EQ);
7781 Args.AddLastArg(CmdArgs, options::OPT_foffload_uniform_block,
7782 options::OPT_fno_offload_uniform_block);
7784 Args.AddLastArg(CmdArgs, options::OPT_foffload_implicit_host_device_templates,
7785 options::OPT_fno_offload_implicit_host_device_templates);
7787 if (IsCudaDevice || IsHIPDevice) {
7788 StringRef InlineThresh =
7789 Args.getLastArgValue(options::OPT_fgpu_inline_threshold_EQ);
7790 if (!InlineThresh.empty()) {
7791 std::string ArgStr =
7792 std::string(
"-inline-threshold=") + InlineThresh.str();
7793 CmdArgs.append({
"-mllvm", Args.MakeArgStringRef(ArgStr)});
7798 Args.addOptOutFlag(CmdArgs,
7799 options::OPT_fhip_fp32_correctly_rounded_divide_sqrt,
7800 options::OPT_fno_hip_fp32_correctly_rounded_divide_sqrt);
7807 if (IsOpenMPDevice) {
7808 CmdArgs.push_back(
"-fopenmp-is-target-device");
7810 if (Args.hasArg(options::OPT_foffload_via_llvm))
7811 CmdArgs.push_back(
"-fcuda-is-device");
7813 if (OpenMPDeviceInput) {
7814 CmdArgs.push_back(
"-fopenmp-host-ir-file-path");
7815 CmdArgs.push_back(Args.MakeArgString(OpenMPDeviceInput->
getFilename()));
7819 if (Triple.isAMDGPU()) {
7822 Args.addOptInFlag(CmdArgs, options::OPT_munsafe_fp_atomics,
7823 options::OPT_mno_unsafe_fp_atomics);
7824 Args.addOptOutFlag(CmdArgs, options::OPT_mamdgpu_ieee,
7825 options::OPT_mno_amdgpu_ieee);
7830 bool VirtualFunctionElimination =
7831 Args.hasFlag(options::OPT_fvirtual_function_elimination,
7832 options::OPT_fno_virtual_function_elimination,
false);
7833 if (VirtualFunctionElimination) {
7837 D.Diag(diag::err_drv_argument_only_allowed_with)
7838 <<
"-fvirtual-function-elimination"
7841 CmdArgs.push_back(
"-fvirtual-function-elimination");
7845 bool WholeProgramVTables = Args.hasFlag(
7846 options::OPT_fwhole_program_vtables,
7847 options::OPT_fno_whole_program_vtables, VirtualFunctionElimination);
7848 if (VirtualFunctionElimination && !WholeProgramVTables) {
7849 D.Diag(diag::err_drv_argument_not_allowed_with)
7850 <<
"-fno-whole-program-vtables"
7851 <<
"-fvirtual-function-elimination";
7854 if (WholeProgramVTables) {
7866 IsDeviceOffloadAction ?
D.getLTOMode() :
D.getOffloadLTOMode();
7867 auto OtherIsUsingLTO = OtherLTOMode !=
LTOK_None;
7869 if ((!IsUsingLTO && !OtherIsUsingLTO) ||
7870 (IsPS4 && !UnifiedLTO && (
D.getLTOMode() !=
LTOK_Full)))
7871 D.Diag(diag::err_drv_argument_only_allowed_with)
7872 <<
"-fwhole-program-vtables"
7873 << ((IsPS4 && !UnifiedLTO) ?
"-flto=full" :
"-flto");
7877 CmdArgs.push_back(
"-fwhole-program-vtables");
7880 bool DefaultsSplitLTOUnit =
7881 ((WholeProgramVTables || SanitizeArgs.needsLTO()) &&
7883 (!Triple.isPS4() && UnifiedLTO);
7885 Args.hasFlag(options::OPT_fsplit_lto_unit,
7886 options::OPT_fno_split_lto_unit, DefaultsSplitLTOUnit);
7887 if (SanitizeArgs.needsLTO() && !SplitLTOUnit)
7888 D.Diag(diag::err_drv_argument_not_allowed_with) <<
"-fno-split-lto-unit"
7889 <<
"-fsanitize=cfi";
7891 CmdArgs.push_back(
"-fsplit-lto-unit");
7893 if (Arg *A = Args.getLastArg(options::OPT_ffat_lto_objects,
7894 options::OPT_fno_fat_lto_objects)) {
7895 if (IsUsingLTO && A->getOption().matches(options::OPT_ffat_lto_objects)) {
7897 if (!Triple.isOSBinFormatELF()) {
7898 D.Diag(diag::err_drv_unsupported_opt_for_target)
7901 CmdArgs.push_back(Args.MakeArgString(
7902 Twine(
"-flto=") + (LTOMode ==
LTOK_Thin ?
"thin" :
"full")));
7903 CmdArgs.push_back(
"-flto-unit");
7904 CmdArgs.push_back(
"-ffat-lto-objects");
7905 A->render(Args, CmdArgs);
7909 if (Arg *A = Args.getLastArg(options::OPT_fglobal_isel,
7910 options::OPT_fno_global_isel)) {
7911 CmdArgs.push_back(
"-mllvm");
7912 if (A->getOption().matches(options::OPT_fglobal_isel)) {
7913 CmdArgs.push_back(
"-global-isel=1");
7918 bool IsArchSupported = Triple.getArch() == llvm::Triple::aarch64;
7919 bool IsOptLevelSupported =
false;
7921 Arg *A = Args.getLastArg(options::OPT_O_Group);
7922 if (Triple.getArch() == llvm::Triple::aarch64) {
7923 if (!A || A->getOption().matches(options::OPT_O0))
7924 IsOptLevelSupported =
true;
7926 if (!IsArchSupported || !IsOptLevelSupported) {
7927 CmdArgs.push_back(
"-mllvm");
7928 CmdArgs.push_back(
"-global-isel-abort=2");
7930 if (!IsArchSupported)
7931 D.Diag(diag::warn_drv_global_isel_incomplete) << Triple.getArchName();
7933 D.Diag(diag::warn_drv_global_isel_incomplete_opt);
7936 CmdArgs.push_back(
"-global-isel=0");
7940 if (Args.hasArg(options::OPT_forder_file_instrumentation)) {
7941 CmdArgs.push_back(
"-forder-file-instrumentation");
7946 CmdArgs.push_back(
"-mllvm");
7947 CmdArgs.push_back(
"-enable-order-file-instrumentation");
7951 if (Arg *A = Args.getLastArg(options::OPT_fforce_enable_int128,
7952 options::OPT_fno_force_enable_int128)) {
7953 if (A->getOption().matches(options::OPT_fforce_enable_int128))
7954 CmdArgs.push_back(
"-fforce-enable-int128");
7957 Args.addOptInFlag(CmdArgs, options::OPT_fkeep_static_consts,
7958 options::OPT_fno_keep_static_consts);
7959 Args.addOptInFlag(CmdArgs, options::OPT_fkeep_persistent_storage_variables,
7960 options::OPT_fno_keep_persistent_storage_variables);
7961 Args.addOptInFlag(CmdArgs, options::OPT_fcomplete_member_pointers,
7962 options::OPT_fno_complete_member_pointers);
7963 Args.addOptOutFlag(CmdArgs, options::OPT_fcxx_static_destructors,
7964 options::OPT_fno_cxx_static_destructors);
7970 if (Triple.isAArch64() &&
7971 (Args.hasArg(options::OPT_mno_fmv) ||
7972 (Triple.isAndroid() && Triple.isAndroidVersionLT(23)) ||
7975 CmdArgs.push_back(
"-target-feature");
7976 CmdArgs.push_back(
"-fmv");
7979 if (Args.hasFlag(options::OPT_faddrsig, options::OPT_fno_addrsig,
7986 CmdArgs.push_back(
"-faddrsig");
7988 if ((Triple.isOSBinFormatELF() || Triple.isOSBinFormatMachO()) &&
7989 (EH || UnwindTables || AsyncUnwindTables ||
7990 DebugInfoKind != llvm::codegenoptions::NoDebugInfo))
7991 CmdArgs.push_back(
"-D__GCC_HAVE_DWARF2_CFI_ASM=1");
7993 if (Arg *A = Args.getLastArg(options::OPT_fsymbol_partition_EQ)) {
7994 std::string Str = A->getAsString(Args);
7996 D.Diag(diag::err_drv_unsupported_opt_for_target)
7998 CmdArgs.push_back(Args.MakeArgString(Str));
8003 if (Output.
getType() == types::TY_Dependencies) {
8006 if (Output.
getType() == clang::driver::types::TY_IFS_CPP ||
8007 Output.
getType() == clang::driver::types::TY_IFS) {
8009 llvm::sys::path::replace_extension(OutputFilename,
"ifs");
8010 CmdArgs.push_back(
"-o");
8011 CmdArgs.push_back(Args.MakeArgString(OutputFilename));
8013 CmdArgs.push_back(
"-o");
8017 assert(Output.
isNothing() &&
"Invalid output.");
8024 FrontendInputs = ExtractAPIInputs;
8026 FrontendInputs = {};
8028 for (
const InputInfo &Input : FrontendInputs) {
8035 if (
D.CC1Main && !
D.CCGenDiagnostics) {
8037 C.addCommand(std::make_unique<CC1Command>(
8039 Output,
D.getPrependArg()));
8041 C.addCommand(std::make_unique<Command>(
8043 Output,
D.getPrependArg()));
8047 if (Output.
getType() == types::TY_Object &&
8048 Args.hasFlag(options::OPT__SLASH_showFilenames,
8049 options::OPT__SLASH_showFilenames_,
false)) {
8050 C.getJobs().getJobs().back()->PrintInputFilenames =
true;
8053 if (Arg *A = Args.getLastArg(options::OPT_pg))
8055 !Args.hasArg(options::OPT_mfentry))
8056 D.Diag(diag::err_drv_argument_not_allowed_with) <<
"-fomit-frame-pointer"
8057 << A->getAsString(Args);
8063 Args.ClaimAllArgs(options::OPT_fpch_preprocess);
8067 Args.ClaimAllArgs(options::OPT_clang_ignored_f_Group);
8068 Args.ClaimAllArgs(options::OPT_clang_ignored_m_Group);
8071 Args.ClaimAllArgs(options::OPT_emit_llvm);
8078 :
Tool(
"clang",
"clang frontend", TC), HasBackend(HasIntegratedBackend) {}
8085ObjCRuntime Clang::AddObjCRuntimeArgs(
const ArgList &args,
8087 ArgStringList &cmdArgs,
8088 RewriteKind rewriteKind)
const {
8091 args.getLastArg(options::OPT_fnext_runtime, options::OPT_fgnu_runtime,
8092 options::OPT_fobjc_runtime_EQ);
8097 runtimeArg->getOption().matches(options::OPT_fobjc_runtime_EQ)) {
8099 StringRef value = runtimeArg->getValue();
8105 (runtime.
getVersion() >= VersionTuple(2, 0)))
8109 diag::err_drv_gnustep_objc_runtime_incompatible_binary)
8113 runtimeArg->render(args, cmdArgs);
8122 unsigned objcABIVersion = 1;
8124 if (Arg *abiArg = args.getLastArg(options::OPT_fobjc_abi_version_EQ)) {
8125 StringRef value = abiArg->getValue();
8128 else if (value ==
"2")
8130 else if (value ==
"3")
8136 bool nonFragileABIIsDefault =
8137 (rewriteKind == RK_NonFragile ||
8138 (rewriteKind == RK_None &&
8140 if (args.hasFlag(options::OPT_fobjc_nonfragile_abi,
8141 options::OPT_fno_objc_nonfragile_abi,
8142 nonFragileABIIsDefault)) {
8144#ifdef DISABLE_DEFAULT_NONFRAGILEABI_TWO
8145 unsigned nonFragileABIVersion = 1;
8147 unsigned nonFragileABIVersion = 2;
8151 args.getLastArg(options::OPT_fobjc_nonfragile_abi_version_EQ)) {
8152 StringRef value = abiArg->getValue();
8154 nonFragileABIVersion = 1;
8155 else if (value ==
"2")
8156 nonFragileABIVersion = 2;
8162 objcABIVersion = 1 + nonFragileABIVersion;
8170 bool isNonFragile = objcABIVersion != 1;
8176 switch (rewriteKind) {
8189 }
else if (runtimeArg->getOption().matches(options::OPT_fnext_runtime)) {
8201 assert(runtimeArg->getOption().matches(options::OPT_fgnu_runtime));
8210 if (llvm::any_of(inputs, [](
const InputInfo &input) {
8214 args.MakeArgString(
"-fobjc-runtime=" + runtime.
getAsString()));
8219 bool HaveDash = (I + 1 < EH.size() && EH[I + 1] ==
'-');
8227 bool Asynch =
false;
8228 bool NoUnwindC =
false;
8240 bool isWindowsMSVC) {
8243 std::vector<std::string> EHArgs =
8244 Args.getAllArgValues(options::OPT__SLASH_EH);
8245 for (
const auto &EHVal : EHArgs) {
8246 for (
size_t I = 0,
E = EHVal.size(); I !=
E; ++I) {
8252 if (!isWindowsMSVC) {
8254 D.Diag(clang::diag::warn_drv_unused_argument) <<
"/EHa" << EHVal;
8271 D.Diag(clang::diag::err_drv_invalid_value) <<
"/EH" << EHVal;
8277 if (EHArgs.empty() &&
8278 Args.hasFlag(options::OPT__SLASH_GX, options::OPT__SLASH_GX_,
8281 EH.NoUnwindC =
true;
8284 if (Args.hasArg(options::OPT__SLASH_kernel)) {
8286 EH.NoUnwindC =
false;
8293void Clang::AddClangCLArgs(
const ArgList &Args,
types::ID InputType,
8294 ArgStringList &CmdArgs)
const {
8299 if (Arg *ShowIncludes =
8300 Args.getLastArg(options::OPT__SLASH_showIncludes,
8301 options::OPT__SLASH_showIncludes_user)) {
8302 CmdArgs.push_back(
"--show-includes");
8303 if (ShowIncludes->getOption().matches(options::OPT__SLASH_showIncludes))
8304 CmdArgs.push_back(
"-sys-header-deps");
8308 if (Args.hasFlag(options::OPT__SLASH_GR_, options::OPT__SLASH_GR,
8310 CmdArgs.push_back(
"-fno-rtti-data");
8314 if (!isNVPTX && Args.hasFlag(options::OPT__SLASH_GS, options::OPT__SLASH_GS_,
8316 CmdArgs.push_back(
"-stack-protector");
8324 if (!isNVPTX && (EH.Synch || EH.Asynch)) {
8326 CmdArgs.push_back(
"-fcxx-exceptions");
8327 CmdArgs.push_back(
"-fexceptions");
8329 CmdArgs.push_back(
"-fasync-exceptions");
8331 if (
types::isCXX(InputType) && EH.Synch && EH.NoUnwindC)
8332 CmdArgs.push_back(
"-fexternc-nounwind");
8335 if (Args.hasArg(options::OPT__SLASH_EP)) {
8336 CmdArgs.push_back(
"-E");
8337 CmdArgs.push_back(
"-P");
8340 if (Args.hasFlag(options::OPT__SLASH_Zc_dllexportInlines_,
8341 options::OPT__SLASH_Zc_dllexportInlines,
8343 CmdArgs.push_back(
"-fno-dllexport-inlines");
8346 if (Args.hasFlag(options::OPT__SLASH_Zc_wchar_t_,
8347 options::OPT__SLASH_Zc_wchar_t,
false)) {
8348 CmdArgs.push_back(
"-fno-wchar");
8351 if (Args.hasArg(options::OPT__SLASH_kernel)) {
8353 std::vector<std::string> Values =
8354 Args.getAllArgValues(options::OPT__SLASH_arch);
8355 if (!Values.empty()) {
8356 llvm::SmallSet<std::string, 4> SupportedArches;
8357 if (Arch == llvm::Triple::x86)
8358 SupportedArches.insert(
"IA32");
8360 for (
auto &
V : Values)
8361 if (!SupportedArches.contains(
V))
8362 D.Diag(diag::err_drv_argument_not_allowed_with)
8363 << std::string(
"/arch:").append(
V) <<
"/kernel";
8366 CmdArgs.push_back(
"-fno-rtti");
8367 if (Args.hasFlag(options::OPT__SLASH_GR, options::OPT__SLASH_GR_,
false))
8368 D.Diag(diag::err_drv_argument_not_allowed_with) <<
"/GR"
8372 Arg *MostGeneralArg = Args.getLastArg(options::OPT__SLASH_vmg);
8373 Arg *BestCaseArg = Args.getLastArg(options::OPT__SLASH_vmb);
8374 if (MostGeneralArg && BestCaseArg)
8375 D.Diag(clang::diag::err_drv_argument_not_allowed_with)
8376 << MostGeneralArg->getAsString(Args) << BestCaseArg->getAsString(Args);
8378 if (MostGeneralArg) {
8379 Arg *SingleArg = Args.getLastArg(options::OPT__SLASH_vms);
8380 Arg *MultipleArg = Args.getLastArg(options::OPT__SLASH_vmm);
8381 Arg *VirtualArg = Args.getLastArg(options::OPT__SLASH_vmv);
8383 Arg *FirstConflict = SingleArg ? SingleArg : MultipleArg;
8384 Arg *SecondConflict = VirtualArg ? VirtualArg : MultipleArg;
8385 if (FirstConflict && SecondConflict && FirstConflict != SecondConflict)
8386 D.Diag(clang::diag::err_drv_argument_not_allowed_with)
8387 << FirstConflict->getAsString(Args)
8388 << SecondConflict->getAsString(Args);
8391 CmdArgs.push_back(
"-fms-memptr-rep=single");
8392 else if (MultipleArg)
8393 CmdArgs.push_back(
"-fms-memptr-rep=multiple");
8395 CmdArgs.push_back(
"-fms-memptr-rep=virtual");
8398 if (Args.hasArg(options::OPT_regcall4))
8399 CmdArgs.push_back(
"-regcall4");
8403 Args.getLastArg(options::OPT__SLASH_Gd, options::OPT__SLASH_Gr,
8404 options::OPT__SLASH_Gz, options::OPT__SLASH_Gv,
8405 options::OPT__SLASH_Gregcall)) {
8406 unsigned DCCOptId = CCArg->getOption().
getID();
8407 const char *DCCFlag =
nullptr;
8408 bool ArchSupported = !isNVPTX;
8411 case options::OPT__SLASH_Gd:
8412 DCCFlag =
"-fdefault-calling-conv=cdecl";
8414 case options::OPT__SLASH_Gr:
8415 ArchSupported = Arch == llvm::Triple::x86;
8416 DCCFlag =
"-fdefault-calling-conv=fastcall";
8418 case options::OPT__SLASH_Gz:
8419 ArchSupported = Arch == llvm::Triple::x86;
8420 DCCFlag =
"-fdefault-calling-conv=stdcall";
8422 case options::OPT__SLASH_Gv:
8423 ArchSupported = Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64;
8424 DCCFlag =
"-fdefault-calling-conv=vectorcall";
8426 case options::OPT__SLASH_Gregcall:
8427 ArchSupported = Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64;
8428 DCCFlag =
"-fdefault-calling-conv=regcall";
8433 if (ArchSupported && DCCFlag)
8434 CmdArgs.push_back(DCCFlag);
8437 if (Args.hasArg(options::OPT__SLASH_Gregcall4))
8438 CmdArgs.push_back(
"-regcall4");
8440 Args.AddLastArg(CmdArgs, options::OPT_vtordisp_mode_EQ);
8442 if (!Args.hasArg(options::OPT_fdiagnostics_format_EQ)) {
8443 CmdArgs.push_back(
"-fdiagnostics-format");
8444 CmdArgs.push_back(
"msvc");
8447 if (Args.hasArg(options::OPT__SLASH_kernel))
8448 CmdArgs.push_back(
"-fms-kernel");
8450 for (
const Arg *A : Args.filtered(options::OPT__SLASH_guard)) {
8451 StringRef GuardArgs = A->getValue();
8454 if (GuardArgs.equals_insensitive(
"cf")) {
8456 CmdArgs.push_back(
"-cfguard");
8457 }
else if (GuardArgs.equals_insensitive(
"cf,nochecks")) {
8459 CmdArgs.push_back(
"-cfguard-no-checks");
8460 }
else if (GuardArgs.equals_insensitive(
"ehcont")) {
8462 CmdArgs.push_back(
"-ehcontguard");
8463 }
else if (GuardArgs.equals_insensitive(
"cf-") ||
8464 GuardArgs.equals_insensitive(
"ehcont-")) {
8467 D.Diag(diag::err_drv_invalid_value) << A->getSpelling() << GuardArgs;
8475 return Args.MakeArgString(llvm::sys::path::filename(Input.
getBaseInput()));
8482 if (
const char *End = strrchr(Str,
'.'))
8483 return Args.MakeArgString(std::string(Str, End));
8492 if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) {
8494 llvm::sys::path::replace_extension(OutputFilename, llvm::Twine(
'd'));
8495 return Args.MakeArgString(OutputFilename);
8504 ArgStringList &CmdArgs)
const {
8510 CmdArgs.push_back(
"-target-abi");
8511 CmdArgs.push_back(ABIName.data());
8515 ArgStringList &CmdArgs)
const {
8519 if (Arg *A = Args.getLastArg(options::OPT_masm_EQ)) {
8520 StringRef
Value = A->getValue();
8522 CmdArgs.push_back(
"-mllvm");
8523 CmdArgs.push_back(Args.MakeArgString(
"-x86-asm-syntax=" +
Value));
8526 << A->getSpelling() <<
Value;
8532 ArgStringList &CmdArgs)
const {
8533 CmdArgs.push_back(
"-target-abi");
8540 ArgStringList &CmdArgs)
const {
8544 CmdArgs.push_back(
"-target-abi");
8545 CmdArgs.push_back(ABIName.data());
8547 if (Args.hasFlag(options::OPT_mdefault_build_attributes,
8548 options::OPT_mno_default_build_attributes,
true)) {
8549 CmdArgs.push_back(
"-mllvm");
8550 CmdArgs.push_back(
"-riscv-add-build-attributes");
8556 const ArgList &Args,
8557 const char *LinkingOutput)
const {
8558 ArgStringList CmdArgs;
8560 assert(Inputs.size() == 1 &&
"Unexpected number of inputs.");
8564 const std::string &TripleStr = Triple.getTriple();
8568 Args.ClaimAllArgs(options::OPT_w);
8570 Args.ClaimAllArgs(options::OPT_emit_llvm);
8577 CmdArgs.push_back(
"-cc1as");
8580 CmdArgs.push_back(
"-triple");
8581 CmdArgs.push_back(Args.MakeArgString(TripleStr));
8587 CmdArgs.push_back(
"-filetype");
8588 CmdArgs.push_back(
"obj");
8592 CmdArgs.push_back(
"-main-file-name");
8596 std::string CPU =
getCPUName(
D, Args, Triple,
true);
8598 CmdArgs.push_back(
"-target-cpu");
8599 CmdArgs.push_back(Args.MakeArgString(CPU));
8606 (void)Args.hasArg(options::OPT_force__cpusubtype__ALL);
8609 Args.AddAllArgs(CmdArgs, options::OPT_I_Group);
8612 Args.AddAllArgs(CmdArgs, options::OPT_embed_dir_EQ);
8615 auto FindSource = [](
const Action *S) ->
const Action * {
8617 assert(!S->getInputs().empty() &&
"unexpected root action!");
8618 S = S->getInputs()[0];
8622 const Action *SourceAction = FindSource(&JA);
8626 bool WantDebug =
false;
8627 Args.ClaimAllArgs(options::OPT_g_Group);
8628 if (Arg *A = Args.getLastArg(options::OPT_g_Group))
8629 WantDebug = !A->getOption().matches(options::OPT_g0) &&
8630 !A->getOption().matches(options::OPT_ggdb0);
8632 llvm::codegenoptions::DebugInfoKind DebugInfoKind =
8633 llvm::codegenoptions::NoDebugInfo;
8636 const char *DebugCompilationDir =
8639 if (SourceAction->
getType() == types::TY_Asm ||
8640 SourceAction->
getType() == types::TY_PP_Asm) {
8645 DebugInfoKind = (WantDebug ? llvm::codegenoptions::DebugInfoConstructor
8646 : llvm::codegenoptions::NoDebugInfo);
8653 CmdArgs.push_back(
"-dwarf-debug-producer");
8657 Args.AddAllArgs(CmdArgs, options::OPT_I);
8661 llvm::DebuggerKind::Default);
8667 llvm::Reloc::Model RelocationModel;
8670 std::tie(RelocationModel, PICLevel, IsPIE) =
8675 CmdArgs.push_back(
"-mrelocation-model");
8676 CmdArgs.push_back(RMName);
8682 ArgStringList OriginalArgs;
8683 for (
const auto &Arg : Args)
8684 Arg->render(Args, OriginalArgs);
8689 for (
const char *OriginalArg : OriginalArgs) {
8693 Flags += EscapedArg;
8695 CmdArgs.push_back(
"-dwarf-debug-flags");
8696 CmdArgs.push_back(Args.MakeArgString(Flags));
8706 case llvm::Triple::mips:
8707 case llvm::Triple::mipsel:
8708 case llvm::Triple::mips64:
8709 case llvm::Triple::mips64el:
8713 case llvm::Triple::x86:
8714 case llvm::Triple::x86_64:
8718 case llvm::Triple::arm:
8719 case llvm::Triple::armeb:
8720 case llvm::Triple::thumb:
8721 case llvm::Triple::thumbeb:
8724 if (Args.hasFlag(options::OPT_mdefault_build_attributes,
8725 options::OPT_mno_default_build_attributes,
true)) {
8726 CmdArgs.push_back(
"-mllvm");
8727 CmdArgs.push_back(
"-arm-add-build-attributes");
8731 case llvm::Triple::aarch64:
8732 case llvm::Triple::aarch64_32:
8733 case llvm::Triple::aarch64_be:
8734 if (Args.hasArg(options::OPT_mmark_bti_property)) {
8735 CmdArgs.push_back(
"-mllvm");
8736 CmdArgs.push_back(
"-aarch64-mark-bti-property");
8740 case llvm::Triple::loongarch32:
8741 case llvm::Triple::loongarch64:
8745 case llvm::Triple::riscv32:
8746 case llvm::Triple::riscv64:
8750 case llvm::Triple::hexagon:
8751 if (Args.hasFlag(options::OPT_mdefault_build_attributes,
8752 options::OPT_mno_default_build_attributes,
true)) {
8753 CmdArgs.push_back(
"-mllvm");
8754 CmdArgs.push_back(
"-hexagon-add-build-attributes");
8764 Args.ClaimAllArgs(options::OPT_W_Group);
8769 Args.AddAllArgs(CmdArgs, options::OPT_mllvm);
8771 if (DebugInfoKind > llvm::codegenoptions::NoDebugInfo && Output.
isFilename())
8778 if (SourceAction != FindSource(&J.getSource()))
8780 auto &JArgs = J.getArguments();
8781 for (
unsigned I = 0; I < JArgs.size(); ++I) {
8782 if (StringRef(JArgs[I]).starts_with(
"-object-file-name=") &&
8784 ArgStringList NewArgs(JArgs.begin(), JArgs.begin() + I);
8787 NewArgs.append(JArgs.begin() + I + 1, JArgs.end());
8788 J.replaceArguments(NewArgs);
8794 assert(Output.
isFilename() &&
"Unexpected lipo output.");
8795 CmdArgs.push_back(
"-o");
8801 T.isOSBinFormatELF()) {
8802 CmdArgs.push_back(
"-split-dwarf-output");
8806 if (Triple.isAMDGPU())
8809 assert(Input.
isFilename() &&
"Invalid input.");
8813 if (
D.CC1Main && !
D.CCGenDiagnostics) {
8815 C.addCommand(std::make_unique<CC1Command>(
8817 Output,
D.getPrependArg()));
8819 C.addCommand(std::make_unique<Command>(
8821 Output,
D.getPrependArg()));
8829 const llvm::opt::ArgList &TCArgs,
8830 const char *LinkingOutput)
const {
8832 assert(isa<OffloadBundlingJobAction>(JA) &&
"Expecting bundling job!");
8842 ArgStringList CmdArgs;
8845 CmdArgs.push_back(TCArgs.MakeArgString(
8848 assert(JA.
getInputs().size() == Inputs.size() &&
8849 "Not have inputs for all dependence actions??");
8853 Triples +=
"-targets=";
8854 for (
unsigned I = 0; I < Inputs.size(); ++I) {
8863 if (
const auto *OA = dyn_cast<OffloadAction>(CurDep)) {
8865 OA->doOnEachDependence([&](
Action *A,
const ToolChain *TC,
const char *) {
8866 assert(CurTC ==
nullptr &&
"Expected one dependence!");
8873 Triples += CurTC->
getTriple().normalize();
8882 StringRef GPUArchName;
8885 for (
unsigned ArgIndex = 0; ArgIndex < TCArgs.size(); ArgIndex++) {
8886 auto ArchStr = StringRef(TCArgs.getArgString(ArgIndex));
8887 auto Arch = ArchStr.starts_with_insensitive(
"-march=");
8889 GPUArchName = ArchStr.substr(7);
8894 Triples += GPUArchName.str();
8897 CmdArgs.push_back(TCArgs.MakeArgString(Triples));
8901 TCArgs.MakeArgString(Twine(
"-output=") + Output.
getFilename()));
8904 for (
unsigned I = 0; I < Inputs.size(); ++I) {
8910 if (
const auto *OA = dyn_cast<OffloadAction>(JA.
getInputs()[I])) {
8912 OA->doOnEachDependence([&](
Action *,
const ToolChain *TC,
const char *) {
8913 assert(CurTC ==
nullptr &&
"Expected one dependence!");
8916 UB +=
C.addTempFile(
8921 CmdArgs.push_back(TCArgs.MakeArgString(UB));
8925 C.addCommand(std::make_unique<Command>(
8928 CmdArgs, std::nullopt, Output));
8933 const InputInfoList &Inputs,
const llvm::opt::ArgList &TCArgs,
8934 const char *LinkingOutput)
const {
8936 auto &UA = cast<OffloadUnbundlingJobAction>(JA);
8947 ArgStringList CmdArgs;
8949 assert(Inputs.size() == 1 &&
"Expecting to unbundle a single file!");
8953 CmdArgs.push_back(TCArgs.MakeArgString(
8958 Triples +=
"-targets=";
8959 auto DepInfo = UA.getDependentActionsInfo();
8960 for (
unsigned I = 0; I < DepInfo.size(); ++I) {
8964 auto &Dep = DepInfo[I];
8967 Triples += Dep.DependentToolChain->getTriple().normalize();
8970 !Dep.DependentBoundArch.empty()) {
8972 Triples += Dep.DependentBoundArch;
8976 StringRef GPUArchName;
8979 for (
unsigned ArgIndex = 0; ArgIndex < TCArgs.size(); ArgIndex++) {
8980 StringRef ArchStr = StringRef(TCArgs.getArgString(ArgIndex));
8981 auto Arch = ArchStr.starts_with_insensitive(
"-march=");
8983 GPUArchName = ArchStr.substr(7);
8988 Triples += GPUArchName.str();
8992 CmdArgs.push_back(TCArgs.MakeArgString(Triples));
8996 TCArgs.MakeArgString(Twine(
"-input=") + Input.
getFilename()));
8999 for (
unsigned I = 0; I < Outputs.size(); ++I) {
9002 UB += DepInfo[I].DependentToolChain->getInputFilename(Outputs[I]);
9003 CmdArgs.push_back(TCArgs.MakeArgString(UB));
9005 CmdArgs.push_back(
"-unbundle");
9006 CmdArgs.push_back(
"-allow-missing-bundles");
9007 if (TCArgs.hasArg(options::OPT_v))
9008 CmdArgs.push_back(
"-verbose");
9011 C.addCommand(std::make_unique<Command>(
9014 CmdArgs, std::nullopt, Outputs));
9020 const llvm::opt::ArgList &Args,
9021 const char *LinkingOutput)
const {
9022 ArgStringList CmdArgs;
9025 assert(Output.
isFilename() &&
"Invalid output.");
9026 CmdArgs.push_back(
"-o");
9033 const ArgList &TCArgs =
9039 : TCArgs.getLastArgValue(options::OPT_march_EQ);
9043 ArgStringList Features;
9047 llvm::copy_if(Features, std::back_inserter(FeatureArgs),
9048 [](StringRef Arg) {
return !Arg.starts_with(
"-target"); });
9051 for (StringRef Feature : llvm::split(Arch.split(
':').second,
':')) {
9052 FeatureArgs.emplace_back(
9053 Args.MakeArgString(Feature.take_back() + Feature.drop_back()));
9060 "file=" +
File.str(),
9062 "arch=" + Arch.str(),
9063 "kind=" + Kind.str(),
9067 for (StringRef Feature : FeatureArgs)
9068 Parts.emplace_back(
"feature=" + Feature.str());
9070 CmdArgs.push_back(Args.MakeArgString(
"--image=" + llvm::join(Parts,
",")));
9073 C.addCommand(std::make_unique<Command>(
9076 CmdArgs, Inputs, Output));
9082 const ArgList &Args,
9083 const char *LinkingOutput)
const {
9086 ArgStringList CmdArgs;
9090 auto TCRange =
C.getOffloadToolChains(Kind);
9091 for (
auto &I : llvm::make_range(TCRange)) {
9095 if (CudaInstallation.
isValid())
9096 CmdArgs.push_back(Args.MakeArgString(
9104 if (
const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
9106 if (A->getOption().matches(options::OPT_O4) ||
9107 A->getOption().matches(options::OPT_Ofast))
9109 else if (A->getOption().matches(options::OPT_O)) {
9110 OOpt = A->getValue();
9113 else if (OOpt ==
"s" || OOpt ==
"z")
9115 }
else if (A->getOption().matches(options::OPT_O0))
9118 CmdArgs.push_back(Args.MakeArgString(Twine(
"--opt-level=O") + OOpt));
9122 Args.MakeArgString(
"--host-triple=" + TheTriple.getTriple()));
9123 if (Args.hasArg(options::OPT_v))
9124 CmdArgs.push_back(
"--wrapper-verbose");
9126 if (
const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
9127 if (!A->getOption().matches(options::OPT_g0))
9128 CmdArgs.push_back(
"--device-debug");
9133 if (
const Arg *A = Args.getLastArg(options::OPT_mcode_object_version_EQ)) {
9134 CmdArgs.push_back(Args.MakeArgString(
"-mllvm"));
9135 CmdArgs.push_back(Args.MakeArgString(
9136 Twine(
"--amdhsa-code-object-version=") + A->getValue()));
9139 for (
const auto &A : Args.getAllArgValues(options::OPT_Xcuda_ptxas))
9140 CmdArgs.push_back(Args.MakeArgString(
"--ptxas-arg=" + A));
9143 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_EQ))
9144 CmdArgs.push_back(Args.MakeArgString(Twine(
"--offload-opt=-pass-remarks=") +
9146 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_missed_EQ))
9147 CmdArgs.push_back(Args.MakeArgString(
9148 Twine(
"--offload-opt=-pass-remarks-missed=") + A->getValue()));
9149 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_analysis_EQ))
9150 CmdArgs.push_back(Args.MakeArgString(
9151 Twine(
"--offload-opt=-pass-remarks-analysis=") + A->getValue()));
9152 if (Args.getLastArg(options::OPT_save_temps_EQ))
9153 CmdArgs.push_back(
"--save-temps");
9156 Linker->
ConstructJob(
C, JA, Output, Inputs, Args, LinkingOutput);
9157 const auto &LinkCommand =
C.getJobs().getJobs().back();
9160 for (Arg *A : Args.filtered(options::OPT_Xoffload_linker)) {
9161 StringRef Val = A->getValue(0);
9164 Args.MakeArgString(Twine(
"--device-linker=") + A->getValue(1)));
9166 CmdArgs.push_back(Args.MakeArgString(
9167 "--device-linker=" +
9171 Args.ClaimAllArgs(options::OPT_Xoffload_linker);
9174 if (Args.hasFlag(options::OPT_fopenmp_target_jit,
9175 options::OPT_fno_openmp_target_jit,
false))
9176 CmdArgs.push_back(
"--embed-bitcode");
9179 for (Arg *A : Args.filtered(options::OPT_mllvm)) {
9180 CmdArgs.push_back(
"-mllvm");
9181 CmdArgs.push_back(A->getValue());
9187 if (!Args.hasFlag(options::OPT_gpulibc, options::OPT_nogpulibc,
true))
9188 CmdArgs.push_back(
"--device-compiler=-nolibc");
9191 CmdArgs.push_back(Args.MakeArgString(Twine(
"--linker-path=") +
9192 LinkCommand->getExecutable()));
9193 for (
const char *LinkArg : LinkCommand->getArguments())
9194 CmdArgs.push_back(LinkArg);
9199 Args.MakeArgString(
getToolChain().GetProgramPath(
"clang-linker-wrapper"));
9203 LinkCommand->replaceExecutable(Exec);
9204 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()