Source file test/fixedbugs/issue27201.go

     1  // run
     2  
     3  // Copyright 2019 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  package main
     8  
     9  import (
    10  	"runtime"
    11  	"strings"
    12  )
    13  
    14  func main() {
    15  	f(nil)
    16  }
    17  
    18  func f(p *int32) {
    19  	defer checkstack()
    20  	v := *p         // panic should happen here, line 20
    21  	sink = int64(v) // not here, line 21
    22  }
    23  
    24  var sink int64
    25  
    26  func checkstack() {
    27  	_ = recover()
    28  	var buf [1024]byte
    29  	n := runtime.Stack(buf[:], false)
    30  	s := string(buf[:n])
    31  	if strings.Contains(s, "issue27201.go:21 ") {
    32  		panic("panic at wrong location")
    33  	}
    34  	if !strings.Contains(s, "issue27201.go:20 ") {
    35  		panic("no panic at correct location")
    36  	}
    37  }
    38  

View as plain text