[cfe-commits] r62250 - in /cfe/trunk/lib/Sema: Sema.h SemaLookup.cpp

Douglas Gregor dgregor at apple.com
Wed Jan 14 18:19:31 PST 2009


Author: dgregor
Date: Wed Jan 14 20:19:31 2009
New Revision: 62250

URL: http://llvm.org/viewvc/llvm-project?rev=62250&view=rev
Log:
Deallocate the BasePaths structure that we allocate for LookupResult.

Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaLookup.cpp

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=62250&r1=62249&r2=62250&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed Jan 14 20:19:31 2009
@@ -638,7 +638,11 @@
       /// by the LookupResult. Last is non-zero to indicate that the
       /// ambiguity is caused by two names found in base class
       /// subobjects of different types.
-      AmbiguousLookup
+      AmbiguousLookup,
+
+      /// We've moved from this object. There should not be any
+      /// attempts to look at its state.
+      Dead
     } StoredKind;
 
     /// The first lookup result, whose contents depend on the kind of
@@ -706,7 +710,9 @@
       AmbiguousBaseSubobjects
     };
 
-    LookupResult() : StoredKind(SingleDecl), First(0), Last(0), Context(0) { }
+    LookupResult() : StoredKind(Dead), First(0), Last(0), Context(0) { }
+
+    LookupResult(const LookupResult& Other);
 
     LookupResult(ASTContext &Context, Decl *D) 
       : StoredKind(SingleDecl), First(reinterpret_cast<uintptr_t>(D)),
@@ -725,6 +731,10 @@
         Last(DifferentSubobjectTypes? 1 : 0),
         Context(&Context) { }
 
+    ~LookupResult();
+
+    LookupResult& operator=(const LookupResult& Other);
+
     LookupKind getKind() const;
 
     /// @brief Determine whether name look found something.

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=62250&r1=62249&r2=62250&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Wed Jan 14 20:19:31 2009
@@ -127,6 +127,15 @@
   return false;
 }
 
+/// @brief Moves the name-lookup results from Other to the
+/// newly-constructed LookupResult.
+Sema::LookupResult::LookupResult(const LookupResult& Other) 
+  : StoredKind(Other.StoredKind), First(Other.First), Last(Other.Last),
+    Context(Other.Context) {
+  Other.StoredKind = Dead;
+}
+
+/// @brief Moves the name-lookup results from Other to this LookupResult.
 Sema::LookupResult::LookupResult(ASTContext &Context, 
                                  IdentifierResolver::iterator F, 
                                  IdentifierResolver::iterator L)
@@ -167,6 +176,25 @@
   Last = 0;
 }
 
+Sema::LookupResult::~LookupResult() {
+  if (StoredKind == AmbiguousLookup)
+    delete getBasePaths();
+}
+
+Sema::LookupResult& Sema::LookupResult::operator=(const LookupResult& Other) {
+  if (StoredKind == AmbiguousLookup)
+    delete getBasePaths();
+
+  StoredKind = Other.StoredKind;
+  First = Other.First;
+  Last = Other.Last;
+  Context = Other.Context;
+
+  Other.StoredKind = Dead;
+  return *this;
+}
+
+
 /// @brief Determine the result of name lookup.
 Sema::LookupResult::LookupKind Sema::LookupResult::getKind() const {
   switch (StoredKind) {
@@ -179,6 +207,10 @@
 
   case AmbiguousLookup:
     return Last? AmbiguousBaseSubobjectTypes : AmbiguousBaseSubobjects;
+
+  case Dead:
+    assert(false && "Attempt to look at a dead LookupResult");
+    break;
   }
 
   // We can't ever get here.
@@ -217,6 +249,9 @@
     assert(false && 
            "Name lookup returned an ambiguity that could not be handled");
     break;
+
+  case Dead:
+    assert(false && "Attempt to look at a dead LookupResult");
   }
 
   return 0;





More information about the cfe-commits mailing list