[cfe-commits] r44192 - /cfe/trunk/AST/StmtSerialization.cpp

Ted Kremenek kremenek at apple.com
Fri Nov 16 11:00:35 PST 2007


Author: kremenek
Date: Fri Nov 16 13:00:35 2007
New Revision: 44192

URL: http://llvm.org/viewvc/llvm-project?rev=44192&view=rev
Log:
Added assertion in serialization of DeclRefExprs.  DeclRefExprs can only
own the decl they reference if it is a FunctionDecl.  Note that his
ownership property is still considered a hack, and should be fixed.

Modified:
    cfe/trunk/AST/StmtSerialization.cpp

Modified: cfe/trunk/AST/StmtSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtSerialization.cpp?rev=44192&r1=44191&r2=44192&view=diff

==============================================================================
--- cfe/trunk/AST/StmtSerialization.cpp (original)
+++ cfe/trunk/AST/StmtSerialization.cpp Fri Nov 16 13:00:35 2007
@@ -376,7 +376,7 @@
   S.Emit(Loc);
   S.Emit(getType());
   
-  // Some DeclRefExprs can actually hold the owning reference to a decl.
+  // Some DeclRefExprs can actually hold the owning reference to a FunctionDecl.
   // This occurs when an implicitly defined function is called, and
   // the decl does not appear in the source file.  We thus check if the
   // decl pointer has been registered, and if not, emit an owned pointer.
@@ -387,14 +387,19 @@
   //  needs an explicit bit indicating that it owns the the object,
   //  or we need a different ownership model.
   
-  if (S.isRegistered(getDecl())) {
-    S.EmitBool(false);
-    S.EmitPtr(getDecl());
+  const Decl* d = getDecl();
+  
+  if (!S.isRegistered(d)) {
+    assert (isa<FunctionDecl>(d) 
+     && "DeclRefExpr can only own FunctionDecls for implicitly def. funcs.");
+
+    S.EmitBool(true);
+    S.EmitOwnedPtr(d);
   }
   else {
-    S.EmitBool(true);
-    S.EmitOwnedPtr(cast<Decl>(getDecl()));
-  }    
+    S.EmitBool(false);
+    S.EmitPtr(d);
+  }
 }
 
 DeclRefExpr* DeclRefExpr::CreateImpl(Deserializer& D) {





More information about the cfe-commits mailing list