compiler: support using return in some branches

When `return` is used in one codepath, but not the other,
we do not clean altstack properly. This commit fixes it.
This commit is contained in:
Evgenii Stratonikov 2020-05-06 15:39:25 +03:00
parent 770cff8b91
commit 156a2eddc5
3 changed files with 37 additions and 12 deletions

View file

@ -133,16 +133,13 @@ func (f funcUsage) funcUsed(name string) bool {
return ok
}
// hasReturnStmt looks if the given FuncDecl has a return statement.
func hasReturnStmt(decl ast.Node) (b bool) {
ast.Inspect(decl, func(node ast.Node) bool {
if _, ok := node.(*ast.ReturnStmt); ok {
b = true
return false
}
return true
})
return
// lastStmtIsReturn checks if last statement of the declaration was return statement..
func lastStmtIsReturn(decl *ast.FuncDecl) (b bool) {
if l := len(decl.Body.List); l != 0 {
_, ok := decl.Body.List[l-1].(*ast.ReturnStmt)
return ok
}
return false
}
func analyzeFuncUsage(pkgs map[*types.Package]*loader.PackageInfo) funcUsage {