r235464 - [modules] Cope with partial module macro information, fix memory leak found by buildbot.

Richard Smith richard-llvm at metafoo.co.uk
Tue Apr 21 19:09:44 PDT 2015


Author: rsmith
Date: Tue Apr 21 21:09:43 2015
New Revision: 235464

URL: http://llvm.org/viewvc/llvm-project?rev=235464&view=rev
Log:
[modules] Cope with partial module macro information, fix memory leak found by buildbot.

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

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=235464&r1=235463&r2=235464&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Tue Apr 21 21:09:43 2015
@@ -659,6 +659,7 @@ public:
   ModuleMacro *addModuleMacro(unsigned ModuleID, IdentifierInfo *II,
                               MacroInfo *Macro,
                               ArrayRef<ModuleMacro *> Overrides, bool &IsNew);
+  ModuleMacro *getModuleMacro(unsigned ModuleID, IdentifierInfo *II);
 
   /// \{
   /// Iterators for the macro history table. Currently defined macros have

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=235464&r1=235463&r2=235464&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Tue Apr 21 21:09:43 2015
@@ -112,6 +112,15 @@ ModuleMacro *Preprocessor::addModuleMacr
   return MM;
 }
 
+ModuleMacro *Preprocessor::getModuleMacro(unsigned ModuleID,
+                                          IdentifierInfo *II) {
+  llvm::FoldingSetNodeID ID;
+  ModuleMacro::Profile(ID, ModuleID, II);
+
+  void *InsertPos;
+  return ModuleMacros.FindNodeOrInsertPos(ID, InsertPos);
+}
+
 /// RegisterBuiltinMacro - Register the specified identifier in the identifier
 /// table and mark it as a builtin macro to be expanded.
 static IdentifierInfo *RegisterBuiltinMacro(Preprocessor &PP, const char *Name){

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=235464&r1=235463&r2=235464&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Apr 21 21:09:43 2015
@@ -1804,19 +1804,17 @@ void ASTReader::resolvePendingMacro(Iden
   // Module macros are listed in reverse dependency order.
   {
     std::reverse(ModuleMacros.begin(), ModuleMacros.end());
-    llvm::SmallDenseMap<unsigned, ModuleMacro*> Macros;
     llvm::SmallVector<ModuleMacro*, 8> Overrides;
     for (auto &MMI : ModuleMacros) {
       Overrides.clear();
       for (unsigned ModID : MMI.Overrides) {
-        auto *Macro = Macros.lookup(ModID);
+        auto *Macro = PP.getModuleMacro(ModID, II);
         assert(Macro && "missing definition for overridden macro");
-        Overrides.push_back(Macros.lookup(ModID));
+        Overrides.push_back(Macro);
       }
 
       bool Inserted = false;
-      Macros[MMI.SubModID] =
-          PP.addModuleMacro(MMI.SubModID, II, MMI.MI, Overrides, Inserted);
+      PP.addModuleMacro(MMI.SubModID, II, MMI.MI, Overrides, Inserted);
       if (!Inserted)
         continue;
 
@@ -1825,7 +1823,7 @@ void ASTReader::resolvePendingMacro(Iden
         // Macros in the owning module are hidden. Just remember this macro to
         // install if we make this module visible.
         HiddenNamesMap[Owner].HiddenMacros.insert(
-            std::make_pair(II, new ModuleMacroInfo(MMI)));
+            std::make_pair(II, new (Context) ModuleMacroInfo(MMI)));
       } else {
         installImportedMacro(II, MMI, Owner);
       }





More information about the cfe-commits mailing list