================
@@ -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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to