[clang] Fix __builtin_object_size calculation for references of unknown origin in C++23 (PR #157778)
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 17 15:54:41 PDT 2025
ahatanak wrote:
Shouldn't it return false even in contexts that don't require constant evaluation?
The following function (adapted from `test/AST/ByteCode/builtin-object-size-codegen.cpp`) returns 16 because `determineEndOffset` uses a conservative lower bound. gcc returns 32.
```
#include <cstdlib>
int foo() {
struct A { char buf[16]; };
struct B : A {};
struct C { int i; B bs[1]; } *c = (C*)malloc(sizeof(C) + sizeof(B));
int gi;
gi = __builtin_object_size(&c->bs[0], 3);
return gi;
}
```
This is exactly the case where the underlying object could become known later.
https://github.com/llvm/llvm-project/pull/157778
More information about the cfe-commits
mailing list