Skip to content

cmd/go: invalid values for go build flag -p don't fail builds #46686

@ainar-g

Description

@ainar-g

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

$ go version
go version go1.17beta1 linux/amd64

(Same in 1.16.)

Does this issue reproduce with the latest release?

Yes.

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ainar/.cache/go-build"
GOENV="/home/ainar/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ainar/go/pkg/mod"
GONOPROXY="[removed]"
GONOSUMDB="[removed]"
GOOS="linux"
GOPATH="/home/ainar/go"
GOPRIVATE="[removed]"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/ainar/go/go1.17"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/ainar/go/go1.17/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17beta1"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="[removed]"
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=/tmp/go-build3876884678=/tmp/go-build -gno-record-gcc-switches"

What did you do?

go build -p=0

What did you expect to see?

Either a build with the default value of p, as if -p=0 weren't there, or an error message and a non-zero exit code.

What did you see instead?

Binary isn't built, there are no error messages, the exit code is zero.

See the following code:

par := cfg.BuildP
if cfg.BuildN {
par = 1
}
for i := 0; i < par; i++ {

Perhaps there should be either some validation there or something like:

par := cfg.BuildP
if par <= 0 {
        par = runtime.GOMAXPROCS(0)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions