Richard Smith | f74d946 | 2017-04-28 01:49:42 +0000 | [diff] [blame] | 1 | // RUN: rm -rf %t |
Richard Smith | 8128f33 | 2017-05-05 22:18:51 +0000 | [diff] [blame] | 2 | // RUN: mkdir %t |
Richard Smith | f74d946 | 2017-04-28 01:49:42 +0000 | [diff] [blame] | 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 | |
Richard Smith | 8128f33 | 2017-05-05 22:18:51 +0000 | [diff] [blame] | 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. |
Richard Smith | 8128f33 | 2017-05-05 22:18:51 +0000 | [diff] [blame] | 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 | |
Richard Smith | 4a3751f | 2017-05-08 20:30:47 +0000 | [diff] [blame] | 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 | |
Richard Smith | 8128f33 | 2017-05-05 22:18:51 +0000 | [diff] [blame] | 25 | // Check the module we built works. |
Richard Smith | 54f0440 | 2017-05-18 02:29:20 +0000 | [diff] [blame] | 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 |
Richard Smith | 8b70610 | 2017-05-31 20:56:55 +0000 | [diff] [blame] | 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 |
Richard Smith | 8128f33 | 2017-05-05 22:18:51 +0000 | [diff] [blame] | 30 | |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 31 | // Now try building the module when the header files are missing. |
Richard Smith | a21c8e1 | 2017-06-26 19:39:25 +0000 | [diff] [blame] | 32 | // RUN: cp %S/Inputs/preprocess/fwd.h %S/Inputs/preprocess/file.h %S/Inputs/preprocess/file2.h %S/Inputs/preprocess/other.h %S/Inputs/preprocess/module.modulemap %t |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 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 |
Richard Smith | a21c8e1 | 2017-06-26 19:39:25 +0000 | [diff] [blame] | 34 | // RUN: rm %t/fwd.h %t/file.h %t/file2.h %t/other.h %t/module.modulemap |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 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 | |
Richard Smith | ab75597 | 2017-06-05 18:10:11 +0000 | [diff] [blame] | 37 | // Check that our module contains correct mapping information for the headers. |
Richard Smith | a21c8e1 | 2017-06-26 19:39:25 +0000 | [diff] [blame] | 38 | // RUN: cp %S/Inputs/preprocess/fwd.h %S/Inputs/preprocess/file.h %S/Inputs/preprocess/file2.h %S/Inputs/preprocess/other.h %S/Inputs/preprocess/module.modulemap %t |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 39 | // RUN: %clang_cc1 -fmodules -fmodule-file=%t/copy.pcm %s -I%t -verify -fno-modules-error-recovery -DCOPY -DINCLUDE |
Richard Smith | a21c8e1 | 2017-06-26 19:39:25 +0000 | [diff] [blame] | 40 | // RUN: rm %t/fwd.h %t/file.h %t/file2.h %t/other.h %t/module.modulemap |
Richard Smith | 8128f33 | 2017-05-05 22:18:51 +0000 | [diff] [blame] | 41 | |
Richard Smith | ab75597 | 2017-06-05 18:10:11 +0000 | [diff] [blame] | 42 | // Check that we can preprocess from a .pcm file and that we get the same result as preprocessing from the original sources. |
| 43 | // 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 |
| 44 | // 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 |
Richard Smith | 6b19934 | 2017-06-05 18:39:31 +0000 | [diff] [blame] | 45 | // FIXME: This check fails on Windows targets, due to canonicalization of directory separators. |
| 46 | // FIXME: cmp %t/rewrite.ii %t/file.rewrite.ii |
| 47 | // FIXME: Instead, just check that the preprocessed output is functionally equivalent to the output when preprocessing from the original sources. |
| 48 | // RUN: FileCheck %s --input-file %t/file.rewrite.ii --check-prefix=CHECK --check-prefix=REWRITE |
| 49 | // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/file.rewrite.ii -emit-module -o %t/file.rewrite.pcm |
| 50 | // RUN: %clang_cc1 -fmodules -fmodule-file=%t/file.rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DFILE_REWRITE |
| 51 | // RUN: %clang_cc1 -fmodules -fmodule-file=%t/file.rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DFILE_REWRITE -DINCLUDE -I%S/Inputs/preprocess |
Richard Smith | 1893475 | 2017-06-06 00:32:01 +0000 | [diff] [blame] | 52 | // |
Richard Smith | a21c8e1 | 2017-06-26 19:39:25 +0000 | [diff] [blame] | 53 | // Check that we can preprocess this user of the .pcm file. |
Lubos Lunak | 533434f | 2019-09-18 19:09:41 +0000 | [diff] [blame] | 54 | // RUN: %clang_cc1 -fmodules -fmodule-file=%t/file.pcm %s -I%t -E -frewrite-imports -DFILE_REWRITE_FULL -o %t/preprocess-module.ii |
Richard Smith | a21c8e1 | 2017-06-26 19:39:25 +0000 | [diff] [blame] | 55 | // RUN: %clang_cc1 -fmodules %t/preprocess-module.ii -verify -fno-modules-error-recovery -DFILE_REWRITE_FULL |
| 56 | // |
Richard Smith | 1893475 | 2017-06-06 00:32:01 +0000 | [diff] [blame] | 57 | // Check that language / header search options are ignored when preprocessing from a .pcm file. |
| 58 | // RUN: %clang_cc1 %t/file.pcm -E -frewrite-includes -o %t/file.rewrite.ii.2 |
| 59 | // RUN: cmp %t/file.rewrite.ii %t/file.rewrite.ii.2 |
| 60 | // |
| 61 | // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -I%S/Inputs/preprocess %t/file.pcm -E -o %t/file.no-rewrite.ii |
| 62 | // RUN: %clang_cc1 %t/file.pcm -E -o %t/file.no-rewrite.ii.2 -Dstruct=error |
| 63 | // RUN: cmp %t/file.no-rewrite.ii %t/file.no-rewrite.ii.2 |
Richard Smith | ab75597 | 2017-06-05 18:10:11 +0000 | [diff] [blame] | 64 | |
Richard Smith | 8128f33 | 2017-05-05 22:18:51 +0000 | [diff] [blame] | 65 | // == module map |
| 66 | // CHECK: # 1 "{{.*}}module.modulemap" |
| 67 | // CHECK: module file { |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 68 | // CHECK: header "file.h" { size |
| 69 | // CHECK: header "file2.h" { size |
Richard Smith | 8128f33 | 2017-05-05 22:18:51 +0000 | [diff] [blame] | 70 | // CHECK: } |
Richard Smith | d138630 | 2017-05-04 00:29:54 +0000 | [diff] [blame] | 71 | |
| 72 | // == file.h |
Richard Smith | f74d946 | 2017-04-28 01:49:42 +0000 | [diff] [blame] | 73 | // CHECK: # 1 "<module-includes>" |
Richard Smith | d138630 | 2017-05-04 00:29:54 +0000 | [diff] [blame] | 74 | // REWRITE: #if 0 |
| 75 | // REWRITE: #include "file.h" |
| 76 | // REWRITE: #endif |
| 77 | // |
| 78 | // FIXME: It would be preferable to consistently put the module begin/end in |
| 79 | // the same file, but the relative ordering of PP callbacks and module |
| 80 | // begin/end tokens makes that difficult. |
| 81 | // |
| 82 | // REWRITE: #pragma clang module begin file |
Richard Smith | f74d946 | 2017-04-28 01:49:42 +0000 | [diff] [blame] | 83 | // CHECK: # 1 "{{.*}}file.h" 1 |
Richard Smith | d138630 | 2017-05-04 00:29:54 +0000 | [diff] [blame] | 84 | // NO-REWRITE: #pragma clang module begin file |
Richard Smith | d138630 | 2017-05-04 00:29:54 +0000 | [diff] [blame] | 85 | // |
Richard Smith | a21c8e1 | 2017-06-26 19:39:25 +0000 | [diff] [blame] | 86 | // REWRITE: #ifndef FILE_H |
| 87 | // REWRITE: #define FILE_H |
| 88 | // |
Richard Smith | d138630 | 2017-05-04 00:29:54 +0000 | [diff] [blame] | 89 | // CHECK: #pragma clang module import fwd /* clang {{-E|-frewrite-includes}}: implicit import |
Richard Smith | f74d946 | 2017-04-28 01:49:42 +0000 | [diff] [blame] | 90 | // CHECK: typedef struct __FILE FILE; |
Richard Smith | d138630 | 2017-05-04 00:29:54 +0000 | [diff] [blame] | 91 | // |
Richard Smith | a21c8e1 | 2017-06-26 19:39:25 +0000 | [diff] [blame] | 92 | // REWRITE: #endif |
| 93 | // |
Richard Smith | d138630 | 2017-05-04 00:29:54 +0000 | [diff] [blame] | 94 | // REWRITE: #pragma clang module end |
Richard Smith | f74d946 | 2017-04-28 01:49:42 +0000 | [diff] [blame] | 95 | // CHECK: # 2 "<module-includes>" 2 |
Richard Smith | d138630 | 2017-05-04 00:29:54 +0000 | [diff] [blame] | 96 | // NO-REWRITE: #pragma clang module end |
| 97 | |
| 98 | // == file2.h |
| 99 | // REWRITE: #if 0 |
| 100 | // REWRITE: #include "file2.h" |
| 101 | // REWRITE: #endif |
| 102 | // |
| 103 | // REWRITE: #pragma clang module begin file |
| 104 | // CHECK: # 1 "{{.*}}file2.h" 1 |
| 105 | // NO-REWRITE: #pragma clang module begin file |
| 106 | // |
| 107 | // ==== recursively re-enter file.h |
| 108 | // REWRITE: #if 0 |
| 109 | // REWRITE: #include "file.h" |
| 110 | // REWRITE: #endif |
| 111 | // |
| 112 | // REWRITE: #pragma clang module begin file |
| 113 | // CHECK: # 1 "{{.*}}file.h" 1 |
| 114 | // NO-REWRITE: #pragma clang module begin file |
Richard Smith | d138630 | 2017-05-04 00:29:54 +0000 | [diff] [blame] | 115 | // |
Richard Smith | a21c8e1 | 2017-06-26 19:39:25 +0000 | [diff] [blame] | 116 | // REWRITE: #ifndef FILE_H |
| 117 | // REWRITE: #define FILE_H |
| 118 | // REWRITE: #if 0 |
| 119 | // REWRITE: #include "fwd.h" |
| 120 | // REWRITE: #endif |
| 121 | // REWRITE-NOT: #pragma clang module import fwd |
| 122 | // REWRITE: #endif |
| 123 | // |
| 124 | // NO-REWRITE-NOT: struct __FILE; |
Richard Smith | d138630 | 2017-05-04 00:29:54 +0000 | [diff] [blame] | 125 | // |
| 126 | // REWRITE: #pragma clang module end |
| 127 | // CHECK: # 2 "{{.*}}file2.h" 2 |
| 128 | // NO-REWRITE: #pragma clang module end |
| 129 | // NO-REWRITE: # 2 "{{.*}}file2.h"{{$}} |
| 130 | // ==== return to file2.h |
| 131 | // |
| 132 | // CHECK: extern int file2; |
| 133 | // |
| 134 | // REWRITE: #pragma clang module end |
| 135 | // CHECK: # 3 "<module-includes>" 2 |
| 136 | // NO-REWRITE: #pragma clang module end |
Richard Smith | 8128f33 | 2017-05-05 22:18:51 +0000 | [diff] [blame] | 137 | |
| 138 | |
Richard Smith | a21c8e1 | 2017-06-26 19:39:25 +0000 | [diff] [blame] | 139 | __FILE *a; // expected-error-re {{{{declaration of '__FILE' must be imported|unknown type name '__FILE'}}}} |
Richard Smith | 6b19934 | 2017-06-05 18:39:31 +0000 | [diff] [blame] | 140 | #if FILE_REWRITE |
Richard Smith | a21c8e1 | 2017-06-26 19:39:25 +0000 | [diff] [blame] | 141 | // expected-note@file.rewrite.ii:* {{here}} |
| 142 | #elif FILE_REWRITE_FULL |
| 143 | // No note diagnostic at all in this case: we've built the 'file' module but not loaded it into this compilation yet. |
Richard Smith | 6b19934 | 2017-06-05 18:39:31 +0000 | [diff] [blame] | 144 | #elif REWRITE |
Richard Smith | a21c8e1 | 2017-06-26 19:39:25 +0000 | [diff] [blame] | 145 | // expected-note@rewrite.ii:* {{here}} |
Richard Smith | 040e126 | 2017-06-02 01:55:39 +0000 | [diff] [blame] | 146 | #elif COPY |
Richard Smith | a21c8e1 | 2017-06-26 19:39:25 +0000 | [diff] [blame] | 147 | // expected-note@copy.ii:* {{here}} |
Richard Smith | 54f0440 | 2017-05-18 02:29:20 +0000 | [diff] [blame] | 148 | #else |
Richard Smith | a21c8e1 | 2017-06-26 19:39:25 +0000 | [diff] [blame] | 149 | // expected-note@no-rewrite.ii:* {{here}} |
Richard Smith | 54f0440 | 2017-05-18 02:29:20 +0000 | [diff] [blame] | 150 | #endif |
Richard Smith | 8128f33 | 2017-05-05 22:18:51 +0000 | [diff] [blame] | 151 | |
Richard Smith | 8b70610 | 2017-05-31 20:56:55 +0000 | [diff] [blame] | 152 | #ifdef INCLUDE |
| 153 | #include "file.h" |
| 154 | #else |
Richard Smith | 8128f33 | 2017-05-05 22:18:51 +0000 | [diff] [blame] | 155 | #pragma clang module import file |
Richard Smith | 8b70610 | 2017-05-31 20:56:55 +0000 | [diff] [blame] | 156 | #endif |
Richard Smith | 8128f33 | 2017-05-05 22:18:51 +0000 | [diff] [blame] | 157 | |
| 158 | FILE *b; |
Richard Smith | 8b70610 | 2017-05-31 20:56:55 +0000 | [diff] [blame] | 159 | int x = file2; // ok, found in file2.h, even under -DINCLUDE |