Skip to content

Commit 87a3ac5

Browse files
cmd/compile: don't let -race override explicit -d=checkptr=0
Change-Id: Icfa204761045b72a8ea173fd55eddf1f0e58d819 Reviewed-on: https://go-review.googlesource.com/c/go/+/304253 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
1 parent 769d4b6 commit 87a3ac5

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

Diff for: src/cmd/compile/internal/base/flag.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ func ParseFlags() {
161161
Flag.WB = true
162162
Debug.InlFuncsWithClosures = 1
163163

164+
Debug.Checkptr = -1 // so we can tell whether it is set explicitly
165+
164166
Flag.Cfg.ImportMap = make(map[string]string)
165167

166168
objabi.AddVersionFlag() // -V
@@ -216,7 +218,9 @@ func ParseFlags() {
216218
}
217219
if Flag.Race || Flag.MSan {
218220
// -race and -msan imply -d=checkptr for now.
219-
Debug.Checkptr = 1
221+
if Debug.Checkptr == -1 { // if not set explicitly
222+
Debug.Checkptr = 1
223+
}
220224
}
221225

222226
if Flag.CompilingRuntime && Flag.N != 0 {
@@ -237,6 +241,10 @@ func ParseFlags() {
237241
Debug.Libfuzzer = 0
238242
}
239243

244+
if Debug.Checkptr == -1 { // if not set explicitly
245+
Debug.Checkptr = 0
246+
}
247+
240248
// set via a -d flag
241249
Ctxt.Debugpcln = Debug.PCTab
242250
}

Diff for: test/fixedbugs/bug513.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// run -race -gcflags=all=-d=checkptr=0
2+
// +build linux,amd64 linux,ppc64le darwin,amd64 freebsd,amd64 netbsd,amd64 windows,amd64
3+
4+
// Copyright 2021 The Go Authors. All rights reserved.
5+
// Use of this source code is governed by a BSD-style
6+
// license that can be found in the LICENSE file.
7+
8+
// Although -race turns on -d=checkptr, the explicit -d=checkptr=0
9+
// should override it.
10+
11+
package main
12+
13+
import "unsafe"
14+
15+
var v1 = new([2]int16)
16+
var v2 *[3]int64
17+
18+
func main() {
19+
v2 = (*[3]int64)(unsafe.Pointer(uintptr(unsafe.Pointer(&(*v1)[0]))))
20+
}

0 commit comments

Comments
 (0)