35#include "clang/Config/config.h"
44#include "llvm/ADT/ScopeExit.h"
45#include "llvm/ADT/SmallSet.h"
46#include "llvm/ADT/StringExtras.h"
47#include "llvm/BinaryFormat/Magic.h"
48#include "llvm/Config/llvm-config.h"
49#include "llvm/Frontend/Debug/Options.h"
50#include "llvm/Object/ObjectFile.h"
51#include "llvm/Option/ArgList.h"
52#include "llvm/Support/CodeGen.h"
53#include "llvm/Support/Compiler.h"
54#include "llvm/Support/Compression.h"
55#include "llvm/Support/Error.h"
56#include "llvm/Support/FileSystem.h"
57#include "llvm/Support/Path.h"
58#include "llvm/Support/Process.h"
59#include "llvm/Support/YAMLParser.h"
60#include "llvm/TargetParser/AArch64TargetParser.h"
61#include "llvm/TargetParser/ARMTargetParserCommon.h"
62#include "llvm/TargetParser/Host.h"
63#include "llvm/TargetParser/LoongArchTargetParser.h"
64#include "llvm/TargetParser/PPCTargetParser.h"
65#include "llvm/TargetParser/RISCVISAInfo.h"
66#include "llvm/TargetParser/RISCVTargetParser.h"
75 if (Arg *A = Args.getLastArg(clang::driver::options::OPT_C, options::OPT_CC,
76 options::OPT_fminimize_whitespace,
77 options::OPT_fno_minimize_whitespace,
78 options::OPT_fkeep_system_includes,
79 options::OPT_fno_keep_system_includes)) {
80 if (!Args.hasArg(options::OPT_E) && !Args.hasArg(options::OPT__SLASH_P) &&
81 !Args.hasArg(options::OPT__SLASH_EP) && !
D.CCCIsCPP()) {
82 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
83 << A->getBaseArg().getAsString(Args)
84 << (
D.IsCLMode() ?
"/E, /P or /EP" :
"-E");
91 if (Args.hasArg(options::OPT_static))
93 Args.getLastArg(options::OPT_dynamic, options::OPT_mdynamic_no_pic))
94 D.Diag(diag::err_drv_argument_not_allowed_with) << A->getAsString(Args)
103 llvm::function_ref<
void(
const ToolChain &)> Work) {
105 Work(RegularToolChain);
120 for (
auto II = TCs.first, IE = TCs.second; II != IE; ++II)
135 const Arg &A,
size_t &Position) {
136 const char RefinementStepToken =
':';
137 Position = In.find(RefinementStepToken);
138 if (Position != StringRef::npos) {
139 StringRef Option = A.getOption().getName();
140 StringRef RefStep = In.substr(Position + 1);
148 if (RefStep.size() != 1) {
149 D.Diag(diag::err_drv_invalid_value) << Option << RefStep;
152 char RefStepChar = RefStep[0];
153 if (RefStepChar <
'0' || RefStepChar >
'9') {
154 D.Diag(diag::err_drv_invalid_value) << Option << RefStep;
163 ArgStringList &OutStrings) {
164 StringRef DisabledPrefixIn =
"!";
165 StringRef DisabledPrefixOut =
"!";
166 StringRef EnabledPrefixOut =
"";
167 StringRef Out =
"-mrecip=";
169 Arg *A = Args.getLastArg(options::OPT_mrecip, options::OPT_mrecip_EQ);
173 unsigned NumOptions = A->getNumValues();
174 if (NumOptions == 0) {
176 OutStrings.push_back(Args.MakeArgString(Out +
"all"));
181 if (NumOptions == 1) {
182 StringRef Val = A->getValue(0);
186 StringRef ValBase = Val.slice(0, RefStepLoc);
187 if (ValBase ==
"all" || ValBase ==
"none" || ValBase ==
"default") {
188 OutStrings.push_back(Args.MakeArgString(Out + Val));
197 llvm::StringMap<bool> OptionStrings;
198 OptionStrings.insert(std::make_pair(
"divd",
false));
199 OptionStrings.insert(std::make_pair(
"divf",
false));
200 OptionStrings.insert(std::make_pair(
"divh",
false));
201 OptionStrings.insert(std::make_pair(
"vec-divd",
false));
202 OptionStrings.insert(std::make_pair(
"vec-divf",
false));
203 OptionStrings.insert(std::make_pair(
"vec-divh",
false));
204 OptionStrings.insert(std::make_pair(
"sqrtd",
false));
205 OptionStrings.insert(std::make_pair(
"sqrtf",
false));
206 OptionStrings.insert(std::make_pair(
"sqrth",
false));
207 OptionStrings.insert(std::make_pair(
"vec-sqrtd",
false));
208 OptionStrings.insert(std::make_pair(
"vec-sqrtf",
false));
209 OptionStrings.insert(std::make_pair(
"vec-sqrth",
false));
211 for (
unsigned i = 0; i != NumOptions; ++i) {
212 StringRef Val = A->getValue(i);
214 bool IsDisabled = Val.starts_with(DisabledPrefixIn);
223 StringRef ValBase = Val.slice(0, RefStep);
224 llvm::StringMap<bool>::iterator OptionIter = OptionStrings.find(ValBase);
225 if (OptionIter == OptionStrings.end()) {
227 OptionIter = OptionStrings.find(ValBase.str() +
'f');
228 if (OptionIter == OptionStrings.end()) {
230 D.Diag(diag::err_drv_unknown_argument) << Val;
236 if (OptionStrings[ValBase.str() +
'd'] ||
237 OptionStrings[ValBase.str() +
'h']) {
238 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Val;
243 if (OptionIter->second ==
true) {
245 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Val;
250 OptionIter->second =
true;
254 if (ValBase.back() !=
'f' && ValBase.back() !=
'd' && ValBase.back() !=
'h') {
255 OptionStrings[ValBase.str() +
'd'] =
true;
256 OptionStrings[ValBase.str() +
'h'] =
true;
260 StringRef Prefix = IsDisabled ? DisabledPrefixOut : EnabledPrefixOut;
261 Out = Args.MakeArgString(Out + Prefix + Val);
262 if (i != NumOptions - 1)
263 Out = Args.MakeArgString(Out +
",");
266 OutStrings.push_back(Args.MakeArgString(Out));
272 ArgStringList &CmdArgs) {
273 Arg *A = Args.getLastArg(options::OPT_mprefer_vector_width_EQ);
277 StringRef
Value = A->getValue();
278 if (
Value ==
"none") {
279 CmdArgs.push_back(
"-mprefer-vector-width=none");
282 if (
Value.getAsInteger(10, Width)) {
283 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() <<
Value;
286 CmdArgs.push_back(Args.MakeArgString(
"-mprefer-vector-width=" +
Value));
292 const llvm::Triple &Triple) {
299 if (!Triple.isMacOSX())
302 return (!Triple.isMacOSXVersionLT(10, 5) &&
303 (Triple.getArch() == llvm::Triple::x86_64 ||
304 Triple.getArch() == llvm::Triple::arm));
314 ArgStringList &CmdArgs) {
315 const llvm::Triple &Triple = TC.
getTriple();
320 Args.ClaimAllArgs(options::OPT_fexceptions);
321 Args.ClaimAllArgs(options::OPT_fno_exceptions);
322 Args.ClaimAllArgs(options::OPT_fobjc_exceptions);
323 Args.ClaimAllArgs(options::OPT_fno_objc_exceptions);
324 Args.ClaimAllArgs(options::OPT_fcxx_exceptions);
325 Args.ClaimAllArgs(options::OPT_fno_cxx_exceptions);
326 Args.ClaimAllArgs(options::OPT_fasync_exceptions);
327 Args.ClaimAllArgs(options::OPT_fno_async_exceptions);
332 bool EH = Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
336 if (Triple.isWindowsMSVCEnvironment()) {
337 bool EHa = Args.hasFlag(options::OPT_fasync_exceptions,
338 options::OPT_fno_async_exceptions,
false);
340 CmdArgs.push_back(
"-fasync-exceptions");
348 Args.hasFlag(options::OPT_fobjc_exceptions,
349 options::OPT_fno_objc_exceptions,
true)) {
350 CmdArgs.push_back(
"-fobjc-exceptions");
357 bool CXXExceptionsEnabled = Triple.getArch() != llvm::Triple::xcore &&
358 !Triple.isPS() && !Triple.isDriverKit();
359 Arg *ExceptionArg = Args.getLastArg(
360 options::OPT_fcxx_exceptions, options::OPT_fno_cxx_exceptions,
361 options::OPT_fexceptions, options::OPT_fno_exceptions);
363 CXXExceptionsEnabled =
364 ExceptionArg->getOption().matches(options::OPT_fcxx_exceptions) ||
365 ExceptionArg->getOption().matches(options::OPT_fexceptions);
367 if (CXXExceptionsEnabled) {
368 CmdArgs.push_back(
"-fcxx-exceptions");
377 Args.AddLastArg(CmdArgs, options::OPT_fignore_exceptions);
379 Args.addOptInFlag(CmdArgs, options::OPT_fassume_nothrow_exception_dtor,
380 options::OPT_fno_assume_nothrow_exception_dtor);
383 CmdArgs.push_back(
"-fexceptions");
399 return Args.hasFlag(options::OPT_fautolink, options::OPT_fno_autolink,
405 ArgStringList &CmdArgs,
406 const llvm::vfs::FileSystem &VFS) {
407 if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ,
408 options::OPT_fdebug_compilation_dir_EQ)) {
409 if (A->getOption().matches(options::OPT_ffile_compilation_dir_EQ))
410 CmdArgs.push_back(Args.MakeArgString(Twine(
"-fdebug-compilation-dir=") +
413 A->render(Args, CmdArgs);
414 }
else if (llvm::ErrorOr<std::string> CWD =
415 VFS.getCurrentWorkingDirectory()) {
416 CmdArgs.push_back(Args.MakeArgString(
"-fdebug-compilation-dir=" + *CWD));
418 StringRef
Path(CmdArgs.back());
419 return Path.substr(
Path.find(
'=') + 1).data();
423 const char *DebugCompilationDir,
424 const char *OutputFileName) {
426 for (
auto *Arg : Args.filtered(options::OPT_Xclang))
427 if (StringRef(Arg->getValue()).starts_with(
"-object-file-name"))
430 if (Args.hasArg(options::OPT_object_file_name_EQ))
434 if (ObjFileNameForDebug !=
"-" &&
435 !llvm::sys::path::is_absolute(ObjFileNameForDebug) &&
436 (!DebugCompilationDir ||
437 llvm::sys::path::is_absolute(DebugCompilationDir))) {
439 llvm::sys::fs::make_absolute(ObjFileNameForDebug);
445 llvm::sys::path::Style Style =
446 llvm::sys::path::is_absolute(ObjFileNameForDebug)
447 ? llvm::sys::path::Style::native
448 : llvm::sys::path::Style::windows_backslash;
449 llvm::sys::path::remove_dots(ObjFileNameForDebug,
true,
452 Args.MakeArgString(Twine(
"-object-file-name=") + ObjFileNameForDebug));
457 const ArgList &Args, ArgStringList &CmdArgs) {
458 auto AddOneArg = [&](StringRef Map, StringRef Name) {
459 if (!Map.contains(
'='))
460 D.Diag(diag::err_drv_invalid_argument_to_option) << Map << Name;
462 CmdArgs.push_back(Args.MakeArgString(
"-fdebug-prefix-map=" + Map));
465 for (
const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
466 options::OPT_fdebug_prefix_map_EQ)) {
467 AddOneArg(A->getValue(), A->getOption().getName());
471 if (GlobalRemapEntry.empty())
473 AddOneArg(GlobalRemapEntry,
"environment");
478 ArgStringList &CmdArgs) {
479 for (
const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
480 options::OPT_fmacro_prefix_map_EQ)) {
481 StringRef Map = A->getValue();
482 if (!Map.contains(
'='))
483 D.Diag(diag::err_drv_invalid_argument_to_option)
484 << Map << A->getOption().getName();
486 CmdArgs.push_back(Args.MakeArgString(
"-fmacro-prefix-map=" + Map));
493 ArgStringList &CmdArgs) {
494 for (
const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
495 options::OPT_fcoverage_prefix_map_EQ)) {
496 StringRef Map = A->getValue();
497 if (!Map.contains(
'='))
498 D.Diag(diag::err_drv_invalid_argument_to_option)
499 << Map << A->getOption().getName();
501 CmdArgs.push_back(Args.MakeArgString(
"-fcoverage-prefix-map=" + Map));
510 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
511 if (A->getOption().matches(options::OPT_O4) ||
512 A->getOption().matches(options::OPT_Ofast))
515 if (A->getOption().matches(options::OPT_O0))
518 assert(A->getOption().matches(options::OPT_O) &&
"Must have a -O flag");
521 StringRef S(A->getValue());
529 unsigned OptLevel = 0;
530 if (S.getAsInteger(10, OptLevel))
541 ArgStringList &CmdArgs) {
544 if (Args.hasArg(options::OPT_verify_pch) && Input.
getType() == types::TY_PCH)
547 CmdArgs.push_back(
"-x");
548 if (Args.hasArg(options::OPT_rewrite_objc))
554 const char *ClangType;
556 case types::TY_CXXModule:
559 case types::TY_PP_CXXModule:
560 ClangType =
"c++-cpp-output";
566 CmdArgs.push_back(ClangType);
573 ArgStringList &CmdArgs) {
575 auto *PGOGenerateArg = Args.getLastArg(options::OPT_fprofile_generate,
576 options::OPT_fprofile_generate_EQ,
577 options::OPT_fno_profile_generate);
578 if (PGOGenerateArg &&
579 PGOGenerateArg->getOption().matches(options::OPT_fno_profile_generate))
580 PGOGenerateArg =
nullptr;
584 auto *ProfileGenerateArg = Args.getLastArg(
585 options::OPT_fprofile_instr_generate,
586 options::OPT_fprofile_instr_generate_EQ,
587 options::OPT_fno_profile_instr_generate);
588 if (ProfileGenerateArg &&
589 ProfileGenerateArg->getOption().matches(
590 options::OPT_fno_profile_instr_generate))
591 ProfileGenerateArg =
nullptr;
593 if (PGOGenerateArg && ProfileGenerateArg)
594 D.Diag(diag::err_drv_argument_not_allowed_with)
595 << PGOGenerateArg->getSpelling() << ProfileGenerateArg->getSpelling();
599 if (PGOGenerateArg && ProfileUseArg)
600 D.Diag(diag::err_drv_argument_not_allowed_with)
601 << ProfileUseArg->getSpelling() << PGOGenerateArg->getSpelling();
603 if (ProfileGenerateArg && ProfileUseArg)
604 D.Diag(diag::err_drv_argument_not_allowed_with)
605 << ProfileGenerateArg->getSpelling() << ProfileUseArg->getSpelling();
607 if (CSPGOGenerateArg && PGOGenerateArg) {
608 D.Diag(diag::err_drv_argument_not_allowed_with)
609 << CSPGOGenerateArg->getSpelling() << PGOGenerateArg->getSpelling();
610 PGOGenerateArg =
nullptr;
615 D.Diag(diag::err_drv_unsupported_opt_for_target)
616 << ProfileSampleUseArg->getSpelling() << TC.
getTriple().str();
619 if (ProfileGenerateArg) {
620 if (ProfileGenerateArg->getOption().matches(
621 options::OPT_fprofile_instr_generate_EQ))
622 CmdArgs.push_back(Args.MakeArgString(Twine(
"-fprofile-instrument-path=") +
623 ProfileGenerateArg->getValue()));
625 CmdArgs.push_back(
"-fprofile-instrument=clang");
626 if (TC.
getTriple().isWindowsMSVCEnvironment() &&
627 Args.hasFlag(options::OPT_frtlib_defaultlib,
628 options::OPT_fno_rtlib_defaultlib,
true)) {
630 CmdArgs.push_back(Args.MakeArgString(
635 if (
auto *ColdFuncCoverageArg = Args.getLastArg(
636 options::OPT_fprofile_generate_cold_function_coverage,
637 options::OPT_fprofile_generate_cold_function_coverage_EQ)) {
639 ColdFuncCoverageArg->getOption().matches(
640 options::OPT_fprofile_generate_cold_function_coverage_EQ)
641 ? ColdFuncCoverageArg->getValue()
643 llvm::sys::path::append(
Path,
"default_%m.profraw");
648 CmdArgs.push_back(
"-mllvm");
649 CmdArgs.push_back(Args.MakeArgString(
650 Twine(
"--instrument-cold-function-only-path=") +
Path));
651 CmdArgs.push_back(
"-mllvm");
652 CmdArgs.push_back(
"--pgo-instrument-cold-function-only");
653 CmdArgs.push_back(
"-mllvm");
654 CmdArgs.push_back(
"--pgo-function-entry-coverage");
657 Arg *PGOGenArg =
nullptr;
658 if (PGOGenerateArg) {
659 assert(!CSPGOGenerateArg);
660 PGOGenArg = PGOGenerateArg;
661 CmdArgs.push_back(
"-fprofile-instrument=llvm");
663 if (CSPGOGenerateArg) {
664 assert(!PGOGenerateArg);
665 PGOGenArg = CSPGOGenerateArg;
666 CmdArgs.push_back(
"-fprofile-instrument=csllvm");
669 if (TC.
getTriple().isWindowsMSVCEnvironment() &&
670 Args.hasFlag(options::OPT_frtlib_defaultlib,
671 options::OPT_fno_rtlib_defaultlib,
true)) {
673 CmdArgs.push_back(Args.MakeArgString(
676 if (PGOGenArg->getOption().matches(
677 PGOGenerateArg ? options::OPT_fprofile_generate_EQ
678 : options::OPT_fcs_profile_generate_EQ)) {
680 llvm::sys::path::append(
Path,
"default_%m.profraw");
682 Args.MakeArgString(Twine(
"-fprofile-instrument-path=") +
Path));
687 if (ProfileUseArg->getOption().matches(options::OPT_fprofile_instr_use_EQ))
688 CmdArgs.push_back(Args.MakeArgString(
689 Twine(
"-fprofile-instrument-use-path=") + ProfileUseArg->getValue()));
690 else if ((ProfileUseArg->getOption().matches(
691 options::OPT_fprofile_use_EQ) ||
692 ProfileUseArg->getOption().matches(
693 options::OPT_fprofile_instr_use))) {
695 ProfileUseArg->getNumValues() == 0 ?
"" : ProfileUseArg->getValue());
696 if (
Path.empty() || llvm::sys::fs::is_directory(
Path))
697 llvm::sys::path::append(
Path,
"default.profdata");
699 Args.MakeArgString(Twine(
"-fprofile-instrument-use-path=") +
Path));
703 bool EmitCovNotes = Args.hasFlag(options::OPT_ftest_coverage,
704 options::OPT_fno_test_coverage,
false) ||
705 Args.hasArg(options::OPT_coverage);
708 if (Args.hasFlag(options::OPT_fcoverage_mapping,
709 options::OPT_fno_coverage_mapping,
false)) {
710 if (!ProfileGenerateArg)
711 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
712 <<
"-fcoverage-mapping"
713 <<
"-fprofile-instr-generate";
715 CmdArgs.push_back(
"-fcoverage-mapping");
718 if (Args.hasFlag(options::OPT_fmcdc_coverage, options::OPT_fno_mcdc_coverage,
720 if (!Args.hasFlag(options::OPT_fcoverage_mapping,
721 options::OPT_fno_coverage_mapping,
false))
722 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
724 <<
"-fcoverage-mapping";
726 CmdArgs.push_back(
"-fcoverage-mcdc");
729 if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ,
730 options::OPT_fcoverage_compilation_dir_EQ)) {
731 if (A->getOption().matches(options::OPT_ffile_compilation_dir_EQ))
732 CmdArgs.push_back(Args.MakeArgString(
733 Twine(
"-fcoverage-compilation-dir=") + A->getValue()));
735 A->render(Args, CmdArgs);
736 }
else if (llvm::ErrorOr<std::string> CWD =
737 D.getVFS().getCurrentWorkingDirectory()) {
738 CmdArgs.push_back(Args.MakeArgString(
"-fcoverage-compilation-dir=" + *CWD));
741 if (Args.hasArg(options::OPT_fprofile_exclude_files_EQ)) {
742 auto *Arg = Args.getLastArg(options::OPT_fprofile_exclude_files_EQ);
743 if (!Args.hasArg(options::OPT_coverage))
744 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
745 <<
"-fprofile-exclude-files="
748 StringRef
v = Arg->getValue();
750 Args.MakeArgString(Twine(
"-fprofile-exclude-files=" +
v)));
753 if (Args.hasArg(options::OPT_fprofile_filter_files_EQ)) {
754 auto *Arg = Args.getLastArg(options::OPT_fprofile_filter_files_EQ);
755 if (!Args.hasArg(options::OPT_coverage))
756 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
757 <<
"-fprofile-filter-files="
760 StringRef
v = Arg->getValue();
761 CmdArgs.push_back(Args.MakeArgString(Twine(
"-fprofile-filter-files=" +
v)));
764 if (
const auto *A = Args.getLastArg(options::OPT_fprofile_update_EQ)) {
765 StringRef Val = A->getValue();
766 if (Val ==
"atomic" || Val ==
"prefer-atomic")
767 CmdArgs.push_back(
"-fprofile-update=atomic");
768 else if (Val !=
"single")
769 D.Diag(diag::err_drv_unsupported_option_argument)
770 << A->getSpelling() << Val;
773 int FunctionGroups = 1;
774 int SelectedFunctionGroup = 0;
775 if (
const auto *A = Args.getLastArg(options::OPT_fprofile_function_groups)) {
776 StringRef Val = A->getValue();
777 if (Val.getAsInteger(0, FunctionGroups) || FunctionGroups < 1)
778 D.Diag(diag::err_drv_invalid_int_value) << A->getAsString(Args) << Val;
781 Args.getLastArg(options::OPT_fprofile_selected_function_group)) {
782 StringRef Val = A->getValue();
783 if (Val.getAsInteger(0, SelectedFunctionGroup) ||
784 SelectedFunctionGroup < 0 || SelectedFunctionGroup >= FunctionGroups)
785 D.Diag(diag::err_drv_invalid_int_value) << A->getAsString(Args) << Val;
787 if (FunctionGroups != 1)
788 CmdArgs.push_back(Args.MakeArgString(
"-fprofile-function-groups=" +
789 Twine(FunctionGroups)));
790 if (SelectedFunctionGroup != 0)
791 CmdArgs.push_back(Args.MakeArgString(
"-fprofile-selected-function-group=" +
792 Twine(SelectedFunctionGroup)));
798 Arg *FProfileDir =
nullptr;
799 if (Args.hasArg(options::OPT_fprofile_arcs) ||
800 Args.hasArg(options::OPT_coverage))
801 FProfileDir = Args.getLastArg(options::OPT_fprofile_dir);
806 if (EmitCovNotes || EmitCovData) {
808 if (Arg *DumpDir = Args.getLastArgNoClaim(options::OPT_dumpdir)) {
811 CoverageFilename = DumpDir->getValue();
812 CoverageFilename += llvm::sys::path::filename(Output.
getBaseInput());
813 }
else if (Arg *FinalOutput =
814 C.getArgs().getLastArg(options::OPT__SLASH_Fo)) {
815 CoverageFilename = FinalOutput->getValue();
816 }
else if (Arg *FinalOutput =
C.getArgs().getLastArg(options::OPT_o)) {
817 CoverageFilename = FinalOutput->getValue();
819 CoverageFilename = llvm::sys::path::filename(Output.
getBaseInput());
821 if (llvm::sys::path::is_relative(CoverageFilename))
822 (void)
D.getVFS().makeAbsolute(CoverageFilename);
823 llvm::sys::path::replace_extension(CoverageFilename,
"gcno");
826 Args.MakeArgString(
"-coverage-notes-file=" + CoverageFilename));
832 CoverageFilename = FProfileDir->getValue();
833 llvm::sys::path::append(CoverageFilename, Gcno);
835 llvm::sys::path::replace_extension(CoverageFilename,
"gcda");
837 Args.MakeArgString(
"-coverage-data-file=" + CoverageFilename));
844 llvm::codegenoptions::DebugInfoKind DebugInfoKind,
845 unsigned DwarfVersion,
846 llvm::DebuggerKind DebuggerTuning) {
848 if (DwarfVersion > 0)
850 Args.MakeArgString(
"-dwarf-version=" + Twine(DwarfVersion)));
851 switch (DebuggerTuning) {
852 case llvm::DebuggerKind::GDB:
853 CmdArgs.push_back(
"-debugger-tuning=gdb");
855 case llvm::DebuggerKind::LLDB:
856 CmdArgs.push_back(
"-debugger-tuning=lldb");
858 case llvm::DebuggerKind::SCE:
859 CmdArgs.push_back(
"-debugger-tuning=sce");
861 case llvm::DebuggerKind::DBX:
862 CmdArgs.push_back(
"-debugger-tuning=dbx");
871 assert(A &&
"Expected non-nullptr argument.");
874 D.Diag(diag::warn_drv_unsupported_debug_info_opt_for_target)
880 ArgStringList &CmdArgs,
883 const Arg *A = Args.getLastArg(options::OPT_gz_EQ);
887 StringRef
Value = A->getValue();
888 if (
Value ==
"none") {
889 CmdArgs.push_back(
"--compress-debug-sections=none");
890 }
else if (
Value ==
"zlib") {
891 if (llvm::compression::zlib::isAvailable()) {
893 Args.MakeArgString(
"--compress-debug-sections=" + Twine(
Value)));
895 D.Diag(diag::warn_debug_compression_unavailable) <<
"zlib";
897 }
else if (
Value ==
"zstd") {
898 if (llvm::compression::zstd::isAvailable()) {
900 Args.MakeArgString(
"--compress-debug-sections=" + Twine(
Value)));
902 D.Diag(diag::warn_debug_compression_unavailable) <<
"zstd";
905 D.Diag(diag::err_drv_unsupported_option_argument)
906 << A->getSpelling() <<
Value;
913 ArgStringList &CmdArgs,
914 bool IsCC1As =
false) {
922 CmdArgs.insert(CmdArgs.begin() + 1,
923 Args.MakeArgString(Twine(
"--amdhsa-code-object-version=") +
925 CmdArgs.insert(CmdArgs.begin() + 1,
"-mllvm");
928 CmdArgs.insert(CmdArgs.begin() + 1,
929 Args.MakeArgString(Twine(
"-mcode-object-version=") +
935 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MemBuf =
936 D.getVFS().getBufferForFile(
Path);
939 llvm::file_magic Magic = llvm::identify_magic((*MemBuf)->getBuffer());
940 if (Magic == llvm::file_magic::unknown)
944 if (Magic == llvm::file_magic::clang_ast)
947 llvm::object::ObjectFile::createObjectFile(**MemBuf, Magic);
948 return !Obj.takeError();
952 llvm::ErrorOr<llvm::vfs::Status> Status =
D.getVFS().status(
Path);
956 if (Status->isDirectory()) {
958 for (llvm::vfs::directory_iterator DI =
D.getVFS().dir_begin(
Path, EC), DE;
959 !EC && DI != DE; DI = DI.increment(EC)) {
963 D.Diag(diag::warn_drv_pch_ignoring_gch_dir) <<
Path;
969 D.Diag(diag::warn_drv_pch_ignoring_gch_file) <<
Path;
974 const Driver &
D,
const ArgList &Args,
975 ArgStringList &CmdArgs,
982 Args.AddLastArg(CmdArgs, options::OPT_C);
983 Args.AddLastArg(CmdArgs, options::OPT_CC);
986 Arg *ArgM = Args.getLastArg(options::OPT_MM);
988 ArgM = Args.getLastArg(options::OPT_M);
989 Arg *ArgMD = Args.getLastArg(options::OPT_MMD);
991 ArgMD = Args.getLastArg(options::OPT_MD);
995 CmdArgs.push_back(
"-w");
1001 const char *DepFile;
1002 if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
1003 DepFile = MF->getValue();
1004 C.addFailureResultFile(DepFile, &JA);
1005 }
else if (Output.
getType() == types::TY_Dependencies) {
1007 }
else if (!ArgMD) {
1011 C.addFailureResultFile(DepFile, &JA);
1013 CmdArgs.push_back(
"-dependency-file");
1014 CmdArgs.push_back(DepFile);
1016 bool HasTarget =
false;
1017 for (
const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) {
1020 if (A->getOption().matches(options::OPT_MT)) {
1021 A->render(Args, CmdArgs);
1023 CmdArgs.push_back(
"-MT");
1026 CmdArgs.push_back(Args.MakeArgString(Quoted));
1032 const char *DepTarget;
1036 Arg *OutputOpt = Args.getLastArg(options::OPT_o, options::OPT__SLASH_Fo);
1037 if (OutputOpt && Output.
getType() != types::TY_Dependencies) {
1038 DepTarget = OutputOpt->getValue();
1044 llvm::sys::path::replace_extension(
P,
"o");
1045 DepTarget = Args.MakeArgString(llvm::sys::path::filename(
P));
1048 CmdArgs.push_back(
"-MT");
1051 CmdArgs.push_back(Args.MakeArgString(Quoted));
1054 if (ArgM->getOption().matches(options::OPT_M) ||
1055 ArgM->getOption().matches(options::OPT_MD))
1056 CmdArgs.push_back(
"-sys-header-deps");
1057 if ((isa<PrecompileJobAction>(JA) &&
1058 !Args.hasArg(options::OPT_fno_module_file_deps)) ||
1059 Args.hasArg(options::OPT_fmodule_file_deps))
1060 CmdArgs.push_back(
"-module-file-deps");
1063 if (Args.hasArg(options::OPT_MG)) {
1064 if (!ArgM || ArgM->getOption().matches(options::OPT_MD) ||
1065 ArgM->getOption().matches(options::OPT_MMD))
1066 D.Diag(diag::err_drv_mg_requires_m_or_mm);
1067 CmdArgs.push_back(
"-MG");
1070 Args.AddLastArg(CmdArgs, options::OPT_MP);
1071 Args.AddLastArg(CmdArgs, options::OPT_MV);
1085 !Args.hasArg(options::OPT_nostdinc) &&
1086 !Args.hasArg(options::OPT_nogpuinc) &&
1089 if (!Args.hasArg(options::OPT_nobuiltininc)) {
1093 llvm::sys::path::append(
P,
"include");
1094 llvm::sys::path::append(
P,
"openmp_wrappers");
1095 CmdArgs.push_back(
"-internal-isystem");
1096 CmdArgs.push_back(Args.MakeArgString(
P));
1099 CmdArgs.push_back(
"-include");
1100 CmdArgs.push_back(
"__clang_openmp_device_functions.h");
1103 if (Args.hasArg(options::OPT_foffload_via_llvm)) {
1107 llvm::sys::path::append(
P,
"include",
"llvm_offload_wrappers");
1108 CmdArgs.append({
"-internal-isystem", Args.MakeArgString(
P),
"-include"});
1110 CmdArgs.push_back(
"__llvm_offload_device.h");
1112 CmdArgs.push_back(
"__llvm_offload_host.h");
1122 const Arg *YcArg = Args.getLastArg(options::OPT__SLASH_Yc);
1123 const Arg *YuArg = Args.getLastArg(options::OPT__SLASH_Yu);
1126 CmdArgs.push_back(Args.MakeArgString(
"-building-pch-with-obj"));
1129 if (Args.hasFlag(options::OPT_fpch_instantiate_templates,
1130 options::OPT_fno_pch_instantiate_templates,
true))
1131 CmdArgs.push_back(Args.MakeArgString(
"-fpch-instantiate-templates"));
1133 if (YcArg || YuArg) {
1134 StringRef ThroughHeader = YcArg ? YcArg->getValue() : YuArg->getValue();
1135 if (!isa<PrecompileJobAction>(JA)) {
1136 CmdArgs.push_back(
"-include-pch");
1137 CmdArgs.push_back(Args.MakeArgString(
D.GetClPchPath(
1138 C, !ThroughHeader.empty()
1140 : llvm::sys::path::filename(Inputs[0].getBaseInput()))));
1143 if (ThroughHeader.empty()) {
1144 CmdArgs.push_back(Args.MakeArgString(
1145 Twine(
"-pch-through-hdrstop-") + (YcArg ?
"create" :
"use")));
1148 Args.MakeArgString(Twine(
"-pch-through-header=") + ThroughHeader));
1153 bool RenderedImplicitInclude =
false;
1154 for (
const Arg *A : Args.filtered(options::OPT_clang_i_Group)) {
1155 if (A->getOption().matches(options::OPT_include) &&
1156 D.getProbePrecompiled()) {
1158 bool IsFirstImplicitInclude = !RenderedImplicitInclude;
1159 RenderedImplicitInclude =
true;
1161 bool FoundPCH =
false;
1166 llvm::sys::path::replace_extension(
P,
"pch");
1167 if (
D.getVFS().exists(
P))
1172 llvm::sys::path::replace_extension(
P,
"gch");
1177 if (IsFirstImplicitInclude) {
1179 CmdArgs.push_back(
"-include-pch");
1180 CmdArgs.push_back(Args.MakeArgString(
P));
1184 D.Diag(diag::warn_drv_pch_not_first_include) <<
P
1185 << A->getAsString(Args);
1188 }
else if (A->getOption().matches(options::OPT_isystem_after)) {
1195 }
else if (A->getOption().matches(options::OPT_stdlibxx_isystem)) {
1198 }
else if (A->getOption().matches(options::OPT_ibuiltininc)) {
1205 A->render(Args, CmdArgs);
1208 Args.addAllArgs(CmdArgs,
1209 {options::OPT_D, options::OPT_U, options::OPT_I_Group,
1210 options::OPT_F, options::OPT_embed_dir_EQ});
1218 Args.AddAllArgValues(CmdArgs, options::OPT_Wp_COMMA,
1219 options::OPT_Xpreprocessor);
1222 if (Arg *A = Args.getLastArg(options::OPT_I_))
1223 D.Diag(diag::err_drv_I_dash_not_supported) << A->getAsString(Args);
1227 StringRef sysroot =
C.getSysRoot();
1228 if (sysroot !=
"") {
1229 if (!Args.hasArg(options::OPT_isysroot)) {
1230 CmdArgs.push_back(
"-isysroot");
1231 CmdArgs.push_back(
C.getArgs().MakeArgString(sysroot));
1248 addDirectoryList(Args, CmdArgs,
"-objcxx-isystem",
"OBJCPLUS_INCLUDE_PATH");
1256 bool HasStdlibxxIsystem = Args.hasArg(options::OPT_stdlibxx_isystem);
1259 [&Args, &CmdArgs, HasStdlibxxIsystem](
const ToolChain &TC) {
1269 if (!Args.hasArg(options::OPT_nostdinc) &&
1270 !Args.hasArg(options::OPT_nogpuinc) &&
1271 !Args.hasArg(options::OPT_nobuiltininc)) {
1279 llvm::sys::path::append(
P,
"include");
1280 llvm::sys::path::append(
P,
getToolChain().getTripleString());
1281 CmdArgs.push_back(
"-internal-isystem");
1282 CmdArgs.push_back(Args.MakeArgString(
P));
1287 llvm::sys::path::append(
P,
"include");
1288 llvm::sys::path::append(
P,
"llvm_libc_wrappers");
1289 CmdArgs.push_back(
"-internal-isystem");
1290 CmdArgs.push_back(Args.MakeArgString(
P));
1297 [&Args, &CmdArgs](
const ToolChain &TC) {
1308 Args.AddLastArg(CmdArgs, options::OPT_ffile_reproducible,
1309 options::OPT_fno_file_reproducible);
1311 if (
const char *Epoch = std::getenv(
"SOURCE_DATE_EPOCH")) {
1312 CmdArgs.push_back(
"-source-date-epoch");
1313 CmdArgs.push_back(Args.MakeArgString(Epoch));
1316 Args.addOptInFlag(CmdArgs, options::OPT_fdefine_target_os_macros,
1317 options::OPT_fno_define_target_os_macros);
1322 switch (Triple.getArch()) {
1326 case llvm::Triple::aarch64:
1327 case llvm::Triple::aarch64_32:
1328 case llvm::Triple::aarch64_be:
1329 case llvm::Triple::arm:
1330 case llvm::Triple::armeb:
1331 case llvm::Triple::thumb:
1332 case llvm::Triple::thumbeb:
1333 if (Triple.isOSDarwin() || Triple.isOSWindows())
1337 case llvm::Triple::ppc:
1338 case llvm::Triple::ppc64:
1339 if (Triple.isOSDarwin())
1343 case llvm::Triple::hexagon:
1344 case llvm::Triple::msp430:
1345 case llvm::Triple::ppcle:
1346 case llvm::Triple::ppc64le:
1347 case llvm::Triple::riscv32:
1348 case llvm::Triple::riscv64:
1349 case llvm::Triple::systemz:
1350 case llvm::Triple::xcore:
1351 case llvm::Triple::xtensa:
1357 const ArgList &Args) {
1360 if (!Triple.isOSDarwin())
1364 return Args.getAllArgValues(options::OPT_arch).size() > 1;
1368 const llvm::Triple &Triple) {
1373 bool hasExplicitOutputFile =
1374 Args.getLastArg(options::OPT_foptimization_record_file_EQ);
1376 D.Diag(diag::err_drv_invalid_output_with_multiple_archs)
1377 <<
"-foptimization-record-file";
1384 const llvm::Triple &Triple,
1387 StringRef Format =
"yaml";
1388 if (
const Arg *A = Args.getLastArg(options::OPT_fsave_optimization_record_EQ))
1389 Format = A->getValue();
1391 CmdArgs.push_back(
"-opt-record-file");
1393 const Arg *A = Args.getLastArg(options::OPT_foptimization_record_file_EQ);
1395 CmdArgs.push_back(A->getValue());
1397 bool hasMultipleArchs =
1398 Triple.isOSDarwin() &&
1399 Args.getAllArgValues(options::OPT_arch).size() > 1;
1403 if (Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)) {
1404 if (Arg *FinalOutput = Args.getLastArg(options::OPT_o))
1405 F = FinalOutput->getValue();
1407 if (Format !=
"yaml" &&
1408 Triple.isOSDarwin() &&
1422 llvm::sys::path::replace_extension(F,
"");
1424 Triple.normalize());
1434 if (hasMultipleArchs) {
1438 llvm::sys::path::replace_extension(F,
"");
1441 F += Triple.getArchName();
1443 llvm::sys::path::replace_extension(F, OldExtension);
1447 Extension +=
"opt.";
1448 Extension += Format;
1450 llvm::sys::path::replace_extension(F, Extension);
1451 CmdArgs.push_back(Args.MakeArgString(F));
1455 Args.getLastArg(options::OPT_foptimization_record_passes_EQ)) {
1456 CmdArgs.push_back(
"-opt-record-passes");
1457 CmdArgs.push_back(A->getValue());
1460 if (!Format.empty()) {
1461 CmdArgs.push_back(
"-opt-record-format");
1462 CmdArgs.push_back(Format.data());
1467 if (!Args.hasFlag(options::OPT_faapcs_bitfield_width,
1468 options::OPT_fno_aapcs_bitfield_width,
true))
1469 CmdArgs.push_back(
"-fno-aapcs-bitfield-width");
1471 if (Args.getLastArg(options::OPT_ForceAAPCSBitfieldLoad))
1472 CmdArgs.push_back(
"-faapcs-bitfield-load");
1476void RenderARMABI(
const Driver &
D,
const llvm::Triple &Triple,
1477 const ArgList &Args, ArgStringList &CmdArgs) {
1481 const char *ABIName =
nullptr;
1482 if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
1483 ABIName = A->getValue();
1485 std::string CPU =
getCPUName(
D, Args, Triple,
false);
1486 ABIName = llvm::ARM::computeDefaultTargetABI(Triple, CPU).data();
1489 CmdArgs.push_back(
"-target-abi");
1490 CmdArgs.push_back(ABIName);
1493void AddUnalignedAccessWarning(ArgStringList &CmdArgs) {
1494 auto StrictAlignIter =
1495 llvm::find_if(llvm::reverse(CmdArgs), [](StringRef Arg) {
1496 return Arg ==
"+strict-align" || Arg ==
"-strict-align";
1498 if (StrictAlignIter != CmdArgs.rend() &&
1499 StringRef(*StrictAlignIter) ==
"+strict-align")
1500 CmdArgs.push_back(
"-Wunaligned-access");
1508 if (!DriverArgs.hasArg(options::OPT_fptrauth_intrinsics,
1509 options::OPT_fno_ptrauth_intrinsics))
1510 CC1Args.push_back(
"-fptrauth-intrinsics");
1512 if (!DriverArgs.hasArg(options::OPT_fptrauth_calls,
1513 options::OPT_fno_ptrauth_calls))
1514 CC1Args.push_back(
"-fptrauth-calls");
1516 if (!DriverArgs.hasArg(options::OPT_fptrauth_returns,
1517 options::OPT_fno_ptrauth_returns))
1518 CC1Args.push_back(
"-fptrauth-returns");
1520 if (!DriverArgs.hasArg(options::OPT_fptrauth_auth_traps,
1521 options::OPT_fno_ptrauth_auth_traps))
1522 CC1Args.push_back(
"-fptrauth-auth-traps");
1524 if (!DriverArgs.hasArg(
1525 options::OPT_fptrauth_vtable_pointer_address_discrimination,
1526 options::OPT_fno_ptrauth_vtable_pointer_address_discrimination))
1527 CC1Args.push_back(
"-fptrauth-vtable-pointer-address-discrimination");
1529 if (!DriverArgs.hasArg(
1530 options::OPT_fptrauth_vtable_pointer_type_discrimination,
1531 options::OPT_fno_ptrauth_vtable_pointer_type_discrimination))
1532 CC1Args.push_back(
"-fptrauth-vtable-pointer-type-discrimination");
1534 if (!DriverArgs.hasArg(options::OPT_fptrauth_indirect_gotos,
1535 options::OPT_fno_ptrauth_indirect_gotos))
1536 CC1Args.push_back(
"-fptrauth-indirect-gotos");
1538 if (!DriverArgs.hasArg(options::OPT_fptrauth_init_fini,
1539 options::OPT_fno_ptrauth_init_fini))
1540 CC1Args.push_back(
"-fptrauth-init-fini");
1544 ArgStringList &CmdArgs,
bool isAArch64) {
1545 const Arg *A = isAArch64
1546 ? Args.getLastArg(options::OPT_msign_return_address_EQ,
1547 options::OPT_mbranch_protection_EQ)
1548 : Args.getLastArg(options::OPT_mbranch_protection_EQ);
1554 if (!(isAArch64 || (Triple.isArmT32() && Triple.isArmMClass())))
1555 D.Diag(diag::warn_incompatible_branch_protection_option)
1556 << Triple.getArchName();
1558 StringRef
Scope, Key;
1559 bool IndirectBranches, BranchProtectionPAuthLR, GuardedControlStack;
1561 if (A->getOption().matches(options::OPT_msign_return_address_EQ)) {
1562 Scope = A->getValue();
1564 D.Diag(diag::err_drv_unsupported_option_argument)
1565 << A->getSpelling() <<
Scope;
1567 IndirectBranches =
false;
1568 BranchProtectionPAuthLR =
false;
1569 GuardedControlStack =
false;
1572 llvm::ARM::ParsedBranchProtection PBP;
1573 bool EnablePAuthLR =
false;
1580 auto isPAuthLR = [](
const char *member) {
1581 llvm::AArch64::ExtensionInfo pauthlr_extension =
1582 llvm::AArch64::getExtensionByID(llvm::AArch64::AEK_PAUTHLR);
1583 return pauthlr_extension.PosTargetFeature == member;
1586 if (std::any_of(CmdArgs.begin(), CmdArgs.end(), isPAuthLR))
1587 EnablePAuthLR =
true;
1589 if (!llvm::ARM::parseBranchProtection(A->getValue(), PBP, DiagMsg,
1591 D.Diag(diag::err_drv_unsupported_option_argument)
1592 << A->getSpelling() << DiagMsg;
1593 if (!isAArch64 && PBP.Key ==
"b_key")
1594 D.Diag(diag::warn_unsupported_branch_protection)
1595 <<
"b-key" << A->getAsString(Args);
1598 BranchProtectionPAuthLR = PBP.BranchProtectionPAuthLR;
1599 IndirectBranches = PBP.BranchTargetEnforcement;
1600 GuardedControlStack = PBP.GuardedControlStack;
1604 Args.MakeArgString(Twine(
"-msign-return-address=") +
Scope));
1605 if (
Scope !=
"none") {
1606 if (Triple.getEnvironment() == llvm::Triple::PAuthTest)
1607 D.Diag(diag::err_drv_unsupported_opt_for_target)
1608 << A->getAsString(Args) << Triple.getTriple();
1610 Args.MakeArgString(Twine(
"-msign-return-address-key=") + Key));
1612 if (BranchProtectionPAuthLR) {
1613 if (Triple.getEnvironment() == llvm::Triple::PAuthTest)
1614 D.Diag(diag::err_drv_unsupported_opt_for_target)
1615 << A->getAsString(Args) << Triple.getTriple();
1617 Args.MakeArgString(Twine(
"-mbranch-protection-pauth-lr")));
1619 if (IndirectBranches)
1620 CmdArgs.push_back(
"-mbranch-target-enforce");
1623 if (GuardedControlStack) {
1624 if (Triple.getEnvironment() == llvm::Triple::PAuthTest)
1625 D.Diag(diag::err_drv_unsupported_opt_for_target)
1626 << A->getAsString(Args) << Triple.getTriple();
1627 CmdArgs.push_back(
"-mguarded-control-stack");
1631void Clang::AddARMTargetArgs(
const llvm::Triple &Triple,
const ArgList &Args,
1632 ArgStringList &CmdArgs,
bool KernelOrKext)
const {
1633 RenderARMABI(
getToolChain().getDriver(), Triple, Args, CmdArgs);
1640 CmdArgs.push_back(
"-msoft-float");
1641 CmdArgs.push_back(
"-mfloat-abi");
1642 CmdArgs.push_back(
"soft");
1645 CmdArgs.push_back(
"-mfloat-abi");
1646 CmdArgs.push_back(
"soft");
1650 CmdArgs.push_back(
"-mfloat-abi");
1651 CmdArgs.push_back(
"hard");
1655 if (Arg *A = Args.getLastArg(options::OPT_mglobal_merge,
1656 options::OPT_mno_global_merge)) {
1657 CmdArgs.push_back(
"-mllvm");
1658 if (A->getOption().matches(options::OPT_mno_global_merge))
1659 CmdArgs.push_back(
"-arm-global-merge=false");
1661 CmdArgs.push_back(
"-arm-global-merge=true");
1664 if (!Args.hasFlag(options::OPT_mimplicit_float,
1665 options::OPT_mno_implicit_float,
true))
1666 CmdArgs.push_back(
"-no-implicit-float");
1668 if (Args.getLastArg(options::OPT_mcmse))
1669 CmdArgs.push_back(
"-mcmse");
1676 AddUnalignedAccessWarning(CmdArgs);
1679void Clang::RenderTargetOptions(
const llvm::Triple &EffectiveTriple,
1680 const ArgList &Args,
bool KernelOrKext,
1681 ArgStringList &CmdArgs)
const {
1692 case llvm::Triple::arm:
1693 case llvm::Triple::armeb:
1694 case llvm::Triple::thumb:
1695 case llvm::Triple::thumbeb:
1697 AddARMTargetArgs(EffectiveTriple, Args, CmdArgs, KernelOrKext);
1700 case llvm::Triple::aarch64:
1701 case llvm::Triple::aarch64_32:
1702 case llvm::Triple::aarch64_be:
1703 AddAArch64TargetArgs(Args, CmdArgs);
1706 case llvm::Triple::loongarch32:
1707 case llvm::Triple::loongarch64:
1708 AddLoongArchTargetArgs(Args, CmdArgs);
1711 case llvm::Triple::mips:
1712 case llvm::Triple::mipsel:
1713 case llvm::Triple::mips64:
1714 case llvm::Triple::mips64el:
1715 AddMIPSTargetArgs(Args, CmdArgs);
1718 case llvm::Triple::ppc:
1719 case llvm::Triple::ppcle:
1720 case llvm::Triple::ppc64:
1721 case llvm::Triple::ppc64le:
1722 AddPPCTargetArgs(Args, CmdArgs);
1725 case llvm::Triple::riscv32:
1726 case llvm::Triple::riscv64:
1727 AddRISCVTargetArgs(Args, CmdArgs);
1730 case llvm::Triple::sparc:
1731 case llvm::Triple::sparcel:
1732 case llvm::Triple::sparcv9:
1733 AddSparcTargetArgs(Args, CmdArgs);
1736 case llvm::Triple::systemz:
1737 AddSystemZTargetArgs(Args, CmdArgs);
1740 case llvm::Triple::x86:
1741 case llvm::Triple::x86_64:
1742 AddX86TargetArgs(Args, CmdArgs);
1745 case llvm::Triple::lanai:
1746 AddLanaiTargetArgs(Args, CmdArgs);
1749 case llvm::Triple::hexagon:
1750 AddHexagonTargetArgs(Args, CmdArgs);
1753 case llvm::Triple::wasm32:
1754 case llvm::Triple::wasm64:
1755 AddWebAssemblyTargetArgs(Args, CmdArgs);
1758 case llvm::Triple::ve:
1759 AddVETargetArgs(Args, CmdArgs);
1765void RenderAArch64ABI(
const llvm::Triple &Triple,
const ArgList &Args,
1766 ArgStringList &CmdArgs) {
1767 const char *ABIName =
nullptr;
1768 if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
1769 ABIName = A->getValue();
1770 else if (Triple.isOSDarwin())
1771 ABIName =
"darwinpcs";
1772 else if (Triple.getEnvironment() == llvm::Triple::PAuthTest)
1773 ABIName =
"pauthtest";
1777 CmdArgs.push_back(
"-target-abi");
1778 CmdArgs.push_back(ABIName);
1782void Clang::AddAArch64TargetArgs(
const ArgList &Args,
1783 ArgStringList &CmdArgs)
const {
1786 if (!Args.hasFlag(options::OPT_mred_zone, options::OPT_mno_red_zone,
true) ||
1787 Args.hasArg(options::OPT_mkernel) ||
1788 Args.hasArg(options::OPT_fapple_kext))
1789 CmdArgs.push_back(
"-disable-red-zone");
1791 if (!Args.hasFlag(options::OPT_mimplicit_float,
1792 options::OPT_mno_implicit_float,
true))
1793 CmdArgs.push_back(
"-no-implicit-float");
1795 RenderAArch64ABI(Triple, Args, CmdArgs);
1798 if (Arg *A = Args.getLastArg(options::OPT_mglobal_merge,
1799 options::OPT_mno_global_merge)) {
1800 CmdArgs.push_back(
"-mllvm");
1801 if (A->getOption().matches(options::OPT_mno_global_merge))
1802 CmdArgs.push_back(
"-aarch64-enable-global-merge=false");
1804 CmdArgs.push_back(
"-aarch64-enable-global-merge=true");
1810 if (Triple.getEnvironment() == llvm::Triple::PAuthTest)
1814 if (Arg *A = Args.getLastArg(options::OPT_msve_vector_bits_EQ)) {
1815 StringRef Val = A->getValue();
1817 if (Val ==
"128" || Val ==
"256" || Val ==
"512" || Val ==
"1024" ||
1818 Val ==
"2048" || Val ==
"128+" || Val ==
"256+" || Val ==
"512+" ||
1819 Val ==
"1024+" || Val ==
"2048+") {
1821 if (!Val.consume_back(
"+")) {
1823 assert(!
Invalid &&
"Failed to parse value");
1825 Args.MakeArgString(
"-mvscale-max=" + llvm::Twine(Bits / 128)));
1829 assert(!
Invalid &&
"Failed to parse value");
1831 Args.MakeArgString(
"-mvscale-min=" + llvm::Twine(Bits / 128)));
1833 }
else if (Val !=
"scalable")
1835 D.Diag(diag::err_drv_unsupported_option_argument)
1836 << A->getSpelling() << Val;
1841 if (
const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
1842 CmdArgs.push_back(
"-tune-cpu");
1843 if (strcmp(A->getValue(),
"native") == 0)
1844 CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
1846 CmdArgs.push_back(A->getValue());
1849 AddUnalignedAccessWarning(CmdArgs);
1851 Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_intrinsics,
1852 options::OPT_fno_ptrauth_intrinsics);
1853 Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_calls,
1854 options::OPT_fno_ptrauth_calls);
1855 Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_returns,
1856 options::OPT_fno_ptrauth_returns);
1857 Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_auth_traps,
1858 options::OPT_fno_ptrauth_auth_traps);
1860 CmdArgs, options::OPT_fptrauth_vtable_pointer_address_discrimination,
1861 options::OPT_fno_ptrauth_vtable_pointer_address_discrimination);
1863 CmdArgs, options::OPT_fptrauth_vtable_pointer_type_discrimination,
1864 options::OPT_fno_ptrauth_vtable_pointer_type_discrimination);
1866 CmdArgs, options::OPT_fptrauth_type_info_vtable_pointer_discrimination,
1867 options::OPT_fno_ptrauth_type_info_vtable_pointer_discrimination);
1869 CmdArgs, options::OPT_fptrauth_function_pointer_type_discrimination,
1870 options::OPT_fno_ptrauth_function_pointer_type_discrimination);
1872 Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_indirect_gotos,
1873 options::OPT_fno_ptrauth_indirect_gotos);
1874 Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_init_fini,
1875 options::OPT_fno_ptrauth_init_fini);
1876 Args.addOptInFlag(CmdArgs,
1877 options::OPT_fptrauth_init_fini_address_discrimination,
1878 options::OPT_fno_ptrauth_init_fini_address_discrimination);
1879 Args.addOptInFlag(CmdArgs, options::OPT_faarch64_jump_table_hardening,
1880 options::OPT_fno_aarch64_jump_table_hardening);
1883void Clang::AddLoongArchTargetArgs(
const ArgList &Args,
1884 ArgStringList &CmdArgs)
const {
1887 CmdArgs.push_back(
"-target-abi");
1893 if (
const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
1894 std::string TuneCPU = A->getValue();
1896 CmdArgs.push_back(
"-tune-cpu");
1897 CmdArgs.push_back(Args.MakeArgString(TuneCPU));
1900 if (Arg *A = Args.getLastArg(options::OPT_mannotate_tablejump,
1901 options::OPT_mno_annotate_tablejump)) {
1902 if (A->getOption().matches(options::OPT_mannotate_tablejump)) {
1903 CmdArgs.push_back(
"-mllvm");
1904 CmdArgs.push_back(
"-loongarch-annotate-tablejump");
1909void Clang::AddMIPSTargetArgs(
const ArgList &Args,
1910 ArgStringList &CmdArgs)
const {
1917 CmdArgs.push_back(
"-target-abi");
1918 CmdArgs.push_back(ABIName.data());
1923 CmdArgs.push_back(
"-msoft-float");
1924 CmdArgs.push_back(
"-mfloat-abi");
1925 CmdArgs.push_back(
"soft");
1929 CmdArgs.push_back(
"-mfloat-abi");
1930 CmdArgs.push_back(
"hard");
1933 if (Arg *A = Args.getLastArg(options::OPT_mldc1_sdc1,
1934 options::OPT_mno_ldc1_sdc1)) {
1935 if (A->getOption().matches(options::OPT_mno_ldc1_sdc1)) {
1936 CmdArgs.push_back(
"-mllvm");
1937 CmdArgs.push_back(
"-mno-ldc1-sdc1");
1941 if (Arg *A = Args.getLastArg(options::OPT_mcheck_zero_division,
1942 options::OPT_mno_check_zero_division)) {
1943 if (A->getOption().matches(options::OPT_mno_check_zero_division)) {
1944 CmdArgs.push_back(
"-mllvm");
1945 CmdArgs.push_back(
"-mno-check-zero-division");
1949 if (Args.getLastArg(options::OPT_mfix4300)) {
1950 CmdArgs.push_back(
"-mllvm");
1951 CmdArgs.push_back(
"-mfix4300");
1954 if (Arg *A = Args.getLastArg(options::OPT_G)) {
1955 StringRef
v = A->getValue();
1956 CmdArgs.push_back(
"-mllvm");
1957 CmdArgs.push_back(Args.MakeArgString(
"-mips-ssection-threshold=" +
v));
1961 Arg *GPOpt = Args.getLastArg(options::OPT_mgpopt, options::OPT_mno_gpopt);
1963 Args.getLastArg(options::OPT_mabicalls, options::OPT_mno_abicalls);
1976 ABICalls && ABICalls->getOption().matches(options::OPT_mno_abicalls);
1978 llvm::Reloc::Model RelocationModel;
1981 std::tie(RelocationModel, PICLevel, IsPIE) =
1984 NoABICalls = NoABICalls ||
1985 (RelocationModel == llvm::Reloc::Static && ABIName ==
"n64");
1987 bool WantGPOpt = GPOpt && GPOpt->getOption().matches(options::OPT_mgpopt);
1989 if (NoABICalls && (!GPOpt || WantGPOpt)) {
1990 CmdArgs.push_back(
"-mllvm");
1991 CmdArgs.push_back(
"-mgpopt");
1993 Arg *LocalSData = Args.getLastArg(options::OPT_mlocal_sdata,
1994 options::OPT_mno_local_sdata);
1995 Arg *ExternSData = Args.getLastArg(options::OPT_mextern_sdata,
1996 options::OPT_mno_extern_sdata);
1997 Arg *EmbeddedData = Args.getLastArg(options::OPT_membedded_data,
1998 options::OPT_mno_embedded_data);
2000 CmdArgs.push_back(
"-mllvm");
2001 if (LocalSData->getOption().matches(options::OPT_mlocal_sdata)) {
2002 CmdArgs.push_back(
"-mlocal-sdata=1");
2004 CmdArgs.push_back(
"-mlocal-sdata=0");
2006 LocalSData->claim();
2010 CmdArgs.push_back(
"-mllvm");
2011 if (ExternSData->getOption().matches(options::OPT_mextern_sdata)) {
2012 CmdArgs.push_back(
"-mextern-sdata=1");
2014 CmdArgs.push_back(
"-mextern-sdata=0");
2016 ExternSData->claim();
2020 CmdArgs.push_back(
"-mllvm");
2021 if (EmbeddedData->getOption().matches(options::OPT_membedded_data)) {
2022 CmdArgs.push_back(
"-membedded-data=1");
2024 CmdArgs.push_back(
"-membedded-data=0");
2026 EmbeddedData->claim();
2029 }
else if ((!ABICalls || (!NoABICalls && ABICalls)) && WantGPOpt)
2030 D.Diag(diag::warn_drv_unsupported_gpopt) << (ABICalls ? 0 : 1);
2035 if (Arg *A = Args.getLastArg(options::OPT_mcompact_branches_EQ)) {
2036 StringRef Val = StringRef(A->getValue());
2038 if (Val ==
"never" || Val ==
"always" || Val ==
"optimal") {
2039 CmdArgs.push_back(
"-mllvm");
2040 CmdArgs.push_back(Args.MakeArgString(
"-mips-compact-branches=" + Val));
2042 D.Diag(diag::err_drv_unsupported_option_argument)
2043 << A->getSpelling() << Val;
2045 D.Diag(diag::warn_target_unsupported_compact_branches) << CPUName;
2048 if (Arg *A = Args.getLastArg(options::OPT_mrelax_pic_calls,
2049 options::OPT_mno_relax_pic_calls)) {
2050 if (A->getOption().matches(options::OPT_mno_relax_pic_calls)) {
2051 CmdArgs.push_back(
"-mllvm");
2052 CmdArgs.push_back(
"-mips-jalr-reloc=0");
2057void Clang::AddPPCTargetArgs(
const ArgList &Args,
2058 ArgStringList &CmdArgs)
const {
2061 if (Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
2062 CmdArgs.push_back(
"-tune-cpu");
2063 StringRef CPU = llvm::PPC::getNormalizedPPCTuneCPU(
T, A->getValue());
2064 CmdArgs.push_back(Args.MakeArgString(CPU.str()));
2068 const char *ABIName =
nullptr;
2069 if (
T.isOSBinFormatELF()) {
2071 case llvm::Triple::ppc64: {
2072 if (
T.isPPC64ELFv2ABI())
2078 case llvm::Triple::ppc64le:
2087 bool VecExtabi =
false;
2088 for (
const Arg *A : Args.filtered(options::OPT_mabi_EQ)) {
2089 StringRef
V = A->getValue();
2090 if (
V ==
"ieeelongdouble") {
2091 IEEELongDouble =
true;
2093 }
else if (
V ==
"ibmlongdouble") {
2094 IEEELongDouble =
false;
2096 }
else if (
V ==
"vec-default") {
2099 }
else if (
V ==
"vec-extabi") {
2102 }
else if (
V ==
"elfv1") {
2105 }
else if (
V ==
"elfv2") {
2108 }
else if (
V !=
"altivec")
2112 ABIName = A->getValue();
2115 CmdArgs.push_back(
"-mabi=ieeelongdouble");
2118 D.Diag(diag::err_drv_unsupported_opt_for_target)
2119 <<
"-mabi=vec-extabi" <<
T.str();
2120 CmdArgs.push_back(
"-mabi=vec-extabi");
2123 if (!Args.hasFlag(options::OPT_mred_zone, options::OPT_mno_red_zone,
true))
2124 CmdArgs.push_back(
"-disable-red-zone");
2129 CmdArgs.push_back(
"-msoft-float");
2130 CmdArgs.push_back(
"-mfloat-abi");
2131 CmdArgs.push_back(
"soft");
2135 CmdArgs.push_back(
"-mfloat-abi");
2136 CmdArgs.push_back(
"hard");
2140 CmdArgs.push_back(
"-target-abi");
2141 CmdArgs.push_back(ABIName);
2145void Clang::AddRISCVTargetArgs(
const ArgList &Args,
2146 ArgStringList &CmdArgs)
const {
2150 CmdArgs.push_back(
"-target-abi");
2151 CmdArgs.push_back(ABIName.data());
2153 if (Arg *A = Args.getLastArg(options::OPT_G)) {
2154 CmdArgs.push_back(
"-msmall-data-limit");
2155 CmdArgs.push_back(A->getValue());
2158 if (!Args.hasFlag(options::OPT_mimplicit_float,
2159 options::OPT_mno_implicit_float,
true))
2160 CmdArgs.push_back(
"-no-implicit-float");
2162 if (
const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
2163 CmdArgs.push_back(
"-tune-cpu");
2164 if (strcmp(A->getValue(),
"native") == 0)
2165 CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
2167 CmdArgs.push_back(A->getValue());
2171 if (Arg *A = Args.getLastArg(options::OPT_mrvv_vector_bits_EQ)) {
2172 StringRef Val = A->getValue();
2176 unsigned MinVLen = 0;
2178 auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
2181 if (!errorToBool(ISAInfo.takeError()))
2182 MinVLen = (*ISAInfo)->getMinVLen();
2187 if (Val ==
"zvl" && MinVLen >= llvm::RISCV::RVVBitsPerBlock) {
2189 }
else if (!Val.getAsInteger(10, Bits)) {
2192 if (Bits < MinVLen || Bits < llvm::RISCV::RVVBitsPerBlock ||
2193 Bits > 65536 || !llvm::isPowerOf2_32(Bits))
2199 unsigned VScaleMin = Bits / llvm::RISCV::RVVBitsPerBlock;
2201 Args.MakeArgString(
"-mvscale-max=" + llvm::Twine(VScaleMin)));
2203 Args.MakeArgString(
"-mvscale-min=" + llvm::Twine(VScaleMin)));
2204 }
else if (Val !=
"scalable") {
2206 D.Diag(diag::err_drv_unsupported_option_argument)
2207 << A->getSpelling() << Val;
2212void Clang::AddSparcTargetArgs(
const ArgList &Args,
2213 ArgStringList &CmdArgs)
const {
2219 CmdArgs.push_back(
"-msoft-float");
2220 CmdArgs.push_back(
"-mfloat-abi");
2221 CmdArgs.push_back(
"soft");
2225 CmdArgs.push_back(
"-mfloat-abi");
2226 CmdArgs.push_back(
"hard");
2229 if (
const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
2230 StringRef Name = A->getValue();
2231 std::string TuneCPU;
2232 if (Name ==
"native")
2233 TuneCPU = std::string(llvm::sys::getHostCPUName());
2235 TuneCPU = std::string(Name);
2237 CmdArgs.push_back(
"-tune-cpu");
2238 CmdArgs.push_back(Args.MakeArgString(TuneCPU));
2242void Clang::AddSystemZTargetArgs(
const ArgList &Args,
2243 ArgStringList &CmdArgs)
const {
2244 if (
const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
2245 CmdArgs.push_back(
"-tune-cpu");
2246 if (strcmp(A->getValue(),
"native") == 0)
2247 CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
2249 CmdArgs.push_back(A->getValue());
2253 Args.hasFlag(options::OPT_mbackchain, options::OPT_mno_backchain,
false);
2254 bool HasPackedStack = Args.hasFlag(options::OPT_mpacked_stack,
2255 options::OPT_mno_packed_stack,
false);
2259 if (HasBackchain && HasPackedStack && !HasSoftFloat) {
2261 D.Diag(diag::err_drv_unsupported_opt)
2262 <<
"-mpacked-stack -mbackchain -mhard-float";
2265 CmdArgs.push_back(
"-mbackchain");
2267 CmdArgs.push_back(
"-mpacked-stack");
2270 CmdArgs.push_back(
"-msoft-float");
2271 CmdArgs.push_back(
"-mfloat-abi");
2272 CmdArgs.push_back(
"soft");
2276void Clang::AddX86TargetArgs(
const ArgList &Args,
2277 ArgStringList &CmdArgs)
const {
2281 if (!Args.hasFlag(options::OPT_mred_zone, options::OPT_mno_red_zone,
true) ||
2282 Args.hasArg(options::OPT_mkernel) ||
2283 Args.hasArg(options::OPT_fapple_kext))
2284 CmdArgs.push_back(
"-disable-red-zone");
2286 if (!Args.hasFlag(options::OPT_mtls_direct_seg_refs,
2287 options::OPT_mno_tls_direct_seg_refs,
true))
2288 CmdArgs.push_back(
"-mno-tls-direct-seg-refs");
2292 bool NoImplicitFloat = (Args.hasArg(options::OPT_mkernel) ||
2293 Args.hasArg(options::OPT_fapple_kext));
2294 if (Arg *A = Args.getLastArg(
2295 options::OPT_msoft_float, options::OPT_mno_soft_float,
2296 options::OPT_mimplicit_float, options::OPT_mno_implicit_float)) {
2297 const Option &O = A->getOption();
2298 NoImplicitFloat = (O.matches(options::OPT_mno_implicit_float) ||
2299 O.matches(options::OPT_msoft_float));
2301 if (NoImplicitFloat)
2302 CmdArgs.push_back(
"-no-implicit-float");
2304 if (Arg *A = Args.getLastArg(options::OPT_masm_EQ)) {
2305 StringRef
Value = A->getValue();
2307 CmdArgs.push_back(
"-mllvm");
2308 CmdArgs.push_back(Args.MakeArgString(
"-x86-asm-syntax=" +
Value));
2309 CmdArgs.push_back(Args.MakeArgString(
"-inline-asm=" +
Value));
2311 D.Diag(diag::err_drv_unsupported_option_argument)
2312 << A->getSpelling() <<
Value;
2314 }
else if (
D.IsCLMode()) {
2315 CmdArgs.push_back(
"-mllvm");
2316 CmdArgs.push_back(
"-x86-asm-syntax=intel");
2319 if (Arg *A = Args.getLastArg(options::OPT_mskip_rax_setup,
2320 options::OPT_mno_skip_rax_setup))
2321 if (A->getOption().matches(options::OPT_mskip_rax_setup))
2322 CmdArgs.push_back(Args.MakeArgString(
"-mskip-rax-setup"));
2325 if (Args.hasFlag(options::OPT_miamcu, options::OPT_mno_iamcu,
false)) {
2326 CmdArgs.push_back(
"-mfloat-abi");
2327 CmdArgs.push_back(
"soft");
2328 CmdArgs.push_back(
"-mstack-alignment=4");
2334 std::string TuneCPU;
2335 if (!Args.hasArg(clang::driver::options::OPT_march_EQ) &&
2337 TuneCPU =
"generic";
2340 if (
const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
2341 StringRef Name = A->getValue();
2343 if (Name ==
"native") {
2344 Name = llvm::sys::getHostCPUName();
2346 TuneCPU = std::string(Name);
2348 TuneCPU = std::string(Name);
2351 if (!TuneCPU.empty()) {
2352 CmdArgs.push_back(
"-tune-cpu");
2353 CmdArgs.push_back(Args.MakeArgString(TuneCPU));
2357void Clang::AddHexagonTargetArgs(
const ArgList &Args,
2358 ArgStringList &CmdArgs)
const {
2359 CmdArgs.push_back(
"-mqdsp6-compat");
2360 CmdArgs.push_back(
"-Wreturn-type");
2363 CmdArgs.push_back(
"-mllvm");
2365 Args.MakeArgString(
"-hexagon-small-data-threshold=" + Twine(*G)));
2368 if (!Args.hasArg(options::OPT_fno_short_enums))
2369 CmdArgs.push_back(
"-fshort-enums");
2370 if (Args.getLastArg(options::OPT_mieee_rnd_near)) {
2371 CmdArgs.push_back(
"-mllvm");
2372 CmdArgs.push_back(
"-enable-hexagon-ieee-rnd-near");
2374 CmdArgs.push_back(
"-mllvm");
2375 CmdArgs.push_back(
"-machine-sink-split=0");
2378void Clang::AddLanaiTargetArgs(
const ArgList &Args,
2379 ArgStringList &CmdArgs)
const {
2380 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
2381 StringRef CPUName = A->getValue();
2383 CmdArgs.push_back(
"-target-cpu");
2384 CmdArgs.push_back(Args.MakeArgString(CPUName));
2386 if (Arg *A = Args.getLastArg(options::OPT_mregparm_EQ)) {
2387 StringRef
Value = A->getValue();
2391 if (
Value.getAsInteger(10, Mregparm)) {
2392 if (Mregparm != 4) {
2394 diag::err_drv_unsupported_option_argument)
2395 << A->getSpelling() <<
Value;
2401void Clang::AddWebAssemblyTargetArgs(
const ArgList &Args,
2402 ArgStringList &CmdArgs)
const {
2404 if (!Args.hasArg(options::OPT_fvisibility_EQ,
2405 options::OPT_fvisibility_ms_compat))
2406 CmdArgs.push_back(
"-fvisibility=hidden");
2409void Clang::AddVETargetArgs(
const ArgList &Args, ArgStringList &CmdArgs)
const {
2411 CmdArgs.push_back(
"-mfloat-abi");
2412 CmdArgs.push_back(
"hard");
2417 const InputInfo &Input,
const ArgList &Args)
const {
2419 if (
C.getArgs().hasArg(options::OPT__HASH_HASH_HASH))
2422 using llvm::yaml::escape;
2425 if (!CompilationDatabase) {
2427 auto File = std::make_unique<llvm::raw_fd_ostream>(
2429 llvm::sys::fs::OF_TextWithCRLF | llvm::sys::fs::OF_Append);
2431 D.Diag(clang::diag::err_drv_compilationdatabase) <<
Filename
2435 CompilationDatabase = std::move(
File);
2437 auto &CDB = *CompilationDatabase;
2438 auto CWD =
D.getVFS().getCurrentWorkingDirectory();
2441 CDB <<
"{ \"directory\": \"" << escape(*CWD) <<
"\"";
2442 CDB <<
", \"file\": \"" << escape(Input.
getFilename()) <<
"\"";
2444 CDB <<
", \"output\": \"" << escape(Output.
getFilename()) <<
"\"";
2445 CDB <<
", \"arguments\": [\"" << escape(
D.ClangExecutable) <<
"\"";
2449 CDB <<
", \"" << escape(Buf) <<
"\"";
2450 if (!
D.SysRoot.empty() && !Args.hasArg(options::OPT__sysroot_EQ)) {
2453 CDB <<
", \"" << escape(Buf) <<
"\"";
2455 CDB <<
", \"" << escape(Input.
getFilename()) <<
"\"";
2457 CDB <<
", \"-o\", \"" << escape(Output.
getFilename()) <<
"\"";
2458 for (
auto &A: Args) {
2459 auto &O = A->getOption();
2461 if (O.getID() == options::OPT_x)
2464 if (O.getGroup().isValid() && O.getGroup().getID() == options::OPT_M_Group)
2466 if (O.getID() == options::OPT_gen_cdb_fragment_path)
2469 if (O.getKind() == Option::InputClass)
2472 if (O.getID() == options::OPT_o)
2476 A->render(Args, ASL);
2478 CDB <<
", \"" << escape(it) <<
"\"";
2482 CDB <<
", \"" << escape(Buf) <<
"\"]},\n";
2485void Clang::DumpCompilationDatabaseFragmentToDir(
2487 const InputInfo &Input,
const llvm::opt::ArgList &Args)
const {
2489 if (
C.getArgs().hasArg(options::OPT__HASH_HASH_HASH))
2492 if (CompilationDatabase)
2493 DumpCompilationDatabase(
C,
"",
Target, Output, Input, Args);
2496 const auto &
Driver =
C.getDriver();
2498 auto Err = llvm::sys::fs::create_directory(
Path,
true);
2500 Driver.
Diag(diag::err_drv_compilationdatabase) << Dir << Err.message();
2504 llvm::sys::path::append(
2506 Twine(llvm::sys::path::filename(Input.
getFilename())) +
".%%%%.json");
2509 Err = llvm::sys::fs::createUniqueFile(
Path, FD, TempPath,
2510 llvm::sys::fs::OF_Text);
2512 Driver.
Diag(diag::err_drv_compilationdatabase) <<
Path << Err.message();
2515 CompilationDatabase =
2516 std::make_unique<llvm::raw_fd_ostream>(FD,
true);
2517 DumpCompilationDatabase(
C,
"",
Target, Output, Input, Args);
2527 CmdArgs.push_back(
"-mllvm");
2528 CmdArgs.push_back(Args.MakeArgString(
"-arm-implicit-it=" +
Value));
2532 const ArgList &Args,
2533 ArgStringList &CmdArgs,
2543 Args.addOptInFlag(CmdArgs, options::OPT_mrelax_all,
2544 options::OPT_mno_relax_all);
2548 bool DefaultIncrementalLinkerCompatible =
2549 C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment();
2550 if (Args.hasFlag(options::OPT_mincremental_linker_compatible,
2551 options::OPT_mno_incremental_linker_compatible,
2552 DefaultIncrementalLinkerCompatible))
2553 CmdArgs.push_back(
"-mincremental-linker-compatible");
2555 Args.AddLastArg(CmdArgs, options::OPT_femit_dwarf_unwind_EQ);
2557 Args.addOptInFlag(CmdArgs, options::OPT_femit_compact_unwind_non_canonical,
2558 options::OPT_fno_emit_compact_unwind_non_canonical);
2568 bool TakeNextArg =
false;
2570 const llvm::Triple &Triple =
C.getDefaultToolChain().getTriple();
2571 bool IsELF = Triple.isOSBinFormatELF();
2572 bool Crel =
false, ExperimentalCrel =
false;
2573 bool ImplicitMapSyms =
false;
2574 bool UseRelaxRelocations =
C.getDefaultToolChain().useRelaxRelocations();
2575 bool UseNoExecStack =
false;
2577 const char *MipsTargetFeature =
nullptr;
2578 StringRef ImplicitIt;
2580 Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler,
2581 options::OPT_mimplicit_it_EQ)) {
2584 if (A->getOption().getID() == options::OPT_mimplicit_it_EQ) {
2585 switch (
C.getDefaultToolChain().getArch()) {
2586 case llvm::Triple::arm:
2587 case llvm::Triple::armeb:
2588 case llvm::Triple::thumb:
2589 case llvm::Triple::thumbeb:
2591 ImplicitIt = A->getValue();
2593 D.Diag(diag::err_drv_unsupported_option_argument)
2594 << A->getSpelling() << ImplicitIt;
2601 for (StringRef
Value : A->getValues()) {
2603 CmdArgs.push_back(
Value.data());
2604 TakeNextArg =
false;
2608 if (
C.getDefaultToolChain().getTriple().isOSBinFormatCOFF() &&
2609 Value ==
"-mbig-obj")
2613 auto checkArg = [&](
bool ValidTarget,
2614 std::initializer_list<const char *>
Set) {
2616 D.Diag(diag::err_drv_unsupported_opt_for_target)
2617 << (Twine(
"-Wa,") +
Equal.first +
"=").str()
2618 << Triple.getTriple();
2619 }
else if (!llvm::is_contained(
Set,
Equal.second)) {
2620 D.Diag(diag::err_drv_unsupported_option_argument)
2621 << (Twine(
"-Wa,") +
Equal.first +
"=").str() <<
Equal.second;
2624 switch (
C.getDefaultToolChain().getArch()) {
2627 case llvm::Triple::x86:
2628 case llvm::Triple::x86_64:
2629 if (
Equal.first ==
"-mrelax-relocations" ||
2630 Equal.first ==
"--mrelax-relocations") {
2631 UseRelaxRelocations =
Equal.second ==
"yes";
2632 checkArg(IsELF, {
"yes",
"no"});
2635 if (
Value ==
"-msse2avx") {
2636 CmdArgs.push_back(
"-msse2avx");
2640 case llvm::Triple::wasm32:
2641 case llvm::Triple::wasm64:
2642 if (
Value ==
"--no-type-check") {
2643 CmdArgs.push_back(
"-mno-type-check");
2647 case llvm::Triple::thumb:
2648 case llvm::Triple::thumbeb:
2649 case llvm::Triple::arm:
2650 case llvm::Triple::armeb:
2651 if (
Equal.first ==
"-mimplicit-it") {
2653 ImplicitIt =
Equal.second;
2654 checkArg(
true, {
"always",
"never",
"arm",
"thumb"});
2657 if (
Value ==
"-mthumb")
2662 case llvm::Triple::aarch64:
2663 case llvm::Triple::aarch64_be:
2664 case llvm::Triple::aarch64_32:
2665 if (
Equal.first ==
"-mmapsyms") {
2666 ImplicitMapSyms =
Equal.second ==
"implicit";
2667 checkArg(IsELF, {
"default",
"implicit"});
2671 case llvm::Triple::mips:
2672 case llvm::Triple::mipsel:
2673 case llvm::Triple::mips64:
2674 case llvm::Triple::mips64el:
2675 if (
Value ==
"--trap") {
2676 CmdArgs.push_back(
"-target-feature");
2677 CmdArgs.push_back(
"+use-tcc-in-div");
2680 if (
Value ==
"--break") {
2681 CmdArgs.push_back(
"-target-feature");
2682 CmdArgs.push_back(
"-use-tcc-in-div");
2685 if (
Value.starts_with(
"-msoft-float")) {
2686 CmdArgs.push_back(
"-target-feature");
2687 CmdArgs.push_back(
"+soft-float");
2690 if (
Value.starts_with(
"-mhard-float")) {
2691 CmdArgs.push_back(
"-target-feature");
2692 CmdArgs.push_back(
"-soft-float");
2695 if (
Value ==
"-mmsa") {
2699 if (
Value ==
"-mno-msa") {
2703 MipsTargetFeature = llvm::StringSwitch<const char *>(
Value)
2704 .Case(
"-mips1",
"+mips1")
2705 .Case(
"-mips2",
"+mips2")
2706 .Case(
"-mips3",
"+mips3")
2707 .Case(
"-mips4",
"+mips4")
2708 .Case(
"-mips5",
"+mips5")
2709 .Case(
"-mips32",
"+mips32")
2710 .Case(
"-mips32r2",
"+mips32r2")
2711 .Case(
"-mips32r3",
"+mips32r3")
2712 .Case(
"-mips32r5",
"+mips32r5")
2713 .Case(
"-mips32r6",
"+mips32r6")
2714 .Case(
"-mips64",
"+mips64")
2715 .Case(
"-mips64r2",
"+mips64r2")
2716 .Case(
"-mips64r3",
"+mips64r3")
2717 .Case(
"-mips64r5",
"+mips64r5")
2718 .Case(
"-mips64r6",
"+mips64r6")
2720 if (MipsTargetFeature)
2725 if (
Value ==
"-force_cpusubtype_ALL") {
2727 }
else if (
Value ==
"-L") {
2728 CmdArgs.push_back(
"-msave-temp-labels");
2729 }
else if (
Value ==
"--fatal-warnings") {
2730 CmdArgs.push_back(
"-massembler-fatal-warnings");
2731 }
else if (
Value ==
"--no-warn" ||
Value ==
"-W") {
2732 CmdArgs.push_back(
"-massembler-no-warn");
2733 }
else if (
Value ==
"--noexecstack") {
2734 UseNoExecStack =
true;
2735 }
else if (
Value.starts_with(
"-compress-debug-sections") ||
2736 Value.starts_with(
"--compress-debug-sections") ||
2737 Value ==
"-nocompress-debug-sections" ||
2738 Value ==
"--nocompress-debug-sections") {
2739 CmdArgs.push_back(
Value.data());
2740 }
else if (
Value ==
"--crel") {
2742 }
else if (
Value ==
"--no-crel") {
2744 }
else if (
Value ==
"--allow-experimental-crel") {
2745 ExperimentalCrel =
true;
2746 }
else if (
Value.starts_with(
"-I")) {
2747 CmdArgs.push_back(
Value.data());
2752 }
else if (
Value.starts_with(
"-gdwarf-")) {
2755 if (DwarfVersion == 0) {
2756 CmdArgs.push_back(
Value.data());
2759 llvm::codegenoptions::DebugInfoConstructor,
2760 DwarfVersion, llvm::DebuggerKind::Default);
2762 }
else if (
Value.starts_with(
"-mcpu") ||
Value.starts_with(
"-mfpu") ||
2763 Value.starts_with(
"-mhwdiv") ||
Value.starts_with(
"-march")) {
2765 }
else if (
Value ==
"-defsym" ||
Value ==
"--defsym") {
2766 if (A->getNumValues() != 2) {
2767 D.Diag(diag::err_drv_defsym_invalid_format) <<
Value;
2770 const char *S = A->getValue(1);
2771 auto Pair = StringRef(S).split(
'=');
2772 auto Sym = Pair.first;
2773 auto SVal = Pair.second;
2775 if (Sym.empty() || SVal.empty()) {
2776 D.Diag(diag::err_drv_defsym_invalid_format) << S;
2780 if (SVal.getAsInteger(0, IVal)) {
2781 D.Diag(diag::err_drv_defsym_invalid_symval) << SVal;
2784 CmdArgs.push_back(
"--defsym");
2786 }
else if (
Value ==
"-fdebug-compilation-dir") {
2787 CmdArgs.push_back(
"-fdebug-compilation-dir");
2789 }
else if (
Value.consume_front(
"-fdebug-compilation-dir=")) {
2793 CmdArgs.push_back(
"-fdebug-compilation-dir");
2794 CmdArgs.push_back(
Value.data());
2795 }
else if (
Value ==
"--version") {
2796 D.PrintVersion(
C, llvm::outs());
2798 D.Diag(diag::err_drv_unsupported_option_argument)
2799 << A->getSpelling() <<
Value;
2803 if (ImplicitIt.size())
2806 if (!ExperimentalCrel)
2807 D.Diag(diag::err_drv_experimental_crel);
2808 if (Triple.isOSBinFormatELF() && !Triple.isMIPS()) {
2809 CmdArgs.push_back(
"--crel");
2811 D.Diag(diag::err_drv_unsupported_opt_for_target)
2812 <<
"-Wa,--crel" <<
D.getTargetTriple();
2815 if (ImplicitMapSyms)
2816 CmdArgs.push_back(
"-mmapsyms=implicit");
2818 CmdArgs.push_back(
"-mmsa");
2819 if (!UseRelaxRelocations)
2820 CmdArgs.push_back(
"-mrelax-relocations=no");
2822 CmdArgs.push_back(
"-mnoexecstack");
2823 if (MipsTargetFeature !=
nullptr) {
2824 CmdArgs.push_back(
"-target-feature");
2825 CmdArgs.push_back(MipsTargetFeature);
2829 if (
C.getDriver().embedBitcodeEnabled() ||
2830 C.getDriver().embedBitcodeMarkerOnly())
2831 Args.AddLastArg(CmdArgs, options::OPT_fembed_bitcode_EQ);
2833 if (
const char *AsSecureLogFile = getenv(
"AS_SECURE_LOG_FILE")) {
2834 CmdArgs.push_back(
"-as-secure-log-file");
2835 CmdArgs.push_back(Args.MakeArgString(AsSecureLogFile));
2866 if (str1 != str2 && !str2.empty() && !str1.empty()) {
2867 D.Diag(clang::diag::warn_drv_overriding_option) << str1 << str2;
2874 if (!ComplexRangeStr.empty())
2875 return "-complex-range=" + ComplexRangeStr;
2876 return ComplexRangeStr;
2880 bool OFastEnabled,
const ArgList &Args,
2881 ArgStringList &CmdArgs,
2884 constexpr std::array VecLibImpliesNoMathErrno{llvm::StringLiteral(
"ArmPL"),
2885 llvm::StringLiteral(
"SLEEF")};
2886 bool NoMathErrnoWasImpliedByVecLib =
false;
2887 const Arg *VecLibArg =
nullptr;
2889 const Arg *ArgThatEnabledMathErrnoAfterVecLib =
nullptr;
2896 bool HonorINFs =
true;
2897 bool HonorNaNs =
true;
2898 bool ApproxFunc =
false;
2901 bool AssociativeMath =
false;
2902 bool ReciprocalMath =
false;
2903 bool SignedZeros =
true;
2904 bool TrappingMath =
false;
2905 bool TrappingMathPresent =
false;
2907 bool RoundingFPMath =
false;
2909 StringRef FPModel =
"";
2911 StringRef FPExceptionBehavior =
"";
2913 StringRef FPEvalMethod =
"";
2914 llvm::DenormalMode DenormalFPMath =
2916 llvm::DenormalMode DenormalFP32Math =
2921 StringRef FPContract;
2922 StringRef LastSeenFfpContractOption;
2923 StringRef LastFpContractOverrideOption;
2924 bool SeenUnsafeMathModeOption =
false;
2928 bool StrictFPModel =
false;
2929 StringRef Float16ExcessPrecision =
"";
2930 StringRef BFloat16ExcessPrecision =
"";
2932 std::string ComplexRangeStr =
"";
2933 std::string GccRangeComplexOption =
"";
2938 if (
Range != NewRange)
2940 !GccRangeComplexOption.empty()
2941 ? GccRangeComplexOption
2948 auto applyFastMath = [&](
bool Aggressive) {
2959 AssociativeMath =
true;
2960 ReciprocalMath =
true;
2962 SignedZeros =
false;
2963 TrappingMath =
false;
2964 RoundingFPMath =
false;
2965 FPExceptionBehavior =
"";
2966 FPContract =
"fast";
2967 SeenUnsafeMathModeOption =
true;
2971 auto restoreFPContractState = [&]() {
2981 if (LastSeenFfpContractOption !=
"")
2982 FPContract = LastSeenFfpContractOption;
2983 else if (SeenUnsafeMathModeOption)
2988 LastFpContractOverrideOption =
"";
2991 if (
const Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) {
2992 CmdArgs.push_back(
"-mlimit-float-precision");
2993 CmdArgs.push_back(A->getValue());
2996 for (
const Arg *A : Args) {
2997 auto CheckMathErrnoForVecLib =
2998 llvm::make_scope_exit([&, MathErrnoBeforeArg = MathErrno] {
2999 if (NoMathErrnoWasImpliedByVecLib && !MathErrnoBeforeArg && MathErrno)
3000 ArgThatEnabledMathErrnoAfterVecLib = A;
3003 switch (A->getOption().getID()) {
3007 case options::OPT_fcx_limited_range:
3008 if (GccRangeComplexOption.empty()) {
3011 "-fcx-limited-range");
3013 if (GccRangeComplexOption !=
"-fno-cx-limited-range")
3016 GccRangeComplexOption =
"-fcx-limited-range";
3019 case options::OPT_fno_cx_limited_range:
3020 if (GccRangeComplexOption.empty()) {
3022 "-fno-cx-limited-range");
3024 if (GccRangeComplexOption !=
"-fcx-limited-range" &&
3025 GccRangeComplexOption !=
"-fno-cx-fortran-rules")
3027 "-fno-cx-limited-range");
3029 GccRangeComplexOption =
"-fno-cx-limited-range";
3032 case options::OPT_fcx_fortran_rules:
3033 if (GccRangeComplexOption.empty())
3035 "-fcx-fortran-rules");
3038 GccRangeComplexOption =
"-fcx-fortran-rules";
3041 case options::OPT_fno_cx_fortran_rules:
3042 if (GccRangeComplexOption.empty()) {
3044 "-fno-cx-fortran-rules");
3046 if (GccRangeComplexOption !=
"-fno-cx-limited-range")
3048 "-fno-cx-fortran-rules");
3050 GccRangeComplexOption =
"-fno-cx-fortran-rules";
3053 case options::OPT_fcomplex_arithmetic_EQ: {
3055 StringRef Val = A->getValue();
3058 else if (Val ==
"improved")
3060 else if (Val ==
"promoted")
3062 else if (Val ==
"basic")
3065 D.Diag(diag::err_drv_unsupported_option_argument)
3066 << A->getSpelling() << Val;
3069 if (!GccRangeComplexOption.empty()) {
3070 if (GccRangeComplexOption !=
"-fcx-limited-range") {
3071 if (GccRangeComplexOption !=
"-fcx-fortran-rules") {
3088 case options::OPT_ffp_model_EQ: {
3095 AssociativeMath =
false;
3096 ReciprocalMath =
false;
3099 StringRef Val = A->getValue();
3100 if (OFastEnabled && Val !=
"aggressive") {
3102 D.Diag(clang::diag::warn_drv_overriding_option)
3103 << Args.MakeArgString(
"-ffp-model=" + Val) <<
"-Ofast";
3106 StrictFPModel =
false;
3107 if (!FPModel.empty() && FPModel != Val)
3108 D.Diag(clang::diag::warn_drv_overriding_option)
3109 << Args.MakeArgString(
"-ffp-model=" + FPModel)
3110 << Args.MakeArgString(
"-ffp-model=" + Val);
3111 if (Val ==
"fast") {
3113 applyFastMath(
false);
3115 LastFpContractOverrideOption =
"-ffp-model=fast";
3116 }
else if (Val ==
"aggressive") {
3118 applyFastMath(
true);
3120 LastFpContractOverrideOption =
"-ffp-model=aggressive";
3121 }
else if (Val ==
"precise") {
3124 LastFpContractOverrideOption =
"-ffp-model=precise";
3126 }
else if (Val ==
"strict") {
3127 StrictFPModel =
true;
3128 FPExceptionBehavior =
"strict";
3131 LastFpContractOverrideOption =
"-ffp-model=strict";
3132 TrappingMath =
true;
3133 RoundingFPMath =
true;
3136 D.Diag(diag::err_drv_unsupported_option_argument)
3137 << A->getSpelling() << Val;
3142 case options::OPT_fhonor_infinities: HonorINFs =
true;
break;
3143 case options::OPT_fno_honor_infinities: HonorINFs =
false;
break;
3144 case options::OPT_fhonor_nans: HonorNaNs =
true;
break;
3145 case options::OPT_fno_honor_nans: HonorNaNs =
false;
break;
3146 case options::OPT_fapprox_func: ApproxFunc =
true;
break;
3147 case options::OPT_fno_approx_func: ApproxFunc =
false;
break;
3148 case options::OPT_fmath_errno: MathErrno =
true;
break;
3149 case options::OPT_fno_math_errno: MathErrno =
false;
break;
3150 case options::OPT_fassociative_math: AssociativeMath =
true;
break;
3151 case options::OPT_fno_associative_math: AssociativeMath =
false;
break;
3152 case options::OPT_freciprocal_math: ReciprocalMath =
true;
break;
3153 case options::OPT_fno_reciprocal_math: ReciprocalMath =
false;
break;
3154 case options::OPT_fsigned_zeros: SignedZeros =
true;
break;
3155 case options::OPT_fno_signed_zeros: SignedZeros =
false;
break;
3156 case options::OPT_ftrapping_math:
3157 if (!TrappingMathPresent && !FPExceptionBehavior.empty() &&
3158 FPExceptionBehavior !=
"strict")
3160 D.Diag(clang::diag::warn_drv_overriding_option)
3161 << Args.MakeArgString(
"-ffp-exception-behavior=" +
3162 FPExceptionBehavior)
3163 <<
"-ftrapping-math";
3164 TrappingMath =
true;
3165 TrappingMathPresent =
true;
3166 FPExceptionBehavior =
"strict";
3168 case options::OPT_fveclib:
3170 NoMathErrnoWasImpliedByVecLib =
3171 llvm::is_contained(VecLibImpliesNoMathErrno, A->getValue());
3172 if (NoMathErrnoWasImpliedByVecLib)
3175 case options::OPT_fno_trapping_math:
3176 if (!TrappingMathPresent && !FPExceptionBehavior.empty() &&
3177 FPExceptionBehavior !=
"ignore")
3179 D.Diag(clang::diag::warn_drv_overriding_option)
3180 << Args.MakeArgString(
"-ffp-exception-behavior=" +
3181 FPExceptionBehavior)
3182 <<
"-fno-trapping-math";
3183 TrappingMath =
false;
3184 TrappingMathPresent =
true;
3185 FPExceptionBehavior =
"ignore";
3188 case options::OPT_frounding_math:
3189 RoundingFPMath =
true;
3192 case options::OPT_fno_rounding_math:
3193 RoundingFPMath =
false;
3196 case options::OPT_fdenormal_fp_math_EQ:
3197 DenormalFPMath = llvm::parseDenormalFPAttribute(A->getValue());
3198 DenormalFP32Math = DenormalFPMath;
3199 if (!DenormalFPMath.isValid()) {
3200 D.Diag(diag::err_drv_invalid_value)
3201 << A->getAsString(Args) << A->getValue();
3205 case options::OPT_fdenormal_fp_math_f32_EQ:
3206 DenormalFP32Math = llvm::parseDenormalFPAttribute(A->getValue());
3207 if (!DenormalFP32Math.isValid()) {
3208 D.Diag(diag::err_drv_invalid_value)
3209 << A->getAsString(Args) << A->getValue();
3214 case options::OPT_ffp_contract: {
3215 StringRef Val = A->getValue();
3216 if (Val ==
"fast" || Val ==
"on" || Val ==
"off" ||
3217 Val ==
"fast-honor-pragmas") {
3218 if (Val != FPContract && LastFpContractOverrideOption !=
"") {
3219 D.Diag(clang::diag::warn_drv_overriding_option)
3220 << LastFpContractOverrideOption
3221 << Args.MakeArgString(
"-ffp-contract=" + Val);
3225 LastSeenFfpContractOption = Val;
3226 LastFpContractOverrideOption =
"";
3228 D.Diag(diag::err_drv_unsupported_option_argument)
3229 << A->getSpelling() << Val;
3234 case options::OPT_ffp_exception_behavior_EQ: {
3235 StringRef Val = A->getValue();
3236 if (!TrappingMathPresent && !FPExceptionBehavior.empty() &&
3237 FPExceptionBehavior != Val)
3239 D.Diag(clang::diag::warn_drv_overriding_option)
3240 << Args.MakeArgString(
"-ffp-exception-behavior=" +
3241 FPExceptionBehavior)
3242 << Args.MakeArgString(
"-ffp-exception-behavior=" + Val);
3243 TrappingMath = TrappingMathPresent =
false;
3244 if (Val ==
"ignore" || Val ==
"maytrap")
3245 FPExceptionBehavior = Val;
3246 else if (Val ==
"strict") {
3247 FPExceptionBehavior = Val;
3248 TrappingMath = TrappingMathPresent =
true;
3250 D.Diag(diag::err_drv_unsupported_option_argument)
3251 << A->getSpelling() << Val;
3256 case options::OPT_ffp_eval_method_EQ: {
3257 StringRef Val = A->getValue();
3258 if (Val ==
"double" || Val ==
"extended" || Val ==
"source")
3261 D.Diag(diag::err_drv_unsupported_option_argument)
3262 << A->getSpelling() << Val;
3266 case options::OPT_fexcess_precision_EQ: {
3267 StringRef Val = A->getValue();
3268 const llvm::Triple::ArchType Arch = TC.
getArch();
3269 if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) {
3270 if (Val ==
"standard" || Val ==
"fast")
3271 Float16ExcessPrecision = Val;
3275 else if (Val ==
"16")
3276 Float16ExcessPrecision =
"none";
3278 D.Diag(diag::err_drv_unsupported_option_argument)
3279 << A->getSpelling() << Val;
3281 if (!(Val ==
"standard" || Val ==
"fast"))
3282 D.Diag(diag::err_drv_unsupported_option_argument)
3283 << A->getSpelling() << Val;
3285 BFloat16ExcessPrecision = Float16ExcessPrecision;
3288 case options::OPT_ffinite_math_only:
3292 case options::OPT_fno_finite_math_only:
3297 case options::OPT_funsafe_math_optimizations:
3298 AssociativeMath =
true;
3299 ReciprocalMath =
true;
3300 SignedZeros =
false;
3302 TrappingMath =
false;
3303 FPExceptionBehavior =
"";
3304 FPContract =
"fast";
3305 LastFpContractOverrideOption =
"-funsafe-math-optimizations";
3306 SeenUnsafeMathModeOption =
true;
3308 case options::OPT_fno_unsafe_math_optimizations:
3309 AssociativeMath =
false;
3310 ReciprocalMath =
false;
3313 restoreFPContractState();
3316 case options::OPT_Ofast:
3321 case options::OPT_ffast_math:
3322 applyFastMath(
true);
3323 if (A->getOption().getID() == options::OPT_Ofast)
3324 LastFpContractOverrideOption =
"-Ofast";
3326 LastFpContractOverrideOption =
"-ffast-math";
3328 case options::OPT_fno_fast_math:
3335 AssociativeMath =
false;
3336 ReciprocalMath =
false;
3339 restoreFPContractState();
3340 LastFpContractOverrideOption =
"";
3350 if (StrictFPModel) {
3353 if (HonorINFs && HonorNaNs && !AssociativeMath && !ReciprocalMath &&
3354 SignedZeros && TrappingMath && RoundingFPMath && !ApproxFunc &&
3355 FPContract ==
"off")
3359 StrictFPModel =
false;
3364 auto RHS = (A->getNumValues() == 0)
3366 : Args.MakeArgString(A->getSpelling() + A->getValue());
3367 if (A->getSpelling() !=
"-ffp-contract=") {
3368 if (RHS !=
"-ffp-model=strict")
3369 D.Diag(clang::diag::warn_drv_overriding_option)
3370 <<
"-ffp-model=strict" << RHS;
3380 CmdArgs.push_back(
"-menable-no-infs");
3383 CmdArgs.push_back(
"-menable-no-nans");
3386 CmdArgs.push_back(
"-fapprox-func");
3389 CmdArgs.push_back(
"-fmath-errno");
3390 if (NoMathErrnoWasImpliedByVecLib)
3391 D.Diag(clang::diag::warn_drv_math_errno_enabled_after_veclib)
3392 << ArgThatEnabledMathErrnoAfterVecLib->getAsString(Args)
3393 << VecLibArg->getAsString(Args);
3396 if (AssociativeMath && ReciprocalMath && !SignedZeros && ApproxFunc &&
3398 CmdArgs.push_back(
"-funsafe-math-optimizations");
3401 CmdArgs.push_back(
"-fno-signed-zeros");
3403 if (AssociativeMath && !SignedZeros && !TrappingMath)
3404 CmdArgs.push_back(
"-mreassociate");
3407 CmdArgs.push_back(
"-freciprocal-math");
3411 assert(FPExceptionBehavior ==
"strict");
3415 if (DenormalFPMath != llvm::DenormalMode::getIEEE()) {
3417 llvm::raw_svector_ostream ArgStr(DenormFlag);
3418 ArgStr <<
"-fdenormal-fp-math=" << DenormalFPMath;
3419 CmdArgs.push_back(Args.MakeArgString(ArgStr.str()));
3423 if (DenormalFP32Math != DenormalFPMath) {
3425 llvm::raw_svector_ostream ArgStr(DenormFlag);
3426 ArgStr <<
"-fdenormal-fp-math-f32=" << DenormalFP32Math;
3427 CmdArgs.push_back(Args.MakeArgString(ArgStr.str()));
3430 if (!FPContract.empty())
3431 CmdArgs.push_back(Args.MakeArgString(
"-ffp-contract=" + FPContract));
3434 CmdArgs.push_back(Args.MakeArgString(
"-frounding-math"));
3436 CmdArgs.push_back(Args.MakeArgString(
"-fno-rounding-math"));
3438 if (!FPExceptionBehavior.empty())
3439 CmdArgs.push_back(Args.MakeArgString(
"-ffp-exception-behavior=" +
3440 FPExceptionBehavior));
3442 if (!FPEvalMethod.empty())
3443 CmdArgs.push_back(Args.MakeArgString(
"-ffp-eval-method=" + FPEvalMethod));
3445 if (!Float16ExcessPrecision.empty())
3446 CmdArgs.push_back(Args.MakeArgString(
"-ffloat16-excess-precision=" +
3447 Float16ExcessPrecision));
3448 if (!BFloat16ExcessPrecision.empty())
3449 CmdArgs.push_back(Args.MakeArgString(
"-fbfloat16-excess-precision=" +
3450 BFloat16ExcessPrecision));
3457 if (!HonorINFs && !HonorNaNs && !MathErrno && AssociativeMath && ApproxFunc &&
3458 ReciprocalMath && !SignedZeros && !TrappingMath && !RoundingFPMath)
3459 CmdArgs.push_back(
"-ffast-math");
3465 bool shouldAddFiniteMathOnly =
false;
3466 if (!HonorINFs && !HonorNaNs) {
3467 shouldAddFiniteMathOnly =
true;
3469 bool InfValues =
true;
3470 bool NanValues =
true;
3471 for (
const auto *Arg : Args.filtered(options::OPT_Xclang)) {
3472 StringRef ArgValue = Arg->getValue();
3473 if (ArgValue ==
"-menable-no-nans")
3475 else if (ArgValue ==
"-menable-no-infs")
3478 if (!NanValues && !InfValues)
3479 shouldAddFiniteMathOnly =
true;
3481 if (shouldAddFiniteMathOnly) {
3482 CmdArgs.push_back(
"-ffinite-math-only");
3484 if (
const Arg *A = Args.getLastArg(options::OPT_mfpmath_EQ)) {
3485 CmdArgs.push_back(
"-mfpmath");
3486 CmdArgs.push_back(A->getValue());
3490 if (Args.hasFlag(options::OPT_fno_strict_float_cast_overflow,
3491 options::OPT_fstrict_float_cast_overflow,
false))
3492 CmdArgs.push_back(
"-fno-strict-float-cast-overflow");
3496 if (!ComplexRangeStr.empty()) {
3497 CmdArgs.push_back(Args.MakeArgString(ComplexRangeStr));
3498 if (Args.hasArg(options::OPT_fcomplex_arithmetic_EQ))
3499 CmdArgs.push_back(Args.MakeArgString(
"-fcomplex-arithmetic=" +
3502 if (Args.hasArg(options::OPT_fcx_limited_range))
3503 CmdArgs.push_back(
"-fcx-limited-range");
3504 if (Args.hasArg(options::OPT_fcx_fortran_rules))
3505 CmdArgs.push_back(
"-fcx-fortran-rules");
3506 if (Args.hasArg(options::OPT_fno_cx_limited_range))
3507 CmdArgs.push_back(
"-fno-cx-limited-range");
3508 if (Args.hasArg(options::OPT_fno_cx_fortran_rules))
3509 CmdArgs.push_back(
"-fno-cx-fortran-rules");
3513 const llvm::Triple &Triple,
3516 if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) {
3517 CmdArgs.push_back(
"-analyzer-checker=core");
3518 CmdArgs.push_back(
"-analyzer-checker=apiModeling");
3520 if (!Triple.isWindowsMSVCEnvironment()) {
3521 CmdArgs.push_back(
"-analyzer-checker=unix");
3524 CmdArgs.push_back(
"-analyzer-checker=unix.API");
3525 CmdArgs.push_back(
"-analyzer-checker=unix.Malloc");
3526 CmdArgs.push_back(
"-analyzer-checker=unix.MallocSizeof");
3527 CmdArgs.push_back(
"-analyzer-checker=unix.MismatchedDeallocator");
3528 CmdArgs.push_back(
"-analyzer-checker=unix.cstring.BadSizeArg");
3529 CmdArgs.push_back(
"-analyzer-checker=unix.cstring.NullArg");
3533 if (Triple.isPS()) {
3534 CmdArgs.push_back(
"-analyzer-disable-checker=unix.API");
3535 CmdArgs.push_back(
"-analyzer-disable-checker=unix.Vfork");
3538 if (Triple.isOSDarwin()) {
3539 CmdArgs.push_back(
"-analyzer-checker=osx");
3541 "-analyzer-checker=security.insecureAPI.decodeValueOfObjCType");
3543 else if (Triple.isOSFuchsia())
3544 CmdArgs.push_back(
"-analyzer-checker=fuchsia");
3546 CmdArgs.push_back(
"-analyzer-checker=deadcode");
3549 CmdArgs.push_back(
"-analyzer-checker=cplusplus");
3551 if (!Triple.isPS()) {
3552 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.UncheckedReturn");
3553 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.getpw");
3554 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.gets");
3555 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.mktemp");
3556 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.mkstemp");
3557 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.vfork");
3561 CmdArgs.push_back(
"-analyzer-checker=nullability.NullPassedToNonnull");
3562 CmdArgs.push_back(
"-analyzer-checker=nullability.NullReturnedFromNonnull");
3566 CmdArgs.push_back(
"-analyzer-output");
3567 if (Arg *A = Args.getLastArg(options::OPT__analyzer_output))
3568 CmdArgs.push_back(A->getValue());
3570 CmdArgs.push_back(
"plist");
3575 CmdArgs.push_back(
"-w");
3578 Args.AddAllArgValues(CmdArgs, options::OPT_Xanalyzer);
3585 if (std::isdigit(S[0]))
3588 return llvm::all_of(S, [](
char C) {
return std::isalnum(
C) ||
C ==
'_'; });
3592 const ArgList &Args, ArgStringList &CmdArgs,
3593 bool KernelOrKext) {
3598 if (EffectiveTriple.isNVPTX())
3606 if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector,
3607 options::OPT_fstack_protector_all,
3608 options::OPT_fstack_protector_strong,
3609 options::OPT_fstack_protector)) {
3610 if (A->getOption().matches(options::OPT_fstack_protector))
3611 StackProtectorLevel =
3613 else if (A->getOption().matches(options::OPT_fstack_protector_strong))
3615 else if (A->getOption().matches(options::OPT_fstack_protector_all))
3619 D.Diag(diag::warn_drv_unsupported_option_for_target)
3620 << A->getSpelling() << EffectiveTriple.getTriple();
3621 StackProtectorLevel = DefaultStackProtectorLevel;
3624 StackProtectorLevel = DefaultStackProtectorLevel;
3627 if (StackProtectorLevel) {
3628 CmdArgs.push_back(
"-stack-protector");
3629 CmdArgs.push_back(Args.MakeArgString(Twine(StackProtectorLevel)));
3633 for (
const Arg *A : Args.filtered(options::OPT__param)) {
3634 StringRef Str(A->getValue());
3635 if (Str.starts_with(
"ssp-buffer-size=")) {
3636 if (StackProtectorLevel) {
3637 CmdArgs.push_back(
"-stack-protector-buffer-size");
3639 CmdArgs.push_back(Args.MakeArgString(Str.drop_front(16)));
3645 const std::string &TripleStr = EffectiveTriple.getTriple();
3646 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_EQ)) {
3647 StringRef
Value = A->getValue();
3648 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
3649 !EffectiveTriple.isARM() && !EffectiveTriple.isThumb() &&
3650 !EffectiveTriple.isRISCV() && !EffectiveTriple.isPPC())
3651 D.Diag(diag::err_drv_unsupported_opt_for_target)
3652 << A->getAsString(Args) << TripleStr;
3653 if ((EffectiveTriple.isX86() || EffectiveTriple.isARM() ||
3654 EffectiveTriple.isThumb()) &&
3656 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3657 << A->getOption().getName() <<
Value <<
"tls global";
3660 if ((EffectiveTriple.isARM() || EffectiveTriple.isThumb()) &&
3662 if (!Args.hasArg(options::OPT_mstack_protector_guard_offset_EQ)) {
3663 D.Diag(diag::err_drv_ssp_missing_offset_argument)
3664 << A->getAsString(Args);
3669 D.Diag(diag::err_target_unsupported_tp_hard)
3670 << EffectiveTriple.getArchName();
3674 if (Arg *A = Args.getLastArg(options::OPT_mtp_mode_EQ)) {
3675 StringRef
Value = A->getValue();
3676 if (
Value !=
"cp15") {
3677 D.Diag(diag::err_drv_argument_not_allowed_with)
3678 << A->getAsString(Args) <<
"-mstack-protector-guard=tls";
3682 CmdArgs.push_back(
"-target-feature");
3683 CmdArgs.push_back(
"+read-tp-tpidruro");
3685 if (EffectiveTriple.isAArch64() &&
Value !=
"sysreg" &&
Value !=
"global") {
3686 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3687 << A->getOption().getName() <<
Value <<
"sysreg global";
3690 if (EffectiveTriple.isRISCV() || EffectiveTriple.isPPC()) {
3692 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3693 << A->getOption().getName() <<
Value <<
"tls global";
3696 if (
Value ==
"tls") {
3697 if (!Args.hasArg(options::OPT_mstack_protector_guard_offset_EQ)) {
3698 D.Diag(diag::err_drv_ssp_missing_offset_argument)
3699 << A->getAsString(Args);
3704 A->render(Args, CmdArgs);
3707 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_offset_EQ)) {
3708 StringRef
Value = A->getValue();
3709 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
3710 !EffectiveTriple.isARM() && !EffectiveTriple.isThumb() &&
3711 !EffectiveTriple.isRISCV() && !EffectiveTriple.isPPC())
3712 D.Diag(diag::err_drv_unsupported_opt_for_target)
3713 << A->getAsString(Args) << TripleStr;
3715 if (
Value.getAsInteger(10, Offset)) {
3716 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() <<
Value;
3719 if ((EffectiveTriple.isARM() || EffectiveTriple.isThumb()) &&
3720 (Offset < 0 || Offset > 0xfffff)) {
3721 D.Diag(diag::err_drv_invalid_int_value)
3722 << A->getOption().getName() <<
Value;
3725 A->render(Args, CmdArgs);
3728 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_reg_EQ)) {
3729 StringRef
Value = A->getValue();
3730 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
3731 !EffectiveTriple.isRISCV() && !EffectiveTriple.isPPC())
3732 D.Diag(diag::err_drv_unsupported_opt_for_target)
3733 << A->getAsString(Args) << TripleStr;
3734 if (EffectiveTriple.isX86() && (
Value !=
"fs" &&
Value !=
"gs")) {
3735 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3736 << A->getOption().getName() <<
Value <<
"fs gs";
3739 if (EffectiveTriple.isAArch64() &&
Value !=
"sp_el0") {
3740 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() <<
Value;
3743 if (EffectiveTriple.isRISCV() &&
Value !=
"tp") {
3744 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3745 << A->getOption().getName() <<
Value <<
"tp";
3748 if (EffectiveTriple.isPPC64() &&
Value !=
"r13") {
3749 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3750 << A->getOption().getName() <<
Value <<
"r13";
3753 if (EffectiveTriple.isPPC32() &&
Value !=
"r2") {
3754 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3755 << A->getOption().getName() <<
Value <<
"r2";
3758 A->render(Args, CmdArgs);
3761 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_symbol_EQ)) {
3762 StringRef
Value = A->getValue();
3764 D.Diag(diag::err_drv_argument_only_allowed_with)
3765 << A->getOption().getName() <<
"legal symbol name";
3768 A->render(Args, CmdArgs);
3773 ArgStringList &CmdArgs) {
3776 if (!EffectiveTriple.isOSFreeBSD() && !EffectiveTriple.isOSLinux() &&
3777 !EffectiveTriple.isOSFuchsia())
3780 if (!EffectiveTriple.isX86() && !EffectiveTriple.isSystemZ() &&
3781 !EffectiveTriple.isPPC64() && !EffectiveTriple.isAArch64() &&
3782 !EffectiveTriple.isRISCV())
3785 Args.addOptInFlag(CmdArgs, options::OPT_fstack_clash_protection,
3786 options::OPT_fno_stack_clash_protection);
3791 const ArgList &Args,
3792 ArgStringList &CmdArgs) {
3794 StringRef TrivialAutoVarInit =
"";
3796 for (
const Arg *A : Args) {
3797 switch (A->getOption().getID()) {
3800 case options::OPT_ftrivial_auto_var_init: {
3802 StringRef Val = A->getValue();
3803 if (Val ==
"uninitialized" || Val ==
"zero" || Val ==
"pattern")
3804 TrivialAutoVarInit = Val;
3806 D.Diag(diag::err_drv_unsupported_option_argument)
3807 << A->getSpelling() << Val;
3813 if (TrivialAutoVarInit.empty())
3814 switch (DefaultTrivialAutoVarInit) {
3818 TrivialAutoVarInit =
"pattern";
3821 TrivialAutoVarInit =
"zero";
3825 if (!TrivialAutoVarInit.empty()) {
3827 Args.MakeArgString(
"-ftrivial-auto-var-init=" + TrivialAutoVarInit));
3831 Args.getLastArg(options::OPT_ftrivial_auto_var_init_stop_after)) {
3832 if (!Args.hasArg(options::OPT_ftrivial_auto_var_init) ||
3834 Args.getLastArg(options::OPT_ftrivial_auto_var_init)->getValue()) ==
3836 D.Diag(diag::err_drv_trivial_auto_var_init_stop_after_missing_dependency);
3838 StringRef Val = A->getValue();
3839 if (std::stoi(Val.str()) <= 0)
3840 D.Diag(diag::err_drv_trivial_auto_var_init_stop_after_invalid_value);
3842 Args.MakeArgString(
"-ftrivial-auto-var-init-stop-after=" + Val));
3845 if (Arg *A = Args.getLastArg(options::OPT_ftrivial_auto_var_init_max_size)) {
3846 if (!Args.hasArg(options::OPT_ftrivial_auto_var_init) ||
3848 Args.getLastArg(options::OPT_ftrivial_auto_var_init)->getValue()) ==
3850 D.Diag(diag::err_drv_trivial_auto_var_init_max_size_missing_dependency);
3852 StringRef Val = A->getValue();
3853 if (std::stoi(Val.str()) <= 0)
3854 D.Diag(diag::err_drv_trivial_auto_var_init_max_size_invalid_value);
3856 Args.MakeArgString(
"-ftrivial-auto-var-init-max-size=" + Val));
3864 const unsigned ForwardedArguments[] = {
3865 options::OPT_cl_opt_disable,
3866 options::OPT_cl_strict_aliasing,
3867 options::OPT_cl_single_precision_constant,
3868 options::OPT_cl_finite_math_only,
3869 options::OPT_cl_kernel_arg_info,
3870 options::OPT_cl_unsafe_math_optimizations,
3871 options::OPT_cl_fast_relaxed_math,
3872 options::OPT_cl_mad_enable,
3873 options::OPT_cl_no_signed_zeros,
3874 options::OPT_cl_fp32_correctly_rounded_divide_sqrt,
3875 options::OPT_cl_uniform_work_group_size
3878 if (Arg *A = Args.getLastArg(options::OPT_cl_std_EQ)) {
3879 std::string CLStdStr = std::string(
"-cl-std=") + A->getValue();
3880 CmdArgs.push_back(Args.MakeArgString(CLStdStr));
3881 }
else if (Arg *A = Args.getLastArg(options::OPT_cl_ext_EQ)) {
3882 std::string CLExtStr = std::string(
"-cl-ext=") + A->getValue();
3883 CmdArgs.push_back(Args.MakeArgString(CLExtStr));
3886 if (Args.hasArg(options::OPT_cl_finite_math_only)) {
3887 CmdArgs.push_back(
"-menable-no-infs");
3888 CmdArgs.push_back(
"-menable-no-nans");
3891 for (
const auto &Arg : ForwardedArguments)
3892 if (
const auto *A = Args.getLastArg(Arg))
3893 CmdArgs.push_back(Args.MakeArgString(A->getOption().getPrefixedName()));
3898 !Args.hasArg(options::OPT_cl_no_stdinc)) {
3899 CmdArgs.push_back(
"-finclude-default-header");
3900 CmdArgs.push_back(
"-fdeclare-opencl-builtins");
3906 const unsigned ForwardedArguments[] = {options::OPT_dxil_validator_version,
3910 options::OPT_emit_llvm,
3911 options::OPT_emit_obj,
3912 options::OPT_disable_llvm_passes,
3913 options::OPT_fnative_half_type,
3914 options::OPT_hlsl_entrypoint};
3917 for (
const auto &Arg : ForwardedArguments)
3918 if (
const auto *A = Args.getLastArg(Arg))
3919 A->renderAsInput(Args, CmdArgs);
3921 if (!Args.hasArg(options::OPT_dxc_no_stdinc) &&
3922 !Args.hasArg(options::OPT_nostdinc))
3923 CmdArgs.push_back(
"-finclude-default-header");
3927 ArgStringList &CmdArgs,
types::ID InputType) {
3928 if (!Args.hasArg(options::OPT_fopenacc))
3931 CmdArgs.push_back(
"-fopenacc");
3933 if (Arg *A = Args.getLastArg(options::OPT_openacc_macro_override)) {
3934 StringRef
Value = A->getValue();
3936 if (!
Value.getAsInteger(10, Version))
3937 A->renderAsInput(Args, CmdArgs);
3939 D.Diag(diag::err_drv_clang_unsupported) <<
Value;
3944 ArgStringList &CmdArgs) {
3945 bool ARCMTEnabled =
false;
3946 if (!Args.hasArg(options::OPT_fno_objc_arc, options::OPT_fobjc_arc)) {
3947 if (
const Arg *A = Args.getLastArg(options::OPT_ccc_arcmt_check,
3948 options::OPT_ccc_arcmt_modify,
3949 options::OPT_ccc_arcmt_migrate)) {
3950 ARCMTEnabled =
true;
3951 switch (A->getOption().getID()) {
3952 default: llvm_unreachable(
"missed a case");
3953 case options::OPT_ccc_arcmt_check:
3954 CmdArgs.push_back(
"-arcmt-action=check");
3956 case options::OPT_ccc_arcmt_modify:
3957 CmdArgs.push_back(
"-arcmt-action=modify");
3959 case options::OPT_ccc_arcmt_migrate:
3960 CmdArgs.push_back(
"-arcmt-action=migrate");
3961 CmdArgs.push_back(
"-mt-migrate-directory");
3962 CmdArgs.push_back(A->getValue());
3964 Args.AddLastArg(CmdArgs, options::OPT_arcmt_migrate_report_output);
3965 Args.AddLastArg(CmdArgs, options::OPT_arcmt_migrate_emit_arc_errors);
3970 Args.ClaimAllArgs(options::OPT_ccc_arcmt_check);
3971 Args.ClaimAllArgs(options::OPT_ccc_arcmt_modify);
3972 Args.ClaimAllArgs(options::OPT_ccc_arcmt_migrate);
3975 if (
const Arg *A = Args.getLastArg(options::OPT_ccc_objcmt_migrate)) {
3977 D.Diag(diag::err_drv_argument_not_allowed_with)
3978 << A->getAsString(Args) <<
"-ccc-arcmt-migrate";
3980 CmdArgs.push_back(
"-mt-migrate-directory");
3981 CmdArgs.push_back(A->getValue());
3983 if (!Args.hasArg(options::OPT_objcmt_migrate_literals,
3984 options::OPT_objcmt_migrate_subscripting,
3985 options::OPT_objcmt_migrate_property)) {
3987 CmdArgs.push_back(
"-objcmt-migrate-literals");
3988 CmdArgs.push_back(
"-objcmt-migrate-subscripting");
3989 CmdArgs.push_back(
"-objcmt-migrate-property");
3991 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_literals);
3992 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_subscripting);
3993 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_property);
3996 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_literals);
3997 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_subscripting);
3998 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_property);
3999 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_all);
4000 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_readonly_property);
4001 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_readwrite_property);
4002 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_property_dot_syntax);
4003 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_annotation);
4004 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_instancetype);
4005 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_nsmacros);
4006 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_protocol_conformance);
4007 Args.AddLastArg(CmdArgs, options::OPT_objcmt_atomic_property);
4008 Args.AddLastArg(CmdArgs, options::OPT_objcmt_returns_innerpointer_property);
4009 Args.AddLastArg(CmdArgs, options::OPT_objcmt_ns_nonatomic_iosonly);
4010 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_designated_init);
4011 Args.AddLastArg(CmdArgs, options::OPT_objcmt_allowlist_dir_path);
4016 const ArgList &Args, ArgStringList &CmdArgs) {
4019 Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin,
4020 !Args.hasArg(options::OPT_mkernel));
4022 CmdArgs.push_back(
"-fno-builtin");
4025 if (Args.hasArg(options::OPT_ffreestanding))
4026 UseBuiltins =
false;
4029 for (
const Arg *A : Args.filtered(options::OPT_fno_builtin_)) {
4035 A->render(Args, CmdArgs);
4040 if (
const char *Str = std::getenv(
"CLANG_MODULE_CACHE_PATH")) {
4043 return Path.getSingleStringRef() !=
"";
4045 if (llvm::sys::path::cache_directory(
Result)) {
4046 llvm::sys::path::append(
Result,
"clang");
4047 llvm::sys::path::append(
Result,
"ModuleCache");
4055 const char *BaseInput) {
4056 if (Arg *ModuleOutputEQ = Args.getLastArg(options::OPT_fmodule_output_EQ))
4057 return StringRef(ModuleOutputEQ->getValue());
4060 if (Arg *FinalOutput = Args.getLastArg(options::OPT_o);
4061 FinalOutput && Args.hasArg(options::OPT_c))
4062 OutputPath = FinalOutput->getValue();
4064 OutputPath = BaseInput;
4067 llvm::sys::path::replace_extension(OutputPath, Extension);
4072 const ArgList &Args,
const InputInfo &Input,
4073 const InputInfo &Output,
bool HaveStd20,
4074 ArgStringList &CmdArgs) {
4076 bool HaveStdCXXModules = IsCXX && HaveStd20;
4077 bool HaveModules = HaveStdCXXModules;
4082 bool HaveClangModules =
false;
4083 if (Args.hasFlag(options::OPT_fmodules, options::OPT_fno_modules,
false)) {
4084 bool AllowedInCXX = Args.hasFlag(options::OPT_fcxx_modules,
4085 options::OPT_fno_cxx_modules,
true);
4086 if (AllowedInCXX || !IsCXX) {
4087 CmdArgs.push_back(
"-fmodules");
4088 HaveClangModules =
true;
4092 HaveModules |= HaveClangModules;
4096 if (Args.hasFlag(options::OPT_fimplicit_module_maps,
4097 options::OPT_fno_implicit_module_maps, HaveClangModules))
4098 CmdArgs.push_back(
"-fimplicit-module-maps");
4101 Args.addOptInFlag(CmdArgs, options::OPT_fmodules_decluse,
4102 options::OPT_fno_modules_decluse);
4106 if (Args.hasFlag(options::OPT_fmodules_strict_decluse,
4107 options::OPT_fno_modules_strict_decluse,
false))
4108 CmdArgs.push_back(
"-fmodules-strict-decluse");
4110 Args.addOptOutFlag(CmdArgs, options::OPT_fmodulemap_allow_subdirectory_search,
4111 options::OPT_fno_modulemap_allow_subdirectory_search);
4114 bool ImplicitModules =
false;
4115 if (!Args.hasFlag(options::OPT_fimplicit_modules,
4116 options::OPT_fno_implicit_modules, HaveClangModules)) {
4118 CmdArgs.push_back(
"-fno-implicit-modules");
4119 }
else if (HaveModules) {
4120 ImplicitModules =
true;
4124 if (Arg *A = Args.getLastArg(options::OPT_fmodules_cache_path))
4125 Path = A->getValue();
4127 bool HasPath =
true;
4128 if (
C.isForDiagnostics()) {
4132 llvm::sys::path::replace_extension(
Path,
".cache");
4133 llvm::sys::path::append(
Path,
"modules");
4134 }
else if (
Path.empty()) {
4142 const char Arg[] =
"-fmodules-cache-path=";
4143 Path.insert(
Path.begin(), Arg, Arg + strlen(Arg));
4144 CmdArgs.push_back(Args.MakeArgString(
Path));
4149 if (Args.hasFlag(options::OPT_fprebuilt_implicit_modules,
4150 options::OPT_fno_prebuilt_implicit_modules,
false))
4151 CmdArgs.push_back(
"-fprebuilt-implicit-modules");
4152 if (Args.hasFlag(options::OPT_fmodules_validate_input_files_content,
4153 options::OPT_fno_modules_validate_input_files_content,
4155 CmdArgs.push_back(
"-fvalidate-ast-input-files-content");
4160 Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
4164 Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
4168 if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
4170 llvm::sys::path::append(BuiltinModuleMap,
"include");
4171 llvm::sys::path::append(BuiltinModuleMap,
"module.modulemap");
4172 if (llvm::sys::fs::exists(BuiltinModuleMap))
4174 Args.MakeArgString(
"-fmodule-map-file=" + BuiltinModuleMap));
4181 if (HaveModules || Input.
getType() == clang::driver::types::TY_ModuleFile) {
4182 Args.AddAllArgs(CmdArgs, options::OPT_fmodule_file);
4185 for (
const Arg *A : Args.filtered(options::OPT_fprebuilt_module_path)) {
4186 CmdArgs.push_back(Args.MakeArgString(
4187 std::string(
"-fprebuilt-module-path=") + A->getValue()));
4191 Args.ClaimAllArgs(options::OPT_fmodule_file);
4195 if (HaveClangModules &&
C.isForDiagnostics()) {
4197 llvm::sys::path::replace_extension(VFSDir,
".cache");
4199 C.addTempFile(Args.MakeArgString(VFSDir));
4201 llvm::sys::path::append(VFSDir,
"vfs");
4202 CmdArgs.push_back(
"-module-dependency-dir");
4203 CmdArgs.push_back(Args.MakeArgString(VFSDir));
4206 if (HaveClangModules)
4207 Args.AddLastArg(CmdArgs, options::OPT_fmodules_user_build_path);
4210 Args.AddAllArgs(CmdArgs, options::OPT_fmodules_ignore_macro);
4211 Args.AddLastArg(CmdArgs, options::OPT_fmodules_prune_interval);
4212 Args.AddLastArg(CmdArgs, options::OPT_fmodules_prune_after);
4214 if (HaveClangModules) {
4215 Args.AddLastArg(CmdArgs, options::OPT_fbuild_session_timestamp);
4217 if (Arg *A = Args.getLastArg(options::OPT_fbuild_session_file)) {
4218 if (Args.hasArg(options::OPT_fbuild_session_timestamp))
4219 D.Diag(diag::err_drv_argument_not_allowed_with)
4220 << A->getAsString(Args) <<
"-fbuild-session-timestamp";
4222 llvm::sys::fs::file_status Status;
4223 if (llvm::sys::fs::status(A->getValue(), Status))
4224 D.Diag(diag::err_drv_no_such_file) << A->getValue();
4225 CmdArgs.push_back(Args.MakeArgString(
4226 "-fbuild-session-timestamp=" +
4227 Twine((uint64_t)std::chrono::duration_cast<std::chrono::seconds>(
4228 Status.getLastModificationTime().time_since_epoch())
4232 if (Args.getLastArg(
4233 options::OPT_fmodules_validate_once_per_build_session)) {
4234 if (!Args.getLastArg(options::OPT_fbuild_session_timestamp,
4235 options::OPT_fbuild_session_file))
4236 D.Diag(diag::err_drv_modules_validate_once_requires_timestamp);
4238 Args.AddLastArg(CmdArgs,
4239 options::OPT_fmodules_validate_once_per_build_session);
4242 if (Args.hasFlag(options::OPT_fmodules_validate_system_headers,
4243 options::OPT_fno_modules_validate_system_headers,
4245 CmdArgs.push_back(
"-fmodules-validate-system-headers");
4247 Args.AddLastArg(CmdArgs,
4248 options::OPT_fmodules_disable_diagnostic_validation);
4250 Args.ClaimAllArgs(options::OPT_fbuild_session_timestamp);
4251 Args.ClaimAllArgs(options::OPT_fbuild_session_file);
4252 Args.ClaimAllArgs(options::OPT_fmodules_validate_once_per_build_session);
4253 Args.ClaimAllArgs(options::OPT_fmodules_validate_system_headers);
4254 Args.ClaimAllArgs(options::OPT_fno_modules_validate_system_headers);
4255 Args.ClaimAllArgs(options::OPT_fmodules_disable_diagnostic_validation);
4260 CmdArgs.push_back(
"-fskip-odr-check-in-gmf");
4262 if (Args.hasArg(options::OPT_modules_reduced_bmi) &&
4263 (Input.
getType() == driver::types::TY_CXXModule ||
4264 Input.
getType() == driver::types::TY_PP_CXXModule)) {
4265 CmdArgs.push_back(
"-fmodules-reduced-bmi");
4267 if (Args.hasArg(options::OPT_fmodule_output_EQ))
4268 Args.AddLastArg(CmdArgs, options::OPT_fmodule_output_EQ);
4270 CmdArgs.push_back(Args.MakeArgString(
4271 "-fmodule-output=" +
4278 Args.ClaimAllArgs(options::OPT_modules_reduced_bmi);
4286 if (Input.
getType() == driver::types::TY_CXXModule ||
4287 Input.
getType() == driver::types::TY_PP_CXXModule ||
4288 Input.
getType() == driver::types::TY_ModuleFile) {
4289 Args.ClaimAllArgs(options::OPT_fmodule_output);
4290 Args.ClaimAllArgs(options::OPT_fmodule_output_EQ);
4293 if (Args.hasArg(options::OPT_fmodules_embed_all_files))
4294 CmdArgs.push_back(
"-fmodules-embed-all-files");
4300 ArgStringList &CmdArgs) {
4302 if (
const Arg *A = Args.getLastArg(options::OPT_fsigned_char,
4303 options::OPT_fno_signed_char,
4304 options::OPT_funsigned_char,
4305 options::OPT_fno_unsigned_char)) {
4306 if (A->getOption().matches(options::OPT_funsigned_char) ||
4307 A->getOption().matches(options::OPT_fno_signed_char)) {
4308 CmdArgs.push_back(
"-fno-signed-char");
4311 CmdArgs.push_back(
"-fno-signed-char");
4315 Args.AddLastArg(CmdArgs, options::OPT_fchar8__t, options::OPT_fno_char8__t);
4317 if (
const Arg *A = Args.getLastArg(options::OPT_fshort_wchar,
4318 options::OPT_fno_short_wchar)) {
4319 if (A->getOption().matches(options::OPT_fshort_wchar)) {
4320 CmdArgs.push_back(
"-fwchar-type=short");
4321 CmdArgs.push_back(
"-fno-signed-wchar");
4323 bool IsARM =
T.isARM() ||
T.isThumb() ||
T.isAArch64();
4324 CmdArgs.push_back(
"-fwchar-type=int");
4326 (IsARM && !(
T.isOSWindows() ||
T.isOSNetBSD() ||
T.isOSOpenBSD())))
4327 CmdArgs.push_back(
"-fno-signed-wchar");
4329 CmdArgs.push_back(
"-fsigned-wchar");
4331 }
else if (
T.isOSzOS())
4332 CmdArgs.push_back(
"-fno-signed-wchar");
4336 const llvm::Triple &
T,
const ArgList &Args,
4338 const InputInfo &Input, ArgStringList &CmdArgs) {
4339 const llvm::Triple::ArchType Arch = TC.
getArch();
4345 if (!Args.hasFlag(options::OPT_fobjc_legacy_dispatch,
4346 options::OPT_fno_objc_legacy_dispatch,
4349 CmdArgs.push_back(
"-fobjc-dispatch-method=mixed");
4351 CmdArgs.push_back(
"-fobjc-dispatch-method=non-legacy");
4357 if (Arch == llvm::Triple::x86 &&
T.isMacOSX() &&
4359 CmdArgs.push_back(
"-fobjc-subscripting-legacy-runtime");
4366 CmdArgs.push_back(
"-fobjc-arc");
4373 CmdArgs.push_back(
"-fobjc-arc-cxxlib=libc++");
4375 CmdArgs.push_back(
"-fobjc-arc-cxxlib=libstdc++");
4380 if (Args.hasFlag(options::OPT_fobjc_arc_exceptions,
4381 options::OPT_fno_objc_arc_exceptions,
4383 CmdArgs.push_back(
"-fobjc-arc-exceptions");
4388 if (Args.hasArg(options::OPT_fno_objc_arc)) {
4389 Args.ClaimAllArgs(options::OPT_fobjc_arc_exceptions);
4390 Args.ClaimAllArgs(options::OPT_fno_objc_arc_exceptions);
4396 auto *Arg = Args.getLastArg(
4397 options::OPT_fobjc_convert_messages_to_runtime_calls,
4398 options::OPT_fno_objc_convert_messages_to_runtime_calls);
4400 Arg->getOption().matches(
4401 options::OPT_fno_objc_convert_messages_to_runtime_calls))
4402 CmdArgs.push_back(
"-fno-objc-convert-messages-to-runtime-calls");
4407 if (InferCovariantReturns)
4408 CmdArgs.push_back(
"-fno-objc-infer-related-result-type");
4413 Args.getLastArg(options::OPT_fobjc_weak, options::OPT_fno_objc_weak);
4417 if (WeakArg->getOption().matches(options::OPT_fobjc_weak))
4418 D.Diag(diag::err_objc_weak_unsupported);
4420 WeakArg->render(Args, CmdArgs);
4424 if (Args.hasArg(options::OPT_fobjc_disable_direct_methods_for_testing))
4425 CmdArgs.push_back(
"-fobjc-disable-direct-methods-for-testing");
4429 ArgStringList &CmdArgs) {
4430 bool CaretDefault =
true;
4431 bool ColumnDefault =
true;
4433 if (
const Arg *A = Args.getLastArg(options::OPT__SLASH_diagnostics_classic,
4434 options::OPT__SLASH_diagnostics_column,
4435 options::OPT__SLASH_diagnostics_caret)) {
4436 switch (A->getOption().getID()) {
4437 case options::OPT__SLASH_diagnostics_caret:
4438 CaretDefault =
true;
4439 ColumnDefault =
true;
4441 case options::OPT__SLASH_diagnostics_column:
4442 CaretDefault =
false;
4443 ColumnDefault =
true;
4445 case options::OPT__SLASH_diagnostics_classic:
4446 CaretDefault =
false;
4447 ColumnDefault =
false;
4453 if (!Args.hasFlag(options::OPT_fcaret_diagnostics,
4454 options::OPT_fno_caret_diagnostics, CaretDefault))
4455 CmdArgs.push_back(
"-fno-caret-diagnostics");
4457 Args.addOptOutFlag(CmdArgs, options::OPT_fdiagnostics_fixit_info,
4458 options::OPT_fno_diagnostics_fixit_info);
4459 Args.addOptOutFlag(CmdArgs, options::OPT_fdiagnostics_show_option,
4460 options::OPT_fno_diagnostics_show_option);
4463 Args.getLastArg(options::OPT_fdiagnostics_show_category_EQ)) {
4464 CmdArgs.push_back(
"-fdiagnostics-show-category");
4465 CmdArgs.push_back(A->getValue());
4468 Args.addOptInFlag(CmdArgs, options::OPT_fdiagnostics_show_hotness,
4469 options::OPT_fno_diagnostics_show_hotness);
4472 Args.getLastArg(options::OPT_fdiagnostics_hotness_threshold_EQ)) {
4474 std::string(
"-fdiagnostics-hotness-threshold=") + A->getValue();
4475 CmdArgs.push_back(Args.MakeArgString(Opt));
4479 Args.getLastArg(options::OPT_fdiagnostics_misexpect_tolerance_EQ)) {
4481 std::string(
"-fdiagnostics-misexpect-tolerance=") + A->getValue();
4482 CmdArgs.push_back(Args.MakeArgString(Opt));
4485 if (
const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) {
4486 CmdArgs.push_back(
"-fdiagnostics-format");
4487 CmdArgs.push_back(A->getValue());
4488 if (StringRef(A->getValue()) ==
"sarif" ||
4489 StringRef(A->getValue()) ==
"SARIF")
4490 D.Diag(diag::warn_drv_sarif_format_unstable);
4493 if (
const Arg *A = Args.getLastArg(
4494 options::OPT_fdiagnostics_show_note_include_stack,
4495 options::OPT_fno_diagnostics_show_note_include_stack)) {
4496 const Option &O = A->getOption();
4497 if (O.matches(options::OPT_fdiagnostics_show_note_include_stack))
4498 CmdArgs.push_back(
"-fdiagnostics-show-note-include-stack");
4500 CmdArgs.push_back(
"-fno-diagnostics-show-note-include-stack");
4505 if (Args.hasArg(options::OPT_fansi_escape_codes))
4506 CmdArgs.push_back(
"-fansi-escape-codes");
4508 Args.addOptOutFlag(CmdArgs, options::OPT_fshow_source_location,
4509 options::OPT_fno_show_source_location);
4511 Args.addOptOutFlag(CmdArgs, options::OPT_fdiagnostics_show_line_numbers,
4512 options::OPT_fno_diagnostics_show_line_numbers);
4514 if (Args.hasArg(options::OPT_fdiagnostics_absolute_paths))
4515 CmdArgs.push_back(
"-fdiagnostics-absolute-paths");
4517 if (!Args.hasFlag(options::OPT_fshow_column, options::OPT_fno_show_column,
4519 CmdArgs.push_back(
"-fno-show-column");
4521 Args.addOptOutFlag(CmdArgs, options::OPT_fspell_checking,
4522 options::OPT_fno_spell_checking);
4524 Args.addLastArg(CmdArgs, options::OPT_warning_suppression_mappings_EQ);
4528 const ArgList &Args, Arg *&Arg) {
4529 Arg = Args.getLastArg(options::OPT_gsplit_dwarf, options::OPT_gsplit_dwarf_EQ,
4530 options::OPT_gno_split_dwarf);
4531 if (!Arg || Arg->getOption().matches(options::OPT_gno_split_dwarf))
4534 if (Arg->getOption().matches(options::OPT_gsplit_dwarf))
4537 StringRef
Value = Arg->getValue();
4538 if (
Value ==
"split")
4540 if (
Value ==
"single")
4543 D.Diag(diag::err_drv_unsupported_option_argument)
4544 << Arg->getSpelling() << Arg->getValue();
4549 const ArgList &Args, ArgStringList &CmdArgs,
4550 unsigned DwarfVersion) {
4551 auto *DwarfFormatArg =
4552 Args.getLastArg(options::OPT_gdwarf64, options::OPT_gdwarf32);
4553 if (!DwarfFormatArg)
4556 if (DwarfFormatArg->getOption().matches(options::OPT_gdwarf64)) {
4557 if (DwarfVersion < 3)
4558 D.Diag(diag::err_drv_argument_only_allowed_with)
4559 << DwarfFormatArg->getAsString(Args) <<
"DWARFv3 or greater";
4560 else if (!
T.isArch64Bit())
4561 D.Diag(diag::err_drv_argument_only_allowed_with)
4562 << DwarfFormatArg->getAsString(Args) <<
"64 bit architecture";
4563 else if (!
T.isOSBinFormatELF())
4564 D.Diag(diag::err_drv_argument_only_allowed_with)
4565 << DwarfFormatArg->getAsString(Args) <<
"ELF platforms";
4568 DwarfFormatArg->render(Args, CmdArgs);
4573 const ArgList &Args,
bool IRInput, ArgStringList &CmdArgs,
4575 llvm::codegenoptions::DebugInfoKind &DebugInfoKind,
4577 if (Args.hasFlag(options::OPT_fdebug_info_for_profiling,
4578 options::OPT_fno_debug_info_for_profiling,
false) &&
4580 Args.getLastArg(options::OPT_fdebug_info_for_profiling), Args,
D, TC))
4581 CmdArgs.push_back(
"-fdebug-info-for-profiling");
4594 bool SplitDWARFInlining =
4595 Args.hasFlag(options::OPT_fsplit_dwarf_inlining,
4596 options::OPT_fno_split_dwarf_inlining,
false);
4601 if (IRInput || Args.hasArg(options::OPT_g_Group)) {
4607 SplitDWARFInlining =
false;
4610 if (
const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
4611 DebugInfoKind = llvm::codegenoptions::DebugInfoConstructor;
4615 A->getOption().matches(options::OPT_gN_Group)) {
4621 if (DebugInfoKind == llvm::codegenoptions::NoDebugInfo ||
4622 DebugInfoKind == llvm::codegenoptions::DebugDirectivesOnly ||
4623 (DebugInfoKind == llvm::codegenoptions::DebugLineTablesOnly &&
4624 SplitDWARFInlining))
4630 bool HasDebuggerTuning =
false;
4632 Args.getLastArg(options::OPT_gTune_Group, options::OPT_ggdbN_Group)) {
4633 HasDebuggerTuning =
true;
4635 if (A->getOption().matches(options::OPT_glldb))
4636 DebuggerTuning = llvm::DebuggerKind::LLDB;
4637 else if (A->getOption().matches(options::OPT_gsce))
4638 DebuggerTuning = llvm::DebuggerKind::SCE;
4639 else if (A->getOption().matches(options::OPT_gdbx))
4640 DebuggerTuning = llvm::DebuggerKind::DBX;
4642 DebuggerTuning = llvm::DebuggerKind::GDB;
4647 bool EmitDwarf =
false;
4651 bool EmitCodeView =
false;
4652 if (
const Arg *A = Args.getLastArg(options::OPT_gcodeview))
4657 if (!EmitCodeView && !EmitDwarf &&
4658 DebugInfoKind != llvm::codegenoptions::NoDebugInfo) {
4660 case llvm::codegenoptions::DIF_CodeView:
4661 EmitCodeView =
true;
4663 case llvm::codegenoptions::DIF_DWARF:
4669 unsigned RequestedDWARFVersion = 0;
4670 unsigned EffectiveDWARFVersion = 0;
4675 EffectiveDWARFVersion =
4678 Args.ClaimAllArgs(options::OPT_fdebug_default_version);
4682 if (RequestedDWARFVersion == 0 &&
4683 DebugInfoKind == llvm::codegenoptions::DebugDirectivesOnly)
4684 DebugInfoKind = llvm::codegenoptions::NoDebugInfo;
4688 if (
const Arg *A = Args.getLastArg(options::OPT_gstrict_dwarf))
4690 if (Args.hasFlag(options::OPT_gstrict_dwarf, options::OPT_gno_strict_dwarf,
4691 DebuggerTuning == llvm::DebuggerKind::DBX))
4692 CmdArgs.push_back(
"-gstrict-dwarf");
4695 Args.ClaimAllArgs(options::OPT_g_flags_Group);
4703 if (
const Arg *A = Args.getLastArg(options::OPT_gcolumn_info))
4705 if (!Args.hasFlag(options::OPT_gcolumn_info, options::OPT_gno_column_info,
4707 (DebuggerTuning != llvm::DebuggerKind::SCE &&
4708 DebuggerTuning != llvm::DebuggerKind::DBX)))
4709 CmdArgs.push_back(
"-gno-column-info");
4712 if (Args.hasFlag(options::OPT_gmodules, options::OPT_gno_modules,
false)) {
4717 if (DebugInfoKind != llvm::codegenoptions::DebugLineTablesOnly &&
4718 DebugInfoKind != llvm::codegenoptions::DebugDirectivesOnly) {
4719 DebugInfoKind = llvm::codegenoptions::DebugInfoConstructor;
4720 CmdArgs.push_back(
"-dwarf-ext-refs");
4721 CmdArgs.push_back(
"-fmodule-format=obj");
4726 if (
T.isOSBinFormatELF() && SplitDWARFInlining)
4727 CmdArgs.push_back(
"-fsplit-dwarf-inlining");
4734 bool NeedFullDebug = Args.hasFlag(
4735 options::OPT_fstandalone_debug, options::OPT_fno_standalone_debug,
4736 DebuggerTuning == llvm::DebuggerKind::LLDB ||
4738 if (
const Arg *A = Args.getLastArg(options::OPT_fstandalone_debug))
4741 if (DebugInfoKind == llvm::codegenoptions::LimitedDebugInfo ||
4742 DebugInfoKind == llvm::codegenoptions::DebugInfoConstructor) {
4743 if (Args.hasFlag(options::OPT_fno_eliminate_unused_debug_types,
4744 options::OPT_feliminate_unused_debug_types,
false))
4745 DebugInfoKind = llvm::codegenoptions::UnusedTypeInfo;
4746 else if (NeedFullDebug)
4747 DebugInfoKind = llvm::codegenoptions::FullDebugInfo;
4750 if (Args.hasFlag(options::OPT_gembed_source, options::OPT_gno_embed_source,
4756 const Arg *A = Args.getLastArg(options::OPT_gembed_source);
4757 if (RequestedDWARFVersion < 5)
4758 D.Diag(diag::err_drv_argument_only_allowed_with)
4759 << A->getAsString(Args) <<
"-gdwarf-5";
4760 else if (EffectiveDWARFVersion < 5)
4763 D.Diag(diag::warn_drv_dwarf_version_limited_by_target)
4765 << EffectiveDWARFVersion;
4767 CmdArgs.push_back(
"-gembed-source");
4771 CmdArgs.push_back(
"-gcodeview");
4773 Args.addOptInFlag(CmdArgs, options::OPT_gcodeview_ghash,
4774 options::OPT_gno_codeview_ghash);
4776 Args.addOptOutFlag(CmdArgs, options::OPT_gcodeview_command_line,
4777 options::OPT_gno_codeview_command_line);
4780 Args.addOptOutFlag(CmdArgs, options::OPT_ginline_line_tables,
4781 options::OPT_gno_inline_line_tables);
4785 DebugInfoKind <= llvm::codegenoptions::DebugDirectivesOnly)
4786 DebugInfoKind = llvm::codegenoptions::DebugLineTablesOnly;
4794 T.isOSAIX() && !HasDebuggerTuning
4795 ? llvm::DebuggerKind::Default
4799 if (Args.hasFlag(options::OPT_fdebug_macro, options::OPT_fno_debug_macro,
4803 CmdArgs.push_back(
"-debug-info-macro");
4806 const auto *PubnamesArg =
4807 Args.getLastArg(options::OPT_ggnu_pubnames, options::OPT_gno_gnu_pubnames,
4808 options::OPT_gpubnames, options::OPT_gno_pubnames);
4811 const bool OptionSet =
4813 (PubnamesArg->getOption().matches(options::OPT_gpubnames) ||
4814 PubnamesArg->getOption().matches(options::OPT_ggnu_pubnames)));
4815 if ((DebuggerTuning != llvm::DebuggerKind::LLDB || OptionSet) &&
4817 (!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) &&
4818 !PubnamesArg->getOption().matches(options::OPT_gno_pubnames))))
4819 CmdArgs.push_back(PubnamesArg && PubnamesArg->getOption().matches(
4820 options::OPT_gpubnames)
4822 :
"-ggnu-pubnames");
4824 const auto *SimpleTemplateNamesArg =
4825 Args.getLastArg(options::OPT_gsimple_template_names,
4826 options::OPT_gno_simple_template_names);
4827 bool ForwardTemplateParams = DebuggerTuning == llvm::DebuggerKind::SCE;
4828 if (SimpleTemplateNamesArg &&
4830 const auto &Opt = SimpleTemplateNamesArg->getOption();
4831 if (Opt.matches(options::OPT_gsimple_template_names)) {
4832 ForwardTemplateParams =
true;
4833 CmdArgs.push_back(
"-gsimple-template-names=simple");
4838 bool UseDebugTemplateAlias =
4839 DebuggerTuning == llvm::DebuggerKind::SCE && RequestedDWARFVersion >= 4;
4840 if (
const auto *DebugTemplateAlias = Args.getLastArg(
4841 options::OPT_gtemplate_alias, options::OPT_gno_template_alias)) {
4845 const auto &Opt = DebugTemplateAlias->getOption();
4846 UseDebugTemplateAlias = Opt.matches(options::OPT_gtemplate_alias);
4849 if (UseDebugTemplateAlias)
4850 CmdArgs.push_back(
"-gtemplate-alias");
4852 if (
const Arg *A = Args.getLastArg(options::OPT_gsrc_hash_EQ)) {
4853 StringRef
v = A->getValue();
4854 CmdArgs.push_back(Args.MakeArgString(
"-gsrc-hash=" +
v));
4857 Args.addOptInFlag(CmdArgs, options::OPT_fdebug_ranges_base_address,
4858 options::OPT_fno_debug_ranges_base_address);
4862 if (
const Arg *A = Args.getLastArg(options::OPT_gdwarf_aranges);
4864 CmdArgs.push_back(
"-mllvm");
4865 CmdArgs.push_back(
"-generate-arange-section");
4868 Args.addOptInFlag(CmdArgs, options::OPT_fforce_dwarf_frame,
4869 options::OPT_fno_force_dwarf_frame);
4871 bool EnableTypeUnits =
false;
4872 if (Args.hasFlag(options::OPT_fdebug_types_section,
4873 options::OPT_fno_debug_types_section,
false)) {
4874 if (!(
T.isOSBinFormatELF() ||
T.isOSBinFormatWasm())) {
4875 D.Diag(diag::err_drv_unsupported_opt_for_target)
4876 << Args.getLastArg(options::OPT_fdebug_types_section)
4880 Args.getLastArg(options::OPT_fdebug_types_section), Args,
D,
4882 EnableTypeUnits =
true;
4883 CmdArgs.push_back(
"-mllvm");
4884 CmdArgs.push_back(
"-generate-type-units");
4889 Args.getLastArg(options::OPT_gomit_unreferenced_methods,
4890 options::OPT_gno_omit_unreferenced_methods))
4892 if (Args.hasFlag(options::OPT_gomit_unreferenced_methods,
4893 options::OPT_gno_omit_unreferenced_methods,
false) &&
4894 (DebugInfoKind == llvm::codegenoptions::DebugInfoConstructor ||
4895 DebugInfoKind == llvm::codegenoptions::LimitedDebugInfo) &&
4897 CmdArgs.push_back(
"-gomit-unreferenced-methods");
4903 if (!Args.hasFlag(options::OPT_fdwarf_directory_asm,
4904 options::OPT_fno_dwarf_directory_asm,
4906 CmdArgs.push_back(
"-fno-dwarf-directory-asm");
4910 if (ForwardTemplateParams)
4911 CmdArgs.push_back(
"-debug-forward-template-params");
4915 if (DebuggerTuning == llvm::DebuggerKind::SCE)
4916 CmdArgs.push_back(
"-dwarf-explicit-import");
4922 if (Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc,
false)) {
4923 if (TC.
getTriple().isOSBinFormatELF() ||
4924 TC.
getTriple().isWindowsMSVCEnvironment()) {
4925 if (DebugInfoKind >= llvm::codegenoptions::DebugInfoConstructor)
4926 CmdArgs.push_back(
"-fjmc");
4927 else if (
D.IsCLMode())
4928 D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo) <<
"/JMC"
4931 D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo) <<
"-fjmc"
4934 D.Diag(clang::diag::warn_drv_fjmc_for_elf_only);
4939 const char *DebugCompilationDir =
4951 ArgStringList &CmdArgs) {
4952 unsigned RTOptionID = options::OPT__SLASH_MT;
4954 if (Args.hasArg(options::OPT__SLASH_LDd))
4957 RTOptionID = options::OPT__SLASH_MTd;
4959 if (Arg *A = Args.getLastArg(options::OPT__SLASH_M_Group))
4960 RTOptionID = A->getOption().getID();
4962 if (Arg *A = Args.getLastArg(options::OPT_fms_runtime_lib_EQ)) {
4963 RTOptionID = llvm::StringSwitch<unsigned>(A->getValue())
4964 .Case(
"static", options::OPT__SLASH_MT)
4965 .Case(
"static_dbg", options::OPT__SLASH_MTd)
4966 .Case(
"dll", options::OPT__SLASH_MD)
4967 .Case(
"dll_dbg", options::OPT__SLASH_MDd)
4968 .Default(options::OPT__SLASH_MT);
4971 StringRef FlagForCRT;
4972 switch (RTOptionID) {
4973 case options::OPT__SLASH_MD:
4974 if (Args.hasArg(options::OPT__SLASH_LDd))
4975 CmdArgs.push_back(
"-D_DEBUG");
4976 CmdArgs.push_back(
"-D_MT");
4977 CmdArgs.push_back(
"-D_DLL");
4978 FlagForCRT =
"--dependent-lib=msvcrt";
4980 case options::OPT__SLASH_MDd:
4981 CmdArgs.push_back(
"-D_DEBUG");
4982 CmdArgs.push_back(
"-D_MT");
4983 CmdArgs.push_back(
"-D_DLL");
4984 FlagForCRT =
"--dependent-lib=msvcrtd";
4986 case options::OPT__SLASH_MT:
4987 if (Args.hasArg(options::OPT__SLASH_LDd))
4988 CmdArgs.push_back(
"-D_DEBUG");
4989 CmdArgs.push_back(
"-D_MT");
4990 CmdArgs.push_back(
"-flto-visibility-public-std");
4991 FlagForCRT =
"--dependent-lib=libcmt";
4993 case options::OPT__SLASH_MTd:
4994 CmdArgs.push_back(
"-D_DEBUG");
4995 CmdArgs.push_back(
"-D_MT");
4996 CmdArgs.push_back(
"-flto-visibility-public-std");
4997 FlagForCRT =
"--dependent-lib=libcmtd";
5000 llvm_unreachable(
"Unexpected option ID.");
5003 if (Args.hasArg(options::OPT_fms_omit_default_lib)) {
5004 CmdArgs.push_back(
"-D_VC_NODEFAULTLIB");
5006 CmdArgs.push_back(FlagForCRT.data());
5011 CmdArgs.push_back(
"--dependent-lib=oldnames");
5018 CmdArgs.push_back(
"--dependent-lib=softintrin");
5023 const ArgList &Args,
const char *LinkingOutput)
const {
5025 const llvm::Triple &RawTriple = TC.
getTriple();
5027 const std::string &TripleStr = Triple.getTriple();
5030 Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
5032 ArgStringList CmdArgs;
5034 assert(Inputs.size() >= 1 &&
"Must have at least one input.");
5046 bool IsExtractAPI = isa<ExtractAPIJobAction>(JA);
5049 bool IsHostOffloadingAction =
5052 Args.hasFlag(options::OPT_offload_new_driver,
5053 options::OPT_no_offload_new_driver,
false));
5056 Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
false);
5058 auto LTOMode = IsDeviceOffloadAction ?
D.getOffloadLTOMode() :
D.getLTOMode();
5063 InputInfo ExtractAPIPlaceholderInput(Inputs[0].getType(),
"extract-api",
5067 IsExtractAPI ? ExtractAPIPlaceholderInput : Inputs[0];
5071 const InputInfo *CudaDeviceInput =
nullptr;
5072 const InputInfo *OpenMPDeviceInput =
nullptr;
5074 if (&I == &Input || I.
getType() == types::TY_Nothing) {
5076 }
else if (IsExtractAPI) {
5077 auto ExpectedInputType = ExtractAPIPlaceholderInput.
getType();
5078 if (I.getType() != ExpectedInputType) {
5079 D.Diag(diag::err_drv_extract_api_wrong_kind)
5083 ExtractAPIInputs.push_back(I);
5084 }
else if (IsHostOffloadingAction) {
5085 HostOffloadingInputs.push_back(I);
5086 }
else if ((IsCuda || IsHIP) && !CudaDeviceInput) {
5087 CudaDeviceInput = &I;
5088 }
else if (IsOpenMPDevice && !OpenMPDeviceInput) {
5089 OpenMPDeviceInput = &I;
5091 llvm_unreachable(
"unexpectedly given multiple inputs");
5095 const llvm::Triple *AuxTriple =
5097 bool IsWindowsMSVC = RawTriple.isWindowsMSVCEnvironment();
5098 bool IsIAMCU = RawTriple.isOSIAMCU();
5103 if (IsCuda || IsHIP)
5104 IsWindowsMSVC |= AuxTriple && AuxTriple->isWindowsMSVCEnvironment();
5108 D.Diag(diag::err_drv_clang_unsupported) <<
"C++ for IAMCU";
5113 CmdArgs.push_back(
"-cc1");
5116 CmdArgs.push_back(
"-triple");
5117 CmdArgs.push_back(Args.MakeArgString(TripleStr));
5119 if (
const Arg *MJ = Args.getLastArg(options::OPT_MJ)) {
5120 DumpCompilationDatabase(
C, MJ->getValue(), TripleStr, Output, Input, Args);
5121 Args.ClaimAllArgs(options::OPT_MJ);
5122 }
else if (
const Arg *GenCDBFragment =
5123 Args.getLastArg(options::OPT_gen_cdb_fragment_path)) {
5124 DumpCompilationDatabaseFragmentToDir(GenCDBFragment->getValue(),
C,
5125 TripleStr, Output, Input, Args);
5126 Args.ClaimAllArgs(options::OPT_gen_cdb_fragment_path);
5129 if (IsCuda || IsHIP) {
5132 std::string NormalizedTriple;
5150 assert(CTC &&
"Expected valid CUDA Toolchain.");
5152 CmdArgs.push_back(Args.MakeArgString(
5153 Twine(
"-target-sdk-version=") +
5161 CmdArgs.push_back(
"-fcuda-allow-variadic-functions");
5164 CmdArgs.push_back(
"-aux-triple");
5165 CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
5170 getToolChain().getTriple().getVendor() == llvm::Triple::AMD))) {
5172 if (Args.getLastArg(options::OPT_mprintf_kind_EQ)) {
5173 CmdArgs.push_back(Args.MakeArgString(
5175 Args.getLastArgValue(options::OPT_mprintf_kind_EQ)));
5178 Args.MakeArgString(
"-Werror=format-invalid-specifier"));
5184 if (
const Arg *PF = Args.getLastArg(options::OPT_mprintf_kind_EQ))
5187 if (Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl,
false)) {
5188 CmdArgs.push_back(
"-fsycl-is-device");
5190 if (Arg *A = Args.getLastArg(options::OPT_sycl_std_EQ)) {
5191 A->render(Args, CmdArgs);
5194 CmdArgs.push_back(
"-sycl-std=2020");
5198 if (Args.hasArg(options::OPT_fclangir))
5199 CmdArgs.push_back(
"-fclangir");
5201 if (IsOpenMPDevice) {
5203 std::string NormalizedTriple =
5207 CmdArgs.push_back(
"-aux-triple");
5208 CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
5211 if (Triple.isOSWindows() && (Triple.getArch() == llvm::Triple::arm ||
5212 Triple.getArch() == llvm::Triple::thumb)) {
5213 unsigned Offset = Triple.getArch() == llvm::Triple::arm ? 4 : 6;
5214 unsigned Version = 0;
5216 Triple.getArchName().substr(Offset).consumeInteger(10, Version);
5217 if (Failure || Version < 7)
5218 D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName()
5228 if (Triple.isSPIR() || Triple.isSPIRV())
5229 CmdArgs.push_back(
"-Wspir-compat");
5232 RewriteKind rewriteKind = RK_None;
5234 bool UnifiedLTO =
false;
5236 UnifiedLTO = Args.hasFlag(options::OPT_funified_lto,
5237 options::OPT_fno_unified_lto, Triple.isPS());
5239 CmdArgs.push_back(
"-funified-lto");
5249 if (!isa<AssembleJobAction>(JA)) {
5253 Args.ClaimAllArgs(options::OPT_mrelax_all);
5254 Args.ClaimAllArgs(options::OPT_mno_relax_all);
5255 Args.ClaimAllArgs(options::OPT_mincremental_linker_compatible);
5256 Args.ClaimAllArgs(options::OPT_mno_incremental_linker_compatible);
5257 switch (
C.getDefaultToolChain().getArch()) {
5258 case llvm::Triple::arm:
5259 case llvm::Triple::armeb:
5260 case llvm::Triple::thumb:
5261 case llvm::Triple::thumbeb:
5262 Args.ClaimAllArgs(options::OPT_mimplicit_it_EQ);
5268 Args.ClaimAllArgs(options::OPT_Wa_COMMA);
5269 Args.ClaimAllArgs(options::OPT_Xassembler);
5270 Args.ClaimAllArgs(options::OPT_femit_dwarf_unwind_EQ);
5273 if (isa<AnalyzeJobAction>(JA)) {
5274 assert(JA.
getType() == types::TY_Plist &&
"Invalid output type.");
5275 CmdArgs.push_back(
"-analyze");
5276 }
else if (isa<MigrateJobAction>(JA)) {
5277 CmdArgs.push_back(
"-migrate");
5278 }
else if (isa<PreprocessJobAction>(JA)) {
5279 if (Output.
getType() == types::TY_Dependencies)
5280 CmdArgs.push_back(
"-Eonly");
5282 CmdArgs.push_back(
"-E");
5283 if (Args.hasArg(options::OPT_rewrite_objc) &&
5284 !Args.hasArg(options::OPT_g_Group))
5285 CmdArgs.push_back(
"-P");
5286 else if (JA.
getType() == types::TY_PP_CXXHeaderUnit)
5287 CmdArgs.push_back(
"-fdirectives-only");
5289 }
else if (isa<AssembleJobAction>(JA)) {
5290 CmdArgs.push_back(
"-emit-obj");
5295 (void)Args.hasArg(options::OPT_force__cpusubtype__ALL);
5296 }
else if (isa<PrecompileJobAction>(JA)) {
5297 if (JA.
getType() == types::TY_Nothing)
5298 CmdArgs.push_back(
"-fsyntax-only");
5299 else if (JA.
getType() == types::TY_ModuleFile)
5300 CmdArgs.push_back(
"-emit-module-interface");
5301 else if (JA.
getType() == types::TY_HeaderUnit)
5302 CmdArgs.push_back(
"-emit-header-unit");
5304 CmdArgs.push_back(
"-emit-pch");
5305 }
else if (isa<VerifyPCHJobAction>(JA)) {
5306 CmdArgs.push_back(
"-verify-pch");
5307 }
else if (isa<ExtractAPIJobAction>(JA)) {
5308 assert(JA.
getType() == types::TY_API_INFO &&
5309 "Extract API actions must generate a API information.");
5310 CmdArgs.push_back(
"-extract-api");
5312 if (Arg *PrettySGFArg = Args.getLastArg(options::OPT_emit_pretty_sgf))
5313 PrettySGFArg->render(Args, CmdArgs);
5315 Arg *SymbolGraphDirArg = Args.getLastArg(options::OPT_symbol_graph_dir_EQ);
5317 if (Arg *ProductNameArg = Args.getLastArg(options::OPT_product_name_EQ))
5318 ProductNameArg->render(Args, CmdArgs);
5319 if (Arg *ExtractAPIIgnoresFileArg =
5320 Args.getLastArg(options::OPT_extract_api_ignores_EQ))
5321 ExtractAPIIgnoresFileArg->render(Args, CmdArgs);
5322 if (Arg *EmitExtensionSymbolGraphs =
5323 Args.getLastArg(options::OPT_emit_extension_symbol_graphs)) {
5324 if (!SymbolGraphDirArg)
5325 D.Diag(diag::err_drv_missing_symbol_graph_dir);
5327 EmitExtensionSymbolGraphs->render(Args, CmdArgs);
5329 if (SymbolGraphDirArg)
5330 SymbolGraphDirArg->render(Args, CmdArgs);
5332 assert((isa<CompileJobAction>(JA) || isa<BackendJobAction>(JA)) &&
5333 "Invalid action for clang tool.");
5334 if (JA.
getType() == types::TY_Nothing) {
5335 CmdArgs.push_back(
"-fsyntax-only");
5336 }
else if (JA.
getType() == types::TY_LLVM_IR ||
5337 JA.
getType() == types::TY_LTO_IR) {
5338 CmdArgs.push_back(
"-emit-llvm");
5339 }
else if (JA.
getType() == types::TY_LLVM_BC ||
5340 JA.
getType() == types::TY_LTO_BC) {
5342 if (Triple.isAMDGCN() && IsOpenMPDevice && Args.hasArg(options::OPT_S) &&
5343 Args.hasArg(options::OPT_emit_llvm)) {
5344 CmdArgs.push_back(
"-emit-llvm");
5346 CmdArgs.push_back(
"-emit-llvm-bc");
5348 }
else if (JA.
getType() == types::TY_IFS ||
5349 JA.
getType() == types::TY_IFS_CPP) {
5351 Args.hasArg(options::OPT_interface_stub_version_EQ)
5352 ? Args.getLastArgValue(options::OPT_interface_stub_version_EQ)
5354 CmdArgs.push_back(
"-emit-interface-stubs");
5356 Args.MakeArgString(Twine(
"-interface-stub-version=") + ArgStr.str()));
5357 }
else if (JA.
getType() == types::TY_PP_Asm) {
5358 CmdArgs.push_back(
"-S");
5359 }
else if (JA.
getType() == types::TY_AST) {
5360 CmdArgs.push_back(
"-emit-pch");
5361 }
else if (JA.
getType() == types::TY_ModuleFile) {
5362 CmdArgs.push_back(
"-module-file-info");
5363 }
else if (JA.
getType() == types::TY_RewrittenObjC) {
5364 CmdArgs.push_back(
"-rewrite-objc");
5365 rewriteKind = RK_NonFragile;
5366 }
else if (JA.
getType() == types::TY_RewrittenLegacyObjC) {
5367 CmdArgs.push_back(
"-rewrite-objc");
5368 rewriteKind = RK_Fragile;
5369 }
else if (JA.
getType() == types::TY_CIR) {
5370 CmdArgs.push_back(
"-emit-cir");
5372 assert(JA.
getType() == types::TY_PP_Asm &&
"Unexpected output type!");
5379 if (JA.
getType() == types::TY_LLVM_BC)
5380 CmdArgs.push_back(
"-emit-llvm-uselists");
5384 !Args.hasFlag(options::OPT_offload_new_driver,
5385 options::OPT_no_offload_new_driver,
false) &&
5386 !Triple.isAMDGPU()) {
5387 D.Diag(diag::err_drv_unsupported_opt_for_target)
5388 << Args.getLastArg(options::OPT_foffload_lto,
5389 options::OPT_foffload_lto_EQ)
5391 << Triple.getTriple();
5392 }
else if (Triple.isNVPTX() && !IsRDCMode &&
5394 D.Diag(diag::err_drv_unsupported_opt_for_language_mode)
5395 << Args.getLastArg(options::OPT_foffload_lto,
5396 options::OPT_foffload_lto_EQ)
5401 CmdArgs.push_back(Args.MakeArgString(
5402 Twine(
"-flto=") + (LTOMode ==
LTOK_Thin ?
"thin" :
"full")));
5405 if (!RawTriple.isPS4() ||
5406 (
D.getLTOMode() ==
LTOK_Full) || !UnifiedLTO)
5407 CmdArgs.push_back(
"-flto-unit");
5412 Args.AddLastArg(CmdArgs, options::OPT_dumpdir);
5414 if (
const Arg *A = Args.getLastArg(options::OPT_fthinlto_index_EQ)) {
5416 D.Diag(diag::err_drv_arg_requires_bitcode_input) << A->getAsString(Args);
5417 Args.AddLastArg(CmdArgs, options::OPT_fthinlto_index_EQ);
5421 Args.addOptInFlag(CmdArgs, options::OPT_mregnames,
5422 options::OPT_mno_regnames);
5424 if (Args.getLastArg(options::OPT_fthin_link_bitcode_EQ))
5425 Args.AddLastArg(CmdArgs, options::OPT_fthin_link_bitcode_EQ);
5427 if (Args.getLastArg(options::OPT_save_temps_EQ))
5428 Args.AddLastArg(CmdArgs, options::OPT_save_temps_EQ);
5430 auto *MemProfArg = Args.getLastArg(options::OPT_fmemory_profile,
5431 options::OPT_fmemory_profile_EQ,
5432 options::OPT_fno_memory_profile);
5434 !MemProfArg->getOption().matches(options::OPT_fno_memory_profile))
5435 MemProfArg->render(Args, CmdArgs);
5437 if (
auto *MemProfUseArg =
5438 Args.getLastArg(options::OPT_fmemory_profile_use_EQ)) {
5440 D.Diag(diag::err_drv_argument_not_allowed_with)
5441 << MemProfUseArg->getAsString(Args) << MemProfArg->getAsString(Args);
5442 if (
auto *PGOInstrArg = Args.getLastArg(options::OPT_fprofile_generate,
5443 options::OPT_fprofile_generate_EQ))
5444 D.Diag(diag::err_drv_argument_not_allowed_with)
5445 << MemProfUseArg->getAsString(Args) << PGOInstrArg->getAsString(Args);
5446 MemProfUseArg->render(Args, CmdArgs);
5451 if (
C.getDriver().embedBitcodeInObject() && !IsUsingLTO &&
5452 (isa<BackendJobAction>(JA) || isa<AssembleJobAction>(JA))) {
5454 Args.AddLastArg(CmdArgs, options::OPT_fembed_bitcode_EQ);
5456 CmdArgs.push_back(
"-disable-llvm-passes");
5463 static const constexpr unsigned kBitcodeOptionIgnorelist[] = {
5464 options::OPT_mkernel,
5465 options::OPT_fapple_kext,
5466 options::OPT_ffunction_sections,
5467 options::OPT_fno_function_sections,
5468 options::OPT_fdata_sections,
5469 options::OPT_fno_data_sections,
5470 options::OPT_fbasic_block_sections_EQ,
5471 options::OPT_funique_internal_linkage_names,
5472 options::OPT_fno_unique_internal_linkage_names,
5473 options::OPT_funique_section_names,
5474 options::OPT_fno_unique_section_names,
5475 options::OPT_funique_basic_block_section_names,
5476 options::OPT_fno_unique_basic_block_section_names,
5477 options::OPT_mrestrict_it,
5478 options::OPT_mno_restrict_it,
5479 options::OPT_mstackrealign,
5480 options::OPT_mno_stackrealign,
5481 options::OPT_mstack_alignment,
5482 options::OPT_mcmodel_EQ,
5483 options::OPT_mlong_calls,
5484 options::OPT_mno_long_calls,
5485 options::OPT_ggnu_pubnames,
5486 options::OPT_gdwarf_aranges,
5487 options::OPT_fdebug_types_section,
5488 options::OPT_fno_debug_types_section,
5489 options::OPT_fdwarf_directory_asm,
5490 options::OPT_fno_dwarf_directory_asm,
5491 options::OPT_mrelax_all,
5492 options::OPT_mno_relax_all,
5493 options::OPT_ftrap_function_EQ,
5494 options::OPT_ffixed_r9,
5495 options::OPT_mfix_cortex_a53_835769,
5496 options::OPT_mno_fix_cortex_a53_835769,
5497 options::OPT_ffixed_x18,
5498 options::OPT_mglobal_merge,
5499 options::OPT_mno_global_merge,
5500 options::OPT_mred_zone,
5501 options::OPT_mno_red_zone,
5502 options::OPT_Wa_COMMA,
5503 options::OPT_Xassembler,
5506 for (
const auto &A : Args)
5507 if (llvm::is_contained(kBitcodeOptionIgnorelist, A->getOption().getID()))
5508 D.Diag(diag::err_drv_unsupported_embed_bitcode) << A->getSpelling();
5511 Args.addOptOutFlag(CmdArgs, options::OPT_foptimize_sibling_calls,
5512 options::OPT_fno_optimize_sibling_calls);
5520 case llvm::Triple::arm:
5521 case llvm::Triple::armeb:
5522 case llvm::Triple::thumbeb:
5523 RenderARMABI(
D, Triple, Args, CmdArgs);
5525 case llvm::Triple::aarch64:
5526 case llvm::Triple::aarch64_32:
5527 case llvm::Triple::aarch64_be:
5528 RenderAArch64ABI(Triple, Args, CmdArgs);
5533 if (
const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
5534 if (A->getOption().matches(options::OPT_O4)) {
5535 CmdArgs.push_back(
"-O3");
5536 D.Diag(diag::warn_O4_is_O3);
5538 A->render(Args, CmdArgs);
5543 if (Output.
getType() == types::TY_Dependencies) {
5546 CmdArgs.push_back(
"-o");
5549 assert(Output.
isNothing() &&
"Input output.");
5552 for (
const auto &II : Inputs) {
5554 if (II.isFilename())
5555 CmdArgs.push_back(II.getFilename());
5557 II.getInputArg().renderAsInput(Args, CmdArgs);
5560 C.addCommand(std::make_unique<Command>(
5562 CmdArgs, Inputs, Output,
D.getPrependArg()));
5566 if (
C.getDriver().embedBitcodeMarkerOnly() && !IsUsingLTO)
5567 CmdArgs.push_back(
"-fembed-bitcode=marker");
5572 if (!
C.isForDiagnostics())
5573 CmdArgs.push_back(
"-disable-free");
5574 CmdArgs.push_back(
"-clear-ast-before-backend");
5577 const bool IsAssertBuild =
false;
5579 const bool IsAssertBuild =
true;
5583 if (Args.hasFlag(options::OPT_fno_verify_intermediate_code,
5584 options::OPT_fverify_intermediate_code, !IsAssertBuild)) {
5585 CmdArgs.push_back(
"-disable-llvm-verifier");
5589 if (Args.hasFlag(options::OPT_fdiscard_value_names,
5590 options::OPT_fno_discard_value_names, !IsAssertBuild)) {
5591 if (Args.hasArg(options::OPT_fdiscard_value_names) &&
5593 return types::isLLVMIR(II.getType());
5595 D.Diag(diag::warn_ignoring_fdiscard_for_bitcode);
5597 CmdArgs.push_back(
"-discard-value-names");
5602 CmdArgs.push_back(
"-main-file-name");
5607 if (Args.hasArg(options::OPT_static))
5608 CmdArgs.push_back(
"-static-define");
5610 if (Args.hasArg(options::OPT_municode))
5611 CmdArgs.push_back(
"-DUNICODE");
5613 if (isa<AnalyzeJobAction>(JA))
5616 if (isa<AnalyzeJobAction>(JA) ||
5617 (isa<PreprocessJobAction>(JA) && Args.hasArg(options::OPT__analyze)))
5618 CmdArgs.push_back(
"-setup-static-analyzer");
5623 bool FoundAnalyzerConfig =
false;
5624 for (
auto *Arg : Args.filtered(options::OPT_Xclang))
5625 if (StringRef(Arg->getValue()) ==
"-analyzer-config") {
5626 FoundAnalyzerConfig =
true;
5629 if (!FoundAnalyzerConfig)
5630 for (
auto *Arg : Args.filtered(options::OPT_Xanalyzer))
5631 if (StringRef(Arg->getValue()) ==
"-analyzer-config") {
5632 FoundAnalyzerConfig =
true;
5635 if (FoundAnalyzerConfig)
5636 CmdArgs.push_back(
"-analyzer-config-compatibility-mode=true");
5641 assert(FunctionAlignment <= 31 &&
"function alignment will be truncated!");
5642 if (FunctionAlignment) {
5643 CmdArgs.push_back(
"-function-alignment");
5644 CmdArgs.push_back(Args.MakeArgString(std::to_string(FunctionAlignment)));
5649 if (
const Arg *A = Args.getLastArg(options::OPT_falign_loops_EQ)) {
5651 if (StringRef(A->getValue()).getAsInteger(10,
Value) ||
Value > 65536)
5653 << A->getAsString(Args) << A->getValue();
5655 TC.
getDriver().
Diag(diag::err_drv_alignment_not_power_of_two)
5656 << A->getAsString(Args) << A->getValue();
5659 CmdArgs.push_back(Args.MakeArgString(
"-falign-loops=" +
5660 Twine(std::min(
Value, 65536u))));
5663 if (Triple.isOSzOS()) {
5672 auto findMacroDefinition = [&](
const std::string &Macro) {
5673 auto MacroDefs = Args.getAllArgValues(options::OPT_D);
5674 return llvm::any_of(MacroDefs, [&](
const std::string &M) {
5675 return M == Macro || M.find(Macro +
'=') != std::string::npos;
5680 if (!findMacroDefinition(
"_UNIX03_WITHDRAWN"))
5681 CmdArgs.push_back(
"-D_UNIX03_WITHDRAWN");
5683 if (!findMacroDefinition(
"_OPEN_DEFAULT"))
5684 CmdArgs.push_back(
"-D_OPEN_DEFAULT");
5687 if (!findMacroDefinition(
"_XOPEN_SOURCE"))
5688 CmdArgs.push_back(
"-D_XOPEN_SOURCE=600");
5692 llvm::Reloc::Model RelocationModel;
5695 std::tie(RelocationModel, PICLevel, IsPIE) =
ParsePICArgs(TC, Args);
5696 Arg *LastPICDataRelArg =
5697 Args.getLastArg(options::OPT_mno_pic_data_is_text_relative,
5698 options::OPT_mpic_data_is_text_relative);
5699 bool NoPICDataIsTextRelative =
false;
5700 if (LastPICDataRelArg) {
5701 if (LastPICDataRelArg->getOption().matches(
5702 options::OPT_mno_pic_data_is_text_relative)) {
5703 NoPICDataIsTextRelative =
true;
5705 D.Diag(diag::err_drv_argument_only_allowed_with)
5706 <<
"-mno-pic-data-is-text-relative"
5709 if (!Triple.isSystemZ())
5710 D.Diag(diag::err_drv_unsupported_opt_for_target)
5711 << (NoPICDataIsTextRelative ?
"-mno-pic-data-is-text-relative"
5712 :
"-mpic-data-is-text-relative")
5716 bool IsROPI = RelocationModel == llvm::Reloc::ROPI ||
5717 RelocationModel == llvm::Reloc::ROPI_RWPI;
5718 bool IsRWPI = RelocationModel == llvm::Reloc::RWPI ||
5719 RelocationModel == llvm::Reloc::ROPI_RWPI;
5721 if (Args.hasArg(options::OPT_mcmse) &&
5722 !Args.hasArg(options::OPT_fallow_unsupported)) {
5724 D.Diag(diag::err_cmse_pi_are_incompatible) << IsROPI;
5726 D.Diag(diag::err_cmse_pi_are_incompatible) << !IsRWPI;
5730 !Args.hasArg(options::OPT_fallow_unsupported))
5731 D.Diag(diag::err_drv_ropi_incompatible_with_cxx);
5735 CmdArgs.push_back(
"-mrelocation-model");
5736 CmdArgs.push_back(RMName);
5739 CmdArgs.push_back(
"-pic-level");
5740 CmdArgs.push_back(PICLevel == 1 ?
"1" :
"2");
5742 CmdArgs.push_back(
"-pic-is-pie");
5743 if (NoPICDataIsTextRelative)
5744 CmdArgs.push_back(
"-mcmodel=medium");
5747 if (RelocationModel == llvm::Reloc::ROPI ||
5748 RelocationModel == llvm::Reloc::ROPI_RWPI)
5749 CmdArgs.push_back(
"-fropi");
5750 if (RelocationModel == llvm::Reloc::RWPI ||
5751 RelocationModel == llvm::Reloc::ROPI_RWPI)
5752 CmdArgs.push_back(
"-frwpi");
5754 if (Arg *A = Args.getLastArg(options::OPT_meabi)) {
5755 CmdArgs.push_back(
"-meabi");
5756 CmdArgs.push_back(A->getValue());
5770 if (Triple.isOSBinFormatELF()) {
5771 Arg *A = Args.getLastArg(options::OPT_fsemantic_interposition,
5772 options::OPT_fno_semantic_interposition);
5773 if (RelocationModel != llvm::Reloc::Static && !IsPIE) {
5775 bool SupportsLocalAlias =
5776 Triple.isAArch64() || Triple.isRISCV() || Triple.isX86();
5778 CmdArgs.push_back(
"-fhalf-no-semantic-interposition");
5779 else if (A->getOption().matches(options::OPT_fsemantic_interposition))
5780 A->render(Args, CmdArgs);
5781 else if (!SupportsLocalAlias)
5782 CmdArgs.push_back(
"-fhalf-no-semantic-interposition");
5788 if (Arg *A = Args.getLastArg(options::OPT_mthread_model)) {
5790 D.Diag(diag::err_drv_invalid_thread_model_for_target)
5791 << A->getValue() << A->getAsString(Args);
5792 Model = A->getValue();
5795 if (Model !=
"posix") {
5796 CmdArgs.push_back(
"-mthread-model");
5797 CmdArgs.push_back(Args.MakeArgString(Model));
5801 if (Arg *A = Args.getLastArg(options::OPT_fveclib)) {
5802 StringRef Name = A->getValue();
5803 if (Name ==
"SVML") {
5804 if (Triple.getArch() != llvm::Triple::x86 &&
5805 Triple.getArch() != llvm::Triple::x86_64)
5806 D.Diag(diag::err_drv_unsupported_opt_for_target)
5807 << Name << Triple.getArchName();
5808 }
else if (Name ==
"LIBMVEC-X86") {
5809 if (Triple.getArch() != llvm::Triple::x86 &&
5810 Triple.getArch() != llvm::Triple::x86_64)
5811 D.Diag(diag::err_drv_unsupported_opt_for_target)
5812 << Name << Triple.getArchName();
5813 }
else if (Name ==
"SLEEF" || Name ==
"ArmPL") {
5814 if (Triple.getArch() != llvm::Triple::aarch64 &&
5815 Triple.getArch() != llvm::Triple::aarch64_be &&
5816 Triple.getArch() != llvm::Triple::riscv64)
5817 D.Diag(diag::err_drv_unsupported_opt_for_target)
5818 << Name << Triple.getArchName();
5820 A->render(Args, CmdArgs);
5823 if (Args.hasFlag(options::OPT_fmerge_all_constants,
5824 options::OPT_fno_merge_all_constants,
false))
5825 CmdArgs.push_back(
"-fmerge-all-constants");
5827 Args.addOptOutFlag(CmdArgs, options::OPT_fdelete_null_pointer_checks,
5828 options::OPT_fno_delete_null_pointer_checks);
5832 if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ_quadword_atomics)) {
5833 if (!Triple.isOSAIX() || Triple.isPPC32())
5834 D.Diag(diag::err_drv_unsupported_opt_for_target)
5835 << A->getSpelling() << RawTriple.str();
5836 CmdArgs.push_back(
"-mabi=quadword-atomics");
5839 if (Arg *A = Args.getLastArg(options::OPT_mlong_double_128)) {
5842 if (Triple.isOSAIX())
5843 D.Diag(diag::err_drv_unsupported_opt_for_target)
5844 << A->getSpelling() << RawTriple.str();
5847 if (Arg *A = Args.getLastArg(options::OPT_Wframe_larger_than_EQ)) {
5848 StringRef
V = A->getValue(), V1 =
V;
5850 if (V1.consumeInteger(10, Size) || !V1.empty())
5851 D.Diag(diag::err_drv_invalid_argument_to_option)
5852 <<
V << A->getOption().getName();
5854 CmdArgs.push_back(Args.MakeArgString(
"-fwarn-stack-size=" +
V));
5857 Args.addOptOutFlag(CmdArgs, options::OPT_fjump_tables,
5858 options::OPT_fno_jump_tables);
5859 Args.addOptInFlag(CmdArgs, options::OPT_fprofile_sample_accurate,
5860 options::OPT_fno_profile_sample_accurate);
5861 Args.addOptOutFlag(CmdArgs, options::OPT_fpreserve_as_comments,
5862 options::OPT_fno_preserve_as_comments);
5864 if (Arg *A = Args.getLastArg(options::OPT_mregparm_EQ)) {
5865 CmdArgs.push_back(
"-mregparm");
5866 CmdArgs.push_back(A->getValue());
5869 if (Arg *A = Args.getLastArg(options::OPT_maix_struct_return,
5870 options::OPT_msvr4_struct_return)) {
5872 D.Diag(diag::err_drv_unsupported_opt_for_target)
5873 << A->getSpelling() << RawTriple.str();
5874 }
else if (A->getOption().matches(options::OPT_maix_struct_return)) {
5875 CmdArgs.push_back(
"-maix-struct-return");
5877 assert(A->getOption().matches(options::OPT_msvr4_struct_return));
5878 CmdArgs.push_back(
"-msvr4-struct-return");
5882 if (Arg *A = Args.getLastArg(options::OPT_fpcc_struct_return,
5883 options::OPT_freg_struct_return)) {
5884 if (TC.
getArch() != llvm::Triple::x86) {
5885 D.Diag(diag::err_drv_unsupported_opt_for_target)
5886 << A->getSpelling() << RawTriple.str();
5887 }
else if (A->getOption().matches(options::OPT_fpcc_struct_return)) {
5888 CmdArgs.push_back(
"-fpcc-struct-return");
5890 assert(A->getOption().matches(options::OPT_freg_struct_return));
5891 CmdArgs.push_back(
"-freg-struct-return");
5895 if (Args.hasFlag(options::OPT_mrtd, options::OPT_mno_rtd,
false)) {
5896 if (Triple.getArch() == llvm::Triple::m68k)
5897 CmdArgs.push_back(
"-fdefault-calling-conv=rtdcall");
5899 CmdArgs.push_back(
"-fdefault-calling-conv=stdcall");
5902 if (Args.hasArg(options::OPT_fenable_matrix)) {
5904 CmdArgs.push_back(
"-fenable-matrix");
5905 CmdArgs.push_back(
"-mllvm");
5906 CmdArgs.push_back(
"-enable-matrix");
5911 const char *FPKeepKindStr =
nullptr;
5912 switch (FPKeepKind) {
5914 FPKeepKindStr =
"-mframe-pointer=none";
5917 FPKeepKindStr =
"-mframe-pointer=reserved";
5920 FPKeepKindStr =
"-mframe-pointer=non-leaf";
5923 FPKeepKindStr =
"-mframe-pointer=all";
5926 assert(FPKeepKindStr &&
"unknown FramePointerKind");
5927 CmdArgs.push_back(FPKeepKindStr);
5929 Args.addOptOutFlag(CmdArgs, options::OPT_fzero_initialized_in_bss,
5930 options::OPT_fno_zero_initialized_in_bss);
5934 D.Diag(diag::warn_drv_deprecated_arg_ofast);
5937 OptSpecifier StrictAliasingAliasOption =
5938 OFastEnabled ? options::OPT_Ofast : options::OPT_fstrict_aliasing;
5941 if (!Args.hasFlag(options::OPT_fstrict_aliasing, StrictAliasingAliasOption,
5942 options::OPT_fno_strict_aliasing, !IsWindowsMSVC))
5943 CmdArgs.push_back(
"-relaxed-aliasing");
5944 if (Args.hasFlag(options::OPT_fno_pointer_tbaa, options::OPT_fpointer_tbaa,
5946 CmdArgs.push_back(
"-no-pointer-tbaa");
5947 if (!Args.hasFlag(options::OPT_fstruct_path_tbaa,
5948 options::OPT_fno_struct_path_tbaa,
true))
5949 CmdArgs.push_back(
"-no-struct-path-tbaa");
5950 Args.addOptInFlag(CmdArgs, options::OPT_fstrict_enums,
5951 options::OPT_fno_strict_enums);
5952 Args.addOptOutFlag(CmdArgs, options::OPT_fstrict_return,
5953 options::OPT_fno_strict_return);
5954 Args.addOptInFlag(CmdArgs, options::OPT_fallow_editor_placeholders,
5955 options::OPT_fno_allow_editor_placeholders);
5956 Args.addOptInFlag(CmdArgs, options::OPT_fstrict_vtable_pointers,
5957 options::OPT_fno_strict_vtable_pointers);
5958 Args.addOptInFlag(CmdArgs, options::OPT_fforce_emit_vtables,
5959 options::OPT_fno_force_emit_vtables);
5960 Args.addOptOutFlag(CmdArgs, options::OPT_foptimize_sibling_calls,
5961 options::OPT_fno_optimize_sibling_calls);
5962 Args.addOptOutFlag(CmdArgs, options::OPT_fescaping_block_tail_calls,
5963 options::OPT_fno_escaping_block_tail_calls);
5965 Args.AddLastArg(CmdArgs, options::OPT_ffine_grained_bitfield_accesses,
5966 options::OPT_fno_fine_grained_bitfield_accesses);
5968 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_relative_cxx_abi_vtables,
5969 options::OPT_fno_experimental_relative_cxx_abi_vtables);
5971 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_omit_vtable_rtti,
5972 options::OPT_fno_experimental_omit_vtable_rtti);
5974 Args.AddLastArg(CmdArgs, options::OPT_fdisable_block_signature_string,
5975 options::OPT_fno_disable_block_signature_string);
5978 Args.addOptInFlag(CmdArgs, options::OPT_fsplit_stack,
5979 options::OPT_fno_split_stack);
5982 if (Args.hasFlag(options::OPT_fprotect_parens,
5983 options::OPT_fno_protect_parens,
false))
5984 CmdArgs.push_back(
"-fprotect-parens");
5988 if (Arg *A = Args.getLastArg(options::OPT_fextend_args_EQ)) {
5989 const llvm::Triple::ArchType Arch = TC.
getArch();
5990 if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) {
5991 StringRef
V = A->getValue();
5993 CmdArgs.push_back(
"-fextend-arguments=64");
5995 D.Diag(diag::err_drv_invalid_argument_to_option)
5996 << A->getValue() << A->getOption().getName();
5998 D.Diag(diag::err_drv_unsupported_opt_for_target)
5999 << A->getOption().getName() << TripleStr;
6002 if (Arg *A = Args.getLastArg(options::OPT_mdouble_EQ)) {
6003 if (TC.
getArch() == llvm::Triple::avr)
6004 A->render(Args, CmdArgs);
6006 D.Diag(diag::err_drv_unsupported_opt_for_target)
6007 << A->getAsString(Args) << TripleStr;
6010 if (Arg *A = Args.getLastArg(options::OPT_LongDouble_Group)) {
6012 A->render(Args, CmdArgs);
6014 (A->getOption().getID() != options::OPT_mlong_double_80))
6015 A->render(Args, CmdArgs);
6017 D.Diag(diag::err_drv_unsupported_opt_for_target)
6018 << A->getAsString(Args) << TripleStr;
6024 if (!Args.hasFlag(options::OPT_fverbose_asm, options::OPT_fno_verbose_asm,
6025 IsIntegratedAssemblerDefault))
6026 CmdArgs.push_back(
"-fno-verbose-asm");
6030 if (Arg *A = Args.getLastArg(options::OPT_fbinutils_version_EQ)) {
6031 StringRef
V = A->getValue();
6034 A->render(Args, CmdArgs);
6035 else if (!
V.consumeInteger(10,
Num) &&
Num > 0 &&
6036 (
V.empty() || (
V.consume_front(
".") &&
6037 !
V.consumeInteger(10,
Num) &&
V.empty())))
6038 A->render(Args, CmdArgs);
6040 D.Diag(diag::err_drv_invalid_argument_to_option)
6041 << A->getValue() << A->getOption().getName();
6047 CmdArgs.push_back(
"-no-integrated-as");
6049 if (Args.hasArg(options::OPT_fdebug_pass_structure)) {
6050 CmdArgs.push_back(
"-mdebug-pass");
6051 CmdArgs.push_back(
"Structure");
6053 if (Args.hasArg(options::OPT_fdebug_pass_arguments)) {
6054 CmdArgs.push_back(
"-mdebug-pass");
6055 CmdArgs.push_back(
"Arguments");
6061 if (!RawTriple.isOSDarwin() && !RawTriple.isNVPTX())
6062 CmdArgs.push_back(
"-mconstructor-aliases");
6066 if (KernelOrKext && RawTriple.isOSDarwin())
6067 CmdArgs.push_back(
"-fforbid-guard-variables");
6069 if (Args.hasFlag(options::OPT_mms_bitfields, options::OPT_mno_ms_bitfields,
6070 Triple.isWindowsGNUEnvironment())) {
6071 CmdArgs.push_back(
"-mms-bitfields");
6074 if (Triple.isWindowsGNUEnvironment()) {
6075 Args.addOptOutFlag(CmdArgs, options::OPT_fauto_import,
6076 options::OPT_fno_auto_import);
6079 if (Args.hasFlag(options::OPT_fms_volatile, options::OPT_fno_ms_volatile,
6080 Triple.isX86() && IsWindowsMSVC))
6081 CmdArgs.push_back(
"-fms-volatile");
6086 if (Arg *A = Args.getLastArg(options::OPT_fdirect_access_external_data,
6087 options::OPT_fno_direct_access_external_data)) {
6088 if (A->getOption().matches(options::OPT_fdirect_access_external_data) !=
6090 A->render(Args, CmdArgs);
6091 }
else if (PICLevel == 0 && Triple.isLoongArch()) {
6094 CmdArgs.push_back(
"-fno-direct-access-external-data");
6097 if (Args.hasFlag(options::OPT_fno_plt, options::OPT_fplt,
false)) {
6098 CmdArgs.push_back(
"-fno-plt");
6105 Args.hasFlag(options::OPT_ffreestanding, options::OPT_fhosted,
false) ||
6108 CmdArgs.push_back(
"-ffreestanding");
6110 Args.AddLastArg(CmdArgs, options::OPT_fno_knr_functions);
6117 bool IsAsyncUnwindTablesDefault =
6119 bool IsSyncUnwindTablesDefault =
6122 bool AsyncUnwindTables = Args.hasFlag(
6123 options::OPT_fasynchronous_unwind_tables,
6124 options::OPT_fno_asynchronous_unwind_tables,
6125 (IsAsyncUnwindTablesDefault || SanitizeArgs.needsUnwindTables()) &&
6128 Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables,
6129 IsSyncUnwindTablesDefault && !Freestanding);
6130 if (AsyncUnwindTables)
6131 CmdArgs.push_back(
"-funwind-tables=2");
6132 else if (UnwindTables)
6133 CmdArgs.push_back(
"-funwind-tables=1");
6137 if (!Args.getLastArg(options::OPT_gpu_use_aux_triple_only) &&
6138 (IsCudaDevice || IsHIPDevice)) {
6139 const ArgList &HostArgs =
6141 std::string HostCPU =
6143 if (!HostCPU.empty()) {
6144 CmdArgs.push_back(
"-aux-target-cpu");
6145 CmdArgs.push_back(Args.MakeArgString(HostCPU));
6153 addMCModel(
D, Args, Triple, RelocationModel, CmdArgs);
6155 if (Arg *A = Args.getLastArg(options::OPT_mtls_size_EQ)) {
6156 StringRef
Value = A->getValue();
6157 unsigned TLSSize = 0;
6158 Value.getAsInteger(10, TLSSize);
6159 if (!Triple.isAArch64() || !Triple.isOSBinFormatELF())
6160 D.Diag(diag::err_drv_unsupported_opt_for_target)
6161 << A->getOption().getName() << TripleStr;
6162 if (TLSSize != 12 && TLSSize != 24 && TLSSize != 32 && TLSSize != 48)
6163 D.Diag(diag::err_drv_invalid_int_value)
6164 << A->getOption().getName() <<
Value;
6165 Args.AddLastArg(CmdArgs, options::OPT_mtls_size_EQ);
6169 CmdArgs.push_back(
"-enable-tlsdesc");
6172 std::string CPU =
getCPUName(
D, Args, Triple,
false);
6174 CmdArgs.push_back(
"-target-cpu");
6175 CmdArgs.push_back(Args.MakeArgString(CPU));
6178 RenderTargetOptions(Triple, Args, KernelOrKext, CmdArgs);
6183 AddClangCLArgs(Args, InputType, CmdArgs);
6185 llvm::codegenoptions::DebugInfoKind DebugInfoKind =
6186 llvm::codegenoptions::NoDebugInfo;
6189 CmdArgs, Output, DebugInfoKind, DwarfFission);
6197 (isa<AssembleJobAction>(JA) || isa<CompileJobAction>(JA) ||
6198 isa<BackendJobAction>(JA));
6200 const char *SplitDWARFOut =
SplitDebugName(JA, Args, Input, Output);
6201 CmdArgs.push_back(
"-split-dwarf-file");
6202 CmdArgs.push_back(SplitDWARFOut);
6204 CmdArgs.push_back(
"-split-dwarf-output");
6205 CmdArgs.push_back(SplitDWARFOut);
6210 if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) {
6211 CmdArgs.push_back(
"-target-linker-version");
6212 CmdArgs.push_back(A->getValue());
6217 if (!Args.hasArg(options::OPT_fallow_unsupported)) {
6219 if (
types::isCXX(InputType) && RawTriple.isOSDarwin() &&
6220 TC.
getArch() == llvm::Triple::x86) {
6221 if ((Unsupported = Args.getLastArg(options::OPT_fapple_kext)) ||
6222 (Unsupported = Args.getLastArg(options::OPT_mkernel)))
6223 D.Diag(diag::err_drv_clang_unsupported_opt_cxx_darwin_i386)
6224 << Unsupported->getOption().getName();
6227 if ((Unsupported = Args.getLastArg(options::OPT_faltivec)))
6228 D.Diag(diag::err_drv_clang_unsupported_opt_faltivec)
6229 << Unsupported->getOption().getName()
6230 <<
"please use -maltivec and include altivec.h explicitly";
6231 if ((Unsupported = Args.getLastArg(options::OPT_fno_altivec)))
6232 D.Diag(diag::err_drv_clang_unsupported_opt_faltivec)
6233 << Unsupported->getOption().getName() <<
"please use -mno-altivec";
6236 Args.AddAllArgs(CmdArgs, options::OPT_v);
6238 if (Args.getLastArg(options::OPT_H)) {
6239 CmdArgs.push_back(
"-H");
6240 CmdArgs.push_back(
"-sys-header-deps");
6242 Args.AddAllArgs(CmdArgs, options::OPT_fshow_skipped_includes);
6244 if (
D.CCPrintHeadersFormat && !
D.CCGenDiagnostics) {
6245 CmdArgs.push_back(
"-header-include-file");
6246 CmdArgs.push_back(!
D.CCPrintHeadersFilename.empty()
6247 ?
D.CCPrintHeadersFilename.c_str()
6249 CmdArgs.push_back(
"-sys-header-deps");
6250 CmdArgs.push_back(Args.MakeArgString(
6251 "-header-include-format=" +
6254 Args.MakeArgString(
"-header-include-filtering=" +
6256 D.CCPrintHeadersFiltering))));
6258 Args.AddLastArg(CmdArgs, options::OPT_P);
6259 Args.AddLastArg(CmdArgs, options::OPT_print_ivar_layout);
6261 if (
D.CCLogDiagnostics && !
D.CCGenDiagnostics) {
6262 CmdArgs.push_back(
"-diagnostic-log-file");
6263 CmdArgs.push_back(!
D.CCLogDiagnosticsFilename.empty()
6264 ?
D.CCLogDiagnosticsFilename.c_str()
6270 if (
D.CCGenDiagnostics)
6271 CmdArgs.push_back(
"-disable-pragma-debug-crash");
6275 if (Args.hasArg(options::OPT_fcrash_diagnostics_dir)) {
6276 StringRef Dir = Args.getLastArgValue(options::OPT_fcrash_diagnostics_dir);
6277 CmdArgs.push_back(
"-mllvm");
6278 CmdArgs.push_back(Args.MakeArgString(
"-crash-diagnostics-dir=" + Dir));
6283 if (Args.hasFlag(options::OPT_ffunction_sections,
6284 options::OPT_fno_function_sections, UseSeparateSections)) {
6285 CmdArgs.push_back(
"-ffunction-sections");
6288 if (Arg *A = Args.getLastArg(options::OPT_fbasic_block_address_map,
6289 options::OPT_fno_basic_block_address_map)) {
6290 if ((Triple.isX86() || Triple.isAArch64()) && Triple.isOSBinFormatELF()) {
6291 if (A->getOption().matches(options::OPT_fbasic_block_address_map))
6292 A->render(Args, CmdArgs);
6294 D.Diag(diag::err_drv_unsupported_opt_for_target)
6295 << A->getAsString(Args) << TripleStr;
6299 if (Arg *A = Args.getLastArg(options::OPT_fbasic_block_sections_EQ)) {
6300 StringRef Val = A->getValue();
6301 if (Val ==
"labels") {
6302 D.Diag(diag::warn_drv_deprecated_arg)
6303 << A->getAsString(Args) <<
true
6304 <<
"-fbasic-block-address-map";
6305 CmdArgs.push_back(
"-fbasic-block-address-map");
6306 }
else if (Triple.isX86() && Triple.isOSBinFormatELF()) {
6307 if (Val !=
"all" && Val !=
"none" && !Val.starts_with(
"list="))
6308 D.Diag(diag::err_drv_invalid_value)
6309 << A->getAsString(Args) << A->getValue();
6311 A->render(Args, CmdArgs);
6312 }
else if (Triple.isAArch64() && Triple.isOSBinFormatELF()) {
6315 if (Val !=
"labels" && Val !=
"none" && !Val.starts_with(
"list="))
6316 D.Diag(diag::err_drv_invalid_value)
6317 << A->getAsString(Args) << A->getValue();
6319 A->render(Args, CmdArgs);
6320 }
else if (Triple.isNVPTX()) {
6323 }
else if (Val !=
"none") {
6326 D.Diag(diag::err_drv_unsupported_opt_for_target)
6327 << A->getAsString(Args) << TripleStr;
6331 bool HasDefaultDataSections = Triple.isOSBinFormatXCOFF();
6332 if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
6333 UseSeparateSections || HasDefaultDataSections)) {
6334 CmdArgs.push_back(
"-fdata-sections");
6337 Args.addOptOutFlag(CmdArgs, options::OPT_funique_section_names,
6338 options::OPT_fno_unique_section_names);
6339 Args.addOptInFlag(CmdArgs, options::OPT_fseparate_named_sections,
6340 options::OPT_fno_separate_named_sections);
6341 Args.addOptInFlag(CmdArgs, options::OPT_funique_internal_linkage_names,
6342 options::OPT_fno_unique_internal_linkage_names);
6343 Args.addOptInFlag(CmdArgs, options::OPT_funique_basic_block_section_names,
6344 options::OPT_fno_unique_basic_block_section_names);
6346 if (Arg *A = Args.getLastArg(options::OPT_fsplit_machine_functions,
6347 options::OPT_fno_split_machine_functions)) {
6348 if (!A->getOption().matches(options::OPT_fno_split_machine_functions)) {
6350 if ((Triple.isX86() || Triple.isAArch64()) && Triple.isOSBinFormatELF())
6351 A->render(Args, CmdArgs);
6353 D.Diag(diag::err_drv_unsupported_opt_for_target)
6354 << A->getAsString(Args) << TripleStr;
6358 Args.AddLastArg(CmdArgs, options::OPT_finstrument_functions,
6359 options::OPT_finstrument_functions_after_inlining,
6360 options::OPT_finstrument_function_entry_bare);
6361 Args.AddLastArg(CmdArgs, options::OPT_fconvergent_functions,
6362 options::OPT_fno_convergent_functions);
6367 if (!Triple.isNVPTX() && !Triple.isAMDGCN())
6370 Args.AddLastArg(CmdArgs, options::OPT_fclang_abi_compat_EQ);
6373 Args.hasArg(options::OPT_fsample_profile_use_profi)) {
6374 CmdArgs.push_back(
"-mllvm");
6375 CmdArgs.push_back(
"-sample-profile-use-profi");
6379 if (RawTriple.isPS() &&
6380 !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
6386 if (Args.hasArg(options::OPT_nostdinc)) {
6387 CmdArgs.push_back(
"-nostdsysteminc");
6388 CmdArgs.push_back(
"-nobuiltininc");
6390 if (Args.hasArg(options::OPT_nostdlibinc))
6391 CmdArgs.push_back(
"-nostdsysteminc");
6392 Args.AddLastArg(CmdArgs, options::OPT_nostdincxx);
6393 Args.AddLastArg(CmdArgs, options::OPT_nobuiltininc);
6397 CmdArgs.push_back(
"-resource-dir");
6398 CmdArgs.push_back(
D.ResourceDir.c_str());
6400 Args.AddLastArg(CmdArgs, options::OPT_working_directory);
6409 AddPreprocessingOptions(
C, JA,
D, Args, CmdArgs, Output, Inputs);
6415 Args.ClaimAllArgs(options::OPT_D);
6418 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
6419 if (A->getOption().matches(options::OPT_O4)) {
6420 CmdArgs.push_back(
"-O3");
6421 D.Diag(diag::warn_O4_is_O3);
6423 A->render(Args, CmdArgs);
6429 Args.filtered(options::OPT_clang_ignored_gcc_optimization_f_Group)) {
6430 D.Diag(diag::warn_ignored_gcc_optimization) << A->getAsString(Args);
6435 Args.filtered(options::OPT_clang_ignored_legacy_options_Group)) {
6436 D.Diag(diag::warn_ignored_clang_option) << A->getAsString(Args);
6442 Args.AddAllArgs(CmdArgs, options::OPT_R_Group);
6445 Args.filtered(options::OPT_W_Group, options::OPT__SLASH_wd)) {
6447 if (A->getOption().getID() == options::OPT__SLASH_wd) {
6448 unsigned WarningNumber;
6449 if (StringRef(A->getValue()).getAsInteger(10, WarningNumber)) {
6450 D.Diag(diag::err_drv_invalid_int_value)
6451 << A->getAsString(Args) << A->getValue();
6456 CmdArgs.push_back(Args.MakeArgString(
6461 A->render(Args, CmdArgs);
6464 Args.AddAllArgs(CmdArgs, options::OPT_Wsystem_headers_in_module_EQ);
6466 if (Args.hasFlag(options::OPT_pedantic, options::OPT_no_pedantic,
false))
6467 CmdArgs.push_back(
"-pedantic");
6468 Args.AddLastArg(CmdArgs, options::OPT_pedantic_errors);
6469 Args.AddLastArg(CmdArgs, options::OPT_w);
6471 Args.addOptInFlag(CmdArgs, options::OPT_ffixed_point,
6472 options::OPT_fno_fixed_point);
6474 if (Arg *A = Args.getLastArg(options::OPT_fcxx_abi_EQ))
6475 A->render(Args, CmdArgs);
6477 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_relative_cxx_abi_vtables,
6478 options::OPT_fno_experimental_relative_cxx_abi_vtables);
6480 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_omit_vtable_rtti,
6481 options::OPT_fno_experimental_omit_vtable_rtti);
6483 if (Arg *A = Args.getLastArg(options::OPT_ffuchsia_api_level_EQ))
6484 A->render(Args, CmdArgs);
6491 bool ImplyVCPPCVer =
false;
6492 bool ImplyVCPPCXXVer =
false;
6493 const Arg *
Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi);
6495 if (
Std->getOption().matches(options::OPT_ansi))
6497 CmdArgs.push_back(
"-std=c++98");
6499 CmdArgs.push_back(
"-std=c89");
6501 Std->render(Args, CmdArgs);
6504 if (Arg *A = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi,
6505 options::OPT_ftrigraphs,
6506 options::OPT_fno_trigraphs))
6508 A->render(Args, CmdArgs);
6517 if (!Args.hasArg(options::OPT__SLASH_std)) {
6518 Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ,
"-std=",
6521 ImplyVCPPCVer =
true;
6523 else if (IsWindowsMSVC)
6524 ImplyVCPPCXXVer =
true;
6526 Args.AddLastArg(CmdArgs, options::OPT_ftrigraphs,
6527 options::OPT_fno_trigraphs);
6543 Args.getLastArg(options::OPT_Wwrite_strings,
6544 options::OPT_Wno_write_strings, options::OPT_w);
6546 WriteStrings->getOption().matches(options::OPT_Wwrite_strings))
6547 CmdArgs.push_back(
"-fconst-strings");
6554 Args.hasFlag(options::OPT_Wdeprecated, options::OPT_Wno_deprecated,
6556 CmdArgs.push_back(
"-fdeprecated-macro");
6560 if (Arg *
Asm = Args.getLastArg(options::OPT_fasm, options::OPT_fno_asm)) {
6561 if (
Asm->getOption().matches(options::OPT_fasm))
6562 CmdArgs.push_back(
"-fgnu-keywords");
6564 CmdArgs.push_back(
"-fno-gnu-keywords");
6568 CmdArgs.push_back(
"-fno-autolink");
6570 Args.AddLastArg(CmdArgs, options::OPT_ftemplate_depth_EQ);
6571 Args.AddLastArg(CmdArgs, options::OPT_foperator_arrow_depth_EQ);
6572 Args.AddLastArg(CmdArgs, options::OPT_fconstexpr_depth_EQ);
6573 Args.AddLastArg(CmdArgs, options::OPT_fconstexpr_steps_EQ);
6575 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_library);
6577 if (Args.hasArg(options::OPT_fexperimental_new_constant_interpreter))
6578 CmdArgs.push_back(
"-fexperimental-new-constant-interpreter");
6580 if (Arg *A = Args.getLastArg(options::OPT_fbracket_depth_EQ)) {
6581 CmdArgs.push_back(
"-fbracket-depth");
6582 CmdArgs.push_back(A->getValue());
6585 if (Arg *A = Args.getLastArg(options::OPT_Wlarge_by_value_copy_EQ,
6586 options::OPT_Wlarge_by_value_copy_def)) {
6587 if (A->getNumValues()) {
6588 StringRef
bytes = A->getValue();
6589 CmdArgs.push_back(Args.MakeArgString(
"-Wlarge-by-value-copy=" +
bytes));
6591 CmdArgs.push_back(
"-Wlarge-by-value-copy=64");
6594 if (Args.hasArg(options::OPT_relocatable_pch))
6595 CmdArgs.push_back(
"-relocatable-pch");
6597 if (
const Arg *A = Args.getLastArg(options::OPT_fcf_runtime_abi_EQ)) {
6598 static const char *kCFABIs[] = {
6599 "standalone",
"objc",
"swift",
"swift-5.0",
"swift-4.2",
"swift-4.1",
6602 if (!llvm::is_contained(kCFABIs, StringRef(A->getValue())))
6603 D.Diag(diag::err_drv_invalid_cf_runtime_abi) << A->getValue();
6605 A->render(Args, CmdArgs);
6608 if (Arg *A = Args.getLastArg(options::OPT_fconstant_string_class_EQ)) {
6609 CmdArgs.push_back(
"-fconstant-string-class");
6610 CmdArgs.push_back(A->getValue());
6613 if (Arg *A = Args.getLastArg(options::OPT_ftabstop_EQ)) {
6614 CmdArgs.push_back(
"-ftabstop");
6615 CmdArgs.push_back(A->getValue());
6618 Args.addOptInFlag(CmdArgs, options::OPT_fstack_size_section,
6619 options::OPT_fno_stack_size_section);
6621 if (Args.hasArg(options::OPT_fstack_usage)) {
6622 CmdArgs.push_back(
"-stack-usage-file");
6624 if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) {
6626 llvm::sys::path::replace_extension(OutputFilename,
"su");
6627 CmdArgs.push_back(Args.MakeArgString(OutputFilename));
6633 CmdArgs.push_back(
"-ferror-limit");
6634 if (Arg *A = Args.getLastArg(options::OPT_ferror_limit_EQ))
6635 CmdArgs.push_back(A->getValue());
6637 CmdArgs.push_back(
"19");
6639 Args.AddLastArg(CmdArgs, options::OPT_fconstexpr_backtrace_limit_EQ);
6640 Args.AddLastArg(CmdArgs, options::OPT_fmacro_backtrace_limit_EQ);
6641 Args.AddLastArg(CmdArgs, options::OPT_ftemplate_backtrace_limit_EQ);
6642 Args.AddLastArg(CmdArgs, options::OPT_fspell_checking_limit_EQ);
6643 Args.AddLastArg(CmdArgs, options::OPT_fcaret_diagnostics_max_lines_EQ);
6646 unsigned MessageLength = 0;
6647 if (Arg *A = Args.getLastArg(options::OPT_fmessage_length_EQ)) {
6648 StringRef
V(A->getValue());
6649 if (
V.getAsInteger(0, MessageLength))
6650 D.Diag(diag::err_drv_invalid_argument_to_option)
6651 <<
V << A->getOption().getName();
6655 MessageLength = llvm::sys::Process::StandardErrColumns();
6657 if (MessageLength != 0)
6659 Args.MakeArgString(
"-fmessage-length=" + Twine(MessageLength)));
6661 if (Arg *A = Args.getLastArg(options::OPT_frandomize_layout_seed_EQ))
6663 Args.MakeArgString(
"-frandomize-layout-seed=" + Twine(A->getValue(0))));
6665 if (Arg *A = Args.getLastArg(options::OPT_frandomize_layout_seed_file_EQ))
6666 CmdArgs.push_back(Args.MakeArgString(
"-frandomize-layout-seed-file=" +
6667 Twine(A->getValue(0))));
6670 if (
const Arg *A = Args.getLastArg(options::OPT_fvisibility_EQ,
6671 options::OPT_fvisibility_ms_compat)) {
6672 if (A->getOption().matches(options::OPT_fvisibility_EQ)) {
6673 A->render(Args, CmdArgs);
6675 assert(A->getOption().matches(options::OPT_fvisibility_ms_compat));
6676 CmdArgs.push_back(
"-fvisibility=hidden");
6677 CmdArgs.push_back(
"-ftype-visibility=default");
6679 }
else if (IsOpenMPDevice) {
6683 CmdArgs.push_back(
"-fvisibility=protected");
6687 if (!RawTriple.isPS()) {
6689 Args.getLastArg(options::OPT_fvisibility_from_dllstorageclass,
6690 options::OPT_fno_visibility_from_dllstorageclass)) {
6691 if (A->getOption().matches(
6692 options::OPT_fvisibility_from_dllstorageclass)) {
6693 CmdArgs.push_back(
"-fvisibility-from-dllstorageclass");
6694 Args.AddLastArg(CmdArgs, options::OPT_fvisibility_dllexport_EQ);
6695 Args.AddLastArg(CmdArgs, options::OPT_fvisibility_nodllstorageclass_EQ);
6696 Args.AddLastArg(CmdArgs, options::OPT_fvisibility_externs_dllimport_EQ);
6697 Args.AddLastArg(CmdArgs,
6698 options::OPT_fvisibility_externs_nodllstorageclass_EQ);
6703 if (Args.hasFlag(options::OPT_fvisibility_inlines_hidden,
6704 options::OPT_fno_visibility_inlines_hidden,
false))
6705 CmdArgs.push_back(
"-fvisibility-inlines-hidden");
6707 Args.AddLastArg(CmdArgs, options::OPT_fvisibility_inlines_hidden_static_local_var,
6708 options::OPT_fno_visibility_inlines_hidden_static_local_var);
6713 Args.getLastArg(options::OPT_fvisibility_global_new_delete_hidden)) {
6714 D.Diag(diag::warn_drv_deprecated_arg)
6715 << A->getAsString(Args) <<
true
6716 <<
"-fvisibility-global-new-delete=force-hidden";
6720 Args.getLastArg(options::OPT_fvisibility_global_new_delete_EQ,
6721 options::OPT_fvisibility_global_new_delete_hidden)) {
6722 if (A->getOption().matches(options::OPT_fvisibility_global_new_delete_EQ)) {
6723 A->render(Args, CmdArgs);
6725 assert(A->getOption().matches(
6726 options::OPT_fvisibility_global_new_delete_hidden));
6727 CmdArgs.push_back(
"-fvisibility-global-new-delete=force-hidden");
6731 Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ);
6733 if (Args.hasFlag(options::OPT_fnew_infallible,
6734 options::OPT_fno_new_infallible,
false))
6735 CmdArgs.push_back(
"-fnew-infallible");
6737 if (Args.hasFlag(options::OPT_fno_operator_names,
6738 options::OPT_foperator_names,
false))
6739 CmdArgs.push_back(
"-fno-operator-names");
6742 Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
6743 Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
6744 Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs);
6745 Args.AddLastArg(CmdArgs, options::OPT_fzero_call_used_regs_EQ);
6746 Args.AddLastArg(CmdArgs, options::OPT_fraw_string_literals,
6747 options::OPT_fno_raw_string_literals);
6749 if (Args.hasFlag(options::OPT_femulated_tls, options::OPT_fno_emulated_tls,
6750 Triple.hasDefaultEmulatedTLS()))
6751 CmdArgs.push_back(
"-femulated-tls");
6753 Args.addOptInFlag(CmdArgs, options::OPT_fcheck_new,
6754 options::OPT_fno_check_new);
6756 if (Arg *A = Args.getLastArg(options::OPT_fzero_call_used_regs_EQ)) {
6760 if (!Triple.isX86() && !Triple.isAArch64())
6761 D.Diag(diag::err_drv_unsupported_opt_for_target)
6762 << A->getAsString(Args) << TripleStr;
6766 if (!isa<PreprocessJobAction>(JA) || Output.
getType() != types::TY_PP_Asm)
6767 Args.AddLastArg(CmdArgs, options::OPT_fzvector);
6769 Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_show_template_tree);
6770 Args.AddLastArg(CmdArgs, options::OPT_fno_elide_type);
6774 if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
6775 options::OPT_fno_openmp,
false) &&
6776 !Args.hasFlag(options::OPT_foffload_via_llvm,
6777 options::OPT_fno_offload_via_llvm,
false) &&
6780 switch (
D.getOpenMPRuntime(Args)) {
6784 CmdArgs.push_back(
"-fopenmp");
6789 if (!Args.hasFlag(options::OPT_fopenmp_use_tls,
6790 options::OPT_fnoopenmp_use_tls,
true))
6791 CmdArgs.push_back(
"-fnoopenmp-use-tls");
6792 Args.AddLastArg(CmdArgs, options::OPT_fopenmp_simd,
6793 options::OPT_fno_openmp_simd);
6794 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_enable_irbuilder);
6795 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
6796 if (!Args.hasFlag(options::OPT_fopenmp_extensions,
6797 options::OPT_fno_openmp_extensions,
true))
6798 CmdArgs.push_back(
"-fno-openmp-extensions");
6799 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_cuda_number_of_sm_EQ);
6800 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_cuda_blocks_per_sm_EQ);
6801 Args.AddAllArgs(CmdArgs,
6802 options::OPT_fopenmp_cuda_teams_reduction_recs_num_EQ);
6803 if (Args.hasFlag(options::OPT_fopenmp_optimistic_collapse,
6804 options::OPT_fno_openmp_optimistic_collapse,
6806 CmdArgs.push_back(
"-fopenmp-optimistic-collapse");
6810 if (Args.hasFlag(options::OPT_fopenmp_cuda_mode,
6811 options::OPT_fno_openmp_cuda_mode,
false))
6812 CmdArgs.push_back(
"-fopenmp-cuda-mode");
6815 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_target_debug_EQ);
6816 if (Args.hasFlag(options::OPT_fopenmp_target_debug,
6817 options::OPT_fno_openmp_target_debug,
false))
6818 CmdArgs.push_back(
"-fopenmp-target-debug");
6822 if (Args.hasFlag(options::OPT_fopenmp_assume_teams_oversubscription,
6823 options::OPT_fno_openmp_assume_teams_oversubscription,
6825 CmdArgs.push_back(
"-fopenmp-assume-teams-oversubscription");
6826 if (Args.hasFlag(options::OPT_fopenmp_assume_threads_oversubscription,
6827 options::OPT_fno_openmp_assume_threads_oversubscription,
6829 CmdArgs.push_back(
"-fopenmp-assume-threads-oversubscription");
6830 if (Args.hasArg(options::OPT_fopenmp_assume_no_thread_state))
6831 CmdArgs.push_back(
"-fopenmp-assume-no-thread-state");
6832 if (Args.hasArg(options::OPT_fopenmp_assume_no_nested_parallelism))
6833 CmdArgs.push_back(
"-fopenmp-assume-no-nested-parallelism");
6834 if (Args.hasArg(options::OPT_fopenmp_offload_mandatory))
6835 CmdArgs.push_back(
"-fopenmp-offload-mandatory");
6836 if (Args.hasArg(options::OPT_fopenmp_force_usm))
6837 CmdArgs.push_back(
"-fopenmp-force-usm");
6849 Args.AddLastArg(CmdArgs, options::OPT_fopenmp_simd,
6850 options::OPT_fno_openmp_simd);
6851 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
6852 Args.addOptOutFlag(CmdArgs, options::OPT_fopenmp_extensions,
6853 options::OPT_fno_openmp_extensions);
6858 if (Args.hasFlag(options::OPT_foffload_via_llvm,
6859 options::OPT_fno_offload_via_llvm,
false)) {
6860 CmdArgs.append({
"--offload-new-driver",
"-foffload-via-llvm"});
6861 }
else if (Args.hasFlag(options::OPT_offload_new_driver,
6862 options::OPT_no_offload_new_driver,
false)) {
6863 CmdArgs.push_back(
"--offload-new-driver");
6867 XRay.
addArgs(TC, Args, CmdArgs, InputType);
6870 Args.getAllArgValues(options::OPT_fprofile_list_EQ)) {
6872 CmdArgs.push_back(Args.MakeArgString(
"-fprofile-list=" +
Filename));
6874 D.Diag(clang::diag::err_drv_no_such_file) <<
Filename;
6877 if (Arg *A = Args.getLastArg(options::OPT_fpatchable_function_entry_EQ)) {
6878 StringRef S0 = A->getValue(), S = S0;
6879 unsigned Size, Offset = 0;
6880 if (!Triple.isAArch64() && !Triple.isLoongArch() && !Triple.isRISCV() &&
6882 !(!Triple.isOSAIX() && (Triple.getArch() == llvm::Triple::ppc ||
6883 Triple.getArch() == llvm::Triple::ppc64)))
6884 D.Diag(diag::err_drv_unsupported_opt_for_target)
6885 << A->getAsString(Args) << TripleStr;
6886 else if (S.consumeInteger(10, Size) ||
6887 (!S.empty() && (!S.consume_front(
",") ||
6888 S.consumeInteger(10, Offset) || !S.empty())))
6889 D.Diag(diag::err_drv_invalid_argument_to_option)
6890 << S0 << A->getOption().getName();
6891 else if (Size < Offset)
6892 D.Diag(diag::err_drv_unsupported_fpatchable_function_entry_argument);
6894 CmdArgs.push_back(Args.MakeArgString(A->getSpelling() + Twine(Size)));
6895 CmdArgs.push_back(Args.MakeArgString(
6896 "-fpatchable-function-entry-offset=" + Twine(Offset)));
6900 Args.AddLastArg(CmdArgs, options::OPT_fms_hotpatch);
6903 Args.AddLastArg(CmdArgs, options::OPT_pg);
6905 llvm::Triple::ArchType Arch = TC.
getArch();
6906 if (Arg *A = Args.getLastArg(options::OPT_mfentry)) {
6907 if (Arch == llvm::Triple::systemz || TC.
getTriple().isX86())
6908 A->render(Args, CmdArgs);
6910 D.Diag(diag::err_drv_unsupported_opt_for_target)
6911 << A->getAsString(Args) << TripleStr;
6913 if (Arg *A = Args.getLastArg(options::OPT_mnop_mcount)) {
6914 if (Arch == llvm::Triple::systemz)
6915 A->render(Args, CmdArgs);
6917 D.Diag(diag::err_drv_unsupported_opt_for_target)
6918 << A->getAsString(Args) << TripleStr;
6920 if (Arg *A = Args.getLastArg(options::OPT_mrecord_mcount)) {
6921 if (Arch == llvm::Triple::systemz)
6922 A->render(Args, CmdArgs);
6924 D.Diag(diag::err_drv_unsupported_opt_for_target)
6925 << A->getAsString(Args) << TripleStr;
6929 if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) {
6931 D.Diag(diag::err_drv_unsupported_opt_for_target)
6932 << A->getAsString(Args) << TripleStr;
6935 if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
6937 D.Diag(diag::err_drv_unsupported_opt_for_target)
6938 << A->getAsString(Args) << TripleStr;
6941 if (Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg)) {
6942 if (A->getOption().matches(options::OPT_p)) {
6944 if (TC.
getTriple().isOSAIX() && !Args.hasArgNoClaim(options::OPT_pg))
6945 CmdArgs.push_back(
"-pg");
6951 for (
const Arg *A : Args.filtered(options::OPT_b, options::OPT_K,
6952 options::OPT_mxcoff_build_id_EQ)) {
6953 D.Diag(diag::err_drv_unsupported_opt_for_target)
6954 << A->getSpelling() << TripleStr;
6958 if (Args.getLastArg(options::OPT_fapple_kext) ||
6959 (Args.hasArg(options::OPT_mkernel) &&
types::isCXX(InputType)))
6960 CmdArgs.push_back(
"-fapple-kext");
6962 Args.AddLastArg(CmdArgs, options::OPT_altivec_src_compat);
6963 Args.AddLastArg(CmdArgs, options::OPT_flax_vector_conversions_EQ);
6964 Args.AddLastArg(CmdArgs, options::OPT_fobjc_sender_dependent_dispatch);
6965 Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_print_source_range_info);
6966 Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_parseable_fixits);
6967 Args.AddLastArg(CmdArgs, options::OPT_ftime_report);
6968 Args.AddLastArg(CmdArgs, options::OPT_ftime_report_EQ);
6969 Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
6970 Args.AddLastArg(CmdArgs, options::OPT_malign_double);
6971 Args.AddLastArg(CmdArgs, options::OPT_fno_temp_file);
6973 if (
const char *Name =
C.getTimeTraceFile(&JA)) {
6974 CmdArgs.push_back(Args.MakeArgString(
"-ftime-trace=" + Twine(Name)));
6975 Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
6976 Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_verbose);
6979 if (Arg *A = Args.getLastArg(options::OPT_ftrapv_handler_EQ)) {
6980 CmdArgs.push_back(
"-ftrapv-handler");
6981 CmdArgs.push_back(A->getValue());
6984 Args.AddLastArg(CmdArgs, options::OPT_ftrap_function_EQ);
6990 Args.AddLastArg(CmdArgs, options::OPT_ffinite_loops,
6991 options::OPT_fno_finite_loops);
6993 Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings);
6994 Args.AddLastArg(CmdArgs, options::OPT_funroll_loops,
6995 options::OPT_fno_unroll_loops);
6997 Args.AddLastArg(CmdArgs, options::OPT_fstrict_flex_arrays_EQ);
6999 Args.AddLastArg(CmdArgs, options::OPT_pthread);
7001 Args.addOptInFlag(CmdArgs, options::OPT_mspeculative_load_hardening,
7002 options::OPT_mno_speculative_load_hardening);
7008 Args.AddLastArg(CmdArgs, options::OPT_fswift_async_fp_EQ);
7010 Args.addOptInFlag(CmdArgs, options::OPT_mstackrealign,
7011 options::OPT_mno_stackrealign);
7013 if (Args.hasArg(options::OPT_mstack_alignment)) {
7014 StringRef alignment = Args.getLastArgValue(options::OPT_mstack_alignment);
7015 CmdArgs.push_back(Args.MakeArgString(
"-mstack-alignment=" + alignment));
7018 if (Args.hasArg(options::OPT_mstack_probe_size)) {
7019 StringRef Size = Args.getLastArgValue(options::OPT_mstack_probe_size);
7022 CmdArgs.push_back(Args.MakeArgString(
"-mstack-probe-size=" + Size));
7024 CmdArgs.push_back(
"-mstack-probe-size=0");
7027 Args.addOptOutFlag(CmdArgs, options::OPT_mstack_arg_probe,
7028 options::OPT_mno_stack_arg_probe);
7030 if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it,
7031 options::OPT_mno_restrict_it)) {
7032 if (A->getOption().matches(options::OPT_mrestrict_it)) {
7033 CmdArgs.push_back(
"-mllvm");
7034 CmdArgs.push_back(
"-arm-restrict-it");
7036 CmdArgs.push_back(
"-mllvm");
7037 CmdArgs.push_back(
"-arm-default-it");
7051 if (Args.hasFlag(options::OPT_fhip_new_launch_api,
7052 options::OPT_fno_hip_new_launch_api,
true))
7053 CmdArgs.push_back(
"-fhip-new-launch-api");
7054 Args.addOptInFlag(CmdArgs, options::OPT_fgpu_allow_device_init,
7055 options::OPT_fno_gpu_allow_device_init);
7056 Args.AddLastArg(CmdArgs, options::OPT_hipstdpar);
7057 Args.AddLastArg(CmdArgs, options::OPT_hipstdpar_interpose_alloc);
7058 Args.addOptInFlag(CmdArgs, options::OPT_fhip_kernel_arg_name,
7059 options::OPT_fno_hip_kernel_arg_name);
7062 if (IsCuda || IsHIP) {
7064 CmdArgs.push_back(
"-fgpu-rdc");
7065 Args.addOptInFlag(CmdArgs, options::OPT_fgpu_defer_diag,
7066 options::OPT_fno_gpu_defer_diag);
7067 if (Args.hasFlag(options::OPT_fgpu_exclude_wrong_side_overloads,
7068 options::OPT_fno_gpu_exclude_wrong_side_overloads,
7070 CmdArgs.push_back(
"-fgpu-exclude-wrong-side-overloads");
7071 CmdArgs.push_back(
"-fgpu-defer-diag");
7076 if (Args.hasArg(options::OPT_nogpulib))
7077 CmdArgs.push_back(
"-nogpulib");
7079 if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
7081 Args.MakeArgString(Twine(
"-fcf-protection=") + A->getValue()));
7083 if (Arg *SA = Args.getLastArg(options::OPT_mcf_branch_label_scheme_EQ))
7084 CmdArgs.push_back(Args.MakeArgString(Twine(
"-mcf-branch-label-scheme=") +
7088 if (Arg *A = Args.getLastArg(options::OPT_mfunction_return_EQ))
7090 Args.MakeArgString(Twine(
"-mfunction-return=") + A->getValue()));
7092 Args.AddLastArg(CmdArgs, options::OPT_mindirect_branch_cs_prefix);
7097 if (!(IsCudaDevice || IsHIPDevice)) {
7099 auto *PGOArg = Args.getLastArg(
7100 options::OPT_fprofile_generate, options::OPT_fprofile_generate_EQ,
7101 options::OPT_fcs_profile_generate,
7102 options::OPT_fcs_profile_generate_EQ, options::OPT_fprofile_use,
7103 options::OPT_fprofile_use_EQ);
7105 D.Diag(diag::err_drv_argument_not_allowed_with)
7106 <<
"SampleUse with PGO options";
7108 StringRef fname = A->getValue();
7109 if (!llvm::sys::fs::exists(fname))
7110 D.Diag(diag::err_drv_no_such_file) << fname;
7112 A->render(Args, CmdArgs);
7114 Args.AddLastArg(CmdArgs, options::OPT_fprofile_remapping_file_EQ);
7116 if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
7117 options::OPT_fno_pseudo_probe_for_profiling,
false)) {
7118 CmdArgs.push_back(
"-fpseudo-probe-for-profiling");
7121 if (Args.hasFlag(options::OPT_funique_internal_linkage_names,
7122 options::OPT_fno_unique_internal_linkage_names,
true))
7123 CmdArgs.push_back(
"-funique-internal-linkage-names");
7128 Args.addOptOutFlag(CmdArgs, options::OPT_fassume_sane_operator_new,
7129 options::OPT_fno_assume_sane_operator_new);
7131 if (Args.hasFlag(options::OPT_fapinotes, options::OPT_fno_apinotes,
false))
7132 CmdArgs.push_back(
"-fapinotes");
7133 if (Args.hasFlag(options::OPT_fapinotes_modules,
7134 options::OPT_fno_apinotes_modules,
false))
7135 CmdArgs.push_back(
"-fapinotes-modules");
7136 Args.AddLastArg(CmdArgs, options::OPT_fapinotes_swift_version);
7139 if (Args.hasFlag(options::OPT_fblocks, options::OPT_fno_blocks,
7141 (Args.hasArg(options::OPT_fgnu_runtime) &&
7142 Args.hasArg(options::OPT_fobjc_nonfragile_abi) &&
7143 !Args.hasArg(options::OPT_fno_blocks))) {
7144 CmdArgs.push_back(
"-fblocks");
7147 CmdArgs.push_back(
"-fblocks-runtime-optional");
7152 CmdArgs.push_back(
"-fencode-extended-block-signature");
7154 if (Args.hasFlag(options::OPT_fcoro_aligned_allocation,
7155 options::OPT_fno_coro_aligned_allocation,
false) &&
7157 CmdArgs.push_back(
"-fcoro-aligned-allocation");
7159 Args.AddLastArg(CmdArgs, options::OPT_fdouble_square_bracket_attributes,
7160 options::OPT_fno_double_square_bracket_attributes);
7162 Args.addOptOutFlag(CmdArgs, options::OPT_faccess_control,
7163 options::OPT_fno_access_control);
7164 Args.addOptOutFlag(CmdArgs, options::OPT_felide_constructors,
7165 options::OPT_fno_elide_constructors);
7171 CmdArgs.push_back(
"-fno-rtti");
7174 if (Args.hasFlag(options::OPT_fshort_enums, options::OPT_fno_short_enums,
7175 TC.
getArch() == llvm::Triple::hexagon || Triple.isOSzOS()))
7176 CmdArgs.push_back(
"-fshort-enums");
7182 options::OPT_fuse_cxa_atexit, options::OPT_fno_use_cxa_atexit,
7183 !RawTriple.isOSAIX() && !RawTriple.isOSWindows() &&
7184 ((RawTriple.getVendor() != llvm::Triple::MipsTechnologies) ||
7185 RawTriple.hasEnvironment())) ||
7187 CmdArgs.push_back(
"-fno-use-cxa-atexit");
7189 if (Args.hasFlag(options::OPT_fregister_global_dtors_with_atexit,
7190 options::OPT_fno_register_global_dtors_with_atexit,
7191 RawTriple.isOSDarwin() && !KernelOrKext))
7192 CmdArgs.push_back(
"-fregister-global-dtors-with-atexit");
7194 Args.addOptInFlag(CmdArgs, options::OPT_fuse_line_directives,
7195 options::OPT_fno_use_line_directives);
7198 if (Args.hasFlag(options::OPT_fminimize_whitespace,
7199 options::OPT_fno_minimize_whitespace,
false)) {
7200 types::ID InputType = Inputs[0].getType();
7201 if (!isDerivedFromC(InputType))
7202 D.Diag(diag::err_drv_opt_unsupported_input_type)
7204 CmdArgs.push_back(
"-fminimize-whitespace");
7208 if (Args.hasFlag(options::OPT_fkeep_system_includes,
7209 options::OPT_fno_keep_system_includes,
false)) {
7210 types::ID InputType = Inputs[0].getType();
7211 if (!isDerivedFromC(InputType))
7212 D.Diag(diag::err_drv_opt_unsupported_input_type)
7214 CmdArgs.push_back(
"-fkeep-system-includes");
7218 if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
7220 CmdArgs.push_back(
"-fms-extensions");
7223 bool IsMSVCCompat = Args.hasFlag(
7224 options::OPT_fms_compatibility, options::OPT_fno_ms_compatibility,
7225 (IsWindowsMSVC && Args.hasFlag(options::OPT_fms_extensions,
7226 options::OPT_fno_ms_extensions,
true)));
7228 CmdArgs.push_back(
"-fms-compatibility");
7230 Args.hasArg(options::OPT_fms_define_stdc))
7231 CmdArgs.push_back(
"-fms-define-stdc");
7234 if (Triple.isWindowsMSVCEnvironment() && !
D.IsCLMode() &&
7235 Args.hasArg(options::OPT_fms_runtime_lib_EQ))
7239 VersionTuple GNUCVer;
7240 if (Arg *A = Args.getLastArg(options::OPT_fgnuc_version_EQ)) {
7243 StringRef Val = A->getValue();
7244 Val = Val.empty() ?
"0" : Val;
7245 bool Invalid = GNUCVer.tryParse(Val);
7246 unsigned Minor = GNUCVer.getMinor().value_or(0);
7247 unsigned Patch = GNUCVer.getSubminor().value_or(0);
7248 if (
Invalid || GNUCVer.getBuild() || Minor >= 100 || Patch >= 100) {
7249 D.Diag(diag::err_drv_invalid_value)
7250 << A->getAsString(Args) << A->getValue();
7252 }
else if (!IsMSVCCompat) {
7254 GNUCVer = VersionTuple(4, 2, 1);
7256 if (!GNUCVer.empty()) {
7258 Args.MakeArgString(
"-fgnuc-version=" + GNUCVer.getAsString()));
7264 Args.MakeArgString(
"-fms-compatibility-version=" + MSVT.getAsString()));
7266 bool IsMSVC2015Compatible = MSVT.getMajor() >= 19;
7267 if (ImplyVCPPCVer) {
7268 StringRef LanguageStandard;
7269 if (
const Arg *StdArg = Args.getLastArg(options::OPT__SLASH_std)) {
7271 LanguageStandard = llvm::StringSwitch<StringRef>(StdArg->getValue())
7272 .Case(
"c11",
"-std=c11")
7273 .Case(
"c17",
"-std=c17")
7275 if (LanguageStandard.empty())
7276 D.Diag(clang::diag::warn_drv_unused_argument)
7277 << StdArg->getAsString(Args);
7279 CmdArgs.push_back(LanguageStandard.data());
7281 if (ImplyVCPPCXXVer) {
7282 StringRef LanguageStandard;
7283 if (
const Arg *StdArg = Args.getLastArg(options::OPT__SLASH_std)) {
7285 LanguageStandard = llvm::StringSwitch<StringRef>(StdArg->getValue())
7286 .Case(
"c++14",
"-std=c++14")
7287 .Case(
"c++17",
"-std=c++17")
7288 .Case(
"c++20",
"-std=c++20")
7290 .Case(
"c++23preview",
"-std=c++23")
7291 .Case(
"c++latest",
"-std=c++26")
7293 if (LanguageStandard.empty())
7294 D.Diag(clang::diag::warn_drv_unused_argument)
7295 << StdArg->getAsString(Args);
7298 if (LanguageStandard.empty()) {
7299 if (IsMSVC2015Compatible)
7300 LanguageStandard =
"-std=c++14";
7302 LanguageStandard =
"-std=c++11";
7305 CmdArgs.push_back(LanguageStandard.data());
7308 Args.addOptInFlag(CmdArgs, options::OPT_fborland_extensions,
7309 options::OPT_fno_borland_extensions);
7312 if (Args.hasFlag(options::OPT_fdeclspec, options::OPT_fno_declspec,
7314 CmdArgs.push_back(
"-fdeclspec");
7315 else if (Args.hasArg(options::OPT_fno_declspec))
7316 CmdArgs.push_back(
"-fno-declspec");
7320 if (!Args.hasFlag(options::OPT_fthreadsafe_statics,
7321 options::OPT_fno_threadsafe_statics,
7323 (!IsWindowsMSVC || IsMSVC2015Compatible)))
7324 CmdArgs.push_back(
"-fno-threadsafe-statics");
7326 if (!Args.hasFlag(options::OPT_fms_tls_guards, options::OPT_fno_ms_tls_guards,
7328 CmdArgs.push_back(
"-fno-ms-tls-guards");
7331 if (!Args.hasFlag(options::OPT_fassumptions, options::OPT_fno_assumptions,
7333 CmdArgs.push_back(
"-fno-assumptions");
7337 Args.AddLastArg(CmdArgs, options::OPT_fgnu_keywords,
7338 options::OPT_fno_gnu_keywords);
7340 Args.addOptInFlag(CmdArgs, options::OPT_fgnu89_inline,
7341 options::OPT_fno_gnu89_inline);
7343 const Arg *InlineArg = Args.getLastArg(options::OPT_finline_functions,
7344 options::OPT_finline_hint_functions,
7345 options::OPT_fno_inline_functions);
7346 if (Arg *A = Args.getLastArg(options::OPT_finline, options::OPT_fno_inline)) {
7347 if (A->getOption().matches(options::OPT_fno_inline))
7348 A->render(Args, CmdArgs);
7349 }
else if (InlineArg) {
7350 InlineArg->render(Args, CmdArgs);
7353 Args.AddLastArg(CmdArgs, options::OPT_finline_max_stacksize_EQ);
7358 (
Std->containsValue(
"c++2a") ||
Std->containsValue(
"gnu++2a") ||
7359 Std->containsValue(
"c++20") ||
Std->containsValue(
"gnu++20") ||
7360 Std->containsValue(
"c++2b") ||
Std->containsValue(
"gnu++2b") ||
7361 Std->containsValue(
"c++23") ||
Std->containsValue(
"gnu++23") ||
7362 Std->containsValue(
"c++2c") ||
Std->containsValue(
"gnu++2c") ||
7363 Std->containsValue(
"c++26") ||
Std->containsValue(
"gnu++26") ||
7364 Std->containsValue(
"c++latest") ||
Std->containsValue(
"gnu++latest"));
7379 if (Args.hasFlag(options::OPT_fdelayed_template_parsing,
7380 options::OPT_fno_delayed_template_parsing,
7381 IsWindowsMSVC && !HaveCxx20)) {
7383 D.Diag(clang::diag::warn_drv_delayed_template_parsing_after_cxx20);
7385 CmdArgs.push_back(
"-fdelayed-template-parsing");
7388 if (Args.hasFlag(options::OPT_fpch_validate_input_files_content,
7389 options::OPT_fno_pch_validate_input_files_content,
false))
7390 CmdArgs.push_back(
"-fvalidate-ast-input-files-content");
7391 if (Args.hasFlag(options::OPT_fpch_instantiate_templates,
7392 options::OPT_fno_pch_instantiate_templates,
false))
7393 CmdArgs.push_back(
"-fpch-instantiate-templates");
7394 if (Args.hasFlag(options::OPT_fpch_codegen, options::OPT_fno_pch_codegen,
7396 CmdArgs.push_back(
"-fmodules-codegen");
7397 if (Args.hasFlag(options::OPT_fpch_debuginfo, options::OPT_fno_pch_debuginfo,
7399 CmdArgs.push_back(
"-fmodules-debuginfo");
7401 ObjCRuntime Runtime = AddObjCRuntimeArgs(Args, Inputs, CmdArgs, rewriteKind);
7406 Args.hasFlag(options::OPT_fobjc_encode_cxx_class_template_spec,
7407 options::OPT_fno_objc_encode_cxx_class_template_spec,
7409 CmdArgs.push_back(
"-fobjc-encode-cxx-class-template-spec");
7411 if (Args.hasFlag(options::OPT_fapplication_extension,
7412 options::OPT_fno_application_extension,
false))
7413 CmdArgs.push_back(
"-fapplication-extension");
7417 if (!
C.getDriver().IsCLMode())
7418 EH =
addExceptionArgs(Args, InputType, TC, KernelOrKext, Runtime, CmdArgs);
7421 Arg *A = Args.getLastArg(
7422 options::OPT_fsjlj_exceptions, options::OPT_fseh_exceptions,
7423 options::OPT_fdwarf_exceptions, options::OPT_fwasm_exceptions);
7425 const Option &Opt = A->getOption();
7426 if (Opt.matches(options::OPT_fsjlj_exceptions))
7427 CmdArgs.push_back(
"-exception-model=sjlj");
7428 if (Opt.matches(options::OPT_fseh_exceptions))
7429 CmdArgs.push_back(
"-exception-model=seh");
7430 if (Opt.matches(options::OPT_fdwarf_exceptions))
7431 CmdArgs.push_back(
"-exception-model=dwarf");
7432 if (Opt.matches(options::OPT_fwasm_exceptions))
7433 CmdArgs.push_back(
"-exception-model=wasm");
7438 case llvm::ExceptionHandling::DwarfCFI:
7439 CmdArgs.push_back(
"-exception-model=dwarf");
7441 case llvm::ExceptionHandling::SjLj:
7442 CmdArgs.push_back(
"-exception-model=sjlj");
7444 case llvm::ExceptionHandling::WinEH:
7445 CmdArgs.push_back(
"-exception-model=seh");
7451 Args.addOptOutFlag(CmdArgs, options::OPT_fassume_sane_operator_new,
7452 options::OPT_fno_assume_sane_operator_new);
7455 Args.addOptOutFlag(CmdArgs, options::OPT_fassume_unique_vtables,
7456 options::OPT_fno_assume_unique_vtables);
7460 Args.getLastArg(options::OPT_frelaxed_template_template_args,
7461 options::OPT_fno_relaxed_template_template_args)) {
7462 if (A->getOption().matches(
7463 options::OPT_fno_relaxed_template_template_args)) {
7464 D.Diag(diag::warn_drv_deprecated_arg_no_relaxed_template_template_args);
7465 CmdArgs.push_back(
"-fno-relaxed-template-template-args");
7467 D.Diag(diag::warn_drv_deprecated_arg)
7468 << A->getAsString(Args) <<
false;
7474 Args.addLastArg(CmdArgs, options::OPT_fsized_deallocation,
7475 options::OPT_fno_sized_deallocation);
7479 if (Arg *A = Args.getLastArg(options::OPT_faligned_allocation,
7480 options::OPT_fno_aligned_allocation,
7481 options::OPT_faligned_new_EQ)) {
7482 if (A->getOption().matches(options::OPT_fno_aligned_allocation))
7483 CmdArgs.push_back(
"-fno-aligned-allocation");
7485 CmdArgs.push_back(
"-faligned-allocation");
7490 if (Arg *A = Args.getLastArg(options::OPT_fnew_alignment_EQ,
7491 options::OPT_faligned_new_EQ))
7493 Args.MakeArgString(Twine(
"-fnew-alignment=") + A->getValue()));
7497 if (!Args.hasFlag(options::OPT_fconstant_cfstrings,
7498 options::OPT_fno_constant_cfstrings,
true) ||
7499 !Args.hasFlag(options::OPT_mconstant_cfstrings,
7500 options::OPT_mno_constant_cfstrings,
true))
7501 CmdArgs.push_back(
"-fno-constant-cfstrings");
7503 Args.addOptInFlag(CmdArgs, options::OPT_fpascal_strings,
7504 options::OPT_fno_pascal_strings);
7508 if (Arg *A = Args.getLastArg(options::OPT_fpack_struct_EQ)) {
7509 std::string PackStructStr =
"-fpack-struct=";
7510 PackStructStr += A->getValue();
7511 CmdArgs.push_back(Args.MakeArgString(PackStructStr));
7512 }
else if (Args.hasFlag(options::OPT_fpack_struct,
7513 options::OPT_fno_pack_struct,
false)) {
7514 CmdArgs.push_back(
"-fpack-struct=1");
7518 bool SkipMaxTypeAlign = Args.hasArg(options::OPT_fno_max_type_align);
7519 if (Arg *A = Args.getLastArg(options::OPT_fmax_type_align_EQ)) {
7520 if (!SkipMaxTypeAlign) {
7521 std::string MaxTypeAlignStr =
"-fmax-type-align=";
7522 MaxTypeAlignStr += A->getValue();
7523 CmdArgs.push_back(Args.MakeArgString(MaxTypeAlignStr));
7525 }
else if (RawTriple.isOSDarwin()) {
7526 if (!SkipMaxTypeAlign) {
7527 std::string MaxTypeAlignStr =
"-fmax-type-align=16";
7528 CmdArgs.push_back(Args.MakeArgString(MaxTypeAlignStr));
7532 if (!Args.hasFlag(options::OPT_Qy, options::OPT_Qn,
true))
7533 CmdArgs.push_back(
"-Qn");
7536 Args.addOptInFlag(CmdArgs, options::OPT_fcommon, options::OPT_fno_common);
7540 if (!Args.hasFlag(options::OPT_fsigned_bitfields,
7541 options::OPT_funsigned_bitfields,
true))
7542 D.Diag(diag::warn_drv_clang_unsupported)
7543 << Args.getLastArg(options::OPT_funsigned_bitfields)->getAsString(Args);
7546 if (!Args.hasFlag(options::OPT_ffor_scope, options::OPT_fno_for_scope,
true))
7547 D.Diag(diag::err_drv_clang_unsupported)
7548 << Args.getLastArg(options::OPT_fno_for_scope)->getAsString(Args);
7551 if (Arg *inputCharset = Args.getLastArg(options::OPT_finput_charset_EQ)) {
7552 StringRef value = inputCharset->getValue();
7553 if (!value.equals_insensitive(
"utf-8"))
7554 D.Diag(diag::err_drv_invalid_value) << inputCharset->getAsString(Args)
7559 if (Arg *execCharset = Args.getLastArg(options::OPT_fexec_charset_EQ)) {
7560 StringRef value = execCharset->getValue();
7561 if (!value.equals_insensitive(
"utf-8"))
7562 D.Diag(diag::err_drv_invalid_value) << execCharset->getAsString(Args)
7568 Args.addOptInFlag(CmdArgs, options::OPT_fasm_blocks,
7569 options::OPT_fno_asm_blocks);
7571 Args.addOptOutFlag(CmdArgs, options::OPT_fgnu_inline_asm,
7572 options::OPT_fno_gnu_inline_asm);
7578 OptSpecifier VectorizeAliasOption =
7579 EnableVec ? options::OPT_O_Group : options::OPT_fvectorize;
7580 if (Args.hasFlag(options::OPT_fvectorize, VectorizeAliasOption,
7581 options::OPT_fno_vectorize, EnableVec))
7582 CmdArgs.push_back(
"-vectorize-loops");
7586 OptSpecifier SLPVectAliasOption =
7587 EnableSLPVec ? options::OPT_O_Group : options::OPT_fslp_vectorize;
7588 if (Args.hasFlag(options::OPT_fslp_vectorize, SLPVectAliasOption,
7589 options::OPT_fno_slp_vectorize, EnableSLPVec))
7590 CmdArgs.push_back(
"-vectorize-slp");
7594 Args.AddLastArg(CmdArgs, options::OPT_fshow_overloads_EQ);
7595 Args.AddLastArg(CmdArgs,
7596 options::OPT_fsanitize_undefined_strip_path_components_EQ);
7600 if (Arg *A = Args.getLastArg(options::OPT_fdollars_in_identifiers,
7601 options::OPT_fno_dollars_in_identifiers)) {
7602 if (A->getOption().matches(options::OPT_fdollars_in_identifiers))
7603 CmdArgs.push_back(
"-fdollars-in-identifiers");
7605 CmdArgs.push_back(
"-fno-dollars-in-identifiers");
7608 Args.addOptInFlag(CmdArgs, options::OPT_fapple_pragma_pack,
7609 options::OPT_fno_apple_pragma_pack);
7615 bool RewriteImports = Args.hasFlag(options::OPT_frewrite_imports,
7616 options::OPT_fno_rewrite_imports,
false);
7618 CmdArgs.push_back(
"-frewrite-imports");
7620 Args.addOptInFlag(CmdArgs, options::OPT_fdirectives_only,
7621 options::OPT_fno_directives_only);
7627 if (Args.hasFlag(options::OPT_frewrite_includes,
7628 options::OPT_fno_rewrite_includes,
false) ||
7629 (
C.isForDiagnostics() && !HaveModules))
7630 CmdArgs.push_back(
"-frewrite-includes");
7632 if (Args.hasFlag(options::OPT_fzos_extensions,
7633 options::OPT_fno_zos_extensions,
false))
7634 CmdArgs.push_back(
"-fzos-extensions");
7635 else if (Args.hasArg(options::OPT_fno_zos_extensions))
7636 CmdArgs.push_back(
"-fno-zos-extensions");
7639 if (Arg *A = Args.getLastArg(options::OPT_traditional,
7640 options::OPT_traditional_cpp)) {
7641 if (isa<PreprocessJobAction>(JA))
7642 CmdArgs.push_back(
"-traditional-cpp");
7644 D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
7647 Args.AddLastArg(CmdArgs, options::OPT_dM);
7648 Args.AddLastArg(CmdArgs, options::OPT_dD);
7649 Args.AddLastArg(CmdArgs, options::OPT_dI);
7651 Args.AddLastArg(CmdArgs, options::OPT_fmax_tokens_EQ);
7654 if (Arg *A = Args.getLastArg(options::OPT__serialize_diags)) {
7655 CmdArgs.push_back(
"-serialize-diagnostic-file");
7656 CmdArgs.push_back(Args.MakeArgString(A->getValue()));
7659 if (Args.hasArg(options::OPT_fretain_comments_from_system_headers))
7660 CmdArgs.push_back(
"-fretain-comments-from-system-headers");
7663 Args.AddAllArgs(CmdArgs, options::OPT_fcomment_block_commands);
7665 Args.AddAllArgs(CmdArgs, options::OPT_fparse_all_comments);
7668 for (
const Arg *A : Args.filtered(options::OPT_fplugin_EQ)) {
7669 CmdArgs.push_back(
"-load");
7670 CmdArgs.push_back(A->getValue());
7682 for (
const Arg *A : Args.filtered(options::OPT_fplugin_arg)) {
7683 auto ArgValue = StringRef(A->getValue());
7684 auto FirstDashIndex = ArgValue.find(
'-');
7685 StringRef PluginName = ArgValue.substr(0, FirstDashIndex);
7686 StringRef Arg = ArgValue.substr(FirstDashIndex + 1);
7689 if (FirstDashIndex == StringRef::npos || Arg.empty()) {
7690 if (PluginName.empty()) {
7691 D.Diag(diag::warn_drv_missing_plugin_name) << A->getAsString(Args);
7693 D.Diag(diag::warn_drv_missing_plugin_arg)
7694 << PluginName << A->getAsString(Args);
7699 CmdArgs.push_back(Args.MakeArgString(Twine(
"-plugin-arg-") + PluginName));
7700 CmdArgs.push_back(Args.MakeArgString(Arg));
7704 for (
const Arg *A : Args.filtered(options::OPT_fpass_plugin_EQ)) {
7706 Args.MakeArgString(Twine(
"-fpass-plugin=") + A->getValue()));
7711 for (
const Arg *A : Args.filtered(options::OPT_vfsoverlay)) {
7712 CmdArgs.push_back(
"--vfsoverlay");
7713 CmdArgs.push_back(A->getValue());
7717 Args.addOptInFlag(CmdArgs, options::OPT_fsafe_buffer_usage_suggestions,
7718 options::OPT_fno_safe_buffer_usage_suggestions);
7720 Args.addOptInFlag(CmdArgs, options::OPT_fexperimental_late_parse_attributes,
7721 options::OPT_fno_experimental_late_parse_attributes);
7725 if (!StatsFile.empty()) {
7726 CmdArgs.push_back(Args.MakeArgString(Twine(
"-stats-file=") + StatsFile));
7727 if (
D.CCPrintInternalStats)
7728 CmdArgs.push_back(
"-stats-file-append");
7733 for (
auto Arg : Args.filtered(options::OPT_Xclang)) {
7737 if (
C.getDriver().isSaveTempsEnabled() &&
7738 !isa<PreprocessJobAction>(JA)) {
7739 if (StringRef(Arg->getValue()) ==
"-finclude-default-header")
7742 CmdArgs.push_back(Arg->getValue());
7744 for (
const Arg *A : Args.filtered(options::OPT_mllvm)) {
7750 if (StringRef(A->getValue(0)) ==
"-disable-llvm-optzns") {
7751 CmdArgs.push_back(
"-disable-llvm-optzns");
7753 A->render(Args, CmdArgs);
7759 SanitizeArgs.addArgs(TC, Args, CmdArgs, InputType);
7769 if ((
C.getDriver().isSaveTempsEnabled() ||
7771 !(
C.getDriver().embedBitcodeInObject() && !IsUsingLTO) &&
7772 isa<CompileJobAction>(JA))
7773 CmdArgs.push_back(
"-disable-llvm-passes");
7775 Args.AddAllArgs(CmdArgs, options::OPT_undef);
7777 const char *Exec =
D.getClangProgramPath();
7784 auto GRecordSwitches =
false;
7785 auto FRecordSwitches =
false;
7789 CmdArgs.push_back(
"-dwarf-debug-flags");
7790 CmdArgs.push_back(FlagsArgString);
7792 if (FRecordSwitches) {
7793 CmdArgs.push_back(
"-record-command-line");
7794 CmdArgs.push_back(FlagsArgString);
7801 if ((IsCuda || IsHIP) && CudaDeviceInput) {
7802 CmdArgs.push_back(
"-fcuda-include-gpubinary");
7803 CmdArgs.push_back(CudaDeviceInput->
getFilename());
7804 }
else if (!HostOffloadingInputs.empty()) {
7805 if ((IsCuda || IsHIP) && !IsRDCMode) {
7806 assert(HostOffloadingInputs.size() == 1 &&
"Only one input expected");
7807 CmdArgs.push_back(
"-fcuda-include-gpubinary");
7808 CmdArgs.push_back(HostOffloadingInputs.front().getFilename());
7810 for (
const InputInfo Input : HostOffloadingInputs)
7811 CmdArgs.push_back(Args.MakeArgString(
"-fembed-offload-object=" +
7817 if (Args.hasFlag(options::OPT_fcuda_short_ptr,
7818 options::OPT_fno_cuda_short_ptr,
false))
7819 CmdArgs.push_back(
"-fcuda-short-ptr");
7822 if (IsCuda || IsHIP) {
7824 const Action *SourceAction = &JA;
7826 assert(!SourceAction->
getInputs().empty() &&
"unexpected root action!");
7827 SourceAction = SourceAction->
getInputs()[0];
7829 auto CUID = cast<InputAction>(SourceAction)->getId();
7831 CmdArgs.push_back(Args.MakeArgString(Twine(
"-cuid=") + Twine(CUID)));
7835 bool UseApproxTranscendentals = Args.hasFlag(
7836 options::OPT_ffast_math, options::OPT_fno_fast_math,
false);
7837 if (Args.hasFlag(options::OPT_fgpu_approx_transcendentals,
7838 options::OPT_fno_gpu_approx_transcendentals,
7839 UseApproxTranscendentals))
7840 CmdArgs.push_back(
"-fgpu-approx-transcendentals");
7842 Args.claimAllArgs(options::OPT_fgpu_approx_transcendentals,
7843 options::OPT_fno_gpu_approx_transcendentals);
7847 CmdArgs.push_back(
"-fcuda-allow-variadic-functions");
7848 Args.AddLastArg(CmdArgs, options::OPT_fgpu_default_stream_EQ);
7851 Args.AddAllArgs(CmdArgs,
7852 options::OPT_fsanitize_undefined_ignore_overflow_pattern_EQ);
7854 Args.AddLastArg(CmdArgs, options::OPT_foffload_uniform_block,
7855 options::OPT_fno_offload_uniform_block);
7857 Args.AddLastArg(CmdArgs, options::OPT_foffload_implicit_host_device_templates,
7858 options::OPT_fno_offload_implicit_host_device_templates);
7860 if (IsCudaDevice || IsHIPDevice) {
7861 StringRef InlineThresh =
7862 Args.getLastArgValue(options::OPT_fgpu_inline_threshold_EQ);
7863 if (!InlineThresh.empty()) {
7864 std::string ArgStr =
7865 std::string(
"-inline-threshold=") + InlineThresh.str();
7866 CmdArgs.append({
"-mllvm", Args.MakeArgStringRef(ArgStr)});
7871 Args.addOptOutFlag(CmdArgs,
7872 options::OPT_fhip_fp32_correctly_rounded_divide_sqrt,
7873 options::OPT_fno_hip_fp32_correctly_rounded_divide_sqrt);
7880 if (IsOpenMPDevice) {
7881 CmdArgs.push_back(
"-fopenmp-is-target-device");
7883 if (Args.hasArg(options::OPT_foffload_via_llvm))
7884 CmdArgs.push_back(
"-fcuda-is-device");
7886 if (OpenMPDeviceInput) {
7887 CmdArgs.push_back(
"-fopenmp-host-ir-file-path");
7888 CmdArgs.push_back(Args.MakeArgString(OpenMPDeviceInput->
getFilename()));
7892 if (Triple.isAMDGPU()) {
7895 Args.addOptInFlag(CmdArgs, options::OPT_munsafe_fp_atomics,
7896 options::OPT_mno_unsafe_fp_atomics);
7897 Args.addOptOutFlag(CmdArgs, options::OPT_mamdgpu_ieee,
7898 options::OPT_mno_amdgpu_ieee);
7903 bool VirtualFunctionElimination =
7904 Args.hasFlag(options::OPT_fvirtual_function_elimination,
7905 options::OPT_fno_virtual_function_elimination,
false);
7906 if (VirtualFunctionElimination) {
7910 D.Diag(diag::err_drv_argument_only_allowed_with)
7911 <<
"-fvirtual-function-elimination"
7914 CmdArgs.push_back(
"-fvirtual-function-elimination");
7918 bool WholeProgramVTables = Args.hasFlag(
7919 options::OPT_fwhole_program_vtables,
7920 options::OPT_fno_whole_program_vtables, VirtualFunctionElimination);
7921 if (VirtualFunctionElimination && !WholeProgramVTables) {
7922 D.Diag(diag::err_drv_argument_not_allowed_with)
7923 <<
"-fno-whole-program-vtables"
7924 <<
"-fvirtual-function-elimination";
7927 if (WholeProgramVTables) {
7939 IsDeviceOffloadAction ?
D.getLTOMode() :
D.getOffloadLTOMode();
7940 auto OtherIsUsingLTO = OtherLTOMode !=
LTOK_None;
7942 if ((!IsUsingLTO && !OtherIsUsingLTO) ||
7943 (IsPS4 && !UnifiedLTO && (
D.getLTOMode() !=
LTOK_Full)))
7944 D.Diag(diag::err_drv_argument_only_allowed_with)
7945 <<
"-fwhole-program-vtables"
7946 << ((IsPS4 && !UnifiedLTO) ?
"-flto=full" :
"-flto");
7950 CmdArgs.push_back(
"-fwhole-program-vtables");
7953 bool DefaultsSplitLTOUnit =
7954 ((WholeProgramVTables || SanitizeArgs.needsLTO()) &&
7956 (!Triple.isPS4() && UnifiedLTO);
7958 Args.hasFlag(options::OPT_fsplit_lto_unit,
7959 options::OPT_fno_split_lto_unit, DefaultsSplitLTOUnit);
7960 if (SanitizeArgs.needsLTO() && !SplitLTOUnit)
7961 D.Diag(diag::err_drv_argument_not_allowed_with) <<
"-fno-split-lto-unit"
7962 <<
"-fsanitize=cfi";
7964 CmdArgs.push_back(
"-fsplit-lto-unit");
7966 if (Arg *A = Args.getLastArg(options::OPT_ffat_lto_objects,
7967 options::OPT_fno_fat_lto_objects)) {
7968 if (IsUsingLTO && A->getOption().matches(options::OPT_ffat_lto_objects)) {
7970 if (!Triple.isOSBinFormatELF()) {
7971 D.Diag(diag::err_drv_unsupported_opt_for_target)
7974 CmdArgs.push_back(Args.MakeArgString(
7975 Twine(
"-flto=") + (LTOMode ==
LTOK_Thin ?
"thin" :
"full")));
7976 CmdArgs.push_back(
"-flto-unit");
7977 CmdArgs.push_back(
"-ffat-lto-objects");
7978 A->render(Args, CmdArgs);
7982 if (Arg *A = Args.getLastArg(options::OPT_fglobal_isel,
7983 options::OPT_fno_global_isel)) {
7984 CmdArgs.push_back(
"-mllvm");
7985 if (A->getOption().matches(options::OPT_fglobal_isel)) {
7986 CmdArgs.push_back(
"-global-isel=1");
7991 bool IsArchSupported = Triple.getArch() == llvm::Triple::aarch64;
7992 bool IsOptLevelSupported =
false;
7994 Arg *A = Args.getLastArg(options::OPT_O_Group);
7995 if (Triple.getArch() == llvm::Triple::aarch64) {
7996 if (!A || A->getOption().matches(options::OPT_O0))
7997 IsOptLevelSupported =
true;
7999 if (!IsArchSupported || !IsOptLevelSupported) {
8000 CmdArgs.push_back(
"-mllvm");
8001 CmdArgs.push_back(
"-global-isel-abort=2");
8003 if (!IsArchSupported)
8004 D.Diag(diag::warn_drv_global_isel_incomplete) << Triple.getArchName();
8006 D.Diag(diag::warn_drv_global_isel_incomplete_opt);
8009 CmdArgs.push_back(
"-global-isel=0");
8013 if (Args.hasArg(options::OPT_forder_file_instrumentation)) {
8014 CmdArgs.push_back(
"-forder-file-instrumentation");
8019 CmdArgs.push_back(
"-mllvm");
8020 CmdArgs.push_back(
"-enable-order-file-instrumentation");
8024 if (Arg *A = Args.getLastArg(options::OPT_fforce_enable_int128,
8025 options::OPT_fno_force_enable_int128)) {
8026 if (A->getOption().matches(options::OPT_fforce_enable_int128))
8027 CmdArgs.push_back(
"-fforce-enable-int128");
8030 Args.addOptInFlag(CmdArgs, options::OPT_fkeep_static_consts,
8031 options::OPT_fno_keep_static_consts);
8032 Args.addOptInFlag(CmdArgs, options::OPT_fkeep_persistent_storage_variables,
8033 options::OPT_fno_keep_persistent_storage_variables);
8034 Args.addOptInFlag(CmdArgs, options::OPT_fcomplete_member_pointers,
8035 options::OPT_fno_complete_member_pointers);
8036 if (Arg *A = Args.getLastArg(options::OPT_cxx_static_destructors_EQ))
8037 A->render(Args, CmdArgs);
8043 if (Triple.isAArch64() &&
8044 (Args.hasArg(options::OPT_mno_fmv) ||
8045 (Triple.isAndroid() && Triple.isAndroidVersionLT(23)) ||
8048 CmdArgs.push_back(
"-target-feature");
8049 CmdArgs.push_back(
"-fmv");
8052 if (Args.hasFlag(options::OPT_faddrsig, options::OPT_fno_addrsig,
8059 CmdArgs.push_back(
"-faddrsig");
8061 if ((Triple.isOSBinFormatELF() || Triple.isOSBinFormatMachO()) &&
8062 (EH || UnwindTables || AsyncUnwindTables ||
8063 DebugInfoKind != llvm::codegenoptions::NoDebugInfo))
8064 CmdArgs.push_back(
"-D__GCC_HAVE_DWARF2_CFI_ASM=1");
8066 if (Arg *A = Args.getLastArg(options::OPT_fsymbol_partition_EQ)) {
8067 std::string Str = A->getAsString(Args);
8069 D.Diag(diag::err_drv_unsupported_opt_for_target)
8071 CmdArgs.push_back(Args.MakeArgString(Str));
8076 if (Output.
getType() == types::TY_Dependencies) {
8079 if (Output.
getType() == clang::driver::types::TY_IFS_CPP ||
8080 Output.
getType() == clang::driver::types::TY_IFS) {
8082 llvm::sys::path::replace_extension(OutputFilename,
"ifs");
8083 CmdArgs.push_back(
"-o");
8084 CmdArgs.push_back(Args.MakeArgString(OutputFilename));
8086 CmdArgs.push_back(
"-o");
8090 assert(Output.
isNothing() &&
"Invalid output.");
8097 FrontendInputs = ExtractAPIInputs;
8099 FrontendInputs = {};
8101 for (
const InputInfo &Input : FrontendInputs) {
8108 if (
D.CC1Main && !
D.CCGenDiagnostics) {
8110 C.addCommand(std::make_unique<CC1Command>(
8112 Output,
D.getPrependArg()));
8114 C.addCommand(std::make_unique<Command>(
8116 Output,
D.getPrependArg()));
8120 if (Output.
getType() == types::TY_Object &&
8121 Args.hasFlag(options::OPT__SLASH_showFilenames,
8122 options::OPT__SLASH_showFilenames_,
false)) {
8123 C.getJobs().getJobs().back()->PrintInputFilenames =
true;
8126 if (Arg *A = Args.getLastArg(options::OPT_pg))
8128 !Args.hasArg(options::OPT_mfentry))
8129 D.Diag(diag::err_drv_argument_not_allowed_with) <<
"-fomit-frame-pointer"
8130 << A->getAsString(Args);
8136 Args.ClaimAllArgs(options::OPT_fpch_preprocess);
8140 Args.ClaimAllArgs(options::OPT_clang_ignored_f_Group);
8141 Args.ClaimAllArgs(options::OPT_clang_ignored_m_Group);
8144 Args.ClaimAllArgs(options::OPT_emit_llvm);
8151 :
Tool(
"clang",
"clang frontend", TC), HasBackend(HasIntegratedBackend) {}
8158ObjCRuntime Clang::AddObjCRuntimeArgs(
const ArgList &args,
8160 ArgStringList &cmdArgs,
8161 RewriteKind rewriteKind)
const {
8164 args.getLastArg(options::OPT_fnext_runtime, options::OPT_fgnu_runtime,
8165 options::OPT_fobjc_runtime_EQ);
8170 runtimeArg->getOption().matches(options::OPT_fobjc_runtime_EQ)) {
8172 StringRef value = runtimeArg->getValue();
8178 (runtime.
getVersion() >= VersionTuple(2, 0)))
8182 diag::err_drv_gnustep_objc_runtime_incompatible_binary)
8186 runtimeArg->render(args, cmdArgs);
8195 unsigned objcABIVersion = 1;
8197 if (Arg *abiArg = args.getLastArg(options::OPT_fobjc_abi_version_EQ)) {
8198 StringRef value = abiArg->getValue();
8201 else if (value ==
"2")
8203 else if (value ==
"3")
8209 bool nonFragileABIIsDefault =
8210 (rewriteKind == RK_NonFragile ||
8211 (rewriteKind == RK_None &&
8213 if (args.hasFlag(options::OPT_fobjc_nonfragile_abi,
8214 options::OPT_fno_objc_nonfragile_abi,
8215 nonFragileABIIsDefault)) {
8217#ifdef DISABLE_DEFAULT_NONFRAGILEABI_TWO
8218 unsigned nonFragileABIVersion = 1;
8220 unsigned nonFragileABIVersion = 2;
8224 args.getLastArg(options::OPT_fobjc_nonfragile_abi_version_EQ)) {
8225 StringRef value = abiArg->getValue();
8227 nonFragileABIVersion = 1;
8228 else if (value ==
"2")
8229 nonFragileABIVersion = 2;
8235 objcABIVersion = 1 + nonFragileABIVersion;
8243 bool isNonFragile = objcABIVersion != 1;
8249 switch (rewriteKind) {
8262 }
else if (runtimeArg->getOption().matches(options::OPT_fnext_runtime)) {
8274 assert(runtimeArg->getOption().matches(options::OPT_fgnu_runtime));
8283 if (llvm::any_of(inputs, [](
const InputInfo &input) {
8287 args.MakeArgString(
"-fobjc-runtime=" + runtime.
getAsString()));
8292 bool HaveDash = (I + 1 < EH.size() && EH[I + 1] ==
'-');
8300 bool Asynch =
false;
8301 bool NoUnwindC =
false;
8313 bool isWindowsMSVC) {
8316 std::vector<std::string> EHArgs =
8317 Args.getAllArgValues(options::OPT__SLASH_EH);
8318 for (
const auto &EHVal : EHArgs) {
8319 for (
size_t I = 0,
E = EHVal.size(); I !=
E; ++I) {
8325 if (!isWindowsMSVC) {
8327 D.Diag(clang::diag::warn_drv_unused_argument) <<
"/EHa" << EHVal;
8344 D.Diag(clang::diag::err_drv_invalid_value) <<
"/EH" << EHVal;
8350 if (EHArgs.empty() &&
8351 Args.hasFlag(options::OPT__SLASH_GX, options::OPT__SLASH_GX_,
8354 EH.NoUnwindC =
true;
8357 if (Args.hasArg(options::OPT__SLASH_kernel)) {
8359 EH.NoUnwindC =
false;
8366void Clang::AddClangCLArgs(
const ArgList &Args,
types::ID InputType,
8367 ArgStringList &CmdArgs)
const {
8372 if (Arg *ShowIncludes =
8373 Args.getLastArg(options::OPT__SLASH_showIncludes,
8374 options::OPT__SLASH_showIncludes_user)) {
8375 CmdArgs.push_back(
"--show-includes");
8376 if (ShowIncludes->getOption().matches(options::OPT__SLASH_showIncludes))
8377 CmdArgs.push_back(
"-sys-header-deps");
8381 if (Args.hasFlag(options::OPT__SLASH_GR_, options::OPT__SLASH_GR,
8383 CmdArgs.push_back(
"-fno-rtti-data");
8387 if (!isNVPTX && Args.hasFlag(options::OPT__SLASH_GS, options::OPT__SLASH_GS_,
8389 CmdArgs.push_back(
"-stack-protector");
8397 if (!isNVPTX && (EH.Synch || EH.Asynch)) {
8399 CmdArgs.push_back(
"-fcxx-exceptions");
8400 CmdArgs.push_back(
"-fexceptions");
8402 CmdArgs.push_back(
"-fasync-exceptions");
8404 if (
types::isCXX(InputType) && EH.Synch && EH.NoUnwindC)
8405 CmdArgs.push_back(
"-fexternc-nounwind");
8408 if (Args.hasArg(options::OPT__SLASH_EP)) {
8409 CmdArgs.push_back(
"-E");
8410 CmdArgs.push_back(
"-P");
8413 if (Args.hasFlag(options::OPT__SLASH_Zc_dllexportInlines_,
8414 options::OPT__SLASH_Zc_dllexportInlines,
8416 CmdArgs.push_back(
"-fno-dllexport-inlines");
8419 if (Args.hasFlag(options::OPT__SLASH_Zc_wchar_t_,
8420 options::OPT__SLASH_Zc_wchar_t,
false)) {
8421 CmdArgs.push_back(
"-fno-wchar");
8424 if (Args.hasArg(options::OPT__SLASH_kernel)) {
8426 std::vector<std::string> Values =
8427 Args.getAllArgValues(options::OPT__SLASH_arch);
8428 if (!Values.empty()) {
8429 llvm::SmallSet<std::string, 4> SupportedArches;
8430 if (Arch == llvm::Triple::x86)
8431 SupportedArches.insert(
"IA32");
8433 for (
auto &
V : Values)
8434 if (!SupportedArches.contains(
V))
8435 D.Diag(diag::err_drv_argument_not_allowed_with)
8436 << std::string(
"/arch:").append(
V) <<
"/kernel";
8439 CmdArgs.push_back(
"-fno-rtti");
8440 if (Args.hasFlag(options::OPT__SLASH_GR, options::OPT__SLASH_GR_,
false))
8441 D.Diag(diag::err_drv_argument_not_allowed_with) <<
"/GR"
8445 Arg *MostGeneralArg = Args.getLastArg(options::OPT__SLASH_vmg);
8446 Arg *BestCaseArg = Args.getLastArg(options::OPT__SLASH_vmb);
8447 if (MostGeneralArg && BestCaseArg)
8448 D.Diag(clang::diag::err_drv_argument_not_allowed_with)
8449 << MostGeneralArg->getAsString(Args) << BestCaseArg->getAsString(Args);
8451 if (MostGeneralArg) {
8452 Arg *SingleArg = Args.getLastArg(options::OPT__SLASH_vms);
8453 Arg *MultipleArg = Args.getLastArg(options::OPT__SLASH_vmm);
8454 Arg *VirtualArg = Args.getLastArg(options::OPT__SLASH_vmv);
8456 Arg *FirstConflict = SingleArg ? SingleArg : MultipleArg;
8457 Arg *SecondConflict = VirtualArg ? VirtualArg : MultipleArg;
8458 if (FirstConflict && SecondConflict && FirstConflict != SecondConflict)
8459 D.Diag(clang::diag::err_drv_argument_not_allowed_with)
8460 << FirstConflict->getAsString(Args)
8461 << SecondConflict->getAsString(Args);
8464 CmdArgs.push_back(
"-fms-memptr-rep=single");
8465 else if (MultipleArg)
8466 CmdArgs.push_back(
"-fms-memptr-rep=multiple");
8468 CmdArgs.push_back(
"-fms-memptr-rep=virtual");
8471 if (Args.hasArg(options::OPT_regcall4))
8472 CmdArgs.push_back(
"-regcall4");
8476 Args.getLastArg(options::OPT__SLASH_Gd, options::OPT__SLASH_Gr,
8477 options::OPT__SLASH_Gz, options::OPT__SLASH_Gv,
8478 options::OPT__SLASH_Gregcall)) {
8479 unsigned DCCOptId = CCArg->getOption().
getID();
8480 const char *DCCFlag =
nullptr;
8481 bool ArchSupported = !isNVPTX;
8484 case options::OPT__SLASH_Gd:
8485 DCCFlag =
"-fdefault-calling-conv=cdecl";
8487 case options::OPT__SLASH_Gr:
8488 ArchSupported = Arch == llvm::Triple::x86;
8489 DCCFlag =
"-fdefault-calling-conv=fastcall";
8491 case options::OPT__SLASH_Gz:
8492 ArchSupported = Arch == llvm::Triple::x86;
8493 DCCFlag =
"-fdefault-calling-conv=stdcall";
8495 case options::OPT__SLASH_Gv:
8496 ArchSupported = Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64;
8497 DCCFlag =
"-fdefault-calling-conv=vectorcall";
8499 case options::OPT__SLASH_Gregcall:
8500 ArchSupported = Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64;
8501 DCCFlag =
"-fdefault-calling-conv=regcall";
8506 if (ArchSupported && DCCFlag)
8507 CmdArgs.push_back(DCCFlag);
8510 if (Args.hasArg(options::OPT__SLASH_Gregcall4))
8511 CmdArgs.push_back(
"-regcall4");
8513 Args.AddLastArg(CmdArgs, options::OPT_vtordisp_mode_EQ);
8515 if (!Args.hasArg(options::OPT_fdiagnostics_format_EQ)) {
8516 CmdArgs.push_back(
"-fdiagnostics-format");
8517 CmdArgs.push_back(
"msvc");
8520 if (Args.hasArg(options::OPT__SLASH_kernel))
8521 CmdArgs.push_back(
"-fms-kernel");
8523 for (
const Arg *A : Args.filtered(options::OPT__SLASH_guard)) {
8524 StringRef GuardArgs = A->getValue();
8527 if (GuardArgs.equals_insensitive(
"cf")) {
8529 CmdArgs.push_back(
"-cfguard");
8530 }
else if (GuardArgs.equals_insensitive(
"cf,nochecks")) {
8532 CmdArgs.push_back(
"-cfguard-no-checks");
8533 }
else if (GuardArgs.equals_insensitive(
"ehcont")) {
8535 CmdArgs.push_back(
"-ehcontguard");
8536 }
else if (GuardArgs.equals_insensitive(
"cf-") ||
8537 GuardArgs.equals_insensitive(
"ehcont-")) {
8540 D.Diag(diag::err_drv_invalid_value) << A->getSpelling() << GuardArgs;
8548 return Args.MakeArgString(llvm::sys::path::filename(Input.
getBaseInput()));
8555 if (
const char *End = strrchr(Str,
'.'))
8556 return Args.MakeArgString(std::string(Str, End));
8565 if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) {
8567 llvm::sys::path::replace_extension(OutputFilename, llvm::Twine(
'd'));
8568 return Args.MakeArgString(OutputFilename);
8577 ArgStringList &CmdArgs)
const {
8583 CmdArgs.push_back(
"-target-abi");
8584 CmdArgs.push_back(ABIName.data());
8588 ArgStringList &CmdArgs)
const {
8592 if (Arg *A = Args.getLastArg(options::OPT_masm_EQ)) {
8593 StringRef
Value = A->getValue();
8595 CmdArgs.push_back(
"-mllvm");
8596 CmdArgs.push_back(Args.MakeArgString(
"-x86-asm-syntax=" +
Value));
8599 << A->getSpelling() <<
Value;
8605 ArgStringList &CmdArgs)
const {
8606 CmdArgs.push_back(
"-target-abi");
8613 ArgStringList &CmdArgs)
const {
8617 CmdArgs.push_back(
"-target-abi");
8618 CmdArgs.push_back(ABIName.data());
8620 if (Args.hasFlag(options::OPT_mdefault_build_attributes,
8621 options::OPT_mno_default_build_attributes,
true)) {
8622 CmdArgs.push_back(
"-mllvm");
8623 CmdArgs.push_back(
"-riscv-add-build-attributes");
8629 const ArgList &Args,
8630 const char *LinkingOutput)
const {
8631 ArgStringList CmdArgs;
8633 assert(Inputs.size() == 1 &&
"Unexpected number of inputs.");
8637 const std::string &TripleStr = Triple.getTriple();
8641 Args.ClaimAllArgs(options::OPT_w);
8643 Args.ClaimAllArgs(options::OPT_emit_llvm);
8650 CmdArgs.push_back(
"-cc1as");
8653 CmdArgs.push_back(
"-triple");
8654 CmdArgs.push_back(Args.MakeArgString(TripleStr));
8660 CmdArgs.push_back(
"-filetype");
8661 CmdArgs.push_back(
"obj");
8665 CmdArgs.push_back(
"-main-file-name");
8669 std::string CPU =
getCPUName(
D, Args, Triple,
true);
8671 CmdArgs.push_back(
"-target-cpu");
8672 CmdArgs.push_back(Args.MakeArgString(CPU));
8679 (void)Args.hasArg(options::OPT_force__cpusubtype__ALL);
8682 Args.AddAllArgs(CmdArgs, options::OPT_I_Group);
8685 Args.AddAllArgs(CmdArgs, options::OPT_embed_dir_EQ);
8688 auto FindSource = [](
const Action *S) ->
const Action * {
8690 assert(!S->getInputs().empty() &&
"unexpected root action!");
8691 S = S->getInputs()[0];
8695 const Action *SourceAction = FindSource(&JA);
8699 bool WantDebug =
false;
8700 Args.ClaimAllArgs(options::OPT_g_Group);
8701 if (Arg *A = Args.getLastArg(options::OPT_g_Group))
8702 WantDebug = !A->getOption().matches(options::OPT_g0) &&
8703 !A->getOption().matches(options::OPT_ggdb0);
8706 bool EmitDwarf =
false;
8710 bool EmitCodeView =
false;
8711 if (
const Arg *A = Args.getLastArg(options::OPT_gcodeview))
8716 if (!EmitCodeView && !EmitDwarf && WantDebug) {
8718 case llvm::codegenoptions::DIF_CodeView:
8719 EmitCodeView =
true;
8721 case llvm::codegenoptions::DIF_DWARF:
8731 llvm::codegenoptions::DebugInfoKind DebugInfoKind =
8732 llvm::codegenoptions::NoDebugInfo;
8735 const char *DebugCompilationDir =
8738 if (SourceAction->
getType() == types::TY_Asm ||
8739 SourceAction->
getType() == types::TY_PP_Asm) {
8744 DebugInfoKind = (WantDebug ? llvm::codegenoptions::DebugInfoConstructor
8745 : llvm::codegenoptions::NoDebugInfo);
8752 CmdArgs.push_back(
"-dwarf-debug-producer");
8756 Args.AddAllArgs(CmdArgs, options::OPT_I);
8760 llvm::DebuggerKind::Default);
8766 llvm::Reloc::Model RelocationModel;
8769 std::tie(RelocationModel, PICLevel, IsPIE) =
8774 CmdArgs.push_back(
"-mrelocation-model");
8775 CmdArgs.push_back(RMName);
8781 ArgStringList OriginalArgs;
8782 for (
const auto &Arg : Args)
8783 Arg->render(Args, OriginalArgs);
8788 for (
const char *OriginalArg : OriginalArgs) {
8792 Flags += EscapedArg;
8794 CmdArgs.push_back(
"-dwarf-debug-flags");
8795 CmdArgs.push_back(Args.MakeArgString(Flags));
8805 case llvm::Triple::mips:
8806 case llvm::Triple::mipsel:
8807 case llvm::Triple::mips64:
8808 case llvm::Triple::mips64el:
8812 case llvm::Triple::x86:
8813 case llvm::Triple::x86_64:
8817 case llvm::Triple::arm:
8818 case llvm::Triple::armeb:
8819 case llvm::Triple::thumb:
8820 case llvm::Triple::thumbeb:
8823 if (Args.hasFlag(options::OPT_mdefault_build_attributes,
8824 options::OPT_mno_default_build_attributes,
true)) {
8825 CmdArgs.push_back(
"-mllvm");
8826 CmdArgs.push_back(
"-arm-add-build-attributes");
8830 case llvm::Triple::aarch64:
8831 case llvm::Triple::aarch64_32:
8832 case llvm::Triple::aarch64_be:
8833 if (Args.hasArg(options::OPT_mmark_bti_property)) {
8834 CmdArgs.push_back(
"-mllvm");
8835 CmdArgs.push_back(
"-aarch64-mark-bti-property");
8839 case llvm::Triple::loongarch32:
8840 case llvm::Triple::loongarch64:
8844 case llvm::Triple::riscv32:
8845 case llvm::Triple::riscv64:
8849 case llvm::Triple::hexagon:
8850 if (Args.hasFlag(options::OPT_mdefault_build_attributes,
8851 options::OPT_mno_default_build_attributes,
true)) {
8852 CmdArgs.push_back(
"-mllvm");
8853 CmdArgs.push_back(
"-hexagon-add-build-attributes");
8863 Args.ClaimAllArgs(options::OPT_W_Group);
8868 Args.AddAllArgs(CmdArgs, options::OPT_mllvm);
8870 if (DebugInfoKind > llvm::codegenoptions::NoDebugInfo && Output.
isFilename())
8877 if (SourceAction != FindSource(&J.getSource()))
8879 auto &JArgs = J.getArguments();
8880 for (
unsigned I = 0; I < JArgs.size(); ++I) {
8881 if (StringRef(JArgs[I]).starts_with(
"-object-file-name=") &&
8883 ArgStringList NewArgs(JArgs.begin(), JArgs.begin() + I);
8886 NewArgs.append(JArgs.begin() + I + 1, JArgs.end());
8887 J.replaceArguments(NewArgs);
8893 assert(Output.
isFilename() &&
"Unexpected lipo output.");
8894 CmdArgs.push_back(
"-o");
8900 T.isOSBinFormatELF()) {
8901 CmdArgs.push_back(
"-split-dwarf-output");
8905 if (Triple.isAMDGPU())
8908 assert(Input.
isFilename() &&
"Invalid input.");
8912 if (
D.CC1Main && !
D.CCGenDiagnostics) {
8914 C.addCommand(std::make_unique<CC1Command>(
8916 Output,
D.getPrependArg()));
8918 C.addCommand(std::make_unique<Command>(
8920 Output,
D.getPrependArg()));
8928 const llvm::opt::ArgList &TCArgs,
8929 const char *LinkingOutput)
const {
8931 assert(isa<OffloadBundlingJobAction>(JA) &&
"Expecting bundling job!");
8941 ArgStringList CmdArgs;
8944 CmdArgs.push_back(TCArgs.MakeArgString(
8947 assert(JA.
getInputs().size() == Inputs.size() &&
8948 "Not have inputs for all dependence actions??");
8952 Triples +=
"-targets=";
8953 for (
unsigned I = 0; I < Inputs.size(); ++I) {
8962 if (
const auto *OA = dyn_cast<OffloadAction>(CurDep)) {
8964 OA->doOnEachDependence([&](
Action *A,
const ToolChain *TC,
const char *) {
8965 assert(CurTC ==
nullptr &&
"Expected one dependence!");
8972 Triples += CurTC->
getTriple().normalize();
8981 StringRef GPUArchName;
8984 for (
unsigned ArgIndex = 0; ArgIndex < TCArgs.size(); ArgIndex++) {
8985 auto ArchStr = StringRef(TCArgs.getArgString(ArgIndex));
8986 auto Arch = ArchStr.starts_with_insensitive(
"-march=");
8988 GPUArchName = ArchStr.substr(7);
8993 Triples += GPUArchName.str();
8996 CmdArgs.push_back(TCArgs.MakeArgString(Triples));
9000 TCArgs.MakeArgString(Twine(
"-output=") + Output.
getFilename()));
9003 for (
unsigned I = 0; I < Inputs.size(); ++I) {
9009 if (
const auto *OA = dyn_cast<OffloadAction>(JA.
getInputs()[I])) {
9011 OA->doOnEachDependence([&](
Action *,
const ToolChain *TC,
const char *) {
9012 assert(CurTC ==
nullptr &&
"Expected one dependence!");
9015 UB +=
C.addTempFile(
9020 CmdArgs.push_back(TCArgs.MakeArgString(UB));
9024 C.addCommand(std::make_unique<Command>(
9027 CmdArgs, std::nullopt, Output));
9032 const InputInfoList &Inputs,
const llvm::opt::ArgList &TCArgs,
9033 const char *LinkingOutput)
const {
9035 auto &UA = cast<OffloadUnbundlingJobAction>(JA);
9046 ArgStringList CmdArgs;
9048 assert(Inputs.size() == 1 &&
"Expecting to unbundle a single file!");
9052 CmdArgs.push_back(TCArgs.MakeArgString(
9057 Triples +=
"-targets=";
9058 auto DepInfo = UA.getDependentActionsInfo();
9059 for (
unsigned I = 0; I < DepInfo.size(); ++I) {
9063 auto &Dep = DepInfo[I];
9066 Triples += Dep.DependentToolChain->getTriple().normalize();
9069 !Dep.DependentBoundArch.empty()) {
9071 Triples += Dep.DependentBoundArch;
9075 StringRef GPUArchName;
9078 for (
unsigned ArgIndex = 0; ArgIndex < TCArgs.size(); ArgIndex++) {
9079 StringRef ArchStr = StringRef(TCArgs.getArgString(ArgIndex));
9080 auto Arch = ArchStr.starts_with_insensitive(
"-march=");
9082 GPUArchName = ArchStr.substr(7);
9087 Triples += GPUArchName.str();
9091 CmdArgs.push_back(TCArgs.MakeArgString(Triples));
9095 TCArgs.MakeArgString(Twine(
"-input=") + Input.
getFilename()));
9098 for (
unsigned I = 0; I < Outputs.size(); ++I) {
9101 UB += DepInfo[I].DependentToolChain->getInputFilename(Outputs[I]);
9102 CmdArgs.push_back(TCArgs.MakeArgString(UB));
9104 CmdArgs.push_back(
"-unbundle");
9105 CmdArgs.push_back(
"-allow-missing-bundles");
9106 if (TCArgs.hasArg(options::OPT_v))
9107 CmdArgs.push_back(
"-verbose");
9110 C.addCommand(std::make_unique<Command>(
9113 CmdArgs, std::nullopt, Outputs));
9119 const llvm::opt::ArgList &Args,
9120 const char *LinkingOutput)
const {
9121 ArgStringList CmdArgs;
9124 assert(Output.
isFilename() &&
"Invalid output.");
9125 CmdArgs.push_back(
"-o");
9132 const ArgList &TCArgs =
9138 : TCArgs.getLastArgValue(options::OPT_march_EQ);
9142 ArgStringList Features;
9146 llvm::copy_if(Features, std::back_inserter(FeatureArgs),
9147 [](StringRef Arg) {
return !Arg.starts_with(
"-target"); });
9152 "file=" +
File.str(),
9154 "arch=" + Arch.str(),
9155 "kind=" + Kind.str(),
9159 for (StringRef Feature : FeatureArgs)
9160 Parts.emplace_back(
"feature=" + Feature.str());
9162 CmdArgs.push_back(Args.MakeArgString(
"--image=" + llvm::join(Parts,
",")));
9165 C.addCommand(std::make_unique<Command>(
9168 CmdArgs, Inputs, Output));
9174 const ArgList &Args,
9175 const char *LinkingOutput)
const {
9178 ArgStringList CmdArgs;
9182 auto TCRange =
C.getOffloadToolChains(Kind);
9183 for (
auto &I : llvm::make_range(TCRange)) {
9187 if (CudaInstallation.
isValid())
9188 CmdArgs.push_back(Args.MakeArgString(
9196 if (
const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
9198 if (A->getOption().matches(options::OPT_O4) ||
9199 A->getOption().matches(options::OPT_Ofast))
9201 else if (A->getOption().matches(options::OPT_O)) {
9202 OOpt = A->getValue();
9205 else if (OOpt ==
"s" || OOpt ==
"z")
9207 }
else if (A->getOption().matches(options::OPT_O0))
9210 CmdArgs.push_back(Args.MakeArgString(Twine(
"--opt-level=O") + OOpt));
9214 Args.MakeArgString(
"--host-triple=" + TheTriple.getTriple()));
9215 if (Args.hasArg(options::OPT_v))
9216 CmdArgs.push_back(
"--wrapper-verbose");
9218 if (
const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
9219 if (!A->getOption().matches(options::OPT_g0))
9220 CmdArgs.push_back(
"--device-debug");
9225 if (
const Arg *A = Args.getLastArg(options::OPT_mcode_object_version_EQ)) {
9226 CmdArgs.push_back(Args.MakeArgString(
"-mllvm"));
9227 CmdArgs.push_back(Args.MakeArgString(
9228 Twine(
"--amdhsa-code-object-version=") + A->getValue()));
9231 for (
const auto &A : Args.getAllArgValues(options::OPT_Xcuda_ptxas))
9232 CmdArgs.push_back(Args.MakeArgString(
"--ptxas-arg=" + A));
9235 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_EQ))
9236 CmdArgs.push_back(Args.MakeArgString(Twine(
"--offload-opt=-pass-remarks=") +
9238 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_missed_EQ))
9239 CmdArgs.push_back(Args.MakeArgString(
9240 Twine(
"--offload-opt=-pass-remarks-missed=") + A->getValue()));
9241 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_analysis_EQ))
9242 CmdArgs.push_back(Args.MakeArgString(
9243 Twine(
"--offload-opt=-pass-remarks-analysis=") + A->getValue()));
9244 if (Args.getLastArg(options::OPT_save_temps_EQ))
9245 CmdArgs.push_back(
"--save-temps");
9248 Linker->
ConstructJob(
C, JA, Output, Inputs, Args, LinkingOutput);
9249 const auto &LinkCommand =
C.getJobs().getJobs().back();
9252 for (Arg *A : Args.filtered(options::OPT_Xoffload_linker)) {
9253 StringRef Val = A->getValue(0);
9256 Args.MakeArgString(Twine(
"--device-linker=") + A->getValue(1)));
9258 CmdArgs.push_back(Args.MakeArgString(
9259 "--device-linker=" +
9263 Args.ClaimAllArgs(options::OPT_Xoffload_linker);
9266 if (Args.hasFlag(options::OPT_fopenmp_target_jit,
9267 options::OPT_fno_openmp_target_jit,
false))
9268 CmdArgs.push_back(
"--embed-bitcode");
9271 for (Arg *A : Args.filtered(options::OPT_mllvm)) {
9272 CmdArgs.push_back(
"-mllvm");
9273 CmdArgs.push_back(A->getValue());
9278 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_r, options::OPT_nogpulib,
9279 options::OPT_nodefaultlibs, options::OPT_nolibc,
9280 options::OPT_nogpulibc)) {
9288 CmdArgs.push_back(Args.MakeArgString(
9290 CmdArgs.push_back(Args.MakeArgString(
9298 "-lclang_rt.builtins"));
9304 if (!Args.hasFlag(options::OPT_gpulibc, options::OPT_nogpulibc,
true))
9305 CmdArgs.push_back(
"--device-compiler=-nolibc");
9308 CmdArgs.push_back(Args.MakeArgString(Twine(
"--linker-path=") +
9309 LinkCommand->getExecutable()));
9310 for (
const char *LinkArg : LinkCommand->getArguments())
9311 CmdArgs.push_back(LinkArg);
9316 Args.MakeArgString(
getToolChain().GetProgramPath(
"clang-linker-wrapper"));
9320 LinkCommand->replaceExecutable(Exec);
9321 LinkCommand->replaceArguments(CmdArgs);
static StringRef bytes(const std::vector< T, Allocator > &v)
static std::string ComplexRangeKindToStr(LangOptions::ComplexRangeKind Range)
static void ParseMPreferVectorWidth(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs)
The -mprefer-vector-width option accepts either a positive integer or the string "none".
static void RenderDebugInfoCompressionArgs(const ArgList &Args, ArgStringList &CmdArgs, const Driver &D, const ToolChain &TC)
static bool checkDebugInfoOption(const Arg *A, const ArgList &Args, const Driver &D, const ToolChain &TC)
static void RenderOpenCLOptions(const ArgList &Args, ArgStringList &CmdArgs, types::ID InputType)
static bool shouldUseExceptionTablesForObjCExceptions(const ObjCRuntime &runtime, const llvm::Triple &Triple)
static void RenderCharacterOptions(const ArgList &Args, const llvm::Triple &T, ArgStringList &CmdArgs)
static std::string RenderComplexRangeOption(LangOptions::ComplexRangeKind Range)
static void RenderDebugEnablingArgs(const ArgList &Args, ArgStringList &CmdArgs, llvm::codegenoptions::DebugInfoKind DebugInfoKind, unsigned DwarfVersion, llvm::DebuggerKind DebuggerTuning)
static void ProcessVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs)
static void renderDebugOptions(const ToolChain &TC, const Driver &D, const llvm::Triple &T, const ArgList &Args, bool IRInput, ArgStringList &CmdArgs, const InputInfo &Output, llvm::codegenoptions::DebugInfoKind &DebugInfoKind, DwarfFissionKind &DwarfFission)
static bool shouldEnableVectorizerAtOLevel(const ArgList &Args, bool isSlpVec)
Vectorize at all optimization levels greater than 1 except for -Oz.
static void RenderDiagnosticsOptions(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs)
static bool maybeHasClangPchSignature(const Driver &D, StringRef Path)
static bool addExceptionArgs(const ArgList &Args, types::ID InputType, const ToolChain &TC, bool KernelOrKext, const ObjCRuntime &objcRuntime, ArgStringList &CmdArgs)
Adds exception related arguments to the driver command arguments.
static void CheckPreprocessingOptions(const Driver &D, const ArgList &Args)
void AddAAPCSVolatileBitfieldArgs(const ArgList &Args, ArgStringList &CmdArgs)
static bool isSignedCharDefault(const llvm::Triple &Triple)
static EHFlags parseClangCLEHFlags(const Driver &D, const ArgList &Args, bool isWindowsMSVC)
/EH controls whether to run destructor cleanups when exceptions are thrown.
static bool gchProbe(const Driver &D, StringRef Path)
static void RenderOpenACCOptions(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs, types::ID InputType)
static void EmitComplexRangeDiag(const Driver &D, std::string str1, std::string str2)
static bool CheckARMImplicitITArg(StringRef Value)
static bool hasMultipleInvocations(const llvm::Triple &Triple, const ArgList &Args)
static void handleAMDGPUCodeObjectVersionOptions(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs, bool IsCC1As=false)
static void RenderARCMigrateToolOptions(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs)
static void addDashXForInput(const ArgList &Args, const InputInfo &Input, ArgStringList &CmdArgs)
Add -x lang to CmdArgs for Input.
static void ParseMRecip(const Driver &D, const ArgList &Args, ArgStringList &OutStrings)
The -mrecip flag requires processing of many optional parameters.
static void RenderHLSLOptions(const ArgList &Args, ArgStringList &CmdArgs, types::ID InputType)
static void renderDwarfFormat(const Driver &D, const llvm::Triple &T, const ArgList &Args, ArgStringList &CmdArgs, unsigned DwarfVersion)
static void RenderObjCOptions(const ToolChain &TC, const Driver &D, const llvm::Triple &T, const ArgList &Args, ObjCRuntime &Runtime, bool InferCovariantReturns, const InputInfo &Input, ArgStringList &CmdArgs)
static void addCoveragePrefixMapArg(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs)
Add a CC1 and CC1AS option to specify the coverage file path prefix map.
static void AddARMImplicitITArgs(const ArgList &Args, ArgStringList &CmdArgs, StringRef Value)
static bool checkRemarksOptions(const Driver &D, const ArgList &Args, const llvm::Triple &Triple)
static void CollectArgsForIntegratedAssembler(Compilation &C, const ArgList &Args, ArgStringList &CmdArgs, const Driver &D)
static bool RenderModulesOptions(Compilation &C, const Driver &D, const ArgList &Args, const InputInfo &Input, const InputInfo &Output, bool HaveStd20, ArgStringList &CmdArgs)
static void forAllAssociatedToolChains(Compilation &C, const JobAction &JA, const ToolChain &RegularToolChain, llvm::function_ref< void(const ToolChain &)> Work)
Apply Work on the current tool chain RegularToolChain and any other offloading tool chain that is ass...
static bool isValidSymbolName(StringRef S)
static void addMacroPrefixMapArg(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs)
Add a CC1 and CC1AS option to specify the macro file path prefix map.
static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple, const InputInfo &Input, const InputInfo &Output, const JobAction &JA)
static std::string ComplexArithmeticStr(LangOptions::ComplexRangeKind Range)
static void addDebugObjectName(const ArgList &Args, ArgStringList &CmdArgs, const char *DebugCompilationDir, const char *OutputFileName)
static bool getRefinementStep(StringRef In, const Driver &D, const Arg &A, size_t &Position)
This is a helper function for validating the optional refinement step parameter in reciprocal argumen...
static void CollectARMPACBTIOptions(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, bool isAArch64)
static void RenderSSPOptions(const Driver &D, const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, bool KernelOrKext)
static void RenderBuiltinOptions(const ToolChain &TC, const llvm::Triple &T, const ArgList &Args, ArgStringList &CmdArgs)
static void RenderSCPOptions(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs)
static void RenderTrivialAutoVarInitOptions(const Driver &D, const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs)
static bool maybeConsumeDash(const std::string &EH, size_t &I)
static const char * addDebugCompDirArg(const ArgList &Args, ArgStringList &CmdArgs, const llvm::vfs::FileSystem &VFS)
Add a CC1 option to specify the debug compilation directory.
static void CheckCodeGenerationOptions(const Driver &D, const ArgList &Args)
static bool ShouldEnableAutolink(const ArgList &Args, const ToolChain &TC, const JobAction &JA)
static void addDebugPrefixMapArg(const Driver &D, const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs)
Add a CC1 and CC1AS option to specify the debug file path prefix map.
static void RenderAnalyzerOptions(const ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple, const InputInfo &Input)
static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D, bool OFastEnabled, const ArgList &Args, ArgStringList &CmdArgs, const JobAction &JA)
static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C, const JobAction &JA, const InputInfo &Output, const ArgList &Args, SanitizerArgs &SanArgs, ArgStringList &CmdArgs)
static void handlePAuthABI(const ArgList &DriverArgs, ArgStringList &CC1Args)
clang::CodeGenOptions::FramePointerKind getFramePointerKind(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
Defines the clang::LangOptions interface.
llvm::MachO::Target Target
Defines types useful for describing an Objective-C runtime.
Defines version macros and version-related utility functions for Clang.
static StringRef getWarningOptionForGroup(diag::Group)
Given a group ID, returns the flag that toggles the group.
ComplexRangeKind
Controls the various implementations for complex multiplication and.
@ CX_Full
Implementation of complex division and multiplication using a call to runtime library functions(gener...
@ CX_Basic
Implementation of complex division and multiplication using algebraic formulas at source precision.
@ CX_Promoted
Implementation of complex division using algebraic formulas at higher precision.
@ CX_None
No range rule is enabled.
@ CX_Improved
Implementation of complex division offering an improved handling for overflow in intermediate calcula...
The basic abstraction for the target Objective-C runtime.
bool allowsWeak() const
Does this runtime allow the use of __weak?
bool isLegacyDispatchDefaultForArch(llvm::Triple::ArchType Arch)
The default dispatch mechanism to use for the specified architecture.
bool isNeXTFamily() const
Is this runtime basically of the NeXT family of runtimes?
const VersionTuple & getVersion() const
bool tryParse(StringRef input)
Try to parse an Objective-C runtime specification from the given string.
bool isNonFragile() const
Does this runtime follow the set of implied behaviors for a "non-fragile" ABI?
std::string getAsString() const
@ MacOSX
'macosx' is the Apple-provided NeXT-derived runtime on Mac OS X platforms that use the non-fragile AB...
@ FragileMacOSX
'macosx-fragile' is the Apple-provided NeXT-derived runtime on Mac OS X platforms that use the fragil...
@ GNUstep
'gnustep' is the modern non-fragile GNUstep runtime.
@ GCC
'gcc' is the Objective-C runtime shipped with GCC, implementing a fragile Objective-C ABI
Scope - A scope is a transient data structure that is used while parsing the program.
Scope(Scope *Parent, unsigned ScopeFlags, DiagnosticsEngine &Diag)
Action - Represent an abstract compilation step to perform.
const char * getOffloadingArch() const
types::ID getType() const
const ToolChain * getOffloadingToolChain() const
static std::string GetOffloadingFileNamePrefix(OffloadKind Kind, StringRef NormalizedTriple, bool CreatePrefixForHost=false)
Return a string that can be used as prefix in order to generate unique files for each offloading kind...
ActionClass getKind() const
static StringRef GetOffloadKindName(OffloadKind Kind)
Return a string containing a offload kind name.
OffloadKind getOffloadingDeviceKind() const
bool isHostOffloading(unsigned int OKind) const
Check if this action have any offload kinds.
bool isDeviceOffloading(OffloadKind OKind) const
bool isOffloading(OffloadKind OKind) const
Command - An executable path/name and argument vector to execute.
Compilation - A set of tasks to perform for a single driver invocation.
A class to find a viable CUDA installation.
StringRef getInstallPath() const
Get the detected Cuda installation path.
bool isValid() const
Check whether we detected a valid Cuda install.
Distro - Helper class for detecting and classifying Linux distributions.
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
static bool getDefaultModuleCachePath(SmallVectorImpl< char > &Result)
Compute the default -fmodule-cache-path.
const char * getClangProgramPath() const
Get the path to the main clang executable.
DiagnosticBuilder Diag(unsigned DiagID) const
bool isUsingOffloadLTO() const
Returns true if we are performing any kind of offload LTO.
llvm::vfs::FileSystem & getVFS() const
@ OMPRT_IOMP5
The legacy name for the LLVM OpenMP runtime from when it was the Intel OpenMP runtime.
@ OMPRT_OMP
The LLVM OpenMP runtime.
An offload action combines host or/and device actions according to the programming model implementati...
void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const
bool isHLSL(ID Id)
isHLSL - Is this an HLSL input.
bool isObjC(ID Id)
isObjC - Is this an "ObjC" input (Obj-C and Obj-C++ sources and headers).
ID getPreprocessedType(ID Id)
getPreprocessedType - Get the ID of the type for this input when it has been preprocessed,...
bool isLLVMIR(ID Id)
Is this LLVM IR.
const char * getTypeName(ID Id)
getTypeName - Return the name of the type for Id.
bool isOpenCL(ID Id)
isOpenCL - Is this an "OpenCL" input.
bool isSrcFile(ID Id)
isSrcFile - Is this a source file, i.e.
const char * getTypeTempSuffix(ID Id, bool CLStyle=false)
getTypeTempSuffix - Return the suffix to use when creating a temp file of this type,...
bool isCXX(ID Id)
isCXX - Is this a "C++" input (C++ and Obj-C++ sources and headers).
bool isOptimizationLevelFast(const llvm::opt::ArgList &Args)
bool willEmitRemarks(const llvm::opt::ArgList &Args)
@ Quoted
'#include ""' paths, added by 'gcc -iquote'.
The JSON file list parser is used to communicate input to InstallAPI.
std::optional< diag::Group > diagGroupFromCLWarningID(unsigned)
For cl.exe warning IDs that cleany map to clang diagnostic groups, returns the corresponding group.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
void quoteMakeTarget(StringRef Target, SmallVectorImpl< char > &Res)
Quote target names for inclusion in GNU Make dependency files.
const char * headerIncludeFormatKindToString(HeaderIncludeFormatKind K)
const char * headerIncludeFilteringKindToString(HeaderIncludeFilteringKind K)
@ Asm
Assembly: we accept this only so that we can preprocess it.
@ Result
The result type of a method or function.
const char * CudaVersionToString(CudaVersion V)
const FunctionProtoType * T
std::string getClangFullVersion()
Retrieves a string representing the complete clang version, which includes the clang version number,...
static constexpr ResponseFileSupport None()
Returns a ResponseFileSupport indicating that response files are not supported.
static constexpr ResponseFileSupport AtFileUTF8()