Hello,

I pushed the following commit to mob:

    a338258d Fix qualifiers on const array struct members

This fixes the false warning reported by Patrick Pélissier for code that takes
the address of an array member through a pointer to const struct:

    typedef int int_array[1];
    typedef struct { int_array arr; } my_struct;

    int_array const *get_array(const my_struct *s)
    {
        return &(s->arr);
    }

Before the fix, TinyCC emitted:

    warning: assignment discards qualifiers from pointer target type

This was a TinyCC bug. When selecting a field from a const or volatile 
aggregate,
TinyCC propagated the aggregate qualifier by OR-ing it into the selected field's
top-level type. This is not correct for array members, because array types are
represented with the array layer separate from the element type. The qualifier
has to be applied to the element type instead.

The fix changes the field-selection code in tccgen.c to use the existing
array-aware qualifier helper, parse_btype_qualify(), instead of directly OR-ing
the qualifier bits. This keeps the original valid pointer-to-array and array
decay cases silent, while preserving warnings for discarded const/volatile
qualifiers and writes through const array members.

I also added regression tests covering:

    - address-of const array member: no warning
    - decay of const array member: no warning
    - discarded const qualifiers: warning
    - write through const array member: warning
    - array of structs under const aggregate: warning on write
    - equivalent volatile array member cases

Validation:

    make test

completed successfully with:

    ALL TESTS PASSED

Regards,

Mounir IDRASSI




_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

Reply via email to