https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125995

--- Comment #4 from Victor Arvidsson <victarv at gmail dot com> ---
The above code and test case only fails when compiling without optimizations,
however, the program can be adapted to also fail with optimizations enabled:

bar.h:
```
#ifndef BAR_H
#define BAR_H

struct Foo {
    int baz;
    int qux;
};

struct Bar {
    struct Foo foo;
};

const struct Bar* get_bar();

#endif // BAR_H
```

bar.c:
```
#include "bar.h"

static constexpr struct Bar b = {
    .foo = {
        .baz = 1
    }
};

const struct Bar* get_bar() {
    struct Foo foo = b.foo;
    return &b;
}
```

main.c:
```
#include "bar.h"

int main() {
    int a = 1;
    int diff = __builtin_memcmp(&get_bar()->foo.baz, &a, sizeof(a));
    if (diff)
        __builtin_abort();
    return 0;
}
```
Compiled with `gcc -std=c23 -O2 main.c bar.c`.

Reply via email to