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");
2110 CmdArgs.push_back(
"-msoft-float");
2111 CmdArgs.push_back(
"-mfloat-abi");
2112 CmdArgs.push_back(
"soft");
2116 CmdArgs.push_back(
"-mfloat-abi");
2117 CmdArgs.push_back(
"hard");
2121 CmdArgs.push_back(
"-target-abi");
2122 CmdArgs.push_back(ABIName);
2127 ArgStringList &CmdArgs) {
2129 const llvm::Triple &Triple = TC.
getTriple();
2131 const char *SmallDataLimit =
"8";
2133 if (Args.getLastArg(options::OPT_shared, options::OPT_fpic,
2134 options::OPT_fPIC)) {
2136 SmallDataLimit =
"0";
2137 if (Args.hasArg(options::OPT_G)) {
2138 D.Diag(diag::warn_drv_unsupported_sdata);
2140 }
else if (Args.getLastArgValue(options::OPT_mcmodel_EQ)
2141 .equals_insensitive(
"large") &&
2142 (Triple.getArch() == llvm::Triple::riscv64)) {
2144 SmallDataLimit =
"0";
2145 if (Args.hasArg(options::OPT_G)) {
2146 D.Diag(diag::warn_drv_unsupported_sdata);
2148 }
else if (Triple.isAndroid()) {
2150 SmallDataLimit =
"0";
2151 if (Args.hasArg(options::OPT_G)) {
2152 D.Diag(diag::warn_drv_unsupported_sdata);
2154 }
else if (Arg *A = Args.getLastArg(options::OPT_G)) {
2155 SmallDataLimit = A->getValue();
2158 CmdArgs.push_back(
"-msmall-data-limit");
2159 CmdArgs.push_back(SmallDataLimit);
2162void Clang::AddRISCVTargetArgs(
const ArgList &Args,
2163 ArgStringList &CmdArgs)
const {
2167 CmdArgs.push_back(
"-target-abi");
2168 CmdArgs.push_back(ABIName.data());
2172 if (!Args.hasFlag(options::OPT_mimplicit_float,
2173 options::OPT_mno_implicit_float,
true))
2174 CmdArgs.push_back(
"-no-implicit-float");
2176 if (
const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
2177 CmdArgs.push_back(
"-tune-cpu");
2178 if (strcmp(A->getValue(),
"native") == 0)
2179 CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
2181 CmdArgs.push_back(A->getValue());
2185 if (Arg *A = Args.getLastArg(options::OPT_mrvv_vector_bits_EQ)) {
2186 StringRef Val = A->getValue();
2190 unsigned MinVLen = 0;
2192 auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
2195 if (!errorToBool(ISAInfo.takeError()))
2196 MinVLen = (*ISAInfo)->getMinVLen();
2201 if (Val ==
"zvl" && MinVLen >= llvm::RISCV::RVVBitsPerBlock) {
2203 }
else if (!Val.getAsInteger(10, Bits)) {
2206 if (Bits < MinVLen || Bits < llvm::RISCV::RVVBitsPerBlock ||
2207 Bits > 65536 || !llvm::isPowerOf2_32(Bits))
2213 unsigned VScaleMin = Bits / llvm::RISCV::RVVBitsPerBlock;
2215 Args.MakeArgString(
"-mvscale-max=" + llvm::Twine(VScaleMin)));
2217 Args.MakeArgString(
"-mvscale-min=" + llvm::Twine(VScaleMin)));
2218 }
else if (Val !=
"scalable") {
2220 D.Diag(diag::err_drv_unsupported_option_argument)
2221 << A->getSpelling() << Val;
2226void Clang::AddSparcTargetArgs(
const ArgList &Args,
2227 ArgStringList &CmdArgs)
const {
2233 CmdArgs.push_back(
"-msoft-float");
2234 CmdArgs.push_back(
"-mfloat-abi");
2235 CmdArgs.push_back(
"soft");
2239 CmdArgs.push_back(
"-mfloat-abi");
2240 CmdArgs.push_back(
"hard");
2243 if (
const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
2244 StringRef Name = A->getValue();
2245 std::string TuneCPU;
2246 if (Name ==
"native")
2247 TuneCPU = std::string(llvm::sys::getHostCPUName());
2249 TuneCPU = std::string(Name);
2251 CmdArgs.push_back(
"-tune-cpu");
2252 CmdArgs.push_back(Args.MakeArgString(TuneCPU));
2256void Clang::AddSystemZTargetArgs(
const ArgList &Args,
2257 ArgStringList &CmdArgs)
const {
2258 if (
const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
2259 CmdArgs.push_back(
"-tune-cpu");
2260 if (strcmp(A->getValue(),
"native") == 0)
2261 CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
2263 CmdArgs.push_back(A->getValue());
2267 Args.hasFlag(options::OPT_mbackchain, options::OPT_mno_backchain,
false);
2268 bool HasPackedStack = Args.hasFlag(options::OPT_mpacked_stack,
2269 options::OPT_mno_packed_stack,
false);
2273 if (HasBackchain && HasPackedStack && !HasSoftFloat) {
2275 D.Diag(diag::err_drv_unsupported_opt)
2276 <<
"-mpacked-stack -mbackchain -mhard-float";
2279 CmdArgs.push_back(
"-mbackchain");
2281 CmdArgs.push_back(
"-mpacked-stack");
2284 CmdArgs.push_back(
"-msoft-float");
2285 CmdArgs.push_back(
"-mfloat-abi");
2286 CmdArgs.push_back(
"soft");
2290void Clang::AddX86TargetArgs(
const ArgList &Args,
2291 ArgStringList &CmdArgs)
const {
2295 if (!Args.hasFlag(options::OPT_mred_zone, options::OPT_mno_red_zone,
true) ||
2296 Args.hasArg(options::OPT_mkernel) ||
2297 Args.hasArg(options::OPT_fapple_kext))
2298 CmdArgs.push_back(
"-disable-red-zone");
2300 if (!Args.hasFlag(options::OPT_mtls_direct_seg_refs,
2301 options::OPT_mno_tls_direct_seg_refs,
true))
2302 CmdArgs.push_back(
"-mno-tls-direct-seg-refs");
2306 bool NoImplicitFloat = (Args.hasArg(options::OPT_mkernel) ||
2307 Args.hasArg(options::OPT_fapple_kext));
2308 if (Arg *A = Args.getLastArg(
2309 options::OPT_msoft_float, options::OPT_mno_soft_float,
2310 options::OPT_mimplicit_float, options::OPT_mno_implicit_float)) {
2311 const Option &O = A->getOption();
2312 NoImplicitFloat = (O.matches(options::OPT_mno_implicit_float) ||
2313 O.matches(options::OPT_msoft_float));
2315 if (NoImplicitFloat)
2316 CmdArgs.push_back(
"-no-implicit-float");
2318 if (Arg *A = Args.getLastArg(options::OPT_masm_EQ)) {
2319 StringRef
Value = A->getValue();
2321 CmdArgs.push_back(
"-mllvm");
2322 CmdArgs.push_back(Args.MakeArgString(
"-x86-asm-syntax=" +
Value));
2323 CmdArgs.push_back(Args.MakeArgString(
"-inline-asm=" +
Value));
2325 D.Diag(diag::err_drv_unsupported_option_argument)
2326 << A->getSpelling() <<
Value;
2328 }
else if (
D.IsCLMode()) {
2329 CmdArgs.push_back(
"-mllvm");
2330 CmdArgs.push_back(
"-x86-asm-syntax=intel");
2333 if (Arg *A = Args.getLastArg(options::OPT_mskip_rax_setup,
2334 options::OPT_mno_skip_rax_setup))
2335 if (A->getOption().matches(options::OPT_mskip_rax_setup))
2336 CmdArgs.push_back(Args.MakeArgString(
"-mskip-rax-setup"));
2339 if (Args.hasFlag(options::OPT_miamcu, options::OPT_mno_iamcu,
false)) {
2340 CmdArgs.push_back(
"-mfloat-abi");
2341 CmdArgs.push_back(
"soft");
2342 CmdArgs.push_back(
"-mstack-alignment=4");
2348 std::string TuneCPU;
2349 if (!Args.hasArg(clang::driver::options::OPT_march_EQ) &&
2351 TuneCPU =
"generic";
2354 if (
const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
2355 StringRef Name = A->getValue();
2357 if (Name ==
"native") {
2358 Name = llvm::sys::getHostCPUName();
2360 TuneCPU = std::string(Name);
2362 TuneCPU = std::string(Name);
2365 if (!TuneCPU.empty()) {
2366 CmdArgs.push_back(
"-tune-cpu");
2367 CmdArgs.push_back(Args.MakeArgString(TuneCPU));
2371void Clang::AddHexagonTargetArgs(
const ArgList &Args,
2372 ArgStringList &CmdArgs)
const {
2373 CmdArgs.push_back(
"-mqdsp6-compat");
2374 CmdArgs.push_back(
"-Wreturn-type");
2377 CmdArgs.push_back(
"-mllvm");
2379 Args.MakeArgString(
"-hexagon-small-data-threshold=" + Twine(*G)));
2382 if (!Args.hasArg(options::OPT_fno_short_enums))
2383 CmdArgs.push_back(
"-fshort-enums");
2384 if (Args.getLastArg(options::OPT_mieee_rnd_near)) {
2385 CmdArgs.push_back(
"-mllvm");
2386 CmdArgs.push_back(
"-enable-hexagon-ieee-rnd-near");
2388 CmdArgs.push_back(
"-mllvm");
2389 CmdArgs.push_back(
"-machine-sink-split=0");
2392void Clang::AddLanaiTargetArgs(
const ArgList &Args,
2393 ArgStringList &CmdArgs)
const {
2394 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
2395 StringRef CPUName = A->getValue();
2397 CmdArgs.push_back(
"-target-cpu");
2398 CmdArgs.push_back(Args.MakeArgString(CPUName));
2400 if (Arg *A = Args.getLastArg(options::OPT_mregparm_EQ)) {
2401 StringRef
Value = A->getValue();
2405 if (
Value.getAsInteger(10, Mregparm)) {
2406 if (Mregparm != 4) {
2408 diag::err_drv_unsupported_option_argument)
2409 << A->getSpelling() <<
Value;
2415void Clang::AddWebAssemblyTargetArgs(
const ArgList &Args,
2416 ArgStringList &CmdArgs)
const {
2418 if (!Args.hasArg(options::OPT_fvisibility_EQ,
2419 options::OPT_fvisibility_ms_compat))
2420 CmdArgs.push_back(
"-fvisibility=hidden");
2423void Clang::AddVETargetArgs(
const ArgList &Args, ArgStringList &CmdArgs)
const {
2425 CmdArgs.push_back(
"-mfloat-abi");
2426 CmdArgs.push_back(
"hard");
2431 const InputInfo &Input,
const ArgList &Args)
const {
2433 if (
C.getArgs().hasArg(options::OPT__HASH_HASH_HASH))
2436 using llvm::yaml::escape;
2439 if (!CompilationDatabase) {
2441 auto File = std::make_unique<llvm::raw_fd_ostream>(
2443 llvm::sys::fs::OF_TextWithCRLF | llvm::sys::fs::OF_Append);
2445 D.Diag(clang::diag::err_drv_compilationdatabase) <<
Filename
2449 CompilationDatabase = std::move(
File);
2451 auto &CDB = *CompilationDatabase;
2452 auto CWD =
D.getVFS().getCurrentWorkingDirectory();
2455 CDB <<
"{ \"directory\": \"" << escape(*CWD) <<
"\"";
2456 CDB <<
", \"file\": \"" << escape(Input.
getFilename()) <<
"\"";
2458 CDB <<
", \"output\": \"" << escape(Output.
getFilename()) <<
"\"";
2459 CDB <<
", \"arguments\": [\"" << escape(
D.ClangExecutable) <<
"\"";
2463 CDB <<
", \"" << escape(Buf) <<
"\"";
2464 if (!
D.SysRoot.empty() && !Args.hasArg(options::OPT__sysroot_EQ)) {
2467 CDB <<
", \"" << escape(Buf) <<
"\"";
2469 CDB <<
", \"" << escape(Input.
getFilename()) <<
"\"";
2471 CDB <<
", \"-o\", \"" << escape(Output.
getFilename()) <<
"\"";
2472 for (
auto &A: Args) {
2473 auto &O = A->getOption();
2475 if (O.getID() == options::OPT_x)
2478 if (O.getGroup().isValid() && O.getGroup().getID() == options::OPT_M_Group)
2480 if (O.getID() == options::OPT_gen_cdb_fragment_path)
2483 if (O.getKind() == Option::InputClass)
2486 if (O.getID() == options::OPT_o)
2490 A->render(Args, ASL);
2492 CDB <<
", \"" << escape(it) <<
"\"";
2496 CDB <<
", \"" << escape(Buf) <<
"\"]},\n";
2499void Clang::DumpCompilationDatabaseFragmentToDir(
2501 const InputInfo &Input,
const llvm::opt::ArgList &Args)
const {
2503 if (
C.getArgs().hasArg(options::OPT__HASH_HASH_HASH))
2506 if (CompilationDatabase)
2507 DumpCompilationDatabase(
C,
"",
Target, Output, Input, Args);
2510 const auto &
Driver =
C.getDriver();
2512 auto Err = llvm::sys::fs::create_directory(
Path,
true);
2514 Driver.
Diag(diag::err_drv_compilationdatabase) << Dir << Err.message();
2518 llvm::sys::path::append(
2520 Twine(llvm::sys::path::filename(Input.
getFilename())) +
".%%%%.json");
2523 Err = llvm::sys::fs::createUniqueFile(
Path, FD, TempPath,
2524 llvm::sys::fs::OF_Text);
2526 Driver.
Diag(diag::err_drv_compilationdatabase) <<
Path << Err.message();
2529 CompilationDatabase =
2530 std::make_unique<llvm::raw_fd_ostream>(FD,
true);
2531 DumpCompilationDatabase(
C,
"",
Target, Output, Input, Args);
2541 CmdArgs.push_back(
"-mllvm");
2542 CmdArgs.push_back(Args.MakeArgString(
"-arm-implicit-it=" +
Value));
2546 const ArgList &Args,
2547 ArgStringList &CmdArgs,
2557 Args.addOptInFlag(CmdArgs, options::OPT_mrelax_all,
2558 options::OPT_mno_relax_all);
2562 bool DefaultIncrementalLinkerCompatible =
2563 C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment();
2564 if (Args.hasFlag(options::OPT_mincremental_linker_compatible,
2565 options::OPT_mno_incremental_linker_compatible,
2566 DefaultIncrementalLinkerCompatible))
2567 CmdArgs.push_back(
"-mincremental-linker-compatible");
2569 Args.AddLastArg(CmdArgs, options::OPT_femit_dwarf_unwind_EQ);
2571 Args.addOptInFlag(CmdArgs, options::OPT_femit_compact_unwind_non_canonical,
2572 options::OPT_fno_emit_compact_unwind_non_canonical);
2582 bool TakeNextArg =
false;
2584 const llvm::Triple &Triple =
C.getDefaultToolChain().getTriple();
2585 bool Crel =
false, ExperimentalCrel =
false;
2586 bool UseRelaxRelocations =
C.getDefaultToolChain().useRelaxRelocations();
2587 bool UseNoExecStack =
false;
2588 const char *MipsTargetFeature =
nullptr;
2589 StringRef ImplicitIt;
2591 Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler,
2592 options::OPT_mimplicit_it_EQ)) {
2595 if (A->getOption().getID() == options::OPT_mimplicit_it_EQ) {
2596 switch (
C.getDefaultToolChain().getArch()) {
2597 case llvm::Triple::arm:
2598 case llvm::Triple::armeb:
2599 case llvm::Triple::thumb:
2600 case llvm::Triple::thumbeb:
2602 ImplicitIt = A->getValue();
2604 D.Diag(diag::err_drv_unsupported_option_argument)
2605 << A->getSpelling() << ImplicitIt;
2612 for (StringRef
Value : A->getValues()) {
2614 CmdArgs.push_back(
Value.data());
2615 TakeNextArg =
false;
2619 if (
C.getDefaultToolChain().getTriple().isOSBinFormatCOFF() &&
2620 Value ==
"-mbig-obj")
2623 switch (
C.getDefaultToolChain().getArch()) {
2626 case llvm::Triple::x86:
2627 case llvm::Triple::x86_64:
2628 if (
Value ==
"-msse2avx") {
2629 CmdArgs.push_back(
"-msse2avx");
2633 case llvm::Triple::wasm32:
2634 case llvm::Triple::wasm64:
2635 if (
Value ==
"--no-type-check") {
2636 CmdArgs.push_back(
"-mno-type-check");
2640 case llvm::Triple::thumb:
2641 case llvm::Triple::thumbeb:
2642 case llvm::Triple::arm:
2643 case llvm::Triple::armeb:
2644 if (
Value.starts_with(
"-mimplicit-it=")) {
2646 ImplicitIt =
Value.split(
"=").second;
2650 if (
Value ==
"-mthumb")
2655 case llvm::Triple::mips:
2656 case llvm::Triple::mipsel:
2657 case llvm::Triple::mips64:
2658 case llvm::Triple::mips64el:
2659 if (
Value ==
"--trap") {
2660 CmdArgs.push_back(
"-target-feature");
2661 CmdArgs.push_back(
"+use-tcc-in-div");
2664 if (
Value ==
"--break") {
2665 CmdArgs.push_back(
"-target-feature");
2666 CmdArgs.push_back(
"-use-tcc-in-div");
2669 if (
Value.starts_with(
"-msoft-float")) {
2670 CmdArgs.push_back(
"-target-feature");
2671 CmdArgs.push_back(
"+soft-float");
2674 if (
Value.starts_with(
"-mhard-float")) {
2675 CmdArgs.push_back(
"-target-feature");
2676 CmdArgs.push_back(
"-soft-float");
2680 MipsTargetFeature = llvm::StringSwitch<const char *>(
Value)
2681 .Case(
"-mips1",
"+mips1")
2682 .Case(
"-mips2",
"+mips2")
2683 .Case(
"-mips3",
"+mips3")
2684 .Case(
"-mips4",
"+mips4")
2685 .Case(
"-mips5",
"+mips5")
2686 .Case(
"-mips32",
"+mips32")
2687 .Case(
"-mips32r2",
"+mips32r2")
2688 .Case(
"-mips32r3",
"+mips32r3")
2689 .Case(
"-mips32r5",
"+mips32r5")
2690 .Case(
"-mips32r6",
"+mips32r6")
2691 .Case(
"-mips64",
"+mips64")
2692 .Case(
"-mips64r2",
"+mips64r2")
2693 .Case(
"-mips64r3",
"+mips64r3")
2694 .Case(
"-mips64r5",
"+mips64r5")
2695 .Case(
"-mips64r6",
"+mips64r6")
2697 if (MipsTargetFeature)
2701 if (
Value ==
"-force_cpusubtype_ALL") {
2703 }
else if (
Value ==
"-L") {
2704 CmdArgs.push_back(
"-msave-temp-labels");
2705 }
else if (
Value ==
"--fatal-warnings") {
2706 CmdArgs.push_back(
"-massembler-fatal-warnings");
2707 }
else if (
Value ==
"--no-warn" ||
Value ==
"-W") {
2708 CmdArgs.push_back(
"-massembler-no-warn");
2709 }
else if (
Value ==
"--noexecstack") {
2710 UseNoExecStack =
true;
2711 }
else if (
Value.starts_with(
"-compress-debug-sections") ||
2712 Value.starts_with(
"--compress-debug-sections") ||
2713 Value ==
"-nocompress-debug-sections" ||
2714 Value ==
"--nocompress-debug-sections") {
2715 CmdArgs.push_back(
Value.data());
2716 }
else if (
Value ==
"--crel") {
2718 }
else if (
Value ==
"--no-crel") {
2720 }
else if (
Value ==
"--allow-experimental-crel") {
2721 ExperimentalCrel =
true;
2722 }
else if (
Value ==
"-mrelax-relocations=yes" ||
2723 Value ==
"--mrelax-relocations=yes") {
2724 UseRelaxRelocations =
true;
2725 }
else if (
Value ==
"-mrelax-relocations=no" ||
2726 Value ==
"--mrelax-relocations=no") {
2727 UseRelaxRelocations =
false;
2728 }
else if (
Value.starts_with(
"-I")) {
2729 CmdArgs.push_back(
Value.data());
2734 }
else if (
Value.starts_with(
"-gdwarf-")) {
2737 if (DwarfVersion == 0) {
2738 CmdArgs.push_back(
Value.data());
2741 llvm::codegenoptions::DebugInfoConstructor,
2742 DwarfVersion, llvm::DebuggerKind::Default);
2744 }
else if (
Value.starts_with(
"-mcpu") ||
Value.starts_with(
"-mfpu") ||
2745 Value.starts_with(
"-mhwdiv") ||
Value.starts_with(
"-march")) {
2747 }
else if (
Value ==
"-defsym" ||
Value ==
"--defsym") {
2748 if (A->getNumValues() != 2) {
2749 D.Diag(diag::err_drv_defsym_invalid_format) <<
Value;
2752 const char *S = A->getValue(1);
2753 auto Pair = StringRef(S).split(
'=');
2754 auto Sym = Pair.first;
2755 auto SVal = Pair.second;
2757 if (Sym.empty() || SVal.empty()) {
2758 D.Diag(diag::err_drv_defsym_invalid_format) << S;
2762 if (SVal.getAsInteger(0, IVal)) {
2763 D.Diag(diag::err_drv_defsym_invalid_symval) << SVal;
2766 CmdArgs.push_back(
"--defsym");
2768 }
else if (
Value ==
"-fdebug-compilation-dir") {
2769 CmdArgs.push_back(
"-fdebug-compilation-dir");
2771 }
else if (
Value.consume_front(
"-fdebug-compilation-dir=")) {
2775 CmdArgs.push_back(
"-fdebug-compilation-dir");
2776 CmdArgs.push_back(
Value.data());
2777 }
else if (
Value ==
"--version") {
2778 D.PrintVersion(
C, llvm::outs());
2780 D.Diag(diag::err_drv_unsupported_option_argument)
2781 << A->getSpelling() <<
Value;
2785 if (ImplicitIt.size())
2788 if (!ExperimentalCrel)
2789 D.Diag(diag::err_drv_experimental_crel);
2790 if (Triple.isOSBinFormatELF() && !Triple.isMIPS()) {
2791 CmdArgs.push_back(
"--crel");
2793 D.Diag(diag::err_drv_unsupported_opt_for_target)
2794 <<
"-Wa,--crel" <<
D.getTargetTriple();
2797 if (!UseRelaxRelocations)
2798 CmdArgs.push_back(
"-mrelax-relocations=no");
2800 CmdArgs.push_back(
"-mnoexecstack");
2801 if (MipsTargetFeature !=
nullptr) {
2802 CmdArgs.push_back(
"-target-feature");
2803 CmdArgs.push_back(MipsTargetFeature);
2807 if (
C.getDriver().embedBitcodeEnabled() ||
2808 C.getDriver().embedBitcodeMarkerOnly())
2809 Args.AddLastArg(CmdArgs, options::OPT_fembed_bitcode_EQ);
2811 if (
const char *AsSecureLogFile = getenv(
"AS_SECURE_LOG_FILE")) {
2812 CmdArgs.push_back(
"-as-secure-log-file");
2813 CmdArgs.push_back(Args.MakeArgString(AsSecureLogFile));
2844 if ((str1.compare(str2) != 0) && !str2.empty() && !str1.empty()) {
2845 D.Diag(clang::diag::warn_drv_overriding_option) << str1 << str2;
2852 if (!ComplexRangeStr.empty())
2853 return "-complex-range=" + ComplexRangeStr;
2854 return ComplexRangeStr;
2858 bool OFastEnabled,
const ArgList &Args,
2859 ArgStringList &CmdArgs,
2866 bool HonorINFs =
true;
2867 bool HonorNaNs =
true;
2868 bool ApproxFunc =
false;
2871 bool AssociativeMath =
false;
2872 bool ReciprocalMath =
false;
2873 bool SignedZeros =
true;
2874 bool TrappingMath =
false;
2875 bool TrappingMathPresent =
false;
2877 bool RoundingFPMath =
false;
2879 StringRef FPModel =
"";
2881 StringRef FPExceptionBehavior =
"";
2883 StringRef FPEvalMethod =
"";
2884 llvm::DenormalMode DenormalFPMath =
2886 llvm::DenormalMode DenormalFP32Math =
2891 StringRef FPContract;
2892 StringRef LastSeenFfpContractOption;
2893 StringRef LastFpContractOverrideOption;
2894 bool SeenUnsafeMathModeOption =
false;
2898 bool StrictFPModel =
false;
2899 StringRef Float16ExcessPrecision =
"";
2900 StringRef BFloat16ExcessPrecision =
"";
2902 std::string ComplexRangeStr =
"";
2903 std::string GccRangeComplexOption =
"";
2906 auto applyFastMath = [&]() {
2910 AssociativeMath =
true;
2911 ReciprocalMath =
true;
2913 SignedZeros =
false;
2914 TrappingMath =
false;
2915 RoundingFPMath =
false;
2916 FPExceptionBehavior =
"";
2918 FPContract =
"fast";
2928 !GccRangeComplexOption.empty()
2929 ? GccRangeComplexOption
2932 SeenUnsafeMathModeOption =
true;
2936 auto restoreFPContractState = [&]() {
2946 if (LastSeenFfpContractOption !=
"")
2947 FPContract = LastSeenFfpContractOption;
2948 else if (SeenUnsafeMathModeOption)
2953 LastFpContractOverrideOption =
"";
2956 if (
const Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) {
2957 CmdArgs.push_back(
"-mlimit-float-precision");
2958 CmdArgs.push_back(A->getValue());
2961 for (
const Arg *A : Args) {
2962 switch (A->getOption().getID()) {
2966 case options::OPT_fcx_limited_range:
2967 if (GccRangeComplexOption.empty()) {
2970 "-fcx-limited-range");
2972 if (GccRangeComplexOption !=
"-fno-cx-limited-range")
2975 GccRangeComplexOption =
"-fcx-limited-range";
2978 case options::OPT_fno_cx_limited_range:
2979 if (GccRangeComplexOption.empty()) {
2981 "-fno-cx-limited-range");
2983 if (GccRangeComplexOption.compare(
"-fcx-limited-range") != 0 &&
2984 GccRangeComplexOption.compare(
"-fno-cx-fortran-rules") != 0)
2986 "-fno-cx-limited-range");
2988 GccRangeComplexOption =
"-fno-cx-limited-range";
2991 case options::OPT_fcx_fortran_rules:
2992 if (GccRangeComplexOption.empty())
2994 "-fcx-fortran-rules");
2997 GccRangeComplexOption =
"-fcx-fortran-rules";
3000 case options::OPT_fno_cx_fortran_rules:
3001 if (GccRangeComplexOption.empty()) {
3003 "-fno-cx-fortran-rules");
3005 if (GccRangeComplexOption !=
"-fno-cx-limited-range")
3007 "-fno-cx-fortran-rules");
3009 GccRangeComplexOption =
"-fno-cx-fortran-rules";
3012 case options::OPT_fcomplex_arithmetic_EQ: {
3014 StringRef Val = A->getValue();
3017 else if (Val ==
"improved")
3019 else if (Val ==
"promoted")
3021 else if (Val ==
"basic")
3024 D.Diag(diag::err_drv_unsupported_option_argument)
3025 << A->getSpelling() << Val;
3028 if (!GccRangeComplexOption.empty()) {
3029 if (GccRangeComplexOption.compare(
"-fcx-limited-range") != 0) {
3030 if (GccRangeComplexOption.compare(
"-fcx-fortran-rules") != 0) {
3047 case options::OPT_ffp_model_EQ: {
3054 AssociativeMath =
false;
3055 ReciprocalMath =
false;
3058 StringRef Val = A->getValue();
3059 if (OFastEnabled && Val !=
"fast") {
3061 D.Diag(clang::diag::warn_drv_overriding_option)
3062 << Args.MakeArgString(
"-ffp-model=" + Val) <<
"-Ofast";
3065 StrictFPModel =
false;
3066 if (!FPModel.empty() && FPModel != Val)
3067 D.Diag(clang::diag::warn_drv_overriding_option)
3068 << Args.MakeArgString(
"-ffp-model=" + FPModel)
3069 << Args.MakeArgString(
"-ffp-model=" + Val);
3070 if (Val ==
"fast") {
3074 LastFpContractOverrideOption =
"-ffp-model=fast";
3075 }
else if (Val ==
"precise") {
3078 LastFpContractOverrideOption =
"-ffp-model=precise";
3079 }
else if (Val ==
"strict") {
3080 StrictFPModel =
true;
3081 FPExceptionBehavior =
"strict";
3084 LastFpContractOverrideOption =
"-ffp-model=strict";
3085 TrappingMath =
true;
3086 RoundingFPMath =
true;
3088 D.Diag(diag::err_drv_unsupported_option_argument)
3089 << A->getSpelling() << Val;
3094 case options::OPT_fhonor_infinities: HonorINFs =
true;
break;
3095 case options::OPT_fno_honor_infinities: HonorINFs =
false;
break;
3096 case options::OPT_fhonor_nans: HonorNaNs =
true;
break;
3097 case options::OPT_fno_honor_nans: HonorNaNs =
false;
break;
3098 case options::OPT_fapprox_func: ApproxFunc =
true;
break;
3099 case options::OPT_fno_approx_func: ApproxFunc =
false;
break;
3100 case options::OPT_fmath_errno: MathErrno =
true;
break;
3101 case options::OPT_fno_math_errno: MathErrno =
false;
break;
3102 case options::OPT_fassociative_math: AssociativeMath =
true;
break;
3103 case options::OPT_fno_associative_math: AssociativeMath =
false;
break;
3104 case options::OPT_freciprocal_math: ReciprocalMath =
true;
break;
3105 case options::OPT_fno_reciprocal_math: ReciprocalMath =
false;
break;
3106 case options::OPT_fsigned_zeros: SignedZeros =
true;
break;
3107 case options::OPT_fno_signed_zeros: SignedZeros =
false;
break;
3108 case options::OPT_ftrapping_math:
3109 if (!TrappingMathPresent && !FPExceptionBehavior.empty() &&
3110 FPExceptionBehavior !=
"strict")
3112 D.Diag(clang::diag::warn_drv_overriding_option)
3113 << Args.MakeArgString(
"-ffp-exception-behavior=" +
3114 FPExceptionBehavior)
3115 <<
"-ftrapping-math";
3116 TrappingMath =
true;
3117 TrappingMathPresent =
true;
3118 FPExceptionBehavior =
"strict";
3120 case options::OPT_fno_trapping_math:
3121 if (!TrappingMathPresent && !FPExceptionBehavior.empty() &&
3122 FPExceptionBehavior !=
"ignore")
3124 D.Diag(clang::diag::warn_drv_overriding_option)
3125 << Args.MakeArgString(
"-ffp-exception-behavior=" +
3126 FPExceptionBehavior)
3127 <<
"-fno-trapping-math";
3128 TrappingMath =
false;
3129 TrappingMathPresent =
true;
3130 FPExceptionBehavior =
"ignore";
3133 case options::OPT_frounding_math:
3134 RoundingFPMath =
true;
3137 case options::OPT_fno_rounding_math:
3138 RoundingFPMath =
false;
3141 case options::OPT_fdenormal_fp_math_EQ:
3142 DenormalFPMath = llvm::parseDenormalFPAttribute(A->getValue());
3143 DenormalFP32Math = DenormalFPMath;
3144 if (!DenormalFPMath.isValid()) {
3145 D.Diag(diag::err_drv_invalid_value)
3146 << A->getAsString(Args) << A->getValue();
3150 case options::OPT_fdenormal_fp_math_f32_EQ:
3151 DenormalFP32Math = llvm::parseDenormalFPAttribute(A->getValue());
3152 if (!DenormalFP32Math.isValid()) {
3153 D.Diag(diag::err_drv_invalid_value)
3154 << A->getAsString(Args) << A->getValue();
3159 case options::OPT_ffp_contract: {
3160 StringRef Val = A->getValue();
3161 if (Val ==
"fast" || Val ==
"on" || Val ==
"off" ||
3162 Val ==
"fast-honor-pragmas") {
3163 if (Val != FPContract && LastFpContractOverrideOption !=
"") {
3164 D.Diag(clang::diag::warn_drv_overriding_option)
3165 << LastFpContractOverrideOption
3166 << Args.MakeArgString(
"-ffp-contract=" + Val);
3170 LastSeenFfpContractOption = Val;
3171 LastFpContractOverrideOption =
"";
3173 D.Diag(diag::err_drv_unsupported_option_argument)
3174 << A->getSpelling() << Val;
3179 case options::OPT_ffp_exception_behavior_EQ: {
3180 StringRef Val = A->getValue();
3181 if (!TrappingMathPresent && !FPExceptionBehavior.empty() &&
3182 FPExceptionBehavior != Val)
3184 D.Diag(clang::diag::warn_drv_overriding_option)
3185 << Args.MakeArgString(
"-ffp-exception-behavior=" +
3186 FPExceptionBehavior)
3187 << Args.MakeArgString(
"-ffp-exception-behavior=" + Val);
3188 TrappingMath = TrappingMathPresent =
false;
3189 if (Val ==
"ignore" || Val ==
"maytrap")
3190 FPExceptionBehavior = Val;
3191 else if (Val ==
"strict") {
3192 FPExceptionBehavior = Val;
3193 TrappingMath = TrappingMathPresent =
true;
3195 D.Diag(diag::err_drv_unsupported_option_argument)
3196 << A->getSpelling() << Val;
3201 case options::OPT_ffp_eval_method_EQ: {
3202 StringRef Val = A->getValue();
3203 if (Val ==
"double" || Val ==
"extended" || Val ==
"source")
3206 D.Diag(diag::err_drv_unsupported_option_argument)
3207 << A->getSpelling() << Val;
3211 case options::OPT_fexcess_precision_EQ: {
3212 StringRef Val = A->getValue();
3213 const llvm::Triple::ArchType Arch = TC.
getArch();
3214 if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) {
3215 if (Val ==
"standard" || Val ==
"fast")
3216 Float16ExcessPrecision = Val;
3220 else if (Val ==
"16")
3221 Float16ExcessPrecision =
"none";
3223 D.Diag(diag::err_drv_unsupported_option_argument)
3224 << A->getSpelling() << Val;
3226 if (!(Val ==
"standard" || Val ==
"fast"))
3227 D.Diag(diag::err_drv_unsupported_option_argument)
3228 << A->getSpelling() << Val;
3230 BFloat16ExcessPrecision = Float16ExcessPrecision;
3233 case options::OPT_ffinite_math_only:
3237 case options::OPT_fno_finite_math_only:
3242 case options::OPT_funsafe_math_optimizations:
3243 AssociativeMath =
true;
3244 ReciprocalMath =
true;
3245 SignedZeros =
false;
3247 TrappingMath =
false;
3248 FPExceptionBehavior =
"";
3249 FPContract =
"fast";
3250 LastFpContractOverrideOption =
"-funsafe-math-optimizations";
3251 SeenUnsafeMathModeOption =
true;
3253 case options::OPT_fno_unsafe_math_optimizations:
3254 AssociativeMath =
false;
3255 ReciprocalMath =
false;
3258 restoreFPContractState();
3261 case options::OPT_Ofast:
3266 case options::OPT_ffast_math:
3268 if (A->getOption().getID() == options::OPT_Ofast)
3269 LastFpContractOverrideOption =
"-Ofast";
3271 LastFpContractOverrideOption =
"-ffast-math";
3273 case options::OPT_fno_fast_math:
3280 AssociativeMath =
false;
3281 ReciprocalMath =
false;
3284 restoreFPContractState();
3285 LastFpContractOverrideOption =
"";
3295 if (StrictFPModel) {
3298 if (HonorINFs && HonorNaNs && !AssociativeMath && !ReciprocalMath &&
3299 SignedZeros && TrappingMath && RoundingFPMath && !ApproxFunc &&
3300 FPContract ==
"off")
3304 StrictFPModel =
false;
3309 auto RHS = (A->getNumValues() == 0)
3311 : Args.MakeArgString(A->getSpelling() + A->getValue());
3312 if (A->getSpelling() !=
"-ffp-contract=") {
3313 if (RHS !=
"-ffp-model=strict")
3314 D.Diag(clang::diag::warn_drv_overriding_option)
3315 <<
"-ffp-model=strict" << RHS;
3325 CmdArgs.push_back(
"-menable-no-infs");
3328 CmdArgs.push_back(
"-menable-no-nans");
3331 CmdArgs.push_back(
"-fapprox-func");
3334 CmdArgs.push_back(
"-fmath-errno");
3336 if (AssociativeMath && ReciprocalMath && !SignedZeros && ApproxFunc &&
3338 CmdArgs.push_back(
"-funsafe-math-optimizations");
3341 CmdArgs.push_back(
"-fno-signed-zeros");
3343 if (AssociativeMath && !SignedZeros && !TrappingMath)
3344 CmdArgs.push_back(
"-mreassociate");
3347 CmdArgs.push_back(
"-freciprocal-math");
3351 assert(FPExceptionBehavior ==
"strict");
3355 if (DenormalFPMath != llvm::DenormalMode::getIEEE()) {
3357 llvm::raw_svector_ostream ArgStr(DenormFlag);
3358 ArgStr <<
"-fdenormal-fp-math=" << DenormalFPMath;
3359 CmdArgs.push_back(Args.MakeArgString(ArgStr.str()));
3363 if (DenormalFP32Math != DenormalFPMath) {
3365 llvm::raw_svector_ostream ArgStr(DenormFlag);
3366 ArgStr <<
"-fdenormal-fp-math-f32=" << DenormalFP32Math;
3367 CmdArgs.push_back(Args.MakeArgString(ArgStr.str()));
3370 if (!FPContract.empty())
3371 CmdArgs.push_back(Args.MakeArgString(
"-ffp-contract=" + FPContract));
3374 CmdArgs.push_back(Args.MakeArgString(
"-frounding-math"));
3376 CmdArgs.push_back(Args.MakeArgString(
"-fno-rounding-math"));
3378 if (!FPExceptionBehavior.empty())
3379 CmdArgs.push_back(Args.MakeArgString(
"-ffp-exception-behavior=" +
3380 FPExceptionBehavior));
3382 if (!FPEvalMethod.empty())
3383 CmdArgs.push_back(Args.MakeArgString(
"-ffp-eval-method=" + FPEvalMethod));
3385 if (!Float16ExcessPrecision.empty())
3386 CmdArgs.push_back(Args.MakeArgString(
"-ffloat16-excess-precision=" +
3387 Float16ExcessPrecision));
3388 if (!BFloat16ExcessPrecision.empty())
3389 CmdArgs.push_back(Args.MakeArgString(
"-fbfloat16-excess-precision=" +
3390 BFloat16ExcessPrecision));
3397 if (!HonorINFs && !HonorNaNs && !MathErrno && AssociativeMath && ApproxFunc &&
3398 ReciprocalMath && !SignedZeros && !TrappingMath && !RoundingFPMath)
3399 CmdArgs.push_back(
"-ffast-math");
3405 bool shouldAddFiniteMathOnly =
false;
3406 if (!HonorINFs && !HonorNaNs) {
3407 shouldAddFiniteMathOnly =
true;
3409 bool InfValues =
true;
3410 bool NanValues =
true;
3411 for (
const auto *Arg : Args.filtered(options::OPT_Xclang)) {
3412 StringRef ArgValue = Arg->getValue();
3413 if (ArgValue ==
"-menable-no-nans")
3415 else if (ArgValue ==
"-menable-no-infs")
3418 if (!NanValues && !InfValues)
3419 shouldAddFiniteMathOnly =
true;
3421 if (shouldAddFiniteMathOnly) {
3422 CmdArgs.push_back(
"-ffinite-math-only");
3424 if (
const Arg *A = Args.getLastArg(options::OPT_mfpmath_EQ)) {
3425 CmdArgs.push_back(
"-mfpmath");
3426 CmdArgs.push_back(A->getValue());
3430 if (Args.hasFlag(options::OPT_fno_strict_float_cast_overflow,
3431 options::OPT_fstrict_float_cast_overflow,
false))
3432 CmdArgs.push_back(
"-fno-strict-float-cast-overflow");
3436 if (!ComplexRangeStr.empty()) {
3437 CmdArgs.push_back(Args.MakeArgString(ComplexRangeStr));
3438 if (Args.hasArg(options::OPT_fcomplex_arithmetic_EQ))
3439 CmdArgs.push_back(Args.MakeArgString(
"-fcomplex-arithmetic=" +
3442 if (Args.hasArg(options::OPT_fcx_limited_range))
3443 CmdArgs.push_back(
"-fcx-limited-range");
3444 if (Args.hasArg(options::OPT_fcx_fortran_rules))
3445 CmdArgs.push_back(
"-fcx-fortran-rules");
3446 if (Args.hasArg(options::OPT_fno_cx_limited_range))
3447 CmdArgs.push_back(
"-fno-cx-limited-range");
3448 if (Args.hasArg(options::OPT_fno_cx_fortran_rules))
3449 CmdArgs.push_back(
"-fno-cx-fortran-rules");
3453 const llvm::Triple &Triple,
3456 if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) {
3457 CmdArgs.push_back(
"-analyzer-checker=core");
3458 CmdArgs.push_back(
"-analyzer-checker=apiModeling");
3460 if (!Triple.isWindowsMSVCEnvironment()) {
3461 CmdArgs.push_back(
"-analyzer-checker=unix");
3464 CmdArgs.push_back(
"-analyzer-checker=unix.API");
3465 CmdArgs.push_back(
"-analyzer-checker=unix.Malloc");
3466 CmdArgs.push_back(
"-analyzer-checker=unix.MallocSizeof");
3467 CmdArgs.push_back(
"-analyzer-checker=unix.MismatchedDeallocator");
3468 CmdArgs.push_back(
"-analyzer-checker=unix.cstring.BadSizeArg");
3469 CmdArgs.push_back(
"-analyzer-checker=unix.cstring.NullArg");
3473 if (Triple.isPS()) {
3474 CmdArgs.push_back(
"-analyzer-disable-checker=unix.API");
3475 CmdArgs.push_back(
"-analyzer-disable-checker=unix.Vfork");
3478 if (Triple.isOSDarwin()) {
3479 CmdArgs.push_back(
"-analyzer-checker=osx");
3481 "-analyzer-checker=security.insecureAPI.decodeValueOfObjCType");
3483 else if (Triple.isOSFuchsia())
3484 CmdArgs.push_back(
"-analyzer-checker=fuchsia");
3486 CmdArgs.push_back(
"-analyzer-checker=deadcode");
3489 CmdArgs.push_back(
"-analyzer-checker=cplusplus");
3491 if (!Triple.isPS()) {
3492 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.UncheckedReturn");
3493 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.getpw");
3494 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.gets");
3495 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.mktemp");
3496 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.mkstemp");
3497 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.vfork");
3501 CmdArgs.push_back(
"-analyzer-checker=nullability.NullPassedToNonnull");
3502 CmdArgs.push_back(
"-analyzer-checker=nullability.NullReturnedFromNonnull");
3506 CmdArgs.push_back(
"-analyzer-output");
3507 if (Arg *A = Args.getLastArg(options::OPT__analyzer_output))
3508 CmdArgs.push_back(A->getValue());
3510 CmdArgs.push_back(
"plist");
3515 CmdArgs.push_back(
"-w");
3518 Args.AddAllArgValues(CmdArgs, options::OPT_Xanalyzer);
3525 if (std::isdigit(S[0]))
3528 return llvm::all_of(S, [](
char C) {
return std::isalnum(
C) ||
C ==
'_'; });
3532 const ArgList &Args, ArgStringList &CmdArgs,
3533 bool KernelOrKext) {
3538 if (EffectiveTriple.isNVPTX())
3546 if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector,
3547 options::OPT_fstack_protector_all,
3548 options::OPT_fstack_protector_strong,
3549 options::OPT_fstack_protector)) {
3550 if (A->getOption().matches(options::OPT_fstack_protector))
3551 StackProtectorLevel =
3553 else if (A->getOption().matches(options::OPT_fstack_protector_strong))
3555 else if (A->getOption().matches(options::OPT_fstack_protector_all))
3559 D.Diag(diag::warn_drv_unsupported_option_for_target)
3560 << A->getSpelling() << EffectiveTriple.getTriple();
3561 StackProtectorLevel = DefaultStackProtectorLevel;
3564 StackProtectorLevel = DefaultStackProtectorLevel;
3567 if (StackProtectorLevel) {
3568 CmdArgs.push_back(
"-stack-protector");
3569 CmdArgs.push_back(Args.MakeArgString(Twine(StackProtectorLevel)));
3573 for (
const Arg *A : Args.filtered(options::OPT__param)) {
3574 StringRef Str(A->getValue());
3575 if (Str.starts_with(
"ssp-buffer-size=")) {
3576 if (StackProtectorLevel) {
3577 CmdArgs.push_back(
"-stack-protector-buffer-size");
3579 CmdArgs.push_back(Args.MakeArgString(Str.drop_front(16)));
3585 const std::string &TripleStr = EffectiveTriple.getTriple();
3586 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_EQ)) {
3587 StringRef
Value = A->getValue();
3588 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
3589 !EffectiveTriple.isARM() && !EffectiveTriple.isThumb())
3590 D.Diag(diag::err_drv_unsupported_opt_for_target)
3591 << A->getAsString(Args) << TripleStr;
3592 if ((EffectiveTriple.isX86() || EffectiveTriple.isARM() ||
3593 EffectiveTriple.isThumb()) &&
3595 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3596 << A->getOption().getName() <<
Value <<
"tls global";
3599 if ((EffectiveTriple.isARM() || EffectiveTriple.isThumb()) &&
3601 if (!Args.hasArg(options::OPT_mstack_protector_guard_offset_EQ)) {
3602 D.Diag(diag::err_drv_ssp_missing_offset_argument)
3603 << A->getAsString(Args);
3608 D.Diag(diag::err_target_unsupported_tp_hard)
3609 << EffectiveTriple.getArchName();
3613 if (Arg *A = Args.getLastArg(options::OPT_mtp_mode_EQ)) {
3614 StringRef
Value = A->getValue();
3615 if (
Value !=
"cp15") {
3616 D.Diag(diag::err_drv_argument_not_allowed_with)
3617 << A->getAsString(Args) <<
"-mstack-protector-guard=tls";
3621 CmdArgs.push_back(
"-target-feature");
3622 CmdArgs.push_back(
"+read-tp-tpidruro");
3624 if (EffectiveTriple.isAArch64() &&
Value !=
"sysreg" &&
Value !=
"global") {
3625 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3626 << A->getOption().getName() <<
Value <<
"sysreg global";
3629 A->render(Args, CmdArgs);
3632 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_offset_EQ)) {
3633 StringRef
Value = A->getValue();
3634 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
3635 !EffectiveTriple.isARM() && !EffectiveTriple.isThumb())
3636 D.Diag(diag::err_drv_unsupported_opt_for_target)
3637 << A->getAsString(Args) << TripleStr;
3639 if (
Value.getAsInteger(10, Offset)) {
3640 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() <<
Value;
3643 if ((EffectiveTriple.isARM() || EffectiveTriple.isThumb()) &&
3644 (Offset < 0 || Offset > 0xfffff)) {
3645 D.Diag(diag::err_drv_invalid_int_value)
3646 << A->getOption().getName() <<
Value;
3649 A->render(Args, CmdArgs);
3652 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_reg_EQ)) {
3653 StringRef
Value = A->getValue();
3654 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64())
3655 D.Diag(diag::err_drv_unsupported_opt_for_target)
3656 << A->getAsString(Args) << TripleStr;
3657 if (EffectiveTriple.isX86() && (
Value !=
"fs" &&
Value !=
"gs")) {
3658 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3659 << A->getOption().getName() <<
Value <<
"fs gs";
3662 if (EffectiveTriple.isAArch64() &&
Value !=
"sp_el0") {
3663 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() <<
Value;
3666 A->render(Args, CmdArgs);
3669 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_symbol_EQ)) {
3670 StringRef
Value = A->getValue();
3672 D.Diag(diag::err_drv_argument_only_allowed_with)
3673 << A->getOption().getName() <<
"legal symbol name";
3676 A->render(Args, CmdArgs);
3681 ArgStringList &CmdArgs) {
3684 if (!EffectiveTriple.isOSFreeBSD() && !EffectiveTriple.isOSLinux())
3687 if (!EffectiveTriple.isX86() && !EffectiveTriple.isSystemZ() &&
3688 !EffectiveTriple.isPPC64() && !EffectiveTriple.isAArch64())
3691 Args.addOptInFlag(CmdArgs, options::OPT_fstack_clash_protection,
3692 options::OPT_fno_stack_clash_protection);
3697 const ArgList &Args,
3698 ArgStringList &CmdArgs) {
3700 StringRef TrivialAutoVarInit =
"";
3702 for (
const Arg *A : Args) {
3703 switch (A->getOption().getID()) {
3706 case options::OPT_ftrivial_auto_var_init: {
3708 StringRef Val = A->getValue();
3709 if (Val ==
"uninitialized" || Val ==
"zero" || Val ==
"pattern")
3710 TrivialAutoVarInit = Val;
3712 D.Diag(diag::err_drv_unsupported_option_argument)
3713 << A->getSpelling() << Val;
3719 if (TrivialAutoVarInit.empty())
3720 switch (DefaultTrivialAutoVarInit) {
3724 TrivialAutoVarInit =
"pattern";
3727 TrivialAutoVarInit =
"zero";
3731 if (!TrivialAutoVarInit.empty()) {
3733 Args.MakeArgString(
"-ftrivial-auto-var-init=" + TrivialAutoVarInit));
3737 Args.getLastArg(options::OPT_ftrivial_auto_var_init_stop_after)) {
3738 if (!Args.hasArg(options::OPT_ftrivial_auto_var_init) ||
3740 Args.getLastArg(options::OPT_ftrivial_auto_var_init)->getValue()) ==
3742 D.Diag(diag::err_drv_trivial_auto_var_init_stop_after_missing_dependency);
3744 StringRef Val = A->getValue();
3745 if (std::stoi(Val.str()) <= 0)
3746 D.Diag(diag::err_drv_trivial_auto_var_init_stop_after_invalid_value);
3748 Args.MakeArgString(
"-ftrivial-auto-var-init-stop-after=" + Val));
3751 if (Arg *A = Args.getLastArg(options::OPT_ftrivial_auto_var_init_max_size)) {
3752 if (!Args.hasArg(options::OPT_ftrivial_auto_var_init) ||
3754 Args.getLastArg(options::OPT_ftrivial_auto_var_init)->getValue()) ==
3756 D.Diag(diag::err_drv_trivial_auto_var_init_max_size_missing_dependency);
3758 StringRef Val = A->getValue();
3759 if (std::stoi(Val.str()) <= 0)
3760 D.Diag(diag::err_drv_trivial_auto_var_init_max_size_invalid_value);
3762 Args.MakeArgString(
"-ftrivial-auto-var-init-max-size=" + Val));
3770 const unsigned ForwardedArguments[] = {
3771 options::OPT_cl_opt_disable,
3772 options::OPT_cl_strict_aliasing,
3773 options::OPT_cl_single_precision_constant,
3774 options::OPT_cl_finite_math_only,
3775 options::OPT_cl_kernel_arg_info,
3776 options::OPT_cl_unsafe_math_optimizations,
3777 options::OPT_cl_fast_relaxed_math,
3778 options::OPT_cl_mad_enable,
3779 options::OPT_cl_no_signed_zeros,
3780 options::OPT_cl_fp32_correctly_rounded_divide_sqrt,
3781 options::OPT_cl_uniform_work_group_size
3784 if (Arg *A = Args.getLastArg(options::OPT_cl_std_EQ)) {
3785 std::string CLStdStr = std::string(
"-cl-std=") + A->getValue();
3786 CmdArgs.push_back(Args.MakeArgString(CLStdStr));
3787 }
else if (Arg *A = Args.getLastArg(options::OPT_cl_ext_EQ)) {
3788 std::string CLExtStr = std::string(
"-cl-ext=") + A->getValue();
3789 CmdArgs.push_back(Args.MakeArgString(CLExtStr));
3792 if (Args.hasArg(options::OPT_cl_finite_math_only)) {
3793 CmdArgs.push_back(
"-menable-no-infs");
3794 CmdArgs.push_back(
"-menable-no-nans");
3797 for (
const auto &Arg : ForwardedArguments)
3798 if (
const auto *A = Args.getLastArg(Arg))
3799 CmdArgs.push_back(Args.MakeArgString(A->getOption().getPrefixedName()));
3804 !Args.hasArg(options::OPT_cl_no_stdinc)) {
3805 CmdArgs.push_back(
"-finclude-default-header");
3806 CmdArgs.push_back(
"-fdeclare-opencl-builtins");
3812 const unsigned ForwardedArguments[] = {options::OPT_dxil_validator_version,
3816 options::OPT_emit_llvm,
3817 options::OPT_emit_obj,
3818 options::OPT_disable_llvm_passes,
3819 options::OPT_fnative_half_type,
3820 options::OPT_hlsl_entrypoint};
3823 for (
const auto &Arg : ForwardedArguments)
3824 if (
const auto *A = Args.getLastArg(Arg))
3825 A->renderAsInput(Args, CmdArgs);
3827 if (!Args.hasArg(options::OPT_dxc_no_stdinc) &&
3828 !Args.hasArg(options::OPT_nostdinc))
3829 CmdArgs.push_back(
"-finclude-default-header");
3833 ArgStringList &CmdArgs,
types::ID InputType) {
3834 if (!Args.hasArg(options::OPT_fopenacc))
3837 CmdArgs.push_back(
"-fopenacc");
3839 if (Arg *A = Args.getLastArg(options::OPT_openacc_macro_override)) {
3840 StringRef
Value = A->getValue();
3842 if (!
Value.getAsInteger(10, Version))
3843 A->renderAsInput(Args, CmdArgs);
3845 D.Diag(diag::err_drv_clang_unsupported) <<
Value;
3850 ArgStringList &CmdArgs) {
3851 bool ARCMTEnabled =
false;
3852 if (!Args.hasArg(options::OPT_fno_objc_arc, options::OPT_fobjc_arc)) {
3853 if (
const Arg *A = Args.getLastArg(options::OPT_ccc_arcmt_check,
3854 options::OPT_ccc_arcmt_modify,
3855 options::OPT_ccc_arcmt_migrate)) {
3856 ARCMTEnabled =
true;
3857 switch (A->getOption().getID()) {
3858 default: llvm_unreachable(
"missed a case");
3859 case options::OPT_ccc_arcmt_check:
3860 CmdArgs.push_back(
"-arcmt-action=check");
3862 case options::OPT_ccc_arcmt_modify:
3863 CmdArgs.push_back(
"-arcmt-action=modify");
3865 case options::OPT_ccc_arcmt_migrate:
3866 CmdArgs.push_back(
"-arcmt-action=migrate");
3867 CmdArgs.push_back(
"-mt-migrate-directory");
3868 CmdArgs.push_back(A->getValue());
3870 Args.AddLastArg(CmdArgs, options::OPT_arcmt_migrate_report_output);
3871 Args.AddLastArg(CmdArgs, options::OPT_arcmt_migrate_emit_arc_errors);
3876 Args.ClaimAllArgs(options::OPT_ccc_arcmt_check);
3877 Args.ClaimAllArgs(options::OPT_ccc_arcmt_modify);
3878 Args.ClaimAllArgs(options::OPT_ccc_arcmt_migrate);
3881 if (
const Arg *A = Args.getLastArg(options::OPT_ccc_objcmt_migrate)) {
3883 D.Diag(diag::err_drv_argument_not_allowed_with)
3884 << A->getAsString(Args) <<
"-ccc-arcmt-migrate";
3886 CmdArgs.push_back(
"-mt-migrate-directory");
3887 CmdArgs.push_back(A->getValue());
3889 if (!Args.hasArg(options::OPT_objcmt_migrate_literals,
3890 options::OPT_objcmt_migrate_subscripting,
3891 options::OPT_objcmt_migrate_property)) {
3893 CmdArgs.push_back(
"-objcmt-migrate-literals");
3894 CmdArgs.push_back(
"-objcmt-migrate-subscripting");
3895 CmdArgs.push_back(
"-objcmt-migrate-property");
3897 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_literals);
3898 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_subscripting);
3899 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_property);
3902 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_literals);
3903 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_subscripting);
3904 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_property);
3905 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_all);
3906 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_readonly_property);
3907 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_readwrite_property);
3908 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_property_dot_syntax);
3909 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_annotation);
3910 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_instancetype);
3911 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_nsmacros);
3912 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_protocol_conformance);
3913 Args.AddLastArg(CmdArgs, options::OPT_objcmt_atomic_property);
3914 Args.AddLastArg(CmdArgs, options::OPT_objcmt_returns_innerpointer_property);
3915 Args.AddLastArg(CmdArgs, options::OPT_objcmt_ns_nonatomic_iosonly);
3916 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_designated_init);
3917 Args.AddLastArg(CmdArgs, options::OPT_objcmt_allowlist_dir_path);
3922 const ArgList &Args, ArgStringList &CmdArgs) {
3925 Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin,
3926 !Args.hasArg(options::OPT_mkernel));
3928 CmdArgs.push_back(
"-fno-builtin");
3931 if (Args.hasArg(options::OPT_ffreestanding))
3932 UseBuiltins =
false;
3935 for (
const Arg *A : Args.filtered(options::OPT_fno_builtin_)) {
3941 A->render(Args, CmdArgs);
3946 if (
const char *Str = std::getenv(
"CLANG_MODULE_CACHE_PATH")) {
3949 return Path.getSingleStringRef() !=
"";
3951 if (llvm::sys::path::cache_directory(
Result)) {
3952 llvm::sys::path::append(
Result,
"clang");
3953 llvm::sys::path::append(
Result,
"ModuleCache");
3961 const char *BaseInput) {
3962 if (Arg *ModuleOutputEQ = Args.getLastArg(options::OPT_fmodule_output_EQ))
3963 return StringRef(ModuleOutputEQ->getValue());
3966 if (Arg *FinalOutput = Args.getLastArg(options::OPT_o);
3967 FinalOutput && Args.hasArg(options::OPT_c))
3968 OutputPath = FinalOutput->getValue();
3970 OutputPath = BaseInput;
3973 llvm::sys::path::replace_extension(OutputPath, Extension);
3978 const ArgList &Args,
const InputInfo &Input,
3979 const InputInfo &Output,
bool HaveStd20,
3980 ArgStringList &CmdArgs) {
3982 bool HaveStdCXXModules = IsCXX && HaveStd20;
3983 bool HaveModules = HaveStdCXXModules;
3988 bool HaveClangModules =
false;
3989 if (Args.hasFlag(options::OPT_fmodules, options::OPT_fno_modules,
false)) {
3990 bool AllowedInCXX = Args.hasFlag(options::OPT_fcxx_modules,
3991 options::OPT_fno_cxx_modules,
true);
3992 if (AllowedInCXX || !IsCXX) {
3993 CmdArgs.push_back(
"-fmodules");
3994 HaveClangModules =
true;
3998 HaveModules |= HaveClangModules;
4002 if (Args.hasFlag(options::OPT_fimplicit_module_maps,
4003 options::OPT_fno_implicit_module_maps, HaveClangModules))
4004 CmdArgs.push_back(
"-fimplicit-module-maps");
4007 Args.addOptInFlag(CmdArgs, options::OPT_fmodules_decluse,
4008 options::OPT_fno_modules_decluse);
4012 if (Args.hasFlag(options::OPT_fmodules_strict_decluse,
4013 options::OPT_fno_modules_strict_decluse,
false))
4014 CmdArgs.push_back(
"-fmodules-strict-decluse");
4016 Args.addOptOutFlag(CmdArgs, options::OPT_fmodulemap_allow_subdirectory_search,
4017 options::OPT_fno_modulemap_allow_subdirectory_search);
4020 bool ImplicitModules =
false;
4021 if (!Args.hasFlag(options::OPT_fimplicit_modules,
4022 options::OPT_fno_implicit_modules, HaveClangModules)) {
4024 CmdArgs.push_back(
"-fno-implicit-modules");
4025 }
else if (HaveModules) {
4026 ImplicitModules =
true;
4030 if (Arg *A = Args.getLastArg(options::OPT_fmodules_cache_path))
4031 Path = A->getValue();
4033 bool HasPath =
true;
4034 if (
C.isForDiagnostics()) {
4038 llvm::sys::path::replace_extension(
Path,
".cache");
4039 llvm::sys::path::append(
Path,
"modules");
4040 }
else if (
Path.empty()) {
4048 const char Arg[] =
"-fmodules-cache-path=";
4049 Path.insert(
Path.begin(), Arg, Arg + strlen(Arg));
4050 CmdArgs.push_back(Args.MakeArgString(
Path));
4055 if (Args.hasFlag(options::OPT_fprebuilt_implicit_modules,
4056 options::OPT_fno_prebuilt_implicit_modules,
false))
4057 CmdArgs.push_back(
"-fprebuilt-implicit-modules");
4058 if (Args.hasFlag(options::OPT_fmodules_validate_input_files_content,
4059 options::OPT_fno_modules_validate_input_files_content,
4061 CmdArgs.push_back(
"-fvalidate-ast-input-files-content");
4066 Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
4070 Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
4074 if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
4076 llvm::sys::path::append(BuiltinModuleMap,
"include");
4077 llvm::sys::path::append(BuiltinModuleMap,
"module.modulemap");
4078 if (llvm::sys::fs::exists(BuiltinModuleMap))
4080 Args.MakeArgString(
"-fmodule-map-file=" + BuiltinModuleMap));
4087 if (HaveModules || Input.
getType() == clang::driver::types::TY_ModuleFile) {
4088 Args.AddAllArgs(CmdArgs, options::OPT_fmodule_file);
4091 for (
const Arg *A : Args.filtered(options::OPT_fprebuilt_module_path)) {
4092 CmdArgs.push_back(Args.MakeArgString(
4093 std::string(
"-fprebuilt-module-path=") + A->getValue()));
4097 Args.ClaimAllArgs(options::OPT_fmodule_file);
4101 if (HaveClangModules &&
C.isForDiagnostics()) {
4103 llvm::sys::path::replace_extension(VFSDir,
".cache");
4105 C.addTempFile(Args.MakeArgString(VFSDir));
4107 llvm::sys::path::append(VFSDir,
"vfs");
4108 CmdArgs.push_back(
"-module-dependency-dir");
4109 CmdArgs.push_back(Args.MakeArgString(VFSDir));
4112 if (HaveClangModules)
4113 Args.AddLastArg(CmdArgs, options::OPT_fmodules_user_build_path);
4116 Args.AddAllArgs(CmdArgs, options::OPT_fmodules_ignore_macro);
4117 Args.AddLastArg(CmdArgs, options::OPT_fmodules_prune_interval);
4118 Args.AddLastArg(CmdArgs, options::OPT_fmodules_prune_after);
4120 if (HaveClangModules) {
4121 Args.AddLastArg(CmdArgs, options::OPT_fbuild_session_timestamp);
4123 if (Arg *A = Args.getLastArg(options::OPT_fbuild_session_file)) {
4124 if (Args.hasArg(options::OPT_fbuild_session_timestamp))
4125 D.Diag(diag::err_drv_argument_not_allowed_with)
4126 << A->getAsString(Args) <<
"-fbuild-session-timestamp";
4128 llvm::sys::fs::file_status Status;
4129 if (llvm::sys::fs::status(A->getValue(), Status))
4130 D.Diag(diag::err_drv_no_such_file) << A->getValue();
4131 CmdArgs.push_back(Args.MakeArgString(
4132 "-fbuild-session-timestamp=" +
4133 Twine((uint64_t)std::chrono::duration_cast<std::chrono::seconds>(
4134 Status.getLastModificationTime().time_since_epoch())
4138 if (Args.getLastArg(
4139 options::OPT_fmodules_validate_once_per_build_session)) {
4140 if (!Args.getLastArg(options::OPT_fbuild_session_timestamp,
4141 options::OPT_fbuild_session_file))
4142 D.Diag(diag::err_drv_modules_validate_once_requires_timestamp);
4144 Args.AddLastArg(CmdArgs,
4145 options::OPT_fmodules_validate_once_per_build_session);
4148 if (Args.hasFlag(options::OPT_fmodules_validate_system_headers,
4149 options::OPT_fno_modules_validate_system_headers,
4151 CmdArgs.push_back(
"-fmodules-validate-system-headers");
4153 Args.AddLastArg(CmdArgs,
4154 options::OPT_fmodules_disable_diagnostic_validation);
4156 Args.ClaimAllArgs(options::OPT_fbuild_session_timestamp);
4157 Args.ClaimAllArgs(options::OPT_fbuild_session_file);
4158 Args.ClaimAllArgs(options::OPT_fmodules_validate_once_per_build_session);
4159 Args.ClaimAllArgs(options::OPT_fmodules_validate_system_headers);
4160 Args.ClaimAllArgs(options::OPT_fno_modules_validate_system_headers);
4161 Args.ClaimAllArgs(options::OPT_fmodules_disable_diagnostic_validation);
4166 CmdArgs.push_back(
"-fskip-odr-check-in-gmf");
4168 if (Args.hasArg(options::OPT_modules_reduced_bmi) &&
4169 (Input.
getType() == driver::types::TY_CXXModule ||
4170 Input.
getType() == driver::types::TY_PP_CXXModule)) {
4171 CmdArgs.push_back(
"-fexperimental-modules-reduced-bmi");
4173 if (Args.hasArg(options::OPT_fmodule_output_EQ))
4174 Args.AddLastArg(CmdArgs, options::OPT_fmodule_output_EQ);
4176 CmdArgs.push_back(Args.MakeArgString(
4177 "-fmodule-output=" +
4184 Args.ClaimAllArgs(options::OPT_modules_reduced_bmi);
4192 if (Input.
getType() == driver::types::TY_CXXModule ||
4193 Input.
getType() == driver::types::TY_PP_CXXModule ||
4194 Input.
getType() == driver::types::TY_ModuleFile) {
4195 Args.ClaimAllArgs(options::OPT_fmodule_output);
4196 Args.ClaimAllArgs(options::OPT_fmodule_output_EQ);
4203 ArgStringList &CmdArgs) {
4205 if (
const Arg *A = Args.getLastArg(options::OPT_fsigned_char,
4206 options::OPT_fno_signed_char,
4207 options::OPT_funsigned_char,
4208 options::OPT_fno_unsigned_char)) {
4209 if (A->getOption().matches(options::OPT_funsigned_char) ||
4210 A->getOption().matches(options::OPT_fno_signed_char)) {
4211 CmdArgs.push_back(
"-fno-signed-char");
4214 CmdArgs.push_back(
"-fno-signed-char");
4218 Args.AddLastArg(CmdArgs, options::OPT_fchar8__t, options::OPT_fno_char8__t);
4220 if (
const Arg *A = Args.getLastArg(options::OPT_fshort_wchar,
4221 options::OPT_fno_short_wchar)) {
4222 if (A->getOption().matches(options::OPT_fshort_wchar)) {
4223 CmdArgs.push_back(
"-fwchar-type=short");
4224 CmdArgs.push_back(
"-fno-signed-wchar");
4226 bool IsARM =
T.isARM() ||
T.isThumb() ||
T.isAArch64();
4227 CmdArgs.push_back(
"-fwchar-type=int");
4229 (IsARM && !(
T.isOSWindows() ||
T.isOSNetBSD() ||
T.isOSOpenBSD())))
4230 CmdArgs.push_back(
"-fno-signed-wchar");
4232 CmdArgs.push_back(
"-fsigned-wchar");
4234 }
else if (
T.isOSzOS())
4235 CmdArgs.push_back(
"-fno-signed-wchar");
4239 const llvm::Triple &
T,
const ArgList &Args,
4241 const InputInfo &Input, ArgStringList &CmdArgs) {
4242 const llvm::Triple::ArchType Arch = TC.
getArch();
4248 if (!Args.hasFlag(options::OPT_fobjc_legacy_dispatch,
4249 options::OPT_fno_objc_legacy_dispatch,
4252 CmdArgs.push_back(
"-fobjc-dispatch-method=mixed");
4254 CmdArgs.push_back(
"-fobjc-dispatch-method=non-legacy");
4260 if (Arch == llvm::Triple::x86 &&
T.isMacOSX() &&
4262 CmdArgs.push_back(
"-fobjc-subscripting-legacy-runtime");
4269 CmdArgs.push_back(
"-fobjc-arc");
4276 CmdArgs.push_back(
"-fobjc-arc-cxxlib=libc++");
4278 CmdArgs.push_back(
"-fobjc-arc-cxxlib=libstdc++");
4283 if (Args.hasFlag(options::OPT_fobjc_arc_exceptions,
4284 options::OPT_fno_objc_arc_exceptions,
4286 CmdArgs.push_back(
"-fobjc-arc-exceptions");
4291 if (Args.hasArg(options::OPT_fno_objc_arc)) {
4292 Args.ClaimAllArgs(options::OPT_fobjc_arc_exceptions);
4293 Args.ClaimAllArgs(options::OPT_fno_objc_arc_exceptions);
4299 auto *Arg = Args.getLastArg(
4300 options::OPT_fobjc_convert_messages_to_runtime_calls,
4301 options::OPT_fno_objc_convert_messages_to_runtime_calls);
4303 Arg->getOption().matches(
4304 options::OPT_fno_objc_convert_messages_to_runtime_calls))
4305 CmdArgs.push_back(
"-fno-objc-convert-messages-to-runtime-calls");
4310 if (InferCovariantReturns)
4311 CmdArgs.push_back(
"-fno-objc-infer-related-result-type");
4316 Args.getLastArg(options::OPT_fobjc_weak, options::OPT_fno_objc_weak);
4320 if (WeakArg->getOption().matches(options::OPT_fobjc_weak))
4321 D.Diag(diag::err_objc_weak_unsupported);
4323 WeakArg->render(Args, CmdArgs);
4327 if (Args.hasArg(options::OPT_fobjc_disable_direct_methods_for_testing))
4328 CmdArgs.push_back(
"-fobjc-disable-direct-methods-for-testing");
4332 ArgStringList &CmdArgs) {
4333 bool CaretDefault =
true;
4334 bool ColumnDefault =
true;
4336 if (
const Arg *A = Args.getLastArg(options::OPT__SLASH_diagnostics_classic,
4337 options::OPT__SLASH_diagnostics_column,
4338 options::OPT__SLASH_diagnostics_caret)) {
4339 switch (A->getOption().getID()) {
4340 case options::OPT__SLASH_diagnostics_caret:
4341 CaretDefault =
true;
4342 ColumnDefault =
true;
4344 case options::OPT__SLASH_diagnostics_column:
4345 CaretDefault =
false;
4346 ColumnDefault =
true;
4348 case options::OPT__SLASH_diagnostics_classic:
4349 CaretDefault =
false;
4350 ColumnDefault =
false;
4356 if (!Args.hasFlag(options::OPT_fcaret_diagnostics,
4357 options::OPT_fno_caret_diagnostics, CaretDefault))
4358 CmdArgs.push_back(
"-fno-caret-diagnostics");
4360 Args.addOptOutFlag(CmdArgs, options::OPT_fdiagnostics_fixit_info,
4361 options::OPT_fno_diagnostics_fixit_info);
4362 Args.addOptOutFlag(CmdArgs, options::OPT_fdiagnostics_show_option,
4363 options::OPT_fno_diagnostics_show_option);
4366 Args.getLastArg(options::OPT_fdiagnostics_show_category_EQ)) {
4367 CmdArgs.push_back(
"-fdiagnostics-show-category");
4368 CmdArgs.push_back(A->getValue());
4371 Args.addOptInFlag(CmdArgs, options::OPT_fdiagnostics_show_hotness,
4372 options::OPT_fno_diagnostics_show_hotness);
4375 Args.getLastArg(options::OPT_fdiagnostics_hotness_threshold_EQ)) {
4377 std::string(
"-fdiagnostics-hotness-threshold=") + A->getValue();
4378 CmdArgs.push_back(Args.MakeArgString(Opt));
4382 Args.getLastArg(options::OPT_fdiagnostics_misexpect_tolerance_EQ)) {
4384 std::string(
"-fdiagnostics-misexpect-tolerance=") + A->getValue();
4385 CmdArgs.push_back(Args.MakeArgString(Opt));
4388 if (
const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) {
4389 CmdArgs.push_back(
"-fdiagnostics-format");
4390 CmdArgs.push_back(A->getValue());
4391 if (StringRef(A->getValue()) ==
"sarif" ||
4392 StringRef(A->getValue()) ==
"SARIF")
4393 D.Diag(diag::warn_drv_sarif_format_unstable);
4396 if (
const Arg *A = Args.getLastArg(
4397 options::OPT_fdiagnostics_show_note_include_stack,
4398 options::OPT_fno_diagnostics_show_note_include_stack)) {
4399 const Option &O = A->getOption();
4400 if (O.matches(options::OPT_fdiagnostics_show_note_include_stack))
4401 CmdArgs.push_back(
"-fdiagnostics-show-note-include-stack");
4403 CmdArgs.push_back(
"-fno-diagnostics-show-note-include-stack");
4410 Args.getLastArg(options::OPT_fcolor_diagnostics,
4411 options::OPT_fno_color_diagnostics);
4412 if (
const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_color_EQ)) {
4413 StringRef
Value(A->getValue());
4415 D.Diag(diag::err_drv_invalid_argument_to_option)
4416 <<
Value << A->getOption().getName();
4419 if (
D.getDiags().getDiagnosticOptions().ShowColors)
4420 CmdArgs.push_back(
"-fcolor-diagnostics");
4422 if (Args.hasArg(options::OPT_fansi_escape_codes))
4423 CmdArgs.push_back(
"-fansi-escape-codes");
4425 Args.addOptOutFlag(CmdArgs, options::OPT_fshow_source_location,
4426 options::OPT_fno_show_source_location);
4428 Args.addOptOutFlag(CmdArgs, options::OPT_fdiagnostics_show_line_numbers,
4429 options::OPT_fno_diagnostics_show_line_numbers);
4431 if (Args.hasArg(options::OPT_fdiagnostics_absolute_paths))
4432 CmdArgs.push_back(
"-fdiagnostics-absolute-paths");
4434 if (!Args.hasFlag(options::OPT_fshow_column, options::OPT_fno_show_column,
4436 CmdArgs.push_back(
"-fno-show-column");
4438 Args.addOptOutFlag(CmdArgs, options::OPT_fspell_checking,
4439 options::OPT_fno_spell_checking);
4443 const ArgList &Args, Arg *&Arg) {
4444 Arg = Args.getLastArg(options::OPT_gsplit_dwarf, options::OPT_gsplit_dwarf_EQ,
4445 options::OPT_gno_split_dwarf);
4446 if (!Arg || Arg->getOption().matches(options::OPT_gno_split_dwarf))
4449 if (Arg->getOption().matches(options::OPT_gsplit_dwarf))
4452 StringRef
Value = Arg->getValue();
4453 if (
Value ==
"split")
4455 if (
Value ==
"single")
4458 D.Diag(diag::err_drv_unsupported_option_argument)
4459 << Arg->getSpelling() << Arg->getValue();
4464 const ArgList &Args, ArgStringList &CmdArgs,
4465 unsigned DwarfVersion) {
4466 auto *DwarfFormatArg =
4467 Args.getLastArg(options::OPT_gdwarf64, options::OPT_gdwarf32);
4468 if (!DwarfFormatArg)
4471 if (DwarfFormatArg->getOption().matches(options::OPT_gdwarf64)) {
4472 if (DwarfVersion < 3)
4473 D.Diag(diag::err_drv_argument_only_allowed_with)
4474 << DwarfFormatArg->getAsString(Args) <<
"DWARFv3 or greater";
4475 else if (!
T.isArch64Bit())
4476 D.Diag(diag::err_drv_argument_only_allowed_with)
4477 << DwarfFormatArg->getAsString(Args) <<
"64 bit architecture";
4478 else if (!
T.isOSBinFormatELF())
4479 D.Diag(diag::err_drv_argument_only_allowed_with)
4480 << DwarfFormatArg->getAsString(Args) <<
"ELF platforms";
4483 DwarfFormatArg->render(Args, CmdArgs);
4488 const ArgList &Args,
bool IRInput, ArgStringList &CmdArgs,
4490 llvm::codegenoptions::DebugInfoKind &DebugInfoKind,
4492 if (Args.hasFlag(options::OPT_fdebug_info_for_profiling,
4493 options::OPT_fno_debug_info_for_profiling,
false) &&
4495 Args.getLastArg(options::OPT_fdebug_info_for_profiling), Args,
D, TC))
4496 CmdArgs.push_back(
"-fdebug-info-for-profiling");
4509 bool SplitDWARFInlining =
4510 Args.hasFlag(options::OPT_fsplit_dwarf_inlining,
4511 options::OPT_fno_split_dwarf_inlining,
false);
4516 if (IRInput || Args.hasArg(options::OPT_g_Group)) {
4522 SplitDWARFInlining =
false;
4525 if (
const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
4526 DebugInfoKind = llvm::codegenoptions::DebugInfoConstructor;
4530 A->getOption().matches(options::OPT_gN_Group)) {
4536 if (DebugInfoKind == llvm::codegenoptions::NoDebugInfo ||
4537 DebugInfoKind == llvm::codegenoptions::DebugDirectivesOnly ||
4538 (DebugInfoKind == llvm::codegenoptions::DebugLineTablesOnly &&
4539 SplitDWARFInlining))
4545 bool HasDebuggerTuning =
false;
4547 Args.getLastArg(options::OPT_gTune_Group, options::OPT_ggdbN_Group)) {
4548 HasDebuggerTuning =
true;
4550 if (A->getOption().matches(options::OPT_glldb))
4551 DebuggerTuning = llvm::DebuggerKind::LLDB;
4552 else if (A->getOption().matches(options::OPT_gsce))
4553 DebuggerTuning = llvm::DebuggerKind::SCE;
4554 else if (A->getOption().matches(options::OPT_gdbx))
4555 DebuggerTuning = llvm::DebuggerKind::DBX;
4557 DebuggerTuning = llvm::DebuggerKind::GDB;
4562 bool EmitDwarf =
false;
4566 bool EmitCodeView =
false;
4567 if (
const Arg *A = Args.getLastArg(options::OPT_gcodeview))
4572 if (!EmitCodeView && !EmitDwarf &&
4573 DebugInfoKind != llvm::codegenoptions::NoDebugInfo) {
4575 case llvm::codegenoptions::DIF_CodeView:
4576 EmitCodeView =
true;
4578 case llvm::codegenoptions::DIF_DWARF:
4584 unsigned RequestedDWARFVersion = 0;
4585 unsigned EffectiveDWARFVersion = 0;
4590 EffectiveDWARFVersion =
4593 Args.ClaimAllArgs(options::OPT_fdebug_default_version);
4597 if (RequestedDWARFVersion == 0 &&
4598 DebugInfoKind == llvm::codegenoptions::DebugDirectivesOnly)
4599 DebugInfoKind = llvm::codegenoptions::NoDebugInfo;
4603 if (
const Arg *A = Args.getLastArg(options::OPT_gstrict_dwarf))
4605 if (Args.hasFlag(options::OPT_gstrict_dwarf, options::OPT_gno_strict_dwarf,
4606 DebuggerTuning == llvm::DebuggerKind::DBX))
4607 CmdArgs.push_back(
"-gstrict-dwarf");
4610 Args.ClaimAllArgs(options::OPT_g_flags_Group);
4618 if (
const Arg *A = Args.getLastArg(options::OPT_gcolumn_info))
4620 if (!Args.hasFlag(options::OPT_gcolumn_info, options::OPT_gno_column_info,
4622 (DebuggerTuning != llvm::DebuggerKind::SCE &&
4623 DebuggerTuning != llvm::DebuggerKind::DBX)))
4624 CmdArgs.push_back(
"-gno-column-info");
4627 if (Args.hasFlag(options::OPT_gmodules, options::OPT_gno_modules,
false)) {
4632 if (DebugInfoKind != llvm::codegenoptions::DebugLineTablesOnly &&
4633 DebugInfoKind != llvm::codegenoptions::DebugDirectivesOnly) {
4634 DebugInfoKind = llvm::codegenoptions::DebugInfoConstructor;
4635 CmdArgs.push_back(
"-dwarf-ext-refs");
4636 CmdArgs.push_back(
"-fmodule-format=obj");
4641 if (
T.isOSBinFormatELF() && SplitDWARFInlining)
4642 CmdArgs.push_back(
"-fsplit-dwarf-inlining");
4649 bool NeedFullDebug = Args.hasFlag(
4650 options::OPT_fstandalone_debug, options::OPT_fno_standalone_debug,
4651 DebuggerTuning == llvm::DebuggerKind::LLDB ||
4653 if (
const Arg *A = Args.getLastArg(options::OPT_fstandalone_debug))
4656 if (DebugInfoKind == llvm::codegenoptions::LimitedDebugInfo ||
4657 DebugInfoKind == llvm::codegenoptions::DebugInfoConstructor) {
4658 if (Args.hasFlag(options::OPT_fno_eliminate_unused_debug_types,
4659 options::OPT_feliminate_unused_debug_types,
false))
4660 DebugInfoKind = llvm::codegenoptions::UnusedTypeInfo;
4661 else if (NeedFullDebug)
4662 DebugInfoKind = llvm::codegenoptions::FullDebugInfo;
4665 if (Args.hasFlag(options::OPT_gembed_source, options::OPT_gno_embed_source,
4671 const Arg *A = Args.getLastArg(options::OPT_gembed_source);
4672 if (RequestedDWARFVersion < 5)
4673 D.Diag(diag::err_drv_argument_only_allowed_with)
4674 << A->getAsString(Args) <<
"-gdwarf-5";
4675 else if (EffectiveDWARFVersion < 5)
4678 D.Diag(diag::warn_drv_dwarf_version_limited_by_target)
4680 << EffectiveDWARFVersion;
4682 CmdArgs.push_back(
"-gembed-source");
4686 CmdArgs.push_back(
"-gcodeview");
4688 Args.addOptInFlag(CmdArgs, options::OPT_gcodeview_ghash,
4689 options::OPT_gno_codeview_ghash);
4691 Args.addOptOutFlag(CmdArgs, options::OPT_gcodeview_command_line,
4692 options::OPT_gno_codeview_command_line);
4695 Args.addOptOutFlag(CmdArgs, options::OPT_ginline_line_tables,
4696 options::OPT_gno_inline_line_tables);
4700 DebugInfoKind <= llvm::codegenoptions::DebugDirectivesOnly)
4701 DebugInfoKind = llvm::codegenoptions::DebugLineTablesOnly;
4709 T.isOSAIX() && !HasDebuggerTuning
4710 ? llvm::DebuggerKind::Default
4714 if (Args.hasFlag(options::OPT_fdebug_macro, options::OPT_fno_debug_macro,
4718 CmdArgs.push_back(
"-debug-info-macro");
4721 const auto *PubnamesArg =
4722 Args.getLastArg(options::OPT_ggnu_pubnames, options::OPT_gno_gnu_pubnames,
4723 options::OPT_gpubnames, options::OPT_gno_pubnames);
4726 const bool OptionSet =
4728 (PubnamesArg->getOption().matches(options::OPT_gpubnames) ||
4729 PubnamesArg->getOption().matches(options::OPT_ggnu_pubnames)));
4730 if ((DebuggerTuning != llvm::DebuggerKind::LLDB || OptionSet) &&
4732 (!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) &&
4733 !PubnamesArg->getOption().matches(options::OPT_gno_pubnames))))
4734 CmdArgs.push_back(PubnamesArg && PubnamesArg->getOption().matches(
4735 options::OPT_gpubnames)
4737 :
"-ggnu-pubnames");
4739 const auto *SimpleTemplateNamesArg =
4740 Args.getLastArg(options::OPT_gsimple_template_names,
4741 options::OPT_gno_simple_template_names);
4742 bool ForwardTemplateParams = DebuggerTuning == llvm::DebuggerKind::SCE;
4743 if (SimpleTemplateNamesArg &&
4745 const auto &Opt = SimpleTemplateNamesArg->getOption();
4746 if (Opt.matches(options::OPT_gsimple_template_names)) {
4747 ForwardTemplateParams =
true;
4748 CmdArgs.push_back(
"-gsimple-template-names=simple");
4753 bool UseDebugTemplateAlias =
4754 DebuggerTuning == llvm::DebuggerKind::SCE && RequestedDWARFVersion >= 4;
4755 if (
const auto *DebugTemplateAlias = Args.getLastArg(
4756 options::OPT_gtemplate_alias, options::OPT_gno_template_alias)) {
4760 const auto &Opt = DebugTemplateAlias->getOption();
4761 UseDebugTemplateAlias = Opt.matches(options::OPT_gtemplate_alias);
4764 if (UseDebugTemplateAlias)
4765 CmdArgs.push_back(
"-gtemplate-alias");
4767 if (
const Arg *A = Args.getLastArg(options::OPT_gsrc_hash_EQ)) {
4768 StringRef
v = A->getValue();
4769 CmdArgs.push_back(Args.MakeArgString(
"-gsrc-hash=" +
v));
4772 Args.addOptInFlag(CmdArgs, options::OPT_fdebug_ranges_base_address,
4773 options::OPT_fno_debug_ranges_base_address);
4777 if (
const Arg *A = Args.getLastArg(options::OPT_gdwarf_aranges);
4779 CmdArgs.push_back(
"-mllvm");
4780 CmdArgs.push_back(
"-generate-arange-section");
4783 Args.addOptInFlag(CmdArgs, options::OPT_fforce_dwarf_frame,
4784 options::OPT_fno_force_dwarf_frame);
4786 bool EnableTypeUnits =
false;
4787 if (Args.hasFlag(options::OPT_fdebug_types_section,
4788 options::OPT_fno_debug_types_section,
false)) {
4789 if (!(
T.isOSBinFormatELF() ||
T.isOSBinFormatWasm())) {
4790 D.Diag(diag::err_drv_unsupported_opt_for_target)
4791 << Args.getLastArg(options::OPT_fdebug_types_section)
4795 Args.getLastArg(options::OPT_fdebug_types_section), Args,
D,
4797 EnableTypeUnits =
true;
4798 CmdArgs.push_back(
"-mllvm");
4799 CmdArgs.push_back(
"-generate-type-units");
4804 Args.getLastArg(options::OPT_gomit_unreferenced_methods,
4805 options::OPT_gno_omit_unreferenced_methods))
4807 if (Args.hasFlag(options::OPT_gomit_unreferenced_methods,
4808 options::OPT_gno_omit_unreferenced_methods,
false) &&
4809 (DebugInfoKind == llvm::codegenoptions::DebugInfoConstructor ||
4810 DebugInfoKind == llvm::codegenoptions::LimitedDebugInfo) &&
4812 CmdArgs.push_back(
"-gomit-unreferenced-methods");
4818 if (!Args.hasFlag(options::OPT_fdwarf_directory_asm,
4819 options::OPT_fno_dwarf_directory_asm,
4821 CmdArgs.push_back(
"-fno-dwarf-directory-asm");
4825 if (ForwardTemplateParams)
4826 CmdArgs.push_back(
"-debug-forward-template-params");
4830 if (DebuggerTuning == llvm::DebuggerKind::SCE)
4831 CmdArgs.push_back(
"-dwarf-explicit-import");
4837 if (Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc,
false)) {
4838 if (TC.
getTriple().isOSBinFormatELF() ||
D.IsCLMode()) {
4839 if (DebugInfoKind >= llvm::codegenoptions::DebugInfoConstructor)
4840 CmdArgs.push_back(
"-fjmc");
4841 else if (
D.IsCLMode())
4842 D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo) <<
"/JMC"
4845 D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo) <<
"-fjmc"
4848 D.Diag(clang::diag::warn_drv_fjmc_for_elf_only);
4853 const char *DebugCompilationDir =
4865 ArgStringList &CmdArgs) {
4866 unsigned RTOptionID = options::OPT__SLASH_MT;
4868 if (Args.hasArg(options::OPT__SLASH_LDd))
4871 RTOptionID = options::OPT__SLASH_MTd;
4873 if (Arg *A = Args.getLastArg(options::OPT__SLASH_M_Group))
4874 RTOptionID = A->getOption().getID();
4876 if (Arg *A = Args.getLastArg(options::OPT_fms_runtime_lib_EQ)) {
4877 RTOptionID = llvm::StringSwitch<unsigned>(A->getValue())
4878 .Case(
"static", options::OPT__SLASH_MT)
4879 .Case(
"static_dbg", options::OPT__SLASH_MTd)
4880 .Case(
"dll", options::OPT__SLASH_MD)
4881 .Case(
"dll_dbg", options::OPT__SLASH_MDd)
4882 .Default(options::OPT__SLASH_MT);
4885 StringRef FlagForCRT;
4886 switch (RTOptionID) {
4887 case options::OPT__SLASH_MD:
4888 if (Args.hasArg(options::OPT__SLASH_LDd))
4889 CmdArgs.push_back(
"-D_DEBUG");
4890 CmdArgs.push_back(
"-D_MT");
4891 CmdArgs.push_back(
"-D_DLL");
4892 FlagForCRT =
"--dependent-lib=msvcrt";
4894 case options::OPT__SLASH_MDd:
4895 CmdArgs.push_back(
"-D_DEBUG");
4896 CmdArgs.push_back(
"-D_MT");
4897 CmdArgs.push_back(
"-D_DLL");
4898 FlagForCRT =
"--dependent-lib=msvcrtd";
4900 case options::OPT__SLASH_MT:
4901 if (Args.hasArg(options::OPT__SLASH_LDd))
4902 CmdArgs.push_back(
"-D_DEBUG");
4903 CmdArgs.push_back(
"-D_MT");
4904 CmdArgs.push_back(
"-flto-visibility-public-std");
4905 FlagForCRT =
"--dependent-lib=libcmt";
4907 case options::OPT__SLASH_MTd:
4908 CmdArgs.push_back(
"-D_DEBUG");
4909 CmdArgs.push_back(
"-D_MT");
4910 CmdArgs.push_back(
"-flto-visibility-public-std");
4911 FlagForCRT =
"--dependent-lib=libcmtd";
4914 llvm_unreachable(
"Unexpected option ID.");
4917 if (Args.hasArg(options::OPT_fms_omit_default_lib)) {
4918 CmdArgs.push_back(
"-D_VC_NODEFAULTLIB");
4920 CmdArgs.push_back(FlagForCRT.data());
4925 CmdArgs.push_back(
"--dependent-lib=oldnames");
4932 CmdArgs.push_back(
"--dependent-lib=softintrin");
4937 const ArgList &Args,
const char *LinkingOutput)
const {
4939 const llvm::Triple &RawTriple = TC.
getTriple();
4941 const std::string &TripleStr = Triple.getTriple();
4944 Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
4946 ArgStringList CmdArgs;
4948 assert(Inputs.size() >= 1 &&
"Must have at least one input.");
4960 bool IsExtractAPI = isa<ExtractAPIJobAction>(JA);
4963 bool IsHostOffloadingAction =
4966 Args.hasFlag(options::OPT_offload_new_driver,
4967 options::OPT_no_offload_new_driver,
false));
4970 Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
false);
4972 auto LTOMode = IsDeviceOffloadAction ?
D.getOffloadLTOMode() :
D.getLTOMode();
4977 InputInfo ExtractAPIPlaceholderInput(Inputs[0].getType(),
"extract-api",
4981 IsExtractAPI ? ExtractAPIPlaceholderInput : Inputs[0];
4985 const InputInfo *CudaDeviceInput =
nullptr;
4986 const InputInfo *OpenMPDeviceInput =
nullptr;
4988 if (&I == &Input || I.
getType() == types::TY_Nothing) {
4990 }
else if (IsExtractAPI) {
4991 auto ExpectedInputType = ExtractAPIPlaceholderInput.
getType();
4992 if (I.getType() != ExpectedInputType) {
4993 D.Diag(diag::err_drv_extract_api_wrong_kind)
4997 ExtractAPIInputs.push_back(I);
4998 }
else if (IsHostOffloadingAction) {
4999 HostOffloadingInputs.push_back(I);
5000 }
else if ((IsCuda || IsHIP) && !CudaDeviceInput) {
5001 CudaDeviceInput = &I;
5002 }
else if (IsOpenMPDevice && !OpenMPDeviceInput) {
5003 OpenMPDeviceInput = &I;
5005 llvm_unreachable(
"unexpectedly given multiple inputs");
5009 const llvm::Triple *AuxTriple =
5011 bool IsWindowsMSVC = RawTriple.isWindowsMSVCEnvironment();
5012 bool IsIAMCU = RawTriple.isOSIAMCU();
5017 if (IsCuda || IsHIP)
5018 IsWindowsMSVC |= AuxTriple && AuxTriple->isWindowsMSVCEnvironment();
5022 D.Diag(diag::err_drv_clang_unsupported) <<
"C++ for IAMCU";
5027 CmdArgs.push_back(
"-cc1");
5030 CmdArgs.push_back(
"-triple");
5031 CmdArgs.push_back(Args.MakeArgString(TripleStr));
5033 if (
const Arg *MJ = Args.getLastArg(options::OPT_MJ)) {
5034 DumpCompilationDatabase(
C, MJ->getValue(), TripleStr, Output, Input, Args);
5035 Args.ClaimAllArgs(options::OPT_MJ);
5036 }
else if (
const Arg *GenCDBFragment =
5037 Args.getLastArg(options::OPT_gen_cdb_fragment_path)) {
5038 DumpCompilationDatabaseFragmentToDir(GenCDBFragment->getValue(),
C,
5039 TripleStr, Output, Input, Args);
5040 Args.ClaimAllArgs(options::OPT_gen_cdb_fragment_path);
5043 if (IsCuda || IsHIP) {
5046 std::string NormalizedTriple;
5064 assert(CTC &&
"Expected valid CUDA Toolchain.");
5066 CmdArgs.push_back(Args.MakeArgString(
5067 Twine(
"-target-sdk-version=") +
5075 CmdArgs.push_back(
"-fcuda-allow-variadic-functions");
5078 CmdArgs.push_back(
"-aux-triple");
5079 CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
5084 getToolChain().getTriple().getVendor() == llvm::Triple::AMD))) {
5086 if (Args.getLastArg(options::OPT_mprintf_kind_EQ)) {
5087 CmdArgs.push_back(Args.MakeArgString(
5089 Args.getLastArgValue(options::OPT_mprintf_kind_EQ)));
5092 Args.MakeArgString(
"-Werror=format-invalid-specifier"));
5098 if (
const Arg *PF = Args.getLastArg(options::OPT_mprintf_kind_EQ))
5101 if (Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl,
false)) {
5102 CmdArgs.push_back(
"-fsycl-is-device");
5104 if (Arg *A = Args.getLastArg(options::OPT_sycl_std_EQ)) {
5105 A->render(Args, CmdArgs);
5108 CmdArgs.push_back(
"-sycl-std=2020");
5112 if (IsOpenMPDevice) {
5114 std::string NormalizedTriple =
5118 CmdArgs.push_back(
"-aux-triple");
5119 CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
5122 if (Triple.isOSWindows() && (Triple.getArch() == llvm::Triple::arm ||
5123 Triple.getArch() == llvm::Triple::thumb)) {
5124 unsigned Offset = Triple.getArch() == llvm::Triple::arm ? 4 : 6;
5125 unsigned Version = 0;
5127 Triple.getArchName().substr(Offset).consumeInteger(10, Version);
5128 if (Failure || Version < 7)
5129 D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName()
5139 if (Triple.isSPIR() || Triple.isSPIRV())
5140 CmdArgs.push_back(
"-Wspir-compat");
5143 RewriteKind rewriteKind = RK_None;
5145 bool UnifiedLTO =
false;
5147 UnifiedLTO = Args.hasFlag(options::OPT_funified_lto,
5148 options::OPT_fno_unified_lto, Triple.isPS());
5150 CmdArgs.push_back(
"-funified-lto");
5160 if (!isa<AssembleJobAction>(JA)) {
5164 Args.ClaimAllArgs(options::OPT_mrelax_all);
5165 Args.ClaimAllArgs(options::OPT_mno_relax_all);
5166 Args.ClaimAllArgs(options::OPT_mincremental_linker_compatible);
5167 Args.ClaimAllArgs(options::OPT_mno_incremental_linker_compatible);
5168 switch (
C.getDefaultToolChain().getArch()) {
5169 case llvm::Triple::arm:
5170 case llvm::Triple::armeb:
5171 case llvm::Triple::thumb:
5172 case llvm::Triple::thumbeb:
5173 Args.ClaimAllArgs(options::OPT_mimplicit_it_EQ);
5179 Args.ClaimAllArgs(options::OPT_Wa_COMMA);
5180 Args.ClaimAllArgs(options::OPT_Xassembler);
5181 Args.ClaimAllArgs(options::OPT_femit_dwarf_unwind_EQ);
5184 if (isa<AnalyzeJobAction>(JA)) {
5185 assert(JA.
getType() == types::TY_Plist &&
"Invalid output type.");
5186 CmdArgs.push_back(
"-analyze");
5187 }
else if (isa<MigrateJobAction>(JA)) {
5188 CmdArgs.push_back(
"-migrate");
5189 }
else if (isa<PreprocessJobAction>(JA)) {
5190 if (Output.
getType() == types::TY_Dependencies)
5191 CmdArgs.push_back(
"-Eonly");
5193 CmdArgs.push_back(
"-E");
5194 if (Args.hasArg(options::OPT_rewrite_objc) &&
5195 !Args.hasArg(options::OPT_g_Group))
5196 CmdArgs.push_back(
"-P");
5197 else if (JA.
getType() == types::TY_PP_CXXHeaderUnit)
5198 CmdArgs.push_back(
"-fdirectives-only");
5200 }
else if (isa<AssembleJobAction>(JA)) {
5201 CmdArgs.push_back(
"-emit-obj");
5206 (void)Args.hasArg(options::OPT_force__cpusubtype__ALL);
5207 }
else if (isa<PrecompileJobAction>(JA)) {
5208 if (JA.
getType() == types::TY_Nothing)
5209 CmdArgs.push_back(
"-fsyntax-only");
5210 else if (JA.
getType() == types::TY_ModuleFile)
5211 CmdArgs.push_back(
"-emit-module-interface");
5212 else if (JA.
getType() == types::TY_HeaderUnit)
5213 CmdArgs.push_back(
"-emit-header-unit");
5215 CmdArgs.push_back(
"-emit-pch");
5216 }
else if (isa<VerifyPCHJobAction>(JA)) {
5217 CmdArgs.push_back(
"-verify-pch");
5218 }
else if (isa<ExtractAPIJobAction>(JA)) {
5219 assert(JA.
getType() == types::TY_API_INFO &&
5220 "Extract API actions must generate a API information.");
5221 CmdArgs.push_back(
"-extract-api");
5223 if (Arg *PrettySGFArg = Args.getLastArg(options::OPT_emit_pretty_sgf))
5224 PrettySGFArg->render(Args, CmdArgs);
5226 Arg *SymbolGraphDirArg = Args.getLastArg(options::OPT_symbol_graph_dir_EQ);
5228 if (Arg *ProductNameArg = Args.getLastArg(options::OPT_product_name_EQ))
5229 ProductNameArg->render(Args, CmdArgs);
5230 if (Arg *ExtractAPIIgnoresFileArg =
5231 Args.getLastArg(options::OPT_extract_api_ignores_EQ))
5232 ExtractAPIIgnoresFileArg->render(Args, CmdArgs);
5233 if (Arg *EmitExtensionSymbolGraphs =
5234 Args.getLastArg(options::OPT_emit_extension_symbol_graphs)) {
5235 if (!SymbolGraphDirArg)
5236 D.Diag(diag::err_drv_missing_symbol_graph_dir);
5238 EmitExtensionSymbolGraphs->render(Args, CmdArgs);
5240 if (SymbolGraphDirArg)
5241 SymbolGraphDirArg->render(Args, CmdArgs);
5243 assert((isa<CompileJobAction>(JA) || isa<BackendJobAction>(JA)) &&
5244 "Invalid action for clang tool.");
5245 if (JA.
getType() == types::TY_Nothing) {
5246 CmdArgs.push_back(
"-fsyntax-only");
5247 }
else if (JA.
getType() == types::TY_LLVM_IR ||
5248 JA.
getType() == types::TY_LTO_IR) {
5249 CmdArgs.push_back(
"-emit-llvm");
5250 }
else if (JA.
getType() == types::TY_LLVM_BC ||
5251 JA.
getType() == types::TY_LTO_BC) {
5253 if (Triple.isAMDGCN() && IsOpenMPDevice && Args.hasArg(options::OPT_S) &&
5254 Args.hasArg(options::OPT_emit_llvm)) {
5255 CmdArgs.push_back(
"-emit-llvm");
5257 CmdArgs.push_back(
"-emit-llvm-bc");
5259 }
else if (JA.
getType() == types::TY_IFS ||
5260 JA.
getType() == types::TY_IFS_CPP) {
5262 Args.hasArg(options::OPT_interface_stub_version_EQ)
5263 ? Args.getLastArgValue(options::OPT_interface_stub_version_EQ)
5265 CmdArgs.push_back(
"-emit-interface-stubs");
5267 Args.MakeArgString(Twine(
"-interface-stub-version=") + ArgStr.str()));
5268 }
else if (JA.
getType() == types::TY_PP_Asm) {
5269 CmdArgs.push_back(
"-S");
5270 }
else if (JA.
getType() == types::TY_AST) {
5271 CmdArgs.push_back(
"-emit-pch");
5272 }
else if (JA.
getType() == types::TY_ModuleFile) {
5273 CmdArgs.push_back(
"-module-file-info");
5274 }
else if (JA.
getType() == types::TY_RewrittenObjC) {
5275 CmdArgs.push_back(
"-rewrite-objc");
5276 rewriteKind = RK_NonFragile;
5277 }
else if (JA.
getType() == types::TY_RewrittenLegacyObjC) {
5278 CmdArgs.push_back(
"-rewrite-objc");
5279 rewriteKind = RK_Fragile;
5281 assert(JA.
getType() == types::TY_PP_Asm &&
"Unexpected output type!");
5288 if (JA.
getType() == types::TY_LLVM_BC)
5289 CmdArgs.push_back(
"-emit-llvm-uselists");
5293 !Args.hasFlag(options::OPT_offload_new_driver,
5294 options::OPT_no_offload_new_driver,
false) &&
5295 !Triple.isAMDGPU()) {
5296 D.Diag(diag::err_drv_unsupported_opt_for_target)
5297 << Args.getLastArg(options::OPT_foffload_lto,
5298 options::OPT_foffload_lto_EQ)
5300 << Triple.getTriple();
5301 }
else if (Triple.isNVPTX() && !IsRDCMode &&
5303 D.Diag(diag::err_drv_unsupported_opt_for_language_mode)
5304 << Args.getLastArg(options::OPT_foffload_lto,
5305 options::OPT_foffload_lto_EQ)
5310 CmdArgs.push_back(Args.MakeArgString(
5311 Twine(
"-flto=") + (LTOMode ==
LTOK_Thin ?
"thin" :
"full")));
5314 if (!RawTriple.isPS4() ||
5315 (
D.getLTOMode() ==
LTOK_Full) || !UnifiedLTO)
5316 CmdArgs.push_back(
"-flto-unit");
5321 Args.AddLastArg(CmdArgs, options::OPT_dumpdir);
5323 if (
const Arg *A = Args.getLastArg(options::OPT_fthinlto_index_EQ)) {
5325 D.Diag(diag::err_drv_arg_requires_bitcode_input) << A->getAsString(Args);
5326 Args.AddLastArg(CmdArgs, options::OPT_fthinlto_index_EQ);
5330 Args.addOptInFlag(CmdArgs, options::OPT_mregnames,
5331 options::OPT_mno_regnames);
5333 if (Args.getLastArg(options::OPT_fthin_link_bitcode_EQ))
5334 Args.AddLastArg(CmdArgs, options::OPT_fthin_link_bitcode_EQ);
5336 if (Args.getLastArg(options::OPT_save_temps_EQ))
5337 Args.AddLastArg(CmdArgs, options::OPT_save_temps_EQ);
5339 auto *MemProfArg = Args.getLastArg(options::OPT_fmemory_profile,
5340 options::OPT_fmemory_profile_EQ,
5341 options::OPT_fno_memory_profile);
5343 !MemProfArg->getOption().matches(options::OPT_fno_memory_profile))
5344 MemProfArg->render(Args, CmdArgs);
5346 if (
auto *MemProfUseArg =
5347 Args.getLastArg(options::OPT_fmemory_profile_use_EQ)) {
5349 D.Diag(diag::err_drv_argument_not_allowed_with)
5350 << MemProfUseArg->getAsString(Args) << MemProfArg->getAsString(Args);
5351 if (
auto *PGOInstrArg = Args.getLastArg(options::OPT_fprofile_generate,
5352 options::OPT_fprofile_generate_EQ))
5353 D.Diag(diag::err_drv_argument_not_allowed_with)
5354 << MemProfUseArg->getAsString(Args) << PGOInstrArg->getAsString(Args);
5355 MemProfUseArg->render(Args, CmdArgs);
5360 if (
C.getDriver().embedBitcodeInObject() && !IsUsingLTO &&
5361 (isa<BackendJobAction>(JA) || isa<AssembleJobAction>(JA))) {
5363 Args.AddLastArg(CmdArgs, options::OPT_fembed_bitcode_EQ);
5365 CmdArgs.push_back(
"-disable-llvm-passes");
5372 static const constexpr unsigned kBitcodeOptionIgnorelist[] = {
5373 options::OPT_mkernel,
5374 options::OPT_fapple_kext,
5375 options::OPT_ffunction_sections,
5376 options::OPT_fno_function_sections,
5377 options::OPT_fdata_sections,
5378 options::OPT_fno_data_sections,
5379 options::OPT_fbasic_block_sections_EQ,
5380 options::OPT_funique_internal_linkage_names,
5381 options::OPT_fno_unique_internal_linkage_names,
5382 options::OPT_funique_section_names,
5383 options::OPT_fno_unique_section_names,
5384 options::OPT_funique_basic_block_section_names,
5385 options::OPT_fno_unique_basic_block_section_names,
5386 options::OPT_mrestrict_it,
5387 options::OPT_mno_restrict_it,
5388 options::OPT_mstackrealign,
5389 options::OPT_mno_stackrealign,
5390 options::OPT_mstack_alignment,
5391 options::OPT_mcmodel_EQ,
5392 options::OPT_mlong_calls,
5393 options::OPT_mno_long_calls,
5394 options::OPT_ggnu_pubnames,
5395 options::OPT_gdwarf_aranges,
5396 options::OPT_fdebug_types_section,
5397 options::OPT_fno_debug_types_section,
5398 options::OPT_fdwarf_directory_asm,
5399 options::OPT_fno_dwarf_directory_asm,
5400 options::OPT_mrelax_all,
5401 options::OPT_mno_relax_all,
5402 options::OPT_ftrap_function_EQ,
5403 options::OPT_ffixed_r9,
5404 options::OPT_mfix_cortex_a53_835769,
5405 options::OPT_mno_fix_cortex_a53_835769,
5406 options::OPT_ffixed_x18,
5407 options::OPT_mglobal_merge,
5408 options::OPT_mno_global_merge,
5409 options::OPT_mred_zone,
5410 options::OPT_mno_red_zone,
5411 options::OPT_Wa_COMMA,
5412 options::OPT_Xassembler,
5415 for (
const auto &A : Args)
5416 if (llvm::is_contained(kBitcodeOptionIgnorelist, A->getOption().getID()))
5417 D.Diag(diag::err_drv_unsupported_embed_bitcode) << A->getSpelling();
5420 Args.addOptOutFlag(CmdArgs, options::OPT_foptimize_sibling_calls,
5421 options::OPT_fno_optimize_sibling_calls);
5429 case llvm::Triple::arm:
5430 case llvm::Triple::armeb:
5431 case llvm::Triple::thumbeb:
5432 RenderARMABI(
D, Triple, Args, CmdArgs);
5434 case llvm::Triple::aarch64:
5435 case llvm::Triple::aarch64_32:
5436 case llvm::Triple::aarch64_be:
5437 RenderAArch64ABI(Triple, Args, CmdArgs);
5442 if (
const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
5443 if (A->getOption().matches(options::OPT_O4)) {
5444 CmdArgs.push_back(
"-O3");
5445 D.Diag(diag::warn_O4_is_O3);
5447 A->render(Args, CmdArgs);
5452 if (Output.
getType() == types::TY_Dependencies) {
5455 CmdArgs.push_back(
"-o");
5458 assert(Output.
isNothing() &&
"Input output.");
5461 for (
const auto &II : Inputs) {
5463 if (II.isFilename())
5464 CmdArgs.push_back(II.getFilename());
5466 II.getInputArg().renderAsInput(Args, CmdArgs);
5469 C.addCommand(std::make_unique<Command>(
5471 CmdArgs, Inputs, Output,
D.getPrependArg()));
5475 if (
C.getDriver().embedBitcodeMarkerOnly() && !IsUsingLTO)
5476 CmdArgs.push_back(
"-fembed-bitcode=marker");
5481 if (!
C.isForDiagnostics())
5482 CmdArgs.push_back(
"-disable-free");
5483 CmdArgs.push_back(
"-clear-ast-before-backend");
5486 const bool IsAssertBuild =
false;
5488 const bool IsAssertBuild =
true;
5492 if (Args.hasFlag(options::OPT_fno_verify_intermediate_code,
5493 options::OPT_fverify_intermediate_code, !IsAssertBuild)) {
5494 CmdArgs.push_back(
"-disable-llvm-verifier");
5498 if (Args.hasFlag(options::OPT_fdiscard_value_names,
5499 options::OPT_fno_discard_value_names, !IsAssertBuild)) {
5500 if (Args.hasArg(options::OPT_fdiscard_value_names) &&
5502 return types::isLLVMIR(II.getType());
5504 D.Diag(diag::warn_ignoring_fdiscard_for_bitcode);
5506 CmdArgs.push_back(
"-discard-value-names");
5511 CmdArgs.push_back(
"-main-file-name");
5516 if (Args.hasArg(options::OPT_static))
5517 CmdArgs.push_back(
"-static-define");
5519 if (Args.hasArg(options::OPT_municode))
5520 CmdArgs.push_back(
"-DUNICODE");
5522 if (isa<AnalyzeJobAction>(JA))
5525 if (isa<AnalyzeJobAction>(JA) ||
5526 (isa<PreprocessJobAction>(JA) && Args.hasArg(options::OPT__analyze)))
5527 CmdArgs.push_back(
"-setup-static-analyzer");
5532 bool FoundAnalyzerConfig =
false;
5533 for (
auto *Arg : Args.filtered(options::OPT_Xclang))
5534 if (StringRef(Arg->getValue()) ==
"-analyzer-config") {
5535 FoundAnalyzerConfig =
true;
5538 if (!FoundAnalyzerConfig)
5539 for (
auto *Arg : Args.filtered(options::OPT_Xanalyzer))
5540 if (StringRef(Arg->getValue()) ==
"-analyzer-config") {
5541 FoundAnalyzerConfig =
true;
5544 if (FoundAnalyzerConfig)
5545 CmdArgs.push_back(
"-analyzer-config-compatibility-mode=true");
5550 assert(FunctionAlignment <= 31 &&
"function alignment will be truncated!");
5551 if (FunctionAlignment) {
5552 CmdArgs.push_back(
"-function-alignment");
5553 CmdArgs.push_back(Args.MakeArgString(std::to_string(FunctionAlignment)));
5558 if (
const Arg *A = Args.getLastArg(options::OPT_falign_loops_EQ)) {
5560 if (StringRef(A->getValue()).getAsInteger(10,
Value) ||
Value > 65536)
5562 << A->getAsString(Args) << A->getValue();
5564 TC.
getDriver().
Diag(diag::err_drv_alignment_not_power_of_two)
5565 << A->getAsString(Args) << A->getValue();
5568 CmdArgs.push_back(Args.MakeArgString(
"-falign-loops=" +
5569 Twine(std::min(
Value, 65536u))));
5572 if (Triple.isOSzOS()) {
5581 auto findMacroDefinition = [&](
const std::string &Macro) {
5582 auto MacroDefs = Args.getAllArgValues(options::OPT_D);
5583 return llvm::any_of(MacroDefs, [&](
const std::string &M) {
5584 return M == Macro || M.find(Macro +
'=') != std::string::npos;
5589 if (!findMacroDefinition(
"_UNIX03_WITHDRAWN"))
5590 CmdArgs.push_back(
"-D_UNIX03_WITHDRAWN");
5592 if (!findMacroDefinition(
"_OPEN_DEFAULT"))
5593 CmdArgs.push_back(
"-D_OPEN_DEFAULT");
5596 if (!findMacroDefinition(
"_XOPEN_SOURCE"))
5597 CmdArgs.push_back(
"-D_XOPEN_SOURCE=600");
5601 llvm::Reloc::Model RelocationModel;
5604 std::tie(RelocationModel, PICLevel, IsPIE) =
ParsePICArgs(TC, Args);
5605 Arg *LastPICDataRelArg =
5606 Args.getLastArg(options::OPT_mno_pic_data_is_text_relative,
5607 options::OPT_mpic_data_is_text_relative);
5608 bool NoPICDataIsTextRelative =
false;
5609 if (LastPICDataRelArg) {
5610 if (LastPICDataRelArg->getOption().matches(
5611 options::OPT_mno_pic_data_is_text_relative)) {
5612 NoPICDataIsTextRelative =
true;
5614 D.Diag(diag::err_drv_argument_only_allowed_with)
5615 <<
"-mno-pic-data-is-text-relative"
5618 if (!Triple.isSystemZ())
5619 D.Diag(diag::err_drv_unsupported_opt_for_target)
5620 << (NoPICDataIsTextRelative ?
"-mno-pic-data-is-text-relative"
5621 :
"-mpic-data-is-text-relative")
5625 bool IsROPI = RelocationModel == llvm::Reloc::ROPI ||
5626 RelocationModel == llvm::Reloc::ROPI_RWPI;
5627 bool IsRWPI = RelocationModel == llvm::Reloc::RWPI ||
5628 RelocationModel == llvm::Reloc::ROPI_RWPI;
5630 if (Args.hasArg(options::OPT_mcmse) &&
5631 !Args.hasArg(options::OPT_fallow_unsupported)) {
5633 D.Diag(diag::err_cmse_pi_are_incompatible) << IsROPI;
5635 D.Diag(diag::err_cmse_pi_are_incompatible) << !IsRWPI;
5639 !Args.hasArg(options::OPT_fallow_unsupported))
5640 D.Diag(diag::err_drv_ropi_incompatible_with_cxx);
5644 CmdArgs.push_back(
"-mrelocation-model");
5645 CmdArgs.push_back(RMName);
5648 CmdArgs.push_back(
"-pic-level");
5649 CmdArgs.push_back(PICLevel == 1 ?
"1" :
"2");
5651 CmdArgs.push_back(
"-pic-is-pie");
5652 if (NoPICDataIsTextRelative)
5653 CmdArgs.push_back(
"-mcmodel=medium");
5656 if (RelocationModel == llvm::Reloc::ROPI ||
5657 RelocationModel == llvm::Reloc::ROPI_RWPI)
5658 CmdArgs.push_back(
"-fropi");
5659 if (RelocationModel == llvm::Reloc::RWPI ||
5660 RelocationModel == llvm::Reloc::ROPI_RWPI)
5661 CmdArgs.push_back(
"-frwpi");
5663 if (Arg *A = Args.getLastArg(options::OPT_meabi)) {
5664 CmdArgs.push_back(
"-meabi");
5665 CmdArgs.push_back(A->getValue());
5679 if (Triple.isOSBinFormatELF()) {
5680 Arg *A = Args.getLastArg(options::OPT_fsemantic_interposition,
5681 options::OPT_fno_semantic_interposition);
5682 if (RelocationModel != llvm::Reloc::Static && !IsPIE) {
5684 bool SupportsLocalAlias =
5685 Triple.isAArch64() || Triple.isRISCV() || Triple.isX86();
5687 CmdArgs.push_back(
"-fhalf-no-semantic-interposition");
5688 else if (A->getOption().matches(options::OPT_fsemantic_interposition))
5689 A->render(Args, CmdArgs);
5690 else if (!SupportsLocalAlias)
5691 CmdArgs.push_back(
"-fhalf-no-semantic-interposition");
5697 if (Arg *A = Args.getLastArg(options::OPT_mthread_model)) {
5699 D.Diag(diag::err_drv_invalid_thread_model_for_target)
5700 << A->getValue() << A->getAsString(Args);
5701 Model = A->getValue();
5704 if (Model !=
"posix") {
5705 CmdArgs.push_back(
"-mthread-model");
5706 CmdArgs.push_back(Args.MakeArgString(Model));
5710 if (Arg *A = Args.getLastArg(options::OPT_fveclib)) {
5711 StringRef Name = A->getValue();
5712 if (Name ==
"SVML") {
5713 if (Triple.getArch() != llvm::Triple::x86 &&
5714 Triple.getArch() != llvm::Triple::x86_64)
5715 D.Diag(diag::err_drv_unsupported_opt_for_target)
5716 << Name << Triple.getArchName();
5717 }
else if (Name ==
"LIBMVEC-X86") {
5718 if (Triple.getArch() != llvm::Triple::x86 &&
5719 Triple.getArch() != llvm::Triple::x86_64)
5720 D.Diag(diag::err_drv_unsupported_opt_for_target)
5721 << Name << Triple.getArchName();
5722 }
else if (Name ==
"SLEEF" || Name ==
"ArmPL") {
5723 if (Triple.getArch() != llvm::Triple::aarch64 &&
5724 Triple.getArch() != llvm::Triple::aarch64_be)
5725 D.Diag(diag::err_drv_unsupported_opt_for_target)
5726 << Name << Triple.getArchName();
5728 A->render(Args, CmdArgs);
5731 if (Args.hasFlag(options::OPT_fmerge_all_constants,
5732 options::OPT_fno_merge_all_constants,
false))
5733 CmdArgs.push_back(
"-fmerge-all-constants");
5735 Args.addOptOutFlag(CmdArgs, options::OPT_fdelete_null_pointer_checks,
5736 options::OPT_fno_delete_null_pointer_checks);
5740 if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ_quadword_atomics)) {
5741 if (!Triple.isOSAIX() || Triple.isPPC32())
5742 D.Diag(diag::err_drv_unsupported_opt_for_target)
5743 << A->getSpelling() << RawTriple.str();
5744 CmdArgs.push_back(
"-mabi=quadword-atomics");
5747 if (Arg *A = Args.getLastArg(options::OPT_mlong_double_128)) {
5750 if (Triple.isOSAIX())
5751 D.Diag(diag::err_drv_unsupported_opt_for_target)
5752 << A->getSpelling() << RawTriple.str();
5755 if (Arg *A = Args.getLastArg(options::OPT_Wframe_larger_than_EQ)) {
5756 StringRef
V = A->getValue(), V1 =
V;
5758 if (V1.consumeInteger(10, Size) || !V1.empty())
5759 D.Diag(diag::err_drv_invalid_argument_to_option)
5760 <<
V << A->getOption().getName();
5762 CmdArgs.push_back(Args.MakeArgString(
"-fwarn-stack-size=" +
V));
5765 Args.addOptOutFlag(CmdArgs, options::OPT_fjump_tables,
5766 options::OPT_fno_jump_tables);
5767 Args.addOptInFlag(CmdArgs, options::OPT_fprofile_sample_accurate,
5768 options::OPT_fno_profile_sample_accurate);
5769 Args.addOptOutFlag(CmdArgs, options::OPT_fpreserve_as_comments,
5770 options::OPT_fno_preserve_as_comments);
5772 if (Arg *A = Args.getLastArg(options::OPT_mregparm_EQ)) {
5773 CmdArgs.push_back(
"-mregparm");
5774 CmdArgs.push_back(A->getValue());
5777 if (Arg *A = Args.getLastArg(options::OPT_maix_struct_return,
5778 options::OPT_msvr4_struct_return)) {
5780 D.Diag(diag::err_drv_unsupported_opt_for_target)
5781 << A->getSpelling() << RawTriple.str();
5782 }
else if (A->getOption().matches(options::OPT_maix_struct_return)) {
5783 CmdArgs.push_back(
"-maix-struct-return");
5785 assert(A->getOption().matches(options::OPT_msvr4_struct_return));
5786 CmdArgs.push_back(
"-msvr4-struct-return");
5790 if (Arg *A = Args.getLastArg(options::OPT_fpcc_struct_return,
5791 options::OPT_freg_struct_return)) {
5792 if (TC.
getArch() != llvm::Triple::x86) {
5793 D.Diag(diag::err_drv_unsupported_opt_for_target)
5794 << A->getSpelling() << RawTriple.str();
5795 }
else if (A->getOption().matches(options::OPT_fpcc_struct_return)) {
5796 CmdArgs.push_back(
"-fpcc-struct-return");
5798 assert(A->getOption().matches(options::OPT_freg_struct_return));
5799 CmdArgs.push_back(
"-freg-struct-return");
5803 if (Args.hasFlag(options::OPT_mrtd, options::OPT_mno_rtd,
false)) {
5804 if (Triple.getArch() == llvm::Triple::m68k)
5805 CmdArgs.push_back(
"-fdefault-calling-conv=rtdcall");
5807 CmdArgs.push_back(
"-fdefault-calling-conv=stdcall");
5810 if (Args.hasArg(options::OPT_fenable_matrix)) {
5812 CmdArgs.push_back(
"-fenable-matrix");
5813 CmdArgs.push_back(
"-mllvm");
5814 CmdArgs.push_back(
"-enable-matrix");
5819 const char *FPKeepKindStr =
nullptr;
5820 switch (FPKeepKind) {
5822 FPKeepKindStr =
"-mframe-pointer=none";
5825 FPKeepKindStr =
"-mframe-pointer=reserved";