go/test/nilptr5_aix.go
Cherry Mui f9e61a9a32 cmd/compile: duplicate nil check to two branches of write barrier
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>
2025-09-19 07:13:32 -07:00

38 lines
993 B
Go

// errorcheck -0 -d=nil
//go:build aix
// 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 "removed nil check"
*s = 9 // ERROR "removed nil check"
return x + y
}
type T [29]byte
func f6(p, q *T) {
x := *p // ERROR "generated nil check"
*q = x // ERROR "removed 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"
}
// On AIX, a write nil check is removed, but a read nil check
// remains (for the write barrier).
func f9(x **int, y *int) {
*x = y // ERROR "generated nil check" "removed nil check"
}