3 // Copyright 2010 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.
7 // Test that many initializations can be done at link time and
8 // generate no executable init functions.
9 // This test is run by sinit_run.go.
15 // Should be no init func in the assembly.
16 // All these initializations should be done at link time.
18 type S struct{ a, b, c int }
19 type SS struct{ aa, bb, cc S }
20 type SA struct{ a, b, c [3]int }
21 type SC struct{ a, b, c []int }
27 slice = []byte{1, 2, 3}
28 sliceInt = []int{1, 2, 3}
29 hello = "hello, world"
30 bytes = []byte("hello, world")
34 nilmap map[string]int = nil
36 nilchan chan int = nil
40 var a = [3]int{1001, 1002, 1003}
41 var s = S{1101, 1102, 1103}
42 var c = []int{1201, 1202, 1203}
44 var aa = [3][3]int{[3]int{2001, 2002, 2003}, [3]int{2004, 2005, 2006}, [3]int{2007, 2008, 2009}}
45 var as = [3]S{S{2101, 2102, 2103}, S{2104, 2105, 2106}, S{2107, 2108, 2109}}
46 var ac = [3][]int{[]int{2201, 2202, 2203}, []int{2204, 2205, 2206}, []int{2207, 2208, 2209}}
48 var sa = SA{[3]int{3001, 3002, 3003}, [3]int{3004, 3005, 3006}, [3]int{3007, 3008, 3009}}
49 var ss = SS{S{3101, 3102, 3103}, S{3104, 3105, 3106}, S{3107, 3108, 3109}}
50 var sc = SC{[]int{3201, 3202, 3203}, []int{3204, 3205, 3206}, []int{3207, 3208, 3209}}
52 var ca = [][3]int{[3]int{4001, 4002, 4003}, [3]int{4004, 4005, 4006}, [3]int{4007, 4008, 4009}}
53 var cs = []S{S{4101, 4102, 4103}, S{4104, 4105, 4106}, S{4107, 4108, 4109}}
54 var cc = [][]int{[]int{4201, 4202, 4203}, []int{4204, 4205, 4206}, []int{4207, 4208, 4209}}
56 var answers = [...]int{
75 2001, 2201, 2301, 4001, 4201, 4301, 5001, 5201, 5301,
76 2002, 2202, 2302, 4002, 4202, 4302, 5002, 5202, 5302,
77 2003, 2203, 2303, 4003, 4203, 4303, 5003, 5203, 5303,
89 2004, 2204, 2304, 4004, 4204, 4304, 5004, 5204, 5304,
90 2005, 2205, 2305, 4005, 4205, 4305, 5005, 5205, 5305,
91 2006, 2206, 2306, 4006, 4206, 4306, 5006, 5206, 5306,
103 2007, 2207, 2307, 4007, 4207, 4307, 5007, 5207, 5307,
104 2008, 2208, 2308, 4008, 4208, 4308, 5008, 5208, 5308,
105 2009, 2209, 2309, 4009, 4209, 4309, 5009, 5209, 5309,
113 copy_sliceInt = sliceInt
116 // Could be handled without an initialization function, but
117 // requires special handling for "a = []byte("..."); b = a"
118 // which is not a likely case.
119 // copy_bytes = bytes
120 // https://codereview.appspot.com/171840043 is one approach to
121 // make this special case work.
123 copy_four, copy_five = four, five
124 copy_x, copy_y = x, y
125 copy_nilslice = nilslice
127 copy_nilfunc = nilfunc
128 copy_nilchan = nilchan
148 var copy_answers = answers
171 var c0 = complex64(0)
172 var c1 = complex64(1)
175 var d0 = complex128(0)
176 var d1 = complex128(1)
179 var s0 = []int{0, 0, 0}
180 var s1 = []int{1, 2, 3}
182 func fi() int { return 1 }
185 var a0 = [10]int{0, 0, 0}
186 var a1 = [10]int{1, 2, 3, 4}
188 type T struct{ X, Y int }
194 var t1 = T{X: 1, Y: 2}
198 var ps0 = &[]int{0, 0, 0}
199 var ps1 = &[]int{1, 2, 3}
202 var pa0 = &[10]int{0, 0, 0}
203 var pa1 = &[10]int{1, 2, 3}
209 var pt1 = &T{X: 1, Y: 2}
212 // The checks similar to
214 // are commented out. The compiler no longer statically initializes them.
215 // See issue 7665 and https://codereview.appspot.com/93200044.
216 // If https://codereview.appspot.com/169040043 is submitted, and this
217 // test is changed to pass -complete to the compiler, then we can
218 // uncomment the copy lines again.
263 // var copy_psx = psx
267 // var copy_pax = pax
271 // var copy_ptx = ptx
278 var _ interface{} = 1
288 var _ Mer = (*T1)(nil)
291 var PtrByte unsafe.Pointer = unsafe.Pointer(&Byte)