Skip to content

Commit

Permalink
fix assigning identifier overrides llvm alloca
Browse files Browse the repository at this point in the history
  • Loading branch information
dosisod committed Oct 20, 2020
1 parent f5e268b commit e5e3b99
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
12 changes: 7 additions & 5 deletions skull/llvm/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,11 +610,13 @@ void llvm_assign_identifier(Variable *const var, const AstNode *const node) {
PANIC(FMT_ERROR(ERR_TYPE_MISMATCH, { .type = var->type }));
}

var->alloca = LLVMBuildAlloca(
builder,
var->type->llvm_type(),
c32stombs(var->name)
);
if (!var->alloca) {
var->alloca = LLVMBuildAlloca(
builder,
var->type->llvm_type(),
c32stombs(var->name)
);
}

LLVMValueRef load = LLVMBuildLoad2(
builder,
Expand Down
10 changes: 10 additions & 0 deletions test/sh/_reassign_keep_var.sk.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; ModuleID = './test/sh/reassign_keep_var.sk'
source_filename = "./test/sh/reassign_keep_var.sk"

define i64 @main() {
entry:
%x = alloca i64
store i64 0, i64* %x
%0 = load i64, i64* %x
store i64 %0, i64* %x
}
3 changes: 3 additions & 0 deletions test/sh/reassign_keep_var.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mut x := 0

x = x

0 comments on commit e5e3b99

Please sign in to comment.