From 044721631659c2f0bcf3219462fdc20498b9954c Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Tue, 19 Dec 2017 12:08:32 -0500 Subject: [PATCH] cmd/compile: fix corner case in DWARF inline info generation The helper routine for returning pre-inlining parameter declarations wasn't properly handling the case where you have more than one parameter named "_" in a function signature; this triggered a map collision later on when the function was inlined and DWARF was generated for the inlined routine instance. Fixes #23179. Change-Id: I12e5d6556ec5ce08e982a6b53666a4dcc1d22201 Reviewed-on: https://go-review.googlesource.com/84755 Run-TryBot: Than McIntosh TryBot-Result: Gobot Gobot Reviewed-by: Heschi Kreinick Reviewed-by: David Chase Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/gc/pgen.go | 4 +++- test/fixedbugs/issue23179.dir/a.go | 9 +++++++++ test/fixedbugs/issue23179.dir/b.go | 11 +++++++++++ test/fixedbugs/issue23179.go | 7 +++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/fixedbugs/issue23179.dir/a.go create mode 100644 test/fixedbugs/issue23179.dir/b.go create mode 100644 test/fixedbugs/issue23179.go diff --git a/src/cmd/compile/internal/gc/pgen.go b/src/cmd/compile/internal/gc/pgen.go index 07e4f9d2e9e..d3834ddc379 100644 --- a/src/cmd/compile/internal/gc/pgen.go +++ b/src/cmd/compile/internal/gc/pgen.go @@ -599,7 +599,9 @@ func preInliningDcls(fnsym *obj.LSym) []*Node { } for _, n := range dcl { c := n.Sym.Name[0] - if c == '.' || n.Type.IsUntyped() { + // Avoid reporting "_" parameters, since if there are more tham + // one, it can result in a collision later on, as in #23179. + if unversion(n.Sym.Name) == "_" || c == '.' || n.Type.IsUntyped() { continue } rdcl = append(rdcl, n) diff --git a/test/fixedbugs/issue23179.dir/a.go b/test/fixedbugs/issue23179.dir/a.go new file mode 100644 index 00000000000..1b796660fdc --- /dev/null +++ b/test/fixedbugs/issue23179.dir/a.go @@ -0,0 +1,9 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +func F(x int, _ int, _ bool) int { + return x +} diff --git a/test/fixedbugs/issue23179.dir/b.go b/test/fixedbugs/issue23179.dir/b.go new file mode 100644 index 00000000000..edf5e6d8126 --- /dev/null +++ b/test/fixedbugs/issue23179.dir/b.go @@ -0,0 +1,11 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package b + +import "a" + +func G(x int) int { + return a.F(x, 1, false) +} diff --git a/test/fixedbugs/issue23179.go b/test/fixedbugs/issue23179.go new file mode 100644 index 00000000000..8000a5224ff --- /dev/null +++ b/test/fixedbugs/issue23179.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ignored