branch reports whether we can make a branch and learn nilness from the true and false successor. The function returns equal, not-equal successor and the binary operation iff (1) b ends with an equality or inequality comparison; (2) the operands can have nil as a valid value; Otherwise, the funct
(b *ssa.BasicBlock)
| 316 | // |
| 317 | // Otherwise, the function returns all nil. |
| 318 | func branch(b *ssa.BasicBlock) (*ssa.BasicBlock, *ssa.BasicBlock, *ssa.BinOp) { |
| 319 | ifInstr, ok := b.Instrs[len(b.Instrs)-1].(*ssa.If) |
| 320 | if !ok { |
| 321 | return nil, nil, nil |
| 322 | } |
| 323 | binOp, ok := ifInstr.Cond.(*ssa.BinOp) |
| 324 | // Check only one operand is sufficient since the two operands must have the same type. |
| 325 | if !ok || typeshelper.TypeBarsNilness(binOp.X.Type()) { |
| 326 | // not a binary comparison or the type cannot have nil as a value. |
| 327 | return nil, nil, nil |
| 328 | } |
| 329 | switch binOp.Op { |
| 330 | case token.EQL: |
| 331 | return b.Succs[0], b.Succs[1], binOp |
| 332 | case token.NEQ: |
| 333 | return b.Succs[1], b.Succs[0], binOp |
| 334 | } |
| 335 | return nil, nil, nil |
| 336 | } |
| 337 | |
| 338 | // isBuiltinAppendCall reports if the call is a call to builtin append. |
| 339 | func isBuiltinAppendCall(v *ssa.Call) bool { |
no test coverage detected