blob: a3b7892383882a81b91f28bb2b0fc310ab0cfa5e [file] [log] [blame]
Richard Smithf74d9462017-04-28 01:49:42 +00001// RUN: rm -rf %t
Richard Smith8128f332017-05-05 22:18:51 +00002// RUN: mkdir %t
Richard Smithf74d9462017-04-28 01:49:42 +00003
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
Richard Smith8128f332017-05-05 22:18:51 +00007// 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: }
Richard Smithd1386302017-05-04 00:29:54 +000033
34// == file.h
Richard Smithf74d9462017-04-28 01:49:42 +000035// CHECK: # 1 "<module-includes>"
Richard Smithd1386302017-05-04 00:29:54 +000036// 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
Richard Smithf74d9462017-04-28 01:49:42 +000045// CHECK: # 1 "{{.*}}file.h" 1
Richard Smithd1386302017-05-04 00:29:54 +000046// NO-REWRITE: #pragma clang module begin file
47// NO-REWRITE: # 1 "{{.*}}file.h"{{$}}
48//
Richard Smithf74d9462017-04-28 01:49:42 +000049// CHECK: struct __FILE;
Richard Smithd1386302017-05-04 00:29:54 +000050// CHECK: #pragma clang module import fwd /* clang {{-E|-frewrite-includes}}: implicit import
Richard Smithf74d9462017-04-28 01:49:42 +000051// CHECK: typedef struct __FILE FILE;
Richard Smithd1386302017-05-04 00:29:54 +000052//
53// REWRITE: #pragma clang module end
Richard Smithf74d9462017-04-28 01:49:42 +000054// CHECK: # 2 "<module-includes>" 2
Richard Smithd1386302017-05-04 00:29:54 +000055// 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
Richard Smith8128f332017-05-05 22:18:51 +000091
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
100FILE *b;
101int x = file2;