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

2025-06-18 Thread Ying Yi via cfe-commits

MaggieYingYi wrote:

> I had created #144737 for code review.

Fixed the issue. Bot https://lab.llvm.org/buildbot/#/builders/64/builds/4311 
build successfully.

https://github.com/llvm/llvm-project/pull/143614
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2025-06-18 Thread Ying Yi via cfe-commits

MaggieYingYi wrote:

I had created https://github.com/llvm/llvm-project/pull/144737 for code review.

https://github.com/llvm/llvm-project/pull/143614
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2025-06-18 Thread Ying Yi via cfe-commits

MaggieYingYi wrote:

Thanks @lei137, I am working on fixing the test.

https://github.com/llvm/llvm-project/pull/143614
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2025-06-16 Thread Ying Yi via cfe-commits


@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+
+// Create PCH without -ignore-pch.
+// RUN: %clang -x c++-header %S/../Modules/Inputs/codegen-flags/foo.h -### 
2>&1 | FileCheck %s -check-prefix=CHECK-EMIT-PCH

MaggieYingYi wrote:

Hi @MaskRay,

Assuming you are happy with the change. I will commit the change later today if 
I haven't received any further comments.

Thanks,

https://github.com/llvm/llvm-project/pull/143614
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2025-06-12 Thread Ying Yi via cfe-commits


@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+
+// Create PCH without -ignore-pch.
+// RUN: %clang -x c++-header %S/../Modules/Inputs/codegen-flags/foo.h -### 
2>&1 | FileCheck %s -check-prefix=CHECK-EMIT-PCH

MaggieYingYi wrote:

Hi @MaskRay,

Could you please let me know whether you are happy with the change?

Thanks,

https://github.com/llvm/llvm-project/pull/143614
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2025-06-11 Thread Ying Yi via cfe-commits


@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+
+// Create PCH without -ignore-pch.
+// RUN: %clang -x c++-header %S/../Modules/Inputs/codegen-flags/foo.h -### 
2>&1 | FileCheck %s -check-prefix=CHECK-EMIT-PCH

MaggieYingYi wrote:

Thanks, fixed in 
https://github.com/MaggieYingYi/llvm-project/commit/aa9f35a45a4c21f68ef0383abd1ef33463daee8b.

https://github.com/llvm/llvm-project/pull/143614
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2025-06-11 Thread Ying Yi via cfe-commits

https://github.com/MaggieYingYi updated 
https://github.com/llvm/llvm-project/pull/143614

