[clang] [Frontend][PCH]-Add support for ignoring PCH options (-ignore-pch). (PR #142409)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 5 04:26:40 PDT 2025
================
@@ -4286,6 +4286,16 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
YcArg = YuArg = nullptr;
}
+ Arg *IncludePCHArg = Args.getLastArg(options::OPT_include_pch);
+ if (IncludePCHArg && (FinalPhase == phases::Preprocess ||
+ Args.hasArg(options::OPT_ignore_pch))) {
+ // If only preprocessing or -ignore-pch is used, -include-pch is disabled.
+ // Since -emit-pch is CC1option, it will not be added to command argments if
+ // -ignore-pch is used.
+ Args.eraseArg(options::OPT_include_pch);
+ IncludePCHArg = nullptr;
+ }
----------------
MaggieYingYi wrote:
> Though can you explain why you want to include phases::Preprocess here?
I borrowed the idea from `clang-cl /Y-`. The code is shown [Driver.cpp#L4279](https://github.com/MaggieYingYi/llvm-project/blob/yingyi/main/PCH/clang/lib/Driver/Driver.cpp#L4279).
[Driver/Phases.h#L19](https://github.com/MaggieYingYi/llvm-project/blob/yingyi/main/PCH/clang/include/clang/Driver/Phases.h#L19) shows ordered values for successive stages in the compilation process. Since preprocess is the stage before precompile, we don't need to include precompiled header if the final stage is preprocess. There, phases::Preprocess is added here.
https://github.com/llvm/llvm-project/pull/142409
More information about the cfe-commits
mailing list