[llvm-bugs] [Bug 39048] NRVO (elide-constructors) code generation is running in the C compiler
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Sep 24 09:14:06 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=39048
Reid Kleckner <rnk at google.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rnk at google.com
Resolution|--- |INVALID
Status|NEW |RESOLVED
--- Comment #1 from Reid Kleckner <rnk at google.com> ---
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: https://gcc.godbolt.org/z/TuzhSJ
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".
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180924/5b104991/attachment.html>
More information about the llvm-bugs
mailing list