[Frontend][PCH]-Add support for ignoring PCH options (-ignore-pch). by MaggieYingYi · Pull Request #142409 · llvm/llvm-project (original) (raw)

@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: None (MaggieYingYi)

Changes

As part of the mixed host bring up, the support of PCH (precompiled headers) has been raised as a potential issue. 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).


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

6 Files Affected:

diff --git a/clang/docs/PCHInternals.rst b/clang/docs/PCHInternals.rst index 079fba16711dc..de0b341460cac 100644 --- a/clang/docs/PCHInternals.rst +++ b/clang/docs/PCHInternals.rst @@ -31,6 +31,16 @@ option: $ clang -cc1 -include-pch test.h.pch test.c -o test.s +To ignore PCH options using clang -cc1, use the option -ignore-pch: + +.. code-block:: bash + + $ clang -cc1 test.h -emit-pch -ignore-pch -o test.h.pch + $ clang -cc1 -include-pch test.h.pch -ignore-pch test.c -o test.s + +This option disables precompiled headers, overrides -emit-pch and -include-pch. +test.h.pch is not generated and not used as a prefix header. + Design Philosophy

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst index eb9a812f0c1c9..f12b6b4c02193 100644 --- a/clang/docs/UsersManual.rst +++ b/clang/docs/UsersManual.rst @@ -1458,6 +1458,20 @@ 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 a PCH file using Clang, the -Xclang -ignore-pch option is passed to +clang: + +.. code-block:: console +

diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 5ca31c253ed8f..3ed87608bf592 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -8127,6 +8127,8 @@ def emit_header_unit : Flag<["-"], "emit-header-unit">, HelpText<"Generate C++20 header units from header files">; def emit_pch : Flag<["-"], "emit-pch">, HelpText<"Generate pre-compiled header file">; +def ignore_pch : Flag<["-"], "ignore-pch">,

#undef FRONTEND_OPTION_WITH_MARSHALLING

Opts.ProgramAction = frontend::ParseSyntaxOnly; +

diff --git a/clang/test/PCH/Inputs/ignored-pch.h b/clang/test/PCH/Inputs/ignored-pch.h new file mode 100644 index 0000000000000..0956f9da1cb16 --- /dev/null +++ b/clang/test/PCH/Inputs/ignored-pch.h @@ -0,0 +1,6 @@ +#ifndef IGNORED_PCH_H +#define IGNORED_PCH_H +inline int f() {

+#pragma hdrstop +int main() {