| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-additional-options "-std=gnu++20" { target c++ } } */ |
| 3 |
|
| 4 |
struct B {}; |
| 5 |
struct A { int a; |
| 6 |
#ifdef __cplusplus |
| 7 |
[[no_unique_address]] |
| 8 |
#endif |
| 9 |
struct B b; |
| 10 |
char c[]; }; |
| 11 |
volatile void *p; |
| 12 |
|
| 13 |
void __attribute__((noipa)) |
| 14 |
bar (void *q) |
| 15 |
{ |
| 16 |
p = q; |
| 17 |
} |
| 18 |
|
| 19 |
__SIZE_TYPE__ __attribute__((noipa)) |
| 20 |
foo (struct A *p) |
| 21 |
{ |
| 22 |
bar (&p->b); |
| 23 |
bar (&p->c); |
| 24 |
return __builtin_object_size (&p->c, 1); |
| 25 |
} |
| 26 |
|
| 27 |
__SIZE_TYPE__ __attribute__((noipa)) |
| 28 |
baz (void) |
| 29 |
{ |
| 30 |
struct A *p = (struct A *) __builtin_malloc (__builtin_offsetof (struct A, c) + 64); |
| 31 |
bar (&p->b); |
| 32 |
bar (&p->c); |
| 33 |
return __builtin_object_size (&p->c, 1); |
| 34 |
} |
| 35 |
|
| 36 |
__SIZE_TYPE__ __attribute__((noipa)) |
| 37 |
qux (struct A *p) |
| 38 |
{ |
| 39 |
bar (&p->b); |
| 40 |
bar (&p->c); |
| 41 |
return __builtin_object_size (&p->c, 3); |
| 42 |
} |
| 43 |
|
| 44 |
__SIZE_TYPE__ __attribute__((noipa)) |
| 45 |
boo (void) |
| 46 |
{ |
| 47 |
struct A *p = (struct A *) __builtin_malloc (__builtin_offsetof (struct A, c) + 64); |
| 48 |
bar (&p->b); |
| 49 |
bar (&p->c); |
| 50 |
return __builtin_object_size (&p->c, 3); |
| 51 |
} |
| 52 |
|
| 53 |
int |
| 54 |
main () |
| 55 |
{ |
| 56 |
static struct A a = { .a = 1, .b = {}, .c = { 1, 2, 3, 4, 0 } }; |
| 57 |
if (foo (&a) < 5) |
| 58 |
__builtin_abort (); |
| 59 |
if (baz () < 64) |
| 60 |
__builtin_abort (); |
| 61 |
} |