1// errorcheck -0 -m 2 3//go:build !nacl && !386 && !wasm && !arm && !gcflags_noopt 4 5// Copyright 2019 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// Test, using compiler diagnostic flags, that inlining of functions 10// imported from the sync package is working. 11// Compiles but does not run. 12 13// FIXME: This test is disabled on architectures where atomic operations 14// are function calls rather than intrinsics, since this prevents inlining 15// of the sync fast paths. This test should be re-enabled once the problem 16// is solved. 17 18package foo 19 20import ( 21 "sync" 22) 23 24var mutex *sync.Mutex 25 26func small5() { // ERROR "can inline small5" 27 // the Unlock fast path should be inlined 28 mutex.Unlock() // ERROR "inlining call to sync\.\(\*Mutex\)\.Unlock" 29} 30 31func small6() { // ERROR "can inline small6" 32 // the Lock fast path should be inlined 33 mutex.Lock() // ERROR "inlining call to sync\.\(\*Mutex\)\.Lock" 34} 35 36var once *sync.Once 37 38func small7() { // ERROR "can inline small7" 39 // the Do fast path should be inlined 40 once.Do(small5) // ERROR "inlining call to sync\.\(\*Once\)\.Do" "inlining call to atomic\.\(\*Uint32\)\.Load" 41} 42 43var rwmutex *sync.RWMutex 44 45func small8() { // ERROR "can inline small8" 46 // the RUnlock fast path should be inlined 47 rwmutex.RUnlock() // ERROR "inlining call to sync\.\(\*RWMutex\)\.RUnlock" "inlining call to atomic\.\(\*Int32\)\.Add" 48} 49 50func small9() { // ERROR "can inline small9" 51 // the RLock fast path should be inlined 52 rwmutex.RLock() // ERROR "inlining call to sync\.\(\*RWMutex\)\.RLock" "inlining call to atomic\.\(\*Int32\)\.Add" 53} 54