[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


http://llvm.org/bugs/show_bug.cgi?id=7373

           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 6.5.5.5 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
undefined."

This seems pretty clear: the result should be 0.

My guess is that whoever made this undefined was reading from 6.5.5.6:

"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
representable.



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 =
"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
target triple = "i386-pc-linux-gnu"

define i32 @foo() nounwind readnone {
entry:
  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