diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-05-04 00:29:54 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-05-04 00:29:54 +0000 |
commit | d13863008b380aae3be60fd8b6e9d36e913b027e (patch) | |
tree | 4ab68eb4476d6912238d6e7450a58f7fdc72cb70 /clang/test/Modules | |
parent | 8e238705858ff57dd01381be8bd73873a7cd584f (diff) | |
download | bcm5719-llvm-d13863008b380aae3be60fd8b6e9d36e913b027e.tar.gz bcm5719-llvm-d13863008b380aae3be60fd8b6e9d36e913b027e.zip |
Add #pragma clang module begin/end pragmas and generate them when preprocessing a module.
These pragmas are intended to simulate the effect of entering or leaving a file
with an associated module. This is not completely implemented yet: declarations
between the pragmas will not be attributed to the correct module, but macro
visibility is already functional.
Modules named by #pragma clang module begin must already be known to clang (in
some module map that's either loaded or on the search path).
llvm-svn: 302098
Diffstat (limited to 'clang/test/Modules')
-rw-r--r-- | clang/test/Modules/Inputs/preprocess/file2.h | 2 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/preprocess/module.modulemap | 2 | ||||
-rw-r--r-- | clang/test/Modules/preprocess-module.cpp | 57 |
3 files changed, 58 insertions, 3 deletions
diff --git a/clang/test/Modules/Inputs/preprocess/file2.h b/clang/test/Modules/Inputs/preprocess/file2.h new file mode 100644 index 00000000000..04bf796d1e9 --- /dev/null +++ b/clang/test/Modules/Inputs/preprocess/file2.h @@ -0,0 +1,2 @@ +#include "file.h" +extern int file2; diff --git a/clang/test/Modules/Inputs/preprocess/module.modulemap b/clang/test/Modules/Inputs/preprocess/module.modulemap index a5c5b61dddc..943435a953d 100644 --- a/clang/test/Modules/Inputs/preprocess/module.modulemap +++ b/clang/test/Modules/Inputs/preprocess/module.modulemap @@ -1,2 +1,2 @@ module fwd { header "fwd.h" export * } -module file { header "file.h" export * } +module file { header "file.h" header "file2.h" export * } diff --git a/clang/test/Modules/preprocess-module.cpp b/clang/test/Modules/preprocess-module.cpp index 99fe8cf8c30..337cafbf65b 100644 --- a/clang/test/Modules/preprocess-module.cpp +++ b/clang/test/Modules/preprocess-module.cpp @@ -3,10 +3,63 @@ // 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 // MISSING-FWD: module 'fwd' is needed -// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodules-cache-path=%t -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -E | FileCheck %s +// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodules-cache-path=%t -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -E | FileCheck %s --check-prefix=CHECK --check-prefix=NO-REWRITE +// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodules-cache-path=%t -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -E -frewrite-includes | FileCheck %s --check-prefix=CHECK --check-prefix=REWRITE + +// == file.h // CHECK: # 1 "<module-includes>" +// REWRITE: #if 0 +// REWRITE: #include "file.h" +// REWRITE: #endif +// +// FIXME: It would be preferable to consistently put the module begin/end in +// the same file, but the relative ordering of PP callbacks and module +// begin/end tokens makes that difficult. +// +// REWRITE: #pragma clang module begin file // CHECK: # 1 "{{.*}}file.h" 1 +// NO-REWRITE: #pragma clang module begin file +// NO-REWRITE: # 1 "{{.*}}file.h"{{$}} +// // CHECK: struct __FILE; -// CHECK: #pragma clang module import fwd /* clang -E: implicit import for #include "fwd.h" */ +// CHECK: #pragma clang module import fwd /* clang {{-E|-frewrite-includes}}: implicit import // CHECK: typedef struct __FILE FILE; +// +// REWRITE: #pragma clang module end // CHECK: # 2 "<module-includes>" 2 +// NO-REWRITE: #pragma clang module end + +// == file2.h +// REWRITE: #if 0 +// REWRITE: #include "file2.h" +// REWRITE: #endif +// +// REWRITE: #pragma clang module begin file +// CHECK: # 1 "{{.*}}file2.h" 1 +// NO-REWRITE: #pragma clang module begin file +// +// ==== recursively re-enter file.h +// REWRITE: #if 0 +// REWRITE: #include "file.h" +// REWRITE: #endif +// +// REWRITE: #pragma clang module begin file +// CHECK: # 1 "{{.*}}file.h" 1 +// NO-REWRITE: #pragma clang module begin file +// NO-REWRITE: # 1 "{{.*}}file.h"{{$}} +// +// CHECK: struct __FILE; +// CHECK: #pragma clang module import fwd /* clang {{-E|-frewrite-includes}}: implicit import +// CHECK: typedef struct __FILE FILE; +// +// REWRITE: #pragma clang module end +// CHECK: # 2 "{{.*}}file2.h" 2 +// NO-REWRITE: #pragma clang module end +// NO-REWRITE: # 2 "{{.*}}file2.h"{{$}} +// ==== return to file2.h +// +// CHECK: extern int file2; +// +// REWRITE: #pragma clang module end +// CHECK: # 3 "<module-includes>" 2 +// NO-REWRITE: #pragma clang module end |