LEFT | RIGHT |
(no file at all) | |
1 // errorcheck -0 -m -l | 1 // errorcheck -0 -m -l |
2 | 2 |
3 // Copyright 2010 The Go Authors. All rights reserved. | 3 // Copyright 2010 The Go Authors. All rights reserved. |
4 // Use of this source code is governed by a BSD-style | 4 // Use of this source code is governed by a BSD-style |
5 // license that can be found in the LICENSE file. | 5 // license that can be found in the LICENSE file. |
6 | 6 |
7 // Test, using compiler diagnostic flags, that the escape analysis is working. | 7 // Test, using compiler diagnostic flags, that the escape analysis is working. |
8 // Compiles but does not run. Inlining is disabled. | 8 // Compiles but does not run. Inlining is disabled. |
9 | 9 |
10 package foo | 10 package foo |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 } | 554 } |
555 | 555 |
556 func myprint(y *int, x ...interface{}) *int { // ERROR "x does not escape" "leak
ing param: y" | 556 func myprint(y *int, x ...interface{}) *int { // ERROR "x does not escape" "leak
ing param: y" |
557 return y | 557 return y |
558 } | 558 } |
559 | 559 |
560 func myprint1(y *int, x ...interface{}) *interface{} { // ERROR "y does not esca
pe" "leaking param: x" | 560 func myprint1(y *int, x ...interface{}) *interface{} { // ERROR "y does not esca
pe" "leaking param: x" |
561 return &x[0] // ERROR "&x.0. escapes to heap" | 561 return &x[0] // ERROR "&x.0. escapes to heap" |
562 } | 562 } |
563 | 563 |
564 func foo75(z *int) { // ERROR "leaking param: z" | 564 func foo75(z *int) { // ERROR "z does not escape" |
565 myprint(z, 1, 2, 3) // ERROR "[.][.][.] argument does not escape" | 565 myprint(z, 1, 2, 3) // ERROR "[.][.][.] argument does not escape" |
566 } | 566 } |
567 | 567 |
568 func foo75a(z *int) { // ERROR "z does not escape" | 568 func foo75a(z *int) { // ERROR "z does not escape" |
569 » myprint1(z, 1, 2, 3) // ERROR "[.][.][.] argument escapes to heap" | 569 » myprint1(z, 1, 2, 3) // ERROR "[.][.][.] argument does not escape" |
| 570 } |
| 571 |
| 572 func foo75esc(z *int) { // ERROR "leaking param: z" |
| 573 » gxx = myprint(z, 1, 2, 3) // ERROR "[.][.][.] argument does not escape" |
| 574 } |
| 575 |
| 576 func foo75aesc(z *int) { // ERROR "z does not escape" |
| 577 » var ppi **interface{} // assignments to pointer dereferences lose trac
k |
| 578 » *ppi = myprint1(z, 1, 2, 3) // ERROR "[.][.][.] argument escapes to heap
" |
570 } | 579 } |
571 | 580 |
572 func foo76(z *int) { // ERROR "leaking param: z" | 581 func foo76(z *int) { // ERROR "leaking param: z" |
573 myprint(nil, z) // ERROR "[.][.][.] argument does not escape" | 582 myprint(nil, z) // ERROR "[.][.][.] argument does not escape" |
574 } | 583 } |
575 | 584 |
576 func foo76a(z *int) { // ERROR "leaking param: z" | 585 func foo76a(z *int) { // ERROR "leaking param: z" |
577 » myprint1(nil, z) // ERROR "[.][.][.] argument escapes to heap" | 586 » myprint1(nil, z) // ERROR "[.][.][.] argument does not escape" |
578 } | 587 } |
579 | 588 |
580 func foo76b() { | 589 func foo76b() { |
581 myprint(nil, 1, 2, 3) // ERROR "[.][.][.] argument does not escape" | 590 myprint(nil, 1, 2, 3) // ERROR "[.][.][.] argument does not escape" |
582 } | 591 } |
583 | 592 |
584 func foo76c() { | 593 func foo76c() { |
585 » myprint1(nil, 1, 2, 3) // ERROR "[.][.][.] argument escapes to heap" | 594 » myprint1(nil, 1, 2, 3) // ERROR "[.][.][.] argument does not escape" |
586 } | 595 } |
587 | 596 |
588 func foo76d() { | 597 func foo76d() { |
589 defer myprint(nil, 1, 2, 3) // ERROR "[.][.][.] argument does not escape
" | 598 defer myprint(nil, 1, 2, 3) // ERROR "[.][.][.] argument does not escape
" |
590 } | 599 } |
591 | 600 |
592 func foo76e() { | 601 func foo76e() { |
593 » defer myprint1(nil, 1, 2, 3) // ERROR "[.][.][.] argument escapes to hea
p" | 602 » defer myprint1(nil, 1, 2, 3) // ERROR "[.][.][.] argument does not escap
e" |
594 } | 603 } |
595 | 604 |
596 func foo76f() { | 605 func foo76f() { |
597 for { | 606 for { |
598 // TODO: This one really only escapes its scope, but we don't di
stinguish yet. | 607 // TODO: This one really only escapes its scope, but we don't di
stinguish yet. |
599 defer myprint(nil, 1, 2, 3) // ERROR "[.][.][.] argument escapes
to heap" | 608 defer myprint(nil, 1, 2, 3) // ERROR "[.][.][.] argument escapes
to heap" |
600 } | 609 } |
601 } | 610 } |
602 | 611 |
603 func foo76g() { | 612 func foo76g() { |
604 for { | 613 for { |
605 defer myprint1(nil, 1, 2, 3) // ERROR "[.][.][.] argument escape
s to heap" | 614 defer myprint1(nil, 1, 2, 3) // ERROR "[.][.][.] argument escape
s to heap" |
606 } | 615 } |
607 } | 616 } |
608 | 617 |
609 func foo77(z []interface{}) { // ERROR "z does not escape" | 618 func foo77(z []interface{}) { // ERROR "z does not escape" |
610 myprint(nil, z...) // z does not escape | 619 myprint(nil, z...) // z does not escape |
611 } | 620 } |
612 | 621 |
613 func foo77a(z []interface{}) { // ERROR "leaking param: z" | 622 func foo77a(z []interface{}) { // ERROR "z does not escape" |
614 myprint1(nil, z...) | 623 myprint1(nil, z...) |
| 624 } |
| 625 |
| 626 func foo77b(z []interface{}) { // ERROR "leaking param: z" |
| 627 var ppi **interface{} |
| 628 *ppi = myprint1(nil, z...) |
615 } | 629 } |
616 | 630 |
617 func foo78(z int) *int { // ERROR "moved to heap: z" | 631 func foo78(z int) *int { // ERROR "moved to heap: z" |
618 return &z // ERROR "&z escapes to heap" | 632 return &z // ERROR "&z escapes to heap" |
619 } | 633 } |
620 | 634 |
621 func foo78a(z int) *int { // ERROR "moved to heap: z" | 635 func foo78a(z int) *int { // ERROR "moved to heap: z" |
622 y := &z // ERROR "&z escapes to heap" | 636 y := &z // ERROR "&z escapes to heap" |
623 x := &y // ERROR "&y does not escape" | 637 x := &y // ERROR "&y does not escape" |
624 return *x // really return y | 638 return *x // really return y |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 | 1236 |
1223 func foo139() *byte { | 1237 func foo139() *byte { |
1224 type T struct { | 1238 type T struct { |
1225 x struct { | 1239 x struct { |
1226 y byte | 1240 y byte |
1227 } | 1241 } |
1228 } | 1242 } |
1229 t := new(T) // ERROR "new.T. escapes to heap" | 1243 t := new(T) // ERROR "new.T. escapes to heap" |
1230 return &t.x.y // ERROR "&t.x.y escapes to heap" | 1244 return &t.x.y // ERROR "&t.x.y escapes to heap" |
1231 } | 1245 } |
LEFT | RIGHT |