diff options
| author | Richard Trieu <rtrieu@google.com> | 2013-05-16 01:46:09 +0000 |
|---|---|---|
| committer | Richard Trieu <rtrieu@google.com> | 2013-05-16 01:46:09 +0000 |
| commit | ee2f8f2f7c4eacfa305a29fcd916d63c650ca847 (patch) | |
| tree | 51fc5b5b4a521de0792f4b3a66e0b9f26458f100 | |
| parent | c8812a23609af58a90ea9e093b38a0815e6dd9eb (diff) | |
| download | clang-ee2f8f2f7c4eacfa305a29fcd916d63c650ca847.tar.gz clang-ee2f8f2f7c4eacfa305a29fcd916d63c650ca847.tar.bz2 clang-ee2f8f2f7c4eacfa305a29fcd916d63c650ca847.tar.xz | |
Return QualType() when a too large array is attempting to be created. This
prevents further errors and some overflows in size calculations.
One overflow was previously triggering an assert.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181970 91177308-0d34-0410-b5e6-96231b3b80d8
| -rw-r--r-- | lib/Sema/SemaType.cpp | 4 | ||||
| -rw-r--r-- | test/Sema/offsetof-64.c | 13 |
2 files changed, 13 insertions, 4 deletions
diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 0959f7d66a..e4eafc5ee7 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -1549,10 +1549,12 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, // Is the array too large? unsigned ActiveSizeBits = ConstantArrayType::getNumAddressingBits(Context, T, ConstVal); - if (ActiveSizeBits > ConstantArrayType::getMaxSizeBits(Context)) + if (ActiveSizeBits > ConstantArrayType::getMaxSizeBits(Context)) { Diag(ArraySize->getLocStart(), diag::err_array_too_large) << ConstVal.toString(10) << ArraySize->getSourceRange(); + return QualType(); + } } T = Context.getConstantArrayType(T, ConstVal, ASM, Quals); diff --git a/test/Sema/offsetof-64.c b/test/Sema/offsetof-64.c index 1cabec9842..fb3d6e98d1 100644 --- a/test/Sema/offsetof-64.c +++ b/test/Sema/offsetof-64.c @@ -1,15 +1,22 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -triple x86_64-linux-gnu -// expected-no-diagnostics // PR15216 // Don't crash when taking computing the offset of structs with large arrays. const unsigned long Size = (1l << 62); -struct Chunk { +struct Chunk1 { char padding[Size]; char more_padding[1][Size]; char data; }; -int test1 = __builtin_offsetof(struct Chunk, data); +int test1 = __builtin_offsetof(struct Chunk1, data); +struct Chunk2 { + char padding[Size][Size][Size]; // expected-error 2{{array is too large}} + char data; +}; + +// FIXME: Remove this error when the constant evaluator learns to +// ignore bad types. +int test2 = __builtin_offsetof(struct Chunk2, data); // expected-error{{initializer element is not a compile-time constant}} |
