diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 2084c0f557ac..489c6ba4b589 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -3725,7 +3725,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, } // Finally add the compile command to the compilation. - if (Args.hasArg(options::OPT__SLASH_fallback)) { + if (Args.hasArg(options::OPT__SLASH_fallback) && + Output.getType() == types::TY_Object) { tools::visualstudio::Compile CL(getToolChain()); Command *CLCommand = CL.GetCommand(C, JA, Output, Inputs, Args, LinkingOutput); diff --git a/clang/test/Driver/cl-fallback.c b/clang/test/Driver/cl-fallback.c index 2433072a0250..9b33b0c0a748 100644 --- a/clang/test/Driver/cl-fallback.c +++ b/clang/test/Driver/cl-fallback.c @@ -39,3 +39,8 @@ // RUN: %clang_cl /fallback /Ox -### -- %s 2>&1 | FileCheck -check-prefix=Ox %s // Ox: cl.exe // Ox: "/Ox" + +// Only fall back when actually compiling, not for e.g. /P (preprocess). +// RUN: %clang_cl /fallback /P -### -- %s 2>&1 | FileCheck -check-prefix=P %s +// P-NOT: || +// P-NOT: "cl.exe"