1 // RUN: rm -rf %t
2 // RUN: mkdir %t
3 
4 // RUN: not %clang_cc1 -fmodules -fmodule-name=file -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -E 2>&1 | FileCheck %s --check-prefix=MISSING-FWD
5 // MISSING-FWD: module 'fwd' is needed
6 
7 // RUN: %clang_cc1 -fmodules -fmodule-name=fwd -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -emit-module -o %t/fwd.pcm
8 
9 // Check that we can preprocess modules, and get the expected output.
10 // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -E -o %t/no-rewrite.ii
11 // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -E -frewrite-includes -o %t/rewrite.ii
12 //
13 // RUN: FileCheck %s --input-file %t/no-rewrite.ii --check-prefix=CHECK --check-prefix=NO-REWRITE
14 // RUN: FileCheck %s --input-file %t/rewrite.ii    --check-prefix=CHECK --check-prefix=REWRITE
15 
16 // Check that we can build a module from the preprocessed output.
17 // FIXME: For now, we need the headers to exist.
18 // RUN: touch %t/file.h %t/file2.h
19 // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/no-rewrite.ii -emit-module -o %t/no-rewrite.pcm
20 // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/rewrite.ii -emit-module -o %t/rewrite.pcm
21 
22 // Check the module we built works.
23 // RUN: %clang_cc1 -fmodules -fmodule-file=%t/no-rewrite.pcm %s -verify
24 // RUN: %clang_cc1 -fmodules -fmodule-file=%t/rewrite.pcm %s -verify
25 
26 
27 // == module map
28 // CHECK: # 1 "{{.*}}module.modulemap"
29 // CHECK: module file {
30 // CHECK:   header "file.h"
31 // CHECK:   header "file2.h"
32 // CHECK: }
33 
34 // == file.h
35 // CHECK: # 1 "<module-includes>"
36 // REWRITE: #if 0
37 // REWRITE: #include "file.h"
38 // REWRITE: #endif
39 //
40 // FIXME: It would be preferable to consistently put the module begin/end in
41 // the same file, but the relative ordering of PP callbacks and module
42 // begin/end tokens makes that difficult.
43 //
44 // REWRITE: #pragma clang module begin file
45 // CHECK: # 1 "{{.*}}file.h" 1
46 // NO-REWRITE: #pragma clang module begin file
47 // NO-REWRITE: # 1 "{{.*}}file.h"{{$}}
48 //
49 // CHECK: struct __FILE;
50 // CHECK: #pragma clang module import fwd /* clang {{-E|-frewrite-includes}}: implicit import
51 // CHECK: typedef struct __FILE FILE;
52 //
53 // REWRITE: #pragma clang module end
54 // CHECK: # 2 "<module-includes>" 2
55 // NO-REWRITE: #pragma clang module end
56 
57 // == file2.h
58 // REWRITE: #if 0
59 // REWRITE: #include "file2.h"
60 // REWRITE: #endif
61 //
62 // REWRITE: #pragma clang module begin file
63 // CHECK: # 1 "{{.*}}file2.h" 1
64 // NO-REWRITE: #pragma clang module begin file
65 //
66 // ==== recursively re-enter file.h
67 // REWRITE: #if 0
68 // REWRITE: #include "file.h"
69 // REWRITE: #endif
70 //
71 // REWRITE: #pragma clang module begin file
72 // CHECK: # 1 "{{.*}}file.h" 1
73 // NO-REWRITE: #pragma clang module begin file
74 // NO-REWRITE: # 1 "{{.*}}file.h"{{$}}
75 //
76 // CHECK: struct __FILE;
77 // CHECK: #pragma clang module import fwd /* clang {{-E|-frewrite-includes}}: implicit import
78 // CHECK: typedef struct __FILE FILE;
79 //
80 // REWRITE: #pragma clang module end
81 // CHECK: # 2 "{{.*}}file2.h" 2
82 // NO-REWRITE: #pragma clang module end
83 // NO-REWRITE: # 2 "{{.*}}file2.h"{{$}}
84 // ==== return to file2.h
85 //
86 // CHECK: extern int file2;
87 //
88 // REWRITE: #pragma clang module end
89 // CHECK: # 3 "<module-includes>" 2
90 // NO-REWRITE: #pragma clang module end
91 
92 
93 // expected-no-diagnostics
94 
95 // FIXME: This should be rejected: we have not imported the submodule defining it yet.
96 __FILE *a;
97 
98 #pragma clang module import file
99 
100 FILE *b;
101 int x = file2;
102