1// errorcheck -+ -p=runtime 2 3// Copyright 2016 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 go:nowritebarrier and related directives. 8// This must appear to be in package runtime so the compiler 9// recognizes "systemstack". 10 11package runtime 12 13type t struct { 14 f *t 15} 16 17var x t 18var y *t 19 20//go:nowritebarrier 21func a1() { 22 x.f = y // ERROR "write barrier prohibited" 23 a2() // no error 24} 25 26//go:noinline 27func a2() { 28 x.f = y 29} 30 31//go:nowritebarrierrec 32func b1() { 33 b2() 34} 35 36//go:noinline 37func b2() { 38 x.f = y // ERROR "write barrier prohibited by caller" 39} 40 41// Test recursive cycles through nowritebarrierrec and yeswritebarrierrec. 42 43//go:nowritebarrierrec 44func c1() { 45 c2() 46} 47 48//go:yeswritebarrierrec 49func c2() { 50 c3() 51} 52 53func c3() { 54 x.f = y 55 c4() 56} 57 58//go:nowritebarrierrec 59func c4() { 60 c2() 61} 62 63//go:nowritebarrierrec 64func d1() { 65 d2() 66} 67 68func d2() { 69 d3() 70} 71 72//go:noinline 73func d3() { 74 x.f = y // ERROR "write barrier prohibited by caller" 75 d4() 76} 77 78//go:yeswritebarrierrec 79func d4() { 80 d2() 81} 82 83//go:noinline 84func systemstack(func()) {} 85 86//go:nowritebarrierrec 87func e1() { 88 systemstack(e2) 89 systemstack(func() { 90 x.f = y // ERROR "write barrier prohibited by caller" 91 }) 92} 93 94func e2() { 95 x.f = y // ERROR "write barrier prohibited by caller" 96} 97