llgo/ssa: Slice, IndexAddr bugfix

This commit is contained in:
xushiwei
2024-04-30 16:15:36 +08:00
parent 02afd1d73a
commit 40a9e00d4c
6 changed files with 37 additions and 12 deletions

View File

@@ -424,8 +424,17 @@ func (b Builder) IndexAddr(x, idx Expr) Expr {
prog := b.Prog
telem := prog.Index(x.Type)
pt := prog.Pointer(telem)
indices := []llvm.Value{idx.impl}
return Expr{llvm.CreateInBoundsGEP(b.impl, telem.ll, x.impl, indices), pt}
switch x.t.Underlying().(type) {
case *types.Pointer:
indices := []llvm.Value{idx.impl}
return Expr{llvm.CreateInBoundsGEP(b.impl, telem.ll, x.impl, indices), pt}
case *types.Slice:
pkg := b.fn.pkg
ptr := b.InlineCall(pkg.rtFunc("SliceData"), x)
indices := []llvm.Value{idx.impl}
return Expr{llvm.CreateInBoundsGEP(b.impl, telem.ll, ptr.impl, indices), pt}
}
panic("todo")
}
// The Slice instruction yields a slice of an existing string, slice
@@ -458,7 +467,7 @@ func (b Builder) Slice(x, low, high, max Expr) (ret Expr) {
ret.Type = prog.Type(types.NewSlice(te.Elem()))
if low.IsNil() && high.IsNil() && max.IsNil() {
n := prog.Val(int(te.Len()))
ret.impl = b.InlineCall(pkg.rtFunc("NewSlice"), n, n).impl
ret.impl = b.InlineCall(pkg.rtFunc("NewSlice"), x, n, n).impl
return ret
}
}