blob: 9d1a2bb6801f7c2ece6db0af548f5255e74694d0 [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.
Richard Smith8128f332017-05-05 22:18:51 +000017// 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
18// 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
19
Richard Smith4a3751f2017-05-08 20:30:47 +000020// Check that we can load the original module map in the same compilation (this
21// could happen if we had a redundant -fmodule-map-file= in the original
22// build).
23// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -fmodule-map-file=%S/Inputs/preprocess/module.modulemap -x c++-module-map-cpp-output %t/rewrite.ii -emit-module -o /dev/null
24
Richard Smith8128f332017-05-05 22:18:51 +000025// Check the module we built works.
Richard Smith54f04402017-05-18 02:29:20 +000026// RUN: %clang_cc1 -fmodules -fmodule-file=%t/no-rewrite.pcm %s -I%t -verify -fno-modules-error-recovery
27// RUN: %clang_cc1 -fmodules -fmodule-file=%t/rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DREWRITE
Richard Smith8b706102017-05-31 20:56:55 +000028// RUN: %clang_cc1 -fmodules -fmodule-file=%t/no-rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DINCLUDE -I%S/Inputs/preprocess
29// RUN: %clang_cc1 -fmodules -fmodule-file=%t/rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DREWRITE -DINCLUDE -I%S/Inputs/preprocess
Richard Smith8128f332017-05-05 22:18:51 +000030
31
32// == module map
33// CHECK: # 1 "{{.*}}module.modulemap"
34// CHECK: module file {
35// CHECK: header "file.h"
36// CHECK: header "file2.h"
37// CHECK: }
Richard Smithd1386302017-05-04 00:29:54 +000038
39// == file.h
Richard Smithf74d9462017-04-28 01:49:42 +000040// CHECK: # 1 "<module-includes>"
Richard Smithd1386302017-05-04 00:29:54 +000041// REWRITE: #if 0
42// REWRITE: #include "file.h"
43// REWRITE: #endif
44//
45// FIXME: It would be preferable to consistently put the module begin/end in
46// the same file, but the relative ordering of PP callbacks and module
47// begin/end tokens makes that difficult.
48//
49// REWRITE: #pragma clang module begin file
Richard Smithf74d9462017-04-28 01:49:42 +000050// CHECK: # 1 "{{.*}}file.h" 1
Richard Smithd1386302017-05-04 00:29:54 +000051// NO-REWRITE: #pragma clang module begin file
52// NO-REWRITE: # 1 "{{.*}}file.h"{{$}}
53//
Richard Smithf74d9462017-04-28 01:49:42 +000054// CHECK: struct __FILE;
Richard Smithd1386302017-05-04 00:29:54 +000055// CHECK: #pragma clang module import fwd /* clang {{-E|-frewrite-includes}}: implicit import
Richard Smithf74d9462017-04-28 01:49:42 +000056// CHECK: typedef struct __FILE FILE;
Richard Smithd1386302017-05-04 00:29:54 +000057//
58// REWRITE: #pragma clang module end
Richard Smithf74d9462017-04-28 01:49:42 +000059// CHECK: # 2 "<module-includes>" 2
Richard Smithd1386302017-05-04 00:29:54 +000060// NO-REWRITE: #pragma clang module end
61
62// == file2.h
63// REWRITE: #if 0
64// REWRITE: #include "file2.h"
65// REWRITE: #endif
66//
67// REWRITE: #pragma clang module begin file
68// CHECK: # 1 "{{.*}}file2.h" 1
69// NO-REWRITE: #pragma clang module begin file
70//
71// ==== recursively re-enter file.h
72// REWRITE: #if 0
73// REWRITE: #include "file.h"
74// REWRITE: #endif
75//
76// REWRITE: #pragma clang module begin file
77// CHECK: # 1 "{{.*}}file.h" 1
78// NO-REWRITE: #pragma clang module begin file
79// NO-REWRITE: # 1 "{{.*}}file.h"{{$}}
80//
81// CHECK: struct __FILE;
82// CHECK: #pragma clang module import fwd /* clang {{-E|-frewrite-includes}}: implicit import
83// CHECK: typedef struct __FILE FILE;
84//
85// REWRITE: #pragma clang module end
86// CHECK: # 2 "{{.*}}file2.h" 2
87// NO-REWRITE: #pragma clang module end
88// NO-REWRITE: # 2 "{{.*}}file2.h"{{$}}
89// ==== return to file2.h
90//
91// CHECK: extern int file2;
92//
93// REWRITE: #pragma clang module end
94// CHECK: # 3 "<module-includes>" 2
95// NO-REWRITE: #pragma clang module end
Richard Smith8128f332017-05-05 22:18:51 +000096
97
Richard Smith54f04402017-05-18 02:29:20 +000098__FILE *a; // expected-error {{declaration of '__FILE' must be imported}}
99#ifdef REWRITE
100// expected-note@rewrite.ii:1 {{here}}
101#else
102// expected-note@no-rewrite.ii:1 {{here}}
103#endif
Richard Smith8128f332017-05-05 22:18:51 +0000104
Richard Smith8b706102017-05-31 20:56:55 +0000105#ifdef INCLUDE
106#include "file.h"
107#else
Richard Smith8128f332017-05-05 22:18:51 +0000108#pragma clang module import file
Richard Smith8b706102017-05-31 20:56:55 +0000109#endif
Richard Smith8128f332017-05-05 22:18:51 +0000110
111FILE *b;
Richard Smith8b706102017-05-31 20:56:55 +0000112int x = file2; // ok, found in file2.h, even under -DINCLUDE