Source file test/mem2reg.go
1 // errorcheck -0 -d=ssa/mem2reg/debug=4 2 3 // Copyright 2025 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 // Test for variables accessed through pointers that can 8 // be promoted to register by the mem2reg pass. 9 10 package main 11 12 // The following functions are ported from src/cmd/compile/internal/ssa/mem2reg_test.go. 13 14 // Single-block mem2reg test 15 16 func justReturn0() int { 17 var x, y, z int // ERROR "promoted x in single block case" "promoted y in single block case" "promoted z in single block case" 18 xp := &x 19 yp := &y 20 zp := &z 21 *xp = 0 22 *yp = 1 23 *zp = 2 24 *yp = 3 25 *zp = 4 26 *yp = 5 27 valX1 := *xp 28 *zp = valX1 - 1 29 *xp = 1 30 *yp = 2 31 *xp = 3 32 *yp = 4 33 *xp = 5 34 valZ1 := *zp 35 *yp = valZ1 + 1 36 *zp = 1 37 *xp = 2 38 *zp = 3 39 *xp = 4 40 *zp = 5 41 valY1 := *yp 42 return valY1 43 } 44