Commit 09a17ca1 authored by Russ Cox's avatar Russ Cox

cmd/gc: make inlined labels distinct

Fixes #4748.

R=ken2
CC=golang-dev
https://golang.org/cl/7261044
parent d82dcadb
...@@ -510,6 +510,8 @@ tinlvar(Type *t) ...@@ -510,6 +510,8 @@ tinlvar(Type *t)
return nblank; return nblank;
} }
static int inlgen;
// 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.
// On return ninit has the parameter assignments, the nbody is the // On return ninit has the parameter assignments, the nbody is the
// inlined function body and list, rlist contain the input, output // inlined function body and list, rlist contain the input, output
...@@ -730,6 +732,7 @@ mkinlcall1(Node **np, Node *fn, int isddd) ...@@ -730,6 +732,7 @@ mkinlcall1(Node **np, Node *fn, int isddd)
} }
inlretlabel = newlabel(); inlretlabel = newlabel();
inlgen++;
body = inlsubstlist(fn->inl); body = inlsubstlist(fn->inl);
body = list(body, nod(OGOTO, inlretlabel, N)); // avoid 'not used' when function doesnt have return body = list(body, nod(OGOTO, inlretlabel, N)); // avoid 'not used' when function doesnt have return
...@@ -855,6 +858,7 @@ inlsubstlist(NodeList *ll) ...@@ -855,6 +858,7 @@ inlsubstlist(NodeList *ll)
static Node* static Node*
inlsubst(Node *n) inlsubst(Node *n)
{ {
char *p;
Node *m, *as; Node *m, *as;
NodeList *ll; NodeList *ll;
...@@ -897,6 +901,16 @@ inlsubst(Node *n) ...@@ -897,6 +901,16 @@ inlsubst(Node *n)
typecheck(&m, Etop); typecheck(&m, Etop);
// dump("Return after substitution", m); // dump("Return after substitution", m);
return m; return m;
case OGOTO:
case OLABEL:
m = nod(OXXX, N, N);
*m = *n;
m->ninit = nil;
p = smprint("%s·%d", n->left->sym->name, inlgen);
m->left = newname(lookup(p));
free(p);
return m;
} }
......
// run
// Copyright 2013 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.
// Issue 4748.
// This program used to complain because inlining created two exit labels.
package main
func jump() {
goto exit
exit:
return
}
func main() {
jump()
jump()
}
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