github.com/q45/go@v0.0.0-20151101211701-a4fb8c13db3f/test/inline.go (about)

     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  }
    25  
    26  //go:noinline
    27  func g(x int) int {
    28  	return x + 1
    29  }
    30  
    31  func h(x int) int { // ERROR "can inline h"
    32  	return x + 2
    33  }