[cfe-commits] r55479 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/Expr.cpp lib/CodeGen/CodeGenTypes.cpp test/Sema/PR2727.c

Daniel Dunbar daniel at zuster.org
Thu Aug 28 11:02:04 PDT 2008


Author: ddunbar
Date: Thu Aug 28 13:02:04 2008
New Revision: 55479

URL: http://llvm.org/viewvc/llvm-project?rev=55479&view=rev
Log:
Fix double-free error with sizeof applied to VLA types.
 - PR2727.

Also, fix warning in CodeGenTypes for new BlockPointer type.

Added:
    cfe/trunk/test/Sema/PR2727.c
Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/lib/CodeGen/CodeGenTypes.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=55479&r1=55478&r2=55479&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Thu Aug 28 13:02:04 2008
@@ -540,6 +540,8 @@
     Expr(SizeOfAlignOfTypeExprClass, resultType),
     isSizeof(issizeof), Ty(argType), OpLoc(op), RParenLoc(rp) {}
   
+  virtual void Destroy(ASTContext& C);
+
   bool isSizeOf() const { return isSizeof; }
   QualType getArgumentType() const { return Ty; }
   

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=55479&r1=55478&r2=55479&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Thu Aug 28 13:02:04 2008
@@ -1236,6 +1236,11 @@
   return ::evaluateOffsetOf(C, cast<Expr>(Val)) / CharSize;
 }
 
+void SizeOfAlignOfTypeExpr::Destroy(ASTContext& C) {
+  // Override default behavior of traversing children. We do not want
+  // to delete the type.
+}
+
 //===----------------------------------------------------------------------===//
 //  Child Iterators for iterating over subexpressions/substatements
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTypes.cpp?rev=55479&r1=55478&r2=55479&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTypes.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTypes.cpp Thu Aug 28 13:02:04 2008
@@ -352,6 +352,10 @@
     TheModule.addTypeName(TypeName, Res);  
     return Res;
   }
+
+  case Type::BlockPointer: {
+    assert(0 && "FIXME: Cannot get type of block pointer.");
+  }
   }
   
   // FIXME: implement.

Added: cfe/trunk/test/Sema/PR2727.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/PR2727.c?rev=55479&view=auto

==============================================================================
--- cfe/trunk/test/Sema/PR2727.c (added)
+++ cfe/trunk/test/Sema/PR2727.c Thu Aug 28 13:02:04 2008
@@ -0,0 +1,5 @@
+int f (int x)
+{
+  // sizeof applied to a type should not delete the type.
+  return sizeof (int[x]);
+}





More information about the cfe-commits mailing list