[LLVMbugs] [Bug 7373] New: INT_MIN % -1 is not undefined

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Jun 13 22:14:41 PDT 2010


           Summary: INT_MIN % -1 is not undefined
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: regehr at cs.utah.edu
                CC: llvmbugs at cs.uiuc.edu

clang says that INT_MIN % -1 is undefined (see below) but I don't think the
standard justifies this.  In N1124 at we have

"The result of the / operator is the quotient from the division of the first
operand by the second; the result of the % operator is the remainder. In both
operations, if the value of the second operand is zero, the behavior is

This seems pretty clear: the result should be 0.

My guess is that whoever made this undefined was reading from

"When integers are divided, the result of the / operator is the algebraic
quotient with any fractional part discarded. If the quotient a/b is
representable, the expression (a/b)*b + a%b shall equal a."

But I don't buy it.  We have an equality that must hold when a/b is
representable, but it never says that a%b is undefined when a/b is not

regehr at john-home:~$ cat test.c
#include <limits.h>

int foo (void)
  return INT_MIN % -1;
regehr at john-home:~$ clang test.c -S -emit-llvm -O -o -
; ModuleID = 'test.c'
target datalayout =
target triple = "i386-pc-linux-gnu"

define i32 @foo() nounwind readnone {
  ret i32 undef

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