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: inconsistent NumStmt when //line clauses are used #27350

Closed
abhinav opened this issue Aug 29, 2018 · 4 comments
Closed

cmd/cover: inconsistent NumStmt when //line clauses are used #27350

abhinav opened this issue Aug 29, 2018 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@abhinav
Copy link
Contributor

abhinav commented Aug 29, 2018

What version of Go are you using (go version)?

$ go version
go version go1.11 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/abg/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/abg/dev/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ny/884_mv2d6q567f30vz6bff_c0000gn/T/go-build085094136=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I'm using Ragel to generate a lexer. Ragel includes //line clauses in
the generated code which help the Go compiler point back to the original .rl
file when compilation fails.

If I run ragel to generate the code and try to profile the coverage of the
generated code, the go tool cover command fails with the error,
inconsistent NumStmt: changed from 2 to 3.

$ brew install ragel
$ ragel --version
Ragel State Machine Compiler version 6.10 March 2017
Copyright (c) 2001-2009 by Adrian Thurston

$ ragel -Z -G2 -o lex.go lex.rl

$ go test -covermode=count -coverprofile cover.out -coverpkg=. .
ok      cover-repro     0.006s  coverage: 0.0% of statements in .

$ go tool cover -html=cover.out -o cover.html
cover: inconsistent NumStmt: changed from 2 to 3

This has not been an issue in Go 1.5-1.10.

Here's a minimal (non-sensical) lexer for which I was able to reproduce this
issue.

$ cat lex.rl


%% machine bool;

package lexer

%%{
write data;
}%%

func Parse(data []byte) bool {
    var p, pe, cs, ts, te, act int
    %% write init;

    _ = ts
    _ = te
    _ = act

    %%{
        main := |*
            'true' => { return true; fbreak; };
        *|;

        write exec;
    }%%

    return false
}

The generated code from this lexer is available here:
https://play.golang.org/p/cTT82DxYCjB

To reproduce the issue locally, you'll need to place a lex_test.go file in
the same package. (It can be empty.)

$ echo 'package lexer' > lex_test.go

I've also included a zip file containing all the required files and the
resulting cover.out on which go tool cover fails: repro.zip.

I think this has something to do with the //line comments generated by
Ragel because upon removing them, everything works as expected.

What did you expect to see?

An HTML file containing the coverage report.

What did you see instead?

The following error message.

cover: inconsistent NumStmt: changed from 2 to 3
@FiloSottile FiloSottile added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 30, 2018
@FiloSottile FiloSottile added this to the Go1.12 milestone Aug 30, 2018
@FiloSottile
Copy link
Contributor

@gopherbot please file this to be considered for backport to 1.11. This is a regression.

@gopherbot
Copy link
Contributor

Backport issue(s) opened: #27397 (for 1.11).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.

kennytm added a commit to pingcap/tidb-lightning that referenced this issue Dec 5, 2018

Verified

This commit was signed with the committer’s verified signature.
@ianlancetaylor
Copy link
Member

The problem doesn't seem to happen if the file is run through gofmt.

kennytm added a commit to pingcap/tidb-lightning that referenced this issue Dec 6, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
* *: added support for storing checkpoint at local filesystem

* config, tests: change default checkpoint driver to "file"

* mydump: regenerate the parser to avoid golang/go#27350 during coverage

* checkpoints: addressed comments
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/153061 mentions this issue: cmd/cover: avoid repeating positions

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants