36#include "clang/Config/config.h"
45#include "llvm/ADT/ScopeExit.h"
46#include "llvm/ADT/SmallSet.h"
47#include "llvm/ADT/StringExtras.h"
48#include "llvm/BinaryFormat/Magic.h"
49#include "llvm/Config/llvm-config.h"
50#include "llvm/Frontend/Debug/Options.h"
51#include "llvm/Object/ObjectFile.h"
52#include "llvm/Option/ArgList.h"
53#include "llvm/Support/CodeGen.h"
54#include "llvm/Support/Compiler.h"
55#include "llvm/Support/Compression.h"
56#include "llvm/Support/Error.h"
57#include "llvm/Support/FileSystem.h"
58#include "llvm/Support/Path.h"
59#include "llvm/Support/Process.h"
60#include "llvm/Support/YAMLParser.h"
61#include "llvm/TargetParser/AArch64TargetParser.h"
62#include "llvm/TargetParser/ARMTargetParserCommon.h"
63#include "llvm/TargetParser/Host.h"
64#include "llvm/TargetParser/LoongArchTargetParser.h"
65#include "llvm/TargetParser/PPCTargetParser.h"
66#include "llvm/TargetParser/RISCVISAInfo.h"
67#include "llvm/TargetParser/RISCVTargetParser.h"
76 if (Arg *A = Args.getLastArg(clang::driver::options::OPT_C, options::OPT_CC,
77 options::OPT_fminimize_whitespace,
78 options::OPT_fno_minimize_whitespace,
79 options::OPT_fkeep_system_includes,
80 options::OPT_fno_keep_system_includes)) {
81 if (!Args.hasArg(options::OPT_E) && !Args.hasArg(options::OPT__SLASH_P) &&
82 !Args.hasArg(options::OPT__SLASH_EP) && !
D.CCCIsCPP()) {
83 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
84 << A->getBaseArg().getAsString(Args)
85 << (
D.IsCLMode() ?
"/E, /P or /EP" :
"-E");
92 if (Args.hasArg(options::OPT_static))
94 Args.getLastArg(options::OPT_dynamic, options::OPT_mdynamic_no_pic))
95 D.Diag(diag::err_drv_argument_not_allowed_with) << A->getAsString(Args)
104 llvm::function_ref<
void(
const ToolChain &)> Work) {
106 Work(RegularToolChain);
121 for (
auto II = TCs.first, IE = TCs.second; II != IE; ++II)
128 for (
auto II = TCs.first, IE = TCs.second; II != IE; ++II)
143 const Arg &A,
size_t &Position) {
144 const char RefinementStepToken =
':';
145 Position = In.find(RefinementStepToken);
146 if (Position != StringRef::npos) {
147 StringRef Option = A.getOption().getName();
148 StringRef RefStep = In.substr(Position + 1);
156 if (RefStep.size() != 1) {
157 D.Diag(diag::err_drv_invalid_value) << Option << RefStep;
160 char RefStepChar = RefStep[0];
161 if (RefStepChar <
'0' || RefStepChar >
'9') {
162 D.Diag(diag::err_drv_invalid_value) << Option << RefStep;
171 ArgStringList &OutStrings) {
172 StringRef DisabledPrefixIn =
"!";
173 StringRef DisabledPrefixOut =
"!";
174 StringRef EnabledPrefixOut =
"";
175 StringRef Out =
"-mrecip=";
177 Arg *A = Args.getLastArg(options::OPT_mrecip, options::OPT_mrecip_EQ);
181 unsigned NumOptions = A->getNumValues();
182 if (NumOptions == 0) {
184 OutStrings.push_back(Args.MakeArgString(Out +
"all"));
189 if (NumOptions == 1) {
190 StringRef Val = A->getValue(0);
194 StringRef ValBase = Val.slice(0, RefStepLoc);
195 if (ValBase ==
"all" || ValBase ==
"none" || ValBase ==
"default") {
196 OutStrings.push_back(Args.MakeArgString(Out + Val));
205 llvm::StringMap<bool> OptionStrings;
206 OptionStrings.insert(std::make_pair(
"divd",
false));
207 OptionStrings.insert(std::make_pair(
"divf",
false));
208 OptionStrings.insert(std::make_pair(
"divh",
false));
209 OptionStrings.insert(std::make_pair(
"vec-divd",
false));
210 OptionStrings.insert(std::make_pair(
"vec-divf",
false));
211 OptionStrings.insert(std::make_pair(
"vec-divh",
false));
212 OptionStrings.insert(std::make_pair(
"sqrtd",
false));
213 OptionStrings.insert(std::make_pair(
"sqrtf",
false));
214 OptionStrings.insert(std::make_pair(
"sqrth",
false));
215 OptionStrings.insert(std::make_pair(
"vec-sqrtd",
false));
216 OptionStrings.insert(std::make_pair(
"vec-sqrtf",
false));
217 OptionStrings.insert(std::make_pair(
"vec-sqrth",
false));
219 for (
unsigned i = 0; i != NumOptions; ++i) {
220 StringRef Val = A->getValue(i);
222 bool IsDisabled = Val.starts_with(DisabledPrefixIn);
231 StringRef ValBase = Val.slice(0, RefStep);
232 llvm::StringMap<bool>::iterator OptionIter = OptionStrings.find(ValBase);
233 if (OptionIter == OptionStrings.end()) {
235 OptionIter = OptionStrings.find(ValBase.str() +
'f');
236 if (OptionIter == OptionStrings.end()) {
238 D.Diag(diag::err_drv_unknown_argument) << Val;
244 if (OptionStrings[ValBase.str() +
'd'] ||
245 OptionStrings[ValBase.str() +
'h']) {
246 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Val;
251 if (OptionIter->second ==
true) {
253 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() << Val;
258 OptionIter->second =
true;
262 if (ValBase.back() !=
'f' && ValBase.back() !=
'd' && ValBase.back() !=
'h') {
263 OptionStrings[ValBase.str() +
'd'] =
true;
264 OptionStrings[ValBase.str() +
'h'] =
true;
268 StringRef Prefix = IsDisabled ? DisabledPrefixOut : EnabledPrefixOut;
269 Out = Args.MakeArgString(Out + Prefix + Val);
270 if (i != NumOptions - 1)
271 Out = Args.MakeArgString(Out +
",");
274 OutStrings.push_back(Args.MakeArgString(Out));
280 ArgStringList &CmdArgs) {
281 Arg *A = Args.getLastArg(options::OPT_mprefer_vector_width_EQ);
285 StringRef
Value = A->getValue();
286 if (
Value ==
"none") {
287 CmdArgs.push_back(
"-mprefer-vector-width=none");
290 if (
Value.getAsInteger(10, Width)) {
291 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() <<
Value;
294 CmdArgs.push_back(Args.MakeArgString(
"-mprefer-vector-width=" +
Value));
300 const llvm::Triple &Triple) {
307 if (!Triple.isMacOSX())
310 return (!Triple.isMacOSXVersionLT(10, 5) &&
311 (Triple.getArch() == llvm::Triple::x86_64 ||
312 Triple.getArch() == llvm::Triple::arm));
322 ArgStringList &CmdArgs) {
323 const llvm::Triple &Triple = TC.
getTriple();
328 Args.ClaimAllArgs(options::OPT_fexceptions);
329 Args.ClaimAllArgs(options::OPT_fno_exceptions);
330 Args.ClaimAllArgs(options::OPT_fobjc_exceptions);
331 Args.ClaimAllArgs(options::OPT_fno_objc_exceptions);
332 Args.ClaimAllArgs(options::OPT_fcxx_exceptions);
333 Args.ClaimAllArgs(options::OPT_fno_cxx_exceptions);
334 Args.ClaimAllArgs(options::OPT_fasync_exceptions);
335 Args.ClaimAllArgs(options::OPT_fno_async_exceptions);
340 bool EH = Args.hasFlag(options::OPT_fexceptions, options::OPT_fno_exceptions,
344 if (Triple.isWindowsMSVCEnvironment()) {
345 bool EHa = Args.hasFlag(options::OPT_fasync_exceptions,
346 options::OPT_fno_async_exceptions,
false);
348 CmdArgs.push_back(
"-fasync-exceptions");
356 Args.hasFlag(options::OPT_fobjc_exceptions,
357 options::OPT_fno_objc_exceptions,
true)) {
358 CmdArgs.push_back(
"-fobjc-exceptions");
365 bool CXXExceptionsEnabled = Triple.getArch() != llvm::Triple::xcore &&
366 !Triple.isPS() && !Triple.isDriverKit();
367 Arg *ExceptionArg = Args.getLastArg(
368 options::OPT_fcxx_exceptions, options::OPT_fno_cxx_exceptions,
369 options::OPT_fexceptions, options::OPT_fno_exceptions);
371 CXXExceptionsEnabled =
372 ExceptionArg->getOption().matches(options::OPT_fcxx_exceptions) ||
373 ExceptionArg->getOption().matches(options::OPT_fexceptions);
375 if (CXXExceptionsEnabled) {
376 CmdArgs.push_back(
"-fcxx-exceptions");
385 Args.AddLastArg(CmdArgs, options::OPT_fignore_exceptions);
387 Args.addOptInFlag(CmdArgs, options::OPT_fassume_nothrow_exception_dtor,
388 options::OPT_fno_assume_nothrow_exception_dtor);
391 CmdArgs.push_back(
"-fexceptions");
407 return Args.hasFlag(options::OPT_fautolink, options::OPT_fno_autolink,
413 ArgStringList &CmdArgs,
414 const llvm::vfs::FileSystem &VFS) {
415 if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ,
416 options::OPT_fdebug_compilation_dir_EQ)) {
417 if (A->getOption().matches(options::OPT_ffile_compilation_dir_EQ))
418 CmdArgs.push_back(Args.MakeArgString(Twine(
"-fdebug-compilation-dir=") +
421 A->render(Args, CmdArgs);
422 }
else if (llvm::ErrorOr<std::string> CWD =
423 VFS.getCurrentWorkingDirectory()) {
424 CmdArgs.push_back(Args.MakeArgString(
"-fdebug-compilation-dir=" + *CWD));
426 StringRef
Path(CmdArgs.back());
427 return Path.substr(
Path.find(
'=') + 1).data();
431 const char *DebugCompilationDir,
432 const char *OutputFileName) {
434 for (
auto *Arg : Args.filtered(options::OPT_Xclang))
435 if (StringRef(Arg->getValue()).starts_with(
"-object-file-name"))
438 if (Args.hasArg(options::OPT_object_file_name_EQ))
442 if (ObjFileNameForDebug !=
"-" &&
443 !llvm::sys::path::is_absolute(ObjFileNameForDebug) &&
444 (!DebugCompilationDir ||
445 llvm::sys::path::is_absolute(DebugCompilationDir))) {
447 llvm::sys::fs::make_absolute(ObjFileNameForDebug);
453 llvm::sys::path::Style Style =
454 llvm::sys::path::is_absolute(ObjFileNameForDebug)
455 ? llvm::sys::path::Style::native
456 : llvm::sys::path::Style::windows_backslash;
457 llvm::sys::path::remove_dots(ObjFileNameForDebug,
true,
460 Args.MakeArgString(Twine(
"-object-file-name=") + ObjFileNameForDebug));
465 const ArgList &Args, ArgStringList &CmdArgs) {
466 auto AddOneArg = [&](StringRef Map, StringRef Name) {
467 if (!Map.contains(
'='))
468 D.Diag(diag::err_drv_invalid_argument_to_option) << Map << Name;
470 CmdArgs.push_back(Args.MakeArgString(
"-fdebug-prefix-map=" + Map));
473 for (
const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
474 options::OPT_fdebug_prefix_map_EQ)) {
475 AddOneArg(A->getValue(), A->getOption().getName());
479 if (GlobalRemapEntry.empty())
481 AddOneArg(GlobalRemapEntry,
"environment");
486 ArgStringList &CmdArgs) {
487 for (
const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
488 options::OPT_fmacro_prefix_map_EQ)) {
489 StringRef Map = A->getValue();
490 if (!Map.contains(
'='))
491 D.Diag(diag::err_drv_invalid_argument_to_option)
492 << Map << A->getOption().getName();
494 CmdArgs.push_back(Args.MakeArgString(
"-fmacro-prefix-map=" + Map));
501 ArgStringList &CmdArgs) {
502 for (
const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
503 options::OPT_fcoverage_prefix_map_EQ)) {
504 StringRef Map = A->getValue();
505 if (!Map.contains(
'='))
506 D.Diag(diag::err_drv_invalid_argument_to_option)
507 << Map << A->getOption().getName();
509 CmdArgs.push_back(Args.MakeArgString(
"-fcoverage-prefix-map=" + Map));
518 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
519 if (A->getOption().matches(options::OPT_O4) ||
520 A->getOption().matches(options::OPT_Ofast))
523 if (A->getOption().matches(options::OPT_O0))
526 assert(A->getOption().matches(options::OPT_O) &&
"Must have a -O flag");
529 StringRef S(A->getValue());
537 unsigned OptLevel = 0;
538 if (S.getAsInteger(10, OptLevel))
549 ArgStringList &CmdArgs) {
552 if (Args.hasArg(options::OPT_verify_pch) && Input.
getType() == types::TY_PCH)
555 CmdArgs.push_back(
"-x");
556 if (Args.hasArg(options::OPT_rewrite_objc))
562 const char *ClangType;
564 case types::TY_CXXModule:
567 case types::TY_PP_CXXModule:
568 ClangType =
"c++-cpp-output";
574 CmdArgs.push_back(ClangType);
581 ArgStringList &CmdArgs) {
583 auto *PGOGenerateArg = Args.getLastArg(options::OPT_fprofile_generate,
584 options::OPT_fprofile_generate_EQ,
585 options::OPT_fno_profile_generate);
586 if (PGOGenerateArg &&
587 PGOGenerateArg->getOption().matches(options::OPT_fno_profile_generate))
588 PGOGenerateArg =
nullptr;
592 auto *ProfileGenerateArg = Args.getLastArg(
593 options::OPT_fprofile_instr_generate,
594 options::OPT_fprofile_instr_generate_EQ,
595 options::OPT_fno_profile_instr_generate);
596 if (ProfileGenerateArg &&
597 ProfileGenerateArg->getOption().matches(
598 options::OPT_fno_profile_instr_generate))
599 ProfileGenerateArg =
nullptr;
601 if (PGOGenerateArg && ProfileGenerateArg)
602 D.Diag(diag::err_drv_argument_not_allowed_with)
603 << PGOGenerateArg->getSpelling() << ProfileGenerateArg->getSpelling();
607 if (PGOGenerateArg && ProfileUseArg)
608 D.Diag(diag::err_drv_argument_not_allowed_with)
609 << ProfileUseArg->getSpelling() << PGOGenerateArg->getSpelling();
611 if (ProfileGenerateArg && ProfileUseArg)
612 D.Diag(diag::err_drv_argument_not_allowed_with)
613 << ProfileGenerateArg->getSpelling() << ProfileUseArg->getSpelling();
615 if (CSPGOGenerateArg && PGOGenerateArg) {
616 D.Diag(diag::err_drv_argument_not_allowed_with)
617 << CSPGOGenerateArg->getSpelling() << PGOGenerateArg->getSpelling();
618 PGOGenerateArg =
nullptr;
623 D.Diag(diag::err_drv_unsupported_opt_for_target)
624 << ProfileSampleUseArg->getSpelling() << TC.
getTriple().str();
627 if (ProfileGenerateArg) {
628 if (ProfileGenerateArg->getOption().matches(
629 options::OPT_fprofile_instr_generate_EQ))
630 CmdArgs.push_back(Args.MakeArgString(Twine(
"-fprofile-instrument-path=") +
631 ProfileGenerateArg->getValue()));
633 CmdArgs.push_back(
"-fprofile-instrument=clang");
634 if (TC.
getTriple().isWindowsMSVCEnvironment() &&
635 Args.hasFlag(options::OPT_frtlib_defaultlib,
636 options::OPT_fno_rtlib_defaultlib,
true)) {
638 CmdArgs.push_back(Args.MakeArgString(
643 if (
auto *ColdFuncCoverageArg = Args.getLastArg(
644 options::OPT_fprofile_generate_cold_function_coverage,
645 options::OPT_fprofile_generate_cold_function_coverage_EQ)) {
647 ColdFuncCoverageArg->getOption().matches(
648 options::OPT_fprofile_generate_cold_function_coverage_EQ)
649 ? ColdFuncCoverageArg->getValue()
651 llvm::sys::path::append(
Path,
"default_%m.profraw");
656 CmdArgs.push_back(
"-mllvm");
657 CmdArgs.push_back(Args.MakeArgString(
658 Twine(
"--instrument-cold-function-only-path=") +
Path));
659 CmdArgs.push_back(
"-mllvm");
660 CmdArgs.push_back(
"--pgo-instrument-cold-function-only");
661 CmdArgs.push_back(
"-mllvm");
662 CmdArgs.push_back(
"--pgo-function-entry-coverage");
665 if (
auto *A = Args.getLastArg(options::OPT_ftemporal_profile)) {
666 if (!PGOGenerateArg && !CSPGOGenerateArg)
667 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
668 << A->getSpelling() <<
"-fprofile-generate or -fcs-profile-generate";
669 CmdArgs.push_back(
"-mllvm");
670 CmdArgs.push_back(
"--pgo-temporal-instrumentation");
673 Arg *PGOGenArg =
nullptr;
674 if (PGOGenerateArg) {
675 assert(!CSPGOGenerateArg);
676 PGOGenArg = PGOGenerateArg;
677 CmdArgs.push_back(
"-fprofile-instrument=llvm");
679 if (CSPGOGenerateArg) {
680 assert(!PGOGenerateArg);
681 PGOGenArg = CSPGOGenerateArg;
682 CmdArgs.push_back(
"-fprofile-instrument=csllvm");
685 if (TC.
getTriple().isWindowsMSVCEnvironment() &&
686 Args.hasFlag(options::OPT_frtlib_defaultlib,
687 options::OPT_fno_rtlib_defaultlib,
true)) {
689 CmdArgs.push_back(Args.MakeArgString(
692 if (PGOGenArg->getOption().matches(
693 PGOGenerateArg ? options::OPT_fprofile_generate_EQ
694 : options::OPT_fcs_profile_generate_EQ)) {
696 llvm::sys::path::append(
Path,
"default_%m.profraw");
698 Args.MakeArgString(Twine(
"-fprofile-instrument-path=") +
Path));
703 if (ProfileUseArg->getOption().matches(options::OPT_fprofile_instr_use_EQ))
704 CmdArgs.push_back(Args.MakeArgString(
705 Twine(
"-fprofile-instrument-use-path=") + ProfileUseArg->getValue()));
706 else if ((ProfileUseArg->getOption().matches(
707 options::OPT_fprofile_use_EQ) ||
708 ProfileUseArg->getOption().matches(
709 options::OPT_fprofile_instr_use))) {
711 ProfileUseArg->getNumValues() == 0 ?
"" : ProfileUseArg->getValue());
712 if (
Path.empty() || llvm::sys::fs::is_directory(
Path))
713 llvm::sys::path::append(
Path,
"default.profdata");
715 Args.MakeArgString(Twine(
"-fprofile-instrument-use-path=") +
Path));
719 bool EmitCovNotes = Args.hasFlag(options::OPT_ftest_coverage,
720 options::OPT_fno_test_coverage,
false) ||
721 Args.hasArg(options::OPT_coverage);
724 if (Args.hasFlag(options::OPT_fcoverage_mapping,
725 options::OPT_fno_coverage_mapping,
false)) {
726 if (!ProfileGenerateArg)
727 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
728 <<
"-fcoverage-mapping"
729 <<
"-fprofile-instr-generate";
731 CmdArgs.push_back(
"-fcoverage-mapping");
734 if (Args.hasFlag(options::OPT_fmcdc_coverage, options::OPT_fno_mcdc_coverage,
736 if (!Args.hasFlag(options::OPT_fcoverage_mapping,
737 options::OPT_fno_coverage_mapping,
false))
738 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
740 <<
"-fcoverage-mapping";
742 CmdArgs.push_back(
"-fcoverage-mcdc");
745 if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ,
746 options::OPT_fcoverage_compilation_dir_EQ)) {
747 if (A->getOption().matches(options::OPT_ffile_compilation_dir_EQ))
748 CmdArgs.push_back(Args.MakeArgString(
749 Twine(
"-fcoverage-compilation-dir=") + A->getValue()));
751 A->render(Args, CmdArgs);
752 }
else if (llvm::ErrorOr<std::string> CWD =
753 D.getVFS().getCurrentWorkingDirectory()) {
754 CmdArgs.push_back(Args.MakeArgString(
"-fcoverage-compilation-dir=" + *CWD));
757 if (Args.hasArg(options::OPT_fprofile_exclude_files_EQ)) {
758 auto *Arg = Args.getLastArg(options::OPT_fprofile_exclude_files_EQ);
759 if (!Args.hasArg(options::OPT_coverage))
760 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
761 <<
"-fprofile-exclude-files="
764 StringRef
v = Arg->getValue();
766 Args.MakeArgString(Twine(
"-fprofile-exclude-files=" +
v)));
769 if (Args.hasArg(options::OPT_fprofile_filter_files_EQ)) {
770 auto *Arg = Args.getLastArg(options::OPT_fprofile_filter_files_EQ);
771 if (!Args.hasArg(options::OPT_coverage))
772 D.Diag(clang::diag::err_drv_argument_only_allowed_with)
773 <<
"-fprofile-filter-files="
776 StringRef
v = Arg->getValue();
777 CmdArgs.push_back(Args.MakeArgString(Twine(
"-fprofile-filter-files=" +
v)));
780 if (
const auto *A = Args.getLastArg(options::OPT_fprofile_update_EQ)) {
781 StringRef Val = A->getValue();
782 if (Val ==
"atomic" || Val ==
"prefer-atomic")
783 CmdArgs.push_back(
"-fprofile-update=atomic");
784 else if (Val !=
"single")
785 D.Diag(diag::err_drv_unsupported_option_argument)
786 << A->getSpelling() << Val;
789 int FunctionGroups = 1;
790 int SelectedFunctionGroup = 0;
791 if (
const auto *A = Args.getLastArg(options::OPT_fprofile_function_groups)) {
792 StringRef Val = A->getValue();
793 if (Val.getAsInteger(0, FunctionGroups) || FunctionGroups < 1)
794 D.Diag(diag::err_drv_invalid_int_value) << A->getAsString(Args) << Val;
797 Args.getLastArg(options::OPT_fprofile_selected_function_group)) {
798 StringRef Val = A->getValue();
799 if (Val.getAsInteger(0, SelectedFunctionGroup) ||
800 SelectedFunctionGroup < 0 || SelectedFunctionGroup >= FunctionGroups)
801 D.Diag(diag::err_drv_invalid_int_value) << A->getAsString(Args) << Val;
803 if (FunctionGroups != 1)
804 CmdArgs.push_back(Args.MakeArgString(
"-fprofile-function-groups=" +
805 Twine(FunctionGroups)));
806 if (SelectedFunctionGroup != 0)
807 CmdArgs.push_back(Args.MakeArgString(
"-fprofile-selected-function-group=" +
808 Twine(SelectedFunctionGroup)));
814 Arg *FProfileDir =
nullptr;
815 if (Args.hasArg(options::OPT_fprofile_arcs) ||
816 Args.hasArg(options::OPT_coverage))
817 FProfileDir = Args.getLastArg(options::OPT_fprofile_dir);
822 if (EmitCovNotes || EmitCovData) {
824 if (Arg *DumpDir = Args.getLastArgNoClaim(options::OPT_dumpdir)) {
827 CoverageFilename = DumpDir->getValue();
828 CoverageFilename += llvm::sys::path::filename(Output.
getBaseInput());
829 }
else if (Arg *FinalOutput =
830 C.getArgs().getLastArg(options::OPT__SLASH_Fo)) {
831 CoverageFilename = FinalOutput->getValue();
832 }
else if (Arg *FinalOutput =
C.getArgs().getLastArg(options::OPT_o)) {
833 CoverageFilename = FinalOutput->getValue();
835 CoverageFilename = llvm::sys::path::filename(Output.
getBaseInput());
837 if (llvm::sys::path::is_relative(CoverageFilename))
838 (void)
D.getVFS().makeAbsolute(CoverageFilename);
839 llvm::sys::path::replace_extension(CoverageFilename,
"gcno");
842 Args.MakeArgString(
"-coverage-notes-file=" + CoverageFilename));
848 CoverageFilename = FProfileDir->getValue();
849 llvm::sys::path::append(CoverageFilename, Gcno);
851 llvm::sys::path::replace_extension(CoverageFilename,
"gcda");
853 Args.MakeArgString(
"-coverage-data-file=" + CoverageFilename));
860 llvm::codegenoptions::DebugInfoKind DebugInfoKind,
861 unsigned DwarfVersion,
862 llvm::DebuggerKind DebuggerTuning) {
864 if (DwarfVersion > 0)
866 Args.MakeArgString(
"-dwarf-version=" + Twine(DwarfVersion)));
867 switch (DebuggerTuning) {
868 case llvm::DebuggerKind::GDB:
869 CmdArgs.push_back(
"-debugger-tuning=gdb");
871 case llvm::DebuggerKind::LLDB:
872 CmdArgs.push_back(
"-debugger-tuning=lldb");
874 case llvm::DebuggerKind::SCE:
875 CmdArgs.push_back(
"-debugger-tuning=sce");
877 case llvm::DebuggerKind::DBX:
878 CmdArgs.push_back(
"-debugger-tuning=dbx");
887 assert(A &&
"Expected non-nullptr argument.");
890 D.Diag(diag::warn_drv_unsupported_debug_info_opt_for_target)
896 ArgStringList &CmdArgs,
899 const Arg *A = Args.getLastArg(options::OPT_gz_EQ);
903 StringRef
Value = A->getValue();
904 if (
Value ==
"none") {
905 CmdArgs.push_back(
"--compress-debug-sections=none");
906 }
else if (
Value ==
"zlib") {
907 if (llvm::compression::zlib::isAvailable()) {
909 Args.MakeArgString(
"--compress-debug-sections=" + Twine(
Value)));
911 D.Diag(diag::warn_debug_compression_unavailable) <<
"zlib";
913 }
else if (
Value ==
"zstd") {
914 if (llvm::compression::zstd::isAvailable()) {
916 Args.MakeArgString(
"--compress-debug-sections=" + Twine(
Value)));
918 D.Diag(diag::warn_debug_compression_unavailable) <<
"zstd";
921 D.Diag(diag::err_drv_unsupported_option_argument)
922 << A->getSpelling() <<
Value;
929 ArgStringList &CmdArgs,
930 bool IsCC1As =
false) {
938 CmdArgs.insert(CmdArgs.begin() + 1,
939 Args.MakeArgString(Twine(
"--amdhsa-code-object-version=") +
941 CmdArgs.insert(CmdArgs.begin() + 1,
"-mllvm");
944 CmdArgs.insert(CmdArgs.begin() + 1,
945 Args.MakeArgString(Twine(
"-mcode-object-version=") +
951 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MemBuf =
952 D.getVFS().getBufferForFile(
Path);
955 llvm::file_magic Magic = llvm::identify_magic((*MemBuf)->getBuffer());
956 if (Magic == llvm::file_magic::unknown)
960 if (Magic == llvm::file_magic::clang_ast)
963 llvm::object::ObjectFile::createObjectFile(**MemBuf, Magic);
964 return !Obj.takeError();
968 llvm::ErrorOr<llvm::vfs::Status> Status =
D.getVFS().status(
Path);
972 if (Status->isDirectory()) {
974 for (llvm::vfs::directory_iterator DI =
D.getVFS().dir_begin(
Path, EC), DE;
975 !EC && DI != DE; DI = DI.increment(EC)) {
979 D.Diag(diag::warn_drv_pch_ignoring_gch_dir) <<
Path;
985 D.Diag(diag::warn_drv_pch_ignoring_gch_file) <<
Path;
990 const Driver &
D,
const ArgList &Args,
991 ArgStringList &CmdArgs,
998 Args.AddLastArg(CmdArgs, options::OPT_C);
999 Args.AddLastArg(CmdArgs, options::OPT_CC);
1002 Arg *ArgM = Args.getLastArg(options::OPT_MM);
1004 ArgM = Args.getLastArg(options::OPT_M);
1005 Arg *ArgMD = Args.getLastArg(options::OPT_MMD);
1007 ArgMD = Args.getLastArg(options::OPT_MD);
1011 CmdArgs.push_back(
"-w");
1017 const char *DepFile;
1018 if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
1019 DepFile = MF->getValue();
1020 C.addFailureResultFile(DepFile, &JA);
1021 }
else if (Output.
getType() == types::TY_Dependencies) {
1023 }
else if (!ArgMD) {
1027 C.addFailureResultFile(DepFile, &JA);
1029 CmdArgs.push_back(
"-dependency-file");
1030 CmdArgs.push_back(DepFile);
1032 bool HasTarget =
false;
1033 for (
const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) {
1036 if (A->getOption().matches(options::OPT_MT)) {
1037 A->render(Args, CmdArgs);
1039 CmdArgs.push_back(
"-MT");
1042 CmdArgs.push_back(Args.MakeArgString(Quoted));
1048 const char *DepTarget;
1052 Arg *OutputOpt = Args.getLastArg(options::OPT_o, options::OPT__SLASH_Fo);
1053 if (OutputOpt && Output.
getType() != types::TY_Dependencies) {
1054 DepTarget = OutputOpt->getValue();
1060 llvm::sys::path::replace_extension(
P,
"o");
1061 DepTarget = Args.MakeArgString(llvm::sys::path::filename(
P));
1064 CmdArgs.push_back(
"-MT");
1067 CmdArgs.push_back(Args.MakeArgString(Quoted));
1070 if (ArgM->getOption().matches(options::OPT_M) ||
1071 ArgM->getOption().matches(options::OPT_MD))
1072 CmdArgs.push_back(
"-sys-header-deps");
1073 if ((isa<PrecompileJobAction>(JA) &&
1074 !Args.hasArg(options::OPT_fno_module_file_deps)) ||
1075 Args.hasArg(options::OPT_fmodule_file_deps))
1076 CmdArgs.push_back(
"-module-file-deps");
1079 if (Args.hasArg(options::OPT_MG)) {
1080 if (!ArgM || ArgM->getOption().matches(options::OPT_MD) ||
1081 ArgM->getOption().matches(options::OPT_MMD))
1082 D.Diag(diag::err_drv_mg_requires_m_or_mm);
1083 CmdArgs.push_back(
"-MG");
1086 Args.AddLastArg(CmdArgs, options::OPT_MP);
1087 Args.AddLastArg(CmdArgs, options::OPT_MV);
1103 !Args.hasArg(options::OPT_nostdinc) &&
1104 !Args.hasArg(options::OPT_nogpuinc) &&
1107 if (!Args.hasArg(options::OPT_nobuiltininc)) {
1111 llvm::sys::path::append(
P,
"include");
1112 llvm::sys::path::append(
P,
"openmp_wrappers");
1113 CmdArgs.push_back(
"-internal-isystem");
1114 CmdArgs.push_back(Args.MakeArgString(
P));
1117 CmdArgs.push_back(
"-include");
1118 CmdArgs.push_back(
"__clang_openmp_device_functions.h");
1121 if (Args.hasArg(options::OPT_foffload_via_llvm)) {
1125 llvm::sys::path::append(
P,
"include",
"llvm_offload_wrappers");
1126 CmdArgs.append({
"-internal-isystem", Args.MakeArgString(
P),
"-include"});
1128 CmdArgs.push_back(
"__llvm_offload_device.h");
1130 CmdArgs.push_back(
"__llvm_offload_host.h");
1140 const Arg *YcArg = Args.getLastArg(options::OPT__SLASH_Yc);
1141 const Arg *YuArg = Args.getLastArg(options::OPT__SLASH_Yu);
1144 CmdArgs.push_back(Args.MakeArgString(
"-building-pch-with-obj"));
1147 if (Args.hasFlag(options::OPT_fpch_instantiate_templates,
1148 options::OPT_fno_pch_instantiate_templates,
true))
1149 CmdArgs.push_back(Args.MakeArgString(
"-fpch-instantiate-templates"));
1151 if (YcArg || YuArg) {
1152 StringRef ThroughHeader = YcArg ? YcArg->getValue() : YuArg->getValue();
1153 if (!isa<PrecompileJobAction>(JA)) {
1154 CmdArgs.push_back(
"-include-pch");
1155 CmdArgs.push_back(Args.MakeArgString(
D.GetClPchPath(
1156 C, !ThroughHeader.empty()
1158 : llvm::sys::path::filename(Inputs[0].getBaseInput()))));
1161 if (ThroughHeader.empty()) {
1162 CmdArgs.push_back(Args.MakeArgString(
1163 Twine(
"-pch-through-hdrstop-") + (YcArg ?
"create" :
"use")));
1166 Args.MakeArgString(Twine(
"-pch-through-header=") + ThroughHeader));
1171 bool RenderedImplicitInclude =
false;
1172 for (
const Arg *A : Args.filtered(options::OPT_clang_i_Group)) {
1173 if (A->getOption().matches(options::OPT_include) &&
1174 D.getProbePrecompiled()) {
1176 bool IsFirstImplicitInclude = !RenderedImplicitInclude;
1177 RenderedImplicitInclude =
true;
1179 bool FoundPCH =
false;
1184 llvm::sys::path::replace_extension(
P,
"pch");
1185 if (
D.getVFS().exists(
P))
1190 llvm::sys::path::replace_extension(
P,
"gch");
1195 if (IsFirstImplicitInclude) {
1197 CmdArgs.push_back(
"-include-pch");
1198 CmdArgs.push_back(Args.MakeArgString(
P));
1202 D.Diag(diag::warn_drv_pch_not_first_include) <<
P
1203 << A->getAsString(Args);
1206 }
else if (A->getOption().matches(options::OPT_isystem_after)) {
1213 }
else if (A->getOption().matches(options::OPT_stdlibxx_isystem)) {
1216 }
else if (A->getOption().matches(options::OPT_ibuiltininc)) {
1223 A->render(Args, CmdArgs);
1226 Args.addAllArgs(CmdArgs,
1227 {options::OPT_D, options::OPT_U, options::OPT_I_Group,
1228 options::OPT_F, options::OPT_embed_dir_EQ});
1236 Args.AddAllArgValues(CmdArgs, options::OPT_Wp_COMMA,
1237 options::OPT_Xpreprocessor);
1240 if (Arg *A = Args.getLastArg(options::OPT_I_))
1241 D.Diag(diag::err_drv_I_dash_not_supported) << A->getAsString(Args);
1245 StringRef sysroot =
C.getSysRoot();
1246 if (sysroot !=
"") {
1247 if (!Args.hasArg(options::OPT_isysroot)) {
1248 CmdArgs.push_back(
"-isysroot");
1249 CmdArgs.push_back(
C.getArgs().MakeArgString(sysroot));
1266 addDirectoryList(Args, CmdArgs,
"-objcxx-isystem",
"OBJCPLUS_INCLUDE_PATH");
1274 bool HasStdlibxxIsystem = Args.hasArg(options::OPT_stdlibxx_isystem);
1277 [&Args, &CmdArgs, HasStdlibxxIsystem](
const ToolChain &TC) {
1287 if (!Args.hasArg(options::OPT_nostdinc) &&
1288 !Args.hasArg(options::OPT_nogpuinc) &&
1289 !Args.hasArg(options::OPT_nobuiltininc)) {
1297 llvm::sys::path::append(
P,
"include");
1298 llvm::sys::path::append(
P,
getToolChain().getTripleString());
1299 CmdArgs.push_back(
"-internal-isystem");
1300 CmdArgs.push_back(Args.MakeArgString(
P));
1305 llvm::sys::path::append(
P,
"include");
1306 llvm::sys::path::append(
P,
"llvm_libc_wrappers");
1307 CmdArgs.push_back(
"-internal-isystem");
1308 CmdArgs.push_back(Args.MakeArgString(
P));
1315 [&Args, &CmdArgs](
const ToolChain &TC) {
1326 Args.AddLastArg(CmdArgs, options::OPT_ffile_reproducible,
1327 options::OPT_fno_file_reproducible);
1329 if (
const char *Epoch = std::getenv(
"SOURCE_DATE_EPOCH")) {
1330 CmdArgs.push_back(
"-source-date-epoch");
1331 CmdArgs.push_back(Args.MakeArgString(Epoch));
1334 Args.addOptInFlag(CmdArgs, options::OPT_fdefine_target_os_macros,
1335 options::OPT_fno_define_target_os_macros);
1340 switch (Triple.getArch()) {
1344 case llvm::Triple::aarch64:
1345 case llvm::Triple::aarch64_32:
1346 case llvm::Triple::aarch64_be:
1347 case llvm::Triple::arm:
1348 case llvm::Triple::armeb:
1349 case llvm::Triple::thumb:
1350 case llvm::Triple::thumbeb:
1351 if (Triple.isOSDarwin() || Triple.isOSWindows())
1355 case llvm::Triple::ppc:
1356 case llvm::Triple::ppc64:
1357 if (Triple.isOSDarwin())
1361 case llvm::Triple::hexagon:
1362 case llvm::Triple::msp430:
1363 case llvm::Triple::ppcle:
1364 case llvm::Triple::ppc64le:
1365 case llvm::Triple::riscv32:
1366 case llvm::Triple::riscv64:
1367 case llvm::Triple::systemz:
1368 case llvm::Triple::xcore:
1369 case llvm::Triple::xtensa:
1375 const ArgList &Args) {
1378 if (!Triple.isOSDarwin())
1382 return Args.getAllArgValues(options::OPT_arch).size() > 1;
1386 const llvm::Triple &Triple) {
1391 bool hasExplicitOutputFile =
1392 Args.getLastArg(options::OPT_foptimization_record_file_EQ);
1394 D.Diag(diag::err_drv_invalid_output_with_multiple_archs)
1395 <<
"-foptimization-record-file";
1402 const llvm::Triple &Triple,
1405 StringRef Format =
"yaml";
1406 if (
const Arg *A = Args.getLastArg(options::OPT_fsave_optimization_record_EQ))
1407 Format = A->getValue();
1409 CmdArgs.push_back(
"-opt-record-file");
1411 const Arg *A = Args.getLastArg(options::OPT_foptimization_record_file_EQ);
1413 CmdArgs.push_back(A->getValue());
1415 bool hasMultipleArchs =
1416 Triple.isOSDarwin() &&
1417 Args.getAllArgValues(options::OPT_arch).size() > 1;
1421 if (Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)) {
1422 if (Arg *FinalOutput = Args.getLastArg(options::OPT_o))
1423 F = FinalOutput->getValue();
1425 if (Format !=
"yaml" &&
1426 Triple.isOSDarwin() &&
1440 llvm::sys::path::replace_extension(F,
"");
1442 Triple.normalize());
1452 if (hasMultipleArchs) {
1456 llvm::sys::path::replace_extension(F,
"");
1459 F += Triple.getArchName();
1461 llvm::sys::path::replace_extension(F, OldExtension);
1465 Extension +=
"opt.";
1466 Extension += Format;
1468 llvm::sys::path::replace_extension(F, Extension);
1469 CmdArgs.push_back(Args.MakeArgString(F));
1473 Args.getLastArg(options::OPT_foptimization_record_passes_EQ)) {
1474 CmdArgs.push_back(
"-opt-record-passes");
1475 CmdArgs.push_back(A->getValue());
1478 if (!Format.empty()) {
1479 CmdArgs.push_back(
"-opt-record-format");
1480 CmdArgs.push_back(Format.data());
1485 if (!Args.hasFlag(options::OPT_faapcs_bitfield_width,
1486 options::OPT_fno_aapcs_bitfield_width,
true))
1487 CmdArgs.push_back(
"-fno-aapcs-bitfield-width");
1489 if (Args.getLastArg(options::OPT_ForceAAPCSBitfieldLoad))
1490 CmdArgs.push_back(
"-faapcs-bitfield-load");
1494void RenderARMABI(
const Driver &
D,
const llvm::Triple &Triple,
1495 const ArgList &Args, ArgStringList &CmdArgs) {
1499 const char *ABIName =
nullptr;
1500 if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
1501 ABIName = A->getValue();
1503 std::string CPU =
getCPUName(
D, Args, Triple,
false);
1504 ABIName = llvm::ARM::computeDefaultTargetABI(Triple, CPU).data();
1507 CmdArgs.push_back(
"-target-abi");
1508 CmdArgs.push_back(ABIName);
1511void AddUnalignedAccessWarning(ArgStringList &CmdArgs) {
1512 auto StrictAlignIter =
1513 llvm::find_if(llvm::reverse(CmdArgs), [](StringRef Arg) {
1514 return Arg ==
"+strict-align" || Arg ==
"-strict-align";
1516 if (StrictAlignIter != CmdArgs.rend() &&
1517 StringRef(*StrictAlignIter) ==
"+strict-align")
1518 CmdArgs.push_back(
"-Wunaligned-access");
1526 if (!DriverArgs.hasArg(options::OPT_fptrauth_intrinsics,
1527 options::OPT_fno_ptrauth_intrinsics))
1528 CC1Args.push_back(
"-fptrauth-intrinsics");
1530 if (!DriverArgs.hasArg(options::OPT_fptrauth_calls,
1531 options::OPT_fno_ptrauth_calls))
1532 CC1Args.push_back(
"-fptrauth-calls");
1534 if (!DriverArgs.hasArg(options::OPT_fptrauth_returns,
1535 options::OPT_fno_ptrauth_returns))
1536 CC1Args.push_back(
"-fptrauth-returns");
1538 if (!DriverArgs.hasArg(options::OPT_fptrauth_auth_traps,
1539 options::OPT_fno_ptrauth_auth_traps))
1540 CC1Args.push_back(
"-fptrauth-auth-traps");
1542 if (!DriverArgs.hasArg(
1543 options::OPT_fptrauth_vtable_pointer_address_discrimination,
1544 options::OPT_fno_ptrauth_vtable_pointer_address_discrimination))
1545 CC1Args.push_back(
"-fptrauth-vtable-pointer-address-discrimination");
1547 if (!DriverArgs.hasArg(
1548 options::OPT_fptrauth_vtable_pointer_type_discrimination,
1549 options::OPT_fno_ptrauth_vtable_pointer_type_discrimination))
1550 CC1Args.push_back(
"-fptrauth-vtable-pointer-type-discrimination");
1552 if (!DriverArgs.hasArg(options::OPT_fptrauth_indirect_gotos,
1553 options::OPT_fno_ptrauth_indirect_gotos))
1554 CC1Args.push_back(
"-fptrauth-indirect-gotos");
1556 if (!DriverArgs.hasArg(options::OPT_fptrauth_init_fini,
1557 options::OPT_fno_ptrauth_init_fini))
1558 CC1Args.push_back(
"-fptrauth-init-fini");
1562 ArgStringList &CmdArgs,
bool isAArch64) {
1563 const Arg *A = isAArch64
1564 ? Args.getLastArg(options::OPT_msign_return_address_EQ,
1565 options::OPT_mbranch_protection_EQ)
1566 : Args.getLastArg(options::OPT_mbranch_protection_EQ);
1572 if (!(isAArch64 || (Triple.isArmT32() && Triple.isArmMClass())))
1573 D.Diag(diag::warn_incompatible_branch_protection_option)
1574 << Triple.getArchName();
1576 StringRef
Scope, Key;
1577 bool IndirectBranches, BranchProtectionPAuthLR, GuardedControlStack;
1579 if (A->getOption().matches(options::OPT_msign_return_address_EQ)) {
1580 Scope = A->getValue();
1582 D.Diag(diag::err_drv_unsupported_option_argument)
1583 << A->getSpelling() <<
Scope;
1585 IndirectBranches =
false;
1586 BranchProtectionPAuthLR =
false;
1587 GuardedControlStack =
false;
1590 llvm::ARM::ParsedBranchProtection PBP;
1591 bool EnablePAuthLR =
false;
1598 auto isPAuthLR = [](
const char *member) {
1599 llvm::AArch64::ExtensionInfo pauthlr_extension =
1600 llvm::AArch64::getExtensionByID(llvm::AArch64::AEK_PAUTHLR);
1601 return pauthlr_extension.PosTargetFeature == member;
1604 if (std::any_of(CmdArgs.begin(), CmdArgs.end(), isPAuthLR))
1605 EnablePAuthLR =
true;
1607 if (!llvm::ARM::parseBranchProtection(A->getValue(), PBP, DiagMsg,
1609 D.Diag(diag::err_drv_unsupported_option_argument)
1610 << A->getSpelling() << DiagMsg;
1611 if (!isAArch64 && PBP.Key ==
"b_key")
1612 D.Diag(diag::warn_unsupported_branch_protection)
1613 <<
"b-key" << A->getAsString(Args);
1616 BranchProtectionPAuthLR = PBP.BranchProtectionPAuthLR;
1617 IndirectBranches = PBP.BranchTargetEnforcement;
1618 GuardedControlStack = PBP.GuardedControlStack;
1622 Args.MakeArgString(Twine(
"-msign-return-address=") +
Scope));
1623 if (
Scope !=
"none") {
1624 if (Triple.getEnvironment() == llvm::Triple::PAuthTest)
1625 D.Diag(diag::err_drv_unsupported_opt_for_target)
1626 << A->getAsString(Args) << Triple.getTriple();
1628 Args.MakeArgString(Twine(
"-msign-return-address-key=") + Key));
1630 if (BranchProtectionPAuthLR) {
1631 if (Triple.getEnvironment() == llvm::Triple::PAuthTest)
1632 D.Diag(diag::err_drv_unsupported_opt_for_target)
1633 << A->getAsString(Args) << Triple.getTriple();
1635 Args.MakeArgString(Twine(
"-mbranch-protection-pauth-lr")));
1637 if (IndirectBranches)
1638 CmdArgs.push_back(
"-mbranch-target-enforce");
1641 if (GuardedControlStack) {
1642 if (Triple.getEnvironment() == llvm::Triple::PAuthTest)
1643 D.Diag(diag::err_drv_unsupported_opt_for_target)
1644 << A->getAsString(Args) << Triple.getTriple();
1645 CmdArgs.push_back(
"-mguarded-control-stack");
1649void Clang::AddARMTargetArgs(
const llvm::Triple &Triple,
const ArgList &Args,
1650 ArgStringList &CmdArgs,
bool KernelOrKext)
const {
1651 RenderARMABI(
getToolChain().getDriver(), Triple, Args, CmdArgs);
1658 CmdArgs.push_back(
"-msoft-float");
1659 CmdArgs.push_back(
"-mfloat-abi");
1660 CmdArgs.push_back(
"soft");
1663 CmdArgs.push_back(
"-mfloat-abi");
1664 CmdArgs.push_back(
"soft");
1668 CmdArgs.push_back(
"-mfloat-abi");
1669 CmdArgs.push_back(
"hard");
1673 if (Arg *A = Args.getLastArg(options::OPT_mglobal_merge,
1674 options::OPT_mno_global_merge)) {
1675 CmdArgs.push_back(
"-mllvm");
1676 if (A->getOption().matches(options::OPT_mno_global_merge))
1677 CmdArgs.push_back(
"-arm-global-merge=false");
1679 CmdArgs.push_back(
"-arm-global-merge=true");
1682 if (!Args.hasFlag(options::OPT_mimplicit_float,
1683 options::OPT_mno_implicit_float,
true))
1684 CmdArgs.push_back(
"-no-implicit-float");
1686 if (Args.getLastArg(options::OPT_mcmse))
1687 CmdArgs.push_back(
"-mcmse");
1694 AddUnalignedAccessWarning(CmdArgs);
1697void Clang::RenderTargetOptions(
const llvm::Triple &EffectiveTriple,
1698 const ArgList &Args,
bool KernelOrKext,
1699 ArgStringList &CmdArgs)
const {
1710 case llvm::Triple::arm:
1711 case llvm::Triple::armeb:
1712 case llvm::Triple::thumb:
1713 case llvm::Triple::thumbeb:
1715 AddARMTargetArgs(EffectiveTriple, Args, CmdArgs, KernelOrKext);
1718 case llvm::Triple::aarch64:
1719 case llvm::Triple::aarch64_32:
1720 case llvm::Triple::aarch64_be:
1721 AddAArch64TargetArgs(Args, CmdArgs);
1724 case llvm::Triple::loongarch32:
1725 case llvm::Triple::loongarch64:
1726 AddLoongArchTargetArgs(Args, CmdArgs);
1729 case llvm::Triple::mips:
1730 case llvm::Triple::mipsel:
1731 case llvm::Triple::mips64:
1732 case llvm::Triple::mips64el:
1733 AddMIPSTargetArgs(Args, CmdArgs);
1736 case llvm::Triple::ppc:
1737 case llvm::Triple::ppcle:
1738 case llvm::Triple::ppc64:
1739 case llvm::Triple::ppc64le:
1740 AddPPCTargetArgs(Args, CmdArgs);
1743 case llvm::Triple::riscv32:
1744 case llvm::Triple::riscv64:
1745 AddRISCVTargetArgs(Args, CmdArgs);
1748 case llvm::Triple::sparc:
1749 case llvm::Triple::sparcel:
1750 case llvm::Triple::sparcv9:
1751 AddSparcTargetArgs(Args, CmdArgs);
1754 case llvm::Triple::systemz:
1755 AddSystemZTargetArgs(Args, CmdArgs);
1758 case llvm::Triple::x86:
1759 case llvm::Triple::x86_64:
1760 AddX86TargetArgs(Args, CmdArgs);
1763 case llvm::Triple::lanai:
1764 AddLanaiTargetArgs(Args, CmdArgs);
1767 case llvm::Triple::hexagon:
1768 AddHexagonTargetArgs(Args, CmdArgs);
1771 case llvm::Triple::wasm32:
1772 case llvm::Triple::wasm64:
1773 AddWebAssemblyTargetArgs(Args, CmdArgs);
1776 case llvm::Triple::ve:
1777 AddVETargetArgs(Args, CmdArgs);
1783void RenderAArch64ABI(
const llvm::Triple &Triple,
const ArgList &Args,
1784 ArgStringList &CmdArgs) {
1785 const char *ABIName =
nullptr;
1786 if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ))
1787 ABIName = A->getValue();
1788 else if (Triple.isOSDarwin())
1789 ABIName =
"darwinpcs";
1790 else if (Triple.getEnvironment() == llvm::Triple::PAuthTest)
1791 ABIName =
"pauthtest";
1795 CmdArgs.push_back(
"-target-abi");
1796 CmdArgs.push_back(ABIName);
1800void Clang::AddAArch64TargetArgs(
const ArgList &Args,
1801 ArgStringList &CmdArgs)
const {
1804 if (!Args.hasFlag(options::OPT_mred_zone, options::OPT_mno_red_zone,
true) ||
1805 Args.hasArg(options::OPT_mkernel) ||
1806 Args.hasArg(options::OPT_fapple_kext))
1807 CmdArgs.push_back(
"-disable-red-zone");
1809 if (!Args.hasFlag(options::OPT_mimplicit_float,
1810 options::OPT_mno_implicit_float,
true))
1811 CmdArgs.push_back(
"-no-implicit-float");
1813 RenderAArch64ABI(Triple, Args, CmdArgs);
1816 if (Arg *A = Args.getLastArg(options::OPT_mglobal_merge,
1817 options::OPT_mno_global_merge)) {
1818 CmdArgs.push_back(
"-mllvm");
1819 if (A->getOption().matches(options::OPT_mno_global_merge))
1820 CmdArgs.push_back(
"-aarch64-enable-global-merge=false");
1822 CmdArgs.push_back(
"-aarch64-enable-global-merge=true");
1828 if (Triple.getEnvironment() == llvm::Triple::PAuthTest)
1832 if (Arg *A = Args.getLastArg(options::OPT_msve_vector_bits_EQ)) {
1833 StringRef Val = A->getValue();
1835 if (Val ==
"128" || Val ==
"256" || Val ==
"512" || Val ==
"1024" ||
1836 Val ==
"2048" || Val ==
"128+" || Val ==
"256+" || Val ==
"512+" ||
1837 Val ==
"1024+" || Val ==
"2048+") {
1839 if (!Val.consume_back(
"+")) {
1841 assert(!
Invalid &&
"Failed to parse value");
1843 Args.MakeArgString(
"-mvscale-max=" + llvm::Twine(Bits / 128)));
1847 assert(!
Invalid &&
"Failed to parse value");
1849 Args.MakeArgString(
"-mvscale-min=" + llvm::Twine(Bits / 128)));
1851 }
else if (Val !=
"scalable")
1853 D.Diag(diag::err_drv_unsupported_option_argument)
1854 << A->getSpelling() << Val;
1859 if (
const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
1860 CmdArgs.push_back(
"-tune-cpu");
1861 if (strcmp(A->getValue(),
"native") == 0)
1862 CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
1864 CmdArgs.push_back(A->getValue());
1867 AddUnalignedAccessWarning(CmdArgs);
1869 Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_intrinsics,
1870 options::OPT_fno_ptrauth_intrinsics);
1871 Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_calls,
1872 options::OPT_fno_ptrauth_calls);
1873 Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_returns,
1874 options::OPT_fno_ptrauth_returns);
1875 Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_auth_traps,
1876 options::OPT_fno_ptrauth_auth_traps);
1878 CmdArgs, options::OPT_fptrauth_vtable_pointer_address_discrimination,
1879 options::OPT_fno_ptrauth_vtable_pointer_address_discrimination);
1881 CmdArgs, options::OPT_fptrauth_vtable_pointer_type_discrimination,
1882 options::OPT_fno_ptrauth_vtable_pointer_type_discrimination);
1884 CmdArgs, options::OPT_fptrauth_type_info_vtable_pointer_discrimination,
1885 options::OPT_fno_ptrauth_type_info_vtable_pointer_discrimination);
1887 CmdArgs, options::OPT_fptrauth_function_pointer_type_discrimination,
1888 options::OPT_fno_ptrauth_function_pointer_type_discrimination);
1890 Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_indirect_gotos,
1891 options::OPT_fno_ptrauth_indirect_gotos);
1892 Args.addOptInFlag(CmdArgs, options::OPT_fptrauth_init_fini,
1893 options::OPT_fno_ptrauth_init_fini);
1894 Args.addOptInFlag(CmdArgs,
1895 options::OPT_fptrauth_init_fini_address_discrimination,
1896 options::OPT_fno_ptrauth_init_fini_address_discrimination);
1897 Args.addOptInFlag(CmdArgs, options::OPT_faarch64_jump_table_hardening,
1898 options::OPT_fno_aarch64_jump_table_hardening);
1901void Clang::AddLoongArchTargetArgs(
const ArgList &Args,
1902 ArgStringList &CmdArgs)
const {
1905 CmdArgs.push_back(
"-target-abi");
1911 if (
const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
1912 std::string TuneCPU = A->getValue();
1914 CmdArgs.push_back(
"-tune-cpu");
1915 CmdArgs.push_back(Args.MakeArgString(TuneCPU));
1918 if (Arg *A = Args.getLastArg(options::OPT_mannotate_tablejump,
1919 options::OPT_mno_annotate_tablejump)) {
1920 if (A->getOption().matches(options::OPT_mannotate_tablejump)) {
1921 CmdArgs.push_back(
"-mllvm");
1922 CmdArgs.push_back(
"-loongarch-annotate-tablejump");
1927void Clang::AddMIPSTargetArgs(
const ArgList &Args,
1928 ArgStringList &CmdArgs)
const {
1935 CmdArgs.push_back(
"-target-abi");
1936 CmdArgs.push_back(ABIName.data());
1941 CmdArgs.push_back(
"-msoft-float");
1942 CmdArgs.push_back(
"-mfloat-abi");
1943 CmdArgs.push_back(
"soft");
1947 CmdArgs.push_back(
"-mfloat-abi");
1948 CmdArgs.push_back(
"hard");
1951 if (Arg *A = Args.getLastArg(options::OPT_mldc1_sdc1,
1952 options::OPT_mno_ldc1_sdc1)) {
1953 if (A->getOption().matches(options::OPT_mno_ldc1_sdc1)) {
1954 CmdArgs.push_back(
"-mllvm");
1955 CmdArgs.push_back(
"-mno-ldc1-sdc1");
1959 if (Arg *A = Args.getLastArg(options::OPT_mcheck_zero_division,
1960 options::OPT_mno_check_zero_division)) {
1961 if (A->getOption().matches(options::OPT_mno_check_zero_division)) {
1962 CmdArgs.push_back(
"-mllvm");
1963 CmdArgs.push_back(
"-mno-check-zero-division");
1967 if (Args.getLastArg(options::OPT_mfix4300)) {
1968 CmdArgs.push_back(
"-mllvm");
1969 CmdArgs.push_back(
"-mfix4300");
1972 if (Arg *A = Args.getLastArg(options::OPT_G)) {
1973 StringRef
v = A->getValue();
1974 CmdArgs.push_back(
"-mllvm");
1975 CmdArgs.push_back(Args.MakeArgString(
"-mips-ssection-threshold=" +
v));
1979 Arg *GPOpt = Args.getLastArg(options::OPT_mgpopt, options::OPT_mno_gpopt);
1981 Args.getLastArg(options::OPT_mabicalls, options::OPT_mno_abicalls);
1994 ABICalls && ABICalls->getOption().matches(options::OPT_mno_abicalls);
1996 llvm::Reloc::Model RelocationModel;
1999 std::tie(RelocationModel, PICLevel, IsPIE) =
2002 NoABICalls = NoABICalls ||
2003 (RelocationModel == llvm::Reloc::Static && ABIName ==
"n64");
2005 bool WantGPOpt = GPOpt && GPOpt->getOption().matches(options::OPT_mgpopt);
2007 if (NoABICalls && (!GPOpt || WantGPOpt)) {
2008 CmdArgs.push_back(
"-mllvm");
2009 CmdArgs.push_back(
"-mgpopt");
2011 Arg *LocalSData = Args.getLastArg(options::OPT_mlocal_sdata,
2012 options::OPT_mno_local_sdata);
2013 Arg *ExternSData = Args.getLastArg(options::OPT_mextern_sdata,
2014 options::OPT_mno_extern_sdata);
2015 Arg *EmbeddedData = Args.getLastArg(options::OPT_membedded_data,
2016 options::OPT_mno_embedded_data);
2018 CmdArgs.push_back(
"-mllvm");
2019 if (LocalSData->getOption().matches(options::OPT_mlocal_sdata)) {
2020 CmdArgs.push_back(
"-mlocal-sdata=1");
2022 CmdArgs.push_back(
"-mlocal-sdata=0");
2024 LocalSData->claim();
2028 CmdArgs.push_back(
"-mllvm");
2029 if (ExternSData->getOption().matches(options::OPT_mextern_sdata)) {
2030 CmdArgs.push_back(
"-mextern-sdata=1");
2032 CmdArgs.push_back(
"-mextern-sdata=0");
2034 ExternSData->claim();
2038 CmdArgs.push_back(
"-mllvm");
2039 if (EmbeddedData->getOption().matches(options::OPT_membedded_data)) {
2040 CmdArgs.push_back(
"-membedded-data=1");
2042 CmdArgs.push_back(
"-membedded-data=0");
2044 EmbeddedData->claim();
2047 }
else if ((!ABICalls || (!NoABICalls && ABICalls)) && WantGPOpt)
2048 D.Diag(diag::warn_drv_unsupported_gpopt) << (ABICalls ? 0 : 1);
2053 if (Arg *A = Args.getLastArg(options::OPT_mcompact_branches_EQ)) {
2054 StringRef Val = StringRef(A->getValue());
2056 if (Val ==
"never" || Val ==
"always" || Val ==
"optimal") {
2057 CmdArgs.push_back(
"-mllvm");
2058 CmdArgs.push_back(Args.MakeArgString(
"-mips-compact-branches=" + Val));
2060 D.Diag(diag::err_drv_unsupported_option_argument)
2061 << A->getSpelling() << Val;
2063 D.Diag(diag::warn_target_unsupported_compact_branches) << CPUName;
2066 if (Arg *A = Args.getLastArg(options::OPT_mrelax_pic_calls,
2067 options::OPT_mno_relax_pic_calls)) {
2068 if (A->getOption().matches(options::OPT_mno_relax_pic_calls)) {
2069 CmdArgs.push_back(
"-mllvm");
2070 CmdArgs.push_back(
"-mips-jalr-reloc=0");
2075void Clang::AddPPCTargetArgs(
const ArgList &Args,
2076 ArgStringList &CmdArgs)
const {
2079 if (Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
2080 CmdArgs.push_back(
"-tune-cpu");
2081 StringRef CPU = llvm::PPC::getNormalizedPPCTuneCPU(
T, A->getValue());
2082 CmdArgs.push_back(Args.MakeArgString(CPU.str()));
2086 const char *ABIName =
nullptr;
2087 if (
T.isOSBinFormatELF()) {
2089 case llvm::Triple::ppc64: {
2090 if (
T.isPPC64ELFv2ABI())
2096 case llvm::Triple::ppc64le:
2105 bool VecExtabi =
false;
2106 for (
const Arg *A : Args.filtered(options::OPT_mabi_EQ)) {
2107 StringRef
V = A->getValue();
2108 if (
V ==
"ieeelongdouble") {
2109 IEEELongDouble =
true;
2111 }
else if (
V ==
"ibmlongdouble") {
2112 IEEELongDouble =
false;
2114 }
else if (
V ==
"vec-default") {
2117 }
else if (
V ==
"vec-extabi") {
2120 }
else if (
V ==
"elfv1") {
2123 }
else if (
V ==
"elfv2") {
2126 }
else if (
V !=
"altivec")
2130 ABIName = A->getValue();
2133 CmdArgs.push_back(
"-mabi=ieeelongdouble");
2136 D.Diag(diag::err_drv_unsupported_opt_for_target)
2137 <<
"-mabi=vec-extabi" <<
T.str();
2138 CmdArgs.push_back(
"-mabi=vec-extabi");
2141 if (!Args.hasFlag(options::OPT_mred_zone, options::OPT_mno_red_zone,
true))
2142 CmdArgs.push_back(
"-disable-red-zone");
2147 CmdArgs.push_back(
"-msoft-float");
2148 CmdArgs.push_back(
"-mfloat-abi");
2149 CmdArgs.push_back(
"soft");
2153 CmdArgs.push_back(
"-mfloat-abi");
2154 CmdArgs.push_back(
"hard");
2158 CmdArgs.push_back(
"-target-abi");
2159 CmdArgs.push_back(ABIName);
2163void Clang::AddRISCVTargetArgs(
const ArgList &Args,
2164 ArgStringList &CmdArgs)
const {
2168 CmdArgs.push_back(
"-target-abi");
2169 CmdArgs.push_back(ABIName.data());
2171 if (Arg *A = Args.getLastArg(options::OPT_G)) {
2172 CmdArgs.push_back(
"-msmall-data-limit");
2173 CmdArgs.push_back(A->getValue());
2176 if (!Args.hasFlag(options::OPT_mimplicit_float,
2177 options::OPT_mno_implicit_float,
true))
2178 CmdArgs.push_back(
"-no-implicit-float");
2180 if (
const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
2181 CmdArgs.push_back(
"-tune-cpu");
2182 if (strcmp(A->getValue(),
"native") == 0)
2183 CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
2185 CmdArgs.push_back(A->getValue());
2189 if (Arg *A = Args.getLastArg(options::OPT_mrvv_vector_bits_EQ)) {
2190 StringRef Val = A->getValue();
2194 unsigned MinVLen = 0;
2196 auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
2199 if (!errorToBool(ISAInfo.takeError()))
2200 MinVLen = (*ISAInfo)->getMinVLen();
2205 if (Val ==
"zvl" && MinVLen >= llvm::RISCV::RVVBitsPerBlock) {
2207 }
else if (!Val.getAsInteger(10, Bits)) {
2210 if (Bits < MinVLen || Bits < llvm::RISCV::RVVBitsPerBlock ||
2211 Bits > 65536 || !llvm::isPowerOf2_32(Bits))
2217 unsigned VScaleMin = Bits / llvm::RISCV::RVVBitsPerBlock;
2219 Args.MakeArgString(
"-mvscale-max=" + llvm::Twine(VScaleMin)));
2221 Args.MakeArgString(
"-mvscale-min=" + llvm::Twine(VScaleMin)));
2222 }
else if (Val !=
"scalable") {
2224 D.Diag(diag::err_drv_unsupported_option_argument)
2225 << A->getSpelling() << Val;
2230void Clang::AddSparcTargetArgs(
const ArgList &Args,
2231 ArgStringList &CmdArgs)
const {
2237 CmdArgs.push_back(
"-msoft-float");
2238 CmdArgs.push_back(
"-mfloat-abi");
2239 CmdArgs.push_back(
"soft");
2243 CmdArgs.push_back(
"-mfloat-abi");
2244 CmdArgs.push_back(
"hard");
2247 if (
const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
2248 StringRef Name = A->getValue();
2249 std::string TuneCPU;
2250 if (Name ==
"native")
2251 TuneCPU = std::string(llvm::sys::getHostCPUName());
2253 TuneCPU = std::string(Name);
2255 CmdArgs.push_back(
"-tune-cpu");
2256 CmdArgs.push_back(Args.MakeArgString(TuneCPU));
2260void Clang::AddSystemZTargetArgs(
const ArgList &Args,
2261 ArgStringList &CmdArgs)
const {
2262 if (
const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
2263 CmdArgs.push_back(
"-tune-cpu");
2264 if (strcmp(A->getValue(),
"native") == 0)
2265 CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
2267 CmdArgs.push_back(A->getValue());
2271 Args.hasFlag(options::OPT_mbackchain, options::OPT_mno_backchain,
false);
2272 bool HasPackedStack = Args.hasFlag(options::OPT_mpacked_stack,
2273 options::OPT_mno_packed_stack,
false);
2277 if (HasBackchain && HasPackedStack && !HasSoftFloat) {
2279 D.Diag(diag::err_drv_unsupported_opt)
2280 <<
"-mpacked-stack -mbackchain -mhard-float";
2283 CmdArgs.push_back(
"-mbackchain");
2285 CmdArgs.push_back(
"-mpacked-stack");
2288 CmdArgs.push_back(
"-msoft-float");
2289 CmdArgs.push_back(
"-mfloat-abi");
2290 CmdArgs.push_back(
"soft");
2294void Clang::AddX86TargetArgs(
const ArgList &Args,
2295 ArgStringList &CmdArgs)
const {
2299 if (!Args.hasFlag(options::OPT_mred_zone, options::OPT_mno_red_zone,
true) ||
2300 Args.hasArg(options::OPT_mkernel) ||
2301 Args.hasArg(options::OPT_fapple_kext))
2302 CmdArgs.push_back(
"-disable-red-zone");
2304 if (!Args.hasFlag(options::OPT_mtls_direct_seg_refs,
2305 options::OPT_mno_tls_direct_seg_refs,
true))
2306 CmdArgs.push_back(
"-mno-tls-direct-seg-refs");
2310 bool NoImplicitFloat = (Args.hasArg(options::OPT_mkernel) ||
2311 Args.hasArg(options::OPT_fapple_kext));
2312 if (Arg *A = Args.getLastArg(
2313 options::OPT_msoft_float, options::OPT_mno_soft_float,
2314 options::OPT_mimplicit_float, options::OPT_mno_implicit_float)) {
2315 const Option &O = A->getOption();
2316 NoImplicitFloat = (O.matches(options::OPT_mno_implicit_float) ||
2317 O.matches(options::OPT_msoft_float));
2319 if (NoImplicitFloat)
2320 CmdArgs.push_back(
"-no-implicit-float");
2322 if (Arg *A = Args.getLastArg(options::OPT_masm_EQ)) {
2323 StringRef
Value = A->getValue();
2325 CmdArgs.push_back(
"-mllvm");
2326 CmdArgs.push_back(Args.MakeArgString(
"-x86-asm-syntax=" +
Value));
2327 CmdArgs.push_back(Args.MakeArgString(
"-inline-asm=" +
Value));
2329 D.Diag(diag::err_drv_unsupported_option_argument)
2330 << A->getSpelling() <<
Value;
2332 }
else if (
D.IsCLMode()) {
2333 CmdArgs.push_back(
"-mllvm");
2334 CmdArgs.push_back(
"-x86-asm-syntax=intel");
2337 if (Arg *A = Args.getLastArg(options::OPT_mskip_rax_setup,
2338 options::OPT_mno_skip_rax_setup))
2339 if (A->getOption().matches(options::OPT_mskip_rax_setup))
2340 CmdArgs.push_back(Args.MakeArgString(
"-mskip-rax-setup"));
2343 if (Args.hasFlag(options::OPT_miamcu, options::OPT_mno_iamcu,
false)) {
2344 CmdArgs.push_back(
"-mfloat-abi");
2345 CmdArgs.push_back(
"soft");
2346 CmdArgs.push_back(
"-mstack-alignment=4");
2352 std::string TuneCPU;
2353 if (!Args.hasArg(clang::driver::options::OPT_march_EQ) &&
2355 TuneCPU =
"generic";
2358 if (
const Arg *A = Args.getLastArg(clang::driver::options::OPT_mtune_EQ)) {
2359 StringRef Name = A->getValue();
2361 if (Name ==
"native") {
2362 Name = llvm::sys::getHostCPUName();
2364 TuneCPU = std::string(Name);
2366 TuneCPU = std::string(Name);
2369 if (!TuneCPU.empty()) {
2370 CmdArgs.push_back(
"-tune-cpu");
2371 CmdArgs.push_back(Args.MakeArgString(TuneCPU));
2375void Clang::AddHexagonTargetArgs(
const ArgList &Args,
2376 ArgStringList &CmdArgs)
const {
2377 CmdArgs.push_back(
"-mqdsp6-compat");
2378 CmdArgs.push_back(
"-Wreturn-type");
2381 CmdArgs.push_back(
"-mllvm");
2383 Args.MakeArgString(
"-hexagon-small-data-threshold=" + Twine(*G)));
2386 if (!Args.hasArg(options::OPT_fno_short_enums))
2387 CmdArgs.push_back(
"-fshort-enums");
2388 if (Args.getLastArg(options::OPT_mieee_rnd_near)) {
2389 CmdArgs.push_back(
"-mllvm");
2390 CmdArgs.push_back(
"-enable-hexagon-ieee-rnd-near");
2392 CmdArgs.push_back(
"-mllvm");
2393 CmdArgs.push_back(
"-machine-sink-split=0");
2396void Clang::AddLanaiTargetArgs(
const ArgList &Args,
2397 ArgStringList &CmdArgs)
const {
2398 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
2399 StringRef CPUName = A->getValue();
2401 CmdArgs.push_back(
"-target-cpu");
2402 CmdArgs.push_back(Args.MakeArgString(CPUName));
2404 if (Arg *A = Args.getLastArg(options::OPT_mregparm_EQ)) {
2405 StringRef
Value = A->getValue();
2409 if (
Value.getAsInteger(10, Mregparm)) {
2410 if (Mregparm != 4) {
2412 diag::err_drv_unsupported_option_argument)
2413 << A->getSpelling() <<
Value;
2419void Clang::AddWebAssemblyTargetArgs(
const ArgList &Args,
2420 ArgStringList &CmdArgs)
const {
2422 if (!Args.hasArg(options::OPT_fvisibility_EQ,
2423 options::OPT_fvisibility_ms_compat))
2424 CmdArgs.push_back(
"-fvisibility=hidden");
2427void Clang::AddVETargetArgs(
const ArgList &Args, ArgStringList &CmdArgs)
const {
2429 CmdArgs.push_back(
"-mfloat-abi");
2430 CmdArgs.push_back(
"hard");
2435 const InputInfo &Input,
const ArgList &Args)
const {
2437 if (
C.getArgs().hasArg(options::OPT__HASH_HASH_HASH))
2440 using llvm::yaml::escape;
2443 if (!CompilationDatabase) {
2445 auto File = std::make_unique<llvm::raw_fd_ostream>(
2447 llvm::sys::fs::OF_TextWithCRLF | llvm::sys::fs::OF_Append);
2449 D.Diag(clang::diag::err_drv_compilationdatabase) <<
Filename
2453 CompilationDatabase = std::move(
File);
2455 auto &CDB = *CompilationDatabase;
2456 auto CWD =
D.getVFS().getCurrentWorkingDirectory();
2459 CDB <<
"{ \"directory\": \"" << escape(*CWD) <<
"\"";
2460 CDB <<
", \"file\": \"" << escape(Input.
getFilename()) <<
"\"";
2462 CDB <<
", \"output\": \"" << escape(Output.
getFilename()) <<
"\"";
2463 CDB <<
", \"arguments\": [\"" << escape(
D.ClangExecutable) <<
"\"";
2467 CDB <<
", \"" << escape(Buf) <<
"\"";
2468 if (!
D.SysRoot.empty() && !Args.hasArg(options::OPT__sysroot_EQ)) {
2471 CDB <<
", \"" << escape(Buf) <<
"\"";
2473 CDB <<
", \"" << escape(Input.
getFilename()) <<
"\"";
2475 CDB <<
", \"-o\", \"" << escape(Output.
getFilename()) <<
"\"";
2476 for (
auto &A: Args) {
2477 auto &O = A->getOption();
2479 if (O.getID() == options::OPT_x)
2482 if (O.getGroup().isValid() && O.getGroup().getID() == options::OPT_M_Group)
2484 if (O.getID() == options::OPT_gen_cdb_fragment_path)
2487 if (O.getKind() == Option::InputClass)
2490 if (O.getID() == options::OPT_o)
2494 A->render(Args, ASL);
2496 CDB <<
", \"" << escape(it) <<
"\"";
2500 CDB <<
", \"" << escape(Buf) <<
"\"]},\n";
2503void Clang::DumpCompilationDatabaseFragmentToDir(
2505 const InputInfo &Input,
const llvm::opt::ArgList &Args)
const {
2507 if (
C.getArgs().hasArg(options::OPT__HASH_HASH_HASH))
2510 if (CompilationDatabase)
2511 DumpCompilationDatabase(
C,
"",
Target, Output, Input, Args);
2514 const auto &
Driver =
C.getDriver();
2516 auto Err = llvm::sys::fs::create_directory(
Path,
true);
2518 Driver.
Diag(diag::err_drv_compilationdatabase) << Dir << Err.message();
2522 llvm::sys::path::append(
2524 Twine(llvm::sys::path::filename(Input.
getFilename())) +
".%%%%.json");
2527 Err = llvm::sys::fs::createUniqueFile(
Path, FD, TempPath,
2528 llvm::sys::fs::OF_Text);
2530 Driver.
Diag(diag::err_drv_compilationdatabase) <<
Path << Err.message();
2533 CompilationDatabase =
2534 std::make_unique<llvm::raw_fd_ostream>(FD,
true);
2535 DumpCompilationDatabase(
C,
"",
Target, Output, Input, Args);
2545 CmdArgs.push_back(
"-mllvm");
2546 CmdArgs.push_back(Args.MakeArgString(
"-arm-implicit-it=" +
Value));
2550 const ArgList &Args,
2551 ArgStringList &CmdArgs,
2561 Args.addOptInFlag(CmdArgs, options::OPT_mrelax_all,
2562 options::OPT_mno_relax_all);
2566 bool DefaultIncrementalLinkerCompatible =
2567 C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment();
2568 if (Args.hasFlag(options::OPT_mincremental_linker_compatible,
2569 options::OPT_mno_incremental_linker_compatible,
2570 DefaultIncrementalLinkerCompatible))
2571 CmdArgs.push_back(
"-mincremental-linker-compatible");
2573 Args.AddLastArg(CmdArgs, options::OPT_femit_dwarf_unwind_EQ);
2575 Args.addOptInFlag(CmdArgs, options::OPT_femit_compact_unwind_non_canonical,
2576 options::OPT_fno_emit_compact_unwind_non_canonical);
2586 bool TakeNextArg =
false;
2588 const llvm::Triple &Triple =
C.getDefaultToolChain().getTriple();
2589 bool IsELF = Triple.isOSBinFormatELF();
2590 bool Crel =
false, ExperimentalCrel =
false;
2591 bool ImplicitMapSyms =
false;
2592 bool UseRelaxRelocations =
C.getDefaultToolChain().useRelaxRelocations();
2593 bool UseNoExecStack =
false;
2595 const char *MipsTargetFeature =
nullptr;
2596 StringRef ImplicitIt;
2598 Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler,
2599 options::OPT_mimplicit_it_EQ)) {
2602 if (A->getOption().getID() == options::OPT_mimplicit_it_EQ) {
2603 switch (
C.getDefaultToolChain().getArch()) {
2604 case llvm::Triple::arm:
2605 case llvm::Triple::armeb:
2606 case llvm::Triple::thumb:
2607 case llvm::Triple::thumbeb:
2609 ImplicitIt = A->getValue();
2611 D.Diag(diag::err_drv_unsupported_option_argument)
2612 << A->getSpelling() << ImplicitIt;
2619 for (StringRef
Value : A->getValues()) {
2621 CmdArgs.push_back(
Value.data());
2622 TakeNextArg =
false;
2626 if (
C.getDefaultToolChain().getTriple().isOSBinFormatCOFF() &&
2627 Value ==
"-mbig-obj")
2631 auto checkArg = [&](
bool ValidTarget,
2632 std::initializer_list<const char *>
Set) {
2634 D.Diag(diag::err_drv_unsupported_opt_for_target)
2635 << (Twine(
"-Wa,") +
Equal.first +
"=").str()
2636 << Triple.getTriple();
2637 }
else if (!llvm::is_contained(
Set,
Equal.second)) {
2638 D.Diag(diag::err_drv_unsupported_option_argument)
2639 << (Twine(
"-Wa,") +
Equal.first +
"=").str() <<
Equal.second;
2642 switch (
C.getDefaultToolChain().getArch()) {
2645 case llvm::Triple::x86:
2646 case llvm::Triple::x86_64:
2647 if (
Equal.first ==
"-mrelax-relocations" ||
2648 Equal.first ==
"--mrelax-relocations") {
2649 UseRelaxRelocations =
Equal.second ==
"yes";
2650 checkArg(IsELF, {
"yes",
"no"});
2653 if (
Value ==
"-msse2avx") {
2654 CmdArgs.push_back(
"-msse2avx");
2658 case llvm::Triple::wasm32:
2659 case llvm::Triple::wasm64:
2660 if (
Value ==
"--no-type-check") {
2661 CmdArgs.push_back(
"-mno-type-check");
2665 case llvm::Triple::thumb:
2666 case llvm::Triple::thumbeb:
2667 case llvm::Triple::arm:
2668 case llvm::Triple::armeb:
2669 if (
Equal.first ==
"-mimplicit-it") {
2671 ImplicitIt =
Equal.second;
2672 checkArg(
true, {
"always",
"never",
"arm",
"thumb"});
2675 if (
Value ==
"-mthumb")
2680 case llvm::Triple::aarch64:
2681 case llvm::Triple::aarch64_be:
2682 case llvm::Triple::aarch64_32:
2683 if (
Equal.first ==
"-mmapsyms") {
2684 ImplicitMapSyms =
Equal.second ==
"implicit";
2685 checkArg(IsELF, {
"default",
"implicit"});
2689 case llvm::Triple::mips:
2690 case llvm::Triple::mipsel:
2691 case llvm::Triple::mips64:
2692 case llvm::Triple::mips64el:
2693 if (
Value ==
"--trap") {
2694 CmdArgs.push_back(
"-target-feature");
2695 CmdArgs.push_back(
"+use-tcc-in-div");
2698 if (
Value ==
"--break") {
2699 CmdArgs.push_back(
"-target-feature");
2700 CmdArgs.push_back(
"-use-tcc-in-div");
2703 if (
Value.starts_with(
"-msoft-float")) {
2704 CmdArgs.push_back(
"-target-feature");
2705 CmdArgs.push_back(
"+soft-float");
2708 if (
Value.starts_with(
"-mhard-float")) {
2709 CmdArgs.push_back(
"-target-feature");
2710 CmdArgs.push_back(
"-soft-float");
2713 if (
Value ==
"-mmsa") {
2717 if (
Value ==
"-mno-msa") {
2721 MipsTargetFeature = llvm::StringSwitch<const char *>(
Value)
2722 .Case(
"-mips1",
"+mips1")
2723 .Case(
"-mips2",
"+mips2")
2724 .Case(
"-mips3",
"+mips3")
2725 .Case(
"-mips4",
"+mips4")
2726 .Case(
"-mips5",
"+mips5")
2727 .Case(
"-mips32",
"+mips32")
2728 .Case(
"-mips32r2",
"+mips32r2")
2729 .Case(
"-mips32r3",
"+mips32r3")
2730 .Case(
"-mips32r5",
"+mips32r5")
2731 .Case(
"-mips32r6",
"+mips32r6")
2732 .Case(
"-mips64",
"+mips64")
2733 .Case(
"-mips64r2",
"+mips64r2")
2734 .Case(
"-mips64r3",
"+mips64r3")
2735 .Case(
"-mips64r5",
"+mips64r5")
2736 .Case(
"-mips64r6",
"+mips64r6")
2738 if (MipsTargetFeature)
2743 if (
Value ==
"-force_cpusubtype_ALL") {
2745 }
else if (
Value ==
"-L") {
2746 CmdArgs.push_back(
"-msave-temp-labels");
2747 }
else if (
Value ==
"--fatal-warnings") {
2748 CmdArgs.push_back(
"-massembler-fatal-warnings");
2749 }
else if (
Value ==
"--no-warn" ||
Value ==
"-W") {
2750 CmdArgs.push_back(
"-massembler-no-warn");
2751 }
else if (
Value ==
"--noexecstack") {
2752 UseNoExecStack =
true;
2753 }
else if (
Value.starts_with(
"-compress-debug-sections") ||
2754 Value.starts_with(
"--compress-debug-sections") ||
2755 Value ==
"-nocompress-debug-sections" ||
2756 Value ==
"--nocompress-debug-sections") {
2757 CmdArgs.push_back(
Value.data());
2758 }
else if (
Value ==
"--crel") {
2760 }
else if (
Value ==
"--no-crel") {
2762 }
else if (
Value ==
"--allow-experimental-crel") {
2763 ExperimentalCrel =
true;
2764 }
else if (
Value.starts_with(
"-I")) {
2765 CmdArgs.push_back(
Value.data());
2770 }
else if (
Value.starts_with(
"-gdwarf-")) {
2773 if (DwarfVersion == 0) {
2774 CmdArgs.push_back(
Value.data());
2777 llvm::codegenoptions::DebugInfoConstructor,
2778 DwarfVersion, llvm::DebuggerKind::Default);
2780 }
else if (
Value.starts_with(
"-mcpu") ||
Value.starts_with(
"-mfpu") ||
2781 Value.starts_with(
"-mhwdiv") ||
Value.starts_with(
"-march")) {
2783 }
else if (
Value ==
"-defsym" ||
Value ==
"--defsym") {
2784 if (A->getNumValues() != 2) {
2785 D.Diag(diag::err_drv_defsym_invalid_format) <<
Value;
2788 const char *S = A->getValue(1);
2789 auto Pair = StringRef(S).split(
'=');
2790 auto Sym = Pair.first;
2791 auto SVal = Pair.second;
2793 if (Sym.empty() || SVal.empty()) {
2794 D.Diag(diag::err_drv_defsym_invalid_format) << S;
2798 if (SVal.getAsInteger(0, IVal)) {
2799 D.Diag(diag::err_drv_defsym_invalid_symval) << SVal;
2802 CmdArgs.push_back(
"--defsym");
2804 }
else if (
Value ==
"-fdebug-compilation-dir") {
2805 CmdArgs.push_back(
"-fdebug-compilation-dir");
2807 }
else if (
Value.consume_front(
"-fdebug-compilation-dir=")) {
2811 CmdArgs.push_back(
"-fdebug-compilation-dir");
2812 CmdArgs.push_back(
Value.data());
2813 }
else if (
Value ==
"--version") {
2814 D.PrintVersion(
C, llvm::outs());
2816 D.Diag(diag::err_drv_unsupported_option_argument)
2817 << A->getSpelling() <<
Value;
2821 if (ImplicitIt.size())
2824 if (!ExperimentalCrel)
2825 D.Diag(diag::err_drv_experimental_crel);
2826 if (Triple.isOSBinFormatELF() && !Triple.isMIPS()) {
2827 CmdArgs.push_back(
"--crel");
2829 D.Diag(diag::err_drv_unsupported_opt_for_target)
2830 <<
"-Wa,--crel" <<
D.getTargetTriple();
2833 if (ImplicitMapSyms)
2834 CmdArgs.push_back(
"-mmapsyms=implicit");
2836 CmdArgs.push_back(
"-mmsa");
2837 if (!UseRelaxRelocations)
2838 CmdArgs.push_back(
"-mrelax-relocations=no");
2840 CmdArgs.push_back(
"-mnoexecstack");
2841 if (MipsTargetFeature !=
nullptr) {
2842 CmdArgs.push_back(
"-target-feature");
2843 CmdArgs.push_back(MipsTargetFeature);
2847 if (
C.getDriver().embedBitcodeEnabled() ||
2848 C.getDriver().embedBitcodeMarkerOnly())
2849 Args.AddLastArg(CmdArgs, options::OPT_fembed_bitcode_EQ);
2851 if (
const char *AsSecureLogFile = getenv(
"AS_SECURE_LOG_FILE")) {
2852 CmdArgs.push_back(
"-as-secure-log-file");
2853 CmdArgs.push_back(Args.MakeArgString(AsSecureLogFile));
2884 if (str1 != str2 && !str2.empty() && !str1.empty()) {
2885 D.Diag(clang::diag::warn_drv_overriding_option) << str1 << str2;
2892 if (!ComplexRangeStr.empty())
2893 return "-complex-range=" + ComplexRangeStr;
2894 return ComplexRangeStr;
2898 bool OFastEnabled,
const ArgList &Args,
2899 ArgStringList &CmdArgs,
2902 constexpr std::array VecLibImpliesNoMathErrno{llvm::StringLiteral(
"ArmPL"),
2903 llvm::StringLiteral(
"SLEEF")};
2904 bool NoMathErrnoWasImpliedByVecLib =
false;
2905 const Arg *VecLibArg =
nullptr;
2907 const Arg *ArgThatEnabledMathErrnoAfterVecLib =
nullptr;
2914 bool HonorINFs =
true;
2915 bool HonorNaNs =
true;
2916 bool ApproxFunc =
false;
2919 bool AssociativeMath =
false;
2920 bool ReciprocalMath =
false;
2921 bool SignedZeros =
true;
2922 bool TrappingMath =
false;
2923 bool TrappingMathPresent =
false;
2925 bool RoundingFPMath =
false;
2927 StringRef FPModel =
"";
2929 StringRef FPExceptionBehavior =
"";
2931 StringRef FPEvalMethod =
"";
2932 llvm::DenormalMode DenormalFPMath =
2934 llvm::DenormalMode DenormalFP32Math =
2939 StringRef FPContract;
2940 StringRef LastSeenFfpContractOption;
2941 StringRef LastFpContractOverrideOption;
2942 bool SeenUnsafeMathModeOption =
false;
2946 bool StrictFPModel =
false;
2947 StringRef Float16ExcessPrecision =
"";
2948 StringRef BFloat16ExcessPrecision =
"";
2950 std::string ComplexRangeStr =
"";
2951 std::string GccRangeComplexOption =
"";
2956 if (
Range != NewRange)
2958 !GccRangeComplexOption.empty()
2959 ? GccRangeComplexOption
2966 auto applyFastMath = [&](
bool Aggressive) {
2977 AssociativeMath =
true;
2978 ReciprocalMath =
true;
2980 SignedZeros =
false;
2981 TrappingMath =
false;
2982 RoundingFPMath =
false;
2983 FPExceptionBehavior =
"";
2984 FPContract =
"fast";
2985 SeenUnsafeMathModeOption =
true;
2989 auto restoreFPContractState = [&]() {
2999 if (LastSeenFfpContractOption !=
"")
3000 FPContract = LastSeenFfpContractOption;
3001 else if (SeenUnsafeMathModeOption)
3006 LastFpContractOverrideOption =
"";
3009 if (
const Arg *A = Args.getLastArg(options::OPT_flimited_precision_EQ)) {
3010 CmdArgs.push_back(
"-mlimit-float-precision");
3011 CmdArgs.push_back(A->getValue());
3014 for (
const Arg *A : Args) {
3015 auto CheckMathErrnoForVecLib =
3016 llvm::make_scope_exit([&, MathErrnoBeforeArg = MathErrno] {
3017 if (NoMathErrnoWasImpliedByVecLib && !MathErrnoBeforeArg && MathErrno)
3018 ArgThatEnabledMathErrnoAfterVecLib = A;
3021 switch (A->getOption().getID()) {
3025 case options::OPT_fcx_limited_range:
3026 if (GccRangeComplexOption.empty()) {
3029 "-fcx-limited-range");
3031 if (GccRangeComplexOption !=
"-fno-cx-limited-range")
3034 GccRangeComplexOption =
"-fcx-limited-range";
3037 case options::OPT_fno_cx_limited_range:
3038 if (GccRangeComplexOption.empty()) {
3040 "-fno-cx-limited-range");
3042 if (GccRangeComplexOption !=
"-fcx-limited-range" &&
3043 GccRangeComplexOption !=
"-fno-cx-fortran-rules")
3045 "-fno-cx-limited-range");
3047 GccRangeComplexOption =
"-fno-cx-limited-range";
3050 case options::OPT_fcx_fortran_rules:
3051 if (GccRangeComplexOption.empty())
3053 "-fcx-fortran-rules");
3056 GccRangeComplexOption =
"-fcx-fortran-rules";
3059 case options::OPT_fno_cx_fortran_rules:
3060 if (GccRangeComplexOption.empty()) {
3062 "-fno-cx-fortran-rules");
3064 if (GccRangeComplexOption !=
"-fno-cx-limited-range")
3066 "-fno-cx-fortran-rules");
3068 GccRangeComplexOption =
"-fno-cx-fortran-rules";
3071 case options::OPT_fcomplex_arithmetic_EQ: {
3073 StringRef Val = A->getValue();
3076 else if (Val ==
"improved")
3078 else if (Val ==
"promoted")
3080 else if (Val ==
"basic")
3083 D.Diag(diag::err_drv_unsupported_option_argument)
3084 << A->getSpelling() << Val;
3087 if (!GccRangeComplexOption.empty()) {
3088 if (GccRangeComplexOption !=
"-fcx-limited-range") {
3089 if (GccRangeComplexOption !=
"-fcx-fortran-rules") {
3106 case options::OPT_ffp_model_EQ: {
3113 AssociativeMath =
false;
3114 ReciprocalMath =
false;
3117 StringRef Val = A->getValue();
3118 if (OFastEnabled && Val !=
"aggressive") {
3120 D.Diag(clang::diag::warn_drv_overriding_option)
3121 << Args.MakeArgString(
"-ffp-model=" + Val) <<
"-Ofast";
3124 StrictFPModel =
false;
3125 if (!FPModel.empty() && FPModel != Val)
3126 D.Diag(clang::diag::warn_drv_overriding_option)
3127 << Args.MakeArgString(
"-ffp-model=" + FPModel)
3128 << Args.MakeArgString(
"-ffp-model=" + Val);
3129 if (Val ==
"fast") {
3131 applyFastMath(
false);
3133 LastFpContractOverrideOption =
"-ffp-model=fast";
3134 }
else if (Val ==
"aggressive") {
3136 applyFastMath(
true);
3138 LastFpContractOverrideOption =
"-ffp-model=aggressive";
3139 }
else if (Val ==
"precise") {
3142 LastFpContractOverrideOption =
"-ffp-model=precise";
3144 }
else if (Val ==
"strict") {
3145 StrictFPModel =
true;
3146 FPExceptionBehavior =
"strict";
3149 LastFpContractOverrideOption =
"-ffp-model=strict";
3150 TrappingMath =
true;
3151 RoundingFPMath =
true;
3154 D.Diag(diag::err_drv_unsupported_option_argument)
3155 << A->getSpelling() << Val;
3160 case options::OPT_fhonor_infinities: HonorINFs =
true;
break;
3161 case options::OPT_fno_honor_infinities: HonorINFs =
false;
break;
3162 case options::OPT_fhonor_nans: HonorNaNs =
true;
break;
3163 case options::OPT_fno_honor_nans: HonorNaNs =
false;
break;
3164 case options::OPT_fapprox_func: ApproxFunc =
true;
break;
3165 case options::OPT_fno_approx_func: ApproxFunc =
false;
break;
3166 case options::OPT_fmath_errno: MathErrno =
true;
break;
3167 case options::OPT_fno_math_errno: MathErrno =
false;
break;
3168 case options::OPT_fassociative_math: AssociativeMath =
true;
break;
3169 case options::OPT_fno_associative_math: AssociativeMath =
false;
break;
3170 case options::OPT_freciprocal_math: ReciprocalMath =
true;
break;
3171 case options::OPT_fno_reciprocal_math: ReciprocalMath =
false;
break;
3172 case options::OPT_fsigned_zeros: SignedZeros =
true;
break;
3173 case options::OPT_fno_signed_zeros: SignedZeros =
false;
break;
3174 case options::OPT_ftrapping_math:
3175 if (!TrappingMathPresent && !FPExceptionBehavior.empty() &&
3176 FPExceptionBehavior !=
"strict")
3178 D.Diag(clang::diag::warn_drv_overriding_option)
3179 << Args.MakeArgString(
"-ffp-exception-behavior=" +
3180 FPExceptionBehavior)
3181 <<
"-ftrapping-math";
3182 TrappingMath =
true;
3183 TrappingMathPresent =
true;
3184 FPExceptionBehavior =
"strict";
3186 case options::OPT_fveclib:
3188 NoMathErrnoWasImpliedByVecLib =
3189 llvm::is_contained(VecLibImpliesNoMathErrno, A->getValue());
3190 if (NoMathErrnoWasImpliedByVecLib)
3193 case options::OPT_fno_trapping_math:
3194 if (!TrappingMathPresent && !FPExceptionBehavior.empty() &&
3195 FPExceptionBehavior !=
"ignore")
3197 D.Diag(clang::diag::warn_drv_overriding_option)
3198 << Args.MakeArgString(
"-ffp-exception-behavior=" +
3199 FPExceptionBehavior)
3200 <<
"-fno-trapping-math";
3201 TrappingMath =
false;
3202 TrappingMathPresent =
true;
3203 FPExceptionBehavior =
"ignore";
3206 case options::OPT_frounding_math:
3207 RoundingFPMath =
true;
3210 case options::OPT_fno_rounding_math:
3211 RoundingFPMath =
false;
3214 case options::OPT_fdenormal_fp_math_EQ:
3215 DenormalFPMath = llvm::parseDenormalFPAttribute(A->getValue());
3216 DenormalFP32Math = DenormalFPMath;
3217 if (!DenormalFPMath.isValid()) {
3218 D.Diag(diag::err_drv_invalid_value)
3219 << A->getAsString(Args) << A->getValue();
3223 case options::OPT_fdenormal_fp_math_f32_EQ:
3224 DenormalFP32Math = llvm::parseDenormalFPAttribute(A->getValue());
3225 if (!DenormalFP32Math.isValid()) {
3226 D.Diag(diag::err_drv_invalid_value)
3227 << A->getAsString(Args) << A->getValue();
3232 case options::OPT_ffp_contract: {
3233 StringRef Val = A->getValue();
3234 if (Val ==
"fast" || Val ==
"on" || Val ==
"off" ||
3235 Val ==
"fast-honor-pragmas") {
3236 if (Val != FPContract && LastFpContractOverrideOption !=
"") {
3237 D.Diag(clang::diag::warn_drv_overriding_option)
3238 << LastFpContractOverrideOption
3239 << Args.MakeArgString(
"-ffp-contract=" + Val);
3243 LastSeenFfpContractOption = Val;
3244 LastFpContractOverrideOption =
"";
3246 D.Diag(diag::err_drv_unsupported_option_argument)
3247 << A->getSpelling() << Val;
3252 case options::OPT_ffp_exception_behavior_EQ: {
3253 StringRef Val = A->getValue();
3254 if (!TrappingMathPresent && !FPExceptionBehavior.empty() &&
3255 FPExceptionBehavior != Val)
3257 D.Diag(clang::diag::warn_drv_overriding_option)
3258 << Args.MakeArgString(
"-ffp-exception-behavior=" +
3259 FPExceptionBehavior)
3260 << Args.MakeArgString(
"-ffp-exception-behavior=" + Val);
3261 TrappingMath = TrappingMathPresent =
false;
3262 if (Val ==
"ignore" || Val ==
"maytrap")
3263 FPExceptionBehavior = Val;
3264 else if (Val ==
"strict") {
3265 FPExceptionBehavior = Val;
3266 TrappingMath = TrappingMathPresent =
true;
3268 D.Diag(diag::err_drv_unsupported_option_argument)
3269 << A->getSpelling() << Val;
3274 case options::OPT_ffp_eval_method_EQ: {
3275 StringRef Val = A->getValue();
3276 if (Val ==
"double" || Val ==
"extended" || Val ==
"source")
3279 D.Diag(diag::err_drv_unsupported_option_argument)
3280 << A->getSpelling() << Val;
3284 case options::OPT_fexcess_precision_EQ: {
3285 StringRef Val = A->getValue();
3286 const llvm::Triple::ArchType Arch = TC.
getArch();
3287 if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) {
3288 if (Val ==
"standard" || Val ==
"fast")
3289 Float16ExcessPrecision = Val;
3293 else if (Val ==
"16")
3294 Float16ExcessPrecision =
"none";
3296 D.Diag(diag::err_drv_unsupported_option_argument)
3297 << A->getSpelling() << Val;
3299 if (!(Val ==
"standard" || Val ==
"fast"))
3300 D.Diag(diag::err_drv_unsupported_option_argument)
3301 << A->getSpelling() << Val;
3303 BFloat16ExcessPrecision = Float16ExcessPrecision;
3306 case options::OPT_ffinite_math_only:
3310 case options::OPT_fno_finite_math_only:
3315 case options::OPT_funsafe_math_optimizations:
3316 AssociativeMath =
true;
3317 ReciprocalMath =
true;
3318 SignedZeros =
false;
3320 TrappingMath =
false;
3321 FPExceptionBehavior =
"";
3322 FPContract =
"fast";
3323 LastFpContractOverrideOption =
"-funsafe-math-optimizations";
3324 SeenUnsafeMathModeOption =
true;
3326 case options::OPT_fno_unsafe_math_optimizations:
3327 AssociativeMath =
false;
3328 ReciprocalMath =
false;
3331 restoreFPContractState();
3334 case options::OPT_Ofast:
3339 case options::OPT_ffast_math:
3340 applyFastMath(
true);
3341 if (A->getOption().getID() == options::OPT_Ofast)
3342 LastFpContractOverrideOption =
"-Ofast";
3344 LastFpContractOverrideOption =
"-ffast-math";
3346 case options::OPT_fno_fast_math:
3353 AssociativeMath =
false;
3354 ReciprocalMath =
false;
3357 restoreFPContractState();
3358 LastFpContractOverrideOption =
"";
3368 if (StrictFPModel) {
3371 if (HonorINFs && HonorNaNs && !AssociativeMath && !ReciprocalMath &&
3372 SignedZeros && TrappingMath && RoundingFPMath && !ApproxFunc &&
3373 FPContract ==
"off")
3377 StrictFPModel =
false;
3382 auto RHS = (A->getNumValues() == 0)
3384 : Args.MakeArgString(A->getSpelling() + A->getValue());
3385 if (A->getSpelling() !=
"-ffp-contract=") {
3386 if (RHS !=
"-ffp-model=strict")
3387 D.Diag(clang::diag::warn_drv_overriding_option)
3388 <<
"-ffp-model=strict" << RHS;
3398 CmdArgs.push_back(
"-menable-no-infs");
3401 CmdArgs.push_back(
"-menable-no-nans");
3404 CmdArgs.push_back(
"-fapprox-func");
3407 CmdArgs.push_back(
"-fmath-errno");
3408 if (NoMathErrnoWasImpliedByVecLib)
3409 D.Diag(clang::diag::warn_drv_math_errno_enabled_after_veclib)
3410 << ArgThatEnabledMathErrnoAfterVecLib->getAsString(Args)
3411 << VecLibArg->getAsString(Args);
3414 if (AssociativeMath && ReciprocalMath && !SignedZeros && ApproxFunc &&
3416 CmdArgs.push_back(
"-funsafe-math-optimizations");
3419 CmdArgs.push_back(
"-fno-signed-zeros");
3421 if (AssociativeMath && !SignedZeros && !TrappingMath)
3422 CmdArgs.push_back(
"-mreassociate");
3425 CmdArgs.push_back(
"-freciprocal-math");
3429 assert(FPExceptionBehavior ==
"strict");
3433 if (DenormalFPMath != llvm::DenormalMode::getIEEE()) {
3435 llvm::raw_svector_ostream ArgStr(DenormFlag);
3436 ArgStr <<
"-fdenormal-fp-math=" << DenormalFPMath;
3437 CmdArgs.push_back(Args.MakeArgString(ArgStr.str()));
3441 if (DenormalFP32Math != DenormalFPMath) {
3443 llvm::raw_svector_ostream ArgStr(DenormFlag);
3444 ArgStr <<
"-fdenormal-fp-math-f32=" << DenormalFP32Math;
3445 CmdArgs.push_back(Args.MakeArgString(ArgStr.str()));
3448 if (!FPContract.empty())
3449 CmdArgs.push_back(Args.MakeArgString(
"-ffp-contract=" + FPContract));
3452 CmdArgs.push_back(Args.MakeArgString(
"-frounding-math"));
3454 CmdArgs.push_back(Args.MakeArgString(
"-fno-rounding-math"));
3456 if (!FPExceptionBehavior.empty())
3457 CmdArgs.push_back(Args.MakeArgString(
"-ffp-exception-behavior=" +
3458 FPExceptionBehavior));
3460 if (!FPEvalMethod.empty())
3461 CmdArgs.push_back(Args.MakeArgString(
"-ffp-eval-method=" + FPEvalMethod));
3463 if (!Float16ExcessPrecision.empty())
3464 CmdArgs.push_back(Args.MakeArgString(
"-ffloat16-excess-precision=" +
3465 Float16ExcessPrecision));
3466 if (!BFloat16ExcessPrecision.empty())
3467 CmdArgs.push_back(Args.MakeArgString(
"-fbfloat16-excess-precision=" +
3468 BFloat16ExcessPrecision));
3475 if (!HonorINFs && !HonorNaNs && !MathErrno && AssociativeMath && ApproxFunc &&
3476 ReciprocalMath && !SignedZeros && !TrappingMath && !RoundingFPMath)
3477 CmdArgs.push_back(
"-ffast-math");
3483 bool shouldAddFiniteMathOnly =
false;
3484 if (!HonorINFs && !HonorNaNs) {
3485 shouldAddFiniteMathOnly =
true;
3487 bool InfValues =
true;
3488 bool NanValues =
true;
3489 for (
const auto *Arg : Args.filtered(options::OPT_Xclang)) {
3490 StringRef ArgValue = Arg->getValue();
3491 if (ArgValue ==
"-menable-no-nans")
3493 else if (ArgValue ==
"-menable-no-infs")
3496 if (!NanValues && !InfValues)
3497 shouldAddFiniteMathOnly =
true;
3499 if (shouldAddFiniteMathOnly) {
3500 CmdArgs.push_back(
"-ffinite-math-only");
3502 if (
const Arg *A = Args.getLastArg(options::OPT_mfpmath_EQ)) {
3503 CmdArgs.push_back(
"-mfpmath");
3504 CmdArgs.push_back(A->getValue());
3508 if (Args.hasFlag(options::OPT_fno_strict_float_cast_overflow,
3509 options::OPT_fstrict_float_cast_overflow,
false))
3510 CmdArgs.push_back(
"-fno-strict-float-cast-overflow");
3514 if (!ComplexRangeStr.empty()) {
3515 CmdArgs.push_back(Args.MakeArgString(ComplexRangeStr));
3516 if (Args.hasArg(options::OPT_fcomplex_arithmetic_EQ))
3517 CmdArgs.push_back(Args.MakeArgString(
"-fcomplex-arithmetic=" +
3520 if (Args.hasArg(options::OPT_fcx_limited_range))
3521 CmdArgs.push_back(
"-fcx-limited-range");
3522 if (Args.hasArg(options::OPT_fcx_fortran_rules))
3523 CmdArgs.push_back(
"-fcx-fortran-rules");
3524 if (Args.hasArg(options::OPT_fno_cx_limited_range))
3525 CmdArgs.push_back(
"-fno-cx-limited-range");
3526 if (Args.hasArg(options::OPT_fno_cx_fortran_rules))
3527 CmdArgs.push_back(
"-fno-cx-fortran-rules");
3531 const llvm::Triple &Triple,
3534 if (!Args.hasArg(options::OPT__analyzer_no_default_checks)) {
3535 CmdArgs.push_back(
"-analyzer-checker=core");
3536 CmdArgs.push_back(
"-analyzer-checker=apiModeling");
3538 if (!Triple.isWindowsMSVCEnvironment()) {
3539 CmdArgs.push_back(
"-analyzer-checker=unix");
3542 CmdArgs.push_back(
"-analyzer-checker=unix.API");
3543 CmdArgs.push_back(
"-analyzer-checker=unix.Malloc");
3544 CmdArgs.push_back(
"-analyzer-checker=unix.MallocSizeof");
3545 CmdArgs.push_back(
"-analyzer-checker=unix.MismatchedDeallocator");
3546 CmdArgs.push_back(
"-analyzer-checker=unix.cstring.BadSizeArg");
3547 CmdArgs.push_back(
"-analyzer-checker=unix.cstring.NullArg");
3551 if (Triple.isPS()) {
3552 CmdArgs.push_back(
"-analyzer-disable-checker=unix.API");
3553 CmdArgs.push_back(
"-analyzer-disable-checker=unix.Vfork");
3556 if (Triple.isOSDarwin()) {
3557 CmdArgs.push_back(
"-analyzer-checker=osx");
3559 "-analyzer-checker=security.insecureAPI.decodeValueOfObjCType");
3561 else if (Triple.isOSFuchsia())
3562 CmdArgs.push_back(
"-analyzer-checker=fuchsia");
3564 CmdArgs.push_back(
"-analyzer-checker=deadcode");
3567 CmdArgs.push_back(
"-analyzer-checker=cplusplus");
3569 if (!Triple.isPS()) {
3570 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.UncheckedReturn");
3571 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.getpw");
3572 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.gets");
3573 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.mktemp");
3574 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.mkstemp");
3575 CmdArgs.push_back(
"-analyzer-checker=security.insecureAPI.vfork");
3579 CmdArgs.push_back(
"-analyzer-checker=nullability.NullPassedToNonnull");
3580 CmdArgs.push_back(
"-analyzer-checker=nullability.NullReturnedFromNonnull");
3584 CmdArgs.push_back(
"-analyzer-output");
3585 if (Arg *A = Args.getLastArg(options::OPT__analyzer_output))
3586 CmdArgs.push_back(A->getValue());
3588 CmdArgs.push_back(
"plist");
3593 CmdArgs.push_back(
"-w");
3596 Args.AddAllArgValues(CmdArgs, options::OPT_Xanalyzer);
3603 if (std::isdigit(S[0]))
3606 return llvm::all_of(S, [](
char C) {
return std::isalnum(
C) ||
C ==
'_'; });
3610 const ArgList &Args, ArgStringList &CmdArgs,
3611 bool KernelOrKext) {
3616 if (EffectiveTriple.isNVPTX())
3624 if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector,
3625 options::OPT_fstack_protector_all,
3626 options::OPT_fstack_protector_strong,
3627 options::OPT_fstack_protector)) {
3628 if (A->getOption().matches(options::OPT_fstack_protector))
3629 StackProtectorLevel =
3631 else if (A->getOption().matches(options::OPT_fstack_protector_strong))
3633 else if (A->getOption().matches(options::OPT_fstack_protector_all))
3637 D.Diag(diag::warn_drv_unsupported_option_for_target)
3638 << A->getSpelling() << EffectiveTriple.getTriple();
3639 StackProtectorLevel = DefaultStackProtectorLevel;
3642 StackProtectorLevel = DefaultStackProtectorLevel;
3645 if (StackProtectorLevel) {
3646 CmdArgs.push_back(
"-stack-protector");
3647 CmdArgs.push_back(Args.MakeArgString(Twine(StackProtectorLevel)));
3651 for (
const Arg *A : Args.filtered(options::OPT__param)) {
3652 StringRef Str(A->getValue());
3653 if (Str.starts_with(
"ssp-buffer-size=")) {
3654 if (StackProtectorLevel) {
3655 CmdArgs.push_back(
"-stack-protector-buffer-size");
3657 CmdArgs.push_back(Args.MakeArgString(Str.drop_front(16)));
3663 const std::string &TripleStr = EffectiveTriple.getTriple();
3664 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_EQ)) {
3665 StringRef
Value = A->getValue();
3666 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
3667 !EffectiveTriple.isARM() && !EffectiveTriple.isThumb() &&
3668 !EffectiveTriple.isRISCV() && !EffectiveTriple.isPPC())
3669 D.Diag(diag::err_drv_unsupported_opt_for_target)
3670 << A->getAsString(Args) << TripleStr;
3671 if ((EffectiveTriple.isX86() || EffectiveTriple.isARM() ||
3672 EffectiveTriple.isThumb()) &&
3674 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3675 << A->getOption().getName() <<
Value <<
"tls global";
3678 if ((EffectiveTriple.isARM() || EffectiveTriple.isThumb()) &&
3680 if (!Args.hasArg(options::OPT_mstack_protector_guard_offset_EQ)) {
3681 D.Diag(diag::err_drv_ssp_missing_offset_argument)
3682 << A->getAsString(Args);
3687 D.Diag(diag::err_target_unsupported_tp_hard)
3688 << EffectiveTriple.getArchName();
3692 if (Arg *A = Args.getLastArg(options::OPT_mtp_mode_EQ)) {
3693 StringRef
Value = A->getValue();
3694 if (
Value !=
"cp15") {
3695 D.Diag(diag::err_drv_argument_not_allowed_with)
3696 << A->getAsString(Args) <<
"-mstack-protector-guard=tls";
3700 CmdArgs.push_back(
"-target-feature");
3701 CmdArgs.push_back(
"+read-tp-tpidruro");
3703 if (EffectiveTriple.isAArch64() &&
Value !=
"sysreg" &&
Value !=
"global") {
3704 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3705 << A->getOption().getName() <<
Value <<
"sysreg global";
3708 if (EffectiveTriple.isRISCV() || EffectiveTriple.isPPC()) {
3710 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3711 << A->getOption().getName() <<
Value <<
"tls global";
3714 if (
Value ==
"tls") {
3715 if (!Args.hasArg(options::OPT_mstack_protector_guard_offset_EQ)) {
3716 D.Diag(diag::err_drv_ssp_missing_offset_argument)
3717 << A->getAsString(Args);
3722 A->render(Args, CmdArgs);
3725 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_offset_EQ)) {
3726 StringRef
Value = A->getValue();
3727 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
3728 !EffectiveTriple.isARM() && !EffectiveTriple.isThumb() &&
3729 !EffectiveTriple.isRISCV() && !EffectiveTriple.isPPC())
3730 D.Diag(diag::err_drv_unsupported_opt_for_target)
3731 << A->getAsString(Args) << TripleStr;
3733 if (
Value.getAsInteger(10, Offset)) {
3734 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() <<
Value;
3737 if ((EffectiveTriple.isARM() || EffectiveTriple.isThumb()) &&
3738 (Offset < 0 || Offset > 0xfffff)) {
3739 D.Diag(diag::err_drv_invalid_int_value)
3740 << A->getOption().getName() <<
Value;
3743 A->render(Args, CmdArgs);
3746 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_reg_EQ)) {
3747 StringRef
Value = A->getValue();
3748 if (!EffectiveTriple.isX86() && !EffectiveTriple.isAArch64() &&
3749 !EffectiveTriple.isRISCV() && !EffectiveTriple.isPPC())
3750 D.Diag(diag::err_drv_unsupported_opt_for_target)
3751 << A->getAsString(Args) << TripleStr;
3752 if (EffectiveTriple.isX86() && (
Value !=
"fs" &&
Value !=
"gs")) {
3753 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3754 << A->getOption().getName() <<
Value <<
"fs gs";
3757 if (EffectiveTriple.isAArch64() &&
Value !=
"sp_el0") {
3758 D.Diag(diag::err_drv_invalid_value) << A->getOption().getName() <<
Value;
3761 if (EffectiveTriple.isRISCV() &&
Value !=
"tp") {
3762 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3763 << A->getOption().getName() <<
Value <<
"tp";
3766 if (EffectiveTriple.isPPC64() &&
Value !=
"r13") {
3767 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3768 << A->getOption().getName() <<
Value <<
"r13";
3771 if (EffectiveTriple.isPPC32() &&
Value !=
"r2") {
3772 D.Diag(diag::err_drv_invalid_value_with_suggestion)
3773 << A->getOption().getName() <<
Value <<
"r2";
3776 A->render(Args, CmdArgs);
3779 if (Arg *A = Args.getLastArg(options::OPT_mstack_protector_guard_symbol_EQ)) {
3780 StringRef
Value = A->getValue();
3782 D.Diag(diag::err_drv_argument_only_allowed_with)
3783 << A->getOption().getName() <<
"legal symbol name";
3786 A->render(Args, CmdArgs);
3791 ArgStringList &CmdArgs) {
3794 if (!EffectiveTriple.isOSFreeBSD() && !EffectiveTriple.isOSLinux() &&
3795 !EffectiveTriple.isOSFuchsia())
3798 if (!EffectiveTriple.isX86() && !EffectiveTriple.isSystemZ() &&
3799 !EffectiveTriple.isPPC64() && !EffectiveTriple.isAArch64() &&
3800 !EffectiveTriple.isRISCV())
3803 Args.addOptInFlag(CmdArgs, options::OPT_fstack_clash_protection,
3804 options::OPT_fno_stack_clash_protection);
3809 const ArgList &Args,
3810 ArgStringList &CmdArgs) {
3812 StringRef TrivialAutoVarInit =
"";
3814 for (
const Arg *A : Args) {
3815 switch (A->getOption().getID()) {
3818 case options::OPT_ftrivial_auto_var_init: {
3820 StringRef Val = A->getValue();
3821 if (Val ==
"uninitialized" || Val ==
"zero" || Val ==
"pattern")
3822 TrivialAutoVarInit = Val;
3824 D.Diag(diag::err_drv_unsupported_option_argument)
3825 << A->getSpelling() << Val;
3831 if (TrivialAutoVarInit.empty())
3832 switch (DefaultTrivialAutoVarInit) {
3836 TrivialAutoVarInit =
"pattern";
3839 TrivialAutoVarInit =
"zero";
3843 if (!TrivialAutoVarInit.empty()) {
3845 Args.MakeArgString(
"-ftrivial-auto-var-init=" + TrivialAutoVarInit));
3849 Args.getLastArg(options::OPT_ftrivial_auto_var_init_stop_after)) {
3850 if (!Args.hasArg(options::OPT_ftrivial_auto_var_init) ||
3852 Args.getLastArg(options::OPT_ftrivial_auto_var_init)->getValue()) ==
3854 D.Diag(diag::err_drv_trivial_auto_var_init_stop_after_missing_dependency);
3856 StringRef Val = A->getValue();
3857 if (std::stoi(Val.str()) <= 0)
3858 D.Diag(diag::err_drv_trivial_auto_var_init_stop_after_invalid_value);
3860 Args.MakeArgString(
"-ftrivial-auto-var-init-stop-after=" + Val));
3863 if (Arg *A = Args.getLastArg(options::OPT_ftrivial_auto_var_init_max_size)) {
3864 if (!Args.hasArg(options::OPT_ftrivial_auto_var_init) ||
3866 Args.getLastArg(options::OPT_ftrivial_auto_var_init)->getValue()) ==
3868 D.Diag(diag::err_drv_trivial_auto_var_init_max_size_missing_dependency);
3870 StringRef Val = A->getValue();
3871 if (std::stoi(Val.str()) <= 0)
3872 D.Diag(diag::err_drv_trivial_auto_var_init_max_size_invalid_value);
3874 Args.MakeArgString(
"-ftrivial-auto-var-init-max-size=" + Val));
3882 const unsigned ForwardedArguments[] = {
3883 options::OPT_cl_opt_disable,
3884 options::OPT_cl_strict_aliasing,
3885 options::OPT_cl_single_precision_constant,
3886 options::OPT_cl_finite_math_only,
3887 options::OPT_cl_kernel_arg_info,
3888 options::OPT_cl_unsafe_math_optimizations,
3889 options::OPT_cl_fast_relaxed_math,
3890 options::OPT_cl_mad_enable,
3891 options::OPT_cl_no_signed_zeros,
3892 options::OPT_cl_fp32_correctly_rounded_divide_sqrt,
3893 options::OPT_cl_uniform_work_group_size
3896 if (Arg *A = Args.getLastArg(options::OPT_cl_std_EQ)) {
3897 std::string CLStdStr = std::string(
"-cl-std=") + A->getValue();
3898 CmdArgs.push_back(Args.MakeArgString(CLStdStr));
3899 }
else if (Arg *A = Args.getLastArg(options::OPT_cl_ext_EQ)) {
3900 std::string CLExtStr = std::string(
"-cl-ext=") + A->getValue();
3901 CmdArgs.push_back(Args.MakeArgString(CLExtStr));
3904 if (Args.hasArg(options::OPT_cl_finite_math_only)) {
3905 CmdArgs.push_back(
"-menable-no-infs");
3906 CmdArgs.push_back(
"-menable-no-nans");
3909 for (
const auto &Arg : ForwardedArguments)
3910 if (
const auto *A = Args.getLastArg(Arg))
3911 CmdArgs.push_back(Args.MakeArgString(A->getOption().getPrefixedName()));
3916 !Args.hasArg(options::OPT_cl_no_stdinc)) {
3917 CmdArgs.push_back(
"-finclude-default-header");
3918 CmdArgs.push_back(
"-fdeclare-opencl-builtins");
3924 const unsigned ForwardedArguments[] = {options::OPT_dxil_validator_version,
3928 options::OPT_emit_llvm,
3929 options::OPT_emit_obj,
3930 options::OPT_disable_llvm_passes,
3931 options::OPT_fnative_half_type,
3932 options::OPT_hlsl_entrypoint};
3935 for (
const auto &Arg : ForwardedArguments)
3936 if (
const auto *A = Args.getLastArg(Arg))
3937 A->renderAsInput(Args, CmdArgs);
3939 if (!Args.hasArg(options::OPT_dxc_no_stdinc) &&
3940 !Args.hasArg(options::OPT_nostdinc))
3941 CmdArgs.push_back(
"-finclude-default-header");
3945 ArgStringList &CmdArgs,
types::ID InputType) {
3946 if (!Args.hasArg(options::OPT_fopenacc))
3949 CmdArgs.push_back(
"-fopenacc");
3951 if (Arg *A = Args.getLastArg(options::OPT_openacc_macro_override)) {
3952 StringRef
Value = A->getValue();
3954 if (!
Value.getAsInteger(10, Version))
3955 A->renderAsInput(Args, CmdArgs);
3957 D.Diag(diag::err_drv_clang_unsupported) <<
Value;
3962 ArgStringList &CmdArgs) {
3963 bool ARCMTEnabled =
false;
3964 if (!Args.hasArg(options::OPT_fno_objc_arc, options::OPT_fobjc_arc)) {
3965 if (
const Arg *A = Args.getLastArg(options::OPT_ccc_arcmt_check,
3966 options::OPT_ccc_arcmt_modify,
3967 options::OPT_ccc_arcmt_migrate)) {
3968 ARCMTEnabled =
true;
3969 switch (A->getOption().getID()) {
3970 default: llvm_unreachable(
"missed a case");
3971 case options::OPT_ccc_arcmt_check:
3972 CmdArgs.push_back(
"-arcmt-action=check");
3974 case options::OPT_ccc_arcmt_modify:
3975 CmdArgs.push_back(
"-arcmt-action=modify");
3977 case options::OPT_ccc_arcmt_migrate:
3978 CmdArgs.push_back(
"-arcmt-action=migrate");
3979 CmdArgs.push_back(
"-mt-migrate-directory");
3980 CmdArgs.push_back(A->getValue());
3982 Args.AddLastArg(CmdArgs, options::OPT_arcmt_migrate_report_output);
3983 Args.AddLastArg(CmdArgs, options::OPT_arcmt_migrate_emit_arc_errors);
3988 Args.ClaimAllArgs(options::OPT_ccc_arcmt_check);
3989 Args.ClaimAllArgs(options::OPT_ccc_arcmt_modify);
3990 Args.ClaimAllArgs(options::OPT_ccc_arcmt_migrate);
3993 if (
const Arg *A = Args.getLastArg(options::OPT_ccc_objcmt_migrate)) {
3995 D.Diag(diag::err_drv_argument_not_allowed_with)
3996 << A->getAsString(Args) <<
"-ccc-arcmt-migrate";
3998 CmdArgs.push_back(
"-mt-migrate-directory");
3999 CmdArgs.push_back(A->getValue());
4001 if (!Args.hasArg(options::OPT_objcmt_migrate_literals,
4002 options::OPT_objcmt_migrate_subscripting,
4003 options::OPT_objcmt_migrate_property)) {
4005 CmdArgs.push_back(
"-objcmt-migrate-literals");
4006 CmdArgs.push_back(
"-objcmt-migrate-subscripting");
4007 CmdArgs.push_back(
"-objcmt-migrate-property");
4009 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_literals);
4010 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_subscripting);
4011 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_property);
4014 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_literals);
4015 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_subscripting);
4016 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_property);
4017 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_all);
4018 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_readonly_property);
4019 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_readwrite_property);
4020 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_property_dot_syntax);
4021 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_annotation);
4022 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_instancetype);
4023 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_nsmacros);
4024 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_protocol_conformance);
4025 Args.AddLastArg(CmdArgs, options::OPT_objcmt_atomic_property);
4026 Args.AddLastArg(CmdArgs, options::OPT_objcmt_returns_innerpointer_property);
4027 Args.AddLastArg(CmdArgs, options::OPT_objcmt_ns_nonatomic_iosonly);
4028 Args.AddLastArg(CmdArgs, options::OPT_objcmt_migrate_designated_init);
4029 Args.AddLastArg(CmdArgs, options::OPT_objcmt_allowlist_dir_path);
4034 const ArgList &Args, ArgStringList &CmdArgs) {
4037 Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin,
4038 !Args.hasArg(options::OPT_mkernel));
4040 CmdArgs.push_back(
"-fno-builtin");
4043 if (Args.hasArg(options::OPT_ffreestanding))
4044 UseBuiltins =
false;
4047 for (
const Arg *A : Args.filtered(options::OPT_fno_builtin_)) {
4053 A->render(Args, CmdArgs);
4058 if (
const char *Str = std::getenv(
"CLANG_MODULE_CACHE_PATH")) {
4061 return Path.getSingleStringRef() !=
"";
4063 if (llvm::sys::path::cache_directory(
Result)) {
4064 llvm::sys::path::append(
Result,
"clang");
4065 llvm::sys::path::append(
Result,
"ModuleCache");
4073 const char *BaseInput) {
4074 if (Arg *ModuleOutputEQ = Args.getLastArg(options::OPT_fmodule_output_EQ))
4075 return StringRef(ModuleOutputEQ->getValue());
4078 if (Arg *FinalOutput = Args.getLastArg(options::OPT_o);
4079 FinalOutput && Args.hasArg(options::OPT_c))
4080 OutputPath = FinalOutput->getValue();
4082 OutputPath = BaseInput;
4085 llvm::sys::path::replace_extension(OutputPath, Extension);
4090 const ArgList &Args,
const InputInfo &Input,
4091 const InputInfo &Output,
bool HaveStd20,
4092 ArgStringList &CmdArgs) {
4094 bool HaveStdCXXModules = IsCXX && HaveStd20;
4095 bool HaveModules = HaveStdCXXModules;
4100 bool HaveClangModules =
false;
4101 if (Args.hasFlag(options::OPT_fmodules, options::OPT_fno_modules,
false)) {
4102 bool AllowedInCXX = Args.hasFlag(options::OPT_fcxx_modules,
4103 options::OPT_fno_cxx_modules,
true);
4104 if (AllowedInCXX || !IsCXX) {
4105 CmdArgs.push_back(
"-fmodules");
4106 HaveClangModules =
true;
4110 HaveModules |= HaveClangModules;
4114 if (Args.hasFlag(options::OPT_fimplicit_module_maps,
4115 options::OPT_fno_implicit_module_maps, HaveClangModules))
4116 CmdArgs.push_back(
"-fimplicit-module-maps");
4119 Args.addOptInFlag(CmdArgs, options::OPT_fmodules_decluse,
4120 options::OPT_fno_modules_decluse);
4124 if (Args.hasFlag(options::OPT_fmodules_strict_decluse,
4125 options::OPT_fno_modules_strict_decluse,
false))
4126 CmdArgs.push_back(
"-fmodules-strict-decluse");
4128 Args.addOptOutFlag(CmdArgs, options::OPT_fmodulemap_allow_subdirectory_search,
4129 options::OPT_fno_modulemap_allow_subdirectory_search);
4132 bool ImplicitModules =
false;
4133 if (!Args.hasFlag(options::OPT_fimplicit_modules,
4134 options::OPT_fno_implicit_modules, HaveClangModules)) {
4136 CmdArgs.push_back(
"-fno-implicit-modules");
4137 }
else if (HaveModules) {
4138 ImplicitModules =
true;
4142 if (Arg *A = Args.getLastArg(options::OPT_fmodules_cache_path))
4143 Path = A->getValue();
4145 bool HasPath =
true;
4146 if (
C.isForDiagnostics()) {
4150 llvm::sys::path::replace_extension(
Path,
".cache");
4151 llvm::sys::path::append(
Path,
"modules");
4152 }
else if (
Path.empty()) {
4160 const char Arg[] =
"-fmodules-cache-path=";
4161 Path.insert(
Path.begin(), Arg, Arg + strlen(Arg));
4162 CmdArgs.push_back(Args.MakeArgString(
Path));
4167 if (Args.hasFlag(options::OPT_fprebuilt_implicit_modules,
4168 options::OPT_fno_prebuilt_implicit_modules,
false))
4169 CmdArgs.push_back(
"-fprebuilt-implicit-modules");
4170 if (Args.hasFlag(options::OPT_fmodules_validate_input_files_content,
4171 options::OPT_fno_modules_validate_input_files_content,
4173 CmdArgs.push_back(
"-fvalidate-ast-input-files-content");
4178 Args.AddLastArg(CmdArgs, options::OPT_fmodule_name_EQ);
4182 Args.AddAllArgs(CmdArgs, options::OPT_fmodule_map_file);
4186 if (Args.hasArg(options::OPT_fbuiltin_module_map)) {
4188 llvm::sys::path::append(BuiltinModuleMap,
"include");
4189 llvm::sys::path::append(BuiltinModuleMap,
"module.modulemap");
4190 if (llvm::sys::fs::exists(BuiltinModuleMap))
4192 Args.MakeArgString(
"-fmodule-map-file=" + BuiltinModuleMap));
4199 if (HaveModules || Input.
getType() == clang::driver::types::TY_ModuleFile) {
4200 Args.AddAllArgs(CmdArgs, options::OPT_fmodule_file);
4203 for (
const Arg *A : Args.filtered(options::OPT_fprebuilt_module_path)) {
4204 CmdArgs.push_back(Args.MakeArgString(
4205 std::string(
"-fprebuilt-module-path=") + A->getValue()));
4209 Args.ClaimAllArgs(options::OPT_fmodule_file);
4213 if (HaveClangModules &&
C.isForDiagnostics()) {
4215 llvm::sys::path::replace_extension(VFSDir,
".cache");
4217 C.addTempFile(Args.MakeArgString(VFSDir));
4219 llvm::sys::path::append(VFSDir,
"vfs");
4220 CmdArgs.push_back(
"-module-dependency-dir");
4221 CmdArgs.push_back(Args.MakeArgString(VFSDir));
4224 if (HaveClangModules)
4225 Args.AddLastArg(CmdArgs, options::OPT_fmodules_user_build_path);
4228 Args.AddAllArgs(CmdArgs, options::OPT_fmodules_ignore_macro);
4229 Args.AddLastArg(CmdArgs, options::OPT_fmodules_prune_interval);
4230 Args.AddLastArg(CmdArgs, options::OPT_fmodules_prune_after);
4232 if (HaveClangModules) {
4233 Args.AddLastArg(CmdArgs, options::OPT_fbuild_session_timestamp);
4235 if (Arg *A = Args.getLastArg(options::OPT_fbuild_session_file)) {
4236 if (Args.hasArg(options::OPT_fbuild_session_timestamp))
4237 D.Diag(diag::err_drv_argument_not_allowed_with)
4238 << A->getAsString(Args) <<
"-fbuild-session-timestamp";
4240 llvm::sys::fs::file_status Status;
4241 if (llvm::sys::fs::status(A->getValue(), Status))
4242 D.Diag(diag::err_drv_no_such_file) << A->getValue();
4243 CmdArgs.push_back(Args.MakeArgString(
4244 "-fbuild-session-timestamp=" +
4245 Twine((uint64_t)std::chrono::duration_cast<std::chrono::seconds>(
4246 Status.getLastModificationTime().time_since_epoch())
4250 if (Args.getLastArg(
4251 options::OPT_fmodules_validate_once_per_build_session)) {
4252 if (!Args.getLastArg(options::OPT_fbuild_session_timestamp,
4253 options::OPT_fbuild_session_file))
4254 D.Diag(diag::err_drv_modules_validate_once_requires_timestamp);
4256 Args.AddLastArg(CmdArgs,
4257 options::OPT_fmodules_validate_once_per_build_session);
4260 if (Args.hasFlag(options::OPT_fmodules_validate_system_headers,
4261 options::OPT_fno_modules_validate_system_headers,
4263 CmdArgs.push_back(
"-fmodules-validate-system-headers");
4265 Args.AddLastArg(CmdArgs,
4266 options::OPT_fmodules_disable_diagnostic_validation);
4268 Args.ClaimAllArgs(options::OPT_fbuild_session_timestamp);
4269 Args.ClaimAllArgs(options::OPT_fbuild_session_file);
4270 Args.ClaimAllArgs(options::OPT_fmodules_validate_once_per_build_session);
4271 Args.ClaimAllArgs(options::OPT_fmodules_validate_system_headers);
4272 Args.ClaimAllArgs(options::OPT_fno_modules_validate_system_headers);
4273 Args.ClaimAllArgs(options::OPT_fmodules_disable_diagnostic_validation);
4278 CmdArgs.push_back(
"-fskip-odr-check-in-gmf");
4280 if (Args.hasArg(options::OPT_modules_reduced_bmi) &&
4281 (Input.
getType() == driver::types::TY_CXXModule ||
4282 Input.
getType() == driver::types::TY_PP_CXXModule)) {
4283 CmdArgs.push_back(
"-fmodules-reduced-bmi");
4285 if (Args.hasArg(options::OPT_fmodule_output_EQ))
4286 Args.AddLastArg(CmdArgs, options::OPT_fmodule_output_EQ);
4288 CmdArgs.push_back(Args.MakeArgString(
4289 "-fmodule-output=" +
4296 Args.ClaimAllArgs(options::OPT_modules_reduced_bmi);
4304 if (Input.
getType() == driver::types::TY_CXXModule ||
4305 Input.
getType() == driver::types::TY_PP_CXXModule ||
4306 Input.
getType() == driver::types::TY_ModuleFile) {
4307 Args.ClaimAllArgs(options::OPT_fmodule_output);
4308 Args.ClaimAllArgs(options::OPT_fmodule_output_EQ);
4311 if (Args.hasArg(options::OPT_fmodules_embed_all_files))
4312 CmdArgs.push_back(
"-fmodules-embed-all-files");
4318 ArgStringList &CmdArgs) {
4320 if (
const Arg *A = Args.getLastArg(options::OPT_fsigned_char,
4321 options::OPT_fno_signed_char,
4322 options::OPT_funsigned_char,
4323 options::OPT_fno_unsigned_char)) {
4324 if (A->getOption().matches(options::OPT_funsigned_char) ||
4325 A->getOption().matches(options::OPT_fno_signed_char)) {
4326 CmdArgs.push_back(
"-fno-signed-char");
4329 CmdArgs.push_back(
"-fno-signed-char");
4333 Args.AddLastArg(CmdArgs, options::OPT_fchar8__t, options::OPT_fno_char8__t);
4335 if (
const Arg *A = Args.getLastArg(options::OPT_fshort_wchar,
4336 options::OPT_fno_short_wchar)) {
4337 if (A->getOption().matches(options::OPT_fshort_wchar)) {
4338 CmdArgs.push_back(
"-fwchar-type=short");
4339 CmdArgs.push_back(
"-fno-signed-wchar");
4341 bool IsARM =
T.isARM() ||
T.isThumb() ||
T.isAArch64();
4342 CmdArgs.push_back(
"-fwchar-type=int");
4344 (IsARM && !(
T.isOSWindows() ||
T.isOSNetBSD() ||
T.isOSOpenBSD())))
4345 CmdArgs.push_back(
"-fno-signed-wchar");
4347 CmdArgs.push_back(
"-fsigned-wchar");
4349 }
else if (
T.isOSzOS())
4350 CmdArgs.push_back(
"-fno-signed-wchar");
4354 const llvm::Triple &
T,
const ArgList &Args,
4356 const InputInfo &Input, ArgStringList &CmdArgs) {
4357 const llvm::Triple::ArchType Arch = TC.
getArch();
4363 if (!Args.hasFlag(options::OPT_fobjc_legacy_dispatch,
4364 options::OPT_fno_objc_legacy_dispatch,
4367 CmdArgs.push_back(
"-fobjc-dispatch-method=mixed");
4369 CmdArgs.push_back(
"-fobjc-dispatch-method=non-legacy");
4375 if (Arch == llvm::Triple::x86 &&
T.isMacOSX() &&
4377 CmdArgs.push_back(
"-fobjc-subscripting-legacy-runtime");
4384 CmdArgs.push_back(
"-fobjc-arc");
4391 CmdArgs.push_back(
"-fobjc-arc-cxxlib=libc++");
4393 CmdArgs.push_back(
"-fobjc-arc-cxxlib=libstdc++");
4398 if (Args.hasFlag(options::OPT_fobjc_arc_exceptions,
4399 options::OPT_fno_objc_arc_exceptions,
4401 CmdArgs.push_back(
"-fobjc-arc-exceptions");
4406 if (Args.hasArg(options::OPT_fno_objc_arc)) {
4407 Args.ClaimAllArgs(options::OPT_fobjc_arc_exceptions);
4408 Args.ClaimAllArgs(options::OPT_fno_objc_arc_exceptions);
4414 auto *Arg = Args.getLastArg(
4415 options::OPT_fobjc_convert_messages_to_runtime_calls,
4416 options::OPT_fno_objc_convert_messages_to_runtime_calls);
4418 Arg->getOption().matches(
4419 options::OPT_fno_objc_convert_messages_to_runtime_calls))
4420 CmdArgs.push_back(
"-fno-objc-convert-messages-to-runtime-calls");
4425 if (InferCovariantReturns)
4426 CmdArgs.push_back(
"-fno-objc-infer-related-result-type");
4431 Args.getLastArg(options::OPT_fobjc_weak, options::OPT_fno_objc_weak);
4435 if (WeakArg->getOption().matches(options::OPT_fobjc_weak))
4436 D.Diag(diag::err_objc_weak_unsupported);
4438 WeakArg->render(Args, CmdArgs);
4442 if (Args.hasArg(options::OPT_fobjc_disable_direct_methods_for_testing))
4443 CmdArgs.push_back(
"-fobjc-disable-direct-methods-for-testing");
4447 ArgStringList &CmdArgs) {
4448 bool CaretDefault =
true;
4449 bool ColumnDefault =
true;
4451 if (
const Arg *A = Args.getLastArg(options::OPT__SLASH_diagnostics_classic,
4452 options::OPT__SLASH_diagnostics_column,
4453 options::OPT__SLASH_diagnostics_caret)) {
4454 switch (A->getOption().getID()) {
4455 case options::OPT__SLASH_diagnostics_caret:
4456 CaretDefault =
true;
4457 ColumnDefault =
true;
4459 case options::OPT__SLASH_diagnostics_column:
4460 CaretDefault =
false;
4461 ColumnDefault =
true;
4463 case options::OPT__SLASH_diagnostics_classic:
4464 CaretDefault =
false;
4465 ColumnDefault =
false;
4471 if (!Args.hasFlag(options::OPT_fcaret_diagnostics,
4472 options::OPT_fno_caret_diagnostics, CaretDefault))
4473 CmdArgs.push_back(
"-fno-caret-diagnostics");
4475 Args.addOptOutFlag(CmdArgs, options::OPT_fdiagnostics_fixit_info,
4476 options::OPT_fno_diagnostics_fixit_info);
4477 Args.addOptOutFlag(CmdArgs, options::OPT_fdiagnostics_show_option,
4478 options::OPT_fno_diagnostics_show_option);
4481 Args.getLastArg(options::OPT_fdiagnostics_show_category_EQ)) {
4482 CmdArgs.push_back(
"-fdiagnostics-show-category");
4483 CmdArgs.push_back(A->getValue());
4486 Args.addOptInFlag(CmdArgs, options::OPT_fdiagnostics_show_hotness,
4487 options::OPT_fno_diagnostics_show_hotness);
4490 Args.getLastArg(options::OPT_fdiagnostics_hotness_threshold_EQ)) {
4492 std::string(
"-fdiagnostics-hotness-threshold=") + A->getValue();
4493 CmdArgs.push_back(Args.MakeArgString(Opt));
4497 Args.getLastArg(options::OPT_fdiagnostics_misexpect_tolerance_EQ)) {
4499 std::string(
"-fdiagnostics-misexpect-tolerance=") + A->getValue();
4500 CmdArgs.push_back(Args.MakeArgString(Opt));
4503 if (
const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_format_EQ)) {
4504 CmdArgs.push_back(
"-fdiagnostics-format");
4505 CmdArgs.push_back(A->getValue());
4506 if (StringRef(A->getValue()) ==
"sarif" ||
4507 StringRef(A->getValue()) ==
"SARIF")
4508 D.Diag(diag::warn_drv_sarif_format_unstable);
4511 if (
const Arg *A = Args.getLastArg(
4512 options::OPT_fdiagnostics_show_note_include_stack,
4513 options::OPT_fno_diagnostics_show_note_include_stack)) {
4514 const Option &O = A->getOption();
4515 if (O.matches(options::OPT_fdiagnostics_show_note_include_stack))
4516 CmdArgs.push_back(
"-fdiagnostics-show-note-include-stack");
4518 CmdArgs.push_back(
"-fno-diagnostics-show-note-include-stack");
4523 if (Args.hasArg(options::OPT_fansi_escape_codes))
4524 CmdArgs.push_back(
"-fansi-escape-codes");
4526 Args.addOptOutFlag(CmdArgs, options::OPT_fshow_source_location,
4527 options::OPT_fno_show_source_location);
4529 Args.addOptOutFlag(CmdArgs, options::OPT_fdiagnostics_show_line_numbers,
4530 options::OPT_fno_diagnostics_show_line_numbers);
4532 if (Args.hasArg(options::OPT_fdiagnostics_absolute_paths))
4533 CmdArgs.push_back(
"-fdiagnostics-absolute-paths");
4535 if (!Args.hasFlag(options::OPT_fshow_column, options::OPT_fno_show_column,
4537 CmdArgs.push_back(
"-fno-show-column");
4539 Args.addOptOutFlag(CmdArgs, options::OPT_fspell_checking,
4540 options::OPT_fno_spell_checking);
4542 Args.addLastArg(CmdArgs, options::OPT_warning_suppression_mappings_EQ);
4546 const ArgList &Args, Arg *&Arg) {
4547 Arg = Args.getLastArg(options::OPT_gsplit_dwarf, options::OPT_gsplit_dwarf_EQ,
4548 options::OPT_gno_split_dwarf);
4549 if (!Arg || Arg->getOption().matches(options::OPT_gno_split_dwarf))
4552 if (Arg->getOption().matches(options::OPT_gsplit_dwarf))
4555 StringRef
Value = Arg->getValue();
4556 if (
Value ==
"split")
4558 if (
Value ==
"single")
4561 D.Diag(diag::err_drv_unsupported_option_argument)
4562 << Arg->getSpelling() << Arg->getValue();
4567 const ArgList &Args, ArgStringList &CmdArgs,
4568 unsigned DwarfVersion) {
4569 auto *DwarfFormatArg =
4570 Args.getLastArg(options::OPT_gdwarf64, options::OPT_gdwarf32);
4571 if (!DwarfFormatArg)
4574 if (DwarfFormatArg->getOption().matches(options::OPT_gdwarf64)) {
4575 if (DwarfVersion < 3)
4576 D.Diag(diag::err_drv_argument_only_allowed_with)
4577 << DwarfFormatArg->getAsString(Args) <<
"DWARFv3 or greater";
4578 else if (!
T.isArch64Bit())
4579 D.Diag(diag::err_drv_argument_only_allowed_with)
4580 << DwarfFormatArg->getAsString(Args) <<
"64 bit architecture";
4581 else if (!
T.isOSBinFormatELF())
4582 D.Diag(diag::err_drv_argument_only_allowed_with)
4583 << DwarfFormatArg->getAsString(Args) <<
"ELF platforms";
4586 DwarfFormatArg->render(Args, CmdArgs);
4591 const ArgList &Args,
bool IRInput, ArgStringList &CmdArgs,
4593 llvm::codegenoptions::DebugInfoKind &DebugInfoKind,
4595 if (Args.hasFlag(options::OPT_fdebug_info_for_profiling,
4596 options::OPT_fno_debug_info_for_profiling,
false) &&
4598 Args.getLastArg(options::OPT_fdebug_info_for_profiling), Args,
D, TC))
4599 CmdArgs.push_back(
"-fdebug-info-for-profiling");
4612 bool SplitDWARFInlining =
4613 Args.hasFlag(options::OPT_fsplit_dwarf_inlining,
4614 options::OPT_fno_split_dwarf_inlining,
false);
4619 if (IRInput || Args.hasArg(options::OPT_g_Group)) {
4625 SplitDWARFInlining =
false;
4628 if (
const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
4629 DebugInfoKind = llvm::codegenoptions::DebugInfoConstructor;
4633 A->getOption().matches(options::OPT_gN_Group)) {
4639 if (DebugInfoKind == llvm::codegenoptions::NoDebugInfo ||
4640 DebugInfoKind == llvm::codegenoptions::DebugDirectivesOnly ||
4641 (DebugInfoKind == llvm::codegenoptions::DebugLineTablesOnly &&
4642 SplitDWARFInlining))
4648 bool HasDebuggerTuning =
false;
4650 Args.getLastArg(options::OPT_gTune_Group, options::OPT_ggdbN_Group)) {
4651 HasDebuggerTuning =
true;
4653 if (A->getOption().matches(options::OPT_glldb))
4654 DebuggerTuning = llvm::DebuggerKind::LLDB;
4655 else if (A->getOption().matches(options::OPT_gsce))
4656 DebuggerTuning = llvm::DebuggerKind::SCE;
4657 else if (A->getOption().matches(options::OPT_gdbx))
4658 DebuggerTuning = llvm::DebuggerKind::DBX;
4660 DebuggerTuning = llvm::DebuggerKind::GDB;
4665 bool EmitDwarf =
false;
4669 bool EmitCodeView =
false;
4670 if (
const Arg *A = Args.getLastArg(options::OPT_gcodeview))
4675 if (!EmitCodeView && !EmitDwarf &&
4676 DebugInfoKind != llvm::codegenoptions::NoDebugInfo) {
4678 case llvm::codegenoptions::DIF_CodeView:
4679 EmitCodeView =
true;
4681 case llvm::codegenoptions::DIF_DWARF:
4687 unsigned RequestedDWARFVersion = 0;
4688 unsigned EffectiveDWARFVersion = 0;
4693 EffectiveDWARFVersion =
4696 Args.ClaimAllArgs(options::OPT_fdebug_default_version);
4700 if (RequestedDWARFVersion == 0 &&
4701 DebugInfoKind == llvm::codegenoptions::DebugDirectivesOnly)
4702 DebugInfoKind = llvm::codegenoptions::NoDebugInfo;
4706 if (
const Arg *A = Args.getLastArg(options::OPT_gstrict_dwarf))
4708 if (Args.hasFlag(options::OPT_gstrict_dwarf, options::OPT_gno_strict_dwarf,
4709 DebuggerTuning == llvm::DebuggerKind::DBX))
4710 CmdArgs.push_back(
"-gstrict-dwarf");
4713 Args.ClaimAllArgs(options::OPT_g_flags_Group);
4721 if (
const Arg *A = Args.getLastArg(options::OPT_gcolumn_info))
4723 if (!Args.hasFlag(options::OPT_gcolumn_info, options::OPT_gno_column_info,
4725 (DebuggerTuning != llvm::DebuggerKind::SCE &&
4726 DebuggerTuning != llvm::DebuggerKind::DBX)))
4727 CmdArgs.push_back(
"-gno-column-info");
4730 if (Args.hasFlag(options::OPT_gmodules, options::OPT_gno_modules,
false)) {
4735 if (DebugInfoKind != llvm::codegenoptions::DebugLineTablesOnly &&
4736 DebugInfoKind != llvm::codegenoptions::DebugDirectivesOnly) {
4737 DebugInfoKind = llvm::codegenoptions::DebugInfoConstructor;
4738 CmdArgs.push_back(
"-dwarf-ext-refs");
4739 CmdArgs.push_back(
"-fmodule-format=obj");
4744 if (
T.isOSBinFormatELF() && SplitDWARFInlining)
4745 CmdArgs.push_back(
"-fsplit-dwarf-inlining");
4752 bool NeedFullDebug = Args.hasFlag(
4753 options::OPT_fstandalone_debug, options::OPT_fno_standalone_debug,
4754 DebuggerTuning == llvm::DebuggerKind::LLDB ||
4756 if (
const Arg *A = Args.getLastArg(options::OPT_fstandalone_debug))
4759 if (DebugInfoKind == llvm::codegenoptions::LimitedDebugInfo ||
4760 DebugInfoKind == llvm::codegenoptions::DebugInfoConstructor) {
4761 if (Args.hasFlag(options::OPT_fno_eliminate_unused_debug_types,
4762 options::OPT_feliminate_unused_debug_types,
false))
4763 DebugInfoKind = llvm::codegenoptions::UnusedTypeInfo;
4764 else if (NeedFullDebug)
4765 DebugInfoKind = llvm::codegenoptions::FullDebugInfo;
4768 if (Args.hasFlag(options::OPT_gembed_source, options::OPT_gno_embed_source,
4774 const Arg *A = Args.getLastArg(options::OPT_gembed_source);
4775 if (RequestedDWARFVersion < 5)
4776 D.Diag(diag::err_drv_argument_only_allowed_with)
4777 << A->getAsString(Args) <<
"-gdwarf-5";
4778 else if (EffectiveDWARFVersion < 5)
4781 D.Diag(diag::warn_drv_dwarf_version_limited_by_target)
4783 << EffectiveDWARFVersion;
4785 CmdArgs.push_back(
"-gembed-source");
4789 CmdArgs.push_back(
"-gcodeview");
4791 Args.addOptInFlag(CmdArgs, options::OPT_gcodeview_ghash,
4792 options::OPT_gno_codeview_ghash);
4794 Args.addOptOutFlag(CmdArgs, options::OPT_gcodeview_command_line,
4795 options::OPT_gno_codeview_command_line);
4798 Args.addOptOutFlag(CmdArgs, options::OPT_ginline_line_tables,
4799 options::OPT_gno_inline_line_tables);
4803 DebugInfoKind <= llvm::codegenoptions::DebugDirectivesOnly)
4804 DebugInfoKind = llvm::codegenoptions::DebugLineTablesOnly;
4812 T.isOSAIX() && !HasDebuggerTuning
4813 ? llvm::DebuggerKind::Default
4817 if (Args.hasFlag(options::OPT_fdebug_macro, options::OPT_fno_debug_macro,
4821 CmdArgs.push_back(
"-debug-info-macro");
4824 const auto *PubnamesArg =
4825 Args.getLastArg(options::OPT_ggnu_pubnames, options::OPT_gno_gnu_pubnames,
4826 options::OPT_gpubnames, options::OPT_gno_pubnames);
4829 const bool OptionSet =
4831 (PubnamesArg->getOption().matches(options::OPT_gpubnames) ||
4832 PubnamesArg->getOption().matches(options::OPT_ggnu_pubnames)));
4833 if ((DebuggerTuning != llvm::DebuggerKind::LLDB || OptionSet) &&
4835 (!PubnamesArg->getOption().matches(options::OPT_gno_gnu_pubnames) &&
4836 !PubnamesArg->getOption().matches(options::OPT_gno_pubnames))))
4837 CmdArgs.push_back(PubnamesArg && PubnamesArg->getOption().matches(
4838 options::OPT_gpubnames)
4840 :
"-ggnu-pubnames");
4842 const auto *SimpleTemplateNamesArg =
4843 Args.getLastArg(options::OPT_gsimple_template_names,
4844 options::OPT_gno_simple_template_names);
4845 bool ForwardTemplateParams = DebuggerTuning == llvm::DebuggerKind::SCE;
4846 if (SimpleTemplateNamesArg &&
4848 const auto &Opt = SimpleTemplateNamesArg->getOption();
4849 if (Opt.matches(options::OPT_gsimple_template_names)) {
4850 ForwardTemplateParams =
true;
4851 CmdArgs.push_back(
"-gsimple-template-names=simple");
4856 bool UseDebugTemplateAlias =
4857 DebuggerTuning == llvm::DebuggerKind::SCE && RequestedDWARFVersion >= 4;
4858 if (
const auto *DebugTemplateAlias = Args.getLastArg(
4859 options::OPT_gtemplate_alias, options::OPT_gno_template_alias)) {
4863 const auto &Opt = DebugTemplateAlias->getOption();
4864 UseDebugTemplateAlias = Opt.matches(options::OPT_gtemplate_alias);
4867 if (UseDebugTemplateAlias)
4868 CmdArgs.push_back(
"-gtemplate-alias");
4870 if (
const Arg *A = Args.getLastArg(options::OPT_gsrc_hash_EQ)) {
4871 StringRef
v = A->getValue();
4872 CmdArgs.push_back(Args.MakeArgString(
"-gsrc-hash=" +
v));
4875 Args.addOptInFlag(CmdArgs, options::OPT_fdebug_ranges_base_address,
4876 options::OPT_fno_debug_ranges_base_address);
4880 if (
const Arg *A = Args.getLastArg(options::OPT_gdwarf_aranges);
4882 CmdArgs.push_back(
"-mllvm");
4883 CmdArgs.push_back(
"-generate-arange-section");
4886 Args.addOptInFlag(CmdArgs, options::OPT_fforce_dwarf_frame,
4887 options::OPT_fno_force_dwarf_frame);
4889 bool EnableTypeUnits =
false;
4890 if (Args.hasFlag(options::OPT_fdebug_types_section,
4891 options::OPT_fno_debug_types_section,
false)) {
4892 if (!(
T.isOSBinFormatELF() ||
T.isOSBinFormatWasm())) {
4893 D.Diag(diag::err_drv_unsupported_opt_for_target)
4894 << Args.getLastArg(options::OPT_fdebug_types_section)
4898 Args.getLastArg(options::OPT_fdebug_types_section), Args,
D,
4900 EnableTypeUnits =
true;
4901 CmdArgs.push_back(
"-mllvm");
4902 CmdArgs.push_back(
"-generate-type-units");
4907 Args.getLastArg(options::OPT_gomit_unreferenced_methods,
4908 options::OPT_gno_omit_unreferenced_methods))
4910 if (Args.hasFlag(options::OPT_gomit_unreferenced_methods,
4911 options::OPT_gno_omit_unreferenced_methods,
false) &&
4912 (DebugInfoKind == llvm::codegenoptions::DebugInfoConstructor ||
4913 DebugInfoKind == llvm::codegenoptions::LimitedDebugInfo) &&
4915 CmdArgs.push_back(
"-gomit-unreferenced-methods");
4921 if (!Args.hasFlag(options::OPT_fdwarf_directory_asm,
4922 options::OPT_fno_dwarf_directory_asm,
4924 CmdArgs.push_back(
"-fno-dwarf-directory-asm");
4928 if (ForwardTemplateParams)
4929 CmdArgs.push_back(
"-debug-forward-template-params");
4933 if (DebuggerTuning == llvm::DebuggerKind::SCE)
4934 CmdArgs.push_back(
"-dwarf-explicit-import");
4940 if (Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc,
false)) {
4941 if (TC.
getTriple().isOSBinFormatELF() ||
4942 TC.
getTriple().isWindowsMSVCEnvironment()) {
4943 if (DebugInfoKind >= llvm::codegenoptions::DebugInfoConstructor)
4944 CmdArgs.push_back(
"-fjmc");
4945 else if (
D.IsCLMode())
4946 D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo) <<
"/JMC"
4949 D.Diag(clang::diag::warn_drv_jmc_requires_debuginfo) <<
"-fjmc"
4952 D.Diag(clang::diag::warn_drv_fjmc_for_elf_only);
4957 const char *DebugCompilationDir =
4969 ArgStringList &CmdArgs) {
4970 unsigned RTOptionID = options::OPT__SLASH_MT;
4972 if (Args.hasArg(options::OPT__SLASH_LDd))
4975 RTOptionID = options::OPT__SLASH_MTd;
4977 if (Arg *A = Args.getLastArg(options::OPT__SLASH_M_Group))
4978 RTOptionID = A->getOption().getID();
4980 if (Arg *A = Args.getLastArg(options::OPT_fms_runtime_lib_EQ)) {
4981 RTOptionID = llvm::StringSwitch<unsigned>(A->getValue())
4982 .Case(
"static", options::OPT__SLASH_MT)
4983 .Case(
"static_dbg", options::OPT__SLASH_MTd)
4984 .Case(
"dll", options::OPT__SLASH_MD)
4985 .Case(
"dll_dbg", options::OPT__SLASH_MDd)
4986 .Default(options::OPT__SLASH_MT);
4989 StringRef FlagForCRT;
4990 switch (RTOptionID) {
4991 case options::OPT__SLASH_MD:
4992 if (Args.hasArg(options::OPT__SLASH_LDd))
4993 CmdArgs.push_back(
"-D_DEBUG");
4994 CmdArgs.push_back(
"-D_MT");
4995 CmdArgs.push_back(
"-D_DLL");
4996 FlagForCRT =
"--dependent-lib=msvcrt";
4998 case options::OPT__SLASH_MDd:
4999 CmdArgs.push_back(
"-D_DEBUG");
5000 CmdArgs.push_back(
"-D_MT");
5001 CmdArgs.push_back(
"-D_DLL");
5002 FlagForCRT =
"--dependent-lib=msvcrtd";
5004 case options::OPT__SLASH_MT:
5005 if (Args.hasArg(options::OPT__SLASH_LDd))
5006 CmdArgs.push_back(
"-D_DEBUG");
5007 CmdArgs.push_back(
"-D_MT");
5008 CmdArgs.push_back(
"-flto-visibility-public-std");
5009 FlagForCRT =
"--dependent-lib=libcmt";
5011 case options::OPT__SLASH_MTd:
5012 CmdArgs.push_back(
"-D_DEBUG");
5013 CmdArgs.push_back(
"-D_MT");
5014 CmdArgs.push_back(
"-flto-visibility-public-std");
5015 FlagForCRT =
"--dependent-lib=libcmtd";
5018 llvm_unreachable(
"Unexpected option ID.");
5021 if (Args.hasArg(options::OPT_fms_omit_default_lib)) {
5022 CmdArgs.push_back(
"-D_VC_NODEFAULTLIB");
5024 CmdArgs.push_back(FlagForCRT.data());
5029 CmdArgs.push_back(
"--dependent-lib=oldnames");
5036 CmdArgs.push_back(
"--dependent-lib=softintrin");
5041 const ArgList &Args,
const char *LinkingOutput)
const {
5043 const llvm::Triple &RawTriple = TC.
getTriple();
5045 const std::string &TripleStr = Triple.getTriple();
5048 Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
5050 ArgStringList CmdArgs;
5052 assert(Inputs.size() >= 1 &&
"Must have at least one input.");
5067 bool IsExtractAPI = isa<ExtractAPIJobAction>(JA);
5070 bool IsHostOffloadingAction =
5074 Args.hasFlag(options::OPT_offload_new_driver,
5075 options::OPT_no_offload_new_driver,
5079 Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
false);
5081 auto LTOMode = IsDeviceOffloadAction ?
D.getOffloadLTOMode() :
D.getLTOMode();
5086 InputInfo ExtractAPIPlaceholderInput(Inputs[0].getType(),
"extract-api",
5090 IsExtractAPI ? ExtractAPIPlaceholderInput : Inputs[0];
5094 const InputInfo *CudaDeviceInput =
nullptr;
5095 const InputInfo *OpenMPDeviceInput =
nullptr;
5097 if (&I == &Input || I.
getType() == types::TY_Nothing) {
5099 }
else if (IsExtractAPI) {
5100 auto ExpectedInputType = ExtractAPIPlaceholderInput.
getType();
5101 if (I.getType() != ExpectedInputType) {
5102 D.Diag(diag::err_drv_extract_api_wrong_kind)
5106 ExtractAPIInputs.push_back(I);
5107 }
else if (IsHostOffloadingAction) {
5108 HostOffloadingInputs.push_back(I);
5109 }
else if ((IsCuda || IsHIP) && !CudaDeviceInput) {
5110 CudaDeviceInput = &I;
5111 }
else if (IsOpenMPDevice && !OpenMPDeviceInput) {
5112 OpenMPDeviceInput = &I;
5114 llvm_unreachable(
"unexpectedly given multiple inputs");
5118 const llvm::Triple *AuxTriple =
5120 bool IsWindowsMSVC = RawTriple.isWindowsMSVCEnvironment();
5121 bool IsUEFI = RawTriple.isUEFI();
5122 bool IsIAMCU = RawTriple.isOSIAMCU();
5127 if (IsCuda || IsHIP || IsSYCL)
5128 IsWindowsMSVC |= AuxTriple && AuxTriple->isWindowsMSVCEnvironment();
5132 D.Diag(diag::err_drv_clang_unsupported) <<
"C++ for IAMCU";
5137 CmdArgs.push_back(
"-cc1");
5140 CmdArgs.push_back(
"-triple");
5141 CmdArgs.push_back(Args.MakeArgString(TripleStr));
5143 if (
const Arg *MJ = Args.getLastArg(options::OPT_MJ)) {
5144 DumpCompilationDatabase(
C, MJ->getValue(), TripleStr, Output, Input, Args);
5145 Args.ClaimAllArgs(options::OPT_MJ);
5146 }
else if (
const Arg *GenCDBFragment =
5147 Args.getLastArg(options::OPT_gen_cdb_fragment_path)) {
5148 DumpCompilationDatabaseFragmentToDir(GenCDBFragment->getValue(),
C,
5149 TripleStr, Output, Input, Args);
5150 Args.ClaimAllArgs(options::OPT_gen_cdb_fragment_path);
5153 if (IsCuda || IsHIP) {
5156 std::string NormalizedTriple;
5174 assert(CTC &&
"Expected valid CUDA Toolchain.");
5176 CmdArgs.push_back(Args.MakeArgString(
5177 Twine(
"-target-sdk-version=") +
5185 CmdArgs.push_back(
"-fcuda-allow-variadic-functions");
5188 CmdArgs.push_back(
"-aux-triple");
5189 CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
5194 getToolChain().getTriple().getVendor() == llvm::Triple::AMD))) {
5196 if (Args.getLastArg(options::OPT_mprintf_kind_EQ)) {
5197 CmdArgs.push_back(Args.MakeArgString(
5199 Args.getLastArgValue(options::OPT_mprintf_kind_EQ)));
5202 Args.MakeArgString(
"-Werror=format-invalid-specifier"));
5208 if (
const Arg *PF = Args.getLastArg(options::OPT_mprintf_kind_EQ))
5214 llvm::Triple AuxT =
C.getDefaultToolChain().getTriple();
5215 std::string NormalizedTriple = AuxT.normalize();
5216 CmdArgs.push_back(
"-aux-triple");
5217 CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
5220 CmdArgs.push_back(
"-fsycl-is-device");
5223 if (!Args.getLastArg(options::OPT_O_Group))
5224 CmdArgs.push_back(
"-O2");
5231 CmdArgs.push_back(
"-fsycl-is-host");
5235 Arg *SYCLStdArg = Args.getLastArg(options::OPT_sycl_std_EQ);
5237 SYCLStdArg->render(Args, CmdArgs);
5240 CmdArgs.push_back(
"-sycl-std=2020");
5244 if (Args.hasArg(options::OPT_fclangir))
5245 CmdArgs.push_back(
"-fclangir");
5247 if (IsOpenMPDevice) {
5249 std::string NormalizedTriple =
5253 CmdArgs.push_back(
"-aux-triple");
5254 CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));
5257 if (Triple.isOSWindows() && (Triple.getArch() == llvm::Triple::arm ||
5258 Triple.getArch() == llvm::Triple::thumb)) {
5259 unsigned Offset = Triple.getArch() == llvm::Triple::arm ? 4 : 6;
5260 unsigned Version = 0;
5262 Triple.getArchName().substr(Offset).consumeInteger(10, Version);
5263 if (Failure || Version < 7)
5264 D.Diag(diag::err_target_unsupported_arch) << Triple.getArchName()
5274 if (Triple.isSPIR() || Triple.isSPIRV())
5275 CmdArgs.push_back(
"-Wspir-compat");
5278 RewriteKind rewriteKind = RK_None;
5280 bool UnifiedLTO =
false;
5282 UnifiedLTO = Args.hasFlag(options::OPT_funified_lto,
5283 options::OPT_fno_unified_lto, Triple.isPS());
5285 CmdArgs.push_back(
"-funified-lto");
5295 if (!isa<AssembleJobAction>(JA)) {
5299 Args.ClaimAllArgs(options::OPT_mrelax_all);
5300 Args.ClaimAllArgs(options::OPT_mno_relax_all);
5301 Args.ClaimAllArgs(options::OPT_mincremental_linker_compatible);
5302 Args.ClaimAllArgs(options::OPT_mno_incremental_linker_compatible);
5303 switch (
C.getDefaultToolChain().getArch()) {
5304 case llvm::Triple::arm:
5305 case llvm::Triple::armeb:
5306 case llvm::Triple::thumb:
5307 case llvm::Triple::thumbeb:
5308 Args.ClaimAllArgs(options::OPT_mimplicit_it_EQ);
5314 Args.ClaimAllArgs(options::OPT_Wa_COMMA);
5315 Args.ClaimAllArgs(options::OPT_Xassembler);
5316 Args.ClaimAllArgs(options::OPT_femit_dwarf_unwind_EQ);
5319 if (isa<AnalyzeJobAction>(JA)) {
5320 assert(JA.
getType() == types::TY_Plist &&
"Invalid output type.");
5321 CmdArgs.push_back(
"-analyze");
5322 }
else if (isa<MigrateJobAction>(JA)) {
5323 CmdArgs.push_back(
"-migrate");
5324 }
else if (isa<PreprocessJobAction>(JA)) {
5325 if (Output.
getType() == types::TY_Dependencies)
5326 CmdArgs.push_back(
"-Eonly");
5328 CmdArgs.push_back(
"-E");
5329 if (Args.hasArg(options::OPT_rewrite_objc) &&
5330 !Args.hasArg(options::OPT_g_Group))
5331 CmdArgs.push_back(
"-P");
5332 else if (JA.
getType() == types::TY_PP_CXXHeaderUnit)
5333 CmdArgs.push_back(
"-fdirectives-only");
5335 }
else if (isa<AssembleJobAction>(JA)) {
5336 CmdArgs.push_back(
"-emit-obj");
5341 (void)Args.hasArg(options::OPT_force__cpusubtype__ALL);
5342 }
else if (isa<PrecompileJobAction>(JA)) {
5343 if (JA.
getType() == types::TY_Nothing)
5344 CmdArgs.push_back(
"-fsyntax-only");
5345 else if (JA.
getType() == types::TY_ModuleFile)
5346 CmdArgs.push_back(
"-emit-module-interface");
5347 else if (JA.
getType() == types::TY_HeaderUnit)
5348 CmdArgs.push_back(
"-emit-header-unit");
5350 CmdArgs.push_back(
"-emit-pch");
5351 }
else if (isa<VerifyPCHJobAction>(JA)) {
5352 CmdArgs.push_back(
"-verify-pch");
5353 }
else if (isa<ExtractAPIJobAction>(JA)) {
5354 assert(JA.
getType() == types::TY_API_INFO &&
5355 "Extract API actions must generate a API information.");
5356 CmdArgs.push_back(
"-extract-api");
5358 if (Arg *PrettySGFArg = Args.getLastArg(options::OPT_emit_pretty_sgf))
5359 PrettySGFArg->render(Args, CmdArgs);
5361 Arg *SymbolGraphDirArg = Args.getLastArg(options::OPT_symbol_graph_dir_EQ);
5363 if (Arg *ProductNameArg = Args.getLastArg(options::OPT_product_name_EQ))
5364 ProductNameArg->render(Args, CmdArgs);
5365 if (Arg *ExtractAPIIgnoresFileArg =
5366 Args.getLastArg(options::OPT_extract_api_ignores_EQ))
5367 ExtractAPIIgnoresFileArg->render(Args, CmdArgs);
5368 if (Arg *EmitExtensionSymbolGraphs =
5369 Args.getLastArg(options::OPT_emit_extension_symbol_graphs)) {
5370 if (!SymbolGraphDirArg)
5371 D.Diag(diag::err_drv_missing_symbol_graph_dir);
5373 EmitExtensionSymbolGraphs->render(Args, CmdArgs);
5375 if (SymbolGraphDirArg)
5376 SymbolGraphDirArg->render(Args, CmdArgs);
5378 assert((isa<CompileJobAction>(JA) || isa<BackendJobAction>(JA)) &&
5379 "Invalid action for clang tool.");
5380 if (JA.
getType() == types::TY_Nothing) {
5381 CmdArgs.push_back(
"-fsyntax-only");
5382 }
else if (JA.
getType() == types::TY_LLVM_IR ||
5383 JA.
getType() == types::TY_LTO_IR) {
5384 CmdArgs.push_back(
"-emit-llvm");
5385 }
else if (JA.
getType() == types::TY_LLVM_BC ||
5386 JA.
getType() == types::TY_LTO_BC) {
5388 if (Triple.isAMDGCN() && IsOpenMPDevice && Args.hasArg(options::OPT_S) &&
5389 Args.hasArg(options::OPT_emit_llvm)) {
5390 CmdArgs.push_back(
"-emit-llvm");
5392 CmdArgs.push_back(
"-emit-llvm-bc");
5394 }
else if (JA.
getType() == types::TY_IFS ||
5395 JA.
getType() == types::TY_IFS_CPP) {
5397 Args.hasArg(options::OPT_interface_stub_version_EQ)
5398 ? Args.getLastArgValue(options::OPT_interface_stub_version_EQ)
5400 CmdArgs.push_back(
"-emit-interface-stubs");
5402 Args.MakeArgString(Twine(
"-interface-stub-version=") + ArgStr.str()));
5403 }
else if (JA.
getType() == types::TY_PP_Asm) {
5404 CmdArgs.push_back(
"-S");
5405 }
else if (JA.
getType() == types::TY_AST) {
5406 CmdArgs.push_back(
"-emit-pch");
5407 }
else if (JA.
getType() == types::TY_ModuleFile) {
5408 CmdArgs.push_back(
"-module-file-info");
5409 }
else if (JA.
getType() == types::TY_RewrittenObjC) {
5410 CmdArgs.push_back(
"-rewrite-objc");
5411 rewriteKind = RK_NonFragile;
5412 }
else if (JA.
getType() == types::TY_RewrittenLegacyObjC) {
5413 CmdArgs.push_back(
"-rewrite-objc");
5414 rewriteKind = RK_Fragile;
5415 }
else if (JA.
getType() == types::TY_CIR) {
5416 CmdArgs.push_back(
"-emit-cir");
5418 assert(JA.
getType() == types::TY_PP_Asm &&
"Unexpected output type!");
5425 if (JA.
getType() == types::TY_LLVM_BC)
5426 CmdArgs.push_back(
"-emit-llvm-uselists");
5430 !Args.hasFlag(options::OPT_offload_new_driver,
5431 options::OPT_no_offload_new_driver,
5433 !Triple.isAMDGPU()) {
5434 D.Diag(diag::err_drv_unsupported_opt_for_target)
5435 << Args.getLastArg(options::OPT_foffload_lto,
5436 options::OPT_foffload_lto_EQ)
5438 << Triple.getTriple();
5439 }
else if (Triple.isNVPTX() && !IsRDCMode &&
5441 D.Diag(diag::err_drv_unsupported_opt_for_language_mode)
5442 << Args.getLastArg(options::OPT_foffload_lto,
5443 options::OPT_foffload_lto_EQ)
5448 CmdArgs.push_back(Args.MakeArgString(
5449 Twine(
"-flto=") + (LTOMode ==
LTOK_Thin ?
"thin" :
"full")));
5452 if (!RawTriple.isPS4() ||
5453 (
D.getLTOMode() ==
LTOK_Full) || !UnifiedLTO)
5454 CmdArgs.push_back(
"-flto-unit");
5459 Args.AddLastArg(CmdArgs, options::OPT_dumpdir);
5461 if (
const Arg *A = Args.getLastArg(options::OPT_fthinlto_index_EQ)) {
5463 D.Diag(diag::err_drv_arg_requires_bitcode_input) << A->getAsString(Args);
5464 Args.AddLastArg(CmdArgs, options::OPT_fthinlto_index_EQ);
5468 Args.addOptInFlag(CmdArgs, options::OPT_mregnames,
5469 options::OPT_mno_regnames);
5471 if (Args.getLastArg(options::OPT_fthin_link_bitcode_EQ))
5472 Args.AddLastArg(CmdArgs, options::OPT_fthin_link_bitcode_EQ);
5474 if (Args.getLastArg(options::OPT_save_temps_EQ))
5475 Args.AddLastArg(CmdArgs, options::OPT_save_temps_EQ);
5477 auto *MemProfArg = Args.getLastArg(options::OPT_fmemory_profile,
5478 options::OPT_fmemory_profile_EQ,
5479 options::OPT_fno_memory_profile);
5481 !MemProfArg->getOption().matches(options::OPT_fno_memory_profile))
5482 MemProfArg->render(Args, CmdArgs);
5484 if (
auto *MemProfUseArg =
5485 Args.getLastArg(options::OPT_fmemory_profile_use_EQ)) {
5487 D.Diag(diag::err_drv_argument_not_allowed_with)
5488 << MemProfUseArg->getAsString(Args) << MemProfArg->getAsString(Args);
5489 if (
auto *PGOInstrArg = Args.getLastArg(options::OPT_fprofile_generate,
5490 options::OPT_fprofile_generate_EQ))
5491 D.Diag(diag::err_drv_argument_not_allowed_with)
5492 << MemProfUseArg->getAsString(Args) << PGOInstrArg->getAsString(Args);
5493 MemProfUseArg->render(Args, CmdArgs);
5498 if (
C.getDriver().embedBitcodeInObject() && !IsUsingLTO &&
5499 (isa<BackendJobAction>(JA) || isa<AssembleJobAction>(JA))) {
5501 Args.AddLastArg(CmdArgs, options::OPT_fembed_bitcode_EQ);
5503 CmdArgs.push_back(
"-disable-llvm-passes");
5510 static const constexpr unsigned kBitcodeOptionIgnorelist[] = {
5511 options::OPT_mkernel,
5512 options::OPT_fapple_kext,
5513 options::OPT_ffunction_sections,
5514 options::OPT_fno_function_sections,
5515 options::OPT_fdata_sections,
5516 options::OPT_fno_data_sections,
5517 options::OPT_fbasic_block_sections_EQ,
5518 options::OPT_funique_internal_linkage_names,
5519 options::OPT_fno_unique_internal_linkage_names,
5520 options::OPT_funique_section_names,
5521 options::OPT_fno_unique_section_names,
5522 options::OPT_funique_basic_block_section_names,
5523 options::OPT_fno_unique_basic_block_section_names,
5524 options::OPT_mrestrict_it,
5525 options::OPT_mno_restrict_it,
5526 options::OPT_mstackrealign,
5527 options::OPT_mno_stackrealign,
5528 options::OPT_mstack_alignment,
5529 options::OPT_mcmodel_EQ,
5530 options::OPT_mlong_calls,
5531 options::OPT_mno_long_calls,
5532 options::OPT_ggnu_pubnames,
5533 options::OPT_gdwarf_aranges,
5534 options::OPT_fdebug_types_section,
5535 options::OPT_fno_debug_types_section,
5536 options::OPT_fdwarf_directory_asm,
5537 options::OPT_fno_dwarf_directory_asm,
5538 options::OPT_mrelax_all,
5539 options::OPT_mno_relax_all,
5540 options::OPT_ftrap_function_EQ,
5541 options::OPT_ffixed_r9,
5542 options::OPT_mfix_cortex_a53_835769,
5543 options::OPT_mno_fix_cortex_a53_835769,
5544 options::OPT_ffixed_x18,
5545 options::OPT_mglobal_merge,
5546 options::OPT_mno_global_merge,
5547 options::OPT_mred_zone,
5548 options::OPT_mno_red_zone,
5549 options::OPT_Wa_COMMA,
5550 options::OPT_Xassembler,
5553 for (
const auto &A : Args)
5554 if (llvm::is_contained(kBitcodeOptionIgnorelist, A->getOption().getID()))
5555 D.Diag(diag::err_drv_unsupported_embed_bitcode) << A->getSpelling();
5558 Args.addOptOutFlag(CmdArgs, options::OPT_foptimize_sibling_calls,
5559 options::OPT_fno_optimize_sibling_calls);
5567 case llvm::Triple::arm:
5568 case llvm::Triple::armeb:
5569 case llvm::Triple::thumbeb:
5570 RenderARMABI(
D, Triple, Args, CmdArgs);
5572 case llvm::Triple::aarch64:
5573 case llvm::Triple::aarch64_32:
5574 case llvm::Triple::aarch64_be:
5575 RenderAArch64ABI(Triple, Args, CmdArgs);
5580 if (
const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
5581 if (A->getOption().matches(options::OPT_O4)) {
5582 CmdArgs.push_back(
"-O3");
5583 D.Diag(diag::warn_O4_is_O3);
5585 A->render(Args, CmdArgs);
5590 if (Output.
getType() == types::TY_Dependencies) {
5593 CmdArgs.push_back(
"-o");
5596 assert(Output.
isNothing() &&
"Input output.");
5599 for (
const auto &II : Inputs) {
5601 if (II.isFilename())
5602 CmdArgs.push_back(II.getFilename());
5604 II.getInputArg().renderAsInput(Args, CmdArgs);
5607 C.addCommand(std::make_unique<Command>(
5609 CmdArgs, Inputs, Output,
D.getPrependArg()));
5613 if (
C.getDriver().embedBitcodeMarkerOnly() && !IsUsingLTO)
5614 CmdArgs.push_back(
"-fembed-bitcode=marker");
5619 if (!
C.isForDiagnostics())
5620 CmdArgs.push_back(
"-disable-free");
5621 CmdArgs.push_back(
"-clear-ast-before-backend");
5624 const bool IsAssertBuild =
false;
5626 const bool IsAssertBuild =
true;
5630 if (Args.hasFlag(options::OPT_fno_verify_intermediate_code,
5631 options::OPT_fverify_intermediate_code, !IsAssertBuild)) {
5632 CmdArgs.push_back(
"-disable-llvm-verifier");
5636 if (Args.hasFlag(options::OPT_fdiscard_value_names,
5637 options::OPT_fno_discard_value_names, !IsAssertBuild)) {
5638 if (Args.hasArg(options::OPT_fdiscard_value_names) &&
5640 return types::isLLVMIR(II.getType());
5642 D.Diag(diag::warn_ignoring_fdiscard_for_bitcode);
5644 CmdArgs.push_back(
"-discard-value-names");
5649 CmdArgs.push_back(
"-main-file-name");
5654 if (Args.hasArg(options::OPT_static))
5655 CmdArgs.push_back(
"-static-define");
5657 if (Args.hasArg(options::OPT_municode))
5658 CmdArgs.push_back(
"-DUNICODE");
5660 if (isa<AnalyzeJobAction>(JA))
5663 if (isa<AnalyzeJobAction>(JA) ||
5664 (isa<PreprocessJobAction>(JA) && Args.hasArg(options::OPT__analyze)))
5665 CmdArgs.push_back(
"-setup-static-analyzer");
5670 bool FoundAnalyzerConfig =
false;
5671 for (
auto *Arg : Args.filtered(options::OPT_Xclang))
5672 if (StringRef(Arg->getValue()) ==
"-analyzer-config") {
5673 FoundAnalyzerConfig =
true;
5676 if (!FoundAnalyzerConfig)
5677 for (
auto *Arg : Args.filtered(options::OPT_Xanalyzer))
5678 if (StringRef(Arg->getValue()) ==
"-analyzer-config") {
5679 FoundAnalyzerConfig =
true;
5682 if (FoundAnalyzerConfig)
5683 CmdArgs.push_back(
"-analyzer-config-compatibility-mode=true");
5688 assert(FunctionAlignment <= 31 &&
"function alignment will be truncated!");
5689 if (FunctionAlignment) {
5690 CmdArgs.push_back(
"-function-alignment");
5691 CmdArgs.push_back(Args.MakeArgString(std::to_string(FunctionAlignment)));
5696 if (
const Arg *A = Args.getLastArg(options::OPT_falign_loops_EQ)) {
5698 if (StringRef(A->getValue()).getAsInteger(10,
Value) ||
Value > 65536)
5700 << A->getAsString(Args) << A->getValue();
5702 TC.
getDriver().
Diag(diag::err_drv_alignment_not_power_of_two)
5703 << A->getAsString(Args) << A->getValue();
5706 CmdArgs.push_back(Args.MakeArgString(
"-falign-loops=" +
5707 Twine(std::min(
Value, 65536u))));
5710 if (Triple.isOSzOS()) {
5719 auto findMacroDefinition = [&](
const std::string &Macro) {
5720 auto MacroDefs = Args.getAllArgValues(options::OPT_D);
5721 return llvm::any_of(MacroDefs, [&](
const std::string &M) {
5722 return M == Macro || M.find(Macro +
'=') != std::string::npos;
5727 if (!findMacroDefinition(
"_UNIX03_WITHDRAWN"))
5728 CmdArgs.push_back(
"-D_UNIX03_WITHDRAWN");
5730 if (!findMacroDefinition(
"_OPEN_DEFAULT"))
5731 CmdArgs.push_back(
"-D_OPEN_DEFAULT");
5734 if (!findMacroDefinition(
"_XOPEN_SOURCE"))
5735 CmdArgs.push_back(
"-D_XOPEN_SOURCE=600");
5739 llvm::Reloc::Model RelocationModel;
5742 std::tie(RelocationModel, PICLevel, IsPIE) =
ParsePICArgs(TC, Args);
5743 Arg *LastPICDataRelArg =
5744 Args.getLastArg(options::OPT_mno_pic_data_is_text_relative,
5745 options::OPT_mpic_data_is_text_relative);
5746 bool NoPICDataIsTextRelative =
false;
5747 if (LastPICDataRelArg) {
5748 if (LastPICDataRelArg->getOption().matches(
5749 options::OPT_mno_pic_data_is_text_relative)) {
5750 NoPICDataIsTextRelative =
true;
5752 D.Diag(diag::err_drv_argument_only_allowed_with)
5753 <<
"-mno-pic-data-is-text-relative"
5756 if (!Triple.isSystemZ())
5757 D.Diag(diag::err_drv_unsupported_opt_for_target)
5758 << (NoPICDataIsTextRelative ?
"-mno-pic-data-is-text-relative"
5759 :
"-mpic-data-is-text-relative")
5763 bool IsROPI = RelocationModel == llvm::Reloc::ROPI ||
5764 RelocationModel == llvm::Reloc::ROPI_RWPI;
5765 bool IsRWPI = RelocationModel == llvm::Reloc::RWPI ||
5766 RelocationModel == llvm::Reloc::ROPI_RWPI;
5768 if (Args.hasArg(options::OPT_mcmse) &&
5769 !Args.hasArg(options::OPT_fallow_unsupported)) {
5771 D.Diag(diag::err_cmse_pi_are_incompatible) << IsROPI;
5773 D.Diag(diag::err_cmse_pi_are_incompatible) << !IsRWPI;
5777 !Args.hasArg(options::OPT_fallow_unsupported))
5778 D.Diag(diag::err_drv_ropi_incompatible_with_cxx);
5782 CmdArgs.push_back(
"-mrelocation-model");
5783 CmdArgs.push_back(RMName);
5786 CmdArgs.push_back(
"-pic-level");
5787 CmdArgs.push_back(PICLevel == 1 ?
"1" :
"2");
5789 CmdArgs.push_back(
"-pic-is-pie");
5790 if (NoPICDataIsTextRelative)
5791 CmdArgs.push_back(
"-mcmodel=medium");
5794 if (RelocationModel == llvm::Reloc::ROPI ||
5795 RelocationModel == llvm::Reloc::ROPI_RWPI)
5796 CmdArgs.push_back(
"-fropi");
5797 if (RelocationModel == llvm::Reloc::RWPI ||
5798 RelocationModel == llvm::Reloc::ROPI_RWPI)
5799 CmdArgs.push_back(
"-frwpi");
5801 if (Arg *A = Args.getLastArg(options::OPT_meabi)) {
5802 CmdArgs.push_back(
"-meabi");
5803 CmdArgs.push_back(A->getValue());
5817 if (Triple.isOSBinFormatELF()) {
5818 Arg *A = Args.getLastArg(options::OPT_fsemantic_interposition,
5819 options::OPT_fno_semantic_interposition);
5820 if (RelocationModel != llvm::Reloc::Static && !IsPIE) {
5822 bool SupportsLocalAlias =
5823 Triple.isAArch64() || Triple.isRISCV() || Triple.isX86();
5825 CmdArgs.push_back(
"-fhalf-no-semantic-interposition");
5826 else if (A->getOption().matches(options::OPT_fsemantic_interposition))
5827 A->render(Args, CmdArgs);
5828 else if (!SupportsLocalAlias)
5829 CmdArgs.push_back(
"-fhalf-no-semantic-interposition");
5835 if (Arg *A = Args.getLastArg(options::OPT_mthread_model)) {
5837 D.Diag(diag::err_drv_invalid_thread_model_for_target)
5838 << A->getValue() << A->getAsString(Args);
5839 Model = A->getValue();
5842 if (Model !=
"posix") {
5843 CmdArgs.push_back(
"-mthread-model");
5844 CmdArgs.push_back(Args.MakeArgString(Model));
5848 if (Arg *A = Args.getLastArg(options::OPT_fveclib)) {
5849 StringRef Name = A->getValue();
5850 if (Name ==
"SVML") {
5851 if (Triple.getArch() != llvm::Triple::x86 &&
5852 Triple.getArch() != llvm::Triple::x86_64)
5853 D.Diag(diag::err_drv_unsupported_opt_for_target)
5854 << Name << Triple.getArchName();
5855 }
else if (Name ==
"LIBMVEC-X86") {
5856 if (Triple.getArch() != llvm::Triple::x86 &&
5857 Triple.getArch() != llvm::Triple::x86_64)
5858 D.Diag(diag::err_drv_unsupported_opt_for_target)
5859 << Name << Triple.getArchName();
5860 }
else if (Name ==
"SLEEF" || Name ==
"ArmPL") {
5861 if (Triple.getArch() != llvm::Triple::aarch64 &&
5862 Triple.getArch() != llvm::Triple::aarch64_be &&
5863 Triple.getArch() != llvm::Triple::riscv64)
5864 D.Diag(diag::err_drv_unsupported_opt_for_target)
5865 << Name << Triple.getArchName();
5867 A->render(Args, CmdArgs);
5870 if (Args.hasFlag(options::OPT_fmerge_all_constants,
5871 options::OPT_fno_merge_all_constants,
false))
5872 CmdArgs.push_back(
"-fmerge-all-constants");
5874 Args.addOptOutFlag(CmdArgs, options::OPT_fdelete_null_pointer_checks,
5875 options::OPT_fno_delete_null_pointer_checks);
5879 if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ_quadword_atomics)) {
5880 if (!Triple.isOSAIX() || Triple.isPPC32())
5881 D.Diag(diag::err_drv_unsupported_opt_for_target)
5882 << A->getSpelling() << RawTriple.str();
5883 CmdArgs.push_back(
"-mabi=quadword-atomics");
5886 if (Arg *A = Args.getLastArg(options::OPT_mlong_double_128)) {
5889 if (Triple.isOSAIX())
5890 D.Diag(diag::err_drv_unsupported_opt_for_target)
5891 << A->getSpelling() << RawTriple.str();
5894 if (Arg *A = Args.getLastArg(options::OPT_Wframe_larger_than_EQ)) {
5895 StringRef
V = A->getValue(), V1 =
V;
5897 if (V1.consumeInteger(10, Size) || !V1.empty())
5898 D.Diag(diag::err_drv_invalid_argument_to_option)
5899 <<
V << A->getOption().getName();
5901 CmdArgs.push_back(Args.MakeArgString(
"-fwarn-stack-size=" +
V));
5904 Args.addOptOutFlag(CmdArgs, options::OPT_fjump_tables,
5905 options::OPT_fno_jump_tables);
5906 Args.addOptInFlag(CmdArgs, options::OPT_fprofile_sample_accurate,
5907 options::OPT_fno_profile_sample_accurate);
5908 Args.addOptOutFlag(CmdArgs, options::OPT_fpreserve_as_comments,
5909 options::OPT_fno_preserve_as_comments);
5911 if (Arg *A = Args.getLastArg(options::OPT_mregparm_EQ)) {
5912 CmdArgs.push_back(
"-mregparm");
5913 CmdArgs.push_back(A->getValue());
5916 if (Arg *A = Args.getLastArg(options::OPT_maix_struct_return,
5917 options::OPT_msvr4_struct_return)) {
5919 D.Diag(diag::err_drv_unsupported_opt_for_target)
5920 << A->getSpelling() << RawTriple.str();
5921 }
else if (A->getOption().matches(options::OPT_maix_struct_return)) {
5922 CmdArgs.push_back(
"-maix-struct-return");
5924 assert(A->getOption().matches(options::OPT_msvr4_struct_return));
5925 CmdArgs.push_back(
"-msvr4-struct-return");
5929 if (Arg *A = Args.getLastArg(options::OPT_fpcc_struct_return,
5930 options::OPT_freg_struct_return)) {
5931 if (TC.
getArch() != llvm::Triple::x86) {
5932 D.Diag(diag::err_drv_unsupported_opt_for_target)
5933 << A->getSpelling() << RawTriple.str();
5934 }
else if (A->getOption().matches(options::OPT_fpcc_struct_return)) {
5935 CmdArgs.push_back(
"-fpcc-struct-return");
5937 assert(A->getOption().matches(options::OPT_freg_struct_return));
5938 CmdArgs.push_back(
"-freg-struct-return");
5942 if (Args.hasFlag(options::OPT_mrtd, options::OPT_mno_rtd,
false)) {
5943 if (Triple.getArch() == llvm::Triple::m68k)
5944 CmdArgs.push_back(
"-fdefault-calling-conv=rtdcall");
5946 CmdArgs.push_back(
"-fdefault-calling-conv=stdcall");
5949 if (Args.hasArg(options::OPT_fenable_matrix)) {
5951 CmdArgs.push_back(
"-fenable-matrix");
5952 CmdArgs.push_back(
"-mllvm");
5953 CmdArgs.push_back(
"-enable-matrix");
5958 const char *FPKeepKindStr =
nullptr;
5959 switch (FPKeepKind) {
5961 FPKeepKindStr =
"-mframe-pointer=none";
5964 FPKeepKindStr =
"-mframe-pointer=reserved";
5967 FPKeepKindStr =
"-mframe-pointer=non-leaf";
5970 FPKeepKindStr =
"-mframe-pointer=all";
5973 assert(FPKeepKindStr &&
"unknown FramePointerKind");
5974 CmdArgs.push_back(FPKeepKindStr);
5976 Args.addOptOutFlag(CmdArgs, options::OPT_fzero_initialized_in_bss,
5977 options::OPT_fno_zero_initialized_in_bss);
5981 D.Diag(diag::warn_drv_deprecated_arg_ofast);
5984 OptSpecifier StrictAliasingAliasOption =
5985 OFastEnabled ? options::OPT_Ofast : options::OPT_fstrict_aliasing;
5988 if (!Args.hasFlag(options::OPT_fstrict_aliasing, StrictAliasingAliasOption,
5989 options::OPT_fno_strict_aliasing, !IsWindowsMSVC))
5990 CmdArgs.push_back(
"-relaxed-aliasing");
5991 if (Args.hasFlag(options::OPT_fno_pointer_tbaa, options::OPT_fpointer_tbaa,
5993 CmdArgs.push_back(
"-no-pointer-tbaa");
5994 if (!Args.hasFlag(options::OPT_fstruct_path_tbaa,
5995 options::OPT_fno_struct_path_tbaa,
true))
5996 CmdArgs.push_back(
"-no-struct-path-tbaa");
5997 Args.addOptInFlag(CmdArgs, options::OPT_fstrict_enums,
5998 options::OPT_fno_strict_enums);
5999 Args.addOptOutFlag(CmdArgs, options::OPT_fstrict_return,
6000 options::OPT_fno_strict_return);
6001 Args.addOptInFlag(CmdArgs, options::OPT_fallow_editor_placeholders,
6002 options::OPT_fno_allow_editor_placeholders);
6003 Args.addOptInFlag(CmdArgs, options::OPT_fstrict_vtable_pointers,
6004 options::OPT_fno_strict_vtable_pointers);
6005 Args.addOptInFlag(CmdArgs, options::OPT_fforce_emit_vtables,
6006 options::OPT_fno_force_emit_vtables);
6007 Args.addOptOutFlag(CmdArgs, options::OPT_foptimize_sibling_calls,
6008 options::OPT_fno_optimize_sibling_calls);
6009 Args.addOptOutFlag(CmdArgs, options::OPT_fescaping_block_tail_calls,
6010 options::OPT_fno_escaping_block_tail_calls);
6012 Args.AddLastArg(CmdArgs, options::OPT_ffine_grained_bitfield_accesses,
6013 options::OPT_fno_fine_grained_bitfield_accesses);
6015 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_relative_cxx_abi_vtables,
6016 options::OPT_fno_experimental_relative_cxx_abi_vtables);
6018 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_omit_vtable_rtti,
6019 options::OPT_fno_experimental_omit_vtable_rtti);
6021 Args.AddLastArg(CmdArgs, options::OPT_fdisable_block_signature_string,
6022 options::OPT_fno_disable_block_signature_string);
6025 Args.addOptInFlag(CmdArgs, options::OPT_fsplit_stack,
6026 options::OPT_fno_split_stack);
6029 if (Args.hasFlag(options::OPT_fprotect_parens,
6030 options::OPT_fno_protect_parens,
false))
6031 CmdArgs.push_back(
"-fprotect-parens");
6035 if (Arg *A = Args.getLastArg(options::OPT_fextend_args_EQ)) {
6036 const llvm::Triple::ArchType Arch = TC.
getArch();
6037 if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64) {
6038 StringRef
V = A->getValue();
6040 CmdArgs.push_back(
"-fextend-arguments=64");
6042 D.Diag(diag::err_drv_invalid_argument_to_option)
6043 << A->getValue() << A->getOption().getName();
6045 D.Diag(diag::err_drv_unsupported_opt_for_target)
6046 << A->getOption().getName() << TripleStr;
6049 if (Arg *A = Args.getLastArg(options::OPT_mdouble_EQ)) {
6050 if (TC.
getArch() == llvm::Triple::avr)
6051 A->render(Args, CmdArgs);
6053 D.Diag(diag::err_drv_unsupported_opt_for_target)
6054 << A->getAsString(Args) << TripleStr;
6057 if (Arg *A = Args.getLastArg(options::OPT_LongDouble_Group)) {
6059 A->render(Args, CmdArgs);
6061 (A->getOption().getID() != options::OPT_mlong_double_80))
6062 A->render(Args, CmdArgs);
6064 D.Diag(diag::err_drv_unsupported_opt_for_target)
6065 << A->getAsString(Args) << TripleStr;
6071 if (!Args.hasFlag(options::OPT_fverbose_asm, options::OPT_fno_verbose_asm,
6072 IsIntegratedAssemblerDefault))
6073 CmdArgs.push_back(
"-fno-verbose-asm");
6077 if (Arg *A = Args.getLastArg(options::OPT_fbinutils_version_EQ)) {
6078 StringRef
V = A->getValue();
6081 A->render(Args, CmdArgs);
6082 else if (!
V.consumeInteger(10,
Num) &&
Num > 0 &&
6083 (
V.empty() || (
V.consume_front(
".") &&
6084 !
V.consumeInteger(10,
Num) &&
V.empty())))
6085 A->render(Args, CmdArgs);
6087 D.Diag(diag::err_drv_invalid_argument_to_option)
6088 << A->getValue() << A->getOption().getName();
6094 CmdArgs.push_back(
"-no-integrated-as");
6096 if (Args.hasArg(options::OPT_fdebug_pass_structure)) {
6097 CmdArgs.push_back(
"-mdebug-pass");
6098 CmdArgs.push_back(
"Structure");
6100 if (Args.hasArg(options::OPT_fdebug_pass_arguments)) {
6101 CmdArgs.push_back(
"-mdebug-pass");
6102 CmdArgs.push_back(
"Arguments");
6108 if (!RawTriple.isOSDarwin() && !RawTriple.isNVPTX())
6109 CmdArgs.push_back(
"-mconstructor-aliases");
6113 if (KernelOrKext && RawTriple.isOSDarwin())
6114 CmdArgs.push_back(
"-fforbid-guard-variables");
6116 if (Args.hasFlag(options::OPT_mms_bitfields, options::OPT_mno_ms_bitfields,
6117 Triple.isWindowsGNUEnvironment())) {
6118 CmdArgs.push_back(
"-mms-bitfields");
6121 if (Triple.isWindowsGNUEnvironment()) {
6122 Args.addOptOutFlag(CmdArgs, options::OPT_fauto_import,
6123 options::OPT_fno_auto_import);
6126 if (Args.hasFlag(options::OPT_fms_volatile, options::OPT_fno_ms_volatile,
6127 Triple.isX86() && IsWindowsMSVC))
6128 CmdArgs.push_back(
"-fms-volatile");
6133 if (Arg *A = Args.getLastArg(options::OPT_fdirect_access_external_data,
6134 options::OPT_fno_direct_access_external_data)) {
6135 if (A->getOption().matches(options::OPT_fdirect_access_external_data) !=
6137 A->render(Args, CmdArgs);
6138 }
else if (PICLevel == 0 && Triple.isLoongArch()) {
6141 CmdArgs.push_back(
"-fno-direct-access-external-data");
6144 if (Args.hasFlag(options::OPT_fno_plt, options::OPT_fplt,
false)) {
6145 CmdArgs.push_back(
"-fno-plt");
6152 Args.hasFlag(options::OPT_ffreestanding, options::OPT_fhosted,
false) ||
6155 CmdArgs.push_back(
"-ffreestanding");
6157 Args.AddLastArg(CmdArgs, options::OPT_fno_knr_functions);
6164 bool IsAsyncUnwindTablesDefault =
6166 bool IsSyncUnwindTablesDefault =
6169 bool AsyncUnwindTables = Args.hasFlag(
6170 options::OPT_fasynchronous_unwind_tables,
6171 options::OPT_fno_asynchronous_unwind_tables,
6172 (IsAsyncUnwindTablesDefault || SanitizeArgs.needsUnwindTables()) &&
6175 Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables,
6176 IsSyncUnwindTablesDefault && !Freestanding);
6177 if (AsyncUnwindTables)
6178 CmdArgs.push_back(
"-funwind-tables=2");
6179 else if (UnwindTables)
6180 CmdArgs.push_back(
"-funwind-tables=1");
6184 if (!Args.getLastArg(options::OPT_gpu_use_aux_triple_only) &&
6185 (IsCudaDevice || IsHIPDevice || IsSYCLDevice)) {
6186 const ArgList &HostArgs =
6188 std::string HostCPU =
6190 if (!HostCPU.empty()) {
6191 CmdArgs.push_back(
"-aux-target-cpu");
6192 CmdArgs.push_back(Args.MakeArgString(HostCPU));
6200 addMCModel(
D, Args, Triple, RelocationModel, CmdArgs);
6202 if (Arg *A = Args.getLastArg(options::OPT_mtls_size_EQ)) {
6203 StringRef
Value = A->getValue();
6204 unsigned TLSSize = 0;
6205 Value.getAsInteger(10, TLSSize);
6206 if (!Triple.isAArch64() || !Triple.isOSBinFormatELF())
6207 D.Diag(diag::err_drv_unsupported_opt_for_target)
6208 << A->getOption().getName() << TripleStr;
6209 if (TLSSize != 12 && TLSSize != 24 && TLSSize != 32 && TLSSize != 48)
6210 D.Diag(diag::err_drv_invalid_int_value)
6211 << A->getOption().getName() <<
Value;
6212 Args.AddLastArg(CmdArgs, options::OPT_mtls_size_EQ);
6216 CmdArgs.push_back(
"-enable-tlsdesc");
6219 std::string CPU =
getCPUName(
D, Args, Triple,
false);
6221 CmdArgs.push_back(
"-target-cpu");
6222 CmdArgs.push_back(Args.MakeArgString(CPU));
6225 RenderTargetOptions(Triple, Args, KernelOrKext, CmdArgs);
6230 AddClangCLArgs(Args, InputType, CmdArgs);
6232 llvm::codegenoptions::DebugInfoKind DebugInfoKind =
6233 llvm::codegenoptions::NoDebugInfo;
6236 CmdArgs, Output, DebugInfoKind, DwarfFission);
6244 (isa<AssembleJobAction>(JA) || isa<CompileJobAction>(JA) ||
6245 isa<BackendJobAction>(JA));
6247 const char *SplitDWARFOut =
SplitDebugName(JA, Args, Input, Output);
6248 CmdArgs.push_back(
"-split-dwarf-file");
6249 CmdArgs.push_back(SplitDWARFOut);
6251 CmdArgs.push_back(
"-split-dwarf-output");
6252 CmdArgs.push_back(SplitDWARFOut);
6257 if (Arg *A = Args.getLastArg(options::OPT_mlinker_version_EQ)) {
6258 CmdArgs.push_back(
"-target-linker-version");
6259 CmdArgs.push_back(A->getValue());
6264 if (!Args.hasArg(options::OPT_fallow_unsupported)) {
6266 if (
types::isCXX(InputType) && RawTriple.isOSDarwin() &&
6267 TC.
getArch() == llvm::Triple::x86) {
6268 if ((Unsupported = Args.getLastArg(options::OPT_fapple_kext)) ||
6269 (Unsupported = Args.getLastArg(options::OPT_mkernel)))
6270 D.Diag(diag::err_drv_clang_unsupported_opt_cxx_darwin_i386)
6271 << Unsupported->getOption().getName();
6274 if ((Unsupported = Args.getLastArg(options::OPT_faltivec)))
6275 D.Diag(diag::err_drv_clang_unsupported_opt_faltivec)
6276 << Unsupported->getOption().getName()
6277 <<
"please use -maltivec and include altivec.h explicitly";
6278 if ((Unsupported = Args.getLastArg(options::OPT_fno_altivec)))
6279 D.Diag(diag::err_drv_clang_unsupported_opt_faltivec)
6280 << Unsupported->getOption().getName() <<
"please use -mno-altivec";
6283 Args.AddAllArgs(CmdArgs, options::OPT_v);
6285 if (Args.getLastArg(options::OPT_H)) {
6286 CmdArgs.push_back(
"-H");
6287 CmdArgs.push_back(
"-sys-header-deps");
6289 Args.AddAllArgs(CmdArgs, options::OPT_fshow_skipped_includes);
6291 if (
D.CCPrintHeadersFormat && !
D.CCGenDiagnostics) {
6292 CmdArgs.push_back(
"-header-include-file");
6293 CmdArgs.push_back(!
D.CCPrintHeadersFilename.empty()
6294 ?
D.CCPrintHeadersFilename.c_str()
6296 CmdArgs.push_back(
"-sys-header-deps");
6297 CmdArgs.push_back(Args.MakeArgString(
6298 "-header-include-format=" +
6301 Args.MakeArgString(
"-header-include-filtering=" +
6303 D.CCPrintHeadersFiltering))));
6305 Args.AddLastArg(CmdArgs, options::OPT_P);
6306 Args.AddLastArg(CmdArgs, options::OPT_print_ivar_layout);
6308 if (
D.CCLogDiagnostics && !
D.CCGenDiagnostics) {
6309 CmdArgs.push_back(
"-diagnostic-log-file");
6310 CmdArgs.push_back(!
D.CCLogDiagnosticsFilename.empty()
6311 ?
D.CCLogDiagnosticsFilename.c_str()
6317 if (
D.CCGenDiagnostics)
6318 CmdArgs.push_back(
"-disable-pragma-debug-crash");
6322 if (Args.hasArg(options::OPT_fcrash_diagnostics_dir)) {
6323 StringRef Dir = Args.getLastArgValue(options::OPT_fcrash_diagnostics_dir);
6324 CmdArgs.push_back(
"-mllvm");
6325 CmdArgs.push_back(Args.MakeArgString(
"-crash-diagnostics-dir=" + Dir));
6330 if (Args.hasFlag(options::OPT_ffunction_sections,
6331 options::OPT_fno_function_sections, UseSeparateSections)) {
6332 CmdArgs.push_back(
"-ffunction-sections");
6335 if (Arg *A = Args.getLastArg(options::OPT_fbasic_block_address_map,
6336 options::OPT_fno_basic_block_address_map)) {
6337 if ((Triple.isX86() || Triple.isAArch64()) && Triple.isOSBinFormatELF()) {
6338 if (A->getOption().matches(options::OPT_fbasic_block_address_map))
6339 A->render(Args, CmdArgs);
6341 D.Diag(diag::err_drv_unsupported_opt_for_target)
6342 << A->getAsString(Args) << TripleStr;
6346 if (Arg *A = Args.getLastArg(options::OPT_fbasic_block_sections_EQ)) {
6347 StringRef Val = A->getValue();
6348 if (Val ==
"labels") {
6349 D.Diag(diag::warn_drv_deprecated_arg)
6350 << A->getAsString(Args) <<
true
6351 <<
"-fbasic-block-address-map";
6352 CmdArgs.push_back(
"-fbasic-block-address-map");
6353 }
else if (Triple.isX86() && Triple.isOSBinFormatELF()) {
6354 if (Val !=
"all" && Val !=
"none" && !Val.starts_with(
"list="))
6355 D.Diag(diag::err_drv_invalid_value)
6356 << A->getAsString(Args) << A->getValue();
6358 A->render(Args, CmdArgs);
6359 }
else if (Triple.isAArch64() && Triple.isOSBinFormatELF()) {
6362 if (Val !=
"labels" && Val !=
"none" && !Val.starts_with(
"list="))
6363 D.Diag(diag::err_drv_invalid_value)
6364 << A->getAsString(Args) << A->getValue();
6366 A->render(Args, CmdArgs);
6367 }
else if (Triple.isNVPTX()) {
6370 }
else if (Val !=
"none") {
6373 D.Diag(diag::err_drv_unsupported_opt_for_target)
6374 << A->getAsString(Args) << TripleStr;
6378 bool HasDefaultDataSections = Triple.isOSBinFormatXCOFF();
6379 if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
6380 UseSeparateSections || HasDefaultDataSections)) {
6381 CmdArgs.push_back(
"-fdata-sections");
6384 Args.addOptOutFlag(CmdArgs, options::OPT_funique_section_names,
6385 options::OPT_fno_unique_section_names);
6386 Args.addOptInFlag(CmdArgs, options::OPT_fseparate_named_sections,
6387 options::OPT_fno_separate_named_sections);
6388 Args.addOptInFlag(CmdArgs, options::OPT_funique_internal_linkage_names,
6389 options::OPT_fno_unique_internal_linkage_names);
6390 Args.addOptInFlag(CmdArgs, options::OPT_funique_basic_block_section_names,
6391 options::OPT_fno_unique_basic_block_section_names);
6393 if (Arg *A = Args.getLastArg(options::OPT_fsplit_machine_functions,
6394 options::OPT_fno_split_machine_functions)) {
6395 if (!A->getOption().matches(options::OPT_fno_split_machine_functions)) {
6397 if ((Triple.isX86() || Triple.isAArch64()) && Triple.isOSBinFormatELF())
6398 A->render(Args, CmdArgs);
6400 D.Diag(diag::err_drv_unsupported_opt_for_target)
6401 << A->getAsString(Args) << TripleStr;
6405 Args.AddLastArg(CmdArgs, options::OPT_finstrument_functions,
6406 options::OPT_finstrument_functions_after_inlining,
6407 options::OPT_finstrument_function_entry_bare);
6408 Args.AddLastArg(CmdArgs, options::OPT_fconvergent_functions,
6409 options::OPT_fno_convergent_functions);
6414 if (!Triple.isNVPTX() && !Triple.isAMDGCN())
6417 Args.AddLastArg(CmdArgs, options::OPT_fclang_abi_compat_EQ);
6420 Args.hasArg(options::OPT_fsample_profile_use_profi)) {
6421 CmdArgs.push_back(
"-mllvm");
6422 CmdArgs.push_back(
"-sample-profile-use-profi");
6426 if (RawTriple.isPS() &&
6427 !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
6433 if (Args.hasArg(options::OPT_nostdinc)) {
6434 CmdArgs.push_back(
"-nostdsysteminc");
6435 CmdArgs.push_back(
"-nobuiltininc");
6437 if (Args.hasArg(options::OPT_nostdlibinc))
6438 CmdArgs.push_back(
"-nostdsysteminc");
6439 Args.AddLastArg(CmdArgs, options::OPT_nostdincxx);
6440 Args.AddLastArg(CmdArgs, options::OPT_nobuiltininc);
6444 CmdArgs.push_back(
"-resource-dir");
6445 CmdArgs.push_back(
D.ResourceDir.c_str());
6447 Args.AddLastArg(CmdArgs, options::OPT_working_directory);
6456 AddPreprocessingOptions(
C, JA,
D, Args, CmdArgs, Output, Inputs);
6462 Args.ClaimAllArgs(options::OPT_D);
6465 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
6466 if (A->getOption().matches(options::OPT_O4)) {
6467 CmdArgs.push_back(
"-O3");
6468 D.Diag(diag::warn_O4_is_O3);
6470 A->render(Args, CmdArgs);
6476 Args.filtered(options::OPT_clang_ignored_gcc_optimization_f_Group)) {
6477 D.Diag(diag::warn_ignored_gcc_optimization) << A->getAsString(Args);
6482 Args.filtered(options::OPT_clang_ignored_legacy_options_Group)) {
6483 D.Diag(diag::warn_ignored_clang_option) << A->getAsString(Args);
6489 Args.AddAllArgs(CmdArgs, options::OPT_R_Group);
6492 Args.filtered(options::OPT_W_Group, options::OPT__SLASH_wd)) {
6494 if (A->getOption().getID() == options::OPT__SLASH_wd) {
6495 unsigned WarningNumber;
6496 if (StringRef(A->getValue()).getAsInteger(10, WarningNumber)) {
6497 D.Diag(diag::err_drv_invalid_int_value)
6498 << A->getAsString(Args) << A->getValue();
6503 CmdArgs.push_back(Args.MakeArgString(
6508 A->render(Args, CmdArgs);
6511 Args.AddAllArgs(CmdArgs, options::OPT_Wsystem_headers_in_module_EQ);
6513 if (Args.hasFlag(options::OPT_pedantic, options::OPT_no_pedantic,
false))
6514 CmdArgs.push_back(
"-pedantic");
6515 Args.AddLastArg(CmdArgs, options::OPT_pedantic_errors);
6516 Args.AddLastArg(CmdArgs, options::OPT_w);
6518 Args.addOptInFlag(CmdArgs, options::OPT_ffixed_point,
6519 options::OPT_fno_fixed_point);
6521 if (Arg *A = Args.getLastArg(options::OPT_fcxx_abi_EQ))
6522 A->render(Args, CmdArgs);
6524 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_relative_cxx_abi_vtables,
6525 options::OPT_fno_experimental_relative_cxx_abi_vtables);
6527 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_omit_vtable_rtti,
6528 options::OPT_fno_experimental_omit_vtable_rtti);
6530 if (Arg *A = Args.getLastArg(options::OPT_ffuchsia_api_level_EQ))
6531 A->render(Args, CmdArgs);
6538 bool ImplyVCPPCVer =
false;
6539 bool ImplyVCPPCXXVer =
false;
6540 const Arg *
Std = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi);
6542 if (
Std->getOption().matches(options::OPT_ansi))
6544 CmdArgs.push_back(
"-std=c++98");
6546 CmdArgs.push_back(
"-std=c89");
6548 Std->render(Args, CmdArgs);
6551 if (Arg *A = Args.getLastArg(options::OPT_std_EQ, options::OPT_ansi,
6552 options::OPT_ftrigraphs,
6553 options::OPT_fno_trigraphs))
6555 A->render(Args, CmdArgs);
6564 if (!Args.hasArg(options::OPT__SLASH_std)) {
6565 Args.AddAllArgsTranslated(CmdArgs, options::OPT_std_default_EQ,
"-std=",
6568 ImplyVCPPCVer =
true;
6570 else if (IsWindowsMSVC)
6571 ImplyVCPPCXXVer =
true;
6573 Args.AddLastArg(CmdArgs, options::OPT_ftrigraphs,
6574 options::OPT_fno_trigraphs);
6590 Args.getLastArg(options::OPT_Wwrite_strings,
6591 options::OPT_Wno_write_strings, options::OPT_w);
6593 WriteStrings->getOption().matches(options::OPT_Wwrite_strings))
6594 CmdArgs.push_back(
"-fconst-strings");
6601 Args.hasFlag(options::OPT_Wdeprecated, options::OPT_Wno_deprecated,
6603 CmdArgs.push_back(
"-fdeprecated-macro");
6607 if (Arg *
Asm = Args.getLastArg(options::OPT_fasm, options::OPT_fno_asm)) {
6608 if (
Asm->getOption().matches(options::OPT_fasm))
6609 CmdArgs.push_back(
"-fgnu-keywords");
6611 CmdArgs.push_back(
"-fno-gnu-keywords");
6615 CmdArgs.push_back(
"-fno-autolink");
6617 Args.AddLastArg(CmdArgs, options::OPT_ftemplate_depth_EQ);
6618 Args.AddLastArg(CmdArgs, options::OPT_foperator_arrow_depth_EQ);
6619 Args.AddLastArg(CmdArgs, options::OPT_fconstexpr_depth_EQ);
6620 Args.AddLastArg(CmdArgs, options::OPT_fconstexpr_steps_EQ);
6622 Args.AddLastArg(CmdArgs, options::OPT_fexperimental_library);
6624 if (Args.hasArg(options::OPT_fexperimental_new_constant_interpreter))
6625 CmdArgs.push_back(
"-fexperimental-new-constant-interpreter");
6627 if (Arg *A = Args.getLastArg(options::OPT_fbracket_depth_EQ)) {
6628 CmdArgs.push_back(
"-fbracket-depth");
6629 CmdArgs.push_back(A->getValue());
6632 if (Arg *A = Args.getLastArg(options::OPT_Wlarge_by_value_copy_EQ,
6633 options::OPT_Wlarge_by_value_copy_def)) {
6634 if (A->getNumValues()) {
6635 StringRef
bytes = A->getValue();
6636 CmdArgs.push_back(Args.MakeArgString(
"-Wlarge-by-value-copy=" +
bytes));
6638 CmdArgs.push_back(
"-Wlarge-by-value-copy=64");
6641 if (Args.hasArg(options::OPT_relocatable_pch))
6642 CmdArgs.push_back(
"-relocatable-pch");
6644 if (
const Arg *A = Args.getLastArg(options::OPT_fcf_runtime_abi_EQ)) {
6645 static const char *kCFABIs[] = {
6646 "standalone",
"objc",
"swift",
"swift-5.0",
"swift-4.2",
"swift-4.1",
6649 if (!llvm::is_contained(kCFABIs, StringRef(A->getValue())))
6650 D.Diag(diag::err_drv_invalid_cf_runtime_abi) << A->getValue();
6652 A->render(Args, CmdArgs);
6655 if (Arg *A = Args.getLastArg(options::OPT_fconstant_string_class_EQ)) {
6656 CmdArgs.push_back(
"-fconstant-string-class");
6657 CmdArgs.push_back(A->getValue());
6660 if (Arg *A = Args.getLastArg(options::OPT_ftabstop_EQ)) {
6661 CmdArgs.push_back(
"-ftabstop");
6662 CmdArgs.push_back(A->getValue());
6665 Args.addOptInFlag(CmdArgs, options::OPT_fstack_size_section,
6666 options::OPT_fno_stack_size_section);
6668 if (Args.hasArg(options::OPT_fstack_usage)) {
6669 CmdArgs.push_back(
"-stack-usage-file");
6671 if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) {
6673 llvm::sys::path::replace_extension(OutputFilename,
"su");
6674 CmdArgs.push_back(Args.MakeArgString(OutputFilename));
6680 CmdArgs.push_back(
"-ferror-limit");
6681 if (Arg *A = Args.getLastArg(options::OPT_ferror_limit_EQ))
6682 CmdArgs.push_back(A->getValue());
6684 CmdArgs.push_back(
"19");
6686 Args.AddLastArg(CmdArgs, options::OPT_fconstexpr_backtrace_limit_EQ);
6687 Args.AddLastArg(CmdArgs, options::OPT_fmacro_backtrace_limit_EQ);
6688 Args.AddLastArg(CmdArgs, options::OPT_ftemplate_backtrace_limit_EQ);
6689 Args.AddLastArg(CmdArgs, options::OPT_fspell_checking_limit_EQ);
6690 Args.AddLastArg(CmdArgs, options::OPT_fcaret_diagnostics_max_lines_EQ);
6693 unsigned MessageLength = 0;
6694 if (Arg *A = Args.getLastArg(options::OPT_fmessage_length_EQ)) {
6695 StringRef
V(A->getValue());
6696 if (
V.getAsInteger(0, MessageLength))
6697 D.Diag(diag::err_drv_invalid_argument_to_option)
6698 <<
V << A->getOption().getName();
6702 MessageLength = llvm::sys::Process::StandardErrColumns();
6704 if (MessageLength != 0)
6706 Args.MakeArgString(
"-fmessage-length=" + Twine(MessageLength)));
6708 if (Arg *A = Args.getLastArg(options::OPT_frandomize_layout_seed_EQ))
6710 Args.MakeArgString(
"-frandomize-layout-seed=" + Twine(A->getValue(0))));
6712 if (Arg *A = Args.getLastArg(options::OPT_frandomize_layout_seed_file_EQ))
6713 CmdArgs.push_back(Args.MakeArgString(
"-frandomize-layout-seed-file=" +
6714 Twine(A->getValue(0))));
6717 if (
const Arg *A = Args.getLastArg(options::OPT_fvisibility_EQ,
6718 options::OPT_fvisibility_ms_compat)) {
6719 if (A->getOption().matches(options::OPT_fvisibility_EQ)) {
6720 A->render(Args, CmdArgs);
6722 assert(A->getOption().matches(options::OPT_fvisibility_ms_compat));
6723 CmdArgs.push_back(
"-fvisibility=hidden");
6724 CmdArgs.push_back(
"-ftype-visibility=default");
6726 }
else if (IsOpenMPDevice) {
6730 CmdArgs.push_back(
"-fvisibility=protected");
6734 if (!RawTriple.isPS()) {
6736 Args.getLastArg(options::OPT_fvisibility_from_dllstorageclass,
6737 options::OPT_fno_visibility_from_dllstorageclass)) {
6738 if (A->getOption().matches(
6739 options::OPT_fvisibility_from_dllstorageclass)) {
6740 CmdArgs.push_back(
"-fvisibility-from-dllstorageclass");
6741 Args.AddLastArg(CmdArgs, options::OPT_fvisibility_dllexport_EQ);
6742 Args.AddLastArg(CmdArgs, options::OPT_fvisibility_nodllstorageclass_EQ);
6743 Args.AddLastArg(CmdArgs, options::OPT_fvisibility_externs_dllimport_EQ);
6744 Args.AddLastArg(CmdArgs,
6745 options::OPT_fvisibility_externs_nodllstorageclass_EQ);
6750 if (Args.hasFlag(options::OPT_fvisibility_inlines_hidden,
6751 options::OPT_fno_visibility_inlines_hidden,
false))
6752 CmdArgs.push_back(
"-fvisibility-inlines-hidden");
6754 Args.AddLastArg(CmdArgs, options::OPT_fvisibility_inlines_hidden_static_local_var,
6755 options::OPT_fno_visibility_inlines_hidden_static_local_var);
6760 Args.getLastArg(options::OPT_fvisibility_global_new_delete_hidden)) {
6761 D.Diag(diag::warn_drv_deprecated_arg)
6762 << A->getAsString(Args) <<
true
6763 <<
"-fvisibility-global-new-delete=force-hidden";
6767 Args.getLastArg(options::OPT_fvisibility_global_new_delete_EQ,
6768 options::OPT_fvisibility_global_new_delete_hidden)) {
6769 if (A->getOption().matches(options::OPT_fvisibility_global_new_delete_EQ)) {
6770 A->render(Args, CmdArgs);
6772 assert(A->getOption().matches(
6773 options::OPT_fvisibility_global_new_delete_hidden));
6774 CmdArgs.push_back(
"-fvisibility-global-new-delete=force-hidden");
6778 Args.AddLastArg(CmdArgs, options::OPT_ftlsmodel_EQ);
6780 if (Args.hasFlag(options::OPT_fnew_infallible,
6781 options::OPT_fno_new_infallible,
false))
6782 CmdArgs.push_back(
"-fnew-infallible");
6784 if (Args.hasFlag(options::OPT_fno_operator_names,
6785 options::OPT_foperator_names,
false))
6786 CmdArgs.push_back(
"-fno-operator-names");
6789 Args.AddLastArg(CmdArgs, options::OPT_femit_all_decls);
6790 Args.AddLastArg(CmdArgs, options::OPT_fheinous_gnu_extensions);
6791 Args.AddLastArg(CmdArgs, options::OPT_fdigraphs, options::OPT_fno_digraphs);
6792 Args.AddLastArg(CmdArgs, options::OPT_fzero_call_used_regs_EQ);
6793 Args.AddLastArg(CmdArgs, options::OPT_fraw_string_literals,
6794 options::OPT_fno_raw_string_literals);
6796 if (Args.hasFlag(options::OPT_femulated_tls, options::OPT_fno_emulated_tls,
6797 Triple.hasDefaultEmulatedTLS()))
6798 CmdArgs.push_back(
"-femulated-tls");
6800 Args.addOptInFlag(CmdArgs, options::OPT_fcheck_new,
6801 options::OPT_fno_check_new);
6803 if (Arg *A = Args.getLastArg(options::OPT_fzero_call_used_regs_EQ)) {
6807 if (!Triple.isX86() && !Triple.isAArch64())
6808 D.Diag(diag::err_drv_unsupported_opt_for_target)
6809 << A->getAsString(Args) << TripleStr;
6813 if (!isa<PreprocessJobAction>(JA) || Output.
getType() != types::TY_PP_Asm)
6814 Args.AddLastArg(CmdArgs, options::OPT_fzvector);
6816 Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_show_template_tree);
6817 Args.AddLastArg(CmdArgs, options::OPT_fno_elide_type);
6821 if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
6822 options::OPT_fno_openmp,
false) &&
6823 !Args.hasFlag(options::OPT_foffload_via_llvm,
6824 options::OPT_fno_offload_via_llvm,
false) &&
6827 switch (
D.getOpenMPRuntime(Args)) {
6831 CmdArgs.push_back(
"-fopenmp");
6836 if (!Args.hasFlag(options::OPT_fopenmp_use_tls,
6837 options::OPT_fnoopenmp_use_tls,
true))
6838 CmdArgs.push_back(
"-fnoopenmp-use-tls");
6839 Args.AddLastArg(CmdArgs, options::OPT_fopenmp_simd,
6840 options::OPT_fno_openmp_simd);
6841 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_enable_irbuilder);
6842 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
6843 if (!Args.hasFlag(options::OPT_fopenmp_extensions,
6844 options::OPT_fno_openmp_extensions,
true))
6845 CmdArgs.push_back(
"-fno-openmp-extensions");
6846 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_cuda_number_of_sm_EQ);
6847 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_cuda_blocks_per_sm_EQ);
6848 Args.AddAllArgs(CmdArgs,
6849 options::OPT_fopenmp_cuda_teams_reduction_recs_num_EQ);
6850 if (Args.hasFlag(options::OPT_fopenmp_optimistic_collapse,
6851 options::OPT_fno_openmp_optimistic_collapse,
6853 CmdArgs.push_back(
"-fopenmp-optimistic-collapse");
6857 if (Args.hasFlag(options::OPT_fopenmp_cuda_mode,
6858 options::OPT_fno_openmp_cuda_mode,
false))
6859 CmdArgs.push_back(
"-fopenmp-cuda-mode");
6862 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_target_debug_EQ);
6863 if (Args.hasFlag(options::OPT_fopenmp_target_debug,
6864 options::OPT_fno_openmp_target_debug,
false))
6865 CmdArgs.push_back(
"-fopenmp-target-debug");
6869 if (Args.hasFlag(options::OPT_fopenmp_assume_teams_oversubscription,
6870 options::OPT_fno_openmp_assume_teams_oversubscription,
6872 CmdArgs.push_back(
"-fopenmp-assume-teams-oversubscription");
6873 if (Args.hasFlag(options::OPT_fopenmp_assume_threads_oversubscription,
6874 options::OPT_fno_openmp_assume_threads_oversubscription,
6876 CmdArgs.push_back(
"-fopenmp-assume-threads-oversubscription");
6877 if (Args.hasArg(options::OPT_fopenmp_assume_no_thread_state))
6878 CmdArgs.push_back(
"-fopenmp-assume-no-thread-state");
6879 if (Args.hasArg(options::OPT_fopenmp_assume_no_nested_parallelism))
6880 CmdArgs.push_back(
"-fopenmp-assume-no-nested-parallelism");
6881 if (Args.hasArg(options::OPT_fopenmp_offload_mandatory))
6882 CmdArgs.push_back(
"-fopenmp-offload-mandatory");
6883 if (Args.hasArg(options::OPT_fopenmp_force_usm))
6884 CmdArgs.push_back(
"-fopenmp-force-usm");
6896 Args.AddLastArg(CmdArgs, options::OPT_fopenmp_simd,
6897 options::OPT_fno_openmp_simd);
6898 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
6899 Args.addOptOutFlag(CmdArgs, options::OPT_fopenmp_extensions,
6900 options::OPT_fno_openmp_extensions);
6905 if (Args.hasFlag(options::OPT_foffload_via_llvm,
6906 options::OPT_fno_offload_via_llvm,
false)) {
6907 CmdArgs.append({
"--offload-new-driver",
"-foffload-via-llvm"});
6908 }
else if (Args.hasFlag(options::OPT_offload_new_driver,
6909 options::OPT_no_offload_new_driver,
6911 CmdArgs.push_back(
"--offload-new-driver");
6915 XRay.
addArgs(TC, Args, CmdArgs, InputType);
6918 Args.getAllArgValues(options::OPT_fprofile_list_EQ)) {
6920 CmdArgs.push_back(Args.MakeArgString(
"-fprofile-list=" +
Filename));
6922 D.Diag(clang::diag::err_drv_no_such_file) <<
Filename;
6925 if (Arg *A = Args.getLastArg(options::OPT_fpatchable_function_entry_EQ)) {
6926 StringRef S0 = A->getValue(), S = S0;
6927 unsigned Size, Offset = 0;
6928 if (!Triple.isAArch64() && !Triple.isLoongArch() && !Triple.isRISCV() &&
6930 !(!Triple.isOSAIX() && (Triple.getArch() == llvm::Triple::ppc ||
6931 Triple.getArch() == llvm::Triple::ppc64)))
6932 D.Diag(diag::err_drv_unsupported_opt_for_target)
6933 << A->getAsString(Args) << TripleStr;
6934 else if (S.consumeInteger(10, Size) ||
6935 (!S.empty() && (!S.consume_front(
",") ||
6936 S.consumeInteger(10, Offset) || !S.empty())))
6937 D.Diag(diag::err_drv_invalid_argument_to_option)
6938 << S0 << A->getOption().getName();
6939 else if (Size < Offset)
6940 D.Diag(diag::err_drv_unsupported_fpatchable_function_entry_argument);
6942 CmdArgs.push_back(Args.MakeArgString(A->getSpelling() + Twine(Size)));
6943 CmdArgs.push_back(Args.MakeArgString(
6944 "-fpatchable-function-entry-offset=" + Twine(Offset)));
6948 Args.AddLastArg(CmdArgs, options::OPT_fms_hotpatch);
6951 Args.AddLastArg(CmdArgs, options::OPT_pg);
6953 llvm::Triple::ArchType Arch = TC.
getArch();
6954 if (Arg *A = Args.getLastArg(options::OPT_mfentry)) {
6955 if (Arch == llvm::Triple::systemz || TC.
getTriple().isX86())
6956 A->render(Args, CmdArgs);
6958 D.Diag(diag::err_drv_unsupported_opt_for_target)
6959 << A->getAsString(Args) << TripleStr;
6961 if (Arg *A = Args.getLastArg(options::OPT_mnop_mcount)) {
6962 if (Arch == llvm::Triple::systemz)
6963 A->render(Args, CmdArgs);
6965 D.Diag(diag::err_drv_unsupported_opt_for_target)
6966 << A->getAsString(Args) << TripleStr;
6968 if (Arg *A = Args.getLastArg(options::OPT_mrecord_mcount)) {
6969 if (Arch == llvm::Triple::systemz)
6970 A->render(Args, CmdArgs);
6972 D.Diag(diag::err_drv_unsupported_opt_for_target)
6973 << A->getAsString(Args) << TripleStr;
6977 if (Arg *A = Args.getLastArgNoClaim(options::OPT_pg)) {
6979 D.Diag(diag::err_drv_unsupported_opt_for_target)
6980 << A->getAsString(Args) << TripleStr;
6983 if (Arg *A = Args.getLastArgNoClaim(options::OPT_p)) {
6985 D.Diag(diag::err_drv_unsupported_opt_for_target)
6986 << A->getAsString(Args) << TripleStr;
6989 if (Arg *A = Args.getLastArgNoClaim(options::OPT_p, options::OPT_pg)) {
6990 if (A->getOption().matches(options::OPT_p)) {
6992 if (TC.
getTriple().isOSAIX() && !Args.hasArgNoClaim(options::OPT_pg))
6993 CmdArgs.push_back(
"-pg");
6999 for (
const Arg *A : Args.filtered(options::OPT_b, options::OPT_K,
7000 options::OPT_mxcoff_build_id_EQ)) {
7001 D.Diag(diag::err_drv_unsupported_opt_for_target)
7002 << A->getSpelling() << TripleStr;
7006 if (Args.getLastArg(options::OPT_fapple_kext) ||
7007 (Args.hasArg(options::OPT_mkernel) &&
types::isCXX(InputType)))
7008 CmdArgs.push_back(
"-fapple-kext");
7010 Args.AddLastArg(CmdArgs, options::OPT_altivec_src_compat);
7011 Args.AddLastArg(CmdArgs, options::OPT_flax_vector_conversions_EQ);
7012 Args.AddLastArg(CmdArgs, options::OPT_fobjc_sender_dependent_dispatch);
7013 Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_print_source_range_info);
7014 Args.AddLastArg(CmdArgs, options::OPT_fdiagnostics_parseable_fixits);
7015 Args.AddLastArg(CmdArgs, options::OPT_ftime_report);
7016 Args.AddLastArg(CmdArgs, options::OPT_ftime_report_EQ);
7017 Args.AddLastArg(CmdArgs, options::OPT_ftrapv);
7018 Args.AddLastArg(CmdArgs, options::OPT_malign_double);
7019 Args.AddLastArg(CmdArgs, options::OPT_fno_temp_file);
7021 if (
const char *Name =
C.getTimeTraceFile(&JA)) {
7022 CmdArgs.push_back(Args.MakeArgString(
"-ftime-trace=" + Twine(Name)));
7023 Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_granularity_EQ);
7024 Args.AddLastArg(CmdArgs, options::OPT_ftime_trace_verbose);
7027 if (Arg *A = Args.getLastArg(options::OPT_ftrapv_handler_EQ)) {
7028 CmdArgs.push_back(
"-ftrapv-handler");
7029 CmdArgs.push_back(A->getValue());
7032 Args.AddLastArg(CmdArgs, options::OPT_ftrap_function_EQ);
7038 Args.AddLastArg(CmdArgs, options::OPT_ffinite_loops,
7039 options::OPT_fno_finite_loops);
7041 Args.AddLastArg(CmdArgs, options::OPT_fwritable_strings);
7042 Args.AddLastArg(CmdArgs, options::OPT_funroll_loops,
7043 options::OPT_fno_unroll_loops);
7045 Args.AddLastArg(CmdArgs, options::OPT_fstrict_flex_arrays_EQ);
7047 Args.AddLastArg(CmdArgs, options::OPT_pthread);
7049 Args.addOptInFlag(CmdArgs, options::OPT_mspeculative_load_hardening,
7050 options::OPT_mno_speculative_load_hardening);
7056 Args.AddLastArg(CmdArgs, options::OPT_fswift_async_fp_EQ);
7058 Args.addOptInFlag(CmdArgs, options::OPT_mstackrealign,
7059 options::OPT_mno_stackrealign);
7061 if (Args.hasArg(options::OPT_mstack_alignment)) {
7062 StringRef alignment = Args.getLastArgValue(options::OPT_mstack_alignment);
7063 CmdArgs.push_back(Args.MakeArgString(
"-mstack-alignment=" + alignment));
7066 if (Args.hasArg(options::OPT_mstack_probe_size)) {
7067 StringRef Size = Args.getLastArgValue(options::OPT_mstack_probe_size);
7070 CmdArgs.push_back(Args.MakeArgString(
"-mstack-probe-size=" + Size));
7072 CmdArgs.push_back(
"-mstack-probe-size=0");
7075 Args.addOptOutFlag(CmdArgs, options::OPT_mstack_arg_probe,
7076 options::OPT_mno_stack_arg_probe);
7078 if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it,
7079 options::OPT_mno_restrict_it)) {
7080 if (A->getOption().matches(options::OPT_mrestrict_it)) {
7081 CmdArgs.push_back(
"-mllvm");
7082 CmdArgs.push_back(
"-arm-restrict-it");
7084 CmdArgs.push_back(
"-mllvm");
7085 CmdArgs.push_back(
"-arm-default-it");
7099 if (Args.hasFlag(options::OPT_fhip_new_launch_api,
7100 options::OPT_fno_hip_new_launch_api,
true))
7101 CmdArgs.push_back(
"-fhip-new-launch-api");
7102 Args.addOptInFlag(CmdArgs, options::OPT_fgpu_allow_device_init,
7103 options::OPT_fno_gpu_allow_device_init);
7104 Args.AddLastArg(CmdArgs, options::OPT_hipstdpar);
7105 Args.AddLastArg(CmdArgs, options::OPT_hipstdpar_interpose_alloc);
7106 Args.addOptInFlag(CmdArgs, options::OPT_fhip_kernel_arg_name,
7107 options::OPT_fno_hip_kernel_arg_name);
7110 if (IsCuda || IsHIP) {
7112 CmdArgs.push_back(
"-fgpu-rdc");
7113 Args.addOptInFlag(CmdArgs, options::OPT_fgpu_defer_diag,
7114 options::OPT_fno_gpu_defer_diag);
7115 if (Args.hasFlag(options::OPT_fgpu_exclude_wrong_side_overloads,
7116 options::OPT_fno_gpu_exclude_wrong_side_overloads,
7118 CmdArgs.push_back(
"-fgpu-exclude-wrong-side-overloads");
7119 CmdArgs.push_back(
"-fgpu-defer-diag");
7124 if (Args.hasArg(options::OPT_nogpulib))
7125 CmdArgs.push_back(
"-nogpulib");
7127 if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
7129 Args.MakeArgString(Twine(
"-fcf-protection=") + A->getValue()));
7131 if (Arg *SA = Args.getLastArg(options::OPT_mcf_branch_label_scheme_EQ))
7132 CmdArgs.push_back(Args.MakeArgString(Twine(
"-mcf-branch-label-scheme=") +
7136 if (Arg *A = Args.getLastArg(options::OPT_mfunction_return_EQ))
7138 Args.MakeArgString(Twine(
"-mfunction-return=") + A->getValue()));
7140 Args.AddLastArg(CmdArgs, options::OPT_mindirect_branch_cs_prefix);
7145 if (!(IsCudaDevice || IsHIPDevice)) {
7147 auto *PGOArg = Args.getLastArg(
7148 options::OPT_fprofile_generate, options::OPT_fprofile_generate_EQ,
7149 options::OPT_fcs_profile_generate,
7150 options::OPT_fcs_profile_generate_EQ, options::OPT_fprofile_use,
7151 options::OPT_fprofile_use_EQ);
7153 D.Diag(diag::err_drv_argument_not_allowed_with)
7154 <<
"SampleUse with PGO options";
7156 StringRef fname = A->getValue();
7157 if (!llvm::sys::fs::exists(fname))
7158 D.Diag(diag::err_drv_no_such_file) << fname;
7160 A->render(Args, CmdArgs);
7162 Args.AddLastArg(CmdArgs, options::OPT_fprofile_remapping_file_EQ);
7164 if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
7165 options::OPT_fno_pseudo_probe_for_profiling,
false)) {
7166 CmdArgs.push_back(
"-fpseudo-probe-for-profiling");
7169 if (Args.hasFlag(options::OPT_funique_internal_linkage_names,
7170 options::OPT_fno_unique_internal_linkage_names,
true))
7171 CmdArgs.push_back(
"-funique-internal-linkage-names");
7176 Args.addOptOutFlag(CmdArgs, options::OPT_fassume_sane_operator_new,
7177 options::OPT_fno_assume_sane_operator_new);
7179 if (Args.hasFlag(options::OPT_fapinotes, options::OPT_fno_apinotes,
false))
7180 CmdArgs.push_back(
"-fapinotes");
7181 if (Args.hasFlag(options::OPT_fapinotes_modules,
7182 options::OPT_fno_apinotes_modules,
false))
7183 CmdArgs.push_back(
"-fapinotes-modules");
7184 Args.AddLastArg(CmdArgs, options::OPT_fapinotes_swift_version);
7187 if (Args.hasFlag(options::OPT_fblocks, options::OPT_fno_blocks,
7189 (Args.hasArg(options::OPT_fgnu_runtime) &&
7190 Args.hasArg(options::OPT_fobjc_nonfragile_abi) &&
7191 !Args.hasArg(options::OPT_fno_blocks))) {
7192 CmdArgs.push_back(
"-fblocks");
7195 CmdArgs.push_back(
"-fblocks-runtime-optional");
7200 CmdArgs.push_back(
"-fencode-extended-block-signature");
7202 if (Args.hasFlag(options::OPT_fcoro_aligned_allocation,
7203 options::OPT_fno_coro_aligned_allocation,
false) &&
7205 CmdArgs.push_back(
"-fcoro-aligned-allocation");
7207 Args.AddLastArg(CmdArgs, options::OPT_fdouble_square_bracket_attributes,
7208 options::OPT_fno_double_square_bracket_attributes);
7210 Args.addOptOutFlag(CmdArgs, options::OPT_faccess_control,
7211 options::OPT_fno_access_control);
7212 Args.addOptOutFlag(CmdArgs, options::OPT_felide_constructors,
7213 options::OPT_fno_elide_constructors);
7219 CmdArgs.push_back(
"-fno-rtti");
7222 if (Args.hasFlag(options::OPT_fshort_enums, options::OPT_fno_short_enums,
7223 TC.
getArch() == llvm::Triple::hexagon || Triple.isOSzOS()))
7224 CmdArgs.push_back(
"-fshort-enums");
7230 options::OPT_fuse_cxa_atexit, options::OPT_fno_use_cxa_atexit,
7231 !RawTriple.isOSAIX() && !RawTriple.isOSWindows() &&
7232 ((RawTriple.getVendor() != llvm::Triple::MipsTechnologies) ||
7233 RawTriple.hasEnvironment())) ||
7235 CmdArgs.push_back(
"-fno-use-cxa-atexit");
7237 if (Args.hasFlag(options::OPT_fregister_global_dtors_with_atexit,
7238 options::OPT_fno_register_global_dtors_with_atexit,
7239 RawTriple.isOSDarwin() && !KernelOrKext))
7240 CmdArgs.push_back(
"-fregister-global-dtors-with-atexit");
7242 Args.addOptInFlag(CmdArgs, options::OPT_fuse_line_directives,
7243 options::OPT_fno_use_line_directives);
7246 if (Args.hasFlag(options::OPT_fminimize_whitespace,
7247 options::OPT_fno_minimize_whitespace,
false)) {
7248 types::ID InputType = Inputs[0].getType();
7249 if (!isDerivedFromC(InputType))
7250 D.Diag(diag::err_drv_opt_unsupported_input_type)
7252 CmdArgs.push_back(
"-fminimize-whitespace");
7256 if (Args.hasFlag(options::OPT_fkeep_system_includes,
7257 options::OPT_fno_keep_system_includes,
false)) {
7258 types::ID InputType = Inputs[0].getType();
7259 if (!isDerivedFromC(InputType))
7260 D.Diag(diag::err_drv_opt_unsupported_input_type)
7262 CmdArgs.push_back(
"-fkeep-system-includes");
7266 if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
7267 IsWindowsMSVC || IsUEFI))
7268 CmdArgs.push_back(
"-fms-extensions");
7271 bool IsMSVCCompat = Args.hasFlag(
7272 options::OPT_fms_compatibility, options::OPT_fno_ms_compatibility,
7273 (IsWindowsMSVC && Args.hasFlag(options::OPT_fms_extensions,
7274 options::OPT_fno_ms_extensions,
true)));
7276 CmdArgs.push_back(
"-fms-compatibility");
7278 Args.hasArg(options::OPT_fms_define_stdc))
7279 CmdArgs.push_back(
"-fms-define-stdc");
7282 if (Triple.isWindowsMSVCEnvironment() && !
D.IsCLMode() &&
7283 Args.hasArg(options::OPT_fms_runtime_lib_EQ))
7287 VersionTuple GNUCVer;
7288 if (Arg *A = Args.getLastArg(options::OPT_fgnuc_version_EQ)) {
7291 StringRef Val = A->getValue();
7292 Val = Val.empty() ?
"0" : Val;
7293 bool Invalid = GNUCVer.tryParse(Val);
7294 unsigned Minor = GNUCVer.getMinor().value_or(0);
7295 unsigned Patch = GNUCVer.getSubminor().value_or(0);
7296 if (
Invalid || GNUCVer.getBuild() || Minor >= 100 || Patch >= 100) {
7297 D.Diag(diag::err_drv_invalid_value)
7298 << A->getAsString(Args) << A->getValue();
7300 }
else if (!IsMSVCCompat) {
7302 GNUCVer = VersionTuple(4, 2, 1);
7304 if (!GNUCVer.empty()) {
7306 Args.MakeArgString(
"-fgnuc-version=" + GNUCVer.getAsString()));
7312 Args.MakeArgString(
"-fms-compatibility-version=" + MSVT.getAsString()));
7314 bool IsMSVC2015Compatible = MSVT.getMajor() >= 19;
7315 if (ImplyVCPPCVer) {
7316 StringRef LanguageStandard;
7317 if (
const Arg *StdArg = Args.getLastArg(options::OPT__SLASH_std)) {
7319 LanguageStandard = llvm::StringSwitch<StringRef>(StdArg->getValue())
7320 .Case(
"c11",
"-std=c11")
7321 .Case(
"c17",
"-std=c17")
7323 if (LanguageStandard.empty())
7324 D.Diag(clang::diag::warn_drv_unused_argument)
7325 << StdArg->getAsString(Args);
7327 CmdArgs.push_back(LanguageStandard.data());
7329 if (ImplyVCPPCXXVer) {
7330 StringRef LanguageStandard;
7331 if (
const Arg *StdArg = Args.getLastArg(options::OPT__SLASH_std)) {
7333 LanguageStandard = llvm::StringSwitch<StringRef>(StdArg->getValue())
7334 .Case(
"c++14",
"-std=c++14")
7335 .Case(
"c++17",
"-std=c++17")
7336 .Case(
"c++20",
"-std=c++20")
7338 .Case(
"c++23preview",
"-std=c++23")
7339 .Case(
"c++latest",
"-std=c++26")
7341 if (LanguageStandard.empty())
7342 D.Diag(clang::diag::warn_drv_unused_argument)
7343 << StdArg->getAsString(Args);
7346 if (LanguageStandard.empty()) {
7347 if (IsMSVC2015Compatible)
7348 LanguageStandard =
"-std=c++14";
7350 LanguageStandard =
"-std=c++11";
7353 CmdArgs.push_back(LanguageStandard.data());
7356 Args.addOptInFlag(CmdArgs, options::OPT_fborland_extensions,
7357 options::OPT_fno_borland_extensions);
7360 if (Args.hasFlag(options::OPT_fdeclspec, options::OPT_fno_declspec,
7362 CmdArgs.push_back(
"-fdeclspec");
7363 else if (Args.hasArg(options::OPT_fno_declspec))
7364 CmdArgs.push_back(
"-fno-declspec");
7368 if (!Args.hasFlag(options::OPT_fthreadsafe_statics,
7369 options::OPT_fno_threadsafe_statics,
7371 (!IsWindowsMSVC || IsMSVC2015Compatible)))
7372 CmdArgs.push_back(
"-fno-threadsafe-statics");
7374 if (!Args.hasFlag(options::OPT_fms_tls_guards, options::OPT_fno_ms_tls_guards,
7376 CmdArgs.push_back(
"-fno-ms-tls-guards");
7379 if (!Args.hasFlag(options::OPT_fassumptions, options::OPT_fno_assumptions,
7381 CmdArgs.push_back(
"-fno-assumptions");
7385 Args.AddLastArg(CmdArgs, options::OPT_fgnu_keywords,
7386 options::OPT_fno_gnu_keywords);
7388 Args.addOptInFlag(CmdArgs, options::OPT_fgnu89_inline,
7389 options::OPT_fno_gnu89_inline);
7391 const Arg *InlineArg = Args.getLastArg(options::OPT_finline_functions,
7392 options::OPT_finline_hint_functions,
7393 options::OPT_fno_inline_functions);
7394 if (Arg *A = Args.getLastArg(options::OPT_finline, options::OPT_fno_inline)) {
7395 if (A->getOption().matches(options::OPT_fno_inline))
7396 A->render(Args, CmdArgs);
7397 }
else if (InlineArg) {
7398 InlineArg->render(Args, CmdArgs);
7401 Args.AddLastArg(CmdArgs, options::OPT_finline_max_stacksize_EQ);
7406 (
Std->containsValue(
"c++2a") ||
Std->containsValue(
"gnu++2a") ||
7407 Std->containsValue(
"c++20") ||
Std->containsValue(
"gnu++20") ||
7408 Std->containsValue(
"c++2b") ||
Std->containsValue(
"gnu++2b") ||
7409 Std->containsValue(
"c++23") ||
Std->containsValue(
"gnu++23") ||
7410 Std->containsValue(
"c++2c") ||
Std->containsValue(
"gnu++2c") ||
7411 Std->containsValue(
"c++26") ||
Std->containsValue(
"gnu++26") ||
7412 Std->containsValue(
"c++latest") ||
Std->containsValue(
"gnu++latest"));
7427 if (Args.hasFlag(options::OPT_fdelayed_template_parsing,
7428 options::OPT_fno_delayed_template_parsing,
7429 IsWindowsMSVC && !HaveCxx20)) {
7431 D.Diag(clang::diag::warn_drv_delayed_template_parsing_after_cxx20);
7433 CmdArgs.push_back(
"-fdelayed-template-parsing");
7436 if (Args.hasFlag(options::OPT_fpch_validate_input_files_content,
7437 options::OPT_fno_pch_validate_input_files_content,
false))
7438 CmdArgs.push_back(
"-fvalidate-ast-input-files-content");
7439 if (Args.hasFlag(options::OPT_fpch_instantiate_templates,
7440 options::OPT_fno_pch_instantiate_templates,
false))
7441 CmdArgs.push_back(
"-fpch-instantiate-templates");
7442 if (Args.hasFlag(options::OPT_fpch_codegen, options::OPT_fno_pch_codegen,
7444 CmdArgs.push_back(
"-fmodules-codegen");
7445 if (Args.hasFlag(options::OPT_fpch_debuginfo, options::OPT_fno_pch_debuginfo,
7447 CmdArgs.push_back(
"-fmodules-debuginfo");
7449 ObjCRuntime Runtime = AddObjCRuntimeArgs(Args, Inputs, CmdArgs, rewriteKind);
7454 Args.hasFlag(options::OPT_fobjc_encode_cxx_class_template_spec,
7455 options::OPT_fno_objc_encode_cxx_class_template_spec,
7457 CmdArgs.push_back(
"-fobjc-encode-cxx-class-template-spec");
7459 if (Args.hasFlag(options::OPT_fapplication_extension,
7460 options::OPT_fno_application_extension,
false))
7461 CmdArgs.push_back(
"-fapplication-extension");
7465 if (!
C.getDriver().IsCLMode())
7466 EH =
addExceptionArgs(Args, InputType, TC, KernelOrKext, Runtime, CmdArgs);
7469 Arg *A = Args.getLastArg(
7470 options::OPT_fsjlj_exceptions, options::OPT_fseh_exceptions,
7471 options::OPT_fdwarf_exceptions, options::OPT_fwasm_exceptions);
7473 const Option &Opt = A->getOption();
7474 if (Opt.matches(options::OPT_fsjlj_exceptions))
7475 CmdArgs.push_back(
"-exception-model=sjlj");
7476 if (Opt.matches(options::OPT_fseh_exceptions))
7477 CmdArgs.push_back(
"-exception-model=seh");
7478 if (Opt.matches(options::OPT_fdwarf_exceptions))
7479 CmdArgs.push_back(
"-exception-model=dwarf");
7480 if (Opt.matches(options::OPT_fwasm_exceptions))
7481 CmdArgs.push_back(
"-exception-model=wasm");
7486 case llvm::ExceptionHandling::DwarfCFI:
7487 CmdArgs.push_back(
"-exception-model=dwarf");
7489 case llvm::ExceptionHandling::SjLj:
7490 CmdArgs.push_back(
"-exception-model=sjlj");
7492 case llvm::ExceptionHandling::WinEH:
7493 CmdArgs.push_back(
"-exception-model=seh");
7499 Args.addOptOutFlag(CmdArgs, options::OPT_fassume_sane_operator_new,
7500 options::OPT_fno_assume_sane_operator_new);
7503 Args.addOptOutFlag(CmdArgs, options::OPT_fassume_unique_vtables,
7504 options::OPT_fno_assume_unique_vtables);
7508 Args.getLastArg(options::OPT_frelaxed_template_template_args,
7509 options::OPT_fno_relaxed_template_template_args)) {
7510 if (A->getOption().matches(
7511 options::OPT_fno_relaxed_template_template_args)) {
7512 D.Diag(diag::warn_drv_deprecated_arg_no_relaxed_template_template_args);
7513 CmdArgs.push_back(
"-fno-relaxed-template-template-args");
7515 D.Diag(diag::warn_drv_deprecated_arg)
7516 << A->getAsString(Args) <<
false;
7522 Args.addLastArg(CmdArgs, options::OPT_fsized_deallocation,
7523 options::OPT_fno_sized_deallocation);
7527 if (Arg *A = Args.getLastArg(options::OPT_faligned_allocation,
7528 options::OPT_fno_aligned_allocation,
7529 options::OPT_faligned_new_EQ)) {
7530 if (A->getOption().matches(options::OPT_fno_aligned_allocation))
7531 CmdArgs.push_back(
"-fno-aligned-allocation");
7533 CmdArgs.push_back(
"-faligned-allocation");
7538 if (Arg *A = Args.getLastArg(options::OPT_fnew_alignment_EQ,
7539 options::OPT_faligned_new_EQ))
7541 Args.MakeArgString(Twine(
"-fnew-alignment=") + A->getValue()));
7545 if (!Args.hasFlag(options::OPT_fconstant_cfstrings,
7546 options::OPT_fno_constant_cfstrings,
true) ||
7547 !Args.hasFlag(options::OPT_mconstant_cfstrings,
7548 options::OPT_mno_constant_cfstrings,
true))
7549 CmdArgs.push_back(
"-fno-constant-cfstrings");
7551 Args.addOptInFlag(CmdArgs, options::OPT_fpascal_strings,
7552 options::OPT_fno_pascal_strings);
7556 if (Arg *A = Args.getLastArg(options::OPT_fpack_struct_EQ)) {
7557 std::string PackStructStr =
"-fpack-struct=";
7558 PackStructStr += A->getValue();
7559 CmdArgs.push_back(Args.MakeArgString(PackStructStr));
7560 }
else if (Args.hasFlag(options::OPT_fpack_struct,
7561 options::OPT_fno_pack_struct,
false)) {
7562 CmdArgs.push_back(
"-fpack-struct=1");
7566 bool SkipMaxTypeAlign = Args.hasArg(options::OPT_fno_max_type_align);
7567 if (Arg *A = Args.getLastArg(options::OPT_fmax_type_align_EQ)) {
7568 if (!SkipMaxTypeAlign) {
7569 std::string MaxTypeAlignStr =
"-fmax-type-align=";
7570 MaxTypeAlignStr += A->getValue();
7571 CmdArgs.push_back(Args.MakeArgString(MaxTypeAlignStr));
7573 }
else if (RawTriple.isOSDarwin()) {
7574 if (!SkipMaxTypeAlign) {
7575 std::string MaxTypeAlignStr =
"-fmax-type-align=16";
7576 CmdArgs.push_back(Args.MakeArgString(MaxTypeAlignStr));
7580 if (!Args.hasFlag(options::OPT_Qy, options::OPT_Qn,
true))
7581 CmdArgs.push_back(
"-Qn");
7584 Args.addOptInFlag(CmdArgs, options::OPT_fcommon, options::OPT_fno_common);
7588 if (!Args.hasFlag(options::OPT_fsigned_bitfields,
7589 options::OPT_funsigned_bitfields,
true))
7590 D.Diag(diag::warn_drv_clang_unsupported)
7591 << Args.getLastArg(options::OPT_funsigned_bitfields)->getAsString(Args);
7594 if (!Args.hasFlag(options::OPT_ffor_scope, options::OPT_fno_for_scope,
true))
7595 D.Diag(diag::err_drv_clang_unsupported)
7596 << Args.getLastArg(options::OPT_fno_for_scope)->getAsString(Args);
7599 if (Arg *inputCharset = Args.getLastArg(options::OPT_finput_charset_EQ)) {
7600 StringRef value = inputCharset->getValue();
7601 if (!value.equals_insensitive(
"utf-8"))
7602 D.Diag(diag::err_drv_invalid_value) << inputCharset->getAsString(Args)
7607 if (Arg *execCharset = Args.getLastArg(options::OPT_fexec_charset_EQ)) {
7608 StringRef value = execCharset->getValue();
7609 if (!value.equals_insensitive(
"utf-8"))
7610 D.Diag(diag::err_drv_invalid_value) << execCharset->getAsString(Args)
7616 Args.addOptInFlag(CmdArgs, options::OPT_fasm_blocks,
7617 options::OPT_fno_asm_blocks);
7619 Args.addOptOutFlag(CmdArgs, options::OPT_fgnu_inline_asm,
7620 options::OPT_fno_gnu_inline_asm);
7626 OptSpecifier VectorizeAliasOption =
7627 EnableVec ? options::OPT_O_Group : options::OPT_fvectorize;
7628 if (Args.hasFlag(options::OPT_fvectorize, VectorizeAliasOption,
7629 options::OPT_fno_vectorize, EnableVec))
7630 CmdArgs.push_back(
"-vectorize-loops");
7634 OptSpecifier SLPVectAliasOption =
7635 EnableSLPVec ? options::OPT_O_Group : options::OPT_fslp_vectorize;
7636 if (Args.hasFlag(options::OPT_fslp_vectorize, SLPVectAliasOption,
7637 options::OPT_fno_slp_vectorize, EnableSLPVec))
7638 CmdArgs.push_back(
"-vectorize-slp");
7642 Args.AddLastArg(CmdArgs, options::OPT_fshow_overloads_EQ);
7643 Args.AddLastArg(CmdArgs,
7644 options::OPT_fsanitize_undefined_strip_path_components_EQ);
7648 if (Arg *A = Args.getLastArg(options::OPT_fdollars_in_identifiers,
7649 options::OPT_fno_dollars_in_identifiers)) {
7650 if (A->getOption().matches(options::OPT_fdollars_in_identifiers))
7651 CmdArgs.push_back(
"-fdollars-in-identifiers");
7653 CmdArgs.push_back(
"-fno-dollars-in-identifiers");
7656 Args.addOptInFlag(CmdArgs, options::OPT_fapple_pragma_pack,
7657 options::OPT_fno_apple_pragma_pack);
7663 bool RewriteImports = Args.hasFlag(options::OPT_frewrite_imports,
7664 options::OPT_fno_rewrite_imports,
false);
7666 CmdArgs.push_back(
"-frewrite-imports");
7668 Args.addOptInFlag(CmdArgs, options::OPT_fdirectives_only,
7669 options::OPT_fno_directives_only);
7675 if (Args.hasFlag(options::OPT_frewrite_includes,
7676 options::OPT_fno_rewrite_includes,
false) ||
7677 (
C.isForDiagnostics() && !HaveModules))
7678 CmdArgs.push_back(
"-frewrite-includes");
7680 if (Args.hasFlag(options::OPT_fzos_extensions,
7681 options::OPT_fno_zos_extensions,
false))
7682 CmdArgs.push_back(
"-fzos-extensions");
7683 else if (Args.hasArg(options::OPT_fno_zos_extensions))
7684 CmdArgs.push_back(
"-fno-zos-extensions");
7687 if (Arg *A = Args.getLastArg(options::OPT_traditional,
7688 options::OPT_traditional_cpp)) {
7689 if (isa<PreprocessJobAction>(JA))
7690 CmdArgs.push_back(
"-traditional-cpp");
7692 D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
7695 Args.AddLastArg(CmdArgs, options::OPT_dM);
7696 Args.AddLastArg(CmdArgs, options::OPT_dD);
7697 Args.AddLastArg(CmdArgs, options::OPT_dI);
7699 Args.AddLastArg(CmdArgs, options::OPT_fmax_tokens_EQ);
7702 if (Arg *A = Args.getLastArg(options::OPT__serialize_diags)) {
7703 CmdArgs.push_back(
"-serialize-diagnostic-file");
7704 CmdArgs.push_back(Args.MakeArgString(A->getValue()));
7707 if (Args.hasArg(options::OPT_fretain_comments_from_system_headers))
7708 CmdArgs.push_back(
"-fretain-comments-from-system-headers");
7711 Args.AddAllArgs(CmdArgs, options::OPT_fcomment_block_commands);
7713 Args.AddAllArgs(CmdArgs, options::OPT_fparse_all_comments);
7716 for (
const Arg *A : Args.filtered(options::OPT_fplugin_EQ)) {
7717 CmdArgs.push_back(
"-load");
7718 CmdArgs.push_back(A->getValue());
7730 for (
const Arg *A : Args.filtered(options::OPT_fplugin_arg)) {
7731 auto ArgValue = StringRef(A->getValue());
7732 auto FirstDashIndex = ArgValue.find(
'-');
7733 StringRef PluginName = ArgValue.substr(0, FirstDashIndex);
7734 StringRef Arg = ArgValue.substr(FirstDashIndex + 1);
7737 if (FirstDashIndex == StringRef::npos || Arg.empty()) {
7738 if (PluginName.empty()) {
7739 D.Diag(diag::warn_drv_missing_plugin_name) << A->getAsString(Args);
7741 D.Diag(diag::warn_drv_missing_plugin_arg)
7742 << PluginName << A->getAsString(Args);
7747 CmdArgs.push_back(Args.MakeArgString(Twine(
"-plugin-arg-") + PluginName));
7748 CmdArgs.push_back(Args.MakeArgString(Arg));
7752 for (
const Arg *A : Args.filtered(options::OPT_fpass_plugin_EQ)) {
7754 Args.MakeArgString(Twine(
"-fpass-plugin=") + A->getValue()));
7759 for (
const Arg *A : Args.filtered(options::OPT_vfsoverlay)) {
7760 CmdArgs.push_back(
"--vfsoverlay");
7761 CmdArgs.push_back(A->getValue());
7765 Args.addOptInFlag(CmdArgs, options::OPT_fsafe_buffer_usage_suggestions,
7766 options::OPT_fno_safe_buffer_usage_suggestions);
7768 Args.addOptInFlag(CmdArgs, options::OPT_fexperimental_late_parse_attributes,
7769 options::OPT_fno_experimental_late_parse_attributes);
7773 if (!StatsFile.empty()) {
7774 CmdArgs.push_back(Args.MakeArgString(Twine(
"-stats-file=") + StatsFile));
7775 if (
D.CCPrintInternalStats)
7776 CmdArgs.push_back(
"-stats-file-append");
7781 for (
auto Arg : Args.filtered(options::OPT_Xclang)) {
7785 if (
C.getDriver().isSaveTempsEnabled() &&
7786 !isa<PreprocessJobAction>(JA)) {
7787 if (StringRef(Arg->getValue()) ==
"-finclude-default-header")
7790 CmdArgs.push_back(Arg->getValue());
7792 for (
const Arg *A : Args.filtered(options::OPT_mllvm)) {
7798 if (StringRef(A->getValue(0)) ==
"-disable-llvm-optzns") {
7799 CmdArgs.push_back(
"-disable-llvm-optzns");
7801 A->render(Args, CmdArgs);
7807 SanitizeArgs.addArgs(TC, Args, CmdArgs, InputType);
7817 if ((
C.getDriver().isSaveTempsEnabled() ||
7819 !(
C.getDriver().embedBitcodeInObject() && !IsUsingLTO) &&
7820 isa<CompileJobAction>(JA))
7821 CmdArgs.push_back(
"-disable-llvm-passes");
7823 Args.AddAllArgs(CmdArgs, options::OPT_undef);
7825 const char *Exec =
D.getClangProgramPath();
7832 auto GRecordSwitches =
false;
7833 auto FRecordSwitches =
false;
7837 CmdArgs.push_back(
"-dwarf-debug-flags");
7838 CmdArgs.push_back(FlagsArgString);
7840 if (FRecordSwitches) {
7841 CmdArgs.push_back(
"-record-command-line");
7842 CmdArgs.push_back(FlagsArgString);
7849 if ((IsCuda || IsHIP) && CudaDeviceInput) {
7850 CmdArgs.push_back(
"-fcuda-include-gpubinary");
7851 CmdArgs.push_back(CudaDeviceInput->
getFilename());
7852 }
else if (!HostOffloadingInputs.empty()) {
7853 if ((IsCuda || IsHIP) && !IsRDCMode) {
7854 assert(HostOffloadingInputs.size() == 1 &&
"Only one input expected");
7855 CmdArgs.push_back(
"-fcuda-include-gpubinary");
7856 CmdArgs.push_back(HostOffloadingInputs.front().getFilename());
7858 for (
const InputInfo Input : HostOffloadingInputs)
7859 CmdArgs.push_back(Args.MakeArgString(
"-fembed-offload-object=" +
7865 if (Args.hasFlag(options::OPT_fcuda_short_ptr,
7866 options::OPT_fno_cuda_short_ptr,
false))
7867 CmdArgs.push_back(
"-fcuda-short-ptr");
7870 if (IsCuda || IsHIP) {
7872 const Action *SourceAction = &JA;
7874 assert(!SourceAction->
getInputs().empty() &&
"unexpected root action!");
7875 SourceAction = SourceAction->
getInputs()[0];
7877 auto CUID = cast<InputAction>(SourceAction)->getId();
7879 CmdArgs.push_back(Args.MakeArgString(Twine(
"-cuid=") + Twine(CUID)));
7883 bool UseApproxTranscendentals = Args.hasFlag(
7884 options::OPT_ffast_math, options::OPT_fno_fast_math,
false);
7885 if (Args.hasFlag(options::OPT_fgpu_approx_transcendentals,
7886 options::OPT_fno_gpu_approx_transcendentals,
7887 UseApproxTranscendentals))
7888 CmdArgs.push_back(
"-fgpu-approx-transcendentals");
7890 Args.claimAllArgs(options::OPT_fgpu_approx_transcendentals,
7891 options::OPT_fno_gpu_approx_transcendentals);
7895 CmdArgs.push_back(
"-fcuda-allow-variadic-functions");
7896 Args.AddLastArg(CmdArgs, options::OPT_fgpu_default_stream_EQ);
7899 Args.AddAllArgs(CmdArgs,
7900 options::OPT_fsanitize_undefined_ignore_overflow_pattern_EQ);
7902 Args.AddLastArg(CmdArgs, options::OPT_foffload_uniform_block,
7903 options::OPT_fno_offload_uniform_block);
7905 Args.AddLastArg(CmdArgs, options::OPT_foffload_implicit_host_device_templates,
7906 options::OPT_fno_offload_implicit_host_device_templates);
7908 if (IsCudaDevice || IsHIPDevice) {
7909 StringRef InlineThresh =
7910 Args.getLastArgValue(options::OPT_fgpu_inline_threshold_EQ);
7911 if (!InlineThresh.empty()) {
7912 std::string ArgStr =
7913 std::string(
"-inline-threshold=") + InlineThresh.str();
7914 CmdArgs.append({
"-mllvm", Args.MakeArgStringRef(ArgStr)});
7919 Args.addOptOutFlag(CmdArgs,
7920 options::OPT_fhip_fp32_correctly_rounded_divide_sqrt,
7921 options::OPT_fno_hip_fp32_correctly_rounded_divide_sqrt);
7928 if (IsOpenMPDevice) {
7929 CmdArgs.push_back(
"-fopenmp-is-target-device");
7931 if (Args.hasArg(options::OPT_foffload_via_llvm))
7932 CmdArgs.push_back(
"-fcuda-is-device");
7934 if (OpenMPDeviceInput) {
7935 CmdArgs.push_back(
"-fopenmp-host-ir-file-path");
7936 CmdArgs.push_back(Args.MakeArgString(OpenMPDeviceInput->
getFilename()));
7940 if (Triple.isAMDGPU()) {
7943 Args.addOptInFlag(CmdArgs, options::OPT_munsafe_fp_atomics,
7944 options::OPT_mno_unsafe_fp_atomics);
7945 Args.addOptOutFlag(CmdArgs, options::OPT_mamdgpu_ieee,
7946 options::OPT_mno_amdgpu_ieee);
7951 bool VirtualFunctionElimination =
7952 Args.hasFlag(options::OPT_fvirtual_function_elimination,
7953 options::OPT_fno_virtual_function_elimination,
false);
7954 if (VirtualFunctionElimination) {
7958 D.Diag(diag::err_drv_argument_only_allowed_with)
7959 <<
"-fvirtual-function-elimination"
7962 CmdArgs.push_back(
"-fvirtual-function-elimination");
7966 bool WholeProgramVTables = Args.hasFlag(
7967 options::OPT_fwhole_program_vtables,
7968 options::OPT_fno_whole_program_vtables, VirtualFunctionElimination);
7969 if (VirtualFunctionElimination && !WholeProgramVTables) {
7970 D.Diag(diag::err_drv_argument_not_allowed_with)
7971 <<
"-fno-whole-program-vtables"
7972 <<
"-fvirtual-function-elimination";
7975 if (WholeProgramVTables) {
7987 IsDeviceOffloadAction ?
D.getLTOMode() :
D.getOffloadLTOMode();
7988 auto OtherIsUsingLTO = OtherLTOMode !=
LTOK_None;
7990 if ((!IsUsingLTO && !OtherIsUsingLTO) ||
7991 (IsPS4 && !UnifiedLTO && (
D.getLTOMode() !=
LTOK_Full)))
7992 D.Diag(diag::err_drv_argument_only_allowed_with)
7993 <<
"-fwhole-program-vtables"
7994 << ((IsPS4 && !UnifiedLTO) ?
"-flto=full" :
"-flto");
7998 CmdArgs.push_back(
"-fwhole-program-vtables");
8001 bool DefaultsSplitLTOUnit =
8002 ((WholeProgramVTables || SanitizeArgs.needsLTO()) &&
8004 (!Triple.isPS4() && UnifiedLTO);
8006 Args.hasFlag(options::OPT_fsplit_lto_unit,
8007 options::OPT_fno_split_lto_unit, DefaultsSplitLTOUnit);
8008 if (SanitizeArgs.needsLTO() && !SplitLTOUnit)
8009 D.Diag(diag::err_drv_argument_not_allowed_with) <<
"-fno-split-lto-unit"
8010 <<
"-fsanitize=cfi";
8012 CmdArgs.push_back(
"-fsplit-lto-unit");
8014 if (Arg *A = Args.getLastArg(options::OPT_ffat_lto_objects,
8015 options::OPT_fno_fat_lto_objects)) {
8016 if (IsUsingLTO && A->getOption().matches(options::OPT_ffat_lto_objects)) {
8018 if (!Triple.isOSBinFormatELF()) {
8019 D.Diag(diag::err_drv_unsupported_opt_for_target)
8022 CmdArgs.push_back(Args.MakeArgString(
8023 Twine(
"-flto=") + (LTOMode ==
LTOK_Thin ?
"thin" :
"full")));
8024 CmdArgs.push_back(
"-flto-unit");
8025 CmdArgs.push_back(
"-ffat-lto-objects");
8026 A->render(Args, CmdArgs);
8030 if (Arg *A = Args.getLastArg(options::OPT_fglobal_isel,
8031 options::OPT_fno_global_isel)) {
8032 CmdArgs.push_back(
"-mllvm");
8033 if (A->getOption().matches(options::OPT_fglobal_isel)) {
8034 CmdArgs.push_back(
"-global-isel=1");
8039 bool IsArchSupported = Triple.getArch() == llvm::Triple::aarch64;
8040 bool IsOptLevelSupported =
false;
8042 Arg *A = Args.getLastArg(options::OPT_O_Group);
8043 if (Triple.getArch() == llvm::Triple::aarch64) {
8044 if (!A || A->getOption().matches(options::OPT_O0))
8045 IsOptLevelSupported =
true;
8047 if (!IsArchSupported || !IsOptLevelSupported) {
8048 CmdArgs.push_back(
"-mllvm");
8049 CmdArgs.push_back(
"-global-isel-abort=2");
8051 if (!IsArchSupported)
8052 D.Diag(diag::warn_drv_global_isel_incomplete) << Triple.getArchName();
8054 D.Diag(diag::warn_drv_global_isel_incomplete_opt);
8057 CmdArgs.push_back(
"-global-isel=0");
8062 Args.getLastArg(options::OPT_forder_file_instrumentation)) {
8063 D.Diag(diag::warn_drv_deprecated_arg)
8064 << A->getAsString(Args) <<
true
8065 <<
"-ftemporal-profile";
8066 CmdArgs.push_back(
"-forder-file-instrumentation");
8071 CmdArgs.push_back(
"-mllvm");
8072 CmdArgs.push_back(
"-enable-order-file-instrumentation");
8076 if (Arg *A = Args.getLastArg(options::OPT_fforce_enable_int128,
8077 options::OPT_fno_force_enable_int128)) {
8078 if (A->getOption().matches(options::OPT_fforce_enable_int128))
8079 CmdArgs.push_back(
"-fforce-enable-int128");
8082 Args.addOptInFlag(CmdArgs, options::OPT_fkeep_static_consts,
8083 options::OPT_fno_keep_static_consts);
8084 Args.addOptInFlag(CmdArgs, options::OPT_fkeep_persistent_storage_variables,
8085 options::OPT_fno_keep_persistent_storage_variables);
8086 Args.addOptInFlag(CmdArgs, options::OPT_fcomplete_member_pointers,
8087 options::OPT_fno_complete_member_pointers);
8088 if (Arg *A = Args.getLastArg(options::OPT_cxx_static_destructors_EQ))
8089 A->render(Args, CmdArgs);
8095 if (Triple.isAArch64() &&
8096 (Args.hasArg(options::OPT_mno_fmv) ||
8097 (Triple.isAndroid() && Triple.isAndroidVersionLT(23)) ||
8100 CmdArgs.push_back(
"-target-feature");
8101 CmdArgs.push_back(
"-fmv");
8104 if (Args.hasFlag(options::OPT_faddrsig, options::OPT_fno_addrsig,
8111 CmdArgs.push_back(
"-faddrsig");
8113 if ((Triple.isOSBinFormatELF() || Triple.isOSBinFormatMachO()) &&
8114 (EH || UnwindTables || AsyncUnwindTables ||
8115 DebugInfoKind != llvm::codegenoptions::NoDebugInfo))
8116 CmdArgs.push_back(
"-D__GCC_HAVE_DWARF2_CFI_ASM=1");
8118 if (Arg *A = Args.getLastArg(options::OPT_fsymbol_partition_EQ)) {
8119 std::string Str = A->getAsString(Args);
8121 D.Diag(diag::err_drv_unsupported_opt_for_target)
8123 CmdArgs.push_back(Args.MakeArgString(Str));
8128 if (Output.
getType() == types::TY_Dependencies) {
8131 if (Output.
getType() == clang::driver::types::TY_IFS_CPP ||
8132 Output.
getType() == clang::driver::types::TY_IFS) {
8134 llvm::sys::path::replace_extension(OutputFilename,
"ifs");
8135 CmdArgs.push_back(
"-o");
8136 CmdArgs.push_back(Args.MakeArgString(OutputFilename));
8138 CmdArgs.push_back(
"-o");
8142 assert(Output.
isNothing() &&
"Invalid output.");
8149 FrontendInputs = ExtractAPIInputs;
8151 FrontendInputs = {};
8153 for (
const InputInfo &Input : FrontendInputs) {
8160 if (
D.CC1Main && !
D.CCGenDiagnostics) {
8162 C.addCommand(std::make_unique<CC1Command>(
8164 Output,
D.getPrependArg()));
8166 C.addCommand(std::make_unique<Command>(
8168 Output,
D.getPrependArg()));
8172 if (Output.
getType() == types::TY_Object &&
8173 Args.hasFlag(options::OPT__SLASH_showFilenames,
8174 options::OPT__SLASH_showFilenames_,
false)) {
8175 C.getJobs().getJobs().back()->PrintInputFilenames =
true;
8178 if (Arg *A = Args.getLastArg(options::OPT_pg))
8180 !Args.hasArg(options::OPT_mfentry))
8181 D.Diag(diag::err_drv_argument_not_allowed_with) <<
"-fomit-frame-pointer"
8182 << A->getAsString(Args);
8188 Args.ClaimAllArgs(options::OPT_fpch_preprocess);
8192 Args.ClaimAllArgs(options::OPT_clang_ignored_f_Group);
8193 Args.ClaimAllArgs(options::OPT_clang_ignored_m_Group);
8196 Args.ClaimAllArgs(options::OPT_emit_llvm);
8203 :
Tool(
"clang",
"clang frontend", TC), HasBackend(HasIntegratedBackend) {}
8210ObjCRuntime Clang::AddObjCRuntimeArgs(
const ArgList &args,
8212 ArgStringList &cmdArgs,
8213 RewriteKind rewriteKind)
const {
8216 args.getLastArg(options::OPT_fnext_runtime, options::OPT_fgnu_runtime,
8217 options::OPT_fobjc_runtime_EQ);
8222 runtimeArg->getOption().matches(options::OPT_fobjc_runtime_EQ)) {
8224 StringRef value = runtimeArg->getValue();
8230 (runtime.
getVersion() >= VersionTuple(2, 0)))
8234 diag::err_drv_gnustep_objc_runtime_incompatible_binary)
8238 runtimeArg->render(args, cmdArgs);
8247 unsigned objcABIVersion = 1;
8249 if (Arg *abiArg = args.getLastArg(options::OPT_fobjc_abi_version_EQ)) {
8250 StringRef value = abiArg->getValue();
8253 else if (value ==
"2")
8255 else if (value ==
"3")
8261 bool nonFragileABIIsDefault =
8262 (rewriteKind == RK_NonFragile ||
8263 (rewriteKind == RK_None &&
8265 if (args.hasFlag(options::OPT_fobjc_nonfragile_abi,
8266 options::OPT_fno_objc_nonfragile_abi,
8267 nonFragileABIIsDefault)) {
8269#ifdef DISABLE_DEFAULT_NONFRAGILEABI_TWO
8270 unsigned nonFragileABIVersion = 1;
8272 unsigned nonFragileABIVersion = 2;
8276 args.getLastArg(options::OPT_fobjc_nonfragile_abi_version_EQ)) {
8277 StringRef value = abiArg->getValue();
8279 nonFragileABIVersion = 1;
8280 else if (value ==
"2")
8281 nonFragileABIVersion = 2;
8287 objcABIVersion = 1 + nonFragileABIVersion;
8295 bool isNonFragile = objcABIVersion != 1;
8301 switch (rewriteKind) {
8314 }
else if (runtimeArg->getOption().matches(options::OPT_fnext_runtime)) {
8326 assert(runtimeArg->getOption().matches(options::OPT_fgnu_runtime));
8335 if (llvm::any_of(inputs, [](
const InputInfo &input) {
8339 args.MakeArgString(
"-fobjc-runtime=" + runtime.
getAsString()));
8344 bool HaveDash = (I + 1 < EH.size() && EH[I + 1] ==
'-');
8352 bool Asynch =
false;
8353 bool NoUnwindC =
false;
8365 bool isWindowsMSVC) {
8368 std::vector<std::string> EHArgs =
8369 Args.getAllArgValues(options::OPT__SLASH_EH);
8370 for (
const auto &EHVal : EHArgs) {
8371 for (
size_t I = 0,
E = EHVal.size(); I !=
E; ++I) {
8377 if (!isWindowsMSVC) {
8379 D.Diag(clang::diag::warn_drv_unused_argument) <<
"/EHa" << EHVal;
8396 D.Diag(clang::diag::err_drv_invalid_value) <<
"/EH" << EHVal;
8402 if (EHArgs.empty() &&
8403 Args.hasFlag(options::OPT__SLASH_GX, options::OPT__SLASH_GX_,
8406 EH.NoUnwindC =
true;
8409 if (Args.hasArg(options::OPT__SLASH_kernel)) {
8411 EH.NoUnwindC =
false;
8418void Clang::AddClangCLArgs(
const ArgList &Args,
types::ID InputType,
8419 ArgStringList &CmdArgs)
const {
8424 if (Arg *ShowIncludes =
8425 Args.getLastArg(options::OPT__SLASH_showIncludes,
8426 options::OPT__SLASH_showIncludes_user)) {
8427 CmdArgs.push_back(
"--show-includes");
8428 if (ShowIncludes->getOption().matches(options::OPT__SLASH_showIncludes))
8429 CmdArgs.push_back(
"-sys-header-deps");
8433 if (Args.hasFlag(options::OPT__SLASH_GR_, options::OPT__SLASH_GR,
8435 CmdArgs.push_back(
"-fno-rtti-data");
8439 if (!isNVPTX && Args.hasFlag(options::OPT__SLASH_GS, options::OPT__SLASH_GS_,
8441 CmdArgs.push_back(
"-stack-protector");
8449 if (!isNVPTX && (EH.Synch || EH.Asynch)) {
8451 CmdArgs.push_back(
"-fcxx-exceptions");
8452 CmdArgs.push_back(
"-fexceptions");
8454 CmdArgs.push_back(
"-fasync-exceptions");
8456 if (
types::isCXX(InputType) && EH.Synch && EH.NoUnwindC)
8457 CmdArgs.push_back(
"-fexternc-nounwind");
8460 if (Args.hasArg(options::OPT__SLASH_EP)) {
8461 CmdArgs.push_back(
"-E");
8462 CmdArgs.push_back(
"-P");
8465 if (Args.hasFlag(options::OPT__SLASH_Zc_dllexportInlines_,
8466 options::OPT__SLASH_Zc_dllexportInlines,
8468 CmdArgs.push_back(
"-fno-dllexport-inlines");
8471 if (Args.hasFlag(options::OPT__SLASH_Zc_wchar_t_,
8472 options::OPT__SLASH_Zc_wchar_t,
false)) {
8473 CmdArgs.push_back(
"-fno-wchar");
8476 if (Args.hasArg(options::OPT__SLASH_kernel)) {
8478 std::vector<std::string> Values =
8479 Args.getAllArgValues(options::OPT__SLASH_arch);
8480 if (!Values.empty()) {
8481 llvm::SmallSet<std::string, 4> SupportedArches;
8482 if (Arch == llvm::Triple::x86)
8483 SupportedArches.insert(
"IA32");
8485 for (
auto &
V : Values)
8486 if (!SupportedArches.contains(
V))
8487 D.Diag(diag::err_drv_argument_not_allowed_with)
8488 << std::string(
"/arch:").append(
V) <<
"/kernel";
8491 CmdArgs.push_back(
"-fno-rtti");
8492 if (Args.hasFlag(options::OPT__SLASH_GR, options::OPT__SLASH_GR_,
false))
8493 D.Diag(diag::err_drv_argument_not_allowed_with) <<
"/GR"
8497 Arg *MostGeneralArg = Args.getLastArg(options::OPT__SLASH_vmg);
8498 Arg *BestCaseArg = Args.getLastArg(options::OPT__SLASH_vmb);
8499 if (MostGeneralArg && BestCaseArg)
8500 D.Diag(clang::diag::err_drv_argument_not_allowed_with)
8501 << MostGeneralArg->getAsString(Args) << BestCaseArg->getAsString(Args);
8503 if (MostGeneralArg) {
8504 Arg *SingleArg = Args.getLastArg(options::OPT__SLASH_vms);
8505 Arg *MultipleArg = Args.getLastArg(options::OPT__SLASH_vmm);
8506 Arg *VirtualArg = Args.getLastArg(options::OPT__SLASH_vmv);
8508 Arg *FirstConflict = SingleArg ? SingleArg : MultipleArg;
8509 Arg *SecondConflict = VirtualArg ? VirtualArg : MultipleArg;
8510 if (FirstConflict && SecondConflict && FirstConflict != SecondConflict)
8511 D.Diag(clang::diag::err_drv_argument_not_allowed_with)
8512 << FirstConflict->getAsString(Args)
8513 << SecondConflict->getAsString(Args);
8516 CmdArgs.push_back(
"-fms-memptr-rep=single");
8517 else if (MultipleArg)
8518 CmdArgs.push_back(
"-fms-memptr-rep=multiple");
8520 CmdArgs.push_back(
"-fms-memptr-rep=virtual");
8523 if (Args.hasArg(options::OPT_regcall4))
8524 CmdArgs.push_back(
"-regcall4");
8528 Args.getLastArg(options::OPT__SLASH_Gd, options::OPT__SLASH_Gr,
8529 options::OPT__SLASH_Gz, options::OPT__SLASH_Gv,
8530 options::OPT__SLASH_Gregcall)) {
8531 unsigned DCCOptId = CCArg->getOption().
getID();
8532 const char *DCCFlag =
nullptr;
8533 bool ArchSupported = !isNVPTX;
8536 case options::OPT__SLASH_Gd:
8537 DCCFlag =
"-fdefault-calling-conv=cdecl";
8539 case options::OPT__SLASH_Gr:
8540 ArchSupported = Arch == llvm::Triple::x86;
8541 DCCFlag =
"-fdefault-calling-conv=fastcall";
8543 case options::OPT__SLASH_Gz:
8544 ArchSupported = Arch == llvm::Triple::x86;
8545 DCCFlag =
"-fdefault-calling-conv=stdcall";
8547 case options::OPT__SLASH_Gv:
8548 ArchSupported = Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64;
8549 DCCFlag =
"-fdefault-calling-conv=vectorcall";
8551 case options::OPT__SLASH_Gregcall:
8552 ArchSupported = Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64;
8553 DCCFlag =
"-fdefault-calling-conv=regcall";
8558 if (ArchSupported && DCCFlag)
8559 CmdArgs.push_back(DCCFlag);
8562 if (Args.hasArg(options::OPT__SLASH_Gregcall4))
8563 CmdArgs.push_back(
"-regcall4");
8565 Args.AddLastArg(CmdArgs, options::OPT_vtordisp_mode_EQ);
8567 if (!Args.hasArg(options::OPT_fdiagnostics_format_EQ)) {
8568 CmdArgs.push_back(
"-fdiagnostics-format");
8569 CmdArgs.push_back(
"msvc");
8572 if (Args.hasArg(options::OPT__SLASH_kernel))
8573 CmdArgs.push_back(
"-fms-kernel");
8575 for (
const Arg *A : Args.filtered(options::OPT__SLASH_guard)) {
8576 StringRef GuardArgs = A->getValue();
8579 if (GuardArgs.equals_insensitive(
"cf")) {
8581 CmdArgs.push_back(
"-cfguard");
8582 }
else if (GuardArgs.equals_insensitive(
"cf,nochecks")) {
8584 CmdArgs.push_back(
"-cfguard-no-checks");
8585 }
else if (GuardArgs.equals_insensitive(
"ehcont")) {
8587 CmdArgs.push_back(
"-ehcontguard");
8588 }
else if (GuardArgs.equals_insensitive(
"cf-") ||
8589 GuardArgs.equals_insensitive(
"ehcont-")) {
8592 D.Diag(diag::err_drv_invalid_value) << A->getSpelling() << GuardArgs;
8600 return Args.MakeArgString(llvm::sys::path::filename(Input.
getBaseInput()));
8607 if (
const char *End = strrchr(Str,
'.'))
8608 return Args.MakeArgString(std::string(Str, End));
8617 if (Arg *OutputOpt = Args.getLastArg(options::OPT_o)) {
8619 llvm::sys::path::replace_extension(OutputFilename, llvm::Twine(
'd'));
8620 return Args.MakeArgString(OutputFilename);
8629 ArgStringList &CmdArgs)
const {
8635 CmdArgs.push_back(
"-target-abi");
8636 CmdArgs.push_back(ABIName.data());
8640 ArgStringList &CmdArgs)
const {
8644 if (Arg *A = Args.getLastArg(options::OPT_masm_EQ)) {
8645 StringRef
Value = A->getValue();
8647 CmdArgs.push_back(
"-mllvm");
8648 CmdArgs.push_back(Args.MakeArgString(
"-x86-asm-syntax=" +
Value));
8651 << A->getSpelling() <<
Value;
8657 ArgStringList &CmdArgs)
const {
8658 CmdArgs.push_back(
"-target-abi");
8665 ArgStringList &CmdArgs)
const {
8669 CmdArgs.push_back(
"-target-abi");
8670 CmdArgs.push_back(ABIName.data());
8672 if (Args.hasFlag(options::OPT_mdefault_build_attributes,
8673 options::OPT_mno_default_build_attributes,
true)) {
8674 CmdArgs.push_back(
"-mllvm");
8675 CmdArgs.push_back(
"-riscv-add-build-attributes");
8681 const ArgList &Args,
8682 const char *LinkingOutput)
const {
8683 ArgStringList CmdArgs;
8685 assert(Inputs.size() == 1 &&
"Unexpected number of inputs.");
8689 const std::string &TripleStr = Triple.getTriple();
8693 Args.ClaimAllArgs(options::OPT_w);
8695 Args.ClaimAllArgs(options::OPT_emit_llvm);
8702 CmdArgs.push_back(
"-cc1as");
8705 CmdArgs.push_back(
"-triple");
8706 CmdArgs.push_back(Args.MakeArgString(TripleStr));
8712 CmdArgs.push_back(
"-filetype");
8713 CmdArgs.push_back(
"obj");
8717 CmdArgs.push_back(
"-main-file-name");
8721 std::string CPU =
getCPUName(
D, Args, Triple,
true);
8723 CmdArgs.push_back(
"-target-cpu");
8724 CmdArgs.push_back(Args.MakeArgString(CPU));
8731 (void)Args.hasArg(options::OPT_force__cpusubtype__ALL);
8734 Args.AddAllArgs(CmdArgs, options::OPT_I_Group);
8737 Args.AddAllArgs(CmdArgs, options::OPT_embed_dir_EQ);
8740 auto FindSource = [](
const Action *S) ->
const Action * {
8742 assert(!S->getInputs().empty() &&
"unexpected root action!");
8743 S = S->getInputs()[0];
8747 const Action *SourceAction = FindSource(&JA);
8751 bool WantDebug =
false;
8752 Args.ClaimAllArgs(options::OPT_g_Group);
8753 if (Arg *A = Args.getLastArg(options::OPT_g_Group))
8754 WantDebug = !A->getOption().matches(options::OPT_g0) &&
8755 !A->getOption().matches(options::OPT_ggdb0);
8758 bool EmitDwarf =
false;
8762 bool EmitCodeView =
false;
8763 if (
const Arg *A = Args.getLastArg(options::OPT_gcodeview))
8768 if (!EmitCodeView && !EmitDwarf && WantDebug) {
8770 case llvm::codegenoptions::DIF_CodeView:
8771 EmitCodeView =
true;
8773 case llvm::codegenoptions::DIF_DWARF:
8783 llvm::codegenoptions::DebugInfoKind DebugInfoKind =
8784 llvm::codegenoptions::NoDebugInfo;
8787 const char *DebugCompilationDir =
8790 if (SourceAction->
getType() == types::TY_Asm ||
8791 SourceAction->
getType() == types::TY_PP_Asm) {
8796 DebugInfoKind = (WantDebug ? llvm::codegenoptions::DebugInfoConstructor
8797 : llvm::codegenoptions::NoDebugInfo);
8804 CmdArgs.push_back(
"-dwarf-debug-producer");
8808 Args.AddAllArgs(CmdArgs, options::OPT_I);
8812 llvm::DebuggerKind::Default);
8818 llvm::Reloc::Model RelocationModel;
8821 std::tie(RelocationModel, PICLevel, IsPIE) =
8826 CmdArgs.push_back(
"-mrelocation-model");
8827 CmdArgs.push_back(RMName);
8833 ArgStringList OriginalArgs;
8834 for (
const auto &Arg : Args)
8835 Arg->render(Args, OriginalArgs);
8840 for (
const char *OriginalArg : OriginalArgs) {
8844 Flags += EscapedArg;
8846 CmdArgs.push_back(
"-dwarf-debug-flags");
8847 CmdArgs.push_back(Args.MakeArgString(Flags));
8857 case llvm::Triple::mips:
8858 case llvm::Triple::mipsel:
8859 case llvm::Triple::mips64:
8860 case llvm::Triple::mips64el:
8864 case llvm::Triple::x86:
8865 case llvm::Triple::x86_64:
8869 case llvm::Triple::arm:
8870 case llvm::Triple::armeb:
8871 case llvm::Triple::thumb:
8872 case llvm::Triple::thumbeb:
8875 if (Args.hasFlag(options::OPT_mdefault_build_attributes,
8876 options::OPT_mno_default_build_attributes,
true)) {
8877 CmdArgs.push_back(
"-mllvm");
8878 CmdArgs.push_back(
"-arm-add-build-attributes");
8882 case llvm::Triple::aarch64:
8883 case llvm::Triple::aarch64_32:
8884 case llvm::Triple::aarch64_be:
8885 if (Args.hasArg(options::OPT_mmark_bti_property)) {
8886 CmdArgs.push_back(
"-mllvm");
8887 CmdArgs.push_back(
"-aarch64-mark-bti-property");
8891 case llvm::Triple::loongarch32:
8892 case llvm::Triple::loongarch64:
8896 case llvm::Triple::riscv32:
8897 case llvm::Triple::riscv64:
8901 case llvm::Triple::hexagon:
8902 if (Args.hasFlag(options::OPT_mdefault_build_attributes,
8903 options::OPT_mno_default_build_attributes,
true)) {
8904 CmdArgs.push_back(
"-mllvm");
8905 CmdArgs.push_back(
"-hexagon-add-build-attributes");
8915 Args.ClaimAllArgs(options::OPT_W_Group);
8920 Args.AddAllArgs(CmdArgs, options::OPT_mllvm);
8922 if (DebugInfoKind > llvm::codegenoptions::NoDebugInfo && Output.
isFilename())
8929 if (SourceAction != FindSource(&J.getSource()))
8931 auto &JArgs = J.getArguments();
8932 for (
unsigned I = 0; I < JArgs.size(); ++I) {
8933 if (StringRef(JArgs[I]).starts_with(
"-object-file-name=") &&
8935 ArgStringList NewArgs(JArgs.begin(), JArgs.begin() + I);
8938 NewArgs.append(JArgs.begin() + I + 1, JArgs.end());
8939 J.replaceArguments(NewArgs);
8945 assert(Output.
isFilename() &&
"Unexpected lipo output.");
8946 CmdArgs.push_back(
"-o");
8952 T.isOSBinFormatELF()) {
8953 CmdArgs.push_back(
"-split-dwarf-output");
8957 if (Triple.isAMDGPU())
8960 assert(Input.
isFilename() &&
"Invalid input.");
8964 if (
D.CC1Main && !
D.CCGenDiagnostics) {
8966 C.addCommand(std::make_unique<CC1Command>(
8968 Output,
D.getPrependArg()));
8970 C.addCommand(std::make_unique<Command>(
8972 Output,
D.getPrependArg()));
8980 const llvm::opt::ArgList &TCArgs,
8981 const char *LinkingOutput)
const {
8983 assert(isa<OffloadBundlingJobAction>(JA) &&
"Expecting bundling job!");
8993 ArgStringList CmdArgs;
8996 CmdArgs.push_back(TCArgs.MakeArgString(
8999 assert(JA.
getInputs().size() == Inputs.size() &&
9000 "Not have inputs for all dependence actions??");
9004 Triples +=
"-targets=";
9005 for (
unsigned I = 0; I < Inputs.size(); ++I) {
9014 if (
const auto *OA = dyn_cast<OffloadAction>(CurDep)) {
9016 OA->doOnEachDependence([&](
Action *A,
const ToolChain *TC,
const char *) {
9017 assert(CurTC ==
nullptr &&
"Expected one dependence!");
9024 Triples += CurTC->
getTriple().normalize();
9033 StringRef GPUArchName;
9036 for (
unsigned ArgIndex = 0; ArgIndex < TCArgs.size(); ArgIndex++) {
9037 auto ArchStr = StringRef(TCArgs.getArgString(ArgIndex));
9038 auto Arch = ArchStr.starts_with_insensitive(
"-march=");
9040 GPUArchName = ArchStr.substr(7);
9045 Triples += GPUArchName.str();
9048 CmdArgs.push_back(TCArgs.MakeArgString(Triples));
9052 TCArgs.MakeArgString(Twine(
"-output=") + Output.
getFilename()));
9055 for (
unsigned I = 0; I < Inputs.size(); ++I) {
9061 if (
const auto *OA = dyn_cast<OffloadAction>(JA.
getInputs()[I])) {
9063 OA->doOnEachDependence([&](
Action *,
const ToolChain *TC,
const char *) {
9064 assert(CurTC ==
nullptr &&
"Expected one dependence!");
9067 UB +=
C.addTempFile(
9072 CmdArgs.push_back(TCArgs.MakeArgString(UB));
9076 C.addCommand(std::make_unique<Command>(
9079 CmdArgs, std::nullopt, Output));
9084 const InputInfoList &Inputs,
const llvm::opt::ArgList &TCArgs,
9085 const char *LinkingOutput)
const {
9087 auto &UA = cast<OffloadUnbundlingJobAction>(JA);
9098 ArgStringList CmdArgs;
9100 assert(Inputs.size() == 1 &&
"Expecting to unbundle a single file!");
9104 CmdArgs.push_back(TCArgs.MakeArgString(
9109 Triples +=
"-targets=";
9110 auto DepInfo = UA.getDependentActionsInfo();
9111 for (
unsigned I = 0; I < DepInfo.size(); ++I) {
9115 auto &Dep = DepInfo[I];
9118 Triples += Dep.DependentToolChain->getTriple().normalize();
9121 !Dep.DependentBoundArch.empty()) {
9123 Triples += Dep.DependentBoundArch;
9127 StringRef GPUArchName;
9130 for (
unsigned ArgIndex = 0; ArgIndex < TCArgs.size(); ArgIndex++) {
9131 StringRef ArchStr = StringRef(TCArgs.getArgString(ArgIndex));
9132 auto Arch = ArchStr.starts_with_insensitive(
"-march=");
9134 GPUArchName = ArchStr.substr(7);
9139 Triples += GPUArchName.str();
9143 CmdArgs.push_back(TCArgs.MakeArgString(Triples));
9147 TCArgs.MakeArgString(Twine(
"-input=") + Input.
getFilename()));
9150 for (
unsigned I = 0; I < Outputs.size(); ++I) {
9153 UB += DepInfo[I].DependentToolChain->getInputFilename(Outputs[I]);
9154 CmdArgs.push_back(TCArgs.MakeArgString(UB));
9156 CmdArgs.push_back(
"-unbundle");
9157 CmdArgs.push_back(
"-allow-missing-bundles");
9158 if (TCArgs.hasArg(options::OPT_v))
9159 CmdArgs.push_back(
"-verbose");
9162 C.addCommand(std::make_unique<Command>(
9165 CmdArgs, std::nullopt, Outputs));
9171 const llvm::opt::ArgList &Args,
9172 const char *LinkingOutput)
const {
9173 ArgStringList CmdArgs;
9176 assert(Output.
isFilename() &&
"Invalid output.");
9177 CmdArgs.push_back(
"-o");
9184 const ArgList &TCArgs =
9190 : TCArgs.getLastArgValue(options::OPT_march_EQ);
9194 ArgStringList Features;
9198 llvm::copy_if(Features, std::back_inserter(FeatureArgs),
9199 [](StringRef Arg) {
return !Arg.starts_with(
"-target"); });
9204 "file=" +
File.str(),
9206 "arch=" + Arch.str(),
9207 "kind=" + Kind.str(),
9211 for (StringRef Feature : FeatureArgs)
9212 Parts.emplace_back(
"feature=" + Feature.str());
9214 CmdArgs.push_back(Args.MakeArgString(
"--image=" + llvm::join(Parts,
",")));
9217 C.addCommand(std::make_unique<Command>(
9220 CmdArgs, Inputs, Output));
9226 const ArgList &Args,
9227 const char *LinkingOutput)
const {
9230 ArgStringList CmdArgs;
9234 auto TCRange =
C.getOffloadToolChains(Kind);
9235 for (
auto &I : llvm::make_range(TCRange)) {
9239 if (CudaInstallation.
isValid())
9240 CmdArgs.push_back(Args.MakeArgString(
9248 if (
const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
9250 if (A->getOption().matches(options::OPT_O4) ||
9251 A->getOption().matches(options::OPT_Ofast))
9253 else if (A->getOption().matches(options::OPT_O)) {
9254 OOpt = A->getValue();
9257 else if (OOpt ==
"s" || OOpt ==
"z")
9259 }
else if (A->getOption().matches(options::OPT_O0))
9262 CmdArgs.push_back(Args.MakeArgString(Twine(
"--opt-level=O") + OOpt));
9266 Args.MakeArgString(
"--host-triple=" + TheTriple.getTriple()));
9267 if (Args.hasArg(options::OPT_v))
9268 CmdArgs.push_back(
"--wrapper-verbose");
9270 if (
const Arg *A = Args.getLastArg(options::OPT_g_Group)) {
9271 if (!A->getOption().matches(options::OPT_g0))
9272 CmdArgs.push_back(
"--device-debug");
9277 if (
const Arg *A = Args.getLastArg(options::OPT_mcode_object_version_EQ)) {
9278 CmdArgs.push_back(Args.MakeArgString(
"-mllvm"));
9279 CmdArgs.push_back(Args.MakeArgString(
9280 Twine(
"--amdhsa-code-object-version=") + A->getValue()));
9283 for (
const auto &A : Args.getAllArgValues(options::OPT_Xcuda_ptxas))
9284 CmdArgs.push_back(Args.MakeArgString(
"--ptxas-arg=" + A));
9287 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_EQ))
9288 CmdArgs.push_back(Args.MakeArgString(Twine(
"--offload-opt=-pass-remarks=") +
9290 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_missed_EQ))
9291 CmdArgs.push_back(Args.MakeArgString(
9292 Twine(
"--offload-opt=-pass-remarks-missed=") + A->getValue()));
9293 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_analysis_EQ))
9294 CmdArgs.push_back(Args.MakeArgString(
9295 Twine(
"--offload-opt=-pass-remarks-analysis=") + A->getValue()));
9297 if (Args.getLastArg(options::OPT_ftime_report))
9298 CmdArgs.push_back(
"--device-compiler=-ftime-report");
9300 if (Args.getLastArg(options::OPT_save_temps_EQ))
9301 CmdArgs.push_back(
"--save-temps");
9304 Linker->
ConstructJob(
C, JA, Output, Inputs, Args, LinkingOutput);
9305 const auto &LinkCommand =
C.getJobs().getJobs().back();
9308 for (Arg *A : Args.filtered(options::OPT_Xoffload_linker)) {
9309 StringRef Val = A->getValue(0);
9312 Args.MakeArgString(Twine(
"--device-linker=") + A->getValue(1)));
9314 CmdArgs.push_back(Args.MakeArgString(
9315 "--device-linker=" +
9319 Args.ClaimAllArgs(options::OPT_Xoffload_linker);
9322 if (Args.hasFlag(options::OPT_fopenmp_target_jit,
9323 options::OPT_fno_openmp_target_jit,
false))
9324 CmdArgs.push_back(
"--embed-bitcode");
9327 for (Arg *A : Args.filtered(options::OPT_mllvm)) {
9328 CmdArgs.push_back(
"-mllvm");
9329 CmdArgs.push_back(A->getValue());
9334 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_r, options::OPT_nogpulib,
9335 options::OPT_nodefaultlibs, options::OPT_nolibc,
9336 options::OPT_nogpulibc)) {
9344 CmdArgs.push_back(Args.MakeArgString(
9346 CmdArgs.push_back(Args.MakeArgString(
9354 "-lclang_rt.builtins"));
9360 if (!Args.hasFlag(options::OPT_gpulibc, options::OPT_nogpulibc,
true))
9361 CmdArgs.push_back(
"--device-compiler=-nolibc");
9364 CmdArgs.push_back(Args.MakeArgString(Twine(
"--linker-path=") +
9365 LinkCommand->getExecutable()));
9366 for (
const char *LinkArg : LinkCommand->getArguments())
9367 CmdArgs.push_back(LinkArg);
9372 Args.MakeArgString(
getToolChain().GetProgramPath(
"clang-linker-wrapper"));
9376 LinkCommand->replaceExecutable(Exec);
9377 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()