[Bug c++/58116] missed-optimization: const temporaries could be promoted to static

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Jan 17 23:36:00 GMT 2014


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58116

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Actually this is an invalid optimization.

Take:
struct S
{
  int a, b, c;
};

extern void callee(const S &s);

void test()
{
  const S s{1,2,3};
  callee(s);

  callee((const S){1,2,3});
}

void test1()
{
  callee((const S){1,2,3});
}

void callee(const S &s)
{
  static const S *a;
  if (!a)
    {
      a = &s;
      test();
    }
  if (a == &s)
    __builtin_abort();
  return;
}

>From http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59863#c1:
If the object address can escape and the function can be called 
recursively, this would violate the requirement for distinct objects to 
have distinct addresses.  (See discussion on comp.std.c, "uniqueness of 
automatic objects", Nov 2008; I'm not sure if there was a corresponding 
GCC bug report / fix.)



More information about the Gcc-bugs mailing list