]> granicus.if.org Git - clang/commitdiff
Remove DeclGroupOwningRef, since we intend for declarations to be owned
authorDouglas Gregor <dgregor@apple.com>
Fri, 13 Feb 2009 19:06:18 +0000 (19:06 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 13 Feb 2009 19:06:18 +0000 (19:06 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64474 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclGroup.h
include/clang/AST/Stmt.h
lib/AST/CFG.cpp
lib/AST/DeclGroup.cpp
lib/AST/Stmt.cpp
lib/AST/StmtSerialization.cpp
lib/Sema/SemaStmt.cpp

index 3f7a60a303481479d40266a29bc070a6d9039acd..2b93f3c2cb3df7d692a7bf66f7890979f1ad32d5 100644 (file)
@@ -53,7 +53,7 @@ public:
   void Emit(llvm::Serializer& S) const;
   
   /// Read - Deserialize a DeclGroup from Bitcode.
-  static DeclGroup* Create(llvm::Deserializer& D, ASTContext& C);
+  static DeclGroup* Read(llvm::Deserializer& D, ASTContext& C);
 };
     
 class DeclGroupRef {
@@ -110,30 +110,5 @@ public:
   static DeclGroupRef ReadVal(llvm::Deserializer& D);
 };
   
-class DeclGroupOwningRef : public DeclGroupRef {
-public:
-  explicit DeclGroupOwningRef() : DeclGroupRef((Decl*)0) {}
-  explicit DeclGroupOwningRef(Decl* d) : DeclGroupRef(d) {}
-  explicit DeclGroupOwningRef(DeclGroup* dg) : DeclGroupRef(dg) {}
-
-  ~DeclGroupOwningRef();  
-  void Destroy(ASTContext& C);
-  
-  DeclGroupOwningRef(DeclGroupOwningRef& R)
-    : DeclGroupRef(R) { R.D = 0; }
-  
-  DeclGroupOwningRef& operator=(DeclGroupOwningRef& R) {
-    D = R.D;
-    R.D = 0;
-    return *this;
-  }
-  
-  /// Emit - Serialize a DeclGroupOwningRef to Bitcode.
-  void Emit(llvm::Serializer& S) const;
-  
-  /// Read - Deserialize a DeclGroupOwningRef from Bitcode.
-  DeclGroupOwningRef& Read(llvm::Deserializer& D, ASTContext& C);
-};
-
 } // end clang namespace
 #endif
index ae7596a1063607a3a2e922e8db83992c0fdbb05d..66eb303c9d753ea4100d5fc4bf52284e3b89ae78 100644 (file)
@@ -226,10 +226,10 @@ public:
 ///
 class DeclStmt : public Stmt {
 protected:
-  DeclGroupOwningRef DG;
+  DeclGroupRef DG;
   SourceLocation StartLoc, EndLoc;
 public:
-  DeclStmt(DeclGroupOwningRef& dg, SourceLocation startLoc, 
+  DeclStmt(DeclGroupRef dg, SourceLocation startLoc, 
            SourceLocation endLoc) : Stmt(DeclStmtClass), DG(dg),
                                     StartLoc(startLoc), EndLoc(endLoc) {}
   
index 2ea83882876ec5b2ed3c9332206222c3f2ac52b5..e08a00b8a5e135668cb4c32688b7acd682585d66 100644 (file)
@@ -379,11 +379,8 @@ CFGBlock* CFGBuilder::WalkAST(Stmt* Terminator, bool AlwaysAddStmt = false) {
                        ? 8 : llvm::AlignOf<DeclStmt>::Alignment;
           
           // Allocate the DeclStmt using the BumpPtrAllocator.  It will
-          // get automatically freed with the CFG.  Note that even though
-          // we are using a DeclGroupOwningRef that wraps a singe Decl*,
-          // that Decl* will not get deallocated because the destroy method
-          // of DG is never called.
-          DeclGroupOwningRef DG(*I);
+          // get automatically freed with the CFG. 
+          DeclGroupRef DG(*I);
           Decl* D = *I;
           void* Mem = cfg->getAllocator().Allocate(sizeof(DeclStmt), A);
           
index e7f84e1f46c8fd1fcba78263e95a087a11104e39..35cb6d3bc614a24456947b423a9b7f3484f3fb9a 100644 (file)
@@ -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<DeclGroup>::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<DeclGroup*>(reinterpret_cast<uintptr_t>(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<DeclGroup>());
 }
-
-void DeclGroupOwningRef::Emit(llvm::Serializer& S) const {
-  if (getKind() == DeclKind) {
-    S.EmitBool(false);
-    S.EmitOwnedPtr(D);
-  }
-  else {
-    S.EmitBool(true);
-    S.EmitOwnedPtr(reinterpret_cast<DeclGroup*>(reinterpret_cast<uintptr_t>(D)
-                                                & ~Mask));        
-  }
-}
-
-DeclGroupOwningRef& DeclGroupOwningRef::Read(llvm::Deserializer& Dezr, 
-                                             ASTContext& C) {
-  
-  if (!Dezr.ReadBool())
-    D = Dezr.ReadOwnedPtr<Decl>(C);
-  else {
-    uintptr_t x = reinterpret_cast<uintptr_t>(Dezr.ReadOwnedPtr<DeclGroup>(C));
-    D = reinterpret_cast<Decl*>(x | DeclGroupKind);
-  }
-  
-  return *this;
-}
index 49c8c80509a0de243b2d2e05f91bc3fd8f761e2b..b85a67e689f8b7f22da4f3f195e54f9413c5a344 100644 (file)
@@ -58,7 +58,6 @@ void Stmt::Destroy(ASTContext& C) {
 }
 
 void DeclStmt::Destroy(ASTContext& C) {
-  DG.Destroy(C);
   this->~DeclStmt();
   C.Deallocate((void *)this);
 }
index 5a6e49cb3e35e45fe978fdd3f69ddc1c9f011223..22ce8183fd6871a5d7da0070821a37d45aa2e6a4 100644 (file)
@@ -550,8 +550,7 @@ void DeclStmt::EmitImpl(Serializer& S) const {
 DeclStmt* DeclStmt::CreateImpl(Deserializer& D, ASTContext& C) {
   SourceLocation StartLoc = SourceLocation::ReadVal(D);
   SourceLocation EndLoc = SourceLocation::ReadVal(D); 
-  DeclGroupOwningRef DG;
-  return new DeclStmt(DG.Read(D, C), StartLoc, EndLoc);
+  return new DeclStmt(DeclGroupRef::ReadVal(D), StartLoc, EndLoc);
 }
 
 void DeclRefExpr::EmitImpl(Serializer& S) const {
index dd505f6967310ec184f3e5a5f43d748f66727200..bfa1c5e6d0500eae6f08191848e394ad52fd02ed 100644 (file)
@@ -58,11 +58,11 @@ Sema::OwningStmtResult Sema::ActOnDeclStmt(DeclTy *decl,
   assert (!decls.empty());
 
   if (decls.size() == 1) {
-    DeclGroupOwningRef DG(*decls.begin());                      
+    DeclGroupRef DG(*decls.begin());                      
     return Owned(new (Context) DeclStmt(DG, StartLoc, EndLoc));
   }
   else {
-    DeclGroupOwningRef DG(DeclGroup::Create(Context, decls.size(), &decls[0]));
+    DeclGroupRef DG(DeclGroup::Create(Context, decls.size(), &decls[0]));
     return Owned(new (Context) DeclStmt(DG, StartLoc, EndLoc));
   }
 }