Commit de10a23d authored by Dmitriy Vyukov's avatar Dmitriy Vyukov

cmd/gc: racewalk: fix a bunch of minor issues

1. Prepend racefuncenter() to fn->enter -- fn->enter can contain new() calls,
and we want them to be in the scope of the function.
2. Dump fn->enter and fn->exit.
3. Add TODO that OTYPESW expression can contain interesting memory accesses.
4. Ignore only _ names instead of all names starting with _.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/6822048
parent 4094c1ba
...@@ -43,6 +43,13 @@ racewalk(Node *fn) ...@@ -43,6 +43,13 @@ racewalk(Node *fn)
} }
} }
<<<<<<< local
// TODO(dvyukov): ideally this should be:
// racefuncenter(getreturnaddress())
// because it's much more costly to obtain from runtime library.
nd = mkcall("racefuncenter", T, nil);
fn->enter = concat(list1(nd), fn->enter);
=======
// nodpc is the PC of the caller as extracted by // nodpc is the PC of the caller as extracted by
// getcallerpc. We use -widthptr(FP) for x86. // getcallerpc. We use -widthptr(FP) for x86.
// BUG: this will not work on arm. // BUG: this will not work on arm.
...@@ -52,13 +59,18 @@ racewalk(Node *fn) ...@@ -52,13 +59,18 @@ racewalk(Node *fn)
nodpc->xoffset = -widthptr; nodpc->xoffset = -widthptr;
nd = mkcall("racefuncenter", T, nil, nodpc); nd = mkcall("racefuncenter", T, nil, nodpc);
fn->enter = list(fn->enter, nd); fn->enter = list(fn->enter, nd);
>>>>>>> other
nd = mkcall("racefuncexit", T, nil); nd = mkcall("racefuncexit", T, nil);
fn->exit = list(fn->exit, nd); // works fine if (!fn->exit) fn->exit = list(fn->exit, nd);
racewalklist(curfn->nbody, nil); racewalklist(curfn->nbody, nil);
if(debug['W']) { if(debug['W']) {
snprint(s, sizeof(s), "after racewalk %S", curfn->nname->sym); snprint(s, sizeof(s), "after racewalk %S", curfn->nname->sym);
dumplist(s, curfn->nbody); dumplist(s, curfn->nbody);
snprint(s, sizeof(s), "after walk %S", curfn->nname->sym);
dumplist(s, curfn->nbody);
snprint(s, sizeof(s), "enter %S", curfn->nname->sym);
dumplist(s, curfn->enter);
} }
} }
...@@ -163,7 +175,7 @@ racewalknode(Node **np, NodeList **init, int wr, int skip) ...@@ -163,7 +175,7 @@ racewalknode(Node **np, NodeList **init, int wr, int skip)
case OSWITCH: case OSWITCH:
if(n->ntest->op == OTYPESW) if(n->ntest->op == OTYPESW)
// don't bother, we have static typization // TODO(dvyukov): the expression can contain calls or reads.
return; return;
racewalknode(&n->ntest, &n->ninit, 0, 0); racewalknode(&n->ntest, &n->ninit, 0, 0);
racewalklist(n->nbody, nil); racewalklist(n->nbody, nil);
...@@ -369,7 +381,7 @@ callinstr(Node *n, NodeList **init, int wr, int skip) ...@@ -369,7 +381,7 @@ callinstr(Node *n, NodeList **init, int wr, int skip)
if(n->op == ONAME) { if(n->op == ONAME) {
if(n->sym != S) { if(n->sym != S) {
if(n->sym->name != nil) { if(n->sym->name != nil) {
if(strncmp(n->sym->name, "_", sizeof("_")-1) == 0) if(strcmp(n->sym->name, "_") == 0)
return 0; return 0;
if(strncmp(n->sym->name, "autotmp_", sizeof("autotmp_")-1) == 0) if(strncmp(n->sym->name, "autotmp_", sizeof("autotmp_")-1) == 0)
return 0; return 0;
...@@ -381,7 +393,7 @@ callinstr(Node *n, NodeList **init, int wr, int skip) ...@@ -381,7 +393,7 @@ callinstr(Node *n, NodeList **init, int wr, int skip)
if(t->etype == TSTRUCT) { if(t->etype == TSTRUCT) {
res = 0; res = 0;
for(t1=t->type; t1; t1=t1->down) { for(t1=t->type; t1; t1=t1->down) {
if(t1->sym && strncmp(t1->sym->name, "_", sizeof("_")-1)) { if(t1->sym && strcmp(t1->sym->name, "_")) {
n = treecopy(n); n = treecopy(n);
f = nod(OXDOT, n, newname(t1->sym)); f = nod(OXDOT, n, newname(t1->sym));
if(callinstr(f, init, wr, 0)) { if(callinstr(f, init, wr, 0)) {
......
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