<div dir="ltr"><div class="gmail_extra">On Tue, Sep 17, 2013 at 10:13 AM, SENTHIL KUMAR THANGAVELU <span dir="ltr"><<a href="mailto:senthil.t@samsung.com" target="_blank">senthil.t@samsung.com</a>></span> wrote:<br><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">




<div>
<p>Hello all,</p>
<p>    I saw some odd behaviour in clang for the following test case. g++ and intel compiler produce binary which dumps "Floating point exception (core dumped)" on execution. Incase of clang random values are returned for each execution. Originally I had written a basic template specialization code which does a divide by zero and saw this bug. However clang warns of divide by zero similar to g++ and icc.</p>

<p> </p>
<p>clang version is some trunk  head revision on 12 sep 2013.</p>
<p> </p>
<p>#include <iostream></p>
<p>void F002() {<br>  int b = 23/0;<br>  std::cout << "\n b == " <<<br>    b << std::endl;<br>}</p>
<p>int main() {<br>  F002();<br>}</p>
<p> </p>
<p>======= Following code also executes fine in clang without floating point exception. g++ & intel compiler binary emits floating point exception  ======</p>
<p>template <int d, int e><br>int F004() {<br>  return d/e;<br>}</p>
<p>int main() {<br>  F004<4,5>();<br>  F004<4,0>();<br>}<br></p>
<p>============ clang version info ============</p>
<p>test$ clang++ -v sf2.cpp <br>clang version 3.4 <br>Target: x86_64-unknown-linux-gnu<br>Thread model: posix<br>Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7<br>Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7.2<br>
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7<br> "/usr/local/bin/clang-3.4" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name sf2.cpp -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -v -resource-dir /usr/local/bin/../lib/clang/3.4 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/x86_64-linux-gnu -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/c++/4.7/backward -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../include/x86_64-linux-gnu/c++/4.7 -internal-isystem /usr/local/include -internal-isystem /usr/local/bin/../lib/clang/3.4/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /opt/SISO_BDP_SENTHIL_LLVM_JUL25/test -ferror-limit 19 -fmessage-length 135 -mstackrealign -fobjc-runtime=gcc -fobjc-default-synthesize-properties -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-slp -o /tmp/sf2-0ecc11.o -x c++ sf2.cpp<br>
clang -cc1 version 3.4 based upon LLVM 3.4svn default target x86_64-unknown-linux-gnu</p></div></blockquote><div style>Hey Senthil,</div><div style><br></div><div style>Maybe I can save you some trouble...</div><div style>
<br></div><div style><a href="http://llvm.1065342.n5.nabble.com/Integer-divide-by-zero-tt56495.html">http://llvm.1065342.n5.nabble.com/Integer-divide-by-zero-tt56495.html</a> </div><div style><br></div><div style>To sum it up, integer division by zero is undefined behaviour and the compiler is free to do what it would like to do. Although, I am still not thrilled with this behaviour in Clang/LLVM. My preferred handling of this undefined behaviour is to fall back to the processor's expected behaviour. I believe that this is the "nice" thing to do.</div>
<div style><br></div><div style>Hope that helps,</div><div style>Cameron</div></div><br></div></div>