xref: /llvm-project/clang/test/ClangScanDeps/modules-no-undeclared-includes.c (revision 9d4837f47c48c634d4a0ac799188e1f5332495ef)
1d1873d39SJake Egan // Unsupported on AIX because we don't support the requisite "__clangast"
2d1873d39SJake Egan // section in XCOFF yet.
364e4d03cSPaul Robinson // UNSUPPORTED: target={{.*}}-aix{{.*}}
4d1873d39SJake Egan 
5a6ef3635SJan Svoboda // RUN: rm -rf %t && mkdir %t
6a6ef3635SJan Svoboda // RUN: split-file %s %t
7a6ef3635SJan Svoboda 
8a6ef3635SJan Svoboda //--- undeclared/module.modulemap
9a6ef3635SJan Svoboda module Undeclared { header "undeclared.h" }
10a6ef3635SJan Svoboda 
11a6ef3635SJan Svoboda //--- undeclared/undeclared.h
12a6ef3635SJan Svoboda 
13a6ef3635SJan Svoboda //--- module.modulemap
14a6ef3635SJan Svoboda module User [no_undeclared_includes] { header "user.h" }
15a6ef3635SJan Svoboda 
16a6ef3635SJan Svoboda //--- user.h
17a6ef3635SJan Svoboda #if __has_include("undeclared.h")
18a6ef3635SJan Svoboda #error Unreachable. Undeclared comes from a module that's not 'use'd, meaning the compiler should pretend it doesn't exist.
19a6ef3635SJan Svoboda #endif
20a6ef3635SJan Svoboda 
21a6ef3635SJan Svoboda //--- test.c
22a6ef3635SJan Svoboda #include "user.h"
23a6ef3635SJan Svoboda 
24a6ef3635SJan Svoboda //--- cdb.json.template
25a6ef3635SJan Svoboda [{
26a6ef3635SJan Svoboda   "directory": "DIR",
27a6ef3635SJan Svoboda   "command": "clang -fmodules -gmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -IDIR/undeclared -c DIR/test.c -o DIR/test.o",
28a6ef3635SJan Svoboda   "file": "DIR/test.c"
29a6ef3635SJan Svoboda }]
30a6ef3635SJan Svoboda 
31a6ef3635SJan Svoboda // RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
32a6ef3635SJan Svoboda // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full \
3371e32d5cSJan Svoboda // RUN:   -module-files-dir %t/build > %t/result.json
344d6835f9SJan Svoboda // RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck %s -DPREFIX=%/t
35a6ef3635SJan Svoboda 
36a6ef3635SJan Svoboda // CHECK:        {
37a6ef3635SJan Svoboda // CHECK-NEXT:   "modules": [
38a6ef3635SJan Svoboda // CHECK-NEXT:     {
39a6ef3635SJan Svoboda // CHECK-NEXT:       "clang-module-deps": [],
40a6ef3635SJan Svoboda // CHECK-NEXT:       "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
41a6ef3635SJan Svoboda // CHECK-NEXT:       "command-line": [
42a6ef3635SJan Svoboda // CHECK:              "-fmodule-map-file=[[PREFIX]]/undeclared/module.modulemap"
43a6ef3635SJan Svoboda // CHECK:            ],
44a6ef3635SJan Svoboda // CHECK-NEXT:       "context-hash": "{{.*}}",
45a6ef3635SJan Svoboda // CHECK-NEXT:       "file-deps": [
46a6ef3635SJan Svoboda // CHECK-NEXT:         "[[PREFIX]]/module.modulemap",
47*9d4837f4SJan Svoboda // CHECK-NEXT:         "[[PREFIX]]/user.h",
48*9d4837f4SJan Svoboda // CHECK-NEXT:         "[[PREFIX]]/undeclared/module.modulemap"
49a6ef3635SJan Svoboda // CHECK-NEXT:       ],
5068eb3b20SArtem Chikin // CHECK-NEXT:       "link-libraries": [],
51a6ef3635SJan Svoboda // CHECK-NEXT:       "name": "User"
52a6ef3635SJan Svoboda // CHECK-NEXT:     }
53a6ef3635SJan Svoboda // CHECK-NEXT:   ],
54a6ef3635SJan Svoboda // CHECK-NEXT:   "translation-units": [
55a6ef3635SJan Svoboda // CHECK-NEXT:     {
5683902c40SBen Langmuir // CHECK:            "clang-context-hash": "{{.*}}"
57a6ef3635SJan Svoboda // CHECK-NEXT:       "clang-module-deps": [
58a6ef3635SJan Svoboda // CHECK-NEXT:         {
59a6ef3635SJan Svoboda // CHECK-NEXT:           "context-hash": "{{.*}}"
60a6ef3635SJan Svoboda // CHECK-NEXT:           "module-name": "User"
61a6ef3635SJan Svoboda // CHECK-NEXT:         }
62a6ef3635SJan Svoboda // CHECK-NEXT:       ],
63a6ef3635SJan Svoboda // CHECK-NEXT:       "command-line": [
64a6ef3635SJan Svoboda // CHECK:            ],
6583902c40SBen Langmuir // CHECK:            "file-deps": [
66a6ef3635SJan Svoboda // CHECK-NEXT:         "[[PREFIX]]/test.c"
67a6ef3635SJan Svoboda // CHECK-NEXT:       ],
68a6ef3635SJan Svoboda // CHECK-NEXT:       "input-file": "[[PREFIX]]/test.c"
69a6ef3635SJan Svoboda // CHECK-NEXT:     }
70a6ef3635SJan Svoboda 
7126053ce0SJan Svoboda // RUN: %deps-to-rsp %t/result.json --module-name=User > %t/User.cc1.rsp
7226053ce0SJan Svoboda // RUN: %deps-to-rsp %t/result.json --tu-index=0 > %t/tu.rsp
73a6ef3635SJan Svoboda //
74a6ef3635SJan Svoboda // RUN: %clang @%t/User.cc1.rsp
75a6ef3635SJan Svoboda // RUN: %clang @%t/tu.rsp
76