[PATCH] PR12208 - Problem with -fno-elide-constructors

David Wiberg dwiberg at gmail.com
Wed Dec 25 00:30:23 PST 2013


Hello all,

The attached patch adds a test-case for which incorrect code is
generated and a change which makes the test pass.

>From what I could tell the following happened:
1. Sema::computeNRVO marked a variable as suitable for NRVO
2. CodeGenFunction::EmitAutoVarAlloca handled allocating variables to
the return slot based on getLangOpts().ElideConstructors and the flag
set by Sema.
3. CodeGenFunction::EmitReturnStmt only looked at the flag set by Sema
to determine if necessary to emit a return statement.

The patch changes EmitReturnStmt to require that the ElideConstructors
flag is set to perform NRVO. Another option (which perhaps is better)
would be to let Sema::computeNRVO return early if ElideConstructors
wasn't set and remove the ElideConstructors check within
EmitAutoVarAlloca. Since I haven't worked with this code before I
opted for the least intrusive change.

Best regards
David
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr12208.patch
Type: application/octet-stream
Size: 1392 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131225/c2cf3729/attachment.obj>


More information about the cfe-commits mailing list