[LLVMbugs] [Bug 1850] New: comparing pointer constants gives surprising results

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Mon Dec 10 02:59:49 PST 2007


           Summary: comparing pointer constants gives surprising results
           Product: libraries
           Version: 2.1
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Scalar Optimizations
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: jay.foad at antixlabs.com
                CC: llvmbugs at cs.uiuc.edu

Created an attachment (id=1281)
 --> (http://llvm.org/bugs/attachment.cgi?id=1281)
test case

The attached test case is based on gcc.c-torture/execute/20010329-1.c in the
GCC testsuite. If I compile it with "llvm-gcc -O1 -S -emit-llvm pre.c", I get

define i32 @main() {
        tail call void @abort( )

This is a bit surprising, because the test looks like it should obviously pass
(i.e. call exit(0) instead of abort()). You could probably argue that the
results of the pointer comparisons are undefined, because the pointers don't
point into any valid object, but I still think it would be nice if the code
behaved in the obvious way.

I've investigated a bit, and the GCC front end is generating code a bit like

        %x = inttoptr i64 2147483649 to i8* ; 0x80000001
        %x1 = getelementptr i8* %x, i64 2147483648 ; 0x80000000
        %cond = icmp ule i8* %x1, inttoptr (i64 5 to i8*)

It's a bit strange that it adds 0x80000000 to x instead of subtracting it, but
if pointers are 32 bit then the result will be the same.

Then, after -instcombine, this is folded to false, presumably because the
operations have been evaluated using 64-bit arithmetic. So maybe -instcombine
is wrong to assume that pointers are 64 bit.

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