Skip to content

Commit

Permalink
llgo.string (llgo/ssa.MakeString) fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Jun 19, 2024
1 parent b4e2982 commit 4a1712f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cl/_testlibc/once/in.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ func f() {
}

func main() {
println(c.GoString(c.Str("sync.Once demo\n"), 9))
println(c.GoString(c.Str("sync.Once demo\n")))
f()
f()
}
1 change: 1 addition & 0 deletions cl/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func TestErrBuiltin(t *testing.T) {
test("advance", func(ctx *context) { ctx.advance(nil, nil) })
test("alloca", func(ctx *context) { ctx.alloca(nil, nil) })
test("allocaCStr", func(ctx *context) { ctx.allocaCStr(nil, nil) })
test("string", func(ctx *context) { ctx.string(nil, nil) })
test("stringData", func(ctx *context) { ctx.stringData(nil, nil) })
test("sigsetjmp", func(ctx *context) { ctx.sigsetjmp(nil, nil) })
test("siglongjmp", func(ctx *context) { ctx.siglongjmp(nil, nil) })
Expand Down
12 changes: 8 additions & 4 deletions ssa/datastruct.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,20 @@ func (b Builder) getField(x Expr, idx int) Expr {
// -----------------------------------------------------------------------------

// MakeString creates a new string from a C string pointer and length.
func (b Builder) MakeString(cstr Expr, n ...Expr) Expr {
func (b Builder) MakeString(cstr Expr, n ...Expr) (ret Expr) {
if debugInstr {
log.Printf("MakeString %v\n", cstr.impl)
}
pkg := b.Pkg
prog := b.Prog
ret.Type = prog.String()
if len(n) == 0 {
return b.Call(pkg.rtFunc("StringFromCStr"), cstr)
ret.impl = b.Call(pkg.rtFunc("StringFromCStr"), cstr).impl
} else {
// TODO(xsw): remove Convert
ret.impl = b.Call(pkg.rtFunc("StringFrom"), cstr, b.Convert(prog.Int(), n[0])).impl
}
// TODO(xsw): remove Convert
return b.Call(pkg.rtFunc("StringFrom"), cstr, b.Convert(b.Prog.Int(), n[0]))
return
}

// StringData returns the data pointer of a string.
Expand Down

0 comments on commit 4a1712f

Please sign in to comment.