Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions clang/lib/AST/ByteCode/InterpBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2449,10 +2449,14 @@ static bool interp__builtin_object_size(InterpState &S, CodePtr OpPC,
if (Ptr.isBaseClass())
ByteOffset = computePointerOffset(ASTCtx, Ptr.getBase()) -
computePointerOffset(ASTCtx, Ptr);
else
ByteOffset =
computePointerOffset(ASTCtx, Ptr) -
computePointerOffset(ASTCtx, Ptr.expand().atIndex(0).narrow());
else {
if (Ptr.inArray())
ByteOffset =
computePointerOffset(ASTCtx, Ptr) -
computePointerOffset(ASTCtx, Ptr.expand().atIndex(0).narrow());
else
ByteOffset = 0;
}
} else
ByteOffset = computePointerOffset(ASTCtx, Ptr);

Expand Down
3 changes: 2 additions & 1 deletion clang/test/AST/ByteCode/builtin-object-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ static_assert(__builtin_object_size(&arrf, 0) == (sizeof(float)*2), "");
static_assert(__builtin_object_size(&arrf[1], 0) == sizeof(float), "");
static_assert(__builtin_object_size(&arrf[2], 0) == 0, "");


constexpr struct { int a; int b; } F{};
static_assert(__builtin_object_size(&F.a, 3) == sizeof(int));

struct S {
int a;
Expand Down