summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-12-22 17:13:37 +0000
committerDouglas Gregor <dgregor@apple.com>2009-12-22 17:13:37 +0000
commit2e9c795df03b73f020366125157bad9e17672083 (patch)
tree8ed0b79e81de58ce192a3c28b6230eaee49574b3 /clang/lib
parentbbeb5c391ca99b71ccb39df0aa7bc3197e66e0a6 (diff)
downloadbcm5719-llvm-2e9c795df03b73f020366125157bad9e17672083.tar.gz
bcm5719-llvm-2e9c795df03b73f020366125157bad9e17672083.zip
When transforming a C++ "new" expression that was not explicitly given
a size, check whether the transformed type is itself an array type. If so, take the major array bound as the size to allocate. Fixes PR5833. llvm-svn: 91907
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/TreeTransform.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 8c84d4a95ac..5152a297556 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -4481,6 +4481,31 @@ TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
!ArgumentChanged)
return SemaRef.Owned(E->Retain());
+ if (!ArraySize.get()) {
+ // If no array size was specified, but the new expression was
+ // instantiated with an array type (e.g., "new T" where T is
+ // instantiated with "int[4]"), extract the outer bound from the
+ // array type as our array size. We do this with constant and
+ // dependently-sized array types.
+ const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
+ if (!ArrayT) {
+ // Do nothing
+ } else if (const ConstantArrayType *ConsArrayT
+ = dyn_cast<ConstantArrayType>(ArrayT)) {
+ ArraySize
+ = SemaRef.Owned(new (SemaRef.Context) IntegerLiteral(
+ ConsArrayT->getSize(),
+ SemaRef.Context.getSizeType(),
+ /*FIXME:*/E->getLocStart()));
+ AllocType = ConsArrayT->getElementType();
+ } else if (const DependentSizedArrayType *DepArrayT
+ = dyn_cast<DependentSizedArrayType>(ArrayT)) {
+ if (DepArrayT->getSizeExpr()) {
+ ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()->Retain());
+ AllocType = DepArrayT->getElementType();
+ }
+ }
+ }
return getDerived().RebuildCXXNewExpr(E->getLocStart(),
E->isGlobalNew(),
/*FIXME:*/E->getLocStart(),
OpenPOWER on IntegriCloud