]> granicus.if.org Git - clang/commitdiff
When inferring a submodule ID during module creation, look up the
authorDouglas Gregor <dgregor@apple.com>
Fri, 6 Jan 2012 17:19:32 +0000 (17:19 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 6 Jan 2012 17:19:32 +0000 (17:19 +0000)
include stack to find the first file that is known to be part of the
module. This copes with situations where the module map doesn't
completely specify all of the headers that are involved in the module,
which can come up when there are very strange #include_next chains
(e.g., with weird compiler/stdlib headers like stdarg.h or float.h).

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

lib/Lex/ModuleMap.cpp
test/Modules/Inputs/def-include.h [new file with mode: 0644]
test/Modules/Inputs/def.h

index 6c13938c2094920d0a570ce662baf1ea601f0767..55fa50809a1cf7d635e1a451d2885cb29c71c68f 100644 (file)
@@ -426,12 +426,23 @@ Module *ModuleMap::inferModuleFromLocation(FullSourceLoc Loc) {
   
   const SourceManager &SrcMgr = Loc.getManager();
   FileID ExpansionFileID = ExpansionLoc.getFileID();
-  const FileEntry *ExpansionFile = SrcMgr.getFileEntryForID(ExpansionFileID);
-  if (!ExpansionFile)
-    return 0;
   
-  // Find the module that owns this header.
-  return findModuleForHeader(ExpansionFile);
+  while (const FileEntry *ExpansionFile
+           = SrcMgr.getFileEntryForID(ExpansionFileID)) {
+    // Find the module that owns this header (if any).
+    if (Module *Mod = findModuleForHeader(ExpansionFile))
+      return Mod;
+    
+    // No module owns this header, so look up the inclusion chain to see if
+    // any included header has an associated module.
+    SourceLocation IncludeLoc = SrcMgr.getIncludeLoc(ExpansionFileID);
+    if (IncludeLoc.isInvalid())
+      return 0;
+    
+    ExpansionFileID = SrcMgr.getFileID(IncludeLoc);
+  }
+  
+  return 0;
 }
 
 //----------------------------------------------------------------------------//
diff --git a/test/Modules/Inputs/def-include.h b/test/Modules/Inputs/def-include.h
new file mode 100644 (file)
index 0000000..9e0e575
--- /dev/null
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+struct B {
+  int b1;
+};
index 7c1a99ef7e62dcef1e31bf0a94cda275331b52a9..6d06b08125102f98c8426fc7900ad358f1120c07 100644 (file)
@@ -1,4 +1,4 @@
-
+#include "def-include.h"
 
 
 
@@ -8,7 +8,4 @@
 }
 @end
 
-struct B {
-  int b1;
-};