Source file test/inline_endian.go
1 // errorcheckwithauto -0 -m -d=inlfuncswithclosures=1 2 3 //go:build (386 || amd64 || arm64 || ppc64le || s390x) && !gcflags_noopt 4 5 // Copyright 2021 The Go Authors. All rights reserved. 6 // Use of this source code is governed by a BSD-style 7 // license that can be found in the LICENSE file. 8 9 // Similar to inline.go, but only for architectures that can merge loads. 10 11 package foo 12 13 import ( 14 "encoding/binary" 15 ) 16 17 // Ensure that simple encoding/binary functions are cheap enough 18 // that functions using them can also be inlined (issue 42958). 19 func endian(b []byte) uint64 { // ERROR "can inline endian" "b does not escape" 20 return binary.LittleEndian.Uint64(b) + binary.BigEndian.Uint64(b) // ERROR "inlining call to binary.littleEndian.Uint64" "inlining call to binary.bigEndian.Uint64" 21 } 22 23 func appendLittleEndian(b []byte) []byte { // ERROR "can inline appendLittleEndian" "leaking param: b to result ~r0 level=0" 24 b = binary.LittleEndian.AppendUint64(b, 64) // ERROR "inlining call to binary.littleEndian.AppendUint64" 25 b = binary.LittleEndian.AppendUint32(b, 32) // ERROR "inlining call to binary.littleEndian.AppendUint32" 26 b = binary.LittleEndian.AppendUint16(b, 16) // ERROR "inlining call to binary.littleEndian.AppendUint16" 27 return b 28 } 29 30 func appendBigEndian(b []byte) []byte { // ERROR "can inline appendBigEndian" "leaking param: b to result ~r0 level=0" 31 b = binary.BigEndian.AppendUint64(b, 64) // ERROR "inlining call to binary.bigEndian.AppendUint64" 32 b = binary.BigEndian.AppendUint32(b, 32) // ERROR "inlining call to binary.bigEndian.AppendUint32" 33 b = binary.BigEndian.AppendUint16(b, 16) // ERROR "inlining call to binary.bigEndian.AppendUint16" 34 return b 35 } 36