• Cherry Zhang's avatar
    cmd/compile: fix unnamed parameter handling in escape analysis · be09bdf5
    Cherry Zhang authored
    For recursive functions, the parameters were iterated using
    fn.Name.Defn.Func.Dcl, which does not include unnamed/blank
    parameters. This results in a mismatch in formal-actual
    assignments, for example,
    
    func f(_ T, x T)
    
    f(a, b) should result in { _=a, x=b }, but the escape analysis
    currently sees only { x=a } and drops b on the floor. This may
    cause b to not escape when it should (or a escape when it should
    not).
    
    Fix this by using fntype.Params().FieldSlice() instead, which
    does include unnamed parameters.
    
    Also add a sanity check that ensures all the actual parameters
    are consumed.
    
    Fixes #29000
    
    Change-Id: Icd86f2b5d71e7ebbab76e375b7702f62efcf59ae
    Reviewed-on: https://go-review.googlesource.com/c/152617Reviewed-by: 's avatarKeith Randall <khr@golang.org>
    be09bdf5
esc.go 68.4 KB