From: Alex Lorenz Date: Wed, 20 Dec 2017 21:03:38 +0000 (+0000) Subject: Fix an assertion failure regression in isDesignatorAtObjectEnd for X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1c11a98e84f2d2ca40b963cb0b2511eddbef963f;p=clang Fix an assertion failure regression in isDesignatorAtObjectEnd for __builtin_object_size with incomplete array type in struct The commit r316245 introduced a regression that causes an assertion failure when Clang tries to cast an IncompleteArrayType to a PointerType when evaluating __builtin_object_size. rdar://36094951 Differential Revision: https://reviews.llvm.org/D41405 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@321222 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 7b0b7317cd..8d9b3c3beb 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -7420,7 +7420,10 @@ static bool isDesignatorAtObjectEnd(const ASTContext &Ctx, const LValue &LVal) { // If we don't know the array bound, conservatively assume we're looking at // the final array element. ++I; - BaseType = BaseType->castAs()->getPointeeType(); + if (BaseType->isIncompleteArrayType()) + BaseType = Ctx.getAsArrayType(BaseType)->getElementType(); + else + BaseType = BaseType->castAs()->getPointeeType(); } for (unsigned E = LVal.Designator.Entries.size(); I != E; ++I) { diff --git a/test/Sema/builtin-object-size.c b/test/Sema/builtin-object-size.c index 300c739bbd..096882a088 100644 --- a/test/Sema/builtin-object-size.c +++ b/test/Sema/builtin-object-size.c @@ -91,3 +91,22 @@ int pr31843() { return n; } + +typedef struct { + char string[512]; +} NestedArrayStruct; + +typedef struct { + int x; + NestedArrayStruct session[]; +} IncompleteArrayStruct; + +void rd36094951_IAS_builtin_object_size_assertion(IncompleteArrayStruct *p) { +#define rd36094951_CHECK(mode) \ + __builtin___strlcpy_chk(p->session[0].string, "ab", 2, \ + __builtin_object_size(p->session[0].string, mode)) + rd36094951_CHECK(0); + rd36094951_CHECK(1); + rd36094951_CHECK(2); + rd36094951_CHECK(3); +}