Skip to content

Commit 710f4d3

Browse files
philhoferdr2chase
authored andcommitted
cmd/compile/internal/gc: mark generated wrappers as DUPOK
Interface wrapper functions now get compiled eagerly in some cases. Consequently, they may be present in multiple translation units. Mark them as DUPOK, just like closures. Fixes #19548 Fixes #19550 Change-Id: Ibe74adb5a62dbf6447db37fde22dcbb3479969ef Reviewed-on: https://go-review.googlesource.com/38156 Reviewed-by: David Chase <[email protected]>
1 parent 8a44c8e commit 710f4d3

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

src/cmd/compile/internal/gc/subr.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,7 @@ func genwrapper(rcvr *Type, method *Field, newnam *Sym, iface int) {
17111711
t.Rlist.Set(out)
17121712

17131713
fn := nod(ODCLFUNC, nil, nil)
1714+
fn.Func.SetDupok(true)
17141715
fn.Func.Nname = newname(newnam)
17151716
fn.Func.Nname.Name.Defn = fn
17161717
fn.Func.Nname.Name.Param.Ntype = t

test/fixedbugs/issue19548.dir/a.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2016 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package a
6+
7+
type Mode uint
8+
9+
func (m Mode) String() string { return "mode string" }
10+
func (m *Mode) Addr() *Mode { return m }
11+
12+
type Stringer interface {
13+
String() string
14+
}
15+
16+
var global Stringer
17+
var m Mode
18+
19+
func init() {
20+
// force compilation of the (*Mode).String() wrapper
21+
global = &m
22+
}
23+
24+
func String() string {
25+
return global.String() + Mode(0).String()
26+
}

test/fixedbugs/issue19548.dir/b.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2016 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import "./a"
8+
9+
type Value interface {
10+
a.Stringer
11+
Addr() *a.Mode
12+
}
13+
14+
var global a.Mode
15+
16+
func f() int {
17+
var v Value
18+
v = &global
19+
return int(v.String()[0])
20+
}
21+
22+
func main() {
23+
f()
24+
}

test/fixedbugs/issue19548.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// rundir
2+
3+
// Copyright 2017 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// Test that interface wrappers can be compiled successfully
8+
// in multiple translation units.
9+
package ignore

0 commit comments

Comments
 (0)