[llvm-dev] Some strange i64 behavior with arm 32bit. (Raspberry Pi)
Moritz Angermann via llvm-dev
llvm-dev at lists.llvm.org
Thu Nov 30 23:54:00 PST 2017
Hi,
I have this function:
```
define private ghccc void @c4JC_info(i32*, i32*, i32*, i32, i32, i32, i32, i32) prefix { i32, i32, i32 } { i32 add (i32 sub (i32 ptrtoint ({ i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }* @S4J7_srt to i32), i32 ptrtoint (void (i32*, i32*, i32*, i32, i32, i32, i32, i32)* @c4JC_info to i32)), i32 16), i32 0, i32 196638 } {
%9 = add i32 %3, 3
%10 = inttoptr i32 %9 to i64*
%11 = load i64, i64* %10, align 8
call void @debug(i64 -1)
call void @debug(i64 1)
call void @debug(i64 4294967296)
call void @debug(i64 4294967297)
call void @debug(i64 4294967298)
[...]
ret void
}
```
where @debug is:
```
@.str = private unnamed_addr constant [6 x i8] c"%lld\0A\00", align 1
declare i32 @printf(i8*, ...)
define void @debug(i64 %val) {
%cret = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i64 %val)
ret void
}
```
When I run it the output is:
```
-1
4294967296 ; expected this to be 1 = [0x0,0x0,0x0,0x0
; ,0x0,0x0,0x0,0x1]
1 ; expected this to be 4294967296 = [0x0,0x0,0x0,0x1
; ,0x0,0x0,0x0,0x0]
4294967297 ; this is correct due to symmetry
8589934593 ; expected this to be 4294967298 = [0x0,0x0,0x0,0x1
; ,0x0,0x0,0x0,0x2]
```
As such it looks like my words are in reverse somehow.
However, if I try to build something similar and boil it down to just a simple C main function:
```
define i32 @main(i32, i8**) {
call void @debug(i64 -1)
call void @debug(i64 1)
call void @debug(i64 4294967296)
call void @debug(i64 4294967297)
call void @debug(i64 4294967298)
ret i32 0
}
```
it produces the correct result
```
-1
1
4294967296
4294967297
4294967298
```
If someone could offer some hint, where to look further for debugging this, I'd very much appreciate the advice!
I'm a bit lost right now how to figure out why I end up getting swapped words.
Thank you in advance!
Cheers,
Moritz
More information about the llvm-dev
mailing list