From 4feb36de047de72703acd18000387b11aeee4d26 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Fri, 13 Feb 2009 19:06:18 +0000 Subject: Remove DeclGroupOwningRef, since we intend for declarations to be owned by DeclContexts (always) rather than by statements. DeclContext currently goes out of its way to avoid destroying any Decls that might be owned by a DeclGroupOwningRef. However, in an error-recovery situation, a failure in a declaration statement can cause all of the decls in a DeclGroupOwningRef to be destroyed after they've already be added into the DeclContext. Hence, DeclContext is left with already-destroyed declarations, and bad things happen. This problem was causing failures that showed up as assertions on x86 Linux in test/Parser/objc-forcollection-neg-2.m. llvm-svn: 64474 --- clang/lib/AST/DeclGroup.cpp | 51 ++------------------------------------------- 1 file changed, 2 insertions(+), 49 deletions(-) (limited to 'clang/lib/AST/DeclGroup.cpp') diff --git a/clang/lib/AST/DeclGroup.cpp b/clang/lib/AST/DeclGroup.cpp index e7f84e1f46c..35cb6d3bc61 100644 --- a/clang/lib/AST/DeclGroup.cpp +++ b/clang/lib/AST/DeclGroup.cpp @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// // -// This file defines the DeclGroup, DeclGroupRef, and OwningDeclGroup classes. +// This file defines the DeclGroup and DeclGroupRef classes. // //===----------------------------------------------------------------------===// @@ -36,7 +36,7 @@ void DeclGroup::Emit(llvm::Serializer& S) const { } /// Read - Deserialize a DeclGroup from Bitcode. -DeclGroup* DeclGroup::Create(llvm::Deserializer& D, ASTContext& C) { +DeclGroup* DeclGroup::Read(llvm::Deserializer& D, ASTContext& C) { unsigned NumDecls = (unsigned) D.ReadInt(); unsigned size = sizeof(DeclGroup) + sizeof(Decl*) * NumDecls; unsigned alignment = llvm::AlignOf::Alignment; @@ -54,32 +54,10 @@ DeclGroup::DeclGroup(unsigned numdecls, Decl** decls) : NumDecls(numdecls) { } void DeclGroup::Destroy(ASTContext& C) { - Decl** Decls = (Decl**) (this + 1); - - for (unsigned i = 0; i < NumDecls; ++i) - Decls[i]->Destroy(C); - this->~DeclGroup(); C.Deallocate((void*) this); } -DeclGroupOwningRef::~DeclGroupOwningRef() { - assert (D == 0 && "Destroy method not called."); -} - -void DeclGroupOwningRef::Destroy(ASTContext& C) { - if (!D) - return; - - if (getKind() == DeclKind) - D->Destroy(C); - else - reinterpret_cast(reinterpret_cast(D) & - ~Mask)->Destroy(C); - - D = 0; -} - void DeclGroupRef::Emit(llvm::Serializer& S) const { if (getKind() == DeclKind) { S.EmitBool(false); @@ -98,28 +76,3 @@ DeclGroupRef DeclGroupRef::ReadVal(llvm::Deserializer& D) { return DeclGroupRef(D.ReadPtr()); } - -void DeclGroupOwningRef::Emit(llvm::Serializer& S) const { - if (getKind() == DeclKind) { - S.EmitBool(false); - S.EmitOwnedPtr(D); - } - else { - S.EmitBool(true); - S.EmitOwnedPtr(reinterpret_cast(reinterpret_cast(D) - & ~Mask)); - } -} - -DeclGroupOwningRef& DeclGroupOwningRef::Read(llvm::Deserializer& Dezr, - ASTContext& C) { - - if (!Dezr.ReadBool()) - D = Dezr.ReadOwnedPtr(C); - else { - uintptr_t x = reinterpret_cast(Dezr.ReadOwnedPtr(C)); - D = reinterpret_cast(x | DeclGroupKind); - } - - return *this; -} -- cgit v1.2.3