>From a581eb7725f88d49b65376dcf113299e35aacf78 Mon Sep 17 00:00:00 2001
From: Ying Yi 
Date: Tue, 10 Jun 2025 20:09:57 +0100
Subject: [PATCH 1/2] Reload "[Frontend][PCH]-Add support for ignoring PCH
 options (-ignore-pch). (#142409)"

Visual Studio has an argument to ignore all PCH related switches. clang-cl has 
also support option /Y-. Having the same option in clang would be helpful. This 
commit is to add support for ignoring PCH options (-ignore-pch).

The commit includes:
  1. Implement -ignore-pch as a Driver option.
  2. Add a Driver test and a PCH test.
  3. Add a section of -ignore-pch to user manual.
  4. Add a release note for the new option '-ignore-pch'.

Co-authored-by: Matheus Izvekov 
---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/docs/UsersManual.rst|  13 +++
 clang/include/clang/Driver/Options.td |   3 +
 clang/lib/Driver/Driver.cpp   |   8 ++
 clang/lib/Driver/ToolChains/Clang.cpp |   5 +-
 clang/test/Driver/ignored-pch.cpp |  19 +
 clang/test/PCH/Inputs/ignored-pch.h   |   6 ++
 clang/test/PCH/ignored-pch.c  | 113 ++
 8 files changed, 167 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Driver/ignored-pch.cpp
 create mode 100644 clang/test/PCH/Inputs/ignored-pch.h
 create mode 100644 clang/test/PCH/ignored-pch.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f36c82bff2ef8..86287b28f0bf8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -339,6 +339,8 @@ New Compiler Flags
 
 - New option ``-Wnrvo`` added and disabled by default to warn about missed 
NRVO opportunities.
 
+- New option ``-ignore-pch`` added to disable precompiled headers. It 
overrides ``-emit-pch`` and ``-include-pch``. (#GH142409, `PCHDocs 
`_).
+
 Deprecated Compiler Flags
 -
 
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 62844f7e6a2fa..284a404026dfe 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1458,6 +1458,19 @@ will be processed from the PCH file. Otherwise, Clang 
will report an error.
   ``test.h`` since ``test.h`` was included directly in the source file and not
   specified on the command line using ``-include-pch``.
 
+Ignoring a PCH File
+^^^
+
+To ignore PCH options, a `-ignore-pch` option is passed to ``clang``:
+
+.. code-block:: console
+
+  $ clang -x c-header test.h -Xclang -ignore-pch -o test.h.pch
+  $ clang -include-pch test.h.pch -Xclang -ignore-pch test.c -o test
+
+This option disables precompiled headers, overrides -emit-pch and -include-pch.
+test.h.pch is not generated and not used as a prefix header.
+
 Relocatable PCH Files
 ^
 
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 3582efd7721b0..66d3dc921816d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3348,6 +3348,9 @@ defm pch_codegen: OptInCC1FFlag<"pch-codegen", "Generate 
", "Do not generate ",
   "code for uses of this PCH that assumes an explicit object file will be 
built for the PCH">;
 defm pch_debuginfo: OptInCC1FFlag<"pch-debuginfo", "Generate ", "Do not 
generate ",
   "debug info for types in an object file built from this PCH and do not 
generate them elsewhere">;
+def ignore_pch : Flag<["-"], "ignore-pch">, Group,
+  Visibility<[ClangOption]>,
+  HelpText<"Disable precompiled headers, overrides -emit-pch and 
-include-pch">;
 
 def fimplicit_module_maps : Flag <["-"], "fimplicit-module-maps">, 
Group,
   Visibility<[ClangOption, CC1Option, CLOption]>,
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 80728daca03c9..21489c8b0cde9 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4331,6 +4331,14 @@ void Driver::handleArguments(Compilation &C, 
DerivedArgList &Args,
 YcArg = YuArg = nullptr;
   }
 
+  if (Args.hasArg(options::OPT_include_pch) &&
+  Args.hasArg(options::OPT_ignore_pch)) {
+// If -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);
+  }
+
   bool LinkOnly = phases::Link == FinalPhase && Inputs.size() > 0;
   for (auto &I : Inputs) {
 types::ID InputType = I.first;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index a74fa81f3cf5b..2d676aa0b9c8e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5184,7 +5184,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   CmdArgs.push_back("-emit-module-interface");
 else if (JA.getType() == types::TY_HeaderUnit)
   CmdArgs.pus

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

2025-06-10 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,19 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+
+// Create PCH without -ignore-pch.
+// RUN: %clang -x c++-header %S/../Modules/Inputs/codegen-flags/foo.h -### 
2>&1 | FileCheck %s -check-prefix=CHECK-EMIT-PCH

MaskRay wrote:

`%S/../` references auxiliary file from a different test directory. We 
typically avoid doing this,,, though Index/ and Headers/ seem to have 
violations.

https://github.com/llvm/llvm-project/pull/143614
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2025-06-10 Thread Ying Yi via cfe-commits

MaggieYingYi wrote:

> LGTM.
> 
Thanks @mizvekov.

> So what changed since the last commit is that preprocessing-only mode doesn't 
> imply the semantics of this flag anymore.
> 

Yes, only ignore PCH option when `-ignore-pch` is used in the command line. The 
preprocessing-only mode (-E) doesn't ignore PCH options.

When I implemented `-ignore-pch`, I followed Visual Studio `/Y-` 
implementation: `-include-pch` is ignored when command is used to generate the 
preprocessed file (`-E`). After exploring the test failure of 
crash-vfs-include-pch.m, I think we should NOT ignore PCH option 
(`-include-pch`) when generating the pre-processed file. For example, the user 
might want to check the different preprocessed files between using normal 
header and precompiled header. 

Thanks @dyung for helping me check the build and test on MacOS. check-all 
passed on mac.

> I think It's good practice to mention what changed since the original landing.
>
Thanks, I will add it in commit message.



https://github.com/llvm/llvm-project/pull/143614
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2025-06-10 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/143614
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2025-06-10 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov approved this pull request.

LGTM.

So what changed since the last commit is that preprocessing-only mode doesn't 
imply the semantics of this flag anymore.

I think It's good practice to mention what changed since original landing.

https://github.com/llvm/llvm-project/pull/143614
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2025-06-10 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/143614
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits