1 // Constant float assignment must survive in both compilers.
2 //
3 // The legacy interp read a constant float through LLVMConstRealGetDouble.
4 // That C function returns double in XMM0, but the purego binding read the
5 // return register RAX, so every constant float assignment came out 0 while
6 // integers (returned in RAX) survived. stage4 never used the binding, so the
7 // two compilers disagreed. The shapes below are the exact ones that were
8 // measured: single and multi-value, both widths, and a negative value.
9 //
10 // The values used to sit in package-level initializers; that form is now
11 // illegal in user code (zero value plus assignment in init(), and a main
12 // package cannot declare init()), so the assignments live at the top of main
13 // and the same constant-float codegen is exercised.
14 package main
15 16 var a1 float64
17 var b1, b2 float64
18 var e1 float32
19 var c1 int32
20 var d1, d2 int32
21 22 // A main package cannot declare init(), and a global may not be assigned in
23 // main(), so the assignments live in an init-named helper called first -
24 // exactly when the old package initializer ran.
25 func initGlobals() {
26 a1 = 1.5
27 b1, b2 = 2.5, -3.5
28 e1 = 7.5
29 c1 = 4
30 d1, d2 = 5, 6
31 }
32 33 func main() {
34 initGlobals()
35 if a1 != 1.5 {
36 panic("float64 single initializer")
37 }
38 if b1 != 2.5 || b2 != -3.5 {
39 panic("float64 pair initializer")
40 }
41 if e1 != 7.5 {
42 panic("float32 single initializer")
43 }
44 if c1 != 4 || d1 != 5 || d2 != 6 {
45 panic("int initializer")
46 }
47 println("ok")
48 }
49