From 6463e2cc2a253f2e76fd006bf2d9a6eb33b1b1d3 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 19 Apr 2024 00:39:09 +0800 Subject: [PATCH] TestFuncMultiRet --- ssa/decl.go | 3 +-- ssa/package.go | 2 +- ssa/ssa_test.go | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/ssa/decl.go b/ssa/decl.go index 41f13f50..1f098e09 100644 --- a/ssa/decl.go +++ b/ssa/decl.go @@ -45,8 +45,7 @@ type NamedConst = *aNamedConst // Pos() returns the position of the ast.ValueSpec.Names[*] // identifier. type aGlobal struct { - impl llvm.Value - Type + Expr } type Global = *aGlobal diff --git a/ssa/package.go b/ssa/package.go index ae04a014..3ba7dc3a 100644 --- a/ssa/package.go +++ b/ssa/package.go @@ -163,7 +163,7 @@ func (p Package) NewConst(name string, val constant.Value) NamedConst { func (p Package) NewVar(name string, typ types.Type) Global { t := p.prog.llvmType(typ) gbl := llvm.AddGlobal(p.mod, t.ll, name) - return &aGlobal{gbl, t} + return &aGlobal{Expr{gbl, t}} } func (p Package) NewFunc(name string, sig *types.Signature) Function { diff --git a/ssa/ssa_test.go b/ssa/ssa_test.go index 208f6b62..0e5612e9 100644 --- a/ssa/ssa_test.go +++ b/ssa/ssa_test.go @@ -167,6 +167,31 @@ define void @main() { `) } +func TestFuncMultiRet(t *testing.T) { + prog := NewProgram(nil) + pkg := prog.NewPackage("bar", "foo/bar") + params := types.NewTuple( + types.NewVar(0, nil, "b", types.Typ[types.Float64])) + rets := types.NewTuple( + types.NewVar(0, nil, "c", types.Typ[types.Int]), + types.NewVar(0, nil, "d", types.Typ[types.Float64])) + sig := types.NewSignatureType(nil, nil, nil, params, rets, false) + a := pkg.NewVar("a", types.Typ[types.Int]) + fn := pkg.NewFunc("fn", sig) + b := fn.MakeBody("") + b.Return(a.Expr, fn.Param(0)) + assertPkg(t, pkg, `; ModuleID = 'foo/bar' +source_filename = "foo/bar" + +@a = external global i64 + +define { i64, double } @fn(double %0) { + %mrv = insertvalue { i64, double } { ptr @a, double poison }, double %0, 1 + ret { i64, double } %mrv +} +`) +} + func TestBinOp(t *testing.T) { prog := NewProgram(nil) pkg := prog.NewPackage("bar", "foo/bar")