Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ssa): fix incorrectly ABI for uninstantiated generic methods #962

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ func (p *context) compileFuncDecl(pkg llssa.Package, f *ssa.Function) (llssa.Fun
fn.Inline(llssa.NoInline)
}
}
// set compiled to check generic function global instantiation
pkg.Prog.SetFuncCompiled(name)
isCgo := isCgoExternSymbol(f)
if nblk := len(f.Blocks); nblk > 0 {
p.cgoCalled = false
Expand Down
15 changes: 13 additions & 2 deletions compiler/ssa/abitype.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ func (b Builder) abiMethodOf(mPkg *types.Package, mName string, mSig *types.Sign

func (b Builder) abiMthd(mPkg *types.Package, mName string, mSig *types.Signature, name, abiTyp, ifn llvm.Value) (ret Expr, tfn llvm.Value) {
fullName := FuncName(mPkg, mName, mSig.Recv(), false)
if mSig.TypeParams().Len() > 0 || mSig.RecvTypeParams().Len() > 0 {
if !b.Pkg.Prog.FuncCompiled(fullName) {
return
}
}
if b.Pkg.fnlink != nil {
fullName = b.Pkg.fnlink(fullName)
}
Expand Down Expand Up @@ -286,14 +291,20 @@ func (b Builder) abiInitNamed(ret Expr, t *types.Named) func() Expr {
if !mthd.IsNil() {
mthds = append(mthds, mthd)
}
ptrMthds = append(ptrMthds, ptrMthd)
if !ptrMthd.IsNil() {
ptrMthds = append(ptrMthds, ptrMthd)
}
}
if len(mthds) > 0 {
methods = b.SliceLit(tSlice, mthds...)
} else {
methods = prog.Zero(tSlice)
}
ptrMethods = b.SliceLit(tSlice, ptrMthds...)
if len(ptrMthds) > 0 {
ptrMethods = b.SliceLit(tSlice, ptrMthds...)
} else {
ptrMethods = prog.Zero(tSlice)
}
}
return b.Call(initNamed, ret, under, methods, ptrMethods)
}
Expand Down
15 changes: 14 additions & 1 deletion compiler/ssa/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ type aProgram struct {

patchType func(types.Type) types.Type

fnsCompiled map[string]bool

rt *types.Package
rtget func() *types.Package

Expand Down Expand Up @@ -218,6 +220,7 @@ func NewProgram(target *Target) Program {
}
ctx := llvm.NewContext()
td := target.targetData() // TODO(xsw): target config
fnsCompiled := make(map[string]bool)
/*
arch := target.GOARCH
if arch == "" {
Expand All @@ -230,7 +233,7 @@ func NewProgram(target *Target) Program {
*/
is32Bits := (td.PointerSize() == 4 || target.GOARCH == "x86") // TODO(xsw): remove temp code
return &aProgram{
ctx: ctx, gocvt: newGoTypes(),
ctx: ctx, gocvt: newGoTypes(), fnsCompiled: fnsCompiled,
target: target, td: td, is32Bits: is32Bits,
ptrSize: td.PointerSize(), named: make(map[string]llvm.Type), fnnamed: make(map[string]int),
linkname: make(map[string]string),
Expand Down Expand Up @@ -280,6 +283,16 @@ func (p Program) runtime() *types.Package {
return p.rt
}

// check generic function instantiation
func (p Program) FuncCompiled(name string) bool {
_, ok := p.fnsCompiled[name]
return ok
}

func (p Program) SetFuncCompiled(name string) {
p.fnsCompiled[name] = true
}

func (p Program) rtNamed(name string) *types.Named {
if rt := p.runtime(); rt != nil {
if rtScope := rt.Scope(); rtScope != nil {
Expand Down
Loading