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 // 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 20 // 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 25 // Check the module we built works. 26 // 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 28 // 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 30 31 // Now try building the module when the header files are missing. 32 // RUN: cp %S/Inputs/preprocess/fwd.h %S/Inputs/preprocess/file.h %S/Inputs/preprocess/file2.h %S/Inputs/preprocess/module.modulemap %t 33 // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -I%t -x c++-module-map %t/module.modulemap -E -frewrite-includes -o %t/copy.ii 34 // RUN: rm %t/fwd.h %t/file.h %t/file2.h %t/module.modulemap 35 // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/copy.ii -emit-module -o %t/copy.pcm 36 37 // Finally, check that our module contains correct mapping information for the headers. 38 // RUN: cp %S/Inputs/preprocess/fwd.h %S/Inputs/preprocess/file.h %S/Inputs/preprocess/file2.h %S/Inputs/preprocess/module.modulemap %t 39 // RUN: %clang_cc1 -fmodules -fmodule-file=%t/copy.pcm %s -I%t -verify -fno-modules-error-recovery -DCOPY -DINCLUDE 40 41 // == module map 42 // CHECK: # 1 "{{.*}}module.modulemap" 43 // CHECK: module file { 44 // CHECK: header "file.h" { size 45 // CHECK: header "file2.h" { size 46 // CHECK: } 47 48 // == file.h 49 // CHECK: # 1 "<module-includes>" 50 // REWRITE: #if 0 51 // REWRITE: #include "file.h" 52 // REWRITE: #endif 53 // 54 // FIXME: It would be preferable to consistently put the module begin/end in 55 // the same file, but the relative ordering of PP callbacks and module 56 // begin/end tokens makes that difficult. 57 // 58 // REWRITE: #pragma clang module begin file 59 // CHECK: # 1 "{{.*}}file.h" 1 60 // NO-REWRITE: #pragma clang module begin file 61 // NO-REWRITE: # 1 "{{.*}}file.h"{{$}} 62 // 63 // CHECK: struct __FILE; 64 // CHECK: #pragma clang module import fwd /* clang {{-E|-frewrite-includes}}: implicit import 65 // CHECK: typedef struct __FILE FILE; 66 // 67 // REWRITE: #pragma clang module end 68 // CHECK: # 2 "<module-includes>" 2 69 // NO-REWRITE: #pragma clang module end 70 71 // == file2.h 72 // REWRITE: #if 0 73 // REWRITE: #include "file2.h" 74 // REWRITE: #endif 75 // 76 // REWRITE: #pragma clang module begin file 77 // CHECK: # 1 "{{.*}}file2.h" 1 78 // NO-REWRITE: #pragma clang module begin file 79 // 80 // ==== recursively re-enter file.h 81 // REWRITE: #if 0 82 // REWRITE: #include "file.h" 83 // REWRITE: #endif 84 // 85 // REWRITE: #pragma clang module begin file 86 // CHECK: # 1 "{{.*}}file.h" 1 87 // NO-REWRITE: #pragma clang module begin file 88 // NO-REWRITE: # 1 "{{.*}}file.h"{{$}} 89 // 90 // CHECK: struct __FILE; 91 // CHECK: #pragma clang module import fwd /* clang {{-E|-frewrite-includes}}: implicit import 92 // CHECK: typedef struct __FILE FILE; 93 // 94 // REWRITE: #pragma clang module end 95 // CHECK: # 2 "{{.*}}file2.h" 2 96 // NO-REWRITE: #pragma clang module end 97 // NO-REWRITE: # 2 "{{.*}}file2.h"{{$}} 98 // ==== return to file2.h 99 // 100 // CHECK: extern int file2; 101 // 102 // REWRITE: #pragma clang module end 103 // CHECK: # 3 "<module-includes>" 2 104 // NO-REWRITE: #pragma clang module end 105 106 107 __FILE *a; // expected-error {{declaration of '__FILE' must be imported}} 108 #ifdef REWRITE 109 // [email protected]:1 {{here}} 110 #elif COPY 111 // [email protected]:1 {{here}} 112 #else 113 // [email protected]:1 {{here}} 114 #endif 115 116 #ifdef INCLUDE 117 #include "file.h" 118 #else 119 #pragma clang module import file 120 #endif 121 122 FILE *b; 123 int x = file2; // ok, found in file2.h, even under -DINCLUDE 124