mirror of
https://github.com/golang/go.git
synced 2025-10-19 19:13:18 +00:00

Currently, for a write of a pointer (e.g. *p = x where x is a pointer), we generate an explicit nil check of p, despite that the store instruction may have the same faulting behavior as the nil check. This is because the write needs a write barrier, which creates a control flow, which prevents the nil check being removed as it is in a differnt block as the actual store. This CL duplicates the nil check to two branches, so it is likely that they will be followed by the actual store and the write barrier load, which may have the same faulting behavior, so they can be removed. Change-Id: Ied9480de5dd6a8fcbd5affc5f6e029944943cc07 Reviewed-on: https://go-review.googlesource.com/c/go/+/705156 Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com>
37 lines
919 B
Go
37 lines
919 B
Go
// errorcheck -0 -d=nil
|
|
|
|
//go:build wasm
|
|
|
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Test that nil checks are removed.
|
|
// Optimization is enabled.
|
|
|
|
package p
|
|
|
|
func f5(p *float32, q *float64, r *float32, s *float64) float64 {
|
|
x := float64(*p) // ERROR "generated nil check"
|
|
y := *q // ERROR "generated nil check"
|
|
*r = 7 // ERROR "generated nil check"
|
|
*s = 9 // ERROR "generated nil check"
|
|
return x + y
|
|
}
|
|
|
|
type T [29]byte
|
|
|
|
func f6(p, q *T) {
|
|
x := *p // ERROR "generated nil check"
|
|
*q = x // ERROR "generated nil check"
|
|
}
|
|
|
|
// make sure to remove nil check for memory move (issue #18003)
|
|
func f8(t *[8]int) [8]int {
|
|
return *t // ERROR "generated nil check"
|
|
}
|
|
|
|
// nil check is not removed on Wasm.
|
|
func f9(x **int, y *int) {
|
|
*x = y // ERROR "generated nil check"
|
|
}
|