-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Description
Bugzilla Link | 1850 |
Resolution | FIXED |
Resolved on | Apr 24, 2010 07:06 |
Version | 2.1 |
OS | Linux |
Attachments | test case |
Reporter | LLVM Bugzilla Contributor |
CC | @jayfoad |
Extended Description
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 this:
define i32 @main() {
entry:
tail call void @abort( )
unreachable
}
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 this:
%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.