]> granicus.if.org Git - clang/commitdiff
[modules] When a file is listed as a non-textual header in a module map, don't
authorRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 18 May 2015 20:02:41 +0000 (20:02 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Mon, 18 May 2015 20:02:41 +0000 (20:02 +0000)
enter it more than once, even if it doesn't have #include guards -- we already
know that it is intended to have the same effect every time it's included, and
it's already had that effect. This particularly helps with local submodule
visibility builds, where the include guard macro may not be visible in the
includer, but will become visible the moment we enter the included file.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237609 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPDirectives.cpp
test/Modules/malformed.cpp

index ec06e790f0185c19be6ec8c350939f4331f6d6cd..aaed6b92d48b230f07ddaf99930cc7b0d52ed821 100644 (file)
@@ -1737,13 +1737,12 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
     std::max(HeaderInfo.getFileDirFlavor(File),
              SourceMgr.getFileCharacteristic(FilenameTok.getLocation()));
 
-  // FIXME: If we have a suggested module, and we've already visited this file,
-  // don't bother entering it again. We know it has no further effect.
-
   // Ask HeaderInfo if we should enter this #include file.  If not, #including
-  // this file will have no effect.
+  // this file will have no effect. We treat any textual inclusion of a modular
+  // header as a #import here.
   if (ShouldEnter &&
-      !HeaderInfo.ShouldEnterIncludeFile(*this, File, isImport)) {
+      !HeaderInfo.ShouldEnterIncludeFile(
+          *this, File, isImport || SuggestedModule.getModule())) {
     ShouldEnter = false;
     if (Callbacks)
       Callbacks->FileSkipped(*File, FilenameTok, FileCharacter);
index 2d07c4cd0da78c1b65deb196e5e580f290e3ef22..6d49850cceec0a0bb0a00ee2278965119ab9447d 100644 (file)
@@ -23,9 +23,9 @@
 // CHECK-B: {{^}}Inputs/malformed/b1.h:1:{{.*}} note: to match this '{'
 // CHECK-B: {{^}}Inputs/malformed/b1.h:3:{{.*}} error: extraneous closing brace ('}')
 //
-// CHECK-B: While building module 'malformed_b'
-// CHECK-B: {{^}}Inputs/malformed/b2.h:1:{{.*}} error: redefinition of 'g'
-// CHECK-B: {{^}}Inputs/malformed/b2.h:1:{{.*}} note: previous definition is here
+// We don't see another definition of 'g' because we don't re-enter b2.h
+// (even though it has no include guards).
+// CHECK-B-NOT: redefinition of 'g'
 
 void test() { f<int>(); }
 // Test that we use relative paths to name files within an imported module.