diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -3157,16 +3157,6 @@ return; } - Arg *FinalPhaseArg; - phases::ID FinalPhase = getFinalPhase(Args, &FinalPhaseArg); - - if (FinalPhase == phases::Link) { - if (Args.hasArg(options::OPT_emit_llvm)) - Diag(clang::diag::err_drv_emit_llvm_link); - if (IsCLMode() && LTOMode != LTOK_None && - !Args.getLastArgValue(options::OPT_fuse_ld_EQ).equals_lower("lld")) - Diag(clang::diag::err_drv_lto_without_lld); - } // Reject -Z* at the top level, these options should never have been exposed // by gcc. @@ -3220,7 +3210,29 @@ Args.eraseArg(options::OPT__SLASH_Yc); YcArg = nullptr; } - if (FinalPhase == phases::Preprocess || Args.hasArg(options::OPT__SLASH_Y_)) { + + // Builder to be used to build offloading actions. + OffloadingActionBuilder OffloadBuilder(C, Args, Inputs); + + // Construct the actions to perform. + HeaderModulePrecompileJobAction *HeaderModuleAction = nullptr; + ActionList LinkerInputs; + + phases::ID FinalPhase; + { + Arg *FinalPhaseArg; + FinalPhase = getFinalPhase(Args, &FinalPhaseArg); + + if (FinalPhase == phases::Link) { + if (Args.hasArg(options::OPT_emit_llvm)) + Diag(clang::diag::err_drv_emit_llvm_link); + if (IsCLMode() && LTOMode != LTOK_None && + !Args.getLastArgValue(options::OPT_fuse_ld_EQ).equals_lower("lld")) + Diag(clang::diag::err_drv_lto_without_lld); + } + + if (FinalPhase == phases::Preprocess || + Args.hasArg(options::OPT__SLASH_Y_)) { // If only preprocessing or /Y- is used, all pch handling is disabled. // Rather than check for it everywhere, just remove clang-cl pch-related // flags here. @@ -3230,13 +3242,6 @@ YcArg = YuArg = nullptr; } - // Builder to be used to build offloading actions. - OffloadingActionBuilder OffloadBuilder(C, Args, Inputs); - - // Construct the actions to perform. - HeaderModulePrecompileJobAction *HeaderModuleAction = nullptr; - ActionList LinkerInputs; - unsigned LastPLSize = 0; for (auto &I : Inputs) { types::ID InputType = I.first; @@ -3268,7 +3273,10 @@ // Special case '-E' warning on a previously preprocessed file to make // more sense. else if (InitialPhase == phases::Compile && - FinalPhase == phases::Preprocess && + (Args.getLastArg(options::OPT__SLASH_EP, + options::OPT__SLASH_P) || + Args.getLastArg(options::OPT_E) || + Args.getLastArg(options::OPT_M, options::OPT_MM)) && getPreprocessedType(InputType) == types::TY_INVALID) Diag(clang::diag::warn_drv_preprocessed_input_file_unused) << InputArg->getAsString(Args) << !!FinalPhaseArg @@ -3288,8 +3296,7 @@ llvm::SmallVector PCHPL; types::getCompilationPhases(HeaderType, PCHPL); // Build the pipeline for the pch file. - Action *ClangClPch = - C.MakeAction(*InputArg, HeaderType); + Action *ClangClPch = C.MakeAction(*InputArg, HeaderType); for (phases::ID Phase : PCHPL) ClangClPch = ConstructPhaseAction(C, Args, Phase, ClangClPch); assert(ClangClPch); @@ -3301,6 +3308,25 @@ // probably not be considered successful either. } } + } + + // If we are linking, claim any options which are obviously only used for + // compilation. + // FIXME: Understand why the last Phase List length is used here. + if (FinalPhase == phases::Link && LastPLSize == 1) { + Args.ClaimAllArgs(options::OPT_CompileOnly_Group); + Args.ClaimAllArgs(options::OPT_cl_compile_Group); + } + } + + for (auto &I : Inputs) { + types::ID InputType = I.first; + const Arg *InputArg = I.second; + + llvm::SmallVector PL; + types::getCompilationPhases(InputType, PL); + if (PL[0] > FinalPhase) + continue; // Build the pipeline for this file. Action *Current = C.MakeAction(*InputArg, InputType); @@ -3379,14 +3405,6 @@ Actions.push_back(LA); } - // If we are linking, claim any options which are obviously only used for - // compilation. - // FIXME: Understand why the last Phase List length is used here. - if (FinalPhase == phases::Link && LastPLSize == 1) { - Args.ClaimAllArgs(options::OPT_CompileOnly_Group); - Args.ClaimAllArgs(options::OPT_cl_compile_Group); - } - // If --print-supported-cpus, -mcpu=? or -mtune=? is specified, build a custom // Compile phase that prints out supported cpu models and quits. if (Arg *A = Args.getLastArg(options::OPT_print_supported_cpus)) {