terminates.go 579 B

12345678910111213141516171819202122232425
  1. package functions
  2. import "honnef.co/go/tools/ssa"
  3. // Terminates reports whether fn is supposed to return, that is if it
  4. // has at least one theoretic path that returns from the function.
  5. // Explicit panics do not count as terminating.
  6. func Terminates(fn *ssa.Function) bool {
  7. if fn.Blocks == nil {
  8. // assuming that a function terminates is the conservative
  9. // choice
  10. return true
  11. }
  12. for _, block := range fn.Blocks {
  13. if len(block.Instrs) == 0 {
  14. continue
  15. }
  16. if _, ok := block.Instrs[len(block.Instrs)-1].(*ssa.Return); ok {
  17. return true
  18. }
  19. }
  20. return false
  21. }