]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: fix double evaluation in interface comparison
authorDaniel Morsing <daniel.morsing@gmail.com>
Tue, 18 Sep 2012 15:40:53 +0000 (17:40 +0200)
committerDaniel Morsing <daniel.morsing@gmail.com>
Tue, 18 Sep 2012 15:40:53 +0000 (17:40 +0200)
During interface compare, the operands will be evaluated twice. The operands might include function calls for conversion, so make them cheap before comparing them.

R=rsc
CC=golang-dev
https://golang.org/cl/6498133

src/cmd/gc/walk.c

index 935fa6d65d7387ee2c752cfab07d71b38efd750a..c6b7e4278f74ec6e843999c42507a7eb00810409 100644 (file)
@@ -1194,6 +1194,9 @@ walkexpr(Node **np, NodeList **init)
                        fn = syslook("efaceeq", 1);
                else
                        fn = syslook("ifaceeq", 1);
+
+               n->right = cheapexpr(n->right, init);
+               n->left = cheapexpr(n->left, init);
                argtype(fn, n->right->type);
                argtype(fn, n->left->type);
                r = mkcall1(fn, n->type, init, n->left, n->right);