Skip to content

Instantly share code, notes, and snippets.

@jido
Last active March 14, 2019 23:12
Show Gist options
  • Save jido/3371070f5f9687f9b92666e7d7af30cd to your computer and use it in GitHub Desktop.
Save jido/3371070f5f9687f9b92666e7d7af30cd to your computer and use it in GitHub Desktop.
Problem: the alloca calls reserve 16 bytes each, so pointer arithmetic in "plus" is wrong
; ModuleID = 'integer.dodo'
; Function Attrs: noinline nounwind
define void @int32() {
%frame = alloca i8*, align 8
%context = alloca i8*, align 8
br label %test
plus:
%plus1 = load i8*, i8** %frame, align 8
%plus2 = bitcast i8* %plus1 to i32*
%plus3 = getelementptr inbounds i32, i32* %plus2, i64 -1
%plus4 = bitcast i32* %plus3 to i8**
%plus5 = getelementptr inbounds i8*, i8** %plus4, i64 -1
%plus_a = load i32, i32* %plus2, align 4
%plus_b = load i32, i32* %plus3, align 4
%plus_ret = load i8*, i8** %plus5, align 8
%plus6 = add nsw i32 %plus_a, %plus_b
%plus7 = getelementptr inbounds i8*, i8** %plus5, i64 -1
%plus8 = bitcast i8** %plus7 to i32*
store i32 %plus6, i32* %plus8, align 4
indirectbr i8* %plus_ret, [label %endtest]
test:
%test_a = alloca i32, align 4
%test_b = alloca i32, align 4
%test_cont = alloca i8*, align 8
%test_val = alloca i32, align 4
store i32 45, i32* %test_a, align 4
store i32 19, i32* %test_b, align 4
store i8* blockaddress(@int32, %endtest), i8** %test_cont, align 8
%test1 = bitcast i32* %test_a to i8*
store i8* %test1, i8** %frame, align 8
br label %plus
endtest:
%endtest_r = load i32, i32* %test_val, align 4
ret void
}
; Function Attrs: noinline nounwind optnone ssp uwtable
define void @main(i32, i8**) #0 {
call void @int32()
ret void
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment