Skip to content

Commit f726da1

Browse files
committed
[Driver] -include: deprecate probing .gch (llvm#67084)
`-include a.h` probes `a.h.pch` and `a.h.gch`, if not found, falls back to `a.h`. `.pch` is the preferred extension name. Probing .gch is supposed to provide compatibility with build systems that do ``` clang -x c-header a.h -o out/a.h.gch clang -include out/a.h -c a.c # out/a.h.gch is present while out/a.h is absent ``` (not sure what projects actually do this with Clang) But it can often get in the way [^0][^1][^2] when GCC and Clang are mixed as the file format is incompatible with GCC's. Let's deprecate .gch probing. Some tests using `-include` are switched to `.pch`. `test/PCH/pch-dir.c` shows the -Wdeprecated warning. [^0]: https://discourse.llvm.org/t/how-to-have-clang-ignore-gch-directories/51835 [^1]: https://bugreports.qt.io/browse/QTCREATORBUG-22427 [^2]: https://gitlab.kitware.com/cmake/cmake/-/issues/22081
1 parent c72d3ab commit f726da1

File tree

12 files changed

+18
-10
lines changed

12 files changed

+18
-10
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ C/C++ Language Potentially Breaking Changes
4343

4444
- The default extension name for PCH generation (``-c -xc-header`` and ``-c
4545
-xc++-header``) is now ``.pch`` instead of ``.gch``.
46+
- ``-include a.h`` probing ``a.h.gch`` is deprecated. Change the extension name
47+
to ``.pch`` or use ``-include-pch a.h.gch``.
4648

4749
C++ Specific Potentially Breaking Changes
4850
-----------------------------------------

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ def warn_drv_overriding_option : Warning<
431431
def warn_drv_treating_input_as_cxx : Warning<
432432
"treating '%0' input as '%1' when in C++ mode, this behavior is deprecated">,
433433
InGroup<Deprecated>;
434+
def warn_drv_include_probe_gch : Warning<
435+
"'%0' probing .gch is deprecated. Use '-include-pch %1' or switch to .pch instead">,
436+
InGroup<Deprecated>;
434437
def warn_drv_pch_not_first_include : Warning<
435438
"precompiled header '%0' was ignored because '%1' is not first '-include'">;
436439
def warn_missing_sysroot : Warning<"no such sysroot directory: '%0'">,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
12841284
llvm::sys::path::replace_extension(P, "gch");
12851285
if (D.getVFS().exists(P)) {
12861286
FoundPCH = true;
1287+
D.Diag(diag::warn_drv_include_probe_gch) << A->getAsString(Args) << P;
12871288
}
12881289
}
12891290

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"directory": "DIR",
4-
"command": "clang -x c-header DIR/pch.h -fmodules -gmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -o DIR/pch.h.gch",
4+
"command": "clang -x c-header DIR/pch.h -fmodules -gmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -o DIR/pch.h.pch",
55
"file": "DIR/pch.h"
66
}
77
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"directory": "DIR",
4-
"command": "clang -x c-header DIR/pch.h -fmodules -gmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -o DIR/pch.h.gch",
4+
"command": "clang -x c-header DIR/pch.h -fmodules -gmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -o DIR/pch.h.pch",
55
"file": "DIR/pch.h"
66
}
77
]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"directory": "DIR",
4-
"command": "clang -x c-header DIR/pch.h -fmodules -gmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -o DIR/pch.h.gch",
4+
"command": "clang -x c-header DIR/pch.h -fmodules -gmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -o DIR/pch.h.pch",
55
"file": "DIR/pch.h"
66
}
77
]

clang/test/ClangScanDeps/modules-pch-common-submodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
// CHECK-TU: ],
9595
// CHECK-TU: "file-deps": [
9696
// CHECK-TU-NEXT: "[[PREFIX]]/tu.c",
97-
// CHECK-TU-NEXT: "[[PREFIX]]/pch.h.gch"
97+
// CHECK-TU-NEXT: "[[PREFIX]]/pch.h.pch"
9898
// CHECK-TU-NEXT: ],
9999
// CHECK-TU-NEXT: "input-file": "[[PREFIX]]/tu.c"
100100
// CHECK-TU-NEXT: }

