llgo/ssa: Alloc bugfix (heap)

This commit is contained in:
xushiwei
2024-04-28 10:39:11 +08:00
parent 0d68066086
commit eb4146d80d

View File

@@ -410,11 +410,11 @@ func (b Builder) Alloc(t *types.Pointer, heap bool) (ret Expr) {
prog := b.prog prog := b.prog
telem := t.Elem() telem := t.Elem()
if heap { if heap {
ret.impl = llvm.CreateAlloca(b.impl, prog.Type(telem).ll)
} else {
pkg := b.fn.pkg pkg := b.fn.pkg
size := unsafe.Sizeof(telem) size := unsafe.Sizeof(telem)
ret = b.Call(pkg.rtFunc("Alloc"), prog.Val(size)) ret = b.Call(pkg.rtFunc("Alloc"), prog.Val(size))
} else {
ret.impl = llvm.CreateAlloca(b.impl, prog.Type(telem).ll)
} }
// TODO(xsw): zero-initialize // TODO(xsw): zero-initialize
ret.Type = prog.Type(t) ret.Type = prog.Type(t)