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

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

Issue 5696071: code review 5696071: gc: fix string comparisons for new bool rules (Closed)
Patch Set: diff -r aa7ded1d6fab https://code.google.com/p/go/ Created 13 years, 1 month 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/fixedbugs/bug425.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 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 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 #include <u.h> 5 #include <u.h>
6 #include <libc.h> 6 #include <libc.h>
7 #include "go.h" 7 #include "go.h"
8 8
9 static Node* walkprint(Node*, NodeList**, int); 9 static Node* walkprint(Node*, NodeList**, int);
10 static Node* mapfn(char*, Type*); 10 static Node* mapfn(char*, Type*);
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 1010
1011 case OCMPSTR: 1011 case OCMPSTR:
1012 // If one argument to the comparison is an empty string, 1012 // If one argument to the comparison is an empty string,
1013 // comparing the lengths instead will yield the same result 1013 // comparing the lengths instead will yield the same result
1014 // without the function call. 1014 // without the function call.
1015 if((isconst(n->left, CTSTR) && n->left->val.u.sval->len == 0) || 1015 if((isconst(n->left, CTSTR) && n->left->val.u.sval->len == 0) ||
1016 (isconst(n->right, CTSTR) && n->right->val.u.sval->len == 0)) { 1016 (isconst(n->right, CTSTR) && n->right->val.u.sval->len == 0)) {
1017 r = nod(n->etype, nod(OLEN, n->left, N), nod(OLEN, n->ri ght, N)); 1017 r = nod(n->etype, nod(OLEN, n->left, N), nod(OLEN, n->ri ght, N));
1018 typecheck(&r, Erv); 1018 typecheck(&r, Erv);
1019 walkexpr(&r, init); 1019 walkexpr(&r, init);
1020 r->type = n->type;
1020 n = r; 1021 n = r;
1021 goto ret; 1022 goto ret;
1022 } 1023 }
1023 1024
1024 // s + "badgerbadgerbadger" == "badgerbadgerbadger" 1025 // s + "badgerbadgerbadger" == "badgerbadgerbadger"
1025 if((n->etype == OEQ || n->etype == ONE) && 1026 if((n->etype == OEQ || n->etype == ONE) &&
1026 isconst(n->right, CTSTR) && 1027 isconst(n->right, CTSTR) &&
1027 n->left->op == OADDSTR && isconst(n->left->right, CTSTR) && 1028 n->left->op == OADDSTR && isconst(n->left->right, CTSTR) &&
1028 cmpslit(n->right, n->left->right) == 0) { 1029 cmpslit(n->right, n->left->right) == 0) {
1029 r = nod(n->etype, nod(OLEN, n->left->left, N), nodintcon st(0)); 1030 r = nod(n->etype, nod(OLEN, n->left->left, N), nodintcon st(0));
1030 typecheck(&r, Erv); 1031 typecheck(&r, Erv);
1031 walkexpr(&r, init); 1032 walkexpr(&r, init);
1033 r->type = n->type;
1032 n = r; 1034 n = r;
1033 goto ret; 1035 goto ret;
1034 } 1036 }
1035 1037
1036 // prepare for rewrite below 1038 // prepare for rewrite below
1037 if(n->etype == OEQ || n->etype == ONE) { 1039 if(n->etype == OEQ || n->etype == ONE) {
1038 n->left = cheapexpr(n->left, init); 1040 n->left = cheapexpr(n->left, init);
1039 n->right = cheapexpr(n->right, init); 1041 n->right = cheapexpr(n->right, init);
1040 } 1042 }
1041 1043
(...skipping 1541 matching lines...) Expand 10 before | Expand all | Expand 10 after
2583 argtype(fn, n->left->type); 2585 argtype(fn, n->left->type);
2584 argtype(fn, n->left->type); 2586 argtype(fn, n->left->type);
2585 r = mkcall1(fn, n->type, init, typename(n->left->type), l, r); 2587 r = mkcall1(fn, n->type, init, typename(n->left->type), l, r);
2586 if(n->op == ONE) { 2588 if(n->op == ONE) {
2587 r = nod(ONOT, r, N); 2589 r = nod(ONOT, r, N);
2588 typecheck(&r, Erv); 2590 typecheck(&r, Erv);
2589 } 2591 }
2590 *np = r; 2592 *np = r;
2591 return; 2593 return;
2592 } 2594 }
OLDNEW
« no previous file with comments | « no previous file | test/fixedbugs/bug425.go » ('j') | no next file with comments »

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