xref: /llvm-project/clang/test/ClangScanDeps/removed-args.c (revision 9d4837f47c48c634d4a0ac799188e1f5332495ef)
1 // Some command-line arguments used for compiling translation units are not
2 // compatible with the semantics of modules or are likely to differ between
3 // identical modules discovered from different translation units. This test
4 // checks such arguments are removed from the command-lines: '-include',
5 // '-dwarf-debug-flag' and '-main-file-name'. Similarly, several arguments
6 // such as '-fmodules-cache-path=' are only relevant for implicit modules, and
7 // are removed to better-canonicalize the compilation.
8 
9 // RUN: rm -rf %t && mkdir %t
10 // RUN: cp %S/Inputs/removed-args/* %t
11 // RUN: touch %t/build-session
12 // RUN: touch %t/tu.proftext
13 // RUN: llvm-profdata merge %t/tu.proftext -o %t/tu.profdata
14 
15 // RUN: sed "s|DIR|%/t|g" %S/Inputs/removed-args/cdb.json.template > %t/cdb.json
16 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/result.json
17 // RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t
18 //
19 // CHECK:      {
20 // CHECK-NEXT:   "modules": [
21 // CHECK-NEXT:     {
22 // CHECK-NEXT:       "clang-module-deps": [],
23 // CHECK-NEXT:       "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
24 // CHECK-NEXT:       "command-line": [
25 // CHECK-NEXT:         "-cc1"
26 // CHECK-NOT:          "-fdebug-compilation-dir="
27 // CHECK-NOT:          "-fcoverage-compilation-dir="
28 // CHECK-NOT:          "-coverage-notes-file
29 // CHECK-NOT:          "-coverage-data-file
30 // CHECK-NOT:          "-fprofile-instrument-use-path
31 // CHECK-NOT:          "-dwarf-debug-flags"
32 // CHECK-NOT:          "-main-file-name"
33 // CHECK-NOT:          "-include"
34 // CHECK-NOT:          "-fmodules-cache-path=
35 // CHECK-NOT:          "-fmodules-validate-once-per-build-session"
36 // CHECK-NOT:          "-fbuild-session-timestamp=
37 // CHECK-NOT:          "-fmodules-prune-interval=
38 // CHECK-NOT:          "-fmodules-prune-after=
39 // CHECK:            ],
40 // CHECK-NEXT:       "context-hash": "[[HASH_MOD_HEADER:.*]]",
41 // CHECK-NEXT:       "file-deps": [
42 // CHECK-NEXT:         "[[PREFIX]]/module.modulemap",
43 // CHECK-NEXT:         "[[PREFIX]]/mod_header.h"
44 // CHECK-NEXT:       ],
45 // CHECK-NEXT:       "link-libraries": [],
46 // CHECK-NEXT:       "name": "ModHeader"
47 // CHECK-NEXT:     },
48 // CHECK-NEXT:     {
49 // CHECK-NEXT:       "clang-module-deps": [],
50 // CHECK-NEXT:       "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
51 // CHECK-NEXT:       "command-line": [
52 // CHECK-NEXT:         "-cc1"
53 // CHECK-NOT:          "-fdebug-compilation-dir=
54 // CHECK-NOT:          "-fcoverage-compilation-dir=
55 // CHECK-NOT:          "-coverage-notes-file
56 // CHECK-NOT:          "-coverage-data-file
57 // CHECK-NOT:          "-fprofile-instrument-use-path
58 // CHECK-NOT:          "-dwarf-debug-flags"
59 // CHECK-NOT:          "-main-file-name"
60 // CHECK-NOT:          "-include"
61 // CHECK-NOT:          "-fmodules-cache-path=
62 // CHECK-NOT:          "-fmodules-validate-once-per-build-session"
63 // CHECK-NOT:          "-fbuild-session-timestamp=
64 // CHECK-NOT:          "-fmodules-prune-interval=
65 // CHECK-NOT:          "-fmodules-prune-after=
66 // CHECK:            ],
67 // CHECK-NEXT:       "context-hash": "[[HASH_MOD_TU:.*]]",
68 // CHECK-NEXT:       "file-deps": [
69 // CHECK-NEXT:         "[[PREFIX]]/module.modulemap",
70 // CHECK-NEXT:         "[[PREFIX]]/mod_tu.h"
71 // CHECK-NEXT:       ],
72 // CHECK-NEXT:       "link-libraries": [],
73 // CHECK-NEXT:       "name": "ModTU"
74 // CHECK-NEXT:     }
75 // CHECK-NEXT:   ],
76 // CHECK-NEXT:   "translation-units": [
77 // CHECK-NEXT:     {
78 // CHECK:            "clang-context-hash": "[[HASH_TU:.*]]",
79 // CHECK-NEXT:       "clang-module-deps": [
80 // CHECK-NEXT:         {
81 // CHECK-NEXT:           "context-hash": "[[HASH_MOD_HEADER]]",
82 // CHECK-NEXT:           "module-name": "ModHeader"
83 // CHECK-NEXT:         },
84 // CHECK-NEXT:         {
85 // CHECK-NEXT:           "context-hash": "[[HASH_MOD_TU]]",
86 // CHECK-NEXT:           "module-name": "ModTU"
87 // CHECK-NEXT:         }
88 // CHECK-NEXT:       ]
89 // CHECK-NEXT:       "command-line": [
90 // CHECK-NEXT:         "-cc1",
91 // CHECK-NOT:          "-fmodules-cache-path=
92 // CHECK-NOT:          "-fmodules-validate-once-per-build-session"
93 // CHECK-NOT:          "-fbuild-session-timestamp=
94 // CHECK-NOT:          "-fbuild-session-file=
95 // CHECK-NOT:          "-fmodules-prune-interval=
96 // CHECK-NOT:          "-fmodules-prune-after=
97 // CHECK:            ],
98 
99 // Check for removed args for PCH invocations.
100 
101 // RUN: split-file %s %t
102 // RUN: sed "s|DIR|%/t|g" %t/cdb-pch.json.template > %t/cdb-pch.json
103 // RUN: clang-scan-deps -compilation-database %t/cdb-pch.json -format experimental-full > %t/result-pch.json
104 // RUN: cat %t/result-pch.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t -check-prefix=PCH
105 //
106 // PCH-NOT:          "-fdebug-compilation-dir="
107 // PCH-NOT:          "-fcoverage-compilation-dir="
108 // PCH-NOT:          "-coverage-notes-file
109 // PCH-NOT:          "-coverage-data-file
110 // PCH-NOT:          "-fprofile-instrument-use-path
111 // PCH-NOT:          "-include"
112 // PCH-NOT:          "-fmodules-cache-path=
113 // PCH-NOT:          "-fmodules-validate-once-per-build-session"
114 // PCH-NOT:          "-fbuild-session-timestamp=
115 // PCH-NOT:          "-fmodules-prune-interval=
116 // PCH-NOT:          "-fmodules-prune-after=
117 
118 //--- cdb-pch.json.template
119 [
120   {
121     "directory": "DIR",
122     "command": "clang -x c-header DIR/header.h -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -fdebug-compilation-dir=DIR/debug -fcoverage-compilation-dir=DIR/coverage -ftest-coverage -fprofile-instr-use=DIR/tu.profdata -o DIR/header.h.pch -serialize-diagnostics DIR/header.h.pch.diag ",
123     "file": "DIR/header.h.pch"
124   }
125 ]
126