<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Nov 3, 2017 at 5:39 PM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="#FFFFFF" text="#000000"><div><div class="h5">
    <div class="m_-6457140989512367091moz-cite-prefix">On 11/03/2017 07:20 PM, Alexandre
      Isoard via llvm-dev wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">Hello,
        <div><br>
        </div>
        <div>I am not sure about the semantic (if any) of returns_twice
          and noreturn attributes.</div>
        <div><br>
        </div>
        <div><font face="monospace, monospace">int fork()
            __attribute__((returns_twice))<wbr>;</font></div>
        <div><font face="monospace, monospace">void join(int)
            __attribute__((noreturn));</font></div>
        <div><font face="monospace, monospace"><br>
          </font></div>
        <div><font face="monospace, monospace">int f(int n) {</font></div>
        <div><font face="monospace, monospace">  int t = fork();</font></div>
        <div><font face="monospace, monospace">  n++;</font></div>
        <div><font face="monospace, monospace">  if (t != 0)</font></div>
        <div><font face="monospace, monospace">    join(t);</font></div>
        <div><font face="monospace, monospace">  return n;</font></div>
        <div><font face="monospace, monospace">}</font></div><div>
          <div><br>
          </div>
          <div>Where the n++ has been moved after the if, is that legal?</div>
        </div>
      </div>
    </blockquote>
    <br></div></div>
    Why wouldn't it be?</div></blockquote><div><br></div><div>Because fork() could return 0, then n get incremented (first time), we go into join(t) which do not return... but jump back into fork() which returns again, but 1 this time, then n get incremented (second time), and we return n+2.<br></div><div><br></div><div>While if we move the n++ outside of that "region", we change that semantic? Basically, returns_twice and noreturn have SSA-reaching side-effects.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="#FFFFFF" text="#000000"><span class=""><blockquote type="cite"><div dir="ltr"><div>
        </div>
      </div>
    </blockquote>
    <br></span>
    They have semantics. returns_twice, however, really means, "it may
    return more than once". noreturn is interpreted as the name implies.
    Thus the unreachable after the call.<br></div></blockquote><div><br></div><div>That means we can encode a loop this way? :-)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="#FFFFFF" text="#000000">
    <br>
     -Hal<span class="HOEnZb"><font color="#888888"><br><br>
    <pre class="m_-6457140989512367091moz-signature" cols="72">-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
  </font></span></div>

</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><b>Alexandre Isoard</b><br></div></div>
</div></div>