This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/58116] missed-optimization: const temporaries could be promoted to static
- From: "pinskia at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 17 Jan 2014 23:36:22 +0000
- Subject: [Bug c++/58116] missed-optimization: const temporaries could be promoted to static
- Auto-submitted: auto-generated
- References: <bug-58116-4 at http dot gcc dot gnu dot org/bugzilla/>
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.)