[llvm-dev] [frontend-dev][beginner] Allocation of structures
Davide Italiano via llvm-dev
llvm-dev at lists.llvm.org
Mon May 29 18:20:40 PDT 2017
On Mon, May 29, 2017 at 6:14 PM, Dimitri Racordon via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> Hi all,
>
> I’m pretty new to the list, and to LLVM in general, so please excuse my
> extreme newbiesness.
>
> I’m trying to figure out what would be the appropriate way to implement move
> semantics.
> I’ve been trying to dump the IR produced by clang with some basic C++
> snippet, but I’m afraid it didn’t help me much.
>
> Here’s the example I’ve been playing with (in C++):
>
> struct S {
> S() noexcept: x(new int) {}
> S(S&& other) {
> x = other.x
> other.x = nullptr;
> }
> ~S() {
> delete x;
> }
> };
>
> S f1() {
> auto s = S();
> return s;
> }
>
> S f2() {
> auto s = S();
> return std::move(s);
> }
>
> This of course produces a lot of LLVM code (with -O0), but I think I may
> have figured out most of what’s what. In particular, I’ve been able to
> identify the IR code for `f1` and `f2`, but to my surprise, neither of those
> return a value. Both take a pointer to `S` as parameter, which in turn gets
> passed to the constructor of `S`, and return void.
>
See https://en.wikipedia.org/wiki/Return_value_optimization
--
Davide
"There are no solved problems; there are only problems that are more
or less solved" -- Henri Poincare
More information about the llvm-dev
mailing list