summaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/5g/cgen.c11
-rw-r--r--src/cmd/gc/align.c5
-rw-r--r--src/cmd/gc/go.h1
-rw-r--r--src/cmd/gc/inl.c9
-rw-r--r--src/cmd/gc/subr.c9
-rw-r--r--src/cmd/gc/typecheck.c2
-rw-r--r--src/cmd/go/doc.go1
-rw-r--r--src/cmd/go/generate.go5
-rw-r--r--src/cmd/go/generate_test.go6
9 files changed, 39 insertions, 10 deletions
diff --git a/src/cmd/5g/cgen.c b/src/cmd/5g/cgen.c
index c535cfbef..87c64f6e8 100644
--- a/src/cmd/5g/cgen.c
+++ b/src/cmd/5g/cgen.c
@@ -236,18 +236,14 @@ cgen(Node *n, Node *res)
cgen(nl, &n1);
nodconst(&n2, nl->type, -1);
gins(a, &n2, &n1);
- gmove(&n1, res);
- regfree(&n1);
- goto ret;
+ goto norm;
case OMINUS:
regalloc(&n1, nl->type, N);
cgen(nl, &n1);
nodconst(&n2, nl->type, 0);
gins(optoas(OMINUS, nl->type), &n2, &n1);
- gmove(&n1, res);
- regfree(&n1);
- goto ret;
+ goto norm;
// symmetric binary
case OAND:
@@ -483,12 +479,15 @@ abop: // asymmetric binary
cgen(nl, &n1);
}
gins(a, &n2, &n1);
+norm:
// Normalize result for types smaller than word.
if(n->type->width < widthptr) {
switch(n->op) {
case OADD:
case OSUB:
case OMUL:
+ case OCOM:
+ case OMINUS:
gins(optoas(OAS, n->type), &n1, &n1);
break;
}
diff --git a/src/cmd/gc/align.c b/src/cmd/gc/align.c
index 6e5d149c7..63ed2e5af 100644
--- a/src/cmd/gc/align.c
+++ b/src/cmd/gc/align.c
@@ -128,6 +128,11 @@ dowidth(Type *t)
return;
}
+ // break infinite recursion if the broken recursive type
+ // is referenced again
+ if(t->broke && t->width == 0)
+ return;
+
// defer checkwidth calls until after we're done
defercalc++;
diff --git a/src/cmd/gc/go.h b/src/cmd/gc/go.h
index 965a0550d..bbb883513 100644
--- a/src/cmd/gc/go.h
+++ b/src/cmd/gc/go.h
@@ -974,6 +974,7 @@ EXTERN int funcdepth;
EXTERN int typecheckok;
EXTERN int compiling_runtime;
EXTERN int compiling_wrappers;
+EXTERN int inl_nonlocal;
EXTERN int use_writebarrier;
EXTERN int pure_go;
EXTERN char* flag_installsuffix;
diff --git a/src/cmd/gc/inl.c b/src/cmd/gc/inl.c
index cf89b0090..45e15bb9b 100644
--- a/src/cmd/gc/inl.c
+++ b/src/cmd/gc/inl.c
@@ -804,9 +804,12 @@ inlvar(Node *var)
n->curfn = curfn; // the calling function, not the called one
n->addrtaken = var->addrtaken;
- // esc pass wont run if we're inlining into a iface wrapper
- // luckily, we can steal the results from the target func
- if(var->esc == EscHeap)
+ // Esc pass wont run if we're inlining into a iface wrapper.
+ // Luckily, we can steal the results from the target func.
+ // If inlining a function defined in another package after
+ // escape analysis is done, treat all local vars as escaping.
+ // See issue 9537.
+ if(var->esc == EscHeap || (inl_nonlocal && var->op == ONAME))
addrescapes(n);
curfn->dcl = list(curfn->dcl, n);
diff --git a/src/cmd/gc/subr.c b/src/cmd/gc/subr.c
index c3bc5af3b..26153d39b 100644
--- a/src/cmd/gc/subr.c
+++ b/src/cmd/gc/subr.c
@@ -2614,7 +2614,16 @@ genwrapper(Type *rcvr, Type *method, Sym *newnam, int iface)
fn->dupok = 1;
typecheck(&fn, Etop);
typechecklist(fn->nbody, Etop);
+
+ // Set inl_nonlocal to whether we are calling a method on a
+ // type defined in a different package. Checked in inlvar.
+ if(!methodrcvr->local)
+ inl_nonlocal = 1;
+
inlcalls(fn);
+
+ inl_nonlocal = 0;
+
curfn = nil;
funccompile(fn, 0);
}
diff --git a/src/cmd/gc/typecheck.c b/src/cmd/gc/typecheck.c
index 714c66268..ce12f150a 100644
--- a/src/cmd/gc/typecheck.c
+++ b/src/cmd/gc/typecheck.c
@@ -1335,7 +1335,7 @@ reswitch:
goto error;
// Unpack multiple-return result before type-checking.
- if(istype(t, TSTRUCT)) {
+ if(istype(t, TSTRUCT) && t->funarg) {
t = t->type;
if(istype(t, TFIELD))
t = t->type;
diff --git a/src/cmd/go/doc.go b/src/cmd/go/doc.go
index d0d8a8a5b..7191ee0f3 100644
--- a/src/cmd/go/doc.go
+++ b/src/cmd/go/doc.go
@@ -308,6 +308,7 @@ The generator is run in the package's source directory.
Go generate accepts one specific flag:
-run=""
+ TODO: This flag is unimplemented.
if non-empty, specifies a regular expression to
select directives whose command matches the expression.
diff --git a/src/cmd/go/generate.go b/src/cmd/go/generate.go
index baf4d2b55..3c0af8760 100644
--- a/src/cmd/go/generate.go
+++ b/src/cmd/go/generate.go
@@ -106,6 +106,7 @@ The generator is run in the package's source directory.
Go generate accepts one specific flag:
-run=""
+ TODO: This flag is unimplemented.
if non-empty, specifies a regular expression to
select directives whose command matches the expression.
@@ -255,6 +256,10 @@ func (g *Generator) split(line string) []string {
// Parse line, obeying quoted strings.
var words []string
line = line[len("//go:generate ") : len(line)-1] // Drop preamble and final newline.
+ // There may still be a carriage return.
+ if len(line) > 0 && line[len(line)-1] == '\r' {
+ line = line[:len(line)-1]
+ }
// One (possibly quoted) word per iteration.
Words:
for {
diff --git a/src/cmd/go/generate_test.go b/src/cmd/go/generate_test.go
index 660ebabbe..2ec548630 100644
--- a/src/cmd/go/generate_test.go
+++ b/src/cmd/go/generate_test.go
@@ -40,9 +40,15 @@ func TestGenerateCommandParse(t *testing.T) {
}
g.setShorthand([]string{"-command", "yacc", "go", "tool", "yacc"})
for _, test := range splitTests {
+ // First with newlines.
got := g.split("//go:generate " + test.in + "\n")
if !reflect.DeepEqual(got, test.out) {
t.Errorf("split(%q): got %q expected %q", test.in, got, test.out)
}
+ // Then with CRLFs, thank you Windows.
+ got = g.split("//go:generate " + test.in + "\r\n")
+ if !reflect.DeepEqual(got, test.out) {
+ t.Errorf("split(%q): got %q expected %q", test.in, got, test.out)
+ }
}
}