public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57175] New: NRVO and alignment
@ 2013-05-05 13:28 glisse at gcc dot gnu.org
  2013-05-05 13:30 ` [Bug c++/57175] " paolo.carlini at oracle dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-05-05 13:28 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 57175
           Summary: NRVO and alignment
    Classification: Unclassified
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: glisse@gcc.gnu.org


Hello,

in typeck.c (check_return_expr), before applying the NRV optimization, there is
a check: DECL_ALIGN (retval) >= DECL_ALIGN (result)

It seems to me that this check is backwards and should be <= instead (compare
with tree_nrv in tree-nrv.c which seems correct).

#include <iostream>
struct A {
  A(){std::cerr<<"A()\n";}
  ~A(){std::cerr<<"~A()\n";}
  A(A&&){std::cerr<<"A(A&&)\n";}
  A(A const&){std::cerr<<"A(A const&)\n";}
};
A f(){
  alignas(32) A x;
  return x;
}
int main(){
  f();
}

If I understand NRVO properly, main reserves memory for the return value of f
and passes f the address of that memory. f then decides to use that memory
directly for x instead of allocating new memory that would have to be copied
later. So the return memory needs to be at least as aligned as x, not the
reverse (I think retval corresponds to x here).

Current g++ does the elision on this code. If I change >= to <=, it inhibits
the elision.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/57175] NRVO and alignment
  2013-05-05 13:28 [Bug c++/57175] New: NRVO and alignment glisse at gcc dot gnu.org
@ 2013-05-05 13:30 ` paolo.carlini at oracle dot com
  2013-05-05 23:34 ` paolo.carlini at oracle dot com
  2013-05-20  7:52 ` glisse at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-05-05 13:30 UTC (permalink / raw)
  To: gcc-bugs


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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #1 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-05-05 13:30:53 UTC ---
CCing Jason.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/57175] NRVO and alignment
  2013-05-05 13:28 [Bug c++/57175] New: NRVO and alignment glisse at gcc dot gnu.org
  2013-05-05 13:30 ` [Bug c++/57175] " paolo.carlini at oracle dot com
@ 2013-05-05 23:34 ` paolo.carlini at oracle dot com
  2013-05-20  7:52 ` glisse at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-05-05 23:34 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from Paolo Carlini <paolo.carlini at oracle dot com> 2013-05-05 23:34:52 UTC ---
Thanks Eric. Without further ado, I would simply encourage Marc to send a
patchlet to the mailing list (possibly with a nice testcase). Thanks!


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/57175] NRVO and alignment
  2013-05-05 13:28 [Bug c++/57175] New: NRVO and alignment glisse at gcc dot gnu.org
  2013-05-05 13:30 ` [Bug c++/57175] " paolo.carlini at oracle dot com
  2013-05-05 23:34 ` paolo.carlini at oracle dot com
@ 2013-05-20  7:52 ` glisse at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-05-20  7:52 UTC (permalink / raw)
  To: gcc-bugs

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

Marc Glisse <glisse at gcc dot gnu.org> changed:

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

--- Comment #4 from Marc Glisse <glisse at gcc dot gnu.org> ---
r199093 | glisse | 2013-05-20 09:50:54 +0200 (Mon, 20 May 2013) | 10 lines

2013-05-20  Marc Glisse  <marc.glisse@inria.fr>

    PR c++/57175
gcc/cp/
    * typeck.c (check_return_expr): Reverse the alignment comparison.

gcc/testsuite/
    * g++.dg/pr57175.C: New testcase.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-05-20  7:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-05 13:28 [Bug c++/57175] New: NRVO and alignment glisse at gcc dot gnu.org
2013-05-05 13:30 ` [Bug c++/57175] " paolo.carlini at oracle dot com
2013-05-05 23:34 ` paolo.carlini at oracle dot com
2013-05-20  7:52 ` glisse at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).