<HTML><HEAD><TITLE>Samsung Enterprise Portal mySingle</TITLE>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<STYLE id=mysingle_style type=text/css>P {
        MARGIN-TOP: 5px; FONT-FAMILY: Arial, arial; MARGIN-BOTTOM: 5px; FONT-SIZE: 9pt
}
TD {
        MARGIN-TOP: 5px; FONT-FAMILY: Arial, arial; MARGIN-BOTTOM: 5px; FONT-SIZE: 9pt
}
LI {
        MARGIN-TOP: 5px; FONT-FAMILY: Arial, arial; MARGIN-BOTTOM: 5px; FONT-SIZE: 9pt
}
BODY {
        LINE-HEIGHT: 1.4; MARGIN: 10px; FONT-FAMILY: Arial, arial; FONT-SIZE: 9pt
}
</STYLE>

<META name=GENERATOR content=ActiveSquare></HEAD>
<BODY>
<P>Hello Cameron,</P>
<P>        From the thread you mentioned I can see why this behaviour is the way it is. Some documentation on this behaviour would help because natural expectation of people might be to see a floating point exception being thrown. I think this thread will show up on next web search though.</P>
<P> </P>
<P>------- <B>Original Message</B> -------</P>
<P><B>Sender</B> : Cameron McInally<cameron.mcinally@nyu.edu></P>
<P><B>Date</B> : Sep 17, 2013 20:16 (GMT+05:30)</P>
<P><B>Title</B> : Re: [cfe-dev] Divide by zero - no floating point exception thrown</P>
<P> </P>
<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 style="BORDER-LEFT: rgb(204,204,204) 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class=gmail_quote>
<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>Hey Senthil,</DIV>
<DIV><BR></DIV>
<DIV>Maybe I can save you some trouble...</DIV>
<DIV><BR></DIV>
<DIV><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><BR></DIV>
<DIV>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><BR></DIV>
<DIV>Hope that helps,</DIV>
<DIV>Cameron</DIV></DIV><BR></DIV></DIV>
<P> </P>
<P> </P><!--SP:senthil.t-->
<P>Regards</P>
<P>Senthil Kumar</P>
<P> </P><!--senthil.t:EP-->
<P> </P>
<TABLE id=confidentialsignimg>
<TBODY>
<TR>
<TD NAMO_LOCK>
<P><IMG border=0 src="cid:QKNMBDIFBEI0@namo.co.kr" width=520></P></TD></TR></TBODY></TABLE></BODY></HTML><img src='http://ext.samsung.net/mailcheck/SeenTimeChecker?do=6896e2df0a8237371f62a9b2357c262c5a6b2052f3acae4f9cdd14f0554fc2de1d78c8484d0968ef1d70666c366810d91b20909a04efd4d2748cfe1d4e847419cf878f9a26ce15a0' border=0 width=0 height=0 style='display:none'>