]> granicus.if.org Git - clang/commitdiff
Fix double-free error with sizeof applied to VLA types.
authorDaniel Dunbar <daniel@zuster.org>
Thu, 28 Aug 2008 18:02:04 +0000 (18:02 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 28 Aug 2008 18:02:04 +0000 (18:02 +0000)
 - PR2727.

Also, fix warning in CodeGenTypes for new BlockPointer type.

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

include/clang/AST/Expr.h
lib/AST/Expr.cpp
lib/CodeGen/CodeGenTypes.cpp
test/Sema/PR2727.c [new file with mode: 0644]

index 00de0233b451309c88ee72ac5c62f09c14a39ade..b84ca020a1ab14fbfdff772a7bd63865bd147c83 100644 (file)
@@ -540,6 +540,8 @@ public:
     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; }
   
index a7e49d0efcd5af111b5f62f9d2ecff951e255d77..49c76a89d8639ea9b76c1854c5eac5ec75002c9c 100644 (file)
@@ -1236,6 +1236,11 @@ int64_t UnaryOperator::evaluateOffsetOf(ASTContext& C) const
   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
 //===----------------------------------------------------------------------===//
index 1cdd798a3971d5c0af3e2689a83f745f319141c7..e302f2b9ec989f55d6d5bc1017a16bac9ee19674 100644 (file)
@@ -352,6 +352,10 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) {
     TheModule.addTypeName(TypeName, Res);  
     return Res;
   }
+
+  case Type::BlockPointer: {
+    assert(0 && "FIXME: Cannot get type of block pointer.");
+  }
   }
   
   // FIXME: implement.
diff --git a/test/Sema/PR2727.c b/test/Sema/PR2727.c
new file mode 100644 (file)
index 0000000..faf934d
--- /dev/null
@@ -0,0 +1,5 @@
+int f (int x)
+{
+  // sizeof applied to a type should not delete the type.
+  return sizeof (int[x]);
+}