<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><span class="vcard"><a class="email" href="mailto:rnk@google.com" title="Reid Kleckner <rnk@google.com>"> <span class="fn">Reid Kleckner</span></a>
</span> changed
          <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - NRVO (elide-constructors) code generation is running in the C compiler"
   href="https://bugs.llvm.org/show_bug.cgi?id=39048">bug 39048</a>
          <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">CC</td>
           <td>
                
           </td>
           <td>rnk@google.com
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>---
           </td>
           <td>INVALID
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>RESOLVED
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - NRVO (elide-constructors) code generation is running in the C compiler"
   href="https://bugs.llvm.org/show_bug.cgi?id=39048#c1">Comment # 1</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - NRVO (elide-constructors) code generation is running in the C compiler"
   href="https://bugs.llvm.org/show_bug.cgi?id=39048">bug 39048</a>
              from <span class="vcard"><a class="email" href="mailto:rnk@google.com" title="Reid Kleckner <rnk@google.com>"> <span class="fn">Reid Kleckner</span></a>
</span></b>
        <pre>The optimization applies to C in cases like this:

struct BigStruct { long x, y, z, w; };
struct BigStruct foo(int a) {
  struct BigStruct rv = {};
  return rv;
}

You can see the LLVM IR difference by adding and removing the flag more clearly
on godbolt: <a href="https://gcc.godbolt.org/z/TuzhSJ">https://gcc.godbolt.org/z/TuzhSJ</a>

In this case, the optimization will avoid allocating memory for rv in foo, and
will use the out parameter allocated in the caller's stack frame.

It is by design that we do this by default in C as well as C++. It has nothing
to do with constructors, really. My understanding of the history is that Clang
implemented NRVO by default, and then someone came along and added the
non-default -fno-elide-constructors option for code bases that needed it.

Marking "invalid" to mean "working as intended".</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>