15 #include "clang/Config/config.h"
24 #include "llvm/ADT/ArrayRef.h"
25 #include "llvm/ADT/STLExtras.h"
26 #include "llvm/ADT/StringExtras.h"
27 #include "llvm/ADT/StringSet.h"
28 #include "llvm/ADT/StringSwitch.h"
29 #include "llvm/Option/Arg.h"
30 #include "llvm/Option/ArgList.h"
31 #include "llvm/Option/OptSpecifier.h"
32 #include "llvm/Option/OptTable.h"
33 #include "llvm/Option/Option.h"
34 #include "llvm/Support/Debug.h"
35 #include "llvm/Support/ErrorHandling.h"
36 #include "llvm/Support/FileSystem.h"
37 #include "llvm/Support/Path.h"
38 #include "llvm/Support/PrettyStackTrace.h"
39 #include "llvm/Support/Process.h"
40 #include "llvm/Support/Program.h"
41 #include "llvm/Support/raw_ostream.h"
45 using namespace clang::driver;
46 using namespace clang;
47 using namespace llvm::opt;
53 SaveTemps(SaveTempsNone), LTOMode(
LTOK_None),
54 ClangExecutable(ClangExecutable),
55 SysRoot(DEFAULT_SYSROOT), UseStdLib(
true),
56 DefaultTargetTriple(DefaultTargetTriple),
57 DriverTitle(
"clang LLVM compiler"), CCPrintOptionsFilename(nullptr),
58 CCPrintHeadersFilename(nullptr), CCLogDiagnosticsFilename(nullptr),
59 CCCPrintBindings(
false), CCPrintHeaders(
false), CCLogDiagnostics(
false),
60 CCGenDiagnostics(
false), CCCGenericGCCName(
""), CheckInputsExist(
true),
61 CCCUsePCH(
true), SuppressMissingInputWarning(
false) {
67 Name = llvm::sys::path::filename(ClangExecutable);
68 Dir = llvm::sys::path::parent_path(ClangExecutable);
72 StringRef ClangResourceDir(CLANG_RESOURCE_DIR);
74 if (ClangResourceDir !=
"") {
75 llvm::sys::path::append(P, ClangResourceDir);
77 StringRef ClangLibdirSuffix(CLANG_LIBDIR_SUFFIX);
78 llvm::sys::path::append(P,
"..", Twine(
"lib") + ClangLibdirSuffix,
"clang",
87 llvm::DeleteContainerSeconds(ToolChains);
91 const std::string OptName =
92 getOpts().getOption(options::OPT_driver_mode).getPrefixedName();
94 for (
const char *ArgPtr : Args) {
96 if (ArgPtr ==
nullptr)
98 const StringRef Arg = ArgPtr;
99 if (!Arg.startswith(OptName))
102 const StringRef
Value = Arg.drop_front(OptName.size());
103 const unsigned M = llvm::StringSwitch<unsigned>(
Value)
104 .Case(
"gcc", GCCMode)
105 .Case(
"g++", GXXMode)
106 .Case(
"cpp", CPPMode)
111 Mode =
static_cast<DriverMode
>(M);
113 Diag(diag::err_drv_unsupported_option_argument) << OptName <<
Value;
118 llvm::PrettyStackTraceString CrashInfo(
"Command line argument parsing");
120 unsigned IncludedFlagsBitmask;
121 unsigned ExcludedFlagsBitmask;
122 std::tie(IncludedFlagsBitmask, ExcludedFlagsBitmask) =
123 getIncludeExcludeOptionFlagMasks();
125 unsigned MissingArgIndex, MissingArgCount;
127 getOpts().ParseArgs(ArgStrings, MissingArgIndex, MissingArgCount,
128 IncludedFlagsBitmask, ExcludedFlagsBitmask);
132 Diag(clang::diag::err_drv_missing_argument)
133 << Args.getArgString(MissingArgIndex) << MissingArgCount;
136 for (
const Arg *A : Args) {
138 Diag(clang::diag::err_drv_unsupported_opt) << A->getAsString(Args);
143 if (A->getOption().matches(options::OPT_mcpu_EQ) && A->containsValue(
"")) {
144 Diag(clang::diag::warn_drv_empty_joined_argument) << A->getAsString(Args);
148 for (
const Arg *A : Args.filtered(options::OPT_UNKNOWN))
149 Diags.
Report(diag::err_drv_unknown_argument) << A->getAsString(Args);
157 phases::ID Driver::getFinalPhase(
const DerivedArgList &DAL,
158 Arg **FinalPhaseArg)
const {
159 Arg *PhaseArg =
nullptr;
163 if (
CCCIsCPP() || (PhaseArg = DAL.getLastArg(options::OPT_E)) ||
164 (PhaseArg = DAL.getLastArg(options::OPT__SLASH_EP)) ||
165 (PhaseArg = DAL.getLastArg(options::OPT_M, options::OPT_MM)) ||
166 (PhaseArg = DAL.getLastArg(options::OPT__SLASH_P))) {
170 }
else if ((PhaseArg = DAL.getLastArg(options::OPT_fsyntax_only)) ||
171 (PhaseArg = DAL.getLastArg(options::OPT_module_file_info)) ||
172 (PhaseArg = DAL.getLastArg(options::OPT_verify_pch)) ||
173 (PhaseArg = DAL.getLastArg(options::OPT_rewrite_objc)) ||
174 (PhaseArg = DAL.getLastArg(options::OPT_rewrite_legacy_objc)) ||
175 (PhaseArg = DAL.getLastArg(options::OPT__migrate)) ||
176 (PhaseArg = DAL.getLastArg(options::OPT__analyze,
177 options::OPT__analyze_auto)) ||
178 (PhaseArg = DAL.getLastArg(options::OPT_emit_ast))) {
182 }
else if ((PhaseArg = DAL.getLastArg(options::OPT_S))) {
186 }
else if ((PhaseArg = DAL.getLastArg(options::OPT_c))) {
194 *FinalPhaseArg = PhaseArg;
201 Arg *A =
new Arg(Opts->getOption(options::OPT_INPUT),
Value,
202 Args.getBaseArgs().MakeIndex(Value), Value.data());
203 Args.AddSynthesizedArg(A);
208 DerivedArgList *Driver::TranslateInputArgs(
const InputArgList &Args)
const {
209 DerivedArgList *DAL =
new DerivedArgList(Args);
211 bool HasNostdlib = Args.hasArg(options::OPT_nostdlib);
212 bool HasNodefaultlib = Args.hasArg(options::OPT_nodefaultlibs);
213 for (Arg *A : Args) {
220 if ((A->getOption().matches(options::OPT_Wl_COMMA) ||
221 A->getOption().matches(options::OPT_Xlinker)) &&
222 A->containsValue(
"--no-demangle")) {
224 DAL->AddFlagArg(A, Opts->getOption(options::OPT_Z_Xlinker__no_demangle));
227 for (StringRef Val : A->getValues())
228 if (Val !=
"--no-demangle")
229 DAL->AddSeparateArg(A, Opts->getOption(options::OPT_Xlinker), Val);
237 if (A->getOption().matches(options::OPT_Wp_COMMA) &&
238 (A->getValue(0) == StringRef(
"-MD") ||
239 A->getValue(0) == StringRef(
"-MMD"))) {
241 if (A->getValue(0) == StringRef(
"-MD"))
242 DAL->AddFlagArg(A, Opts->getOption(options::OPT_MD));
244 DAL->AddFlagArg(A, Opts->getOption(options::OPT_MMD));
245 if (A->getNumValues() == 2)
246 DAL->AddSeparateArg(A, Opts->getOption(options::OPT_MF),
252 if (A->getOption().matches(options::OPT_l)) {
253 StringRef
Value = A->getValue();
256 if (!HasNostdlib && !HasNodefaultlib && Value ==
"stdc++") {
257 DAL->AddFlagArg(A, Opts->getOption(options::OPT_Z_reserved_lib_stdcxx));
262 if (Value ==
"cc_kext") {
263 DAL->AddFlagArg(A, Opts->getOption(options::OPT_Z_reserved_lib_cckext));
269 if (A->getOption().matches(options::OPT__DASH_DASH)) {
271 for (StringRef Val : A->getValues())
281 #if defined(HOST_LINK_VERSION)
282 if (!Args.hasArg(options::OPT_mlinker_version_EQ) &&
283 strlen(HOST_LINK_VERSION) > 0) {
284 DAL->AddJoinedArg(0, Opts->getOption(options::OPT_mlinker_version_EQ),
286 DAL->getLastArg(options::OPT_mlinker_version_EQ)->claim();
299 StringRef DarwinArchName =
"") {
301 if (
const Arg *A = Args.getLastArg(options::OPT_target))
302 DefaultTargetTriple = A->getValue();
304 llvm::Triple Target(llvm::Triple::normalize(DefaultTargetTriple));
307 if (Target.isOSBinFormatMachO()) {
309 if (!DarwinArchName.empty()) {
315 if (Arg *A = Args.getLastArg(options::OPT_arch)) {
316 StringRef ArchName = A->getValue();
323 if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian,
324 options::OPT_mbig_endian)) {
325 if (A->getOption().matches(options::OPT_mlittle_endian)) {
326 llvm::Triple LE = Target.getLittleEndianArchVariant();
327 if (LE.getArch() != llvm::Triple::UnknownArch)
328 Target = std::move(LE);
330 llvm::Triple BE = Target.getBigEndianArchVariant();
331 if (BE.getArch() != llvm::Triple::UnknownArch)
332 Target = std::move(BE);
337 if (Target.getArch() == llvm::Triple::tce ||
338 Target.getOS() == llvm::Triple::Minix)
342 if (Arg *A = Args.getLastArg(options::OPT_m64, options::OPT_mx32,
343 options::OPT_m32, options::OPT_m16)) {
344 llvm::Triple::ArchType AT = llvm::Triple::UnknownArch;
346 if (A->getOption().matches(options::OPT_m64)) {
347 AT = Target.get64BitArchVariant().getArch();
348 if (Target.getEnvironment() == llvm::Triple::GNUX32)
349 Target.setEnvironment(llvm::Triple::GNU);
350 }
else if (A->getOption().matches(options::OPT_mx32) &&
351 Target.get64BitArchVariant().getArch() == llvm::Triple::x86_64) {
352 AT = llvm::Triple::x86_64;
353 Target.setEnvironment(llvm::Triple::GNUX32);
354 }
else if (A->getOption().matches(options::OPT_m32)) {
355 AT = Target.get32BitArchVariant().getArch();
356 if (Target.getEnvironment() == llvm::Triple::GNUX32)
357 Target.setEnvironment(llvm::Triple::GNU);
358 }
else if (A->getOption().matches(options::OPT_m16) &&
359 Target.get32BitArchVariant().getArch() == llvm::Triple::x86) {
360 AT = llvm::Triple::x86;
361 Target.setEnvironment(llvm::Triple::CODE16);
364 if (AT != llvm::Triple::UnknownArch && AT != Target.getArch())
373 void Driver::setLTOMode(
const llvm::opt::ArgList &Args) {
375 if (!Args.hasFlag(options::OPT_flto, options::OPT_flto_EQ,
376 options::OPT_fno_lto,
false))
379 StringRef LTOName(
"full");
381 const Arg *A = Args.getLastArg(options::OPT_flto_EQ);
383 LTOName = A->getValue();
385 LTOMode = llvm::StringSwitch<LTOKind>(LTOName)
392 Diag(diag::err_drv_unsupported_option_argument) << A->getOption().getName()
398 llvm::PrettyStackTraceString CrashInfo(
"Compilation construction");
403 if (
char *env = ::getenv(
"COMPILER_PATH")) {
404 StringRef CompilerPath = env;
405 while (!CompilerPath.empty()) {
406 std::pair<StringRef, StringRef> Split =
407 CompilerPath.split(llvm::sys::EnvPathSeparator);
409 CompilerPath = Split.second;
428 Args.ClaimAllArgs(options::OPT_no_canonical_prefixes);
431 Args.ClaimAllArgs(options::OPT_pipe);
439 CCCPrintPhases = Args.hasArg(options::OPT_ccc_print_phases);
441 if (
const Arg *A = Args.getLastArg(options::OPT_ccc_gcc_name))
442 CCCGenericGCCName = A->getValue();
444 Args.hasFlag(options::OPT_ccc_pch_is_pch, options::OPT_ccc_pch_is_pth);
450 T.setOS(llvm::Triple::Win32);
451 T.setVendor(llvm::Triple::PC);
452 T.setEnvironment(llvm::Triple::MSVC);
455 if (
const Arg *A = Args.getLastArg(options::OPT_target))
457 if (
const Arg *A = Args.getLastArg(options::OPT_ccc_install_dir))
459 for (
const Arg *A : Args.filtered(options::OPT_B)) {
463 if (
const Arg *A = Args.getLastArg(options::OPT__sysroot_EQ))
465 if (
const Arg *A = Args.getLastArg(options::OPT__dyld_prefix_EQ))
467 if (Args.hasArg(options::OPT_nostdlib))
470 if (
const Arg *A = Args.getLastArg(options::OPT_resource_dir))
473 if (
const Arg *A = Args.getLastArg(options::OPT_save_temps_EQ)) {
474 SaveTemps = llvm::StringSwitch<SaveTempsMode>(A->getValue())
475 .Case(
"cwd", SaveTempsCwd)
476 .Case(
"obj", SaveTempsObj)
477 .Default(SaveTempsCwd);
482 std::unique_ptr<llvm::opt::InputArgList> UArgs =
483 llvm::make_unique<InputArgList>(std::move(Args));
486 DerivedArgList *TranslatedArgs = TranslateInputArgs(*UArgs);
497 ?
"nvptx64-nvidia-cuda"
498 :
"nvptx-nvidia-cuda")));
514 if (CCCPrintPhases) {
524 static void printArgList(raw_ostream &OS,
const llvm::opt::ArgList &Args) {
525 llvm::opt::ArgStringList ASL;
526 for (
const auto *A : Args)
527 A->render(Args, ASL);
529 for (
auto I = ASL.begin(),
E = ASL.end();
I !=
E; ++
I) {
530 if (
I != ASL.begin())
541 const Command &FailingCommand) {
542 if (C.
getArgs().hasArg(options::OPT_fno_crash_diagnostics))
553 Diag(clang::diag::note_drv_command_failed_diag_msg)
554 <<
"PLEASE submit a bug report to " BUG_REPORT_URL
" and include the "
555 "crash backtrace, preprocessed source, and associated run script.";
576 bool IgnoreInput =
false;
582 }
else if (!strcmp(it->second->getValue(),
"-")) {
583 Diag(clang::diag::note_drv_command_failed_diag_msg)
584 <<
"Error generating preprocessed source(s) - "
585 "ignoring input from stdin.";
590 it = Inputs.erase(it);
597 if (Inputs.empty()) {
598 Diag(clang::diag::note_drv_command_failed_diag_msg)
599 <<
"Error generating preprocessed source(s) - "
600 "no preprocessable inputs.";
606 llvm::StringSet<> ArchNames;
607 for (
const Arg *A : C.
getArgs()) {
608 if (A->getOption().matches(options::OPT_arch)) {
609 StringRef ArchName = A->getValue();
610 ArchNames.insert(ArchName);
613 if (ArchNames.size() > 1) {
614 Diag(clang::diag::note_drv_command_failed_diag_msg)
615 <<
"Error generating preprocessed source(s) - cannot generate "
616 "preprocessed source with multiple -arch options.";
632 Diag(clang::diag::note_drv_command_failed_diag_msg)
633 <<
"Error generating preprocessed source(s).";
642 if (!FailingCommands.empty()) {
646 Diag(clang::diag::note_drv_command_failed_diag_msg)
647 <<
"Error generating preprocessed source(s).";
652 if (TempFiles.empty()) {
653 Diag(clang::diag::note_drv_command_failed_diag_msg)
654 <<
"Error generating preprocessed source(s).";
658 Diag(clang::diag::note_drv_command_failed_diag_msg)
659 <<
"\n********************\n\n"
660 "PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\n"
661 "Preprocessed source(s) and associated run script(s) are located at:";
664 for (
const char *TempFile : TempFiles) {
665 Diag(clang::diag::note_drv_command_failed_diag_msg) << TempFile;
666 if (StringRef(TempFile).endswith(
".cache")) {
669 VFS = llvm::sys::path::filename(TempFile);
670 llvm::sys::path::append(VFS,
"vfs",
"vfs.yaml");
677 std::string Script = CrashInfo.
Filename.rsplit(
'.').first.str() +
".sh";
679 llvm::raw_fd_ostream ScriptOS(Script, EC, llvm::sys::fs::F_Excl);
681 Diag(clang::diag::note_drv_command_failed_diag_msg)
682 <<
"Error generating run script: " + Script +
" " + EC.message();
685 <<
"# Driver args: ";
687 ScriptOS <<
"# Original command: ";
688 Cmd.
Print(ScriptOS,
"\n",
true);
689 Cmd.
Print(ScriptOS,
"\n",
true, &CrashInfo);
690 Diag(clang::diag::note_drv_command_failed_diag_msg) << Script;
693 for (
const auto &A : C.
getArgs().filtered(options::OPT_frewrite_map_file,
694 options::OPT_frewrite_map_file_EQ))
695 Diag(clang::diag::note_drv_command_failed_diag_msg) << A->getValue();
697 Diag(clang::diag::note_drv_command_failed_diag_msg)
698 <<
"\n\n********************";
718 if (C.
getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
729 setUpResponseFiles(C, Job);
737 if (FailingCommands.empty())
742 for (
const auto &CmdPair : FailingCommands) {
743 int Res = CmdPair.first;
744 const Command *FailingCommand = CmdPair.second;
768 Diag(clang::diag::err_drv_command_signalled)
779 unsigned IncludedFlagsBitmask;
780 unsigned ExcludedFlagsBitmask;
781 std::tie(IncludedFlagsBitmask, ExcludedFlagsBitmask) =
782 getIncludeExcludeOptionFlagMasks();
786 ExcludedFlagsBitmask |= HelpHidden;
789 IncludedFlagsBitmask, ExcludedFlagsBitmask);
800 if (Arg *A = C.
getArgs().getLastArg(options::OPT_mthread_model)) {
803 OS <<
"Thread model: " << A->getValue();
825 if (C.
getArgs().hasArg(options::OPT_dumpmachine)) {
830 if (C.
getArgs().hasArg(options::OPT_dumpversion)) {
837 llvm::outs() <<
"4.2.1\n";
841 if (C.
getArgs().hasArg(options::OPT__print_diagnostic_categories)) {
846 if (C.
getArgs().hasArg(options::OPT_help) ||
847 C.
getArgs().hasArg(options::OPT__help_hidden)) {
852 if (C.
getArgs().hasArg(options::OPT__version)) {
858 if (C.
getArgs().hasArg(options::OPT_v) ||
859 C.
getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
861 SuppressMissingInputWarning =
true;
866 if (C.
getArgs().hasArg(options::OPT_v))
869 if (C.
getArgs().hasArg(options::OPT_print_search_dirs)) {
870 llvm::outs() <<
"programs: =";
871 bool separator =
false;
875 llvm::outs() << Path;
878 llvm::outs() <<
"\n";
888 llvm::outs() << sysroot << Path.substr(1);
890 llvm::outs() << Path;
892 llvm::outs() <<
"\n";
898 if (Arg *A = C.
getArgs().getLastArg(options::OPT_print_file_name_EQ)) {
899 llvm::outs() <<
GetFilePath(A->getValue(), TC) <<
"\n";
903 if (Arg *A = C.
getArgs().getLastArg(options::OPT_print_prog_name_EQ)) {
908 if (C.
getArgs().hasArg(options::OPT_print_libgcc_file_name)) {
909 llvm::outs() <<
GetFilePath(
"libgcc.a", TC) <<
"\n";
913 if (C.
getArgs().hasArg(options::OPT_print_multi_lib)) {
919 if (C.
getArgs().hasArg(options::OPT_print_multi_directory)) {
922 llvm::outs() <<
".\n";
925 assert(Suffix.front() ==
'/');
926 llvm::outs() << Suffix.substr(1) <<
"\n";
938 std::map<Action *, unsigned> &Ids) {
943 llvm::raw_string_ostream os(str);
947 os <<
"\"" << IA->getInputArg().getValue() <<
"\"";
949 os <<
'"' << BIA->getArchName() <<
'"' <<
", {"
952 os <<
'"' << CDA->getGpuArchName() <<
'"' <<
", {"
958 <<
", gpu binaries ";
959 AL = &CHA->getDeviceActions();
964 const char *Prefix =
"{";
965 for (
Action *PreRequisite : *AL) {
974 unsigned Id = Ids.size();
976 llvm::errs() << Id <<
": " << os.str() <<
", "
985 std::map<Action *, unsigned> Ids;
993 if (isa<CompileJobAction>(A) || isa<BackendJobAction>(A) ||
994 isa<AssembleJobAction>(A))
1006 DerivedArgList &Args = C.
getArgs();
1008 llvm::PrettyStackTraceString CrashInfo(
"Building universal build actions");
1011 llvm::StringSet<> ArchNames;
1013 for (Arg *A : Args) {
1014 if (A->getOption().matches(options::OPT_arch)) {
1017 llvm::Triple::ArchType Arch =
1019 if (Arch == llvm::Triple::UnknownArch) {
1020 Diag(clang::diag::err_drv_invalid_arch_name) << A->getAsString(Args);
1025 if (ArchNames.insert(A->getValue()).second)
1026 Archs.push_back(A->getValue());
1040 for (
Action* Act : SingleActions) {
1048 Diag(clang::diag::err_drv_invalid_output_with_multiple_archs)
1052 for (
unsigned i = 0, e = Archs.size(); i != e; ++i)
1057 if (Inputs.size() == 1 || Act->getType() == types::TY_Nothing)
1058 Actions.append(Inputs.begin(), Inputs.end());
1063 Arg *A = Args.getLastArg(options::OPT_g_Group);
1064 if (A && !A->getOption().matches(options::OPT_g0) &&
1065 !A->getOption().matches(options::OPT_gstabs) &&
1072 if (Act->getType() == types::TY_Image) {
1074 Inputs.push_back(Actions.back());
1081 if (Args.hasArg(options::OPT_verify_debug_info)) {
1082 Action* LastAction = Actions.back();
1085 LastAction, types::TY_Nothing));
1103 if (Arg *WorkDir = Args.getLastArg(options::OPT_working_directory)) {
1104 if (!llvm::sys::path::is_absolute(Path)) {
1106 llvm::sys::path::append(Directory, Value);
1107 Path.assign(Directory);
1111 if (llvm::sys::fs::exists(Twine(Path)))
1114 if (D.
IsCLMode() && !llvm::sys::path::is_absolute(Twine(Path)) &&
1115 llvm::sys::Process::FindInEnvPath(
"LIB", Value))
1118 D.
Diag(clang::diag::err_drv_no_such_file) << Path;
1128 types::ID InputType = types::TY_Nothing;
1129 Arg *InputTypeArg =
nullptr;
1132 if (Arg *TCTP = Args.getLastArgNoClaim(options::OPT__SLASH_TC,
1133 options::OPT__SLASH_TP)) {
1134 InputTypeArg = TCTP;
1135 InputType = TCTP->getOption().matches(options::OPT__SLASH_TC)
1140 Args.filtered_begin(options::OPT__SLASH_TC, options::OPT__SLASH_TP);
1141 const arg_iterator ie = Args.filtered_end();
1143 bool ShowNote =
false;
1145 Diag(clang::diag::warn_drv_overriding_flag_option)
1146 << Previous->getSpelling() << (*it)->getSpelling();
1151 Diag(clang::diag::note_drv_t_option_is_global);
1154 assert(!Args.hasArg(options::OPT_x) &&
"-x and /TC or /TP is not allowed");
1157 for (Arg *A : Args) {
1158 if (A->getOption().getKind() == Option::InputClass) {
1159 const char *Value = A->getValue();
1163 if (InputType == types::TY_Nothing) {
1166 InputTypeArg->claim();
1169 if (memcmp(Value,
"-", 2) == 0) {
1175 if (!Args.hasArgNoClaim(options::OPT_E) && !
CCCIsCPP())
1176 Diag(
IsCLMode() ? clang::diag::err_drv_unknown_stdin_type_clang_cl
1177 : clang::diag::err_drv_unknown_stdin_type);
1184 if (
const char *Ext = strrchr(Value,
'.'))
1191 Ty = types::TY_Object;
1201 Diag(clang::diag::warn_drv_treating_input_as_cxx)
1211 if (Ty != types::TY_Object) {
1212 if (Args.hasArg(options::OPT_ObjC))
1213 Ty = types::TY_ObjC;
1214 else if (Args.hasArg(options::OPT_ObjCXX))
1215 Ty = types::TY_ObjCXX;
1218 assert(InputTypeArg &&
"InputType set w/o InputTypeArg");
1219 if (!InputTypeArg->getOption().matches(options::OPT_x)) {
1222 const char *Ext = strrchr(Value,
'.');
1224 Ty = types::TY_Object;
1228 InputTypeArg->claim();
1233 Inputs.push_back(std::make_pair(Ty, A));
1235 }
else if (A->getOption().matches(options::OPT__SLASH_Tc)) {
1236 StringRef Value = A->getValue();
1238 Arg *InputArg =
MakeInputArg(Args, Opts, A->getValue());
1239 Inputs.push_back(std::make_pair(types::TY_C, InputArg));
1242 }
else if (A->getOption().matches(options::OPT__SLASH_Tp)) {
1243 StringRef Value = A->getValue();
1245 Arg *InputArg =
MakeInputArg(Args, Opts, A->getValue());
1246 Inputs.push_back(std::make_pair(types::TY_CXX, InputArg));
1252 Inputs.push_back(std::make_pair(types::TY_Object, A));
1254 }
else if (A->getOption().matches(options::OPT_x)) {
1263 Diag(clang::diag::err_drv_unknown_language) << A->getValue();
1264 InputType = types::TY_Object;
1268 if (
CCCIsCPP() && Inputs.empty()) {
1272 Inputs.push_back(std::make_pair(types::TY_C, A));
1284 const Arg *InputArg,
Action *HostAction,
1286 Arg *PartialCompilationArg = Args.getLastArg(options::OPT_cuda_host_only,
1287 options::OPT_cuda_device_only);
1289 if (PartialCompilationArg &&
1290 PartialCompilationArg->getOption().matches(options::OPT_cuda_host_only))
1295 llvm::StringSet<> GpuArchNames;
1296 for (Arg *A : Args) {
1297 if (!A->getOption().matches(options::OPT_cuda_gpu_arch_EQ))
1301 const auto& Arch = A->getValue();
1303 C.
getDriver().
Diag(clang::diag::err_drv_cuda_bad_gpu_arch) << Arch;
1304 else if (GpuArchNames.insert(Arch).second)
1305 GpuArchList.push_back(Arch);
1310 if (GpuArchList.empty())
1311 GpuArchList.push_back(
"sm_20");
1315 for (
unsigned I = 0,
E = GpuArchList.size();
I !=
E; ++
I)
1316 CudaDeviceInputs.push_back(std::make_pair(types::TY_CUDA_DEVICE, InputArg));
1320 "Missing toolchain for device-side compilation.");
1323 CudaDeviceInputs, CudaDeviceActions);
1324 assert(GpuArchList.size() == CudaDeviceActions.size() &&
1325 "Failed to create actions for all devices");
1328 bool PartialCompilation =
1329 llvm::any_of(CudaDeviceActions, [](
const Action *a) {
1335 bool DeviceOnlyCompilation = PartialCompilationArg !=
nullptr;
1336 if (PartialCompilation || DeviceOnlyCompilation) {
1342 if (Args.hasArg(options::OPT_o) &&
1343 (!DeviceOnlyCompilation || GpuArchList.size() > 1)) {
1345 clang::diag::err_drv_output_argument_with_multiple_files);
1349 for (
unsigned I = 0,
E = GpuArchList.size();
I !=
E; ++
I)
1354 if (DeviceOnlyCompilation)
1362 for (
unsigned I = 0,
E = GpuArchList.size();
I !=
E; ++
I)
1363 DeviceActions.push_back(
1372 DerivedArgList &Args,
const InputList &Inputs,
1374 llvm::PrettyStackTraceString CrashInfo(
"Building compilation actions");
1376 if (!SuppressMissingInputWarning && Inputs.empty()) {
1377 Diag(clang::diag::err_drv_no_input_files);
1382 phases::ID FinalPhase = getFinalPhase(Args, &FinalPhaseArg);
1384 if (FinalPhase ==
phases::Link && Args.hasArg(options::OPT_emit_llvm)) {
1385 Diag(clang::diag::err_drv_emit_llvm_link);
1390 if (Arg *A = Args.getLastArg(options::OPT_Z_Joined))
1391 Diag(clang::diag::err_drv_use_of_Z_option) << A->getAsString(Args);
1394 if (Arg *A = Args.getLastArg(options::OPT__SLASH_Fo)) {
1395 StringRef V = A->getValue();
1396 if (Inputs.size() > 1 && !V.empty() &&
1397 !llvm::sys::path::is_separator(V.back())) {
1399 Diag(clang::diag::err_drv_out_file_argument_with_multiple_sources)
1400 << A->getSpelling() << V;
1401 Args.eraseArg(options::OPT__SLASH_Fo);
1406 if (Arg *A = Args.getLastArg(options::OPT__SLASH_Fa)) {
1407 StringRef V = A->getValue();
1408 if (Inputs.size() > 1 && !V.empty() &&
1409 !llvm::sys::path::is_separator(V.back())) {
1411 Diag(clang::diag::err_drv_out_file_argument_with_multiple_sources)
1412 << A->getSpelling() << V;
1413 Args.eraseArg(options::OPT__SLASH_Fa);
1418 if (Arg *A = Args.getLastArg(options::OPT__SLASH_o)) {
1419 if (A->getValue()[0] ==
'\0') {
1421 Diag(clang::diag::err_drv_missing_argument) << A->getSpelling() << 1;
1422 Args.eraseArg(options::OPT__SLASH_o);
1430 for (
auto &
I : Inputs) {
1432 const Arg *InputArg =
I.second;
1440 if (InitialPhase > FinalPhase) {
1445 if (Args.hasArg(options::OPT_Qunused_arguments))
1451 Diag(clang::diag::warn_drv_input_file_unused_by_cpp)
1452 << InputArg->getAsString(Args) <<
getPhaseName(InitialPhase);
1458 Diag(clang::diag::warn_drv_preprocessed_input_file_unused)
1459 << InputArg->getAsString(Args) << !!FinalPhaseArg
1460 << (FinalPhaseArg ? FinalPhaseArg->getOption().getName() :
"");
1462 Diag(clang::diag::warn_drv_input_file_unused)
1463 << InputArg->getAsString(Args) <<
getPhaseName(InitialPhase)
1465 << (FinalPhaseArg ? FinalPhaseArg->getOption().getName() :
"");
1482 if (Phase > FinalPhase)
1487 assert((i + 1) == e &&
"linking must be final compilation step.");
1488 LinkerInputs.push_back(Current);
1502 if (InputType == types::TY_CUDA && Phase == CudaInjectionPhase) {
1508 if (Current->
getType() == types::TY_Nothing)
1514 Actions.push_back(Current);
1518 if (!LinkerInputs.empty())
1525 Args.ClaimAllArgs(options::OPT_CompileOnly_Group);
1526 Args.ClaimAllArgs(options::OPT_cl_compile_Group);
1530 Args.ClaimAllArgs(options::OPT_cl_ignored_Group);
1534 Args.ClaimAllArgs(options::OPT_cuda_host_only);
1540 llvm::PrettyStackTraceString CrashInfo(
"Constructing phase actions");
1544 llvm_unreachable(
"link action invalid here.");
1548 if (Args.hasArg(options::OPT_M, options::OPT_MM)) {
1549 OutputTy = types::TY_Dependencies;
1552 if (!Args.hasFlag(options::OPT_frewrite_includes,
1553 options::OPT_fno_rewrite_includes,
false) &&
1557 "Cannot preprocess this input type!");
1563 if (Args.hasArg(options::OPT_fsyntax_only)) {
1565 OutputTy = types::TY_Nothing;
1570 if (Args.hasArg(options::OPT_fsyntax_only))
1572 if (Args.hasArg(options::OPT_rewrite_objc))
1574 if (Args.hasArg(options::OPT_rewrite_legacy_objc))
1576 types::TY_RewrittenLegacyObjC);
1577 if (Args.hasArg(options::OPT__analyze, options::OPT__analyze_auto))
1579 if (Args.hasArg(options::OPT__migrate))
1581 if (Args.hasArg(options::OPT_emit_ast))
1583 if (Args.hasArg(options::OPT_module_file_info))
1585 if (Args.hasArg(options::OPT_verify_pch))
1592 Args.hasArg(options::OPT_S) ? types::TY_LTO_IR : types::TY_LTO_BC;
1595 if (Args.hasArg(options::OPT_emit_llvm)) {
1597 Args.hasArg(options::OPT_S) ? types::TY_LLVM_IR : types::TY_LLVM_BC;
1606 llvm_unreachable(
"invalid phase in ConstructPhaseAction");
1610 llvm::PrettyStackTraceString CrashInfo(
"Building compilation jobs");
1612 Arg *FinalOutput = C.
getArgs().getLastArg(options::OPT_o);
1617 unsigned NumOutputs = 0;
1619 if (A->getType() != types::TY_Nothing)
1622 if (NumOutputs > 1) {
1623 Diag(clang::diag::err_drv_output_argument_with_multiple_files);
1624 FinalOutput =
nullptr;
1629 llvm::StringSet<> ArchNames;
1631 for (
const Arg *A : C.
getArgs())
1632 if (A->getOption().matches(options::OPT_arch))
1633 ArchNames.insert(A->getValue());
1642 const char *LinkingOutput =
nullptr;
1643 if (isa<LipoJobAction>(A)) {
1645 LinkingOutput = FinalOutput->getValue();
1653 ArchNames.size() > 1,
1660 C.
getArgs().hasArg(options::OPT_Qunused_arguments))
1664 (void)C.
getArgs().hasArg(options::OPT__HASH_HASH_HASH);
1667 (void)C.
getArgs().hasArg(options::OPT_driver_mode);
1673 if (!A->isClaimed()) {
1679 const Option &Opt = A->getOption();
1680 if (Opt.getKind() == Option::FlagClass) {
1681 bool DuplicateClaimed =
false;
1683 for (
const Arg *AA : C.
getArgs().filtered(&Opt)) {
1684 if (AA->isClaimed()) {
1685 DuplicateClaimed =
true;
1690 if (DuplicateClaimed)
1694 Diag(clang::diag::warn_drv_unused_argument)
1695 << A->getAsString(C.
getArgs());
1709 const Tool *ToolForJob =
nullptr;
1710 CollapsedCHA =
nullptr;
1717 !C.
getArgs().hasArg(options::OPT_via_file_asm) &&
1718 !C.
getArgs().hasArg(options::OPT__SLASH_FA) &&
1719 !C.
getArgs().hasArg(options::OPT__SLASH_Fa) &&
1720 isa<AssembleJobAction>(JA) && Inputs->size() == 1 &&
1721 isa<BackendJobAction>(*Inputs->begin())) {
1726 const ActionList *BackendInputs = &(*Inputs)[0]->getInputs();
1731 cast<CompileJobAction>(CHA ? *CHA->
begin() : *BackendInputs->begin());
1732 assert(CompileJA &&
"Backend job is not preceeded by compile job.");
1737 Inputs = &CompileJA->getInputs();
1738 ToolForJob = Compiler;
1746 if (isa<BackendJobAction>(JA)) {
1748 assert(Inputs->size() == 1);
1753 cast<CompileJobAction>(CHA ? *CHA->begin() : *Inputs->begin());
1754 assert(CompileJA &&
"Backend job is not preceeded by compile job.");
1758 if (!Compiler->
canEmitIR() || !SaveTemps) {
1759 Inputs = &CompileJA->getInputs();
1760 ToolForJob = Compiler;
1772 if (Inputs->size() == 1 && isa<PreprocessJobAction>(*Inputs->begin()) &&
1773 !C.
getArgs().hasArg(options::OPT_no_integrated_cpp) &&
1774 !C.
getArgs().hasArg(options::OPT_traditional_cpp) && !SaveTemps &&
1775 !C.
getArgs().hasArg(options::OPT_rewrite_objc) &&
1777 Inputs = &(*Inputs)[0]->getInputs();
1783 const ToolChain *TC,
const char *BoundArch,
1784 bool AtTopLevel,
bool MultipleArchs,
1785 const char *LinkingOutput)
const {
1786 llvm::PrettyStackTraceString CrashInfo(
"Building compilation jobs");
1791 for (
const Action *DA : CHA->getDeviceActions()) {
1792 CudaDeviceInputInfos.push_back(
1794 false, LinkingOutput));
1801 if (
const InputAction *IA = dyn_cast<InputAction>(A)) {
1804 const Arg &
Input = IA->getInputArg();
1806 if (Input.getOption().matches(options::OPT_INPUT)) {
1807 const char *
Name = Input.getValue();
1825 MultipleArchs, LinkingOutput);
1831 assert(CDA->getGpuArchName() &&
"No GPU name in device action.");
1833 CDA->getGpuArchName(), CDA->isAtTopLevel(),
1834 true, LinkingOutput);
1839 const JobAction *JA = cast<JobAction>(A);
1849 for (
const Action *DA : CollapsedCHA->getDeviceActions()) {
1850 CudaDeviceInputInfos.push_back(
1852 false, LinkingOutput));
1862 bool SubJobAtTopLevel =
1863 AtTopLevel && (isa<DsymutilJobAction>(A) || isa<VerifyJobAction>(A));
1865 SubJobAtTopLevel, MultipleArchs,
1870 const char *BaseInput = InputInfos[0].getBaseInput();
1874 if (JA->
getType() == types::TY_dSYM)
1875 BaseInput = InputInfos[0].getFilename();
1878 if (CudaDeviceInputInfos.size())
1879 InputInfos.append(CudaDeviceInputInfos.begin(), CudaDeviceInputInfos.end());
1883 if (JA->
getType() == types::TY_Nothing)
1887 AtTopLevel, MultipleArchs),
1892 <<
" - \"" << T->
getName() <<
"\", inputs: [";
1893 for (
unsigned i = 0, e = InputInfos.size(); i != e; ++i) {
1894 llvm::errs() << InputInfos[i].getAsString();
1896 llvm::errs() <<
", ";
1898 llvm::errs() <<
"], output: " << Result.
getAsString() <<
"\n";
1908 return Target.isOSWindows() ?
"a.exe" :
"a.out";
1920 if (ArgValue.empty()) {
1922 Filename = BaseName;
1923 }
else if (llvm::sys::path::is_separator(Filename.back())) {
1925 llvm::sys::path::append(Filename, BaseName);
1928 if (!llvm::sys::path::has_extension(ArgValue)) {
1932 if (FileType == types::TY_Image &&
1933 Args.hasArg(options::OPT__SLASH_LD, options::OPT__SLASH_LDd)) {
1938 llvm::sys::path::replace_extension(Filename, Extension);
1941 return Args.MakeArgString(Filename.c_str());
1945 const char *BaseInput,
1946 const char *BoundArch,
bool AtTopLevel,
1947 bool MultipleArchs)
const {
1948 llvm::PrettyStackTraceString CrashInfo(
"Computing output path");
1950 if (AtTopLevel && !isa<DsymutilJobAction>(JA) && !isa<VerifyJobAction>(JA)) {
1951 if (Arg *FinalOutput = C.
getArgs().getLastArg(options::OPT_o))
1956 if (C.
getArgs().hasArg(options::OPT__SLASH_P)) {
1957 assert(AtTopLevel && isa<PreprocessJobAction>(JA));
1958 StringRef BaseName = llvm::sys::path::filename(BaseInput);
1960 if (Arg *A = C.
getArgs().getLastArg(options::OPT__SLASH_Fi))
1961 NameArg = A->getValue();
1969 (isa<PreprocessJobAction>(JA) || JA.
getType() == types::TY_ModuleFile))
1973 if (JA.
getType() == types::TY_PP_Asm &&
1974 (C.
getArgs().hasArg(options::OPT__SLASH_FA) ||
1975 C.
getArgs().hasArg(options::OPT__SLASH_Fa))) {
1977 StringRef BaseName = llvm::sys::path::filename(BaseInput);
1978 StringRef FaValue = C.
getArgs().getLastArgValue(options::OPT__SLASH_Fa);
1986 !C.
getArgs().hasArg(options::OPT__SLASH_Fo)) ||
1988 StringRef
Name = llvm::sys::path::filename(BaseInput);
1989 std::pair<StringRef, StringRef> Split = Name.split(
'.');
1999 if (isa<DsymutilJobAction>(JA) || isa<VerifyJobAction>(JA))
2000 BaseName = BasePath;
2002 BaseName = llvm::sys::path::filename(BasePath);
2005 const char *NamedOutput;
2007 if (JA.
getType() == types::TY_Object &&
2008 C.
getArgs().hasArg(options::OPT__SLASH_Fo, options::OPT__SLASH_o)) {
2012 .getLastArg(options::OPT__SLASH_Fo, options::OPT__SLASH_o)
2016 }
else if (JA.
getType() == types::TY_Image &&
2017 C.
getArgs().hasArg(options::OPT__SLASH_Fe,
2018 options::OPT__SLASH_o)) {
2022 .getLastArg(options::OPT__SLASH_Fe, options::OPT__SLASH_o)
2026 }
else if (JA.
getType() == types::TY_Image) {
2031 }
else if (MultipleArchs && BoundArch) {
2034 Output.append(BoundArch);
2035 NamedOutput = C.
getArgs().MakeArgString(Output.c_str());
2040 assert(Suffix &&
"All types used for output should have a suffix.");
2042 std::string::size_type
End = std::string::npos;
2044 End = BaseName.rfind(
'.');
2046 if (MultipleArchs && BoundArch) {
2048 Suffixed.append(BoundArch);
2053 if (!AtTopLevel && C.
getArgs().hasArg(options::OPT_emit_llvm) &&
2054 JA.
getType() == types::TY_LLVM_BC)
2058 NamedOutput = C.
getArgs().MakeArgString(Suffixed.c_str());
2063 JA.
getType() != types::TY_PCH) {
2064 Arg *FinalOutput = C.
getArgs().getLastArg(options::OPT_o);
2066 llvm::sys::path::remove_filename(TempPath);
2067 StringRef OutputFileName = llvm::sys::path::filename(NamedOutput);
2068 llvm::sys::path::append(TempPath, OutputFileName);
2069 NamedOutput = C.
getArgs().MakeArgString(TempPath.c_str());
2075 bool SameFile =
false;
2077 llvm::sys::fs::current_path(Result);
2078 llvm::sys::path::append(Result, BaseName);
2079 llvm::sys::fs::equivalent(BaseInput, Result.c_str(), SameFile);
2082 StringRef
Name = llvm::sys::path::filename(BaseInput);
2083 std::pair<StringRef, StringRef> Split = Name.split(
'.');
2091 if (JA.
getType() == types::TY_PCH) {
2092 llvm::sys::path::remove_filename(BasePath);
2093 if (BasePath.empty())
2094 BasePath = NamedOutput;
2096 llvm::sys::path::append(BasePath, NamedOutput);
2110 llvm::sys::path::append(
P, Name);
2111 if (llvm::sys::fs::exists(Twine(
P)))
2116 llvm::sys::path::append(P, Name);
2117 if (llvm::sys::fs::exists(Twine(P)))
2124 llvm::sys::path::append(P, Name);
2125 if (llvm::sys::fs::exists(Twine(P)))
2132 void Driver::generatePrefixedToolNames(
2137 Names.emplace_back(Tool);
2140 std::string LLVMDefaultTargetTriple = llvm::sys::getDefaultTargetTriple();
2142 Names.emplace_back(LLVMDefaultTargetTriple +
"-" + Tool);
2147 for (
const auto &
Name : Names) {
2148 llvm::sys::path::append(Dir,
Name);
2149 if (llvm::sys::fs::can_execute(Twine(Dir)))
2151 llvm::sys::path::remove_filename(Dir);
2159 generatePrefixedToolNames(Name, TC, TargetSpecificExecutables);
2164 if (llvm::sys::fs::is_directory(PrefixDir)) {
2170 if (llvm::sys::fs::can_execute(Twine(P)))
2176 for (
const auto &Path : List) {
2183 for (
const auto &TargetSpecificExecutable : TargetSpecificExecutables)
2184 if (llvm::ErrorOr<std::string>
P =
2185 llvm::sys::findProgramByName(TargetSpecificExecutable))
2192 const char *Suffix)
const {
2194 std::error_code EC = llvm::sys::fs::createTemporaryFile(Prefix, Suffix, Path);
2196 Diag(clang::diag::err_unable_to_make_temp) << EC.message();
2203 const ToolChain &Driver::getToolChain(
const ArgList &Args,
2204 const llvm::Triple &Target)
const {
2206 ToolChain *&TC = ToolChains[Target.str()];
2208 switch (Target.getOS()) {
2209 case llvm::Triple::CloudABI:
2212 case llvm::Triple::Darwin:
2213 case llvm::Triple::MacOSX:
2214 case llvm::Triple::IOS:
2215 case llvm::Triple::TvOS:
2216 case llvm::Triple::WatchOS:
2219 case llvm::Triple::DragonFly:
2222 case llvm::Triple::OpenBSD:
2225 case llvm::Triple::Bitrig:
2228 case llvm::Triple::NetBSD:
2231 case llvm::Triple::FreeBSD:
2234 case llvm::Triple::Minix:
2237 case llvm::Triple::Linux:
2238 if (Target.getArch() == llvm::Triple::hexagon)
2240 else if ((Target.getVendor() == llvm::Triple::MipsTechnologies) &&
2241 !Target.hasEnvironment())
2246 case llvm::Triple::NaCl:
2249 case llvm::Triple::Solaris:
2252 case llvm::Triple::AMDHSA:
2255 case llvm::Triple::Win32:
2256 switch (Target.getEnvironment()) {
2258 if (Target.isOSBinFormatELF())
2260 else if (Target.isOSBinFormatMachO())
2265 case llvm::Triple::GNU:
2268 case llvm::Triple::Itanium:
2271 case llvm::Triple::MSVC:
2272 case llvm::Triple::UnknownEnvironment:
2277 case llvm::Triple::CUDA:
2280 case llvm::Triple::PS4:
2286 switch (Target.getArch()) {
2287 case llvm::Triple::tce:
2290 case llvm::Triple::hexagon:
2293 case llvm::Triple::xcore:
2296 case llvm::Triple::wasm32:
2297 case llvm::Triple::wasm64:
2301 if (Target.getVendor() == llvm::Triple::Myriad)
2303 else if (Target.isOSBinFormatELF())
2305 else if (Target.isOSBinFormatMachO())
2321 if (!isa<PreprocessJobAction>(JA) && !isa<PrecompileJobAction>(JA) &&
2322 !isa<CompileJobAction>(JA) && !isa<BackendJobAction>(JA))
2334 unsigned &Minor,
unsigned &Micro,
2338 Major = Minor = Micro = 0;
2343 Major = (
unsigned)strtol(Str, &End, 10);
2344 if (*Str !=
'\0' && *End ==
'\0')
2350 Minor = (
unsigned)strtol(Str, &End, 10);
2351 if (*Str !=
'\0' && *End ==
'\0')
2357 Micro = (
unsigned)strtol(Str, &End, 10);
2358 if (*Str !=
'\0' && *End ==
'\0')
2366 std::pair<unsigned, unsigned> Driver::getIncludeExcludeOptionFlagMasks()
const {
2367 unsigned IncludedFlagsBitmask = 0;
2370 if (Mode == CLMode) {
2378 return std::make_pair(IncludedFlagsBitmask, ExcludedFlagsBitmask);
2382 return Args.hasFlag(options::OPT_Ofast, options::OPT_O_Group,
false);
ID
ID - Ordered values for successive stages in the compilation process which interact with user options...
const Driver & getDriver() const
Driver(StringRef ClangExecutable, StringRef DefaultTargetTriple, DiagnosticsEngine &Diags, IntrusiveRefCntPtr< vfs::FileSystem > VFS=nullptr)
static bool ContainsCompileOrAssembleAction(const Action *A)
Check whether the given input tree contains any compilation or assembly actions.
void ParseDriverMode(ArrayRef< const char * > Args)
ParseDriverMode - Look for and handle the driver mode option in Args.
const ArgStringMap & getResultFiles() const
std::string getClangFullVersion()
Retrieves a string representing the complete clang version, which includes the clang version number...
bool canLipoType(ID Id)
canLipoType - Is this type acceptable as the output of a universal build (currently, just the Nothing, Image, and Object types).
IntrusiveRefCntPtr< FileSystem > getRealFileSystem()
Gets an vfs::FileSystem for the 'real' file system, as seen by the operating system.
const char * getExecutable() const
const char * getTypeTempSuffix(ID Id, bool CLMode=false)
getTypeTempSuffix - Return the suffix to use when creating a temp file of this type, or null if unspecified.
static Arg * MakeInputArg(DerivedArgList &Args, OptTable *Opts, StringRef Value)
unsigned CCCUsePCH
Use lazy precompiled headers for PCH support.
void setCudaDeviceToolChain(const ToolChain *DeviceToolChain)
void setResponseFile(const char *FileName)
Set to pass arguments via a response file when launching the command.
bool hasErrorOccurred() const
std::string GetTemporaryPath(StringRef Prefix, const char *Suffix) const
GetTemporaryPath - Return the pathname of a temporary file to use as part of compilation; the file wi...
void BuildActions(Compilation &C, const ToolChain &TC, llvm::opt::DerivedArgList &Args, const InputList &Inputs, ActionList &Actions) const
BuildActions - Construct the list of actions to perform for the given arguments, which are only done ...
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
const llvm::opt::OptTable & getOpts() const
std::string DyldPrefix
Dynamic loader prefix, if present.
static StringRef getCategoryNameFromID(unsigned CategoryID)
Given a category ID, return the name of the category.
bool hasErrorOccurred() const
Determine whether any errors have occurred since this object instance was created.
DiagnosticBuilder Diag(unsigned DiagID) const
static bool GetReleaseVersion(const char *Str, unsigned &Major, unsigned &Minor, unsigned &Micro, bool &HadExtra)
GetReleaseVersion - Parse (([0-9]+)(.
Compilation * BuildCompilation(ArrayRef< const char * > Args)
BuildCompilation - Construct a compilation object for a command line argument vector.
void BuildUniversalActions(Compilation &C, const ToolChain &TC, const InputList &BAInputs) const
BuildUniversalActions - Construct the list of actions to perform for the given arguments, which may require a universal build.
const Tool & getCreator() const
getCreator - Return the Tool which caused the creation of this job.
RAII class that determines when any errors have occurred between the time the instance was created an...
types::ID getType() const
bool ShouldUseClangCompiler(const JobAction &JA) const
ShouldUseClangCompiler - Should the clang compiler be used to handle this action. ...
T * MakeAction(Args &&...Arg)
Creates a new Action owned by this Compilation.
bool CCCIsCXX() const
Whether the driver should follow g++ like behavior.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
static bool ScanDirForExecutable(SmallString< 128 > &Dir, ArrayRef< std::string > Names)
void PrintHelp(bool ShowHidden) const
PrintHelp - Print the help text.
static bool DiagnoseInputExistence(const Driver &D, const DerivedArgList &Args, StringRef Value)
Check that the file referenced by Value exists.
void PrintActions(const Compilation &C) const
PrintActions - Print the list of actions.
std::string Dir
The path the driver executable was in, as invoked from the command line.
const std::string & gccSuffix() const
Get the detected GCC installation path suffix for the multi-arch target variant.
ID lookupCXXTypeForCType(ID Id)
lookupCXXTypeForCType - Lookup CXX input type that corresponds to given C type (used for clang++ emul...
ActionClass getKind() const
virtual void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote, CrashReportInfo *CrashInfo=nullptr) const
static unsigned getNumberOfCategories()
Return the number of diagnostic categories.
static Action * buildCudaActions(Compilation &C, DerivedArgList &Args, const Arg *InputArg, Action *HostAction, ActionList &Actions)
Action - Represent an abstract compilation step to perform.
static bool IsValidGpuArchName(llvm::StringRef ArchName)
bool HandleImmediateArgs(const Compilation &C)
HandleImmediateArgs - Handle any arguments which should be treated before building actions or binding...
Concrete class used by the front-end to report problems and issues.
const llvm::opt::DerivedArgList & getArgs() const
std::string GetFilePath(const char *Name, const ToolChain &TC) const
GetFilePath - Lookup Name in the list of file search paths.
llvm::opt::InputArgList ParseArgStrings(ArrayRef< const char * > Args)
ParseArgStrings - Parse the given list of strings into an ArgList.
bool isOptimizationLevelFast(const llvm::opt::ArgList &Args)
bool IsCLMode() const
Whether the driver should follow cl.exe like behavior.
void generateCompilationDiagnostics(Compilation &C, const Command &FailingCommand)
generateCompilationDiagnostics - Generate diagnostics information including preprocessed source file(...
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
const Action & getSource() const
getSource - Return the Action which caused the creation of this job.
detail::InMemoryDirectory::const_iterator I
void PrintVersion(const Compilation &C, raw_ostream &OS) const
PrintVersion - Print the driver version.
bool isSaveTempsEnabled() const
InputInfo BuildJobsForAction(Compilation &C, const Action *A, const ToolChain *TC, const char *BoundArch, bool AtTopLevel, bool MultipleArchs, const char *LinkingOutput) const
BuildJobsForAction - Construct the jobs to perform for the action A and return an InputInfo for the r...
ID getPreprocessedType(ID Id)
getPreprocessedType - Get the ID of the type for this input when it has been preprocessed, or INVALID if this input is not preprocessed.
bool getCheckInputsExist() const
const char * getTypeName(ID Id)
getTypeName - Return the name of the type for Id.
const char * getPhaseName(ID Id)
Defines version macros and version-related utility functions for Clang.
bool CleanupFileList(const llvm::opt::ArgStringList &Files, bool IssueErrors=false) const
CleanupFileList - Remove the files in the given list.
This corresponds to a single GCC Multilib, or a segment of one controlled by a command line flag...
void getCompilationPhases(ID Id, llvm::SmallVectorImpl< phases::ID > &Phases)
getCompilationPhases - Get the list of compilation phases ('Phases') to be done for type 'Id'...
The result type of a method or function.
static void PrintDiagnosticCategories(raw_ostream &OS)
PrintDiagnosticCategories - Implement the –print-diagnostic-categories option.
int ExecuteCompilation(Compilation &C, SmallVectorImpl< std::pair< int, const Command * > > &FailingCommands)
ExecuteCompilation - Execute the compilation according to the command line arguments and return an ap...
bool UseStdLib
If the standard library is used.
bool CleanupFileMap(const ArgStringMap &Files, const JobAction *JA, bool IssueErrors=false) const
CleanupFileMap - Remove the files in the given map.
std::string GetProgramPath(const char *Name, const ToolChain &TC) const
GetProgramPath - Lookup Name in the list of program search paths.
const ToolChain * getCudaDeviceToolChain() const
static unsigned PrintActions1(const Compilation &C, Action *A, std::map< Action *, unsigned > &Ids)
void BuildJobs(Compilation &C) const
BuildJobs - Bind actions to concrete tools and translate arguments to form the list of jobs to run...
const TemplateArgument * iterator
Command - An executable path/name and argument vector to execute.
static llvm::Triple computeTargetTriple(StringRef DefaultTargetTriple, const ArgList &Args, StringRef DarwinArchName="")
Compute target triple from args.
std::string InstalledDir
The path to the installed clang directory, if any.
bool isSaveTempsObj() const
const char * addResultFile(const char *Name, const JobAction *JA)
addResultFile - Add a file to remove on failure, and returns its argument.
static const Tool * selectToolForJob(Compilation &C, bool SaveTemps, const ToolChain *TC, const JobAction *JA, const ActionList *&Inputs, const CudaHostAction *&CollapsedCHA)
bool isAcceptedByClang(ID Id)
isAcceptedByClang - Can clang handle this input type.
const llvm::opt::DerivedArgList & getArgsForToolChain(const ToolChain *TC, const char *BoundArch)
getArgsForToolChain - Return the derived argument list for the tool chain TC (or the default tool cha...
const llvm::opt::ArgStringList & getArguments() const
const ToolChain & getDefaultToolChain() const
void setIgnoreAllWarnings(bool Val)
When set to true, any unmapped warnings are ignored.
const char * getDefaultImageName() const
Returns the default name for linked images (e.g., "a.out").
bool CCCIsCPP() const
Whether the driver is just the preprocessor.
const char * GetNamedOutputPath(Compilation &C, const JobAction &JA, const char *BaseInput, const char *BoundArch, bool AtTopLevel, bool MultipleArchs) const
GetNamedOutputPath - Return the name to use for the output of the action JA.
unsigned CCCPrintBindings
Only print tool bindings, don't build any jobs.
const ArgStringMap & getFailureResultFiles() const
const char * getClassName() const
std::string SysRoot
sysroot, if present
std::string Name
The name the driver was invoked as.
Defines the virtual file system interface vfs::FileSystem.
detail::InMemoryDirectory::const_iterator E
ActionList & getActions()
void ExecuteJobs(const JobList &Jobs, SmallVectorImpl< std::pair< int, const Command * >> &FailingCommands) const
ExecuteJob - Execute a single job.
void BuildInputs(const ToolChain &TC, llvm::opt::DerivedArgList &Args, InputList &Inputs) const
BuildInputs - Construct the list of inputs and their types from the given arguments.
Compilation - A set of tasks to perform for a single driver invocation.
static void printArg(llvm::raw_ostream &OS, const char *Arg, bool Quote)
Print a command argument, and optionally quote it.
static void printArgList(raw_ostream &OS, const llvm::opt::ArgList &Args)
const llvm::opt::InputArgList & getInputArgs() const
void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote, CrashReportInfo *CrashInfo=nullptr) const
llvm::opt::OptTable * createDriverOptTable()
StringRef getSysRoot() const
Returns the sysroot path.
bool isUsingLTO() const
Returns true if we are performing any kind of LTO.
std::string DefaultTargetTriple
Default target triple.
const llvm::opt::ArgStringList & getTempFiles() const
const char * addTempFile(const char *Name)
addTempFile - Add a file to remove on exit, and returns its argument.
Action * ConstructPhaseAction(Compilation &C, const ToolChain &TC, const llvm::opt::ArgList &Args, phases::ID Phase, Action *Input) const
ConstructAction - Construct the appropriate action to do for Phase on the Input, taking in to account...
std::string DriverTitle
Driver title to use with help.
static const char * MakeCLOutputFilename(const ArgList &Args, StringRef ArgValue, StringRef BaseName, types::ID FileType)
Create output filename based on ArgValue, which could either be a full filename, filename without ext...
#define CLANG_VERSION_STRING
A string that describes the Clang version number, e.g., "1.0".
bool appendSuffixForType(ID Id)
appendSuffixForType - When generating outputs of this type, should the suffix be appended (instead of...
ID lookupTypeForTypeSpecifier(const char *Name)
lookupTypeForTypSpecifier - Lookup the type to use for a user specified type name.
void initCompilationForDiagnostics()
initCompilationForDiagnostics - Remove stale state and suppress output so compilation can be reexecut...
unsigned CCGenDiagnostics
Whether the driver is generating diagnostics for debugging purposes.
std::string ResourceDir
The path to the compiler resource directory.