Commit 81728cf0 authored by Russ Cox's avatar Russ Cox

gc: fix inlining bug

R=lvd
CC=golang-dev
https://golang.org/cl/5532077
parent 3fc327b3
...@@ -290,6 +290,7 @@ inlnode(Node **np) ...@@ -290,6 +290,7 @@ inlnode(Node **np)
{ {
Node *n; Node *n;
NodeList *l; NodeList *l;
int lno;
if(*np == nil) if(*np == nil)
return; return;
...@@ -312,6 +313,8 @@ inlnode(Node **np) ...@@ -312,6 +313,8 @@ inlnode(Node **np)
return; return;
} }
lno = setlineno(n);
inlnodelist(n->ninit); inlnodelist(n->ninit);
for(l=n->ninit; l; l=l->next) for(l=n->ninit; l; l=l->next)
if(l->n->op == OINLCALL) if(l->n->op == OINLCALL)
...@@ -431,6 +434,8 @@ inlnode(Node **np) ...@@ -431,6 +434,8 @@ inlnode(Node **np)
break; break;
} }
lineno = lno;
} }
// if *np is a call, and fn is a function with an inlinable body, substitute *np with an OINLCALL. // if *np is a call, and fn is a function with an inlinable body, substitute *np with an OINLCALL.
...@@ -495,20 +500,19 @@ mkinlcall(Node **np, Node *fn) ...@@ -495,20 +500,19 @@ mkinlcall(Node **np, Node *fn)
as = N; as = N;
if(fn->type->thistuple) { if(fn->type->thistuple) {
t = getthisx(fn->type)->type; t = getthisx(fn->type)->type;
if(t != T && t->nname != N && !isblank(t->nname) && !t->nname->inlvar)
if(t != T && t->nname != N && !t->nname->inlvar)
fatal("missing inlvar for %N\n", t->nname); fatal("missing inlvar for %N\n", t->nname);
if(n->left->op == ODOTMETH) { if(n->left->op == ODOTMETH) {
if (!n->left->left) if (!n->left->left)
fatal("method call without receiver: %+N", n); fatal("method call without receiver: %+N", n);
if(t != T && t->nname) if(t != T && t->nname != N && !isblank(t->nname))
as = nod(OAS, t->nname->inlvar, n->left->left); as = nod(OAS, t->nname->inlvar, n->left->left);
// else if !ONAME add to init anyway? // else if !ONAME add to init anyway?
} else { // non-method call to method } else { // non-method call to method
if (!n->list) if (!n->list)
fatal("non-method call to method without first arg: %+N", n); fatal("non-method call to method without first arg: %+N", n);
if(t != T && t->nname) if(t != T && t->nname != N && !isblank(t->nname))
as = nod(OAS, t->nname->inlvar, n->list->n); as = nod(OAS, t->nname->inlvar, n->list->n);
} }
......
...@@ -13,3 +13,7 @@ func F1(T *T) bool { return T == nil } ...@@ -13,3 +13,7 @@ func F1(T *T) bool { return T == nil }
// Issue 2682. // Issue 2682.
func F2(c chan int) bool { return c == (<-chan int)(nil) } func F2(c chan int) bool { return c == (<-chan int)(nil) }
// Call of inlined method with blank receiver.
func (_ *T) M() int { return 1 }
func (t *T) MM() int { return t.M() }
...@@ -12,5 +12,9 @@ import "./one" ...@@ -12,5 +12,9 @@ import "./one"
func use() { func use() {
one.F1(nil) one.F1(nil)
one.F2(nil) one.F2(nil)
var t *one.T
t.M()
t.MM()
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment