https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129247
Bug ID: 129247
Summary: wrong code at -O2: __builtin_dynamic_object_size
returns 0 for an access size of 2^64
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: kyuwoncho18 at gmail dot com
Target Milestone: ---
Target: x86_64-pc-linux-gnu
#include <stdio.h>
typedef unsigned __int128 u128;
__attribute__((noinline, access(read_only, 1, 2)))
size_t f(const char *p, u128 n)
{
return __builtin_dynamic_object_size(p, 0);
}
int main(void)
{
char a = 0;
printf("%zu\n", f(&a, (u128)1 << 64));
}
godbolt: https://godbolt.org/z/onPsfEhxM
At -O0 the program prints 18446744073709551615, while at -O2 it prints 0. The
access size 2^64 cannot be represented by size_t, so the type-0 object-size
query must report an unknown size as (size_t)-1; 18446744073709551615 is the
correct output on this target.