MCPcopy Index your code
hub / github.com/uber-go/nilaway / branch

Function branch

assertion/function/functioncontracts/infer.go:318–336  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

316//
317// Otherwise, the function returns all nil.
318func 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.
339func isBuiltinAppendCall(v *ssa.Call) bool {

Callers 1

learnNilnessFunction · 0.85

Calls 1

TypeBarsNilnessFunction · 0.92

Tested by

no test coverage detected