llgo/ssa: builder.Alloc sizeof(t) bugfix

This commit is contained in:
xushiwei
2024-05-01 16:56:26 +08:00
parent e112d8277f
commit 62f6542ca9
8 changed files with 56 additions and 107 deletions

View File

@@ -23,7 +23,6 @@ import (
"go/token"
"go/types"
"log"
"unsafe"
"github.com/goplus/llvm"
)
@@ -531,8 +530,8 @@ func (b Builder) Alloc(t *types.Pointer, heap bool) (ret Expr) {
telem := t.Elem()
if heap {
pkg := b.fn.pkg
size := unsafe.Sizeof(telem)
ret = b.Call(pkg.rtFunc("Alloc"), prog.Val(size))
size := prog.sizs.Sizeof(telem)
ret = b.Call(pkg.rtFunc("Alloc"), prog.Val(uintptr(size)))
} else {
ret.impl = llvm.CreateAlloca(b.impl, prog.Type(telem).ll)
}