<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Aug 24, 2013, at 3:51 , Yaron Keren <<a href="mailto:yaron.keren@gmail.com">yaron.keren@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="rtl"><div dir="ltr">Hello,</div><div dir="ltr"><br></div><div dir="ltr">Attached is a patch I made to make clang warn where division of two integer literals loses precision. For instance:</div><div dir="ltr"><br>

</div><div dir="ltr"><font face="courier new, monospace">double x = 1/2;</font></div><div dir="ltr"><br></div><div dir="ltr">Which results in x being 0. This is not the programmer's intention. </div><div dir="ltr">While experienced users will know to code 1.0/2 to force floating division, new C/C++ programmers will fall in this trap.</div>

<div dir="ltr"><br></div><div dir="ltr">The patch computes the reminder in the division operation and if only if it is non-zero, warns and suggests a fix.<br></div><div dir="ltr"><br></div><div dir="ltr">This is the first code I write for LLVM so please review it carefully. Specifically, I was not sure whether to create another warning group in DiagnosticSemaKinds.td or reuse an existing one. Maybe the group should be renamed from "DivZero" to "DivProblems".</div>

<div dir="ltr"><br></div><div dir="ltr">Yaron<br></div><div dir="ltr"><br></div></div>
<span><clang_integer_division_warning.diff></span>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br></blockquote></div><br><div>Hi,</div><div><br></div><div>Thanks for this! I've fixed this kind of bug a good number of times and wished there was a warning for it. This belongs on cfe-commits, and needs a test.</div><div><br></div><div>Thanks</div><div><br></div><div><br></div></body></html>