From: Ken Thompson Date: Fri, 29 Aug 2008 20:24:53 +0000 (-0700) Subject: fix type of (1<op != OLITERAL || t == T) + if(n == N || t == T) return; - + switch(n->op) { + default: + return; + case OLITERAL: + break; + case OLSH: + case ORSH: + convlit(n->left, t); + n->type = n->left->type; + return; + } et = t->etype; switch(whatis(n)) { default: diff --git a/src/cmd/gc/walk.c b/src/cmd/gc/walk.c index b018e999c2..b9ec0c1e10 100644 --- a/src/cmd/gc/walk.c +++ b/src/cmd/gc/walk.c @@ -496,8 +496,8 @@ loop: evconst(n); if(n->op == OLITERAL) goto ret; - convlit(n->left, n->left->type); convlit(n->right, types[TUINT32]); + convlit(n->left, types[TINT32]); if(n->left->type == T || n->right->type == T) goto ret; if(issigned[n->right->type->etype]) @@ -1458,6 +1458,7 @@ ascompat(Type *t1, Type *t2) if(isptrdarray(t1)) if(isptrarray(t2)) return 1; + return 0; } diff --git a/test/ken/array.go b/test/ken/array.go new file mode 100644 index 0000000000..bd17f645c5 --- /dev/null +++ b/test/ken/array.go @@ -0,0 +1,156 @@ +// $G $D/$F.go && $L $F.$A && ./$A.out + +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + + +package main + +export func +setpd(a *[]int) +{ +// print("setpd a=", a, " len=", len(a), " cap=", cap(a), "\n"); + for i:=0; i> 0, 0,0,1); + testi( int(1234) << 5, 0,1,0); + testi( int(1234) >> 5, 0,1,1); + testi( int(1234) << 1025, 0,2,0); + testi( int(1234) >> 1025, 0,2,1); + + testi(int(-1234) << 0, 1,0,0); + testi(int(-1234) >> 0, 1,0,1); + testi(int(-1234) << 5, 1,1,0); + testi(int(-1234) >> 5, 1,1,1); + testi(int(-1234) << 1025, 1,2,0); + testi(int(-1234) >> 1025, 1,2,1); + + testu(uint(5678) << 0, 2,0,0); + testu(uint(5678) >> 0, 2,0,1); + testu(uint(5678) << 5, 2,1,0); + testu(uint(5678) >> 5, 2,1,1); + testu(uint(5678) << 1025, 2,2,0); + testu(uint(5678) >> 1025, 2,2,1); + + /* + * test variable evaluations + */ + pass = "var"; // variable part + + for t1:=0; t1<3; t1++ { // +int, -int, uint + for t2:=0; t2<3; t2++ { // 0, +small, +large + for t3:=0; t3<2; t3++ { // <<, >> + switch t1 { + case 0: i = 1234; + case 1: i = -1234; + case 2: u = 5678; + } + switch t2 { + case 0: c = 0; + case 1: c = 5; + case 2: c = 1025; + } + switch t3 { + case 0: i <<= c; u <<= c; + case 1: i >>= c; u >>= c; + } + switch t1 { + case 0: testi(i,t1,t2,t3); + case 1: testi(i,t1,t2,t3); + case 2: testu(u,t1,t2,t3); + } + } + } + } +} + +func +init() +{ + /* + * set the 'correct' answer + */ + + ians[index(0,0,0)] = 1234; + ians[index(0,0,1)] = 1234; + ians[index(0,1,0)] = 39488; + ians[index(0,1,1)] = 38; + ians[index(0,2,0)] = 0; + ians[index(0,2,1)] = 0; + + ians[index(1,0,0)] = -1234; + ians[index(1,0,1)] = -1234; + ians[index(1,1,0)] = -39488; + ians[index(1,1,1)] = -39; + ians[index(1,2,0)] = 0; + ians[index(1,2,1)] = -1; + + uans[index(2,0,0)] = 5678; + uans[index(2,0,1)] = 5678; + uans[index(2,1,0)] = 181696; + uans[index(2,1,1)] = 177; + uans[index(2,2,0)] = 0; + uans[index(2,2,1)] = 0; +}