1
2
3
4
5
6
7 package builtins
8
9 import "unsafe"
10
11 func f0() {}
12
13 func append1() {
14 var b byte
15 var x int
16 var s []byte
17 _ = append()
18 _ = append("foo" )
19 _ = append(nil , s)
20 _ = append(x , s)
21 _ = append(s)
22 _ = append(s, nil...)
23 append (s)
24
25 _ = append(s, b)
26 _ = append(s, x )
27 _ = append(s, s )
28 _ = append(s...)
29 _ = append(s, b, s ...)
30 _ = append(s, 1, 2, 3)
31 _ = append(s, 1, 2, 3, x , 5, 6, 6)
32 _ = append(s, 1, 2 , s...)
33 _ = append([]interface{}(nil), 1, 2, "foo", x, 3.1425, false)
34
35 type S []byte
36 type T string
37 var t T
38 _ = append(s, "foo" )
39 _ = append(s, "foo"...)
40 _ = append(S(s), "foo" )
41 _ = append(S(s), "foo"...)
42 _ = append(s, t )
43 _ = append(s, t...)
44 _ = append(s, T("foo")...)
45 _ = append(S(s), t )
46 _ = append(S(s), t...)
47 _ = append(S(s), T("foo")...)
48 _ = append([]string{}, t , "foo")
49 _ = append([]T{}, t, "foo")
50 }
51
52
53 func append2() {
54 s0 := []int{0, 0}
55 s1 := append(s0, 2)
56 s2 := append(s1, 3, 5, 7)
57 s3 := append(s2, s0...)
58 s4 := append(s3[3:6], s3[2:]...)
59
60 var t []interface{}
61 t = append(t, 42, 3.1415, "foo")
62
63 var b []byte
64 b = append(b, "bar"...)
65
66 _ = s4
67 }
68
69 func append3() {
70 f1 := func() (s []int) { return }
71 f2 := func() (s []int, x int) { return }
72 f3 := func() (s []int, x, y int) { return }
73 f5 := func() (s []interface{}, x int, y float32, z string, b bool) { return }
74 ff := func() (int, float32) { return 0, 0 }
75 _ = append(f0 ())
76 _ = append(f1())
77 _ = append(f2())
78 _ = append(f3())
79 _ = append(f5())
80 _ = append(ff ())
81 }
82
83 func cap1() {
84 var a [10]bool
85 var p *[20]int
86 var c chan string
87 _ = cap()
88 _ = cap(1, 2)
89 _ = cap(42 )
90 const _3 = cap(a)
91 assert(_3 == 10)
92 const _4 = cap(p)
93 assert(_4 == 20)
94 _ = cap(c)
95 cap (c)
96
97
98 type T struct{ a [10]int }
99 const _ = cap(((*T)(nil)).a)
100
101 var s [][]byte
102 _ = cap(s)
103 _ = cap(s... )
104 }
105
106 func cap2() {
107 f1a := func() (a [10]int) { return }
108 f1s := func() (s []int) { return }
109 f2 := func() (s []int, x int) { return }
110 _ = cap(f0 ())
111 _ = cap(f1a())
112 _ = cap(f1s())
113 _ = cap(f2())
114 }
115
116
117 func cap3() {
118 var f = func() int { return 0 }
119 var x = f()
120 const (
121 _ = cap([4]int{})
122 _ = cap([4]int{x})
123 _ = cap ([4]int{f()})
124 _ = cap ([4]int{cap([]int{})})
125 _ = cap([4]int{cap([4]int{})})
126 )
127 var y float64
128 var z complex128
129 const (
130 _ = cap([4]float64{})
131 _ = cap([4]float64{y})
132 _ = cap([4]float64{real(2i)})
133 _ = cap ([4]float64{real(z)})
134 )
135 var ch chan [10]int
136 const (
137 _ = cap (<-ch)
138 _ = cap ([4]int{(<-ch)[0]})
139 )
140 }
141
142 func clear1() {
143 var a [10]int
144 var m map[float64]string
145 var s []byte
146 clear(a )
147 clear(&a)
148 clear(m)
149 clear(s)
150 clear([]int{})
151 }
152
153 func close1() {
154 var c chan int
155 var r <-chan int
156 close()
157 close(1, 2)
158 close(42 )
159 close(r )
160 close(c)
161 _ = close (c)
162
163 var s []chan int
164 close(s... )
165 }
166
167 func close2() {
168 f1 := func() (ch chan int) { return }
169 f2 := func() (ch chan int, x int) { return }
170 close(f0 ())
171 close(f1())
172 close(f2())
173 }
174
175 func complex1() {
176 var i32 int32
177 var f32 float32
178 var f64 float64
179 var c64 complex64
180 var c128 complex128
181 _ = complex()
182 _ = complex(1)
183 _ = complex(true , 0)
184 _ = complex(i32 , 0)
185 _ = complex("foo" , 0)
186 _ = complex(c64 , 0)
187 _ = complex(0 , true)
188 _ = complex(0 , i32)
189 _ = complex(0 , "foo")
190 _ = complex(0 , c64)
191 _ = complex(f32, f32)
192 _ = complex(f32, 1)
193 _ = complex(f32, 1.0)
194 _ = complex(f32, 'a')
195 _ = complex(f64, f64)
196 _ = complex(f64, 1)
197 _ = complex(f64, 1.0)
198 _ = complex(f64, 'a')
199 _ = complex(f32 , f64)
200 _ = complex(f64 , f32)
201 _ = complex(1, 1)
202 _ = complex(1, 1.1)
203 _ = complex(1, 'a')
204 complex (1, 2)
205
206 var _ complex64 = complex(f32, f32)
207 var _ complex64 = complex (f64, f64)
208
209 var _ complex128 = complex (f32, f32)
210 var _ complex128 = complex(f64, f64)
211
212
213 const _ int = complex(1, 0)
214 const _ float32 = complex(1, 0)
215 const _ complex64 = complex(1, 0)
216 const _ complex128 = complex(1, 0)
217 const _ = complex(0i, 0i)
218 const _ = complex(0i, 0)
219 const _ int = 1.0 + complex(1, 0i)
220
221 const _ int = complex (1.1, 0)
222 const _ float32 = complex (1, 2)
223
224
225 var s uint
226 _ = complex(1 <<s, 0)
227 const _ = complex (1 <<s, 0)
228 var _ int = complex (1 <<s, 0)
229
230
231 type F32 float32
232 type F64 float64
233 var x32 F32
234 var x64 F64
235 c64 = complex(x32, x32)
236 _ = complex(x32 , f32)
237 _ = complex(f32 , x32)
238 c128 = complex(x64, x64)
239 _ = c128
240 _ = complex(x64 , f64)
241 _ = complex(f64 , x64)
242
243 var t []float32
244 _ = complex(t... )
245 }
246
247 func complex2() {
248 f1 := func() (x float32) { return }
249 f2 := func() (x, y float32) { return }
250 f3 := func() (x, y, z float32) { return }
251 _ = complex(f0 ())
252 _ = complex(f1())
253 _ = complex(f2())
254 _ = complex(f3())
255 }
256
257 func copy1() {
258 copy()
259 copy("foo")
260 copy([ ...]int{}, []int{})
261 copy([ ]int{}, [...]int{})
262 copy([ ]int8{}, "foo")
263
264
265 var a = [...]int{0, 1, 2, 3, 4, 5, 6, 7}
266 var s = make([]int, 6)
267 var b = make([]byte, 5)
268 n1 := copy(s, a[0:])
269 n2 := copy(s, s[2:])
270 n3 := copy(b, "Hello, World!")
271 _, _, _ = n1, n2, n3
272
273 var t [][]int
274 copy(t, t)
275 copy(t , nil)
276 copy(nil , t)
277 copy(nil , nil)
278 copy(t... )
279 }
280
281 func copy2() {
282 f1 := func() (a []int) { return }
283 f2 := func() (a, b []int) { return }
284 f3 := func() (a, b, c []int) { return }
285 copy(f0 ())
286 copy(f1())
287 copy(f2())
288 copy(f3())
289 }
290
291 func delete1() {
292 var m map[string]int
293 var s string
294 delete()
295 delete(1)
296 delete(1, 2, 3)
297 delete(m, 0 )
298 delete(m, s)
299 _ = delete (m, s)
300
301 var t []map[string]string
302 delete(t... )
303 }
304
305 func delete2() {
306 f1 := func() (m map[string]int) { return }
307 f2 := func() (m map[string]int, k string) { return }
308 f3 := func() (m map[string]int, k string, x float32) { return }
309 delete(f0 ())
310 delete(f1())
311 delete(f2())
312 delete(f3())
313 }
314
315 func imag1() {
316 var f32 float32
317 var f64 float64
318 var c64 complex64
319 var c128 complex128
320 _ = imag()
321 _ = imag(1, 2)
322 _ = imag(10)
323 _ = imag(2.7182818)
324 _ = imag("foo" )
325 _ = imag('a')
326 const _5 = imag(1 + 2i)
327 assert(_5 == 2)
328 f32 = _5
329 f64 = _5
330 const _6 = imag(0i)
331 assert(_6 == 0)
332 f32 = imag(c64)
333 f64 = imag(c128)
334 f32 = imag (c128)
335 f64 = imag (c64)
336 imag (c64)
337 _, _ = f32, f64
338
339
340 type C64 complex64
341 type C128 complex128
342 var x64 C64
343 var x128 C128
344 f32 = imag(x64)
345 f64 = imag(x128)
346
347 var a []complex64
348 _ = imag(a... )
349
350
351 const _ byte = imag(1.2 + 3i)
352 const _ complex128 = imag(1.2 + 3i)
353
354
355 var s uint
356 _ = imag(1 << s)
357 }
358
359 func imag2() {
360 f1 := func() (x complex128) { return }
361 f2 := func() (x, y complex128) { return }
362 _ = imag(f0 ())
363 _ = imag(f1())
364 _ = imag(f2())
365 }
366
367 func len1() {
368 const c = "foobar"
369 var a [10]bool
370 var p *[20]int
371 var m map[string]complex128
372 _ = len()
373 _ = len(1, 2)
374 _ = len(42 )
375 const _3 = len(c)
376 assert(_3 == 6)
377 const _4 = len(a)
378 assert(_4 == 10)
379 const _5 = len(p)
380 assert(_5 == 20)
381 _ = len(m)
382 len (c)
383
384
385 var t string
386 var hash map[interface{}][]*[10]int
387 const n = len (hash[recover()][len(t)])
388 assert(n == 10)
389 var ch <-chan int
390 const nn = len (hash[<-ch][len(t)])
391
392
393 type T struct{ a [10]int }
394 const _ = len(((*T)(nil)).a)
395
396 var s [][]byte
397 _ = len(s)
398 _ = len(s... )
399 }
400
401 func len2() {
402 f1 := func() (x []int) { return }
403 f2 := func() (x, y []int) { return }
404 _ = len(f0 ())
405 _ = len(f1())
406 _ = len(f2())
407 }
408
409
410 func len3() {
411 var f = func() int { return 0 }
412 var x = f()
413 const (
414 _ = len([4]int{})
415 _ = len([4]int{x})
416 _ = len ([4]int{f()})
417 _ = len ([4]int{len([]int{})})
418 _ = len([4]int{len([4]int{})})
419 )
420 var y float64
421 var z complex128
422 const (
423 _ = len([4]float64{})
424 _ = len([4]float64{y})
425 _ = len([4]float64{real(2i)})
426 _ = len ([4]float64{real(z)})
427 )
428 var ch chan [10]int
429 const (
430 _ = len (<-ch)
431 _ = len ([4]int{(<-ch)[0]})
432 )
433 }
434
435 func make1() {
436 var n int
437 var m float32
438 var s uint
439
440 _ = make()
441 _ = make(1 )
442 _ = make(int )
443
444
445 _ = make ([]int)
446 _ = make ([]int, 2, 3, 4)
447 _ = make([]int, int )
448 _ = make([]int, 10, float32 )
449 _ = make([]int, "foo" )
450 _ = make([]int, 10, 2.3 )
451 _ = make([]int, 5, 10.0)
452 _ = make([]int, 0i)
453 _ = make([]int, 1.0)
454 _ = make([]int, 1.0<<s)
455 _ = make([]int, 1.1 <<s)
456 _ = make([]int, - 1, 10)
457 _ = make([]int, 0, - 1)
458 _ = make([]int, - 1, - 1)
459 _ = make([]int, 1 <<100, 1 <<100)
460 _ = make([]int, 10 , 9)
461 _ = make([]int, 1 <<100, 12345)
462 _ = make([]int, m )
463 _ = &make ([]int, 0)
464
465
466 _ = make (map[int]string, 10, 20)
467 _ = make(map[int]float32, int )
468 _ = make(map[int]float32, "foo" )
469 _ = make(map[int]float32, 10)
470 _ = make(map[int]float32, n)
471 _ = make(map[int]float32, int64(n))
472 _ = make(map[string]bool, 10.0)
473 _ = make(map[string]bool, 10.0<<s)
474 _ = &make (map[string]bool)
475
476
477 _ = make (chan int, 10, 20)
478 _ = make(chan int, int )
479 _ = make(chan<- int, "foo" )
480 _ = make(chan int, - 10)
481 _ = make(<-chan float64, 10)
482 _ = make(chan chan int, n)
483 _ = make(chan string, int64(n))
484 _ = make(chan bool, 10.0)
485 _ = make(chan bool, 10.0<<s)
486 _ = &make (chan bool)
487
488 make ([]int, 10)
489
490 var t []int
491 _ = make([]int, t[0], t[1])
492 _ = make([]int, t... )
493 }
494
495 func make2() {
496 f1 := func() (x []int) { return }
497 _ = make(f0 ())
498 _ = make(f1 ())
499 }
500
501 func max1() {
502 var b bool
503 var c complex128
504 var x int
505 var s string
506 type myint int
507 var m myint
508 _ = max()
509 _ = max(b )
510 _ = max(c )
511 _ = max(x)
512 _ = max(s)
513 _ = max(x, x)
514 _ = max(x, x, x, x, x)
515 var _ int = max (m)
516 _ = max(x, m , x)
517
518 _ = max(1, x)
519 _ = max(1.0, x)
520 _ = max(1.2 , x)
521 _ = max(-10, 1.0, c )
522
523 const (
524 _ = max (x)
525 _ = max(true )
526 _ = max(1)
527 _ = max(1, 2.3, 'a')
528 _ = max(1, "foo" )
529 _ = max(1, 0i )
530 _ = max(1, 2 + 3i )
531 )
532 }
533
534 func max2() {
535 _ = assert(max(0) == 0)
536 _ = assert(max(0, 1) == 1)
537 _ = assert(max(0, -10, 123456789) == 123456789)
538 _ = assert(max(-12345678901234567890, 0) == 0)
539
540 _ = assert(max(1, 2.3) == 2.3)
541 _ = assert(max(1, 2.3, 'a') == 'a')
542
543 _ = assert(max("", "a") == "a")
544 _ = assert(max("abcde", "xyz", "foo", "bar") == "xyz")
545
546 const (
547 _ int = max(1.0)
548 _ float32 = max(1, 2)
549 _ int = max (1, 2.3)
550 _ int = max(1.2, 3)
551 _ byte = max(1, 'a')
552 )
553 }
554
555 func min1() {
556 var b bool
557 var c complex128
558 var x int
559 var s string
560 type myint int
561 var m myint
562 _ = min()
563 _ = min(b )
564 _ = min(c )
565 _ = min(x)
566 _ = min(s)
567 _ = min(x, x)
568 _ = min(x, x, x, x, x)
569 var _ int = min (m)
570 _ = min(x, m , x)
571
572 _ = min(1, x)
573 _ = min(1.0, x)
574 _ = min(1.2 , x)
575 _ = min(-10, 1.0, c )
576
577 const (
578 _ = min (x)
579 _ = min(true )
580 _ = min(1)
581 _ = min(1, 2.3, 'a')
582 _ = min(1, "foo" )
583 _ = min(1, 0i )
584 _ = min(1, 2 + 3i )
585 )
586 }
587
588 func min2() {
589 _ = assert(min(0) == 0)
590 _ = assert(min(0, 1) == 0)
591 _ = assert(min(0, -10, 123456789) == -10)
592 _ = assert(min(-12345678901234567890, 0) == -12345678901234567890)
593
594 _ = assert(min(1, 2.3) == 1)
595 _ = assert(min(1, 2.3, 'a') == 1)
596
597 _ = assert(min("", "a") == "")
598 _ = assert(min("abcde", "xyz", "foo", "bar") == "abcde")
599
600 const (
601 _ int = min(1.0)
602 _ float32 = min(1, 2)
603 _ int = min(1, 2.3)
604 _ int = min (1.2, 3)
605 _ byte = min(1, 'a')
606 )
607 }
608
609 func new1() {
610 _ = new()
611 _ = new(1, 2)
612 _ = new("foo" )
613 p := new(float64)
614 _ = new(struct{ x, y int })
615 q := new(*float64)
616 _ = *p == **q
617 new (int)
618 _ = &new (int)
619
620 _ = new(int... )
621 }
622
623 func new2() {
624 f1 := func() (x []int) { return }
625 _ = new(f0 ())
626 _ = new(f1 ())
627 }
628
629 func panic1() {
630 panic()
631 panic(1, 2)
632 panic(0)
633 panic("foo")
634 panic(false)
635 panic(1<<10)
636 panic(1 << 1000)
637 _ = panic (0)
638
639 var s []byte
640 panic(s)
641 panic(s... )
642 }
643
644 func panic2() {
645 f1 := func() (x int) { return }
646 f2 := func() (x, y int) { return }
647 panic(f0 ())
648 panic(f1())
649 panic(f2())
650 }
651
652 func print1() {
653 print()
654 print(1)
655 print(1, 2)
656 print("foo")
657 print(2.718281828)
658 print(false)
659 print(1<<10)
660 print(1 << 1000)
661 println(nil )
662
663 var s []int
664 print(s... )
665 _ = print ()
666 }
667
668 func print2() {
669 f1 := func() (x int) { return }
670 f2 := func() (x, y int) { return }
671 f3 := func() (x int, y float32, z string) { return }
672 print(f0 ())
673 print(f1())
674 print(f2())
675 print(f3())
676 }
677
678 func println1() {
679 println()
680 println(1)
681 println(1, 2)
682 println("foo")
683 println(2.718281828)
684 println(false)
685 println(1<<10)
686 println(1 << 1000)
687 println(nil )
688
689 var s []int
690 println(s... )
691 _ = println ()
692 }
693
694 func println2() {
695 f1 := func() (x int) { return }
696 f2 := func() (x, y int) { return }
697 f3 := func() (x int, y float32, z string) { return }
698 println(f0 ())
699 println(f1())
700 println(f2())
701 println(f3())
702 }
703
704 func real1() {
705 var f32 float32
706 var f64 float64
707 var c64 complex64
708 var c128 complex128
709 _ = real()
710 _ = real(1, 2)
711 _ = real(10)
712 _ = real(2.7182818)
713 _ = real("foo" )
714 const _5 = real(1 + 2i)
715 assert(_5 == 1)
716 f32 = _5
717 f64 = _5
718 const _6 = real(0i)
719 assert(_6 == 0)
720 f32 = real(c64)
721 f64 = real(c128)
722 f32 = real (c128)
723 f64 = real (c64)
724 real (c64)
725
726
727 type C64 complex64
728 type C128 complex128
729 var x64 C64
730 var x128 C128
731 f32 = imag(x64)
732 f64 = imag(x128)
733 _, _ = f32, f64
734
735 var a []complex64
736 _ = real(a... )
737
738
739 const _ byte = real(1 + 2.3i)
740 const _ complex128 = real(1 + 2.3i)
741
742
743 var s uint
744 _ = real(1 << s)
745 }
746
747 func real2() {
748 f1 := func() (x complex128) { return }
749 f2 := func() (x, y complex128) { return }
750 _ = real(f0 ())
751 _ = real(f1())
752 _ = real(f2())
753 }
754
755 func recover1() {
756 _ = recover()
757 _ = recover(10)
758 recover()
759
760 var s []int
761 recover(s... )
762 }
763
764 func recover2() {
765 f1 := func() (x int) { return }
766 f2 := func() (x, y int) { return }
767 _ = recover(f0 ())
768 _ = recover(f1())
769 _ = recover(f2())
770 }
771
772
773 type S0 struct{
774 a bool
775 b rune
776 c *int
777 d bool
778 e complex128
779 }
780
781 type S1 struct{
782 x float32
783 y string
784 z *S1
785 S0
786 }
787
788 type S2 struct{
789 *S1
790 }
791
792 type S3 struct {
793 a int64
794 b int32
795 }
796
797 type S4 struct {
798 S3
799 int32
800 }
801
802 type S5 struct {
803 a [3]int32
804 b int32
805 }
806
807 func (S2) m() {}
808
809 func Alignof1() {
810 var x int
811 _ = unsafe.Alignof()
812 _ = unsafe.Alignof(1, 2)
813 _ = unsafe.Alignof(int )
814 _ = unsafe.Alignof(42)
815 _ = unsafe.Alignof(new(struct{}))
816 _ = unsafe.Alignof(1<<10)
817 _ = unsafe.Alignof(1 << 1000)
818 _ = unsafe.Alignof(nil )
819 unsafe .Alignof(x)
820
821 var y S0
822 assert(unsafe.Alignof(y.a) == 1)
823 assert(unsafe.Alignof(y.b) == 4)
824 assert(unsafe.Alignof(y.c) == 8)
825 assert(unsafe.Alignof(y.d) == 1)
826 assert(unsafe.Alignof(y.e) == 8)
827
828 var s []byte
829 _ = unsafe.Alignof(s)
830 _ = unsafe.Alignof(s... )
831 }
832
833 func Alignof2() {
834 f1 := func() (x int32) { return }
835 f2 := func() (x, y int32) { return }
836 _ = unsafe.Alignof(f0 ())
837 assert(unsafe.Alignof(f1()) == 4)
838 _ = unsafe.Alignof(f2())
839 }
840
841 func Offsetof1() {
842 var x struct{ f int }
843 _ = unsafe.Offsetof()
844 _ = unsafe.Offsetof(1, 2)
845 _ = unsafe.Offsetof(int )
846 _ = unsafe.Offsetof(x )
847 _ = unsafe.Offsetof(nil )
848 _ = unsafe.Offsetof(x.f)
849 _ = unsafe.Offsetof((x.f))
850 _ = unsafe.Offsetof((((((((x))).f)))))
851 unsafe .Offsetof(x.f)
852
853 var y0 S0
854 assert(unsafe.Offsetof(y0.a) == 0)
855 assert(unsafe.Offsetof(y0.b) == 4)
856 assert(unsafe.Offsetof(y0.c) == 8)
857 assert(unsafe.Offsetof(y0.d) == 16)
858 assert(unsafe.Offsetof(y0.e) == 24)
859
860 var y1 S1
861 assert(unsafe.Offsetof(y1.x) == 0)
862 assert(unsafe.Offsetof(y1.y) == 8)
863 assert(unsafe.Offsetof(y1.z) == 24)
864 assert(unsafe.Offsetof(y1.S0) == 32)
865
866 assert(unsafe.Offsetof(y1.S0.a) == 0)
867 assert(unsafe.Offsetof(y1.a) == 32)
868 assert(unsafe.Offsetof(y1.b) == 36)
869 assert(unsafe.Offsetof(y1.c) == 40)
870 assert(unsafe.Offsetof(y1.d) == 48)
871 assert(unsafe.Offsetof(y1.e) == 56)
872
873 var y1p *S1
874 assert(unsafe.Offsetof(y1p.S0) == 32)
875
876 type P *S1
877 var p P = y1p
878 assert(unsafe.Offsetof(p.S0) == 32)
879
880 var y2 S2
881 assert(unsafe.Offsetof(y2.S1) == 0)
882 _ = unsafe.Offsetof(y2 .x)
883 _ = unsafe.Offsetof(y2 .m)
884
885 var s []byte
886 _ = unsafe.Offsetof(s... )
887 }
888
889 func Offsetof2() {
890 f1 := func() (x int32) { return }
891 f2 := func() (x, y int32) { return }
892 _ = unsafe.Offsetof(f0 ())
893 _ = unsafe.Offsetof(f1 ())
894 _ = unsafe.Offsetof(f2 ())
895 }
896
897 func Sizeof1() {
898 var x int
899 _ = unsafe.Sizeof()
900 _ = unsafe.Sizeof(1, 2)
901 _ = unsafe.Sizeof(int )
902 _ = unsafe.Sizeof(42)
903 _ = unsafe.Sizeof(new(complex128))
904 _ = unsafe.Sizeof(1<<10)
905 _ = unsafe.Sizeof(1 << 1000)
906 _ = unsafe.Sizeof(nil )
907 unsafe .Sizeof(x)
908
909
910 assert(unsafe.Sizeof(byte(0)) == 1)
911 assert(unsafe.Sizeof(uint8(0)) == 1)
912 assert(unsafe.Sizeof(int8(0)) == 1)
913 assert(unsafe.Sizeof(uint16(0)) == 2)
914 assert(unsafe.Sizeof(int16(0)) == 2)
915 assert(unsafe.Sizeof(uint32(0)) == 4)
916 assert(unsafe.Sizeof(int32(0)) == 4)
917 assert(unsafe.Sizeof(float32(0)) == 4)
918 assert(unsafe.Sizeof(uint64(0)) == 8)
919 assert(unsafe.Sizeof(int64(0)) == 8)
920 assert(unsafe.Sizeof(float64(0)) == 8)
921 assert(unsafe.Sizeof(complex64(0)) == 8)
922 assert(unsafe.Sizeof(complex128(0)) == 16)
923
924 var y0 S0
925 assert(unsafe.Sizeof(y0.a) == 1)
926 assert(unsafe.Sizeof(y0.b) == 4)
927 assert(unsafe.Sizeof(y0.c) == 8)
928 assert(unsafe.Sizeof(y0.d) == 1)
929 assert(unsafe.Sizeof(y0.e) == 16)
930 assert(unsafe.Sizeof(y0) == 40)
931
932 var y1 S1
933 assert(unsafe.Sizeof(y1) == 72)
934
935 var y2 S2
936 assert(unsafe.Sizeof(y2) == 8)
937
938 var y3 S3
939 assert(unsafe.Sizeof(y3) == 16)
940
941 var y4 S4
942 assert(unsafe.Sizeof(y4) == 24)
943
944 var y5 S5
945 assert(unsafe.Sizeof(y5) == 16)
946
947 var a3 [10]S3
948 assert(unsafe.Sizeof(a3) == 160)
949
950
951 type T struct {
952 a int32
953 _ int32
954 c int32
955 }
956 assert(unsafe.Sizeof(T{}) == 12)
957
958 var s []byte
959 _ = unsafe.Sizeof(s)
960 _ = unsafe.Sizeof(s... )
961 }
962
963 func Sizeof2() {
964 f1 := func() (x int64) { return }
965 f2 := func() (x, y int64) { return }
966 _ = unsafe.Sizeof(f0 ())
967 assert(unsafe.Sizeof(f1()) == 8)
968 _ = unsafe.Sizeof(f2())
969 }
970
971 func Slice1() {
972 var x int
973 unsafe.Slice()
974 unsafe.Slice(1, 2, 3)
975 unsafe.Slice(1 , 2)
976 unsafe.Slice(nil , 0)
977 unsafe.Slice(&x, "foo" )
978 unsafe.Slice(&x, 1.2 )
979 unsafe.Slice(&x, - 1)
980 unsafe .Slice(&x, 0)
981 var _ []byte = unsafe .Slice(&x, 0)
982
983 var _ []int = unsafe.Slice(&x, 0)
984 _ = unsafe.Slice(&x, 1.0)
985 _ = unsafe.Slice((*int)(nil), 0)
986 }
987
988 func SliceData1() {
989 var s []int
990 unsafe.SliceData(0 )
991 unsafe .SliceData(s)
992
993 type S []int
994 _ = unsafe.SliceData(s)
995 _ = unsafe.SliceData(S{})
996 }
997
998 func String1() {
999 var b byte
1000 unsafe.String()
1001 unsafe.String(1, 2, 3)
1002 unsafe.String(1 , 2)
1003 unsafe.String(&b, "foo" )
1004 unsafe.String(&b, 1.2 )
1005 unsafe.String(&b, - 1)
1006 unsafe .String(&b, 0)
1007 var _ []byte = unsafe .String(&b, 0)
1008
1009 var _ string = unsafe.String(&b, 0)
1010 _ = unsafe.String(&b, 1.0)
1011 _ = unsafe.String(nil, 0)
1012 }
1013
1014 func StringData1() {
1015 var s string
1016 type S string
1017 unsafe.StringData(0 )
1018 unsafe.StringData(S ("foo"))
1019 unsafe .StringData(s)
1020
1021 _ = unsafe.StringData(s)
1022 _ = unsafe.StringData("foo")
1023 }
1024
1025
1026 func assert1() {
1027 var x int
1028 assert()
1029 assert(1, 2)
1030 assert("foo" )
1031 assert(x )
1032 assert(true)
1033 assert (false)
1034 _ = assert(true)
1035
1036 var s []byte
1037 assert(s... )
1038 }
1039
1040 func assert2() {
1041 f1 := func() (x bool) { return }
1042 f2 := func() (x bool) { return }
1043 assert(f0 ())
1044 assert(f1 ())
1045 assert(f2 ())
1046 }
1047
1048
1049 func trace1() {
1050
1051
1052
1053
1054
1055 var s []byte
1056 trace(s... )
1057 }
1058
1059 func trace2() {
1060 f1 := func() (x int) { return }
1061 f2 := func() (x int, y string) { return }
1062 f3 := func() (x int, y string, z []int) { return }
1063 _ = f1
1064 _ = f2
1065 _ = f3
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075 }
1076
View as plain text