Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(403)

Side by Side Diff: src/cmd/gc/esc.c

Issue 108870044: code review 108870044: cmd/gc: fix &result escaping into result (Closed)
Patch Set: diff -r cb1af30a996c https://code.google.com/p/go/ Created 10 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/escape2.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // Escape analysis. 5 // Escape analysis.
6 6
7 #include <u.h> 7 #include <u.h>
8 #include <libc.h> 8 #include <libc.h>
9 #include "go.h" 9 #include "go.h"
10 10
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 666
667 case OADDR: 667 case OADDR:
668 n->esc = EscNone; // until proven otherwise 668 n->esc = EscNone; // until proven otherwise
669 e->noesc = list(e->noesc, n); 669 e->noesc = list(e->noesc, n);
670 // current loop depth is an upper bound on actual loop depth 670 // current loop depth is an upper bound on actual loop depth
671 // of addressed value. 671 // of addressed value.
672 n->escloopdepth = e->loopdepth; 672 n->escloopdepth = e->loopdepth;
673 // for &x, use loop depth of x if known. 673 // for &x, use loop depth of x if known.
674 // it should always be known, but if not, be conservative 674 // it should always be known, but if not, be conservative
675 // and keep the current loop depth. 675 // and keep the current loop depth.
676 » » if(n->left->op == ONAME && (n->left->escloopdepth != 0 || n->lef t->class == PPARAMOUT)) { 676 » » if(n->left->op == ONAME) {
677 switch(n->left->class) { 677 switch(n->left->class) {
678 case PAUTO: 678 case PAUTO:
679 if(n->left->escloopdepth != 0)
680 n->escloopdepth = n->left->escloopdepth;
681 break;
679 case PPARAM: 682 case PPARAM:
680 case PPARAMOUT: 683 case PPARAMOUT:
681 » » » » n->escloopdepth = n->left->escloopdepth; 684 » » » » // PPARAM is loop depth 1 always.
685 » » » » // PPARAMOUT is loop depth 0 for writes
686 » » » » // but considered loop depth 1 for address-of,
687 » » » » // so that writing the address of one result
688 » » » » // to another (or the same) result makes the
689 » » » » // first result move to the heap.
690 » » » » n->escloopdepth = 1;
682 break; 691 break;
683 } 692 }
684 } 693 }
685 break; 694 break;
686 } 695 }
687 696
688 lineno = lno; 697 lineno = lno;
689 } 698 }
690 699
691 // Assert that expr somehow gets assigned to dst, if non nil. for 700 // Assert that expr somehow gets assigned to dst, if non nil. for
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 ll->n->paramfld->note = mktag(ll->n->esc); 1271 ll->n->paramfld->note = mktag(ll->n->esc);
1263 break; 1272 break;
1264 case EscHeap: // touched by escflood, moved to heap 1273 case EscHeap: // touched by escflood, moved to heap
1265 case EscScope: // touched by escflood, value leaves scope 1274 case EscScope: // touched by escflood, value leaves scope
1266 break; 1275 break;
1267 } 1276 }
1268 } 1277 }
1269 1278
1270 curfn = savefn; 1279 curfn = savefn;
1271 } 1280 }
OLDNEW
« no previous file with comments | « no previous file | test/escape2.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b