Fix double-free error with sizeof applied to VLA types.
- 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
diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h
index 00de023..b84ca02 100644
--- a/include/clang/AST/Expr.h
+++ b/include/clang/AST/Expr.h
@@ -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; }
diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp
index a7e49d0..49c76a8 100644
--- a/lib/AST/Expr.cpp
+++ b/lib/AST/Expr.cpp
@@ -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
//===----------------------------------------------------------------------===//
diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp
index 1cdd798..e302f2b 100644
--- a/lib/CodeGen/CodeGenTypes.cpp
+++ b/lib/CodeGen/CodeGenTypes.cpp
@@ -352,6 +352,10 @@
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
index 0000000..faf934d
--- /dev/null
+++ b/test/Sema/PR2727.c
@@ -0,0 +1,5 @@
+int f (int x)
+{
+ // sizeof applied to a type should not delete the type.
+ return sizeof (int[x]);
+}