Bugzilla – Bug 268
[llvm-gcc] Incorrect code generation for pointer subtraction
Last modified: 2004-03-08 18:39:03
You need to log in before you can comment on or make changes to this bug.
The llvm-gcc program mis-compiles certain pointer arithmetic expressions. Namely, it seems to generate incorrect LLVM code for expressions which subtract from pointer values. The attached C and corresponding LLVM code demonstrate the problem: The expression: argv[0] - 5 ...becomes: %tmp.3 = getelementptr sbyte* %tmp.2, long 4294967291 ; ty=sbyte* Note that the -5 is represented as an unsigned number (4294967291). This might work, except that long's in LLVM are 64 bits and are translated as such in the CBE and LLC. This causes the hbd program to segfault under certain conditions, and it might be causing other subtle failures in other programs.
Created an attachment (id=89) [details] C code to regenerate the error.
Created an attachment (id=90) [details] Incorrect output generated This is the incorrect output generated when you run the following: llvm-gcc -S -o test.ll test.c Note that the subtraction of 5 is generated incorrectly.
Nice catch! This is definitely a 1.2 bug. -Chris
Assigning myself as I'm currently looking into what the problem might be.
Just a note that this bug is also the one that caused us to miscompile 'gmake'. -Chris
John's patch fixed this bug. Thanks John!! -Chris