xref: /llvm-project/clang/test/ClangScanDeps/Wsystem-headers-in-module.c (revision dc5cbba3196db61d57b7d84118732a6c96d8ee64)
1 // Check that Wsystem-headers-in-module shows diagnostics in the named system
2 // module, but not in other system headers or modules when built with explicit
3 // modules.
4 
5 // RUN: rm -rf %t
6 // RUN: split-file %s %t
7 // RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
8 
9 // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/deps.json
10 
11 // RUN: %deps-to-rsp %t/deps.json --module-name=dependent_sys_mod > %t/dependent_sys_mod.rsp
12 // RUN: %deps-to-rsp %t/deps.json --module-name=sys_mod > %t/sys_mod.rsp
13 // RUN: %deps-to-rsp %t/deps.json --module-name=other_sys_mod > %t/other_sys_mod.rsp
14 // RUN: %deps-to-rsp %t/deps.json --tu-index 0 > %t/tu.rsp
15 
16 // RUN: %clang @%t/dependent_sys_mod.rsp -verify
17 // RUN: %clang @%t/sys_mod.rsp -verify
18 // RUN: %clang @%t/other_sys_mod.rsp -verify
19 // RUN: %clang @%t/tu.rsp -verify
20 
21 // CHECK-NOT: warning:
22 // CHECK: sys_mod.h:2:7: warning: extra ';'
23 // CHECK-NOT: warning:
24 
25 //--- cdb.json.template
26 [{
27   "directory": "DIR",
28   "command": "clang -fsyntax-only -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/mcp DIR/tu.c -isystem DIR/sys -Wextra-semi -Wsystem-headers-in-module=sys_mod",
29   "file": "DIR/tu.c"
30 }]
31 
32 //--- sys/other_sys_header.h
33 int x;;
34 
35 //--- sys_mod.h
36 #include "dependent_sys_mod.h"
37 int y;; // expected-warning {{extra ';' outside of a function}}
38 
39 //--- other_sys_mod.h
40 int z;;
41 // expected-no-diagnostics
42 
43 //--- dependent_sys_mod.h
44 int w;;
45 // expected-no-diagnostics
46 
47 //--- module.modulemap
48 module sys_mod [system] { header "sys_mod.h" }
49 module other_sys_mod [system] { header "other_sys_mod.h" }
50 module dependent_sys_mod [system] { header "dependent_sys_mod.h" }
51 
52 //--- tu.c
53 #include "sys_mod.h"
54 #include "other_sys_mod.h"
55 #include "other_sys_header.h"
56 // expected-no-diagnostics
57