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 // 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 // Check that we can preprocess from a .pcm file and that we get the same result as preprocessing from the original sources. 42 // 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 -emit-module -o %t/file.pcm 43 // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -I%S/Inputs/preprocess %t/file.pcm -E -frewrite-includes -o %t/file.rewrite.ii 44 // RUN: cmp %t/rewrite.ii %t/file.rewrite.ii 45 46 // == module map 47 // CHECK: # 1 "{{.*}}module.modulemap" 48 // CHECK: module file { 49 // CHECK: header "file.h" { size 50 // CHECK: header "file2.h" { size 51 // CHECK: } 52 53 // == file.h 54 // CHECK: # 1 "<module-includes>" 55 // REWRITE: #if 0 56 // REWRITE: #include "file.h" 57 // REWRITE: #endif 58 // 59 // FIXME: It would be preferable to consistently put the module begin/end in 60 // the same file, but the relative ordering of PP callbacks and module 61 // begin/end tokens makes that difficult. 62 // 63 // REWRITE: #pragma clang module begin file 64 // CHECK: # 1 "{{.*}}file.h" 1 65 // NO-REWRITE: #pragma clang module begin file 66 // NO-REWRITE: # 1 "{{.*}}file.h"{{$}} 67 // 68 // CHECK: struct __FILE; 69 // CHECK: #pragma clang module import fwd /* clang {{-E|-frewrite-includes}}: implicit import 70 // CHECK: typedef struct __FILE FILE; 71 // 72 // REWRITE: #pragma clang module end 73 // CHECK: # 2 "<module-includes>" 2 74 // NO-REWRITE: #pragma clang module end 75 76 // == file2.h 77 // REWRITE: #if 0 78 // REWRITE: #include "file2.h" 79 // REWRITE: #endif 80 // 81 // REWRITE: #pragma clang module begin file 82 // CHECK: # 1 "{{.*}}file2.h" 1 83 // NO-REWRITE: #pragma clang module begin file 84 // 85 // ==== recursively re-enter file.h 86 // REWRITE: #if 0 87 // REWRITE: #include "file.h" 88 // REWRITE: #endif 89 // 90 // REWRITE: #pragma clang module begin file 91 // CHECK: # 1 "{{.*}}file.h" 1 92 // NO-REWRITE: #pragma clang module begin file 93 // NO-REWRITE: # 1 "{{.*}}file.h"{{$}} 94 // 95 // CHECK: struct __FILE; 96 // CHECK: #pragma clang module import fwd /* clang {{-E|-frewrite-includes}}: implicit import 97 // CHECK: typedef struct __FILE FILE; 98 // 99 // REWRITE: #pragma clang module end 100 // CHECK: # 2 "{{.*}}file2.h" 2 101 // NO-REWRITE: #pragma clang module end 102 // NO-REWRITE: # 2 "{{.*}}file2.h"{{$}} 103 // ==== return to file2.h 104 // 105 // CHECK: extern int file2; 106 // 107 // REWRITE: #pragma clang module end 108 // CHECK: # 3 "<module-includes>" 2 109 // NO-REWRITE: #pragma clang module end 110 111 112 __FILE *a; // expected-error {{declaration of '__FILE' must be imported}} 113 #ifdef REWRITE 114 // [email protected]:1 {{here}} 115 #elif COPY 116 // [email protected]:1 {{here}} 117 #else 118 // [email protected]:1 {{here}} 119 #endif 120 121 #ifdef INCLUDE 122 #include "file.h" 123 #else 124 #pragma clang module import file 125 #endif 126 127 FILE *b; 128 int x = file2; // ok, found in file2.h, even under -DINCLUDE 129