summaryrefslogtreecommitdiff
path: root/lib/Driver
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2016-08-30 18:55:16 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2016-08-30 18:55:16 +0000
commit0c25e2545416359c181e3486ea7000fc63cdabb9 (patch)
treec37ed6cf396b6a68e3bfac024b18db6e09436f42 /lib/Driver
parentf0601987aade265783efa590abaa49fe35ad8b4a (diff)
downloadclang-0c25e2545416359c181e3486ea7000fc63cdabb9.tar.gz
PR30195: Fix clang-cl attempting to precompile bogus (non-precompilable) input types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@280133 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver')
-rw-r--r--lib/Driver/Driver.cpp8
-rw-r--r--lib/Driver/Types.cpp18
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
index 9871f29eb3..a1adb676a3 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -1685,12 +1685,14 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
if (YcArg) {
// Add a separate precompile phase for the compile phase.
if (FinalPhase >= phases::Compile) {
+ const types::ID HeaderType = lookupHeaderTypeForSourceType(InputType);
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PCHPL;
- types::getCompilationPhases(types::TY_CXXHeader, PCHPL);
+ types::getCompilationPhases(HeaderType, PCHPL);
Arg *PchInputArg = MakeInputArg(Args, Opts, YcArg->getValue());
// Build the pipeline for the pch file.
- Action *ClangClPch = C.MakeAction<InputAction>(*PchInputArg, InputType);
+ Action *ClangClPch =
+ C.MakeAction<InputAction>(*PchInputArg, HeaderType);
for (phases::ID Phase : PCHPL)
ClangClPch = ConstructPhaseAction(C, Args, Phase, ClangClPch);
assert(ClangClPch);
@@ -1812,6 +1814,8 @@ Action *Driver::ConstructPhaseAction(Compilation &C, const ArgList &Args,
return C.MakeAction<PreprocessJobAction>(Input, OutputTy);
}
case phases::Precompile: {
+ assert(onlyPrecompileType(Input->getType()) &&
+ "asked to precompile non-precompilable type");
types::ID OutputTy = types::TY_PCH;
if (Args.hasArg(options::OPT_fsyntax_only)) {
// Syntax checks should not emit a PCH file
diff --git a/lib/Driver/Types.cpp b/lib/Driver/Types.cpp
index e6072de34e..1588c94ac7 100644
--- a/lib/Driver/Types.cpp
+++ b/lib/Driver/Types.cpp
@@ -259,3 +259,21 @@ ID types::lookupCXXTypeForCType(ID Id) {
return types::TY_PP_CXXHeader;
}
}
+
+ID types::lookupHeaderTypeForSourceType(ID Id) {
+ switch (Id) {
+ default:
+ return Id;
+
+ case types::TY_C:
+ return types::TY_CHeader;
+ case types::TY_CXX:
+ return types::TY_CXXHeader;
+ case types::TY_ObjC:
+ return types::TY_ObjCHeader;
+ case types::TY_ObjCXX:
+ return types::TY_ObjCXXHeader;
+ case types::TY_CL:
+ return types::TY_CLHeader;
+ }
+}