14 #include "clang/Config/config.h"
23 #include "llvm/ADT/ArrayRef.h"
24 #include "llvm/ADT/STLExtras.h"
25 #include "llvm/ADT/StringExtras.h"
26 #include "llvm/ADT/StringSet.h"
27 #include "llvm/ADT/StringSwitch.h"
28 #include "llvm/Option/Arg.h"
29 #include "llvm/Option/ArgList.h"
30 #include "llvm/Option/OptSpecifier.h"
31 #include "llvm/Option/OptTable.h"
32 #include "llvm/Option/Option.h"
33 #include "llvm/Support/Debug.h"
34 #include "llvm/Support/ErrorHandling.h"
35 #include "llvm/Support/FileSystem.h"
36 #include "llvm/Support/Path.h"
37 #include "llvm/Support/PrettyStackTrace.h"
38 #include "llvm/Support/Process.h"
39 #include "llvm/Support/Program.h"
40 #include "llvm/Support/raw_ostream.h"
44 using namespace clang::driver;
45 using namespace clang;
46 using namespace llvm::opt;
51 SaveTemps(SaveTempsNone), ClangExecutable(ClangExecutable),
52 SysRoot(DEFAULT_SYSROOT), UseStdLib(
true),
53 DefaultTargetTriple(DefaultTargetTriple),
54 DriverTitle(
"clang LLVM compiler"), CCPrintOptionsFilename(nullptr),
55 CCPrintHeadersFilename(nullptr), CCLogDiagnosticsFilename(nullptr),
56 CCCPrintBindings(
false), CCPrintHeaders(
false), CCLogDiagnostics(
false),
57 CCGenDiagnostics(
false), CCCGenericGCCName(
""), CheckInputsExist(
true),
58 CCCUsePCH(
true), SuppressMissingInputWarning(
false) {
60 Name = llvm::sys::path::filename(ClangExecutable);
61 Dir = llvm::sys::path::parent_path(ClangExecutable);
64 StringRef ClangResourceDir(CLANG_RESOURCE_DIR);
66 if (ClangResourceDir !=
"") {
67 llvm::sys::path::append(P, ClangResourceDir);
69 StringRef ClangLibdirSuffix(CLANG_LIBDIR_SUFFIX);
70 llvm::sys::path::append(P,
"..", Twine(
"lib") + ClangLibdirSuffix,
"clang",
79 llvm::DeleteContainerSeconds(ToolChains);
83 const std::string OptName =
84 getOpts().getOption(options::OPT_driver_mode).getPrefixedName();
86 for (
const char *ArgPtr : Args) {
88 if (ArgPtr ==
nullptr)
90 const StringRef Arg = ArgPtr;
91 if (!Arg.startswith(OptName))
94 const StringRef
Value = Arg.drop_front(OptName.size());
95 const unsigned M = llvm::StringSwitch<unsigned>(
Value)
103 Mode =
static_cast<DriverMode
>(M);
105 Diag(diag::err_drv_unsupported_option_argument) << OptName <<
Value;
110 llvm::PrettyStackTraceString CrashInfo(
"Command line argument parsing");
112 unsigned IncludedFlagsBitmask;
113 unsigned ExcludedFlagsBitmask;
114 std::tie(IncludedFlagsBitmask, ExcludedFlagsBitmask) =
115 getIncludeExcludeOptionFlagMasks();
117 unsigned MissingArgIndex, MissingArgCount;
119 getOpts().ParseArgs(ArgStrings, MissingArgIndex, MissingArgCount,
120 IncludedFlagsBitmask, ExcludedFlagsBitmask);
124 Diag(clang::diag::err_drv_missing_argument)
125 << Args.getArgString(MissingArgIndex) << MissingArgCount;
128 for (
const Arg *A : Args) {
130 Diag(clang::diag::err_drv_unsupported_opt) << A->getAsString(Args);
135 if (A->getOption().matches(options::OPT_mcpu_EQ) && A->containsValue(
"")) {
136 Diag(clang::diag::warn_drv_empty_joined_argument) << A->getAsString(Args);
140 for (
const Arg *A : Args.filtered(options::OPT_UNKNOWN))
141 Diags.
Report(diag::err_drv_unknown_argument) << A->getAsString(Args);
149 phases::ID Driver::getFinalPhase(
const DerivedArgList &DAL,
150 Arg **FinalPhaseArg)
const {
151 Arg *PhaseArg =
nullptr;
155 if (
CCCIsCPP() || (PhaseArg = DAL.getLastArg(options::OPT_E)) ||
156 (PhaseArg = DAL.getLastArg(options::OPT__SLASH_EP)) ||
157 (PhaseArg = DAL.getLastArg(options::OPT_M, options::OPT_MM)) ||
158 (PhaseArg = DAL.getLastArg(options::OPT__SLASH_P))) {
162 }
else if ((PhaseArg = DAL.getLastArg(options::OPT_fsyntax_only)) ||
163 (PhaseArg = DAL.getLastArg(options::OPT_module_file_info)) ||
164 (PhaseArg = DAL.getLastArg(options::OPT_verify_pch)) ||
165 (PhaseArg = DAL.getLastArg(options::OPT_rewrite_objc)) ||
166 (PhaseArg = DAL.getLastArg(options::OPT_rewrite_legacy_objc)) ||
167 (PhaseArg = DAL.getLastArg(options::OPT__migrate)) ||
168 (PhaseArg = DAL.getLastArg(options::OPT__analyze,
169 options::OPT__analyze_auto)) ||
170 (PhaseArg = DAL.getLastArg(options::OPT_emit_ast))) {
174 }
else if ((PhaseArg = DAL.getLastArg(options::OPT_S))) {
178 }
else if ((PhaseArg = DAL.getLastArg(options::OPT_c)) ||
179 (PhaseArg = DAL.getLastArg(options::OPT_cuda_device_only)) ||
180 (PhaseArg = DAL.getLastArg(options::OPT_cuda_host_only))) {
188 *FinalPhaseArg = PhaseArg;
195 Arg *A =
new Arg(Opts->getOption(options::OPT_INPUT),
Value,
196 Args.getBaseArgs().MakeIndex(Value), Value.data());
197 Args.AddSynthesizedArg(A);
202 DerivedArgList *Driver::TranslateInputArgs(
const InputArgList &Args)
const {
203 DerivedArgList *DAL =
new DerivedArgList(Args);
205 bool HasNostdlib = Args.hasArg(options::OPT_nostdlib);
206 for (Arg *A : Args) {
213 if ((A->getOption().matches(options::OPT_Wl_COMMA) ||
214 A->getOption().matches(options::OPT_Xlinker)) &&
215 A->containsValue(
"--no-demangle")) {
217 DAL->AddFlagArg(A, Opts->getOption(options::OPT_Z_Xlinker__no_demangle));
220 for (
const StringRef Val : A->getValues())
221 if (Val !=
"--no-demangle")
222 DAL->AddSeparateArg(A, Opts->getOption(options::OPT_Xlinker), Val);
230 if (A->getOption().matches(options::OPT_Wp_COMMA) &&
231 (A->getValue(0) == StringRef(
"-MD") ||
232 A->getValue(0) == StringRef(
"-MMD"))) {
234 if (A->getValue(0) == StringRef(
"-MD"))
235 DAL->AddFlagArg(A, Opts->getOption(options::OPT_MD));
237 DAL->AddFlagArg(A, Opts->getOption(options::OPT_MMD));
238 if (A->getNumValues() == 2)
239 DAL->AddSeparateArg(A, Opts->getOption(options::OPT_MF),
245 if (A->getOption().matches(options::OPT_l)) {
246 StringRef
Value = A->getValue();
249 if (!HasNostdlib && Value ==
"stdc++") {
250 DAL->AddFlagArg(A, Opts->getOption(options::OPT_Z_reserved_lib_stdcxx));
255 if (Value ==
"cc_kext") {
256 DAL->AddFlagArg(A, Opts->getOption(options::OPT_Z_reserved_lib_cckext));
262 if (A->getOption().matches(options::OPT__DASH_DASH)) {
264 for (
const StringRef Val : A->getValues())
274 #if defined(HOST_LINK_VERSION)
275 if (!Args.hasArg(options::OPT_mlinker_version_EQ) &&
276 strlen(HOST_LINK_VERSION) > 0) {
277 DAL->AddJoinedArg(0, Opts->getOption(options::OPT_mlinker_version_EQ),
279 DAL->getLastArg(options::OPT_mlinker_version_EQ)->claim();
292 StringRef DarwinArchName =
"") {
294 if (
const Arg *A = Args.getLastArg(options::OPT_target))
295 DefaultTargetTriple = A->getValue();
297 llvm::Triple Target(llvm::Triple::normalize(DefaultTargetTriple));
300 if (Target.isOSBinFormatMachO()) {
302 if (!DarwinArchName.empty()) {
308 if (Arg *A = Args.getLastArg(options::OPT_arch)) {
309 StringRef ArchName = A->getValue();
316 if (Arg *A = Args.getLastArg(options::OPT_mlittle_endian,
317 options::OPT_mbig_endian)) {
318 if (A->getOption().matches(options::OPT_mlittle_endian)) {
319 llvm::Triple LE = Target.getLittleEndianArchVariant();
320 if (LE.getArch() != llvm::Triple::UnknownArch)
321 Target = std::move(LE);
323 llvm::Triple BE = Target.getBigEndianArchVariant();
324 if (BE.getArch() != llvm::Triple::UnknownArch)
325 Target = std::move(BE);
330 if (Target.getArchName() ==
"tce" || Target.getOS() == llvm::Triple::Minix)
334 if (Arg *A = Args.getLastArg(options::OPT_m64, options::OPT_mx32,
335 options::OPT_m32, options::OPT_m16)) {
336 llvm::Triple::ArchType AT = llvm::Triple::UnknownArch;
338 if (A->getOption().matches(options::OPT_m64)) {
339 AT = Target.get64BitArchVariant().getArch();
340 if (Target.getEnvironment() == llvm::Triple::GNUX32)
341 Target.setEnvironment(llvm::Triple::GNU);
342 }
else if (A->getOption().matches(options::OPT_mx32) &&
343 Target.get64BitArchVariant().getArch() == llvm::Triple::x86_64) {
344 AT = llvm::Triple::x86_64;
345 Target.setEnvironment(llvm::Triple::GNUX32);
346 }
else if (A->getOption().matches(options::OPT_m32)) {
347 AT = Target.get32BitArchVariant().getArch();
348 if (Target.getEnvironment() == llvm::Triple::GNUX32)
349 Target.setEnvironment(llvm::Triple::GNU);
350 }
else if (A->getOption().matches(options::OPT_m16) &&
351 Target.get32BitArchVariant().getArch() == llvm::Triple::x86) {
352 AT = llvm::Triple::x86;
353 Target.setEnvironment(llvm::Triple::CODE16);
356 if (AT != llvm::Triple::UnknownArch && AT != Target.getArch())
364 llvm::PrettyStackTraceString CrashInfo(
"Compilation construction");
369 if (
char *env = ::getenv(
"COMPILER_PATH")) {
370 StringRef CompilerPath = env;
371 while (!CompilerPath.empty()) {
372 std::pair<StringRef, StringRef> Split =
373 CompilerPath.split(llvm::sys::EnvPathSeparator);
375 CompilerPath = Split.second;
391 Args.ClaimAllArgs(options::OPT_no_canonical_prefixes);
394 Args.ClaimAllArgs(options::OPT_pipe);
402 CCCPrintPhases = Args.hasArg(options::OPT_ccc_print_phases);
404 if (
const Arg *A = Args.getLastArg(options::OPT_ccc_gcc_name))
405 CCCGenericGCCName = A->getValue();
407 Args.hasFlag(options::OPT_ccc_pch_is_pch, options::OPT_ccc_pch_is_pth);
413 T.setOS(llvm::Triple::Win32);
414 T.setEnvironment(llvm::Triple::MSVC);
417 if (
const Arg *A = Args.getLastArg(options::OPT_target))
419 if (
const Arg *A = Args.getLastArg(options::OPT_ccc_install_dir))
421 for (
const Arg *A : Args.filtered(options::OPT_B)) {
425 if (
const Arg *A = Args.getLastArg(options::OPT__sysroot_EQ))
427 if (
const Arg *A = Args.getLastArg(options::OPT__dyld_prefix_EQ))
429 if (Args.hasArg(options::OPT_nostdlib))
432 if (
const Arg *A = Args.getLastArg(options::OPT_resource_dir))
435 if (
const Arg *A = Args.getLastArg(options::OPT_save_temps_EQ)) {
436 SaveTemps = llvm::StringSwitch<SaveTempsMode>(A->getValue())
437 .Case(
"cwd", SaveTempsCwd)
438 .Case(
"obj", SaveTempsObj)
439 .Default(SaveTempsCwd);
442 std::unique_ptr<llvm::opt::InputArgList> UArgs =
443 llvm::make_unique<InputArgList>(std::move(Args));
446 DerivedArgList *TranslatedArgs = TranslateInputArgs(*UArgs);
471 if (CCCPrintPhases) {
481 static void printArgList(raw_ostream &OS,
const llvm::opt::ArgList &Args) {
482 llvm::opt::ArgStringList ASL;
483 for (
const auto *A : Args)
484 A->render(Args, ASL);
486 for (
auto I = ASL.begin(), E = ASL.end(); I != E; ++I) {
487 if (I != ASL.begin())
498 const Command &FailingCommand) {
499 if (C.
getArgs().hasArg(options::OPT_fno_crash_diagnostics))
510 Diag(clang::diag::note_drv_command_failed_diag_msg)
511 <<
"PLEASE submit a bug report to " BUG_REPORT_URL
" and include the "
512 "crash backtrace, preprocessed source, and associated run script.";
532 for (InputList::iterator it = Inputs.begin(), ie = Inputs.end(); it != ie;) {
533 bool IgnoreInput =
false;
539 }
else if (!strcmp(it->second->getValue(),
"-")) {
540 Diag(clang::diag::note_drv_command_failed_diag_msg)
541 <<
"Error generating preprocessed source(s) - "
542 "ignoring input from stdin.";
547 it = Inputs.erase(it);
554 if (Inputs.empty()) {
555 Diag(clang::diag::note_drv_command_failed_diag_msg)
556 <<
"Error generating preprocessed source(s) - "
557 "no preprocessable inputs.";
563 llvm::StringSet<> ArchNames;
564 for (
const Arg *A : C.
getArgs()) {
565 if (A->getOption().matches(options::OPT_arch)) {
566 StringRef ArchName = A->getValue();
567 ArchNames.insert(ArchName);
570 if (ArchNames.size() > 1) {
571 Diag(clang::diag::note_drv_command_failed_diag_msg)
572 <<
"Error generating preprocessed source(s) - cannot generate "
573 "preprocessed source with multiple -arch options.";
589 Diag(clang::diag::note_drv_command_failed_diag_msg)
590 <<
"Error generating preprocessed source(s).";
599 if (!FailingCommands.empty()) {
603 Diag(clang::diag::note_drv_command_failed_diag_msg)
604 <<
"Error generating preprocessed source(s).";
609 if (TempFiles.empty()) {
610 Diag(clang::diag::note_drv_command_failed_diag_msg)
611 <<
"Error generating preprocessed source(s).";
615 Diag(clang::diag::note_drv_command_failed_diag_msg)
616 <<
"\n********************\n\n"
617 "PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:\n"
618 "Preprocessed source(s) and associated run script(s) are located at:";
621 for (
const char *TempFile : TempFiles) {
622 Diag(clang::diag::note_drv_command_failed_diag_msg) << TempFile;
623 if (StringRef(TempFile).endswith(
".cache")) {
626 VFS = llvm::sys::path::filename(TempFile);
627 llvm::sys::path::append(VFS,
"vfs",
"vfs.yaml");
634 std::string Script = CrashInfo.
Filename.rsplit(
'.').first.str() +
".sh";
636 llvm::raw_fd_ostream ScriptOS(Script, EC, llvm::sys::fs::F_Excl);
638 Diag(clang::diag::note_drv_command_failed_diag_msg)
639 <<
"Error generating run script: " + Script +
" " + EC.message();
642 <<
"# Driver args: ";
644 ScriptOS <<
"# Original command: ";
645 Cmd.
Print(ScriptOS,
"\n",
true);
646 Cmd.
Print(ScriptOS,
"\n",
true, &CrashInfo);
647 Diag(clang::diag::note_drv_command_failed_diag_msg) << Script;
650 for (
const auto &A : C.
getArgs().filtered(options::OPT_frewrite_map_file,
651 options::OPT_frewrite_map_file_EQ))
652 Diag(clang::diag::note_drv_command_failed_diag_msg) << A->getValue();
654 Diag(clang::diag::note_drv_command_failed_diag_msg)
655 <<
"\n\n********************";
663 llvm::sys::argumentsFitWithinSystemLimits(Cmd.
getArguments()))
675 if (C.
getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
686 setUpResponseFiles(C, Job);
694 if (FailingCommands.empty())
699 for (
const auto &CmdPair : FailingCommands) {
700 int Res = CmdPair.first;
701 const Command *FailingCommand = CmdPair.second;
725 Diag(clang::diag::err_drv_command_signalled)
736 unsigned IncludedFlagsBitmask;
737 unsigned ExcludedFlagsBitmask;
738 std::tie(IncludedFlagsBitmask, ExcludedFlagsBitmask) =
739 getIncludeExcludeOptionFlagMasks();
743 ExcludedFlagsBitmask |= HelpHidden;
746 IncludedFlagsBitmask, ExcludedFlagsBitmask);
757 if (Arg *A = C.
getArgs().getLastArg(options::OPT_mthread_model)) {
760 OS <<
"Thread model: " << A->getValue();
779 if (C.
getArgs().hasArg(options::OPT_dumpmachine)) {
784 if (C.
getArgs().hasArg(options::OPT_dumpversion)) {
791 llvm::outs() <<
"4.2.1\n";
795 if (C.
getArgs().hasArg(options::OPT__print_diagnostic_categories)) {
800 if (C.
getArgs().hasArg(options::OPT_help) ||
801 C.
getArgs().hasArg(options::OPT__help_hidden)) {
806 if (C.
getArgs().hasArg(options::OPT__version)) {
812 if (C.
getArgs().hasArg(options::OPT_v) ||
813 C.
getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
815 SuppressMissingInputWarning =
true;
820 if (C.
getArgs().hasArg(options::OPT_v))
823 if (C.
getArgs().hasArg(options::OPT_print_search_dirs)) {
824 llvm::outs() <<
"programs: =";
825 bool separator =
false;
829 llvm::outs() << Path;
832 llvm::outs() <<
"\n";
842 llvm::outs() << sysroot << Path.substr(1);
844 llvm::outs() << Path;
846 llvm::outs() <<
"\n";
852 if (Arg *A = C.
getArgs().getLastArg(options::OPT_print_file_name_EQ)) {
853 llvm::outs() <<
GetFilePath(A->getValue(), TC) <<
"\n";
857 if (Arg *A = C.
getArgs().getLastArg(options::OPT_print_prog_name_EQ)) {
862 if (C.
getArgs().hasArg(options::OPT_print_libgcc_file_name)) {
863 llvm::outs() <<
GetFilePath(
"libgcc.a", TC) <<
"\n";
867 if (C.
getArgs().hasArg(options::OPT_print_multi_lib)) {
873 if (C.
getArgs().hasArg(options::OPT_print_multi_directory)) {
876 llvm::outs() <<
".\n";
879 assert(Suffix.front() ==
'/');
880 llvm::outs() << Suffix.substr(1) <<
"\n";
892 std::map<Action *, unsigned> &Ids) {
897 llvm::raw_string_ostream os(str);
901 os <<
"\"" << IA->getInputArg().getValue() <<
"\"";
903 os <<
'"' << BIA->getArchName() <<
'"' <<
", {"
906 os <<
'"' << CDA->getGpuArchName() <<
'"' <<
", {"
912 <<
", gpu binaries ";
913 AL = &CHA->getDeviceActions();
917 const char *Prefix =
"{";
918 for (
Action *PreRequisite : *AL) {
925 unsigned Id = Ids.size();
927 llvm::errs() << Id <<
": " << os.str() <<
", "
936 std::map<Action *, unsigned> Ids;
944 if (isa<CompileJobAction>(A) || isa<BackendJobAction>(A) ||
945 isa<AssembleJobAction>(A))
958 llvm::PrettyStackTraceString CrashInfo(
"Building universal build actions");
961 llvm::StringSet<> ArchNames;
963 for (Arg *A : Args) {
964 if (A->getOption().matches(options::OPT_arch)) {
967 llvm::Triple::ArchType Arch =
969 if (Arch == llvm::Triple::UnknownArch) {
970 Diag(clang::diag::err_drv_invalid_arch_name) << A->getAsString(Args);
975 if (ArchNames.insert(A->getValue()).second)
976 Archs.push_back(A->getValue());
990 for (
unsigned i = 0, e = SingleActions.size(); i != e; ++i) {
991 Action *Act = SingleActions[i];
1000 Diag(clang::diag::err_drv_invalid_output_with_multiple_archs)
1004 for (
unsigned i = 0, e = Archs.size(); i != e; ++i) {
1008 Inputs.back()->setOwnsInputs(
false);
1013 if (Inputs.size() == 1 || Act->
getType() == types::TY_Nothing)
1014 Actions.append(Inputs.begin(), Inputs.end());
1019 Arg *A = Args.getLastArg(options::OPT_g_Group);
1020 if (A && !A->getOption().matches(options::OPT_g0) &&
1021 !A->getOption().matches(options::OPT_gstabs) &&
1028 if (Act->
getType() == types::TY_Image) {
1030 Inputs.push_back(Actions.back());
1036 if (Args.hasArg(options::OPT_verify_debug_info)) {
1037 std::unique_ptr<Action> VerifyInput(Actions.back());
1040 types::TY_Nothing));
1058 if (Arg *WorkDir = Args.getLastArg(options::OPT_working_directory)) {
1059 if (!llvm::sys::path::is_absolute(Path)) {
1061 llvm::sys::path::append(Directory, Value);
1062 Path.assign(Directory);
1066 if (llvm::sys::fs::exists(Twine(Path)))
1069 if (D.
IsCLMode() && !llvm::sys::path::is_absolute(Twine(Path)) &&
1070 llvm::sys::Process::FindInEnvPath(
"LIB", Value))
1073 D.
Diag(clang::diag::err_drv_no_such_file) << Path;
1083 types::ID InputType = types::TY_Nothing;
1084 Arg *InputTypeArg =
nullptr;
1087 if (Arg *TCTP = Args.getLastArgNoClaim(options::OPT__SLASH_TC,
1088 options::OPT__SLASH_TP)) {
1089 InputTypeArg = TCTP;
1090 InputType = TCTP->getOption().matches(options::OPT__SLASH_TC)
1095 Args.filtered_begin(options::OPT__SLASH_TC, options::OPT__SLASH_TP);
1096 const arg_iterator ie = Args.filtered_end();
1098 bool ShowNote =
false;
1100 Diag(clang::diag::warn_drv_overriding_flag_option)
1101 << Previous->getSpelling() << (*it)->getSpelling();
1106 Diag(clang::diag::note_drv_t_option_is_global);
1109 assert(!Args.hasArg(options::OPT_x) &&
"-x and /TC or /TP is not allowed");
1112 for (Arg *A : Args) {
1113 if (A->getOption().getKind() == Option::InputClass) {
1114 const char *Value = A->getValue();
1118 if (InputType == types::TY_Nothing) {
1121 InputTypeArg->claim();
1124 if (memcmp(Value,
"-", 2) == 0) {
1130 if (!Args.hasArgNoClaim(options::OPT_E) && !
CCCIsCPP())
1131 Diag(
IsCLMode() ? clang::diag::err_drv_unknown_stdin_type_clang_cl
1132 : clang::diag::err_drv_unknown_stdin_type);
1139 if (
const char *Ext = strrchr(Value,
'.'))
1146 Ty = types::TY_Object;
1156 Diag(clang::diag::warn_drv_treating_input_as_cxx)
1166 if (Ty != types::TY_Object) {
1167 if (Args.hasArg(options::OPT_ObjC))
1168 Ty = types::TY_ObjC;
1169 else if (Args.hasArg(options::OPT_ObjCXX))
1170 Ty = types::TY_ObjCXX;
1173 assert(InputTypeArg &&
"InputType set w/o InputTypeArg");
1174 if (!InputTypeArg->getOption().matches(options::OPT_x)) {
1177 const char *Ext = strrchr(Value,
'.');
1179 Ty = types::TY_Object;
1183 InputTypeArg->claim();
1188 Inputs.push_back(std::make_pair(Ty, A));
1190 }
else if (A->getOption().matches(options::OPT__SLASH_Tc)) {
1191 StringRef Value = A->getValue();
1193 Arg *InputArg =
MakeInputArg(Args, Opts, A->getValue());
1194 Inputs.push_back(std::make_pair(types::TY_C, InputArg));
1197 }
else if (A->getOption().matches(options::OPT__SLASH_Tp)) {
1198 StringRef Value = A->getValue();
1200 Arg *InputArg =
MakeInputArg(Args, Opts, A->getValue());
1201 Inputs.push_back(std::make_pair(types::TY_CXX, InputArg));
1207 Inputs.push_back(std::make_pair(types::TY_Object, A));
1209 }
else if (A->getOption().matches(options::OPT_x)) {
1218 Diag(clang::diag::err_drv_unknown_language) << A->getValue();
1219 InputType = types::TY_Object;
1223 if (
CCCIsCPP() && Inputs.empty()) {
1227 Inputs.push_back(std::make_pair(types::TY_C, A));
1236 static std::unique_ptr<Action>
1238 const Arg *InputArg,
const types::ID InputType,
1241 assert(InputType == types::TY_CUDA &&
1242 "CUDA Actions only apply to CUDA inputs.");
1246 llvm::StringSet<> GpuArchNames;
1247 for (Arg *A : Args) {
1248 if (A->getOption().matches(options::OPT_cuda_gpu_arch_EQ)) {
1250 if (GpuArchNames.insert(A->getValue()).second)
1251 GpuArchList.push_back(A->getValue());
1257 if (GpuArchList.empty())
1258 GpuArchList.push_back(
"sm_20");
1262 for (
unsigned i = 0, e = GpuArchList.size(); i != e; ++i)
1263 CudaDeviceInputs.push_back(std::make_pair(types::TY_CUDA_DEVICE, InputArg));
1267 D.
BuildActions(TC, Args, CudaDeviceInputs, CudaDeviceActions);
1268 assert(GpuArchList.size() == CudaDeviceActions.size() &&
1269 "Failed to create actions for all devices");
1272 bool PartialCompilation =
false;
1273 bool DeviceOnlyCompilation = Args.hasArg(options::OPT_cuda_device_only);
1274 for (
unsigned i = 0, e = GpuArchList.size(); i != e; ++i) {
1276 PartialCompilation =
true;
1283 if (PartialCompilation || DeviceOnlyCompilation) {
1289 if (Args.hasArg(options::OPT_o) &&
1290 (!DeviceOnlyCompilation || GpuArchList.size() > 1)) {
1291 D.
Diag(clang::diag::err_drv_output_argument_with_multiple_files);
1295 for (
unsigned i = 0, e = GpuArchList.size(); i != e; ++i)
1298 GpuArchList[i],
true));
1300 if (DeviceOnlyCompilation)
1301 Current.reset(
nullptr);
1307 for (
unsigned i = 0, e = GpuArchList.size(); i != e; ++i)
1308 DeviceActions.push_back(
1310 GpuArchList[i],
false));
1313 return std::unique_ptr<Action>(
1320 llvm::PrettyStackTraceString CrashInfo(
"Building compilation actions");
1322 if (!SuppressMissingInputWarning && Inputs.empty()) {
1323 Diag(clang::diag::err_drv_no_input_files);
1328 phases::ID FinalPhase = getFinalPhase(Args, &FinalPhaseArg);
1330 if (FinalPhase ==
phases::Link && Args.hasArg(options::OPT_emit_llvm)) {
1331 Diag(clang::diag::err_drv_emit_llvm_link);
1336 if (Arg *A = Args.getLastArg(options::OPT_Z_Joined))
1337 Diag(clang::diag::err_drv_use_of_Z_option) << A->getAsString(Args);
1340 if (Arg *A = Args.getLastArg(options::OPT__SLASH_Fo)) {
1341 StringRef V = A->getValue();
1342 if (Inputs.size() > 1 && !V.empty() &&
1343 !llvm::sys::path::is_separator(V.back())) {
1345 Diag(clang::diag::err_drv_out_file_argument_with_multiple_sources)
1346 << A->getSpelling() << V;
1347 Args.eraseArg(options::OPT__SLASH_Fo);
1352 if (Arg *A = Args.getLastArg(options::OPT__SLASH_Fa)) {
1353 StringRef V = A->getValue();
1354 if (Inputs.size() > 1 && !V.empty() &&
1355 !llvm::sys::path::is_separator(V.back())) {
1357 Diag(clang::diag::err_drv_out_file_argument_with_multiple_sources)
1358 << A->getSpelling() << V;
1359 Args.eraseArg(options::OPT__SLASH_Fa);
1364 if (Arg *A = Args.getLastArg(options::OPT__SLASH_o)) {
1365 if (A->getValue()[0] ==
'\0') {
1367 Diag(clang::diag::err_drv_missing_argument) << A->getSpelling() << 1;
1368 Args.eraseArg(options::OPT__SLASH_o);
1376 for (
unsigned i = 0, e = Inputs.size(); i != e; ++i) {
1378 const Arg *InputArg = Inputs[i].second;
1386 if (InitialPhase > FinalPhase) {
1391 if (Args.hasArg(options::OPT_Qunused_arguments))
1397 Diag(clang::diag::warn_drv_input_file_unused_by_cpp)
1398 << InputArg->getAsString(Args) <<
getPhaseName(InitialPhase);
1404 Diag(clang::diag::warn_drv_preprocessed_input_file_unused)
1405 << InputArg->getAsString(Args) << !!FinalPhaseArg
1406 << (FinalPhaseArg ? FinalPhaseArg->getOption().getName() :
"");
1408 Diag(clang::diag::warn_drv_input_file_unused)
1409 << InputArg->getAsString(Args) <<
getPhaseName(InitialPhase)
1411 << (FinalPhaseArg ? FinalPhaseArg->getOption().getName() :
"");
1425 for (
auto i = PL.begin(), e = PL.end(); i != e; ++i) {
1428 CudaInjectionPhase = *i;
1431 CudaInjectionPhase = FinalPhase;
1441 if (Phase > FinalPhase)
1446 assert((i + 1) == e &&
"linking must be final compilation step.");
1447 LinkerInputs.push_back(Current.release());
1460 if (InputType == types::TY_CUDA && Phase == CudaInjectionPhase &&
1461 !Args.hasArg(options::OPT_cuda_host_only)) {
1463 std::move(Current), Actions);
1468 if (Current->getType() == types::TY_Nothing)
1474 Actions.push_back(Current.release());
1478 if (!LinkerInputs.empty())
1479 Actions.push_back(
new LinkJobAction(LinkerInputs, types::TY_Image));
1484 Args.ClaimAllArgs(options::OPT_CompileOnly_Group);
1485 Args.ClaimAllArgs(options::OPT_cl_compile_Group);
1489 Args.ClaimAllArgs(options::OPT_cl_ignored_Group);
1492 std::unique_ptr<Action>
1495 std::unique_ptr<Action>
Input)
const {
1496 llvm::PrettyStackTraceString CrashInfo(
"Constructing phase actions");
1500 llvm_unreachable(
"link action invalid here.");
1504 if (Args.hasArg(options::OPT_M, options::OPT_MM)) {
1505 OutputTy = types::TY_Dependencies;
1507 OutputTy = Input->getType();
1508 if (!Args.hasFlag(options::OPT_frewrite_includes,
1509 options::OPT_fno_rewrite_includes,
false) &&
1513 "Cannot preprocess this input type!");
1515 return llvm::make_unique<PreprocessJobAction>(std::move(Input), OutputTy);
1519 if (Args.hasArg(options::OPT_fsyntax_only)) {
1521 OutputTy = types::TY_Nothing;
1523 return llvm::make_unique<PrecompileJobAction>(std::move(Input), OutputTy);
1526 if (Args.hasArg(options::OPT_fsyntax_only))
1527 return llvm::make_unique<CompileJobAction>(std::move(Input),
1529 if (Args.hasArg(options::OPT_rewrite_objc))
1530 return llvm::make_unique<CompileJobAction>(std::move(Input),
1531 types::TY_RewrittenObjC);
1532 if (Args.hasArg(options::OPT_rewrite_legacy_objc))
1533 return llvm::make_unique<CompileJobAction>(std::move(Input),
1534 types::TY_RewrittenLegacyObjC);
1535 if (Args.hasArg(options::OPT__analyze, options::OPT__analyze_auto))
1536 return llvm::make_unique<AnalyzeJobAction>(std::move(Input),
1538 if (Args.hasArg(options::OPT__migrate))
1539 return llvm::make_unique<MigrateJobAction>(std::move(Input),
1541 if (Args.hasArg(options::OPT_emit_ast))
1542 return llvm::make_unique<CompileJobAction>(std::move(Input),
1544 if (Args.hasArg(options::OPT_module_file_info))
1545 return llvm::make_unique<CompileJobAction>(std::move(Input),
1546 types::TY_ModuleFile);
1547 if (Args.hasArg(options::OPT_verify_pch))
1548 return llvm::make_unique<VerifyPCHJobAction>(std::move(Input),
1550 return llvm::make_unique<CompileJobAction>(std::move(Input),
1556 Args.hasArg(options::OPT_S) ? types::TY_LTO_IR : types::TY_LTO_BC;
1557 return llvm::make_unique<BackendJobAction>(std::move(Input), Output);
1559 if (Args.hasArg(options::OPT_emit_llvm)) {
1561 Args.hasArg(options::OPT_S) ? types::TY_LLVM_IR : types::TY_LLVM_BC;
1562 return llvm::make_unique<BackendJobAction>(std::move(Input), Output);
1564 return llvm::make_unique<BackendJobAction>(std::move(Input),
1568 return llvm::make_unique<AssembleJobAction>(std::move(Input),
1572 llvm_unreachable(
"invalid phase in ConstructPhaseAction");
1576 return Args.hasFlag(options::OPT_flto, options::OPT_fno_lto,
false);
1580 llvm::PrettyStackTraceString CrashInfo(
"Building compilation jobs");
1582 Arg *FinalOutput = C.
getArgs().getLastArg(options::OPT_o);
1587 unsigned NumOutputs = 0;
1589 if (A->getType() != types::TY_Nothing)
1592 if (NumOutputs > 1) {
1593 Diag(clang::diag::err_drv_output_argument_with_multiple_files);
1594 FinalOutput =
nullptr;
1599 llvm::StringSet<> ArchNames;
1601 for (
const Arg *A : C.
getArgs())
1602 if (A->getOption().matches(options::OPT_arch))
1603 ArchNames.insert(A->getValue());
1612 const char *LinkingOutput =
nullptr;
1613 if (isa<LipoJobAction>(A)) {
1615 LinkingOutput = FinalOutput->getValue();
1624 ArchNames.size() > 1,
1631 C.
getArgs().hasArg(options::OPT_Qunused_arguments))
1635 (void)C.
getArgs().hasArg(options::OPT__HASH_HASH_HASH);
1638 (void)C.
getArgs().hasArg(options::OPT_driver_mode);
1644 if (!A->isClaimed()) {
1650 const Option &Opt = A->getOption();
1651 if (Opt.getKind() == Option::FlagClass) {
1652 bool DuplicateClaimed =
false;
1654 for (
const Arg *AA : C.
getArgs().filtered(&Opt)) {
1655 if (AA->isClaimed()) {
1656 DuplicateClaimed =
true;
1661 if (DuplicateClaimed)
1665 Diag(clang::diag::warn_drv_unused_argument)
1666 << A->getAsString(C.
getArgs());
1674 const Tool *ToolForJob =
nullptr;
1681 !C.
getArgs().hasArg(options::OPT_via_file_asm) &&
1682 !C.
getArgs().hasArg(options::OPT__SLASH_FA) &&
1683 !C.
getArgs().hasArg(options::OPT__SLASH_Fa) &&
1684 isa<AssembleJobAction>(JA) && Inputs->size() == 1 &&
1685 isa<BackendJobAction>(*Inputs->begin())) {
1690 const ActionList *BackendInputs = &(*Inputs)[0]->getInputs();
1691 JobAction *CompileJA = cast<CompileJobAction>(*BackendInputs->begin());
1695 if (Compiler->hasIntegratedAssembler()) {
1696 Inputs = &(*BackendInputs)[0]->getInputs();
1697 ToolForJob = Compiler;
1704 if (isa<BackendJobAction>(JA)) {
1706 assert(Inputs->size() == 1);
1709 if (
CudaHostAction *CudaHA = dyn_cast<CudaHostAction>(*Inputs->begin()))
1710 CompileJA = cast<CompileJobAction>(*CudaHA->begin());
1712 CompileJA = cast<CompileJobAction>(*Inputs->begin());
1717 if (!Compiler->canEmitIR() || !SaveTemps) {
1718 Inputs = &(*Inputs)[0]->getInputs();
1719 ToolForJob = Compiler;
1730 if (Inputs->size() == 1 && isa<PreprocessJobAction>(*Inputs->begin()) &&
1731 !C.
getArgs().hasArg(options::OPT_no_integrated_cpp) &&
1732 !C.
getArgs().hasArg(options::OPT_traditional_cpp) && !SaveTemps &&
1733 !C.
getArgs().hasArg(options::OPT_rewrite_objc) &&
1735 Inputs = &(*Inputs)[0]->getInputs();
1741 const ToolChain *TC,
const char *BoundArch,
1742 bool AtTopLevel,
bool MultipleArchs,
1743 const char *LinkingOutput,
1745 llvm::PrettyStackTraceString CrashInfo(
"Building compilation jobs");
1751 for (
const Action *DA : CHA->getDeviceActions()) {
1753 false, LinkingOutput, II);
1754 CudaDeviceInputInfos.push_back(II);
1761 if (
const InputAction *IA = dyn_cast<InputAction>(A)) {
1764 const Arg &
Input = IA->getInputArg();
1766 if (Input.getOption().matches(options::OPT_INPUT)) {
1767 const char *
Name = Input.getValue();
1787 MultipleArchs, LinkingOutput, Result);
1795 ?
"nvptx64-nvidia-cuda"
1796 :
"nvptx-nvidia-cuda");
1798 &getToolChain(C.
getArgs(), DeviceTriple),
1799 CDA->getGpuArchName(), CDA->isAtTopLevel(),
1800 true, LinkingOutput, Result);
1806 const JobAction *JA = cast<JobAction>(A);
1817 bool SubJobAtTopLevel =
false;
1818 if (AtTopLevel && (isa<DsymutilJobAction>(A) || isa<VerifyJobAction>(A)))
1819 SubJobAtTopLevel =
true;
1824 InputInfos.push_back(II);
1828 const char *BaseInput = InputInfos[0].getBaseInput();
1832 if (JA->
getType() == types::TY_dSYM)
1833 BaseInput = InputInfos[0].getFilename();
1836 if (CudaDeviceInputInfos.size())
1837 InputInfos.append(CudaDeviceInputInfos.begin(), CudaDeviceInputInfos.end());
1840 if (JA->
getType() == types::TY_Nothing)
1844 AtTopLevel, MultipleArchs),
1848 llvm::errs() <<
"# \"" << T->getToolChain().getTripleString() <<
'"'
1849 <<
" - \"" << T->getName() <<
"\", inputs: [";
1850 for (
unsigned i = 0, e = InputInfos.size(); i != e; ++i) {
1851 llvm::errs() << InputInfos[i].getAsString();
1853 llvm::errs() <<
", ";
1855 llvm::errs() <<
"], output: " << Result.
getAsString() <<
"\n";
1857 T->ConstructJob(C, *JA, Result, InputInfos,
1864 return Target.isOSWindows() ?
"a.exe" :
"a.out";
1876 if (ArgValue.empty()) {
1878 Filename = BaseName;
1879 }
else if (llvm::sys::path::is_separator(Filename.back())) {
1881 llvm::sys::path::append(Filename, BaseName);
1884 if (!llvm::sys::path::has_extension(ArgValue)) {
1888 if (FileType == types::TY_Image &&
1889 Args.hasArg(options::OPT__SLASH_LD, options::OPT__SLASH_LDd)) {
1894 llvm::sys::path::replace_extension(Filename, Extension);
1897 return Args.MakeArgString(Filename.c_str());
1901 const char *BaseInput,
1902 const char *BoundArch,
bool AtTopLevel,
1903 bool MultipleArchs)
const {
1904 llvm::PrettyStackTraceString CrashInfo(
"Computing output path");
1906 if (AtTopLevel && !isa<DsymutilJobAction>(JA) && !isa<VerifyJobAction>(JA)) {
1907 if (Arg *FinalOutput = C.
getArgs().getLastArg(options::OPT_o))
1912 if (C.
getArgs().hasArg(options::OPT__SLASH_P)) {
1913 assert(AtTopLevel && isa<PreprocessJobAction>(JA));
1914 StringRef BaseName = llvm::sys::path::filename(BaseInput);
1916 if (Arg *A = C.
getArgs().getLastArg(options::OPT__SLASH_Fi))
1917 NameArg = A->getValue();
1925 (isa<PreprocessJobAction>(JA) || JA.
getType() == types::TY_ModuleFile))
1929 if (JA.
getType() == types::TY_PP_Asm &&
1930 (C.
getArgs().hasArg(options::OPT__SLASH_FA) ||
1931 C.
getArgs().hasArg(options::OPT__SLASH_Fa))) {
1933 StringRef BaseName = llvm::sys::path::filename(BaseInput);
1934 StringRef FaValue = C.
getArgs().getLastArgValue(options::OPT__SLASH_Fa);
1942 !C.
getArgs().hasArg(options::OPT__SLASH_Fo)) ||
1944 StringRef
Name = llvm::sys::path::filename(BaseInput);
1945 std::pair<StringRef, StringRef> Split = Name.split(
'.');
1955 if (isa<DsymutilJobAction>(JA) || isa<VerifyJobAction>(JA))
1956 BaseName = BasePath;
1958 BaseName = llvm::sys::path::filename(BasePath);
1961 const char *NamedOutput;
1963 if (JA.
getType() == types::TY_Object &&
1964 C.
getArgs().hasArg(options::OPT__SLASH_Fo, options::OPT__SLASH_o)) {
1968 .getLastArg(options::OPT__SLASH_Fo, options::OPT__SLASH_o)
1972 }
else if (JA.
getType() == types::TY_Image &&
1973 C.
getArgs().hasArg(options::OPT__SLASH_Fe,
1974 options::OPT__SLASH_o)) {
1978 .getLastArg(options::OPT__SLASH_Fe, options::OPT__SLASH_o)
1982 }
else if (JA.
getType() == types::TY_Image) {
1987 }
else if (MultipleArchs && BoundArch) {
1990 Output.append(BoundArch);
1991 NamedOutput = C.
getArgs().MakeArgString(Output.c_str());
1996 assert(Suffix &&
"All types used for output should have a suffix.");
1998 std::string::size_type
End = std::string::npos;
2000 End = BaseName.rfind(
'.');
2002 if (MultipleArchs && BoundArch) {
2004 Suffixed.append(BoundArch);
2009 if (!AtTopLevel && C.
getArgs().hasArg(options::OPT_emit_llvm) &&
2010 JA.
getType() == types::TY_LLVM_BC)
2014 NamedOutput = C.
getArgs().MakeArgString(Suffixed.c_str());
2019 JA.
getType() != types::TY_PCH) {
2020 Arg *FinalOutput = C.
getArgs().getLastArg(options::OPT_o);
2022 llvm::sys::path::remove_filename(TempPath);
2023 StringRef OutputFileName = llvm::sys::path::filename(NamedOutput);
2024 llvm::sys::path::append(TempPath, OutputFileName);
2025 NamedOutput = C.
getArgs().MakeArgString(TempPath.c_str());
2031 bool SameFile =
false;
2033 llvm::sys::fs::current_path(Result);
2034 llvm::sys::path::append(Result, BaseName);
2035 llvm::sys::fs::equivalent(BaseInput, Result.c_str(), SameFile);
2038 StringRef
Name = llvm::sys::path::filename(BaseInput);
2039 std::pair<StringRef, StringRef> Split = Name.split(
'.');
2047 if (JA.
getType() == types::TY_PCH) {
2048 llvm::sys::path::remove_filename(BasePath);
2049 if (BasePath.empty())
2050 BasePath = NamedOutput;
2052 llvm::sys::path::append(BasePath, NamedOutput);
2066 llvm::sys::path::append(
P, Name);
2067 if (llvm::sys::fs::exists(Twine(
P)))
2072 llvm::sys::path::append(P, Name);
2073 if (llvm::sys::fs::exists(Twine(P)))
2080 llvm::sys::path::append(P, Name);
2081 if (llvm::sys::fs::exists(Twine(P)))
2088 void Driver::generatePrefixedToolNames(
2093 Names.emplace_back(Tool);
2098 for (
const auto &Name : Names) {
2099 llvm::sys::path::append(Dir, Name);
2100 if (llvm::sys::fs::can_execute(Twine(Dir)))
2102 llvm::sys::path::remove_filename(Dir);
2110 generatePrefixedToolNames(Name, TC, TargetSpecificExecutables);
2115 if (llvm::sys::fs::is_directory(PrefixDir)) {
2121 if (llvm::sys::fs::can_execute(Twine(P)))
2127 for (
const auto &Path : List) {
2134 for (
const auto &TargetSpecificExecutable : TargetSpecificExecutables)
2135 if (llvm::ErrorOr<std::string>
P =
2136 llvm::sys::findProgramByName(TargetSpecificExecutable))
2143 const char *Suffix)
const {
2145 std::error_code EC = llvm::sys::fs::createTemporaryFile(Prefix, Suffix, Path);
2147 Diag(clang::diag::err_unable_to_make_temp) << EC.message();
2154 const ToolChain &Driver::getToolChain(
const ArgList &Args,
2155 const llvm::Triple &Target)
const {
2157 ToolChain *&TC = ToolChains[Target.str()];
2159 switch (Target.getOS()) {
2160 case llvm::Triple::CloudABI:
2163 case llvm::Triple::Darwin:
2164 case llvm::Triple::MacOSX:
2165 case llvm::Triple::IOS:
2168 case llvm::Triple::DragonFly:
2171 case llvm::Triple::OpenBSD:
2174 case llvm::Triple::Bitrig:
2177 case llvm::Triple::NetBSD:
2180 case llvm::Triple::FreeBSD:
2183 case llvm::Triple::Minix:
2186 case llvm::Triple::Linux:
2187 if (Target.getArch() == llvm::Triple::hexagon)
2192 case llvm::Triple::NaCl:
2195 case llvm::Triple::Solaris:
2198 case llvm::Triple::Win32:
2199 switch (Target.getEnvironment()) {
2201 if (Target.isOSBinFormatELF())
2203 else if (Target.isOSBinFormatMachO())
2208 case llvm::Triple::GNU:
2211 case llvm::Triple::Itanium:
2214 case llvm::Triple::MSVC:
2215 case llvm::Triple::UnknownEnvironment:
2220 case llvm::Triple::CUDA:
2226 if (Target.getArchName() ==
"tce")
2228 else if (Target.getArch() == llvm::Triple::hexagon)
2230 else if (Target.getArch() == llvm::Triple::xcore)
2232 else if (Target.getArch() == llvm::Triple::shave)
2234 else if (Target.isOSBinFormatELF())
2236 else if (Target.isOSBinFormatMachO())
2252 if (!isa<PreprocessJobAction>(JA) && !isa<PrecompileJobAction>(JA) &&
2253 !isa<CompileJobAction>(JA) && !isa<BackendJobAction>(JA))
2265 unsigned &Minor,
unsigned &Micro,
2269 Major = Minor = Micro = 0;
2274 Major = (
unsigned)strtol(Str, &End, 10);
2275 if (*Str !=
'\0' && *End ==
'\0')
2281 Minor = (
unsigned)strtol(Str, &End, 10);
2282 if (*Str !=
'\0' && *End ==
'\0')
2288 Micro = (
unsigned)strtol(Str, &End, 10);
2289 if (*Str !=
'\0' && *End ==
'\0')
2297 std::pair<unsigned, unsigned> Driver::getIncludeExcludeOptionFlagMasks()
const {
2298 unsigned IncludedFlagsBitmask = 0;
2301 if (Mode == CLMode) {
2309 return std::make_pair(IncludedFlagsBitmask, ExcludedFlagsBitmask);
2313 return Args.hasFlag(options::OPT_Ofast, options::OPT_O_Group,
false);
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
void BuildUniversalActions(const ToolChain &TC, llvm::opt::DerivedArgList &Args, const InputList &BAInputs, ActionList &Actions) const
std::string getClangFullVersion()
Retrieves a string representing the complete clang version, which includes the clang version number...
const char * getTypeTempSuffix(ID Id, bool CLMode=false)
static Arg * MakeInputArg(DerivedArgList &Args, OptTable *Opts, StringRef Value)
unsigned CCCUsePCH
Use lazy precompiled headers for PCH support.
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
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)
Compilation * BuildCompilation(ArrayRef< const char * > Args)
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
bool CCCIsCXX() const
Whether the driver should follow g++ like behavior.
static bool ScanDirForExecutable(SmallString< 128 > &Dir, ArrayRef< std::string > Names)
void PrintHelp(bool ShowHidden) const
static bool DiagnoseInputExistence(const Driver &D, const DerivedArgList &Args, StringRef Value)
Check that the file referenced by Value exists. If it doesn't, issue a diagnostic and return false...
void PrintActions(const Compilation &C) const
PrintActions - Print the list of actions.
const std::string & gccSuffix() const
Get the detected GCC installation path suffix for the multi-arch target variant. Always starts with a...
ID lookupCXXTypeForCType(ID Id)
ActionClass getKind() const
void BuildActions(const ToolChain &TC, llvm::opt::DerivedArgList &Args, const InputList &Inputs, ActionList &Actions) 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.
bool HandleImmediateArgs(const Compilation &C)
Driver(StringRef _ClangExecutable, StringRef _DefaultTargetTriple, DiagnosticsEngine &_Diags)
Concrete class used by the front-end to report problems and issues.
std::unique_ptr< Action > ConstructPhaseAction(const ToolChain &TC, const llvm::opt::ArgList &Args, phases::ID Phase, std::unique_ptr< Action > Input) const
const llvm::opt::DerivedArgList & getArgs() const
bool IsUsingLTO(const llvm::opt::ArgList &Args) const
std::string GetFilePath(const char *Name, const ToolChain &TC) const
llvm::opt::InputArgList ParseArgStrings(ArrayRef< const char * > Args)
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)
const Action & getSource() const
getSource - Return the Action which caused the creation of this job.
void PrintVersion(const Compilation &C, raw_ostream &OS) const
PrintVersion - Print the driver version.
bool isSaveTempsEnabled() const
ID getPreprocessedType(ID Id)
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
void getCompilationPhases(ID Id, llvm::SmallVectorImpl< phases::ID > &Phases)
ActionList::const_iterator const_iterator
The result type of a method or function.
static void PrintDiagnosticCategories(raw_ostream &OS)
int ExecuteCompilation(Compilation &C, SmallVectorImpl< std::pair< int, const Command * > > &FailingCommands)
static std::unique_ptr< Action > buildCudaActions(const Driver &D, const ToolChain &TC, DerivedArgList &Args, const Arg *InputArg, const types::ID InputType, std::unique_ptr< Action > Current, ActionList &Actions)
bool UseStdLib
If the standard library is used.
bool CleanupFileMap(const ArgStringMap &Files, const JobAction *JA, bool IssueErrors=false) const
std::string GetProgramPath(const char *Name, const ToolChain &TC) const
static unsigned PrintActions1(const Compilation &C, Action *A, std::map< Action *, unsigned > &Ids)
void BuildJobs(Compilation &C) const
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)
bool isAcceptedByClang(ID Id)
isAcceptedByClang - Can clang handle this input type.
const llvm::opt::DerivedArgList & getArgsForToolChain(const ToolChain *TC, const char *BoundArch)
const llvm::opt::ArgStringList & getArguments() const
const ToolChain & getDefaultToolChain() const
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
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.
ActionList & getActions()
void ExecuteJobs(const JobList &Jobs, SmallVectorImpl< std::pair< int, const Command * >> &FailingCommands) const
void BuildInputs(const ToolChain &TC, llvm::opt::DerivedArgList &Args, InputList &Inputs) const
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.
std::string DefaultTargetTriple
Default target triple.
const llvm::opt::ArgStringList & getTempFiles() const
const char * addTempFile(const char *Name)
void BuildJobsForAction(Compilation &C, const Action *A, const ToolChain *TC, const char *BoundArch, bool AtTopLevel, bool MultipleArchs, const char *LinkingOutput, InputInfo &Result) const
static Decl::Kind getKind(const Decl *D)
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)
ID lookupTypeForTypeSpecifier(const char *Name)
void initCompilationForDiagnostics()
unsigned CCGenDiagnostics
Whether the driver is generating diagnostics for debugging purposes.
static const Tool * SelectToolForJob(Compilation &C, bool SaveTemps, const ToolChain *TC, const JobAction *JA, const ActionList *&Inputs)
std::string ResourceDir
The path to the compiler resource directory.