This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Type-punning warnings [was Re: PATCH: silence warnings in unwind-dw2-fde.c]


Andrew Haley wrote:
> Dave Korn wrote:
>> Ben Elliston wrote:
>>> This patch silences the following warnings when building libgcc:
>>>
>>> unwind-dw2-fde.c:321: warning: dereferencing type-punned pointer will break
>>> strict-aliasing rules
>>> -  const _Unwind_Ptr x_ptr = *(const _Unwind_Ptr *) x->pc_begin;
>>> -  const _Unwind_Ptr y_ptr = *(const _Unwind_Ptr *) y->pc_begin;
>>> +  _Unwind_Ptr x_ptr, y_ptr;
>>> +  memcpy (&x_ptr, x->pc_begin, sizeof (_Unwind_Ptr));
>>> +  memcpy (&y_ptr, y->pc_begin, sizeof (_Unwind_Ptr));
>>   Say, I've been in the habit in the past (GCC 3.x) of avoiding these warnings
>> by doing like:
>>
>>> -  const _Unwind_Ptr x_ptr = *(const _Unwind_Ptr *) x->pc_begin;
>>> -  const _Unwind_Ptr y_ptr = *(const _Unwind_Ptr *) y->pc_begin;
>>> +  const _Unwind_Ptr x_ptr = *(const _Unwind_Ptr *) (void *) x->pc_begin;
>>> +  const _Unwind_Ptr y_ptr = *(const _Unwind_Ptr *) (void *) y->pc_begin;
>> ... which I see no longer works.  Was that ever correct, or was I just losing
>> information during the cast-to-void that meant GCC just couldn't diagnose a
>> potential problem, but it was still there?  I believed that casting through
>> void would make the result could-alias-anything, which I thought would prevent
>> any untoward consequences.
> 
> Casting via void* just shuts up a warning; the bad code is still there.

  Oh, ow.

> But this case should be fine AFAICS, because pc_begin is char[].  I'm not
> sure why we get the warning.

  And casting through void just doubles the number of warnings in this case!

    cheers,
      DaveK


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]