aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-01-15 02:19:31 +0000
committerDouglas Gregor <dgregor@apple.com>2009-01-15 02:19:31 +0000
commit4bb64e77dd3b22070e28b7f9ff99feb576eaf6ef (patch)
tree16f3627f41569fc6b55b89c3072e71d6c111ef33
parent293b4af04ca37576d4b228adf09acd6cee3ddb16 (diff)
Deallocate the BasePaths structure that we allocate for LookupResult.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62250 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/Sema.h14
-rw-r--r--lib/Sema/SemaLookup.cpp35
2 files changed, 47 insertions, 2 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index eb718f7f1a..cf9f8502c7 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -638,7 +638,11 @@ public:
/// 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 @@ public:
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 @@ public:
Last(DifferentSubobjectTypes? 1 : 0),
Context(&Context) { }
+ ~LookupResult();
+
+ LookupResult& operator=(const LookupResult& Other);
+
LookupKind getKind() const;
/// @brief Determine whether name look found something.
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp
index b85824382b..cc9a36ced2 100644
--- a/lib/Sema/SemaLookup.cpp
+++ b/lib/Sema/SemaLookup.cpp
@@ -127,6 +127,15 @@ bool Sema::LookupCriteria::isLookupResult(Decl *D) const {
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 @@ Sema::LookupResult::LookupResult(ASTContext &Context,
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 @@ Sema::LookupResult::LookupKind Sema::LookupResult::getKind() const {
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 @@ Decl *Sema::LookupResult::getAsDecl() const {
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;