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

Open
abhinav opened this Issue Aug 29, 2018 · 4 comments

Comments

Projects
None yet
4 participants
@abhinav
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

This comment has been minimized.

Member

FiloSottile commented Aug 30, 2018

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

@gopherbot

This comment has been minimized.

gopherbot commented Aug 30, 2018

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.

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Dec 6, 2018

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

@gopherbot

This comment has been minimized.

gopherbot commented Dec 7, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment