1
2
3
4
5 package test
6
7 import (
8 "internal/testenv"
9 "os"
10 "path/filepath"
11 "strings"
12 "testing"
13 )
14
15 type T struct {
16 x [2]int64
17 p *byte
18 }
19
20
21 func makeT() T {
22 return T{}
23 }
24
25 var g T
26
27 var sink interface{}
28
29 func TestIssue15854(t *testing.T) {
30 for i := 0; i < 10000; i++ {
31 if g.x[0] != 0 {
32 t.Fatalf("g.x[0] clobbered with %x\n", g.x[0])
33 }
34
35
36
37
38
39
40 g = makeT()
41 sink = make([]byte, 1000)
42 }
43 }
44 func TestIssue15854b(t *testing.T) {
45 const N = 10000
46 a := make([]T, N)
47 for i := 0; i < N; i++ {
48 a = append(a, makeT())
49 sink = make([]byte, 1000)
50 }
51 for i, v := range a {
52 if v.x[0] != 0 {
53 t.Fatalf("a[%d].x[0] clobbered with %x\n", i, v.x[0])
54 }
55 }
56 }
57
58
59 func TestIssue16214(t *testing.T) {
60 testenv.MustHaveGoBuild(t)
61 dir := t.TempDir()
62
63 src := filepath.Join(dir, "x.go")
64 err := os.WriteFile(src, []byte(issue16214src), 0644)
65 if err != nil {
66 t.Fatalf("could not write file: %v", err)
67 }
68
69 cmd := testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-p=main", "-S", "-o", filepath.Join(dir, "out.o"), src)
70 out, err := cmd.CombinedOutput()
71 if err != nil {
72 t.Fatalf("go tool compile: %v\n%s", err, out)
73 }
74
75 if strings.Contains(string(out), "unknown line number") {
76 t.Errorf("line number missing in assembly:\n%s", out)
77 }
78 }
79
80 var issue16214src = `
81 package main
82
83 func Mod32(x uint32) uint32 {
84 return x % 3 // frontend rewrites it as HMUL with 2863311531, the LITERAL node has unknown Pos
85 }
86 `
87
View as plain text