`-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
109 lines
4.3 KiB
C
109 lines
4.3 KiB
C
// Unsupported on AIX because we don't support the requisite "__clangast"
|
|
// section in XCOFF yet.
|
|
// UNSUPPORTED: target={{.*}}-aix{{.*}}
|
|
|
|
// Check that when depending on a precompiled module, we depend on the
|
|
// **top-level** module. Submodules don't have some information present (for
|
|
// example the path to the modulemap file) and depending on them might cause
|
|
// problems in the dependency scanner (e.g. generating empty `-fmodule-map-file=`
|
|
// arguments).
|
|
|
|
// RUN: rm -rf %t && mkdir %t
|
|
// RUN: cp %S/Inputs/modules-pch-common-submodule/* %t
|
|
|
|
// Scan dependencies of the PCH:
|
|
//
|
|
// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch-common-submodule/cdb_pch.json > %t/cdb.json
|
|
// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
|
|
// RUN: -module-files-dir %t/build > %t/result_pch.json
|
|
// RUN: cat %t/result_pch.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t -check-prefix=CHECK-PCH
|
|
//
|
|
// CHECK-PCH: {
|
|
// CHECK-PCH-NEXT: "modules": [
|
|
// CHECK-PCH-NEXT: {
|
|
// CHECK-PCH-NEXT: "clang-module-deps": [],
|
|
// CHECK-PCH-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
|
|
// CHECK-PCH-NEXT: "command-line": [
|
|
// CHECK-PCH: ],
|
|
// CHECK-PCH-NEXT: "context-hash": "[[HASH_MOD_COMMON:.*]]",
|
|
// CHECK-PCH-NEXT: "file-deps": [
|
|
// CHECK-PCH-NEXT: "[[PREFIX]]/mod_common.h",
|
|
// CHECK-PCH-NEXT: "[[PREFIX]]/mod_common_sub.h",
|
|
// CHECK-PCH-NEXT: "[[PREFIX]]/module.modulemap"
|
|
// CHECK-PCH-NEXT: ],
|
|
// CHECK-PCH-NEXT: "name": "ModCommon"
|
|
// CHECK-PCH-NEXT: }
|
|
// CHECK-PCH-NEXT: ],
|
|
// CHECK-PCH-NEXT: "translation-units": [
|
|
// CHECK-PCH-NEXT: {
|
|
// CHECK-PCH: "clang-context-hash": "[[HASH_PCH:.*]]",
|
|
// CHECK-PCH-NEXT: "clang-module-deps": [
|
|
// CHECK-PCH-NEXT: {
|
|
// CHECK-PCH-NEXT: "context-hash": "[[HASH_MOD_COMMON]]",
|
|
// CHECK-PCH-NEXT: "module-name": "ModCommon"
|
|
// CHECK-PCH-NEXT: }
|
|
// CHECK-PCH-NEXT: ],
|
|
// CHECK-PCH-NEXT: "command-line": [
|
|
// CHECK-PCH: ],
|
|
// CHECK-PCH: "file-deps": [
|
|
// CHECK-PCH-NEXT: "[[PREFIX]]/pch.h"
|
|
// CHECK-PCH-NEXT: ],
|
|
// CHECK-PCH-NEXT: "input-file": "[[PREFIX]]/pch.h"
|
|
// CHECK-PCH-NEXT: }
|
|
|
|
// Explicitly build the PCH:
|
|
//
|
|
// RUN: %deps-to-rsp %t/result_pch.json --module-name=ModCommon > %t/mod_common.cc1.rsp
|
|
// RUN: %deps-to-rsp %t/result_pch.json --tu-index=0 > %t/pch.rsp
|
|
//
|
|
// RUN: %clang @%t/mod_common.cc1.rsp
|
|
// RUN: %clang @%t/pch.rsp
|
|
|
|
// Scan dependencies of the TU:
|
|
//
|
|
// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-pch-common-submodule/cdb_tu.json > %t/cdb.json
|
|
// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
|
|
// RUN: -module-files-dir %t/build > %t/result_tu.json
|
|
// RUN: cat %t/result_tu.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t -check-prefix=CHECK-TU
|
|
//
|
|
// CHECK-TU: {
|
|
// CHECK-TU-NEXT: "modules": [
|
|
// CHECK-TU-NEXT: {
|
|
// CHECK-TU-NEXT: "clang-module-deps": [],
|
|
// CHECK-TU-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
|
|
// CHECK-TU-NEXT: "command-line": [
|
|
// CHECK-TU: ],
|
|
// CHECK-TU-NEXT: "context-hash": "[[HASH_MOD_TU:.*]]",
|
|
// CHECK-TU-NEXT: "file-deps": [
|
|
// CHECK-TU-NEXT: "[[PREFIX]]/mod_tu.h",
|
|
// CHECK-TU-NEXT: "[[PREFIX]]/module.modulemap"
|
|
// CHECK-TU-NEXT: ],
|
|
// CHECK-TU-NEXT: "name": "ModTU"
|
|
// CHECK-TU-NEXT: }
|
|
// CHECK-TU-NEXT: ],
|
|
// CHECK-TU-NEXT: "translation-units": [
|
|
// CHECK-TU-NEXT: {
|
|
// CHECK-TU: "clang-context-hash": "[[HASH_TU:.*]]",
|
|
// CHECK-TU-NEXT: "clang-module-deps": [
|
|
// CHECK-TU-NEXT: {
|
|
// CHECK-TU-NEXT: "context-hash": "[[HASH_MOD_TU]]"
|
|
// CHECK-TU-NEXT: "module-name": "ModTU"
|
|
// CHECK-TU-NEXT: }
|
|
// CHECK-TU-NEXT: ],
|
|
// CHECK-TU-NEXT: "command-line": [
|
|
// CHECK-TU: ],
|
|
// CHECK-TU: "file-deps": [
|
|
// CHECK-TU-NEXT: "[[PREFIX]]/tu.c",
|
|
// CHECK-TU-NEXT: "[[PREFIX]]/pch.h.pch"
|
|
// CHECK-TU-NEXT: ],
|
|
// CHECK-TU-NEXT: "input-file": "[[PREFIX]]/tu.c"
|
|
// CHECK-TU-NEXT: }
|
|
|
|
// Explicitly build the TU:
|
|
//
|
|
// RUN: %deps-to-rsp %t/result_tu.json --module-name=ModTU > %t/mod_tu.cc1.rsp
|
|
// RUN: %deps-to-rsp %t/result_tu.json --tu-index=0 > %t/tu.rsp
|
|
//
|
|
// RUN: %clang @%t/mod_tu.cc1.rsp
|
|
// RUN: %clang @%t/tu.rsp
|