]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/cmd/compile/internal/inline/inlheur/analyze_func_flags.go
cmd/compile/internal/inline: fix buglet in panic path scoring
[gostls13.git] / src / cmd / compile / internal / inline / inlheur / analyze_func_flags.go
index 8211c452d554d2900d613a4ebb3da9062d30b60d..588d2f4f598da746371bced9e863b11f1fb503e9 100644 (file)
@@ -148,14 +148,28 @@ func branchCombine(p1, p2 pstate) pstate {
 // as updating disposition of intermediate nodes.
 func (ffa *funcFlagsAnalyzer) stateForList(list ir.Nodes) pstate {
        st := psTop
-       for i := range list {
+       // Walk the list backwards so that we can update the state for
+       // earlier list elements based on what we find out about their
+       // successors. Example:
+       //
+       //        if ... {
+       //  L10:    foo()
+       //  L11:    <stmt>
+       //  L12:    panic(...)
+       //        }
+       //
+       // After combining the dispositions for line 11 and 12, we want to
+       // update the state for the call at line 10 based on that combined
+       // disposition (if L11 has no path to "return", then the call at
+       // line 10 will be on a panic path).
+       for i := len(list) - 1; i >= 0; i-- {
                n := list[i]
                psi := ffa.getstate(n)
                if debugTrace&debugTraceFuncFlags != 0 {
                        fmt.Fprintf(os.Stderr, "=-= %v: stateForList n=%s ps=%s\n",
                                ir.Line(n), n.Op().String(), psi.String())
                }
-               st = blockCombine(st, psi)
+               st = blockCombine(psi, st)
                ffa.updatestate(n, st)
        }
        if st == psTop {