Skip to content

Commit

Permalink
Fix an assertion failure regression in isDesignatorAtObjectEnd for
Browse files Browse the repository at this point in the history
__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

llvm-svn: 321222
  • Loading branch information
hyp committed Dec 20, 2017
1 parent 3f84c0f commit 4e24648
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion clang/lib/AST/ExprConstant.cpp
Expand Up @@ -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<PointerType>()->getPointeeType();
if (BaseType->isIncompleteArrayType())
BaseType = Ctx.getAsArrayType(BaseType)->getElementType();
else
BaseType = BaseType->castAs<PointerType>()->getPointeeType();
}

for (unsigned E = LVal.Designator.Entries.size(); I != E; ++I) {
Expand Down
19 changes: 19 additions & 0 deletions clang/test/Sema/builtin-object-size.c
Expand Up @@ -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);
}

0 comments on commit 4e24648

Please sign in to comment.