1
2
3
4
5 package test
6
7 import (
8 "bytes"
9 "internal/platform"
10 "internal/testenv"
11 "os"
12 "path/filepath"
13 "runtime"
14 "strings"
15 "testing"
16 )
17
18 type T struct {
19 x [2]int64
20 p *byte
21 }
22
23
24 func makeT() T {
25 return T{}
26 }
27
28 var g T
29
30 var sink any
31
32 func TestIssue15854(t *testing.T) {
33 for i := 0; i < 10000; i++ {
34 if g.x[0] != 0 {
35 t.Fatalf("g.x[0] clobbered with %x\n", g.x[0])
36 }
37
38
39
40
41
42
43 g = makeT()
44 sink = make([]byte, 1000)
45 }
46 }
47 func TestIssue15854b(t *testing.T) {
48 const N = 10000
49 a := make([]T, N)
50 for i := 0; i < N; i++ {
51 a = append(a, makeT())
52 sink = make([]byte, 1000)
53 }
54 for i, v := range a {
55 if v.x[0] != 0 {
56 t.Fatalf("a[%d].x[0] clobbered with %x\n", i, v.x[0])
57 }
58 }
59 }
60
61
62 func TestIssue16214(t *testing.T) {
63 testenv.MustHaveGoBuild(t)
64 dir := t.TempDir()
65
66 src := filepath.Join(dir, "x.go")
67 err := os.WriteFile(src, []byte(issue16214src), 0644)
68 if err != nil {
69 t.Fatalf("could not write file: %v", err)
70 }
71
72 cmd := testenv.Command(t, testenv.GoToolPath(t), "tool", "compile", "-p=main", "-S", "-o", filepath.Join(dir, "out.o"), src)
73 out, err := cmd.CombinedOutput()
74 if err != nil {
75 t.Fatalf("go tool compile: %v\n%s", err, out)
76 }
77
78 if strings.Contains(string(out), "unknown line number") {
79 t.Errorf("line number missing in assembly:\n%s", out)
80 }
81 }
82
83 var issue16214src = `
84 package main
85
86 func Mod32(x uint32) uint32 {
87 return x % 3 // frontend rewrites it as HMUL with 2863311531, the LITERAL node has unknown Pos
88 }
89 `
90
91
92
93
94
95
96 func TestIssue77597(t *testing.T) {
97 if !platform.RaceDetectorSupported(runtime.GOOS, runtime.GOARCH) {
98 t.Skipf("race detector not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
99 }
100 testenv.MustHaveGoBuild(t)
101 testenv.MustHaveGoRun(t)
102 testenv.MustHaveCGO(t)
103
104 dir := t.TempDir()
105 src := filepath.Join(dir, "main.go")
106 err := os.WriteFile(src, []byte(issue77597src), 0644)
107 if err != nil {
108 t.Fatalf("could not write file: %v", err)
109 }
110
111 cmd := testenv.Command(t, testenv.GoToolPath(t), "run", "-race", "-gcflags=all=-N -l", src)
112 out, err := cmd.CombinedOutput()
113 if err != nil {
114
115 unsupportedVMA := []byte("unsupported VMA range")
116 if bytes.Contains(out, unsupportedVMA) {
117 t.Skipf("skipped due to unsupported VMA on %s/%s", runtime.GOOS, runtime.GOARCH)
118 } else {
119 t.Fatalf("program failed: %v\n%s", err, out)
120 }
121 }
122 }
123
124 var issue77597src = `
125 package main
126
127 import "fmt"
128
129 func main() {
130 fmt.Println("OK")
131 }
132 `
133
View as plain text