1 // RUN: rm -rf %t
2 // RUN: mkdir %t
3 
4 // RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fmodule-name=nested -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -E -o %t/no-rewrite.ii
5 // RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fmodule-name=nested -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -E -frewrite-includes -o %t/rewrite.ii
6 
7 // RUN: FileCheck %s --input-file %t/no-rewrite.ii --check-prefix=CHECK --check-prefix=NO-REWRITE
8 // RUN: FileCheck %s --input-file %t/rewrite.ii    --check-prefix=CHECK --check-prefix=REWRITE
9 
10 // Check that we can build a module from the preprocessed output.
11 // FIXME: For now, the files need to exist.
12 // RUN: touch %t/a.h %t/b.h %t/c.h
13 // RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fmodule-name=nested -x c++-module-map-cpp-output %t/no-rewrite.ii -emit-module -o %t/no-rewrite.pcm
14 // RUN: %clang_cc1 -fmodules -fmodules-local-submodule-visibility -fmodule-name=nested -x c++-module-map-cpp-output %t/rewrite.ii -emit-module -o %t/rewrite.pcm
15 
16 // Check the module we built works.
17 // RUN: %clang_cc1 -fmodules -fmodule-file=%t/no-rewrite.pcm %s -I%t -verify -fno-modules-error-recovery
18 // RUN: %clang_cc1 -fmodules -fmodule-file=%t/rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DREWRITE
19 
20 // == module map
21 // CHECK: # 1 "{{.*}}module.modulemap"
22 // CHECK: module nested {
23 // CHECK:   module a {
24 // CHECK:     header "a.h"
25 // CHECK:   }
26 // CHECK:   module b {
27 // CHECK:     header "b.h"
28 // CHECK:   }
29 // CHECK:   module c {
30 // CHECK:     header "c.h"
31 // CHECK:   }
32 // CHECK: }
33 
34 // CHECK: #pragma clang module begin nested.a
35 // CHECK: #pragma clang module begin nested.c
36 // CHECK: using T = int;
37 // CHECK: #pragma clang module end
38 // CHECK: T a();
39 // CHECK: #pragma clang module end
40 
41 // CHECK: #pragma clang module begin nested.b
42 // CHECK: #pragma clang module import nested.c
43 // CHECK-NOT: #pragma clang module begin nested.c
44 // CHECK-NOT: using T = int;
45 // CHECK-NOT: #pragma clang module end
46 // CHECK: T b();
47 // CHECK: #pragma clang module end
48 
49 // CHECK: #pragma clang module import nested.c
50 
51 #pragma clang module import nested.b
52 
53 int n = b();
54 T c; // expected-error {{must be imported}}
55 #ifdef REWRITE
56 // [email protected]:* {{declar}}
57 #else
58 // [email protected]:* {{declar}}
59 #endif
60