__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
// 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) {
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);
+}