Skip to content

Commit 545e727

Browse files
committedDec 16, 2014
Use the object's package to mangle method names, rather than the receiver's package
If we use the receiver's package, we can end up with identical manglings for different functions. Consider: package p type U struct{} func (U) f() package q import "p" type T struct { p.U } func (T) f() The method set of *T has two synthetic methods named (*T).f(); one forwards to (T).f(), and the other to (U).f(). Previously, we were distinguishing them by the receiver's package, and in this case because both methods have the same receiver, they received the same name. The methods are correctly distinguished by the package owning the identifier "f", which is available via f.Object().Pkg(). Differential Revision: http://reviews.llvm.org/D6673 llvm-svn: 224357
1 parent a4a94f1 commit 545e727

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed
 

‎llgo/irgen/typemap.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -659,21 +659,25 @@ func (ctx *manglerContext) mangleFunctionName(f *ssa.Function) string {
659659
return b.String()
660660
}
661661

662-
pkg := f.Pkg
663-
var pkgobj *types.Package
664-
if pkg != nil {
665-
pkgobj = pkg.Object
666-
} else if f.Signature.Recv() != nil {
667-
pkgobj = f.Signature.Recv().Pkg()
668-
} else {
662+
// Synthetic bound and thunk functions are special cases; they can only be
663+
// distinguished using private data that is only exposed via String().
664+
if strings.HasSuffix(f.Name(), "$bound") || strings.HasSuffix(f.Name(), "$thunk") {
669665
b.WriteString(f.String())
670666
return b.String()
671667
}
672668

669+
var pkg *types.Package
670+
if f.Pkg != nil {
671+
pkg = f.Pkg.Object
672+
} else if !f.Object().Exported() {
673+
pkg = f.Object().Pkg()
674+
}
675+
673676
if pkg != nil {
674-
ctx.manglePackagePath(pkgobj.Path(), &b)
677+
ctx.manglePackagePath(pkg.Path(), &b)
675678
b.WriteRune('.')
676679
}
680+
677681
if f.Signature.Recv() == nil && f.Name() == "init" {
678682
b.WriteString(".import")
679683
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package p
2+
3+
type U struct{}
4+
func (U) f()
File renamed without changes.

‎llgo/test/irgen/mangling-synthetic.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: llgo -fgo-pkgpath=p -c -o %T/p.o %S/Inputs/mangling-synthetic-p.go
2+
// RUN: llgo -fgo-pkgpath=q -I %T -S -emit-llvm -o - %s | FileCheck %s
3+
4+
package q
5+
6+
import "p"
7+
8+
// CHECK-DAG: define linkonce_odr void @p.f.N3_q.T(i8*)
9+
// CHECK-DAG: define linkonce_odr void @p.f.pN3_q.T(i8*)
10+
type T struct { p.U }
11+
12+
// CHECK-DAG: declare void @q.f.N3_q.T(i8*)
13+
// CHECK-DAG: define linkonce_odr void @q.f.pN3_q.T(i8*)
14+
func (T) f()

0 commit comments

Comments
 (0)
Please sign in to comment.