patch: honor volatile bitfield types

Manuel López-Ibáñez lopezibanez@gmail.com
Tue Jun 15 08:32:00 GMT 2010


On 15 June 2010 03:20, DJ Delorie <dj@redhat.com> wrote:
>
>> And, the field name should definitely be mentioned if at all
>> possible.
>
> Sigh, not possible without major code changes.  This is the problem I
> ran into writing the patch itself - the decls are all long since lost
> by the time we get to these routines, and some of the paths that lead
> to them make it very difficult to keep track of them (if they're
> available at all).
>
> How's this for the message?
>
>
>              if (bitsize == total_bits)
>                warning (0, "mis-aligned access used for structure member");
>              else
>                warning (0, "mis-aligned access used for structure bitfield");
>
>              if (! warned_about_misalignment)
>                {
>                  warned_about_misalignment = true;
>                  warning (0, "volatile objects require a single access to preserve their"
>                           " volatility, but this member spans multiple type-sized locations."
>                           " Normally the compiler would use multiple accesses for such fields"
>                           " to avoid mis-aligned accesses.  This code may fail at runtime")
>                }
>

You should use "inform" for such follow-up notes. Since the warning is
only enabled by fstrict-volatile-fields, you can use
OPT_fstrict_volatile_fields instead of 0. This way the option will be
shown alongside the warning.

I guess it is impossible to get a precise location here. I still would
prefer to use warning_at (input_location to remind us that this should
be fixed in the future.

Cheers,

Manuel.



More information about the Gcc-patches mailing list