r177760 - [modules] When a MacroInfo object is deserialized, allocate and store its submodule ID.

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Mar 22 14:12:52 PDT 2013


Author: akirtzidis
Date: Fri Mar 22 16:12:51 2013
New Revision: 177760

URL: http://llvm.org/viewvc/llvm-project?rev=177760&view=rev
Log:
[modules] When a MacroInfo object is deserialized, allocate and store its submodule ID.

Modified:
    cfe/trunk/include/clang/Lex/MacroInfo.h
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/Lex/MacroInfo.cpp
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/include/clang/Lex/MacroInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/MacroInfo.h?rev=177760&r1=177759&r2=177760&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/MacroInfo.h (original)
+++ cfe/trunk/include/clang/Lex/MacroInfo.h Fri Mar 22 16:12:51 2013
@@ -101,6 +101,9 @@ private:
   /// \brief Must warn if the macro is unused at the end of translation unit.
   bool IsWarnIfUnused : 1;
 
+  /// \brief Whether this macro info was loaded from an AST file.
+  unsigned FromASTFile : 1;
+
   ~MacroInfo() {
     assert(ArgumentList == 0 && "Didn't call destroy before dtor!");
   }
@@ -272,8 +275,28 @@ public:
     IsDisabled = true;
   }
 
+  /// \brief Determine whether this macro info came from an AST file (such as
+  /// a precompiled header or module) rather than having been parsed.
+  bool isFromASTFile() const { return FromASTFile; }
+
+  /// \brief Retrieve the global ID of the module that owns this particular
+  /// macro info.
+  unsigned getOwningModuleID() const {
+    if (isFromASTFile())
+      return *(const unsigned*)(this+1);
+
+    return 0;
+  }
+
 private:
   unsigned getDefinitionLengthSlow(SourceManager &SM) const;
+
+  void setOwningModuleID(unsigned ID) {
+    assert(isFromASTFile());
+    *(unsigned*)(this+1) = ID;
+  }
+
+  friend class Preprocessor;
 };
 
 /// \brief Encapsulates changes to the "macros namespace" (the location where

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=177760&r1=177759&r2=177760&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Fri Mar 22 16:12:51 2013
@@ -1208,6 +1208,10 @@ public:
   /// \brief Allocate a new MacroInfo object with the provided SourceLocation.
   MacroInfo *AllocateMacroInfo(SourceLocation L);
 
+  /// \brief Allocate a new MacroInfo object loaded from an AST file.
+  MacroInfo *AllocateDeserializedMacroInfo(SourceLocation L,
+                                           unsigned SubModuleID);
+
   /// \brief Turn the specified lexer token into a fully checked and spelled
   /// filename, e.g. as an operand of \#include. 
   ///

Modified: cfe/trunk/lib/Lex/MacroInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/MacroInfo.cpp?rev=177760&r1=177759&r2=177760&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/MacroInfo.cpp (original)
+++ cfe/trunk/lib/Lex/MacroInfo.cpp Fri Mar 22 16:12:51 2013
@@ -28,7 +28,8 @@ MacroInfo::MacroInfo(SourceLocation DefL
     IsDisabled(false),
     IsUsed(false),
     IsAllowRedefinitionsWithoutWarning(false),
-    IsWarnIfUnused(false) {
+    IsWarnIfUnused(false),
+    FromASTFile(false) {
 }
 
 unsigned MacroInfo::getDefinitionLengthSlow(SourceManager &SM) const {

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=177760&r1=177759&r2=177760&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Fri Mar 22 16:12:51 2013
@@ -57,6 +57,19 @@ MacroInfo *Preprocessor::AllocateMacroIn
   return MI;
 }
 
+MacroInfo *Preprocessor::AllocateDeserializedMacroInfo(SourceLocation L,
+                                                       unsigned SubModuleID) {
+  LLVM_STATIC_ASSERT(llvm::AlignOf<MacroInfo>::Alignment >= sizeof(SubModuleID),
+                     "alignment for MacroInfo is less than the ID");
+  MacroInfo *MI =
+      (MacroInfo*)BP.Allocate(sizeof(MacroInfo) + sizeof(SubModuleID),
+                              llvm::AlignOf<MacroInfo>::Alignment);
+  new (MI) MacroInfo(L);
+  MI->FromASTFile = true;
+  MI->setOwningModuleID(SubModuleID);
+  return MI;
+}
+
 MacroDirective *Preprocessor::AllocateMacroDirective(MacroInfo *MI,
                                                      SourceLocation Loc,
                                                      bool isImported) {

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=177760&r1=177759&r2=177760&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Mar 22 16:12:51 2013
@@ -1151,7 +1151,7 @@ void ASTReader::ReadMacroRecord(ModuleFi
       SubmoduleID GlobalSubmoduleID = getGlobalSubmoduleID(F, Record[2]);
       unsigned NextIndex = 3;
       SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex);
-      MacroInfo *MI = PP.AllocateMacroInfo(Loc);
+      MacroInfo *MI = PP.AllocateDeserializedMacroInfo(Loc, GlobalSubmoduleID);
       // FIXME: Location should be import location in case of module.
       MacroDirective *MD = PP.AllocateMacroDirective(MI, Loc,
                                                      /*isImported=*/true);





More information about the cfe-commits mailing list