Source file test/fixedbugs/bug473.go

     1  // run
     2  
     3  // Copyright 2013 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  // Used to be miscompiled by gccgo, due to a bug in handling
     8  // initialization ordering.
     9  
    10  package main
    11  
    12  func F(a ...interface{}) interface{} {
    13  	s := 0
    14  	for _, v := range a {
    15  		s += v.(int)
    16  	}
    17  	return s
    18  }
    19  
    20  var V1 = F(V10, V4, V3, V11)
    21  
    22  var V2 = F(V1)
    23  
    24  var V3 = F(1)
    25  
    26  var V4 = F(2)
    27  
    28  var V5 = F(3)
    29  
    30  var V6 = F(4)
    31  
    32  var V7 = F(5)
    33  
    34  var V8 = F(V14, V7, V3, V6, V5)
    35  
    36  var V9 = F(V4, F(V12))
    37  
    38  var V10 = F(V4, V9)
    39  
    40  var V11 = F(6)
    41  
    42  var V12 = F(V5, V3, V8)
    43  
    44  var V13 = F(7)
    45  
    46  var V14 = F(8)
    47  
    48  func expect(name string, a interface{}, b int) {
    49  	if a.(int) != b {
    50  		panic(name)
    51  	}
    52  }
    53  
    54  func main() {
    55  	expect("V1", V1, 38)
    56  	expect("V2", V2, 38)
    57  	expect("V3", V3, 1)
    58  	expect("V4", V4, 2)
    59  	expect("V5", V5, 3)
    60  	expect("V6", V6, 4)
    61  	expect("V7", V7, 5)
    62  	expect("V8", V8, 21)
    63  	expect("V9", V9, 27)
    64  	expect("V10", V10, 29)
    65  	expect("V11", V11, 6)
    66  	expect("V12", V12, 25)
    67  	expect("V13", V13, 7)
    68  	expect("V14", V14, 8)
    69  }
    70  

View as plain text