Russ Cox | 77ccb16 | 2015-02-24 12:19:01 -0500 | [diff] [blame] | 1 | // errorcheck -0 -m |
| 2 | |
| 3 | // Copyright 2015 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, using compiler diagnostic flags, that inlining is working. |
| 8 | // Compiles but does not run. |
| 9 | |
| 10 | package foo |
| 11 | |
| 12 | import "unsafe" |
| 13 | |
| 14 | func add2(p *byte, n uintptr) *byte { // ERROR "can inline add2" "leaking param: p to result" |
| 15 | return (*byte)(add1(unsafe.Pointer(p), n)) // ERROR "inlining call to add1" |
| 16 | } |
| 17 | |
| 18 | func add1(p unsafe.Pointer, x uintptr) unsafe.Pointer { // ERROR "can inline add1" "leaking param: p to result" |
| 19 | return unsafe.Pointer(uintptr(p) + x) |
| 20 | } |
| 21 | |
| 22 | func f(x *byte) *byte { // ERROR "can inline f" "leaking param: x to result" |
| 23 | return add2(x, 1) // ERROR "inlining call to add2" "inlining call to add1" |
| 24 | } |