From: Daniel Dunbar Date: Wed, 14 Jul 2010 18:46:27 +0000 (+0000) Subject: Driver: When re'execing clang, use path to the main executable instead of X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b9a822639c570b1853c75c235e9d6bad485f9e01;p=clang Driver: When re'execing clang, use path to the main executable instead of looking up Clang in the normal search paths (which may end up finding the wrong clang). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108346 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h index 153981f842..bb578b516c 100644 --- a/include/clang/Driver/Driver.h +++ b/include/clang/Driver/Driver.h @@ -62,6 +62,9 @@ public: /// command line. std::string Dir; + /// The original path to the clang executable. + std::string ClangExecutable; + /// The path to the compiler resource directory. std::string ResourceDir; @@ -163,6 +166,11 @@ public: const std::string &getTitle() { return DriverTitle; } void setTitle(std::string Value) { DriverTitle = Value; } + /// \brief Get the path to the main clang executable. + std::string getClangProgramPath() const { + return ClangExecutable; + } + /// @} /// @name Primary Functionality /// @{ diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 5da7908434..2fc0a5354d 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -75,6 +75,11 @@ Driver::Driver(llvm::StringRef _Name, llvm::StringRef _Dir, P.appendComponent("clang"); P.appendComponent(CLANG_VERSION_STRING); ResourceDir = P.str(); + + // Save the original clang executable path. + P = Dir; + P.appendComponent(Name); + ClangExecutable = P.str(); } Driver::~Driver() { diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 14744998f1..f423d4e3b9 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1489,8 +1489,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, Args.AddAllArgs(CmdArgs, options::OPT_undef); - const char *Exec = - Args.MakeArgString(getToolChain().GetProgramPath("clang")); + std::string Exec = getToolChain().getDriver().getClangProgramPath(); // Optionally embed the -cc1 level arguments into the debug info, for build // analysis. @@ -1510,7 +1509,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Args.MakeArgString(Flags.str())); } - Dest.addCommand(new Command(JA, *this, Exec, CmdArgs)); + Dest.addCommand(new Command(JA, *this, Exec.c_str(), CmdArgs)); // Explicitly warn that these options are unsupported, even though // we are allowing compilation to continue. @@ -1589,9 +1588,8 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(Input.getFilename()); } - const char *Exec = - Args.MakeArgString(getToolChain().GetProgramPath("clang")); - Dest.addCommand(new Command(JA, *this, Exec, CmdArgs)); + std::string Exec = getToolChain().getDriver().getClangProgramPath(); + Dest.addCommand(new Command(JA, *this, Exec.c_str(), CmdArgs)); } void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA,