<div dir="auto"><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Feb 8, 2017 5:46 PM, "Mehdi Amini via llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><div class="quoted-text"><blockquote type="cite"><div>On Feb 8, 2017, at 12:58 PM, Reid Kleckner via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="m_2549668641611942073Apple-interchange-newline"><div><div dir="ltr">I think this behavior is intended to allow better LTO between C and C++. Consider this kind of code:<div><br></div><div>// foo.h</div><div>extern "C" int doThing(bool canThrow);</div><div>// foo.cpp</div><div>int doThing(bool canThrow) {</div><div>  ...</div><div>  if (hadError) {</div><div>    if (canThrow) throw MyException; else return -1;<br>  }</div><div>}</div><div>// bar.c</div><div>#include "foo.h"</div><div>void f() {</div><div>  doThing(false); // don't declare doThing as nounwind<br>}</div><div>// baz.cpp</div><div>...</div><div>  doThing(true);</div><div><br></div><div>Basically, compiling a C declaration for a function is not an assertion that it never throws an exception. However, *defining* a function in a C TU implies that it will not throw an exception.</div></div></div></blockquote><div><br></div></div><div>What isn’t clear to me still is : why shouldn't this be transitive?</div><div>In the example you’re showing, for a caller of f() in bar, what is the advantage of knowing that f() is nounwind if it an exception can still be thrown? What does it allow?</div></div></div></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">Given the semantics, aren't we allowed to infer it transitively? I.e. if a callee of a nounwind function does dynamically unwind through the nounwind caller, then it is UB.</div><div dir="auto"><br></div><div dir="auto">-- Sean Silva</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><br></div><div>— </div><div>Mehdi</div><div class="quoted-text"><div><br></div><div><br></div><div><br></div><br><blockquote type="cite"><div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Feb 5, 2017 at 8:32 AM, Andrew Kelley via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>from <a href="http://llvm.org/docs/LangRef.html" target="_blank">http://llvm.org/docs/Lang<wbr>Ref.html</a>:</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">nounwind<br>This function attribute indicates that the function never raises an exception. If the function does raise an exception, its runtime behavior is undefined. However, functions marked nounwind may still trap or generate asynchronous exceptions. Exception handling schemes that are recognized by LLVM to handle asynchronous exceptions, such as SEH, will still provide their implementation defined semantics.</blockquote><div><br></div><div>Some things I noticed by looking at various C test programs with clang -S -emit-llvm:</div><div><br></div><div> * If a function definition is provided, it gets nounwind, even if it calls a non-nounwind function</div><div> * If a function is external (no definition provided), it does not get nounwind</div><div><br></div><div>What I don't understand is:</div><div> * A non-nounwind function that calls a nounwind function, wouldn't the ability for an exception to be thrown transfer? I thought if you don't catch an exception, it bubbles up to the caller and so on.</div><div> * More importantly, if compiling in C mode, why doesn't every function have nounwind? I thought that C does not have exceptions, so calling a function and having it throw an exception would be undefined behavior anyway. Wouldn't that mean every function should be nounwind?</div><div><br></div><div>Regards,</div><div>Andrew<br></div></div>
<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>
______________________________<wbr>_________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br></div></blockquote></div></div><br></div><br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div></div>