<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 8, 2017, at 12:58 PM, Reid Kleckner via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I think this behavior is intended to allow better LTO between C and C++. Consider this kind of code:<div class=""><br class=""></div><div class="">// foo.h</div><div class="">extern "C" int doThing(bool canThrow);</div><div class="">// foo.cpp</div><div class="">int doThing(bool canThrow) {</div><div class="">  ...</div><div class="">  if (hadError) {</div><div class="">    if (canThrow) throw MyException; else return -1;<br class="">  }</div><div class="">}</div><div class="">// bar.c</div><div class="">#include "foo.h"</div><div class="">void f() {</div><div class="">  doThing(false); // don't declare doThing as nounwind<br class="">}</div><div class="">// baz.cpp</div><div class="">...</div><div class="">  doThing(true);</div><div class=""><br class=""></div><div class="">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 class=""></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><br class=""></div><div>— </div><div>Mehdi</div><div><br class=""></div><div><br class=""></div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sun, Feb 5, 2017 at 8:32 AM, Andrew Kelley via llvm-dev <span dir="ltr" class=""><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class="">from <a href="http://llvm.org/docs/LangRef.html" target="_blank" class="">http://llvm.org/docs/<wbr class="">LangRef.html</a>:</div><div class=""><br class=""></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 class="">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 class=""><br class=""></div><div class="">Some things I noticed by looking at various C test programs with clang -S -emit-llvm:</div><div class=""><br class=""></div><div class=""> * If a function definition is provided, it gets nounwind, even if it calls a non-nounwind function</div><div class=""> * If a function is external (no definition provided), it does not get nounwind</div><div class=""><br class=""></div><div class="">What I don't understand is:</div><div class=""> * 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 class=""> * 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 class=""><br class=""></div><div class="">Regards,</div><div class="">Andrew<br class=""></div></div>
<br class="">______________________________<wbr class="">_________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/<wbr class="">mailman/listinfo/llvm-dev</a><br class="">
<br class=""></blockquote></div><br class=""></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></body></html>