summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2014-06-26 19:59:02 +0000
committerHans Wennborg <hans@hanshq.net>2014-06-26 19:59:02 +0000
commit29bbc5791e987f999f1ae68f2611dc76163d5b47 (patch)
tree8ffe35288dd8b18ba0897431e2af2bb29c23fb71
parentc8d94b6e324b3d381db666f94a0f3b14d0cc519a (diff)
downloadclang-29bbc5791e987f999f1ae68f2611dc76163d5b47.tar.gz
clang-29bbc5791e987f999f1ae68f2611dc76163d5b47.tar.bz2
clang-29bbc5791e987f999f1ae68f2611dc76163d5b47.tar.xz
clang-cl: Don't store the cl compiler Tool on the stack (PR20131)
The Command will refer back to the Tool as its source, so it has to outlive the Command. Having the Tool on the stack would cause us to crash when using "clang-cl -GR -fallback", because if the Command fails, Driver::ExecuteCompilation tries to peek at the Command's source. Differential Revision: http://reviews.llvm.org/D4314 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211802 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Driver/Tools.cpp11
-rw-r--r--lib/Driver/Tools.h11
2 files changed, 18 insertions, 4 deletions
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 843177414d..28528ffbd0 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -4184,9 +4184,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (Args.hasArg(options::OPT__SLASH_fallback) &&
Output.getType() == types::TY_Object &&
(InputType == types::TY_C || InputType == types::TY_CXX)) {
- tools::visualstudio::Compile CL(getToolChain());
- Command *CLCommand = CL.GetCommand(C, JA, Output, Inputs, Args,
- LinkingOutput);
+ Command *CLCommand = getCLFallback()->GetCommand(C, JA, Output, Inputs,
+ Args, LinkingOutput);
// RTTI support in clang-cl is a work in progress. Fall back to MSVC early
// if we are using 'clang-cl /fallback /GR'.
// FIXME: Remove this when RTTI is finished.
@@ -4450,6 +4449,12 @@ void Clang::AddClangCLArgs(const ArgList &Args, ArgStringList &CmdArgs) const {
}
}
+visualstudio::Compile *Clang::getCLFallback() const {
+ if (!CLFallback)
+ CLFallback.reset(new visualstudio::Compile(getToolChain()));
+ return CLFallback.get();
+}
+
void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
diff --git a/lib/Driver/Tools.h b/lib/Driver/Tools.h
index a25653ea70..c4e6d6c829 100644
--- a/lib/Driver/Tools.h
+++ b/lib/Driver/Tools.h
@@ -29,6 +29,11 @@ namespace toolchains {
}
namespace tools {
+
+namespace visualstudio {
+ class Compile;
+}
+
using llvm::opt::ArgStringList;
/// \brief Clang compiler tool.
@@ -78,6 +83,10 @@ using llvm::opt::ArgStringList;
void AddClangCLArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const;
+ visualstudio::Compile *getCLFallback() const;
+
+ mutable std::unique_ptr<visualstudio::Compile> CLFallback;
+
public:
Clang(const ToolChain &TC) : Tool("clang", "clang frontend", TC) {}
@@ -563,7 +572,7 @@ namespace dragonfly {
};
} // end namespace dragonfly
- /// Visual studio tools.
+/// Visual studio tools.
namespace visualstudio {
class LLVM_LIBRARY_VISIBILITY Link : public Tool {
public: