llgo/ssa: Slice, IndexAddr bugfix
This commit is contained in:
15
ssa/expr.go
15
ssa/expr.go
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user