Author: rsmith
Date: Mon Jun 26 12:39:25 2017
New Revision: 306320

URL: http://llvm.org/viewvc/llvm-project?rev=306320&view=rev
Log:
When preprocessing with -frewrite-imports and -fmodule-file=, do not pass all
modules to preprocessing of nested .pcm files.

Making those module files available results in loading more .pcm files than
necessary, and potentially in misbehavior if a module makes itself visible
during its own compilation (as parts of that module that have not yet been
processed would then become visible).

Added:
    cfe/trunk/test/Modules/Inputs/preprocess/file.h
    cfe/trunk/test/Modules/Inputs/preprocess/other.h
Modified:
    cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp
    cfe/trunk/test/Modules/Inputs/preprocess/fwd.h
    cfe/trunk/test/Modules/Inputs/preprocess/module.modulemap
    cfe/trunk/test/Modules/preprocess-module.cpp

Modified: cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp?rev=306320&r1=306319&r2=306320&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/Rewrite/FrontendActions.cpp Mon Jun 26 12:39:25 2017
@@ -247,6 +247,8 @@ public:
     Instance.getFrontendOpts().Inputs.clear();
     Instance.getFrontendOpts().Inputs.emplace_back(
         Filename, InputKind(InputKind::Unknown, InputKind::Precompiled));
+    Instance.getFrontendOpts().ModuleFiles.clear();
+    Instance.getFrontendOpts().ModuleMapFiles.clear();
     // Don't recursively rewrite imports. We handle them all at the top level.
     Instance.getPreprocessorOutputOpts().RewriteImports = false;
 

Added: cfe/trunk/test/Modules/Inputs/preprocess/file.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/preprocess/file.h?rev=306320&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/preprocess/file.h (added)
+++ cfe/trunk/test/Modules/Inputs/preprocess/file.h Mon Jun 26 12:39:25 2017
@@ -0,0 +1,9 @@
+#include "other.h"
+
+#ifndef FILE_H
+#define FILE_H
+struct __FILE;
+#include "fwd.h"
+typedef struct __FILE FILE;
+typedef foo bar;
+#endif

Modified: cfe/trunk/test/Modules/Inputs/preprocess/fwd.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/preprocess/fwd.h?rev=306320&r1=306319&r2=306320&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/preprocess/fwd.h (original)
+++ cfe/trunk/test/Modules/Inputs/preprocess/fwd.h Mon Jun 26 12:39:25 2017
@@ -1 +1,2 @@
+typedef struct foo foo;
 struct __FILE;

Modified: cfe/trunk/test/Modules/Inputs/preprocess/module.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/preprocess/module.modulemap?rev=306320&r1=306319&r2=306320&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/preprocess/module.modulemap (original)
+++ cfe/trunk/test/Modules/Inputs/preprocess/module.modulemap Mon Jun 26 
12:39:25 2017
@@ -1,5 +1,5 @@
 module fwd { header "fwd.h" export * }
