]> granicus.if.org Git - clang/commitdiff
[Modules] Prevent #import to reenter header if not building a module.
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Thu, 10 Aug 2017 15:16:24 +0000 (15:16 +0000)
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Thu, 10 Aug 2017 15:16:24 +0000 (15:16 +0000)
When non-modular headers are imported while not building a module but
in -fmodules mode, be conservative and preserve the default #import
semantic: do not reenter headers.

rdar://problem/33745031

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

lib/Lex/HeaderSearch.cpp
test/Modules/Inputs/import-textual/x.h [new file with mode: 0644]
test/Modules/import-textual-nomodules.m [new file with mode: 0644]

index 1ebcc0a1c657c835e702ad67657f075ba121719f..4b5df8c1cc67f595bf7d5050f61f8451a5f1ae43 100644 (file)
@@ -1143,7 +1143,7 @@ bool HeaderSearch::ShouldEnterIncludeFile(Preprocessor &PP,
     // headers find in the wild might rely only on #import and do not contain
     // controlling macros, be conservative and only try to enter textual headers
     // if such macro is present.
-    if (!FileInfo.isModuleHeader &&
+    if (FileInfo.isCompilingModuleHeader && !FileInfo.isModuleHeader &&
         FileInfo.getControllingMacro(ExternalLookup))
       TryEnterHdr = true;
     return TryEnterHdr;
diff --git a/test/Modules/Inputs/import-textual/x.h b/test/Modules/Inputs/import-textual/x.h
new file mode 100644 (file)
index 0000000..9b41ccd
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef RANDOM_DEP
+
+@interface X
+@end
+
+#endif // RANDOM_DEP
diff --git a/test/Modules/import-textual-nomodules.m b/test/Modules/import-textual-nomodules.m
new file mode 100644 (file)
index 0000000..7cf8c1e
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fsyntax-only -fmodules -fimplicit-module-maps -I%S/Inputs/import-textual -fmodules-cache-path=%t %s -verify
+
+// expected-no-diagnostics
+
+#import "x.h"
+#import "x.h"
+