Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / ClangScanDeps / modules-context-hash.c
blob3108c924b0721f5017683ce7aefdb1dbec853529
1 // RUN: rm -rf %t && mkdir %t
2 // RUN: cp -r %S/Inputs/modules-context-hash/* %t
4 // Check that the scanner reports the same module as distinct dependencies when
5 // a single translation unit gets compiled with multiple command-lines that
6 // produce different **strict** context hashes.
8 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-context-hash/cdb_a.json.template > %t/cdb_a.json
9 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-context-hash/cdb_b.json.template > %t/cdb_b.json
10 // RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-context-hash/cdb_b2.json.template > %t/cdb_b2.json
12 // We run separate scans. The context hash for "a" and "b" can differ between
13 // systems. If we'd scan both Clang invocations in a single run, the order of JSON
14 // entities would be non-deterministic. To prevent this, run the scans separately
15 // and verify that the context hashes differ with a single FileCheck invocation.
17 // RUN: clang-scan-deps -compilation-database %t/cdb_a.json -format experimental-full -j 1 > %t/result_a.json
18 // RUN: clang-scan-deps -compilation-database %t/cdb_b.json -format experimental-full -j 1 > %t/result_b.json
19 // RUN: clang-scan-deps -compilation-database %t/cdb_b2.json -format experimental-full -j 1 > %t/result_b2.json
20 // RUN: cat %t/result_a.json %t/result_b.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t -check-prefix=CHECK
21 // RUN: cat %t/result_b.json %t/result_b2.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t -check-prefix=FLAG_ONLY
23 // CHECK: {
24 // CHECK-NEXT: "modules": [
25 // CHECK-NEXT: {
26 // CHECK-NEXT: "clang-module-deps": [],
27 // CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
28 // CHECK-NEXT: "command-line": [
29 // CHECK-NEXT: "-cc1"
30 // CHECK: "-emit-module"
31 // CHECK: "-I"
32 // CHECK: "[[PREFIX]]/a"
33 // CHECK: "-fmodule-name=mod"
34 // CHECK: ],
35 // CHECK-NEXT: "context-hash": "[[HASH_MOD_A:.*]]",
36 // CHECK-NEXT: "file-deps": [
37 // CHECK-NEXT: "[[PREFIX]]/a/dep.h",
38 // CHECK-NEXT: "[[PREFIX]]/mod.h",
39 // CHECK-NEXT: "[[PREFIX]]/module.modulemap"
40 // CHECK-NEXT: ],
41 // CHECK-NEXT: "name": "mod"
42 // CHECK-NEXT: }
43 // CHECK-NEXT: ],
44 // CHECK-NEXT: "translation-units": [
45 // CHECK-NEXT: {
46 // CHECK: "clang-context-hash": "{{.*}}",
47 // CHECK-NEXT: "clang-module-deps": [
48 // CHECK-NEXT: {
49 // CHECK-NEXT: "context-hash": "[[HASH_MOD_A]]",
50 // CHECK-NEXT: "module-name": "mod"
51 // CHECK-NEXT: }
52 // CHECK-NEXT: ],
53 // CHECK-NEXT: "command-line": [
54 // CHECK: ],
55 // CHECK: "file-deps": [
56 // CHECK-NEXT: "[[PREFIX]]/tu.c"
57 // CHECK-NEXT: ],
58 // CHECK-NEXT: "input-file": "[[PREFIX]]/tu.c"
59 // CHECK-NEXT: }
61 // CHECK: "modules": [
62 // CHECK-NEXT: {
63 // CHECK-NEXT: "clang-module-deps": [],
64 // CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
65 // CHECK-NEXT: "command-line": [
66 // CHECK-NEXT: "-cc1"
67 // CHECK: "-emit-module"
68 // CHECK: "-I"
69 // CHECK: "[[PREFIX]]/b"
70 // CHECK: "-fmodule-name=mod"
71 // CHECK: ],
72 // CHECK-NOT: "context-hash": "[[HASH_MOD_A]]",
73 // CHECK: "file-deps": [
74 // CHECK-NEXT: "[[PREFIX]]/b/dep.h",
75 // CHECK-NEXT: "[[PREFIX]]/mod.h",
76 // CHECK-NEXT: "[[PREFIX]]/module.modulemap"
77 // CHECK-NEXT: ],
78 // CHECK-NEXT: "name": "mod"
79 // CHECK-NEXT: }
80 // CHECK-NEXT: ],
81 // CHECK-NEXT: "translation-units": [
82 // CHECK-NEXT: {
83 // CHECK: "clang-context-hash": "{{.*}}",
84 // CHECK-NEXT: "clang-module-deps": [
85 // CHECK-NEXT: {
86 // CHECK-NOT: "context-hash": "[[HASH_MOD_A]]",
87 // CHECK: "module-name": "mod"
88 // CHECK-NEXT: }
89 // CHECK-NEXT: ],
90 // CHECK-NEXT: "command-line": [
91 // CHECK: ],
92 // CHECK: "file-deps": [
93 // CHECK-NEXT: "[[PREFIX]]/tu.c"
94 // CHECK-NEXT: ],
95 // CHECK-NEXT: "input-file": "[[PREFIX]]/tu.c"
96 // CHECK-NEXT: }
98 // B and B2 only differ by -fapplication-extension
100 // FLAG_ONLY: "modules": [
101 // FLAG_ONLY-NEXT: {
102 // FLAG_ONLY: "context-hash": "[[HASH_MOD_B1:.*]]"
103 // FLAG_ONLY-NOT: "-fapplication-extension"
105 // FLAG_ONLY: "modules": [
106 // FLAG_ONLY-NEXT: {
107 // FLAG_ONLY-NOT: "context-hash": "[[HASH_MOD_B1]]"
108 // FLAG_ONLY: "-fapplication-extension"
109 // FLAG_ONLY: "translation-units": [
110 // FLAG_ONLY-NOT: "context-hash": "[[HASH_MOD_B1]]"