Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/cover: go test -c -cover runtime fails #10270

Closed
dvyukov opened this issue Mar 27, 2015 · 1 comment
Closed

cmd/cover: go test -c -cover runtime fails #10270

dvyukov opened this issue Mar 27, 2015 · 1 comment
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Mar 27, 2015

$ go test -c -cover runtime
# runtime
/var/folders/00/0zkq0000h01000cxqpysvccm003y_w/T/go-build973521540/runtime/_test/_obj_test/cgocall.go:152: args escapes to heap, not allowed in runtime.
/var/folders/00/0zkq0000h01000cxqpysvccm003y_w/T/go-build973521540/runtime/_test/_obj_test/chan.go:95: t escapes to heap, not allowed in runtime.
/var/folders/00/0zkq0000h01000cxqpysvccm003y_w/T/go-build973521540/runtime/_test/_obj_test/chan.go:312: c escapes to heap, not allowed in runtime.
/var/folders/00/0zkq0000h01000cxqpysvccm003y_w/T/go-build973521540/runtime/_test/_obj_test/chan.go:635: t escapes to heap, not allowed in runtime.
/var/folders/00/0zkq0000h01000cxqpysvccm003y_w/T/go-build973521540/runtime/_test/_obj_test/chan.go:653: t escapes to heap, not allowed in runtime.
/var/folders/00/0zkq0000h01000cxqpysvccm003y_w/T/go-build973521540/runtime/_test/_obj_test/env_posix.go:40: arg escapes to heap, not allowed in runtime.
/var/folders/00/0zkq0000h01000cxqpysvccm003y_w/T/go-build973521540/runtime/_test/_obj_test/env_posix.go:51: arg escapes to heap, not allowed in runtime.
/var/folders/00/0zkq0000h01000cxqpysvccm003y_w/T/go-build973521540/runtime/_test/_obj_test/extern.go:10: rpc escapes to heap, not allowed in runtime.
/var/folders/00/0zkq0000h01000cxqpysvccm003y_w/T/go-build973521540/runtime/_test/_obj_test/hashmap.go:218: t escapes to heap, not allowed in runtime.
/var/folders/00/0zkq0000h01000cxqpysvccm003y_w/T/go-build973521540/runtime/_test/_obj_test/hashmap.go:287: t escapes to heap, not allowed in runtime.
/var/folders/00/0zkq0000h01000cxqpysvccm003y_w/T/go-build973521540/runtime/_test/_obj_test/hashmap.go:287: too many errors

The problem is that cover strips all comments, including important //go:noescape/nosplit/linkname comments that affect behavior. We have such comments in runtime, bytes, crypto/md5, syscall and maybe other packages.

cover must not strip these comments.

FWIW, here is a patch that works for me:

diff --git a/cmd/cover/cover.go b/cmd/cover/cover.go
index 3aaf246..2bce5c6 100644
--- a/cmd/cover/cover.go
+++ b/cmd/cover/cover.go
@@ -19,6 +19,7 @@ import (
    "path/filepath"
    "sort"
    "strconv"
+   "strings"
 )

 const usageMessage = "" +
@@ -324,11 +325,26 @@ func annotate(name string) {
    if err != nil {
        log.Fatalf("cover: %s: %s", name, err)
    }
-   parsedFile, err := parser.ParseFile(fset, name, content, 0)
+   parsedFile, err := parser.ParseFile(fset, name, content, parser.ParseComments)
    if err != nil {
        log.Fatalf("cover: %s: %s", name, err)
    }

+   cgs := parsedFile.Comments
+   parsedFile.Comments = nil
+   for _, cg := range cgs {
+       cs := cg.List
+       cg.List = nil
+       for _, c := range cs {
+           if strings.HasPrefix(c.Text, "//go:") {
+               cg.List = append(cg.List, c)
+           }
+       }
+       if cg.List != nil {
+           parsedFile.Comments = append(parsedFile.Comments, cg)
+       }
+   }
+
@dvyukov dvyukov added this to the Go1.5 milestone Mar 27, 2015
@robpike
Copy link
Contributor

robpike commented Mar 27, 2015

@robpike robpike closed this as completed Mar 27, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
@rsc rsc unassigned robpike Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants