<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div class="">Hi all,</div>
<div class=""><br class="">
</div>
<div class="">I’m pretty new to the list, and to LLVM in general, so please excuse my extreme newbiesness.</div>
<div class=""><br class="">
</div>
<div class="">I’m trying to figure out what would be the appropriate way to implement move semantics.</div>
<div class="">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.</div>
<div class=""><br class="">
</div>
<div class="">Here’s the example I’ve been playing with (in C++):</div>
<div class=""><br class="">
</div>
<div class="">
<div class=""><font face="Menlo" class="">struct S {</font></div>
<div class=""><font face="Menlo" class="">  S() noexcept: x(new int) {}</font></div>
<div class=""><font face="Menlo" class="">  S(S&& other) {</font></div>
<div class=""><font face="Menlo" class="">    x = other.x</font></div>
<div class=""><font face="Menlo" class="">    other.x = nullptr;</font></div>
<div class=""><font face="Menlo" class="">  }</font></div>
<div class=""><font face="Menlo" class="">  ~S() {</font></div>
<div class=""><font face="Menlo" class="">    delete x;</font></div>
<div class=""><font face="Menlo" class="">  }</font></div>
<div class=""><font face="Menlo" class="">};</font></div>
<div class=""><font face="Menlo" class=""><br class="">
</font></div>
<div class=""><font face="Menlo" class="">S f1() {</font></div>
<div class=""><font face="Menlo" class="">  auto s = S();</font></div>
<div class=""><font face="Menlo" class="">  return s;</font></div>
<div class=""><font face="Menlo" class="">}</font></div>
<div class=""><font face="Menlo" class=""><br class="">
</font></div>
<div class="">
<div class=""><font face="Menlo" class="">S f2() {</font></div>
<div class=""><font face="Menlo" class="">  auto s = S();</font></div>
<div class=""><font face="Menlo" class="">  return std::move(s);</font></div>
<div class=""><font face="Menlo" class="">}</font></div>
</div>
</div>
<div class=""><br class="">
</div>
<div class="">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.</div>
<div class=""><br class="">
</div>
<div class="">This leaves me with two main questions:</div>
<div class="">
<ul class="MailOutline">
<li class="">First, is the use of a pointer to S as parameter a specificity of clang, or generally the way to go? I’ve seen in the language reference that one could return a struct with a simple ret instruction, so I’m surprised not to see it for the version
 that doesn’t use move semantics.</li><li class="">Second, would I use a non-void ret instruction to return the result of an alloca, when would the latter be destroyed? Would that involve a copy from the runtime stack of the callee to that of the caller?</li></ul>
<div class=""><br class="">
</div>
</div>
<div class="">Thank you very much for your time and your answer,</div>
<div class=""><br class="">
</div>
<div class="">Best,</div>
<div class=""><br class="">
</div>
<br class="">
<div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Dimitri Racordon<br class="">
CUI, Université de Genève<br class="">
7, route de Drize, CH-1227 Carouge - Switzerland<br class="">
Phone: +41 22 379 01 24
<div class=""><br class="">
</div>
</div>
<br class="Apple-interchange-newline">
<br class="Apple-interchange-newline">
</div>
<br class="">
</div>
</body>
</html>