[LLVMbugs] [Bug 7584] New: Bad code generated for Remainder operation
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed Jul 7 06:34:21 PDT 2010
http://llvm.org/bugs/show_bug.cgi?id=7584
Summary: Bad code generated for Remainder operation
Product: clang
Version: unspecified
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: esteaqui at hotmail.com
CC: llvmbugs at cs.uiuc.edu
When clang is fed an unsigned int as the divisor on the Remainder operand (%)
the generated code is faulty.
According to C99 specc, the sign of the remainder shall be the same as the sign
of the dividend.
Also, assuming n: dividend and d: divisor, "n / d x d - n == n % d"
(assuming a truncating division)
This bug is further explained by the attached source code.
As an example, following C99:
2 % 5 = 2
-2 % 5 = -2
But clang generates
2 % 5 = 2
-2 % 5 = 4
I got my C99 specification from
http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf (relevant page is 82,
mark 6.5.5.6)
and also from
http://en.wikipedia.org/wiki/Modulo_operation ("Integer modulo operators in
various programming languages")
If my interpretation of the standard is wrong, please let me know and mark the
bug as invalid.
--
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