Reputation: 125
I am trying to pass a global variable to a function as a parameter and modify this variable inside of a function
i have IR code as follows
@n = common global i32 0
declare i32 @readln(i32)
declare i32 @writeln(i32)
define i32 @main() {
entry:
%n = load i32, i32* @n, align 4
%calltmp = call i32 @readln(i32 %n)
%n1 = load i32, i32* @n, align 4
%calltmp2 = call i32 @writeln(i32 %n1)
ret i32 0
}
readln defined in separate module as a C function
int readln(int * x) {
return scanf("%d", x);
}
upon running i get segmentation fault 11
What am I doing wrong ?
Upvotes: 1
Views: 812
Reputation: 394
comment is correct. inspire by this
Builder.CreateLoad(Builder.CreateIntToPtr(Value,Type::getInt32PtrTy(TheContext)), "ptr");
Builder.CreateIntToPtr(Value,Type::getInt32PtrTy(TheContext));
Upvotes: 1