[Bug c++/77388] Reference to a packed structure member

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Aug 26 10:21:00 GMT 2016


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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
This happens on x86_64 as well and is because you invoke undefined behavior
when extending the lifetime of A::c across the lifetime of the object
it refers to.  s->c is an rvalue here because it's type isn't compatible
due to the mismatched alignment and thus a temporary of correct alignment
is build and the address of that is passed to A::A.

I suppose the FE could emit a warning here.

Oh, and the .optimized you see is because the FE emits a CLOBBER to explicitely
end the lifetime of said temporary:


A B::foo() (struct B * const this)
{
  const short int & SR.1;
  const short int D.2330;
  struct A D.2331;
  struct A D.2342;
  struct test_struct * _1;
  short int _2;

  <bb 2>:
  _1 = this_4(D)->s;
  _2 = _1->c;
  D.2330 = _2;
  MEM[(struct A *)&D.2342] = &D.2330;
  D.2330 ={v} {CLOBBER};
  return D.2342;

thus we can DSE the store to D.2330.


More information about the Gcc-bugs mailing list