clang/test/ClangScanDeps/modules-pch-common-via-submodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
// CHECK-TU: ],
9292
// CHECK-TU: "file-deps": [
9393
// CHECK-TU-NEXT: "[[PREFIX]]/tu.c",
94-
// CHECK-TU-NEXT: "[[PREFIX]]/pch.h.gch"
94+
// CHECK-TU-NEXT: "[[PREFIX]]/pch.h.pch"
9595
// CHECK-TU-NEXT: ],
9696
// CHECK-TU-NEXT: "input-file": "[[PREFIX]]/tu.c"
9797
// CHECK-TU-NEXT: }

clang/test/ClangScanDeps/modules-pch.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// RUN: cat %t/result_pch.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t -check-prefix=CHECK-PCH
1515
//
1616
// Check we didn't build the PCH during dependency scanning.
17-
// RUN: not cat %/t/pch.h.gch
17+
// RUN: not cat %/t/pch.h.pch
1818
//
1919
// CHECK-PCH: {
2020
// CHECK-PCH-NEXT: "modules": [
@@ -129,7 +129,7 @@
129129
// CHECK-TU: ],
130130
// CHECK-TU: "file-deps": [
131131
// CHECK-TU-NEXT: "[[PREFIX]]/tu.c",
132-
// CHECK-TU-NEXT: "[[PREFIX]]/pch.h.gch"
132+
// CHECK-TU-NEXT: "[[PREFIX]]/pch.h.pch"
133133
// CHECK-TU-NEXT: ],
134134
// CHECK-TU-NEXT: "input-file": "[[PREFIX]]/tu.c"
135135
// CHECK-TU-NEXT: }
@@ -179,7 +179,7 @@
179179
// CHECK-TU-WITH-COMMON: ],
180180
// CHECK-TU-WITH-COMMON: "file-deps": [
181181
// CHECK-TU-WITH-COMMON-NEXT: "[[PREFIX]]/tu_with_common.c",
182-
// CHECK-TU-WITH-COMMON-NEXT: "[[PREFIX]]/pch.h.gch"
182+
// CHECK-TU-WITH-COMMON-NEXT: "[[PREFIX]]/pch.h.pch"
183183
// CHECK-TU-WITH-COMMON-NEXT: ],
184184
// CHECK-TU-WITH-COMMON-NEXT: "input-file": "[[PREFIX]]/tu_with_common.c"
185185
// CHECK-TU-WITH-COMMON-NEXT: }

clang/test/Index/cindex-from-source.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// REQUIRES: native
2-
// RUN: c-index-test -write-pch %t.pfx.h.gch -x objective-c-header %S/Inputs/cindex-from-source.h
2+
// RUN: c-index-test -write-pch %t.pfx.h.pch -x objective-c-header %S/Inputs/cindex-from-source.h
33
// RUN: c-index-test -test-load-source local %s -include %t.pfx.h > %t
44
// RUN: FileCheck %s < %t
55
// CHECK: cindex-from-source.m:{{.*}}:{{.*}}: StructDecl=s0:{{.*}}:{{.*}}

clang/test/PCH/pch-dir.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ int FOO;
2828

2929
int get(void) {
3030
#ifdef __cplusplus
31+
// CHECK-CPP: warning: '-include {{.*}}.h' probing .gch is deprecated. Use '-include-pch {{.*}}.h.gch' or switch to .pch instead
3132
// CHECK-CPP: .h.gch{{[/\\]}}cpp.gch
3233
return i;
3334
#else
35+
// CHECK-C: warning: '-include {{.*}}.h' probing .gch is deprecated. Use '-include-pch {{.*}}.h.gch' or switch to .pch instead
3436
// CHECK-C: .h.gch{{[/\\]}}c.gch
3537
return j;
3638
#endif

clang/test/SemaCXX/warn-unused-local-typedef-serialize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang -x c++-header -c -Wunused-local-typedef %s -o %t.gch -Werror
1+
// RUN: %clang -x c++-header -c -Wunused-local-typedef %s -o %t.pch -Werror
22
// RUN: %clang -DBE_THE_SOURCE -c -Wunused-local-typedef -include %t %s -o /dev/null 2>&1 | FileCheck %s
33
// RUN: %clang -DBE_THE_SOURCE -c -Wunused-local-typedef -include %t %s -o /dev/null 2>&1 | FileCheck %s
44

0 commit comments

Comments
 (0)