diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-08-18 00:39:00 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-08-18 00:39:00 +0000 |
commit | caa1bf434d93a9cd583e05c8247649276ad3eeba (patch) | |
tree | 7dbbef626f45c1123abe1a38dd8022c57ef6246e /clang/lib/Sema/SemaExprCXX.cpp | |
parent | b91c903f461b2d92675aca44481742df0b6daca7 (diff) | |
download | bcm5719-llvm-caa1bf434d93a9cd583e05c8247649276ad3eeba.tar.gz bcm5719-llvm-caa1bf434d93a9cd583e05c8247649276ad3eeba.zip |
Emit an error if an array is too large. We're slightly more strict
than GCC 4.2 here when building 32-bit (where GCC will allow
allocation of an array for which we can't get a valid past-the-end
pointer), and emulate its odd behavior in 64-bit where it only allows
63 bits worth of storage in the array. The former is a correctness
issue; the latter is harmless in practice (you wouldn't be able to use
such an array anyway) and helps us pass a GCC DejaGNU test.
Fixes <rdar://problem/8212293>.
llvm-svn: 111338
Diffstat (limited to 'clang/lib/Sema/SemaExprCXX.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 35e679f53e7..5e46090c058 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -716,8 +716,20 @@ Sema::BuildCXXNew(SourceLocation StartLoc, bool UseGlobal, llvm::APInt::getNullValue(Value.getBitWidth()), Value.isUnsigned())) return ExprError(Diag(ArraySize->getSourceRange().getBegin(), - diag::err_typecheck_negative_array_size) + diag::err_typecheck_negative_array_size) << ArraySize->getSourceRange()); + + if (!AllocType->isDependentType()) { + unsigned ActiveSizeBits + = ConstantArrayType::getNumAddressingBits(Context, AllocType, Value); + if (ActiveSizeBits > ConstantArrayType::getMaxSizeBits(Context)) { + Diag(ArraySize->getSourceRange().getBegin(), + diag::err_array_too_large) + << Value.toString(10) + << ArraySize->getSourceRange(); + return ExprError(); + } + } } else if (TypeIdParens.isValid()) { // Can't have dynamic array size when the type-id is in parentheses. Diag(ArraySize->getLocStart(), diag::ext_new_paren_array_nonconst) |