-module file { header "file.h" header "file2.h" export * }
+module file { header "file.h" header "file2.h" header "other.h" export * }
 module nested {
   module a { header "a.h" }
   module b { header "b.h" }

Added: cfe/trunk/test/Modules/Inputs/preprocess/other.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/preprocess/other.h?rev=306320&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/preprocess/other.h (added)
+++ cfe/trunk/test/Modules/Inputs/preprocess/other.h Mon Jun 26 12:39:25 2017
@@ -0,0 +1 @@
+// other.h: empty

Modified: cfe/trunk/test/Modules/preprocess-module.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/preprocess-module.cpp?rev=306320&r1=306319&r2=306320&view=diff
==============================================================================
--- cfe/trunk/test/Modules/preprocess-module.cpp (original)
+++ cfe/trunk/test/Modules/preprocess-module.cpp Mon Jun 26 12:39:25 2017
@@ -29,15 +29,15 @@
 // RUN: %clang_cc1 -fmodules -fmodule-file=%t/rewrite.pcm %s -I%t -verify 
-fno-modules-error-recovery -DREWRITE -DINCLUDE -I%S/Inputs/preprocess
 
 // Now try building the module when the header files are missing.
-// RUN: cp %S/Inputs/preprocess/fwd.h %S/Inputs/preprocess/file.h 
%S/Inputs/preprocess/file2.h %S/Inputs/preprocess/module.modulemap %t
+// 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
 // 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
-// RUN: rm %t/fwd.h %t/file.h %t/file2.h %t/module.modulemap
+// RUN: rm %t/fwd.h %t/file.h %t/file2.h %t/other.h %t/module.modulemap
 // 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
 
 // Check that our module contains correct mapping information for the headers.
-// RUN: cp %S/Inputs/preprocess/fwd.h %S/Inputs/preprocess/file.h 
%S/Inputs/preprocess/file2.h %S/Inputs/preprocess/module.modulemap %t
+// 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
 // RUN: %clang_cc1 -fmodules -fmodule-file=%t/copy.pcm %s -I%t -verify 
-fno-modules-error-recovery -DCOPY -DINCLUDE
-// RUN: rm %t/fwd.h %t/file.h %t/file2.h %t/module.modulemap
+// RUN: rm %t/fwd.h %t/file.h %t/file2.h %t/other.h %t/module.modulemap
 
 // Check that we can preprocess from a .pcm file and that we get the same 
result as preprocessing from the original sources.
 // 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
@@ -50,6 +50,10 @@
 // RUN: %clang_cc1 -fmodules -fmodule-file=%t/file.rewrite.pcm %s -I%t -verify 
-fno-modules-error-recovery -DFILE_REWRITE
 // 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
 //
+// Check that we can preprocess this user of the .pcm file.
+// RUN: %clang_cc1 -fmodules -fmodule-file=%t/file.pcm %s -I%t -E 
-frewrite-imports -o %t/preprocess-module.ii
+// RUN: %clang_cc1 -fmodules %t/preprocess-module.ii -verify 
-fno-modules-error-recovery -DFILE_REWRITE_FULL
+//
 // Check that language / header search options are ignored when preprocessing 
from a .pcm file.
 // RUN: %clang_cc1 %t/file.pcm -E -frewrite-includes -o %t/file.rewrite.ii.2
 // RUN: cmp %t/file.rewrite.ii %t/file.rewrite.ii.2
@@ -78,12 +82,15 @@
 // 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;
+// REWRITE: #ifndef FILE_H
+// REWRITE: #define FILE_H
+//
 // CHECK: #pragma clang module import fwd /* clang {{-E|-frewrite-includes}}: 
implicit import
 // CHECK: typedef struct __FILE FILE;
 //
+// REWRITE: #endif
+//
 // REWRITE: #pragma clang module end
 // CHECK: # 2 "<module-includes>" 2
 // NO-REWRITE: #pragma clang module end
@@ -105,11 +112,16 @@
 // 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: #ifndef FILE_H
+// REWRITE: #define FILE_H
+// REWRITE: #if 0
+// REWRITE: #include "fwd.h"
+// REWRITE: #endif
+// REWRITE-NOT: #pragma clang module import fwd
+// REWRITE: #endif
+//
+// NO-REWRITE-NOT: struct __FILE;
 //
 // REWRITE: #pragma clang module end
 // CHECK: # 2 "{{.*}}file2.h" 2
@@ -124,15 +136,17 @@
 // NO-REWRITE: #pragma clang module end
 
 
-__FILE *a; // expected-error {{declaration of '__FILE' must be imported}}
+__FILE *a; // expected-error-re {{{{declaration of '__FILE' must be 
imported|unknown type name '__FILE'}}}}
 #if FILE_REWRITE
-// expected-n...@file.rewrite.ii:1 {{here}}
+// expected-n...@file.rewrite.ii:* {{here}}
+#elif FILE_REWRITE_FULL
+// No note diagnostic at all in this case: we've built the 'file' module but 
not loaded it into this compilation yet.
 #elif REWRITE
-// expected-n...@rewrite.ii:1 {{here}}
+// expected-n...@rewrite.ii:* {{here}}
 #elif COPY
-// expected-n...@copy.ii:1 {{here}}
+// expected-n...@copy.ii:* {{here}}
 #else
-// expected-n...@no-rewrite.ii:1 {{here}}
+// expected-n...@no-rewrite.ii:* {{here}}
 #endif
 
 #ifdef INCLUDE


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to