[clang] [Driver] Change default PCH extension name from .gch to .pch (PR #66165)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 12 19:15:21 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-driver
<details>
<summary>Changes</summary>
For `c-header` and `c++-header` inputs, Clang driver selects the
`-emit-pch` frontend action and defaults the output suffix name to
`.gch` (except clang-cl, which uses `.pch`) to follow GCC.
```
clang -c a.h # a.h.gch
clang -xc++-header -c a.h # a.h.gch
```
In every other place we prefer `.pch` to `.gch`. E.g. `-include a.h`
probes `a.h.pch` before `a.h.gch`, and we have `-include-pch` instead of
`-include-gch`. (Clang and GCC use different extension names for C++ modules as well.)
This change isn't disruptive because:
* Most newer build systems specify explicit output filenames and are unaffected
* Implicit output name users almost assuredly use something like
`-include a.h`, which probes both `a.h.pch` and `a.h.gch`[^1]
[^1]: In the future, we shall stop probing `a.h.gch` for `-include a.h` as the
compatibility intended behavior actually gets in the way
(https://discourse.llvm.org/t/how-to-have-clang-ignore-gch-directories/51835).
This patch is a prerequisite.
--
Full diff: https://github.com/llvm/llvm-project/pull/66165.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.rst (+3)
- (modified) clang/include/clang/Driver/Types.def (+1-1)
- (modified) clang/test/Driver/pch-codegen.cpp (+3-1)
<pre>
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3cdad2f7b9f0e5a..d558705f16ca3be 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -41,6 +41,9 @@ code bases.
C/C++ Language Potentially Breaking Changes
-------------------------------------------
+- The default extension name for PCH generation (``-c -xc-header`` and ``-c
+ -xc++-header``) is now ``.pch`` instead of ``.gch``.
+
C++ Specific Potentially Breaking Changes
-----------------------------------------
diff --git a/clang/include/clang/Driver/Types.def b/clang/include/clang/Driver/Types.def
index 519d51f8ad1e5f0..b889883125c4c16 100644
--- a/clang/include/clang/Driver/Types.def
+++ b/clang/include/clang/Driver/Types.def
@@ -98,7 +98,7 @@ TYPE("plist", Plist, INVALID, "plist", phases
TYPE("rewritten-objc", RewrittenObjC,INVALID, "cpp", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("rewritten-legacy-objc", RewrittenLegacyObjC,INVALID, "cpp", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("remap", Remap, INVALID, "remap", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("precompiled-header", PCH, INVALID, "gch", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("precompiled-header", PCH, INVALID, "pch", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("object", Object, INVALID, "o", phases::Link)
TYPE("treelang", Treelang, INVALID, nullptr, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("image", Image, INVALID, "out", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
diff --git a/clang/test/Driver/pch-codegen.cpp b/clang/test/Driver/pch-codegen.cpp
index f16f6b51bf409ff..ac4ffb978ca59b1 100644
--- a/clang/test/Driver/pch-codegen.cpp
+++ b/clang/test/Driver/pch-codegen.cpp
@@ -2,10 +2,12 @@
// RUN: mkdir -p %t
// Create PCH without codegen.
-// RUN: %clang -x c++-header %S/../Modules/Inputs/codegen-flags/foo.h -o %t/foo-cg.pch -### 2>&1 | FileCheck %s -check-prefix=CHECK-PCH-CREATE
+// RUN: %clang -x c++-header %S/../Modules/Inputs/codegen-flags/foo.h -### 2>&1 | FileCheck %s -check-prefix=CHECK-PCH-CREATE
// CHECK-PCH-CREATE: -emit-pch
// CHECK-PCH-CREATE-NOT: -fmodules-codegen
// CHECK-PCH-CREATE-NOT: -fmodules-debuginfo
+/// Also test that the default extension name is .pch instead of .gch
+// CHECK-PCH-CREATE: "-o" "{{[^"]+.pch}}"
// Create PCH with -fpch-codegen.
// RUN: %clang -x c++-header -fpch-codegen %S/../Modules/Inputs/codegen-flags/foo.h -o %t/foo-cg.pch -### 2>&1 | FileCheck %s -check-prefix=CHECK-PCH-CODEGEN-CREATE
</pre>
</details>
https://github.com/llvm/llvm-project/pull/66165
More information about the cfe-commits
mailing list