]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: record line number for auto-generated wrappers as <autogenerated>:1
authorRuss Cox <rsc@golang.org>
Mon, 12 May 2014 15:59:55 +0000 (11:59 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 12 May 2014 15:59:55 +0000 (11:59 -0400)
Before we used line 1 of the first source file.
This should be clearer.

Fixes #4388.

LGTM=iant
R=golang-codereviews, iant
CC=golang-codereviews
https://golang.org/cl/92250044

src/cmd/gc/subr.c
src/liblink/obj.c
test/fixedbugs/issue4388.go [new file with mode: 0644]

index c7db5e8cd9252bf1c0a072cff68f5e3004519495..23cc9e11f741e7761436c471857104a0a95622e2 100644 (file)
@@ -2498,7 +2498,9 @@ genwrapper(Type *rcvr, Type *method, Sym *newnam, int iface)
                print("genwrapper rcvrtype=%T method=%T newnam=%S\n",
                        rcvr, method, newnam);
 
-       lineno = 1;     // less confusing than end of input
+       lexlineno++;
+       lineno = lexlineno;
+       linehist("<autogenerated>", 0, 0);
 
        dclcontext = PEXTERN;
        markdcl();
index 53ae47035424d0a45d9e55d2df13f16a1f749c76..b8083b0ec4b5b925dffed2306596b80b3bbaeea8 100644 (file)
@@ -183,7 +183,7 @@ linkgetline(Link *ctxt, int32 line, LSym **f, int32 *l)
                file = a[n].incl->name;
                dlno = a[n].idel-1;
        }
-       if((!ctxt->windows && file[0] == '/') || (ctxt->windows && file[1] == ':'))
+       if((!ctxt->windows && file[0] == '/') || (ctxt->windows && file[1] == ':') || file[0] == '<')
                snprint(buf, sizeof buf, "%s", file);
        else
                snprint(buf, sizeof buf, "%s/%s", ctxt->pathname, file);
diff --git a/test/fixedbugs/issue4388.go b/test/fixedbugs/issue4388.go
new file mode 100644 (file)
index 0000000..c8c53b7
--- /dev/null
@@ -0,0 +1,50 @@
+// run
+
+// Copyright 2014 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.
+
+package main
+
+import (
+       "fmt"
+       "io"
+       "runtime"
+)
+
+type T struct {
+       io.Closer
+}
+
+func f1() {
+       // The 4 here and below depends on the number of internal runtime frames
+       // that sit between a deferred function called during panic and
+       // the original frame. If that changes, this test will start failing and
+       // the number here will need to be updated.
+       defer checkLine(4)
+       var t *T
+       var c io.Closer = t
+       c.Close()
+}
+
+func f2() {
+       defer checkLine(4)
+       var t T
+       var c io.Closer = t
+       c.Close()
+}
+
+func main() {
+       f1()
+       f2()
+}
+
+func checkLine(n int) {
+       if err := recover(); err == nil {
+               panic("did not panic")
+       }
+       _, file, line, _ := runtime.Caller(n)
+       if file != "<autogenerated>" || line != 1 {
+               panic(fmt.Sprintf("expected <autogenerated>:1 have %s:%d", file, line))
+       }
+}