r318258 - PR35214: don't crash if we see an array of unknown bound added to an empty but invalid designator.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 14 19:03:57 PST 2017
Author: rsmith
Date: Tue Nov 14 19:03:56 2017
New Revision: 318258
URL: http://llvm.org/viewvc/llvm-project?rev=318258&view=rev
Log:
PR35214: don't crash if we see an array of unknown bound added to an empty but invalid designator.
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/Sema/const-eval.c
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=318258&r1=318257&r2=318258&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Nov 14 19:03:56 2017
@@ -1351,10 +1351,11 @@ namespace {
Designator.setInvalid();
return;
}
-
- assert(getType(Base)->isPointerType() || getType(Base)->isArrayType());
- Designator.FirstEntryIsAnUnsizedArray = true;
- Designator.addUnsizedArrayUnchecked(ElemTy);
+ if (checkSubobject(Info, E, CSK_ArrayToPointer)) {
+ assert(getType(Base)->isPointerType() || getType(Base)->isArrayType());
+ Designator.FirstEntryIsAnUnsizedArray = true;
+ Designator.addUnsizedArrayUnchecked(ElemTy);
+ }
}
void addArray(EvalInfo &Info, const Expr *E, const ConstantArrayType *CAT) {
if (checkSubobject(Info, E, CSK_ArrayToPointer))
Modified: cfe/trunk/test/Sema/const-eval.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/const-eval.c?rev=318258&r1=318257&r2=318258&view=diff
==============================================================================
--- cfe/trunk/test/Sema/const-eval.c (original)
+++ cfe/trunk/test/Sema/const-eval.c Tue Nov 14 19:03:56 2017
@@ -144,3 +144,11 @@ void *PR28739a = (__int128)(unsigned lon
void *PR28739b = &PR28739b + (__int128)(unsigned long)-1;
__int128 PR28739c = (&PR28739c + (__int128)(unsigned long)-1) - &PR28739c;
void *PR28739d = &(&PR28739d)[(__int128)(unsigned long)-1];
+
+struct PR35214_X {
+ int k;
+ int arr[];
+};
+int PR35214_x;
+int PR35214_y = ((struct PR35214_X *)&PR35214_x)->arr[1]; // expected-error {{not a compile-time constant}}
+int *PR35214_z = &((struct PR35214_X *)&PR35214_x)->arr[1]; // ok, &PR35214_x + 2
More information about the cfe-commits
mailing list