[clang] [Frontend][PCH]-Add support for ignoring PCH options (-ignore-pch). (PR #142409)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 4 18:40:34 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;
+  }
----------------
mizvekov wrote:

```suggestion
  if (Args.hasArg(options::OPT_include_pch) && (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);
  }
```

Though can you explain why you want to include `phases::Preprocess` here? seems like an unrelated change.

https://github.com/llvm/llvm-project/pull/142409


More information about the cfe-commits mailing list