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: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]


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.



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

int foo (void)
{
  return INT_MIN % -1;
}
reg...@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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to