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

My initial report text was apparently lost in the Bugzilla migration, so here I
am submitting it again.

----

In this code:

    #include <stdint.h>

    struct foo {
        uint16_t a, b;
    } __attribute__((packed));

    extern struct foo *f(void);
    extern void g(uint16_t *p);

    void h(void) {
        struct foo *s0 = __builtin_assume_aligned(f(), 16);
        g(&s0->a);

        struct foo s1 __attribute__ ((aligned(16)));
        g(&s1.a);
    }

GCC will warn about taking the address of s0->a and s1.a, even though it has
enough information to recognise those as false positives.

On many platforms, variables on the stack are naturally aligned at a 32-bit (or
coarser) boundary, so I believe &s1.a is a false positive on those platforms
even without the attribute, but I’m less sure if skipping the warning for this
case is desirable.

Reply via email to