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