diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2021-02-22 20:37:25 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2021-02-22 21:02:12 +0100 |
| commit | fcc6d71be2c3ce7d9305c04fc2e87af554571bac (patch) | |
| tree | b01dbb3d1e2988e28ea158d2d543d603ec0b9569 /vendor/github.com/gostaticanalysis | |
| parent | 8f23c528ad5a943b9ffec5dcaf332fd0f614006e (diff) | |
go.mod: update golangci-lint to v1.37
Diffstat (limited to 'vendor/github.com/gostaticanalysis')
3 files changed, 75 insertions, 7 deletions
diff --git a/vendor/github.com/gostaticanalysis/analysisutil/README.md b/vendor/github.com/gostaticanalysis/analysisutil/README.md index c031e16e2..d8fd3d2a4 100644 --- a/vendor/github.com/gostaticanalysis/analysisutil/README.md +++ b/vendor/github.com/gostaticanalysis/analysisutil/README.md @@ -1,10 +1,5 @@ # analysisutil -[![godoc.org][godoc-badge]][godoc] +[](https://pkg.go.dev/github.com/gostaticanalysis/analysisutil) Utilities for x/tools/go/analysis package. - -<!-- links --> -[godoc]: https://godoc.org/github.com/gostaticanalysis/analysisutil -[godoc-badge]: https://img.shields.io/badge/godoc-reference-4F73B3.svg?style=flat-square&label=%20godoc.org - diff --git a/vendor/github.com/gostaticanalysis/analysisutil/ssa.go b/vendor/github.com/gostaticanalysis/analysisutil/ssa.go index ce3af580b..517f6b9b4 100644 --- a/vendor/github.com/gostaticanalysis/analysisutil/ssa.go +++ b/vendor/github.com/gostaticanalysis/analysisutil/ssa.go @@ -72,7 +72,7 @@ func returnsInBlock(b *ssa.BasicBlock, done map[*ssa.BasicBlock]bool) (rets []*s } // BinOp returns binary operator values which are contained in the block b. -func BinOp(b *ssa.BasicBlock) ([]*ssa.BinOp) { +func BinOp(b *ssa.BasicBlock) []*ssa.BinOp { var binops []*ssa.BinOp for _, instr := range b.Instrs { if binop, ok := instr.(*ssa.BinOp); ok { @@ -81,3 +81,66 @@ func BinOp(b *ssa.BasicBlock) ([]*ssa.BinOp) { } return binops } + +// Used returns an instruction which uses the value in the instructions. +func Used(v ssa.Value, instrs []ssa.Instruction) ssa.Instruction { + if len(instrs) == 0 || v.Referrers() == nil { + return nil + } + + for _, instr := range instrs { + if used := usedInInstr(v, instr); used != nil { + return used + } + } + + return nil +} + +func usedInInstr(v ssa.Value, instr ssa.Instruction) ssa.Instruction { + switch instr := instr.(type) { + case *ssa.MakeClosure: + return usedInClosure(v, instr) + default: + operands := instr.Operands(nil) + for _, x := range operands { + if x != nil && *x == v { + return instr + } + } + } + + switch v := v.(type) { + case *ssa.UnOp: + return usedInInstr(v.X, instr) + } + + return nil +} + +func usedInClosure(v ssa.Value, instr *ssa.MakeClosure) ssa.Instruction { + fn, _ := instr.Fn.(*ssa.Function) + if fn == nil { + return nil + } + + var fv *ssa.FreeVar + for i := range instr.Bindings { + if instr.Bindings[i] == v { + fv = fn.FreeVars[i] + break + } + } + + if fv == nil { + return nil + } + + for _, b := range fn.Blocks { + if used := Used(fv, b.Instrs); used != nil { + return used + } + } + + return nil +} diff --git a/vendor/github.com/gostaticanalysis/analysisutil/types.go b/vendor/github.com/gostaticanalysis/analysisutil/types.go index 4773ac43e..46b970621 100644 --- a/vendor/github.com/gostaticanalysis/analysisutil/types.go +++ b/vendor/github.com/gostaticanalysis/analysisutil/types.go @@ -196,3 +196,13 @@ func mergeTypesInfo(i1, i2 *types.Info) { // InitOrder i1.InitOrder = append(i1.InitOrder, i2.InitOrder...) } + +// Under returns the most bottom underlying type. +func Under(t types.Type) types.Type { + switch t := t.(type) { + case *types.Named: + return Under(t.Underlying()) + default: + return t + } +} |
