[LLVMbugs] [Bug 12687] New: clang should warn when tautologically comparing a smaller-type numeric value against a larger-typed constant outside the smaller type's range
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Fri Apr 27 12:58:20 PDT 2012
http://llvm.org/bugs/show_bug.cgi?id=12687
Bug #: 12687
Summary: clang should warn when tautologically comparing a
smaller-type numeric value against a larger-typed
constant outside the smaller type's range
Product: clang
Version: unspecified
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P
Component: Frontend
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: jwalden+llvm at mit.edu
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
I recently wrote code that looked roughly like this (the isfinite and copysign
expressions were spelled in other terms that didn't make the code look so
obviously wrong):
#include <math.h>
#include <stdlib.h>
inline double TimeClip(double time)
{
if (!isfinite(time) || abs(time) > 8.64e15)
return NAN;
return copysign(floor(fabs(time)), time + 0.0);
}
int main()
{
TimeClip(17.0);
return 0;
}
This code's buggy in that it uses abs (int -> int) when it should have used
fabs (double -> double). The compiler can't be expected to figure that out, of
course. But it should be able to figure out that no |int| value will ever be
greater than 8.64e15, and it should emit a tautological-compare warning just as
it would if it saw any other always-true or always-false comparison.
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list