Source file test/fixedbugs/issue26248.go

     1  // run
     2  
     3  // Copyright 2018 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  // Issue 26248: gccgo miscompiles interface field expression.
     8  // In G().M where G returns an interface, G() is evaluated twice.
     9  
    10  package main
    11  
    12  type I interface {
    13  	M()
    14  }
    15  
    16  type T struct{}
    17  
    18  func (T) M() {}
    19  
    20  var g = 0
    21  
    22  //go:noinline
    23  func G() I {
    24  	g++
    25  	return T{}
    26  }
    27  
    28  //go:noinline
    29  func Use(interface{}) {}
    30  
    31  func main() {
    32  	x := G().M
    33  	Use(x)
    34  
    35  	if g != 1 {
    36  		println("want 1, got", g)
    37  		panic("FAIL")
    38  	}
    39  }
    40  

View as plain text