[cfe-commits] r147662 - in /cfe/trunk: lib/Lex/ModuleMap.cpp test/Modules/Inputs/def-include.h test/Modules/Inputs/def.h

Douglas Gregor dgregor at apple.com
Fri Jan 6 09:19:32 PST 2012


Author: dgregor
Date: Fri Jan  6 11:19:32 2012
New Revision: 147662

URL: http://llvm.org/viewvc/llvm-project?rev=147662&view=rev
Log:
When inferring a submodule ID during module creation, look up the
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).


Added:
    cfe/trunk/test/Modules/Inputs/def-include.h   (with props)
Modified:
    cfe/trunk/lib/Lex/ModuleMap.cpp
    cfe/trunk/test/Modules/Inputs/def.h

Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=147662&r1=147661&r2=147662&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Fri Jan  6 11:19:32 2012
@@ -426,12 +426,23 @@
   
   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;
 }
 
 //----------------------------------------------------------------------------//

Added: cfe/trunk/test/Modules/Inputs/def-include.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/def-include.h?rev=147662&view=auto
==============================================================================
--- cfe/trunk/test/Modules/Inputs/def-include.h (added)
+++ cfe/trunk/test/Modules/Inputs/def-include.h Fri Jan  6 11:19:32 2012
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+struct B {
+  int b1;
+};

Propchange: cfe/trunk/test/Modules/Inputs/def-include.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/trunk/test/Modules/Inputs/def-include.h
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cfe/trunk/test/Modules/Inputs/def-include.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cfe/trunk/test/Modules/Inputs/def.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/def.h?rev=147662&r1=147661&r2=147662&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/def.h (original)
+++ cfe/trunk/test/Modules/Inputs/def.h Fri Jan  6 11:19:32 2012
@@ -1,4 +1,4 @@
-
+#include "def-include.h"
 
 
 
@@ -8,7 +8,4 @@
 }
 @end
 
-struct B {
-  int b1;
-};
 





More information about the cfe-commits mailing list