...
Run Format

Source file test/fixedbugs/issue4518.go

Documentation: test/fixedbugs

     1  // run
     2  
     3  // Copyright 2012 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 4518. In some circumstances "return F(...)"
     8  // where F has multiple returns is miscompiled by 6g due to
     9  // bold assumptions in componentgen.
    10  
    11  package main
    12  
    13  //go:noinline
    14  func F(e interface{}) (int, int) {
    15  	return 3, 7
    16  }
    17  
    18  //go:noinline
    19  func G() (int, int) {
    20  	return 3, 7
    21  }
    22  
    23  func bogus1(d interface{}) (int, int) {
    24  	switch {
    25  	default:
    26  		return F(d)
    27  	}
    28  	return 0, 0
    29  }
    30  
    31  func bogus2() (int, int) {
    32  	switch {
    33  	default:
    34  		return F(3)
    35  	}
    36  	return 0, 0
    37  }
    38  
    39  func bogus3(d interface{}) (int, int) {
    40  	switch {
    41  	default:
    42  		return G()
    43  	}
    44  	return 0, 0
    45  }
    46  
    47  func bogus4() (int, int) {
    48  	switch {
    49  	default:
    50  		return G()
    51  	}
    52  	return 0, 0
    53  }
    54  
    55  func check(a, b int) {
    56  	if a != 3 || b != 7 {
    57  		println(a, b)
    58  		panic("a != 3 || b != 7")
    59  	}
    60  }
    61  
    62  func main() {
    63  	check(bogus1(42))
    64  	check(bogus2())
    65  }
    66  

View as plain text