]> Cypherpunks.ru repositories - gostls13.git/blob - test/abi/bad_internal_offsets.go
d396c1a60f722667ca767bf3550a842c0e90e64d
[gostls13.git] / test / abi / bad_internal_offsets.go
1 // compile
2
3 //go:build !wasm
4 // +build !wasm
5
6 // Copyright 2021 The Go Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style
8 // license that can be found in the LICENSE file.
9
10 package genChecker0
11
12 var FailCount int
13
14 //go:noinline
15 func NoteFailure(fidx int, pkg string, pref string, parmNo int, _ uint64) {
16         FailCount += 1
17         if FailCount > 10 {
18                 panic("bad")
19         }
20 }
21
22 //go:noinline
23 func NoteFailureElem(fidx int, pkg string, pref string, parmNo int, elem int, _ uint64) {
24         FailCount += 1
25         if FailCount > 10 {
26                 panic("bad")
27         }
28 }
29
30 type StructF0S0 struct {
31         F0 int16
32         F1 string
33         F2 StructF0S1
34 }
35
36 type StructF0S1 struct {
37         _ uint16
38 }
39
40 // 0 returns 3 params
41 //go:registerparams
42 //go:noinline
43 func Test0(p0 uint32, p1 StructF0S0, p2 int32) {
44         // consume some stack space, so as to trigger morestack
45         var pad [256]uint64
46         pad[FailCount]++
47         if p0 == 0 {
48                 return
49         }
50         p1f0c := int16(-3096)
51         if p1.F0 != p1f0c {
52                 NoteFailureElem(0, "genChecker0", "parm", 1, 0, pad[0])
53                 return
54         }
55         p1f1c := "f6ꂅ8ˋ<"
56         if p1.F1 != p1f1c {
57                 NoteFailureElem(0, "genChecker0", "parm", 1, 1, pad[0])
58                 return
59         }
60         p1f2c := StructF0S1{}
61         if p1.F2 != p1f2c {
62                 NoteFailureElem(0, "genChecker0", "parm", 1, 2, pad[0])
63                 return
64         }
65         p2f0c := int32(496713155)
66         if p2 != p2f0c {
67                 NoteFailureElem(0, "genChecker0", "parm", 2, 0, pad[0])
68                 return
69         }
70         // recursive call
71         Test0(p0-1, p1, p2)
72         return
73         // 0 addr-taken params, 0 addr-taken returns
74 }