|
@@ -120,16 +120,16 @@ std::string Driver::GetResourcesPath(StringRef BinaryPath,
|
|
Driver::Driver(StringRef ClangExecutable, StringRef TargetTriple,
|
|
Driver::Driver(StringRef ClangExecutable, StringRef TargetTriple,
|
|
DiagnosticsEngine &Diags,
|
|
DiagnosticsEngine &Diags,
|
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
|
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS)
|
|
- : Opts(createDriverOptTable()), Diags(Diags), VFS(std::move(VFS)),
|
|
|
|
- Mode(GCCMode), SaveTemps(SaveTempsNone), BitcodeEmbed(EmbedNone),
|
|
|
|
- LTOMode(LTOK_None), ClangExecutable(ClangExecutable),
|
|
|
|
- SysRoot(DEFAULT_SYSROOT), DriverTitle("clang LLVM compiler"),
|
|
|
|
- CCPrintOptionsFilename(nullptr), CCPrintHeadersFilename(nullptr),
|
|
|
|
- CCLogDiagnosticsFilename(nullptr), CCCPrintBindings(false),
|
|
|
|
- CCPrintOptions(false), CCPrintHeaders(false), CCLogDiagnostics(false),
|
|
|
|
- CCGenDiagnostics(false), TargetTriple(TargetTriple),
|
|
|
|
- CCCGenericGCCName(""), Saver(Alloc), CheckInputsExist(true),
|
|
|
|
- GenReproducer(false), SuppressMissingInputWarning(false) {
|
|
|
|
|
|
+ : Diags(Diags), VFS(std::move(VFS)), Mode(GCCMode),
|
|
|
|
+ SaveTemps(SaveTempsNone), BitcodeEmbed(EmbedNone), LTOMode(LTOK_None),
|
|
|
|
+ ClangExecutable(ClangExecutable), SysRoot(DEFAULT_SYSROOT),
|
|
|
|
+ DriverTitle("clang LLVM compiler"), CCPrintOptionsFilename(nullptr),
|
|
|
|
+ CCPrintHeadersFilename(nullptr), CCLogDiagnosticsFilename(nullptr),
|
|
|
|
+ CCCPrintBindings(false), CCPrintOptions(false), CCPrintHeaders(false),
|
|
|
|
+ CCLogDiagnostics(false), CCGenDiagnostics(false),
|
|
|
|
+ TargetTriple(TargetTriple), CCCGenericGCCName(""), Saver(Alloc),
|
|
|
|
+ CheckInputsExist(true), GenReproducer(false),
|
|
|
|
+ SuppressMissingInputWarning(false) {
|
|
|
|
|
|
// Provide a sane fallback if no VFS is specified.
|
|
// Provide a sane fallback if no VFS is specified.
|
|
if (!this->VFS)
|
|
if (!this->VFS)
|
|
@@ -310,7 +310,7 @@ phases::ID Driver::getFinalPhase(const DerivedArgList &DAL,
|
|
return FinalPhase;
|
|
return FinalPhase;
|
|
}
|
|
}
|
|
|
|
|
|
-static Arg *MakeInputArg(DerivedArgList &Args, OptTable &Opts,
|
|
|
|
|
|
+static Arg *MakeInputArg(DerivedArgList &Args, const OptTable &Opts,
|
|
StringRef Value, bool Claim = true) {
|
|
StringRef Value, bool Claim = true) {
|
|
Arg *A = new Arg(Opts.getOption(options::OPT_INPUT), Value,
|
|
Arg *A = new Arg(Opts.getOption(options::OPT_INPUT), Value,
|
|
Args.getBaseArgs().MakeIndex(Value), Value.data());
|
|
Args.getBaseArgs().MakeIndex(Value), Value.data());
|
|
@@ -321,6 +321,7 @@ static Arg *MakeInputArg(DerivedArgList &Args, OptTable &Opts,
|
|
}
|
|
}
|
|
|
|
|
|
DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
|
|
DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
|
|
|
|
+ const llvm::opt::OptTable &Opts = getOpts();
|
|
DerivedArgList *DAL = new DerivedArgList(Args);
|
|
DerivedArgList *DAL = new DerivedArgList(Args);
|
|
|
|
|
|
bool HasNostdlib = Args.hasArg(options::OPT_nostdlib);
|
|
bool HasNostdlib = Args.hasArg(options::OPT_nostdlib);
|
|
@@ -337,12 +338,12 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
|
|
A->getOption().matches(options::OPT_Xlinker)) &&
|
|
A->getOption().matches(options::OPT_Xlinker)) &&
|
|
A->containsValue("--no-demangle")) {
|
|
A->containsValue("--no-demangle")) {
|
|
// Add the rewritten no-demangle argument.
|
|
// Add the rewritten no-demangle argument.
|
|
- DAL->AddFlagArg(A, Opts->getOption(options::OPT_Z_Xlinker__no_demangle));
|
|
|
|
|
|
+ DAL->AddFlagArg(A, Opts.getOption(options::OPT_Z_Xlinker__no_demangle));
|
|
|
|
|
|
// Add the remaining values as Xlinker arguments.
|
|
// Add the remaining values as Xlinker arguments.
|
|
for (StringRef Val : A->getValues())
|
|
for (StringRef Val : A->getValues())
|
|
if (Val != "--no-demangle")
|
|
if (Val != "--no-demangle")
|
|
- DAL->AddSeparateArg(A, Opts->getOption(options::OPT_Xlinker), Val);
|
|
|
|
|
|
+ DAL->AddSeparateArg(A, Opts.getOption(options::OPT_Xlinker), Val);
|
|
|
|
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
@@ -355,12 +356,11 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
|
|
A->getValue(0) == StringRef("-MMD"))) {
|
|
A->getValue(0) == StringRef("-MMD"))) {
|
|
// Rewrite to -MD/-MMD along with -MF.
|
|
// Rewrite to -MD/-MMD along with -MF.
|
|
if (A->getValue(0) == StringRef("-MD"))
|
|
if (A->getValue(0) == StringRef("-MD"))
|
|
- DAL->AddFlagArg(A, Opts->getOption(options::OPT_MD));
|
|
|
|
|
|
+ DAL->AddFlagArg(A, Opts.getOption(options::OPT_MD));
|
|
else
|
|
else
|
|
- DAL->AddFlagArg(A, Opts->getOption(options::OPT_MMD));
|
|
|
|
|
|
+ DAL->AddFlagArg(A, Opts.getOption(options::OPT_MMD));
|
|
if (A->getNumValues() == 2)
|
|
if (A->getNumValues() == 2)
|
|
- DAL->AddSeparateArg(A, Opts->getOption(options::OPT_MF),
|
|
|
|
- A->getValue(1));
|
|
|
|
|
|
+ DAL->AddSeparateArg(A, Opts.getOption(options::OPT_MF), A->getValue(1));
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -371,13 +371,13 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
|
|
// Rewrite unless -nostdlib is present.
|
|
// Rewrite unless -nostdlib is present.
|
|
if (!HasNostdlib && !HasNodefaultlib && !HasNostdlibxx &&
|
|
if (!HasNostdlib && !HasNodefaultlib && !HasNostdlibxx &&
|
|
Value == "stdc++") {
|
|
Value == "stdc++") {
|
|
- DAL->AddFlagArg(A, Opts->getOption(options::OPT_Z_reserved_lib_stdcxx));
|
|
|
|
|
|
+ DAL->AddFlagArg(A, Opts.getOption(options::OPT_Z_reserved_lib_stdcxx));
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
// Rewrite unconditionally.
|
|
// Rewrite unconditionally.
|
|
if (Value == "cc_kext") {
|
|
if (Value == "cc_kext") {
|
|
- DAL->AddFlagArg(A, Opts->getOption(options::OPT_Z_reserved_lib_cckext));
|
|
|
|
|
|
+ DAL->AddFlagArg(A, Opts.getOption(options::OPT_Z_reserved_lib_cckext));
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -386,7 +386,7 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
|
|
if (A->getOption().matches(options::OPT__DASH_DASH)) {
|
|
if (A->getOption().matches(options::OPT__DASH_DASH)) {
|
|
A->claim();
|
|
A->claim();
|
|
for (StringRef Val : A->getValues())
|
|
for (StringRef Val : A->getValues())
|
|
- DAL->append(MakeInputArg(*DAL, *Opts, Val, false));
|
|
|
|
|
|
+ DAL->append(MakeInputArg(*DAL, Opts, Val, false));
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -395,14 +395,14 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const {
|
|
|
|
|
|
// Enforce -static if -miamcu is present.
|
|
// Enforce -static if -miamcu is present.
|
|
if (Args.hasFlag(options::OPT_miamcu, options::OPT_mno_iamcu, false))
|
|
if (Args.hasFlag(options::OPT_miamcu, options::OPT_mno_iamcu, false))
|
|
- DAL->AddFlagArg(0, Opts->getOption(options::OPT_static));
|
|
|
|
|
|
+ DAL->AddFlagArg(0, Opts.getOption(options::OPT_static));
|
|
|
|
|
|
// Add a default value of -mlinker-version=, if one was given and the user
|
|
// Add a default value of -mlinker-version=, if one was given and the user
|
|
// didn't specify one.
|
|
// didn't specify one.
|
|
#if defined(HOST_LINK_VERSION)
|
|
#if defined(HOST_LINK_VERSION)
|
|
if (!Args.hasArg(options::OPT_mlinker_version_EQ) &&
|
|
if (!Args.hasArg(options::OPT_mlinker_version_EQ) &&
|
|
strlen(HOST_LINK_VERSION) > 0) {
|
|
strlen(HOST_LINK_VERSION) > 0) {
|
|
- DAL->AddJoinedArg(0, Opts->getOption(options::OPT_mlinker_version_EQ),
|
|
|
|
|
|
+ DAL->AddJoinedArg(0, Opts.getOption(options::OPT_mlinker_version_EQ),
|
|
HOST_LINK_VERSION);
|
|
HOST_LINK_VERSION);
|
|
DAL->getLastArg(options::OPT_mlinker_version_EQ)->claim();
|
|
DAL->getLastArg(options::OPT_mlinker_version_EQ)->claim();
|
|
}
|
|
}
|
|
@@ -1592,16 +1592,17 @@ void Driver::HandleAutocompletions(StringRef PassedFlags) const {
|
|
if (llvm::is_contained(Flags, "-Xclang") || llvm::is_contained(Flags, "-cc1"))
|
|
if (llvm::is_contained(Flags, "-Xclang") || llvm::is_contained(Flags, "-cc1"))
|
|
DisableFlags &= ~options::NoDriverOption;
|
|
DisableFlags &= ~options::NoDriverOption;
|
|
|
|
|
|
|
|
+ const llvm::opt::OptTable &Opts = getOpts();
|
|
StringRef Cur;
|
|
StringRef Cur;
|
|
Cur = Flags.at(Flags.size() - 1);
|
|
Cur = Flags.at(Flags.size() - 1);
|
|
StringRef Prev;
|
|
StringRef Prev;
|
|
if (Flags.size() >= 2) {
|
|
if (Flags.size() >= 2) {
|
|
Prev = Flags.at(Flags.size() - 2);
|
|
Prev = Flags.at(Flags.size() - 2);
|
|
- SuggestedCompletions = Opts->suggestValueCompletions(Prev, Cur);
|
|
|
|
|
|
+ SuggestedCompletions = Opts.suggestValueCompletions(Prev, Cur);
|
|
}
|
|
}
|
|
|
|
|
|
if (SuggestedCompletions.empty())
|
|
if (SuggestedCompletions.empty())
|
|
- SuggestedCompletions = Opts->suggestValueCompletions(Cur, "");
|
|
|
|
|
|
+ SuggestedCompletions = Opts.suggestValueCompletions(Cur, "");
|
|
|
|
|
|
// If Flags were empty, it means the user typed `clang [tab]` where we should
|
|
// If Flags were empty, it means the user typed `clang [tab]` where we should
|
|
// list all possible flags. If there was no value completion and the user
|
|
// list all possible flags. If there was no value completion and the user
|
|
@@ -1619,7 +1620,7 @@ void Driver::HandleAutocompletions(StringRef PassedFlags) const {
|
|
// If the flag is in the form of "--autocomplete=-foo",
|
|
// If the flag is in the form of "--autocomplete=-foo",
|
|
// we were requested to print out all option names that start with "-foo".
|
|
// we were requested to print out all option names that start with "-foo".
|
|
// For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
|
|
// For example, "--autocomplete=-fsyn" is expanded to "-fsyntax-only".
|
|
- SuggestedCompletions = Opts->findByPrefix(Cur, DisableFlags);
|
|
|
|
|
|
+ SuggestedCompletions = Opts.findByPrefix(Cur, DisableFlags);
|
|
|
|
|
|
// We have to query the -W flags manually as they're not in the OptTable.
|
|
// We have to query the -W flags manually as they're not in the OptTable.
|
|
// TODO: Find a good way to add them to OptTable instead and them remove
|
|
// TODO: Find a good way to add them to OptTable instead and them remove
|
|
@@ -2037,6 +2038,7 @@ bool Driver::DiagnoseInputExistence(const DerivedArgList &Args, StringRef Value,
|
|
// Construct a the list of inputs and their types.
|
|
// Construct a the list of inputs and their types.
|
|
void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
|
|
void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
|
|
InputList &Inputs) const {
|
|
InputList &Inputs) const {
|
|
|
|
+ const llvm::opt::OptTable &Opts = getOpts();
|
|
// Track the current user specified (-x) input. We also explicitly track the
|
|
// Track the current user specified (-x) input. We also explicitly track the
|
|
// argument used to set the type; we only want to claim the type when we
|
|
// argument used to set the type; we only want to claim the type when we
|
|
// actually use it, so we warn about unused -x arguments.
|
|
// actually use it, so we warn about unused -x arguments.
|
|
@@ -2160,7 +2162,7 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
|
|
StringRef Value = A->getValue();
|
|
StringRef Value = A->getValue();
|
|
if (DiagnoseInputExistence(Args, Value, types::TY_C,
|
|
if (DiagnoseInputExistence(Args, Value, types::TY_C,
|
|
/*TypoCorrect=*/false)) {
|
|
/*TypoCorrect=*/false)) {
|
|
- Arg *InputArg = MakeInputArg(Args, *Opts, A->getValue());
|
|
|
|
|
|
+ Arg *InputArg = MakeInputArg(Args, Opts, A->getValue());
|
|
Inputs.push_back(std::make_pair(types::TY_C, InputArg));
|
|
Inputs.push_back(std::make_pair(types::TY_C, InputArg));
|
|
}
|
|
}
|
|
A->claim();
|
|
A->claim();
|
|
@@ -2168,7 +2170,7 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
|
|
StringRef Value = A->getValue();
|
|
StringRef Value = A->getValue();
|
|
if (DiagnoseInputExistence(Args, Value, types::TY_CXX,
|
|
if (DiagnoseInputExistence(Args, Value, types::TY_CXX,
|
|
/*TypoCorrect=*/false)) {
|
|
/*TypoCorrect=*/false)) {
|
|
- Arg *InputArg = MakeInputArg(Args, *Opts, A->getValue());
|
|
|
|
|
|
+ Arg *InputArg = MakeInputArg(Args, Opts, A->getValue());
|
|
Inputs.push_back(std::make_pair(types::TY_CXX, InputArg));
|
|
Inputs.push_back(std::make_pair(types::TY_CXX, InputArg));
|
|
}
|
|
}
|
|
A->claim();
|
|
A->claim();
|
|
@@ -2202,7 +2204,7 @@ void Driver::BuildInputs(const ToolChain &TC, DerivedArgList &Args,
|
|
if (CCCIsCPP() && Inputs.empty()) {
|
|
if (CCCIsCPP() && Inputs.empty()) {
|
|
// If called as standalone preprocessor, stdin is processed
|
|
// If called as standalone preprocessor, stdin is processed
|
|
// if no other input is present.
|
|
// if no other input is present.
|
|
- Arg *A = MakeInputArg(Args, *Opts, "-");
|
|
|
|
|
|
+ Arg *A = MakeInputArg(Args, Opts, "-");
|
|
Inputs.push_back(std::make_pair(types::TY_C, A));
|
|
Inputs.push_back(std::make_pair(types::TY_C, A));
|
|
}
|
|
}
|
|
}
|
|
}
|