mirror of
https://github.com/golang/go
synced 2024-11-13 14:20:23 -07:00
^ type(const) now inverts "enough" bits
^ signed(const) becomes illegal ^ unsigned(const) becomes legal R=r OCL=26697 CL=26697
This commit is contained in:
parent
85e014a27e
commit
b8be809c10
@ -282,8 +282,9 @@ evconst(Node *n)
|
|||||||
Node *nl, *nr;
|
Node *nl, *nr;
|
||||||
int32 len;
|
int32 len;
|
||||||
String *str;
|
String *str;
|
||||||
int wl, wr, lno;
|
int wl, wr, lno, et;
|
||||||
Val v;
|
Val v;
|
||||||
|
Mpint b;
|
||||||
|
|
||||||
nl = n->left;
|
nl = n->left;
|
||||||
if(nl == N || nl->type == T)
|
if(nl == N || nl->type == T)
|
||||||
@ -541,7 +542,34 @@ unary:
|
|||||||
mpnegfix(v.u.xval);
|
mpnegfix(v.u.xval);
|
||||||
break;
|
break;
|
||||||
case TUP(OCOM, CTINT):
|
case TUP(OCOM, CTINT):
|
||||||
mpcomfix(v.u.xval);
|
et = Txxx;
|
||||||
|
if(nl->type != T)
|
||||||
|
et = nl->type->etype;
|
||||||
|
|
||||||
|
// calculate the mask in b
|
||||||
|
// result will be (a ^ mask)
|
||||||
|
switch(et) {
|
||||||
|
default:
|
||||||
|
mpmovecfix(&b, -1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TINT8:
|
||||||
|
case TINT16:
|
||||||
|
case TINT32:
|
||||||
|
case TINT64:
|
||||||
|
case TINT:
|
||||||
|
et++; // convert to unsigned
|
||||||
|
// fallthrough
|
||||||
|
case TUINT8:
|
||||||
|
case TUINT16:
|
||||||
|
case TUINT32:
|
||||||
|
case TUINT64:
|
||||||
|
case TUINT:
|
||||||
|
case TUINTPTR:
|
||||||
|
mpmovefixfix(&b, maxintval[et]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
mpxorfixfix(v.u.xval, &b);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TUP(OPLUS, CTFLT):
|
case TUP(OPLUS, CTFLT):
|
||||||
|
@ -39,7 +39,7 @@ var (
|
|||||||
b3 = Uint8 - Uint8; // OK
|
b3 = Uint8 - Uint8; // OK
|
||||||
b4 = Uint8 - Uint8 - Uint8; // ERROR "overflow"
|
b4 = Uint8 - Uint8 - Uint8; // ERROR "overflow"
|
||||||
b5 = uint8(^0); // ERROR "overflow"
|
b5 = uint8(^0); // ERROR "overflow"
|
||||||
b6 = ^uint8(0); // ERROR "overflow"
|
b6 = ^uint8(0); // OK
|
||||||
b7 = uint8(Minus1); // ERROR "overflow"
|
b7 = uint8(Minus1); // ERROR "overflow"
|
||||||
b8 = uint8(int8(-1)); // ERROR "overflow"
|
b8 = uint8(int8(-1)); // ERROR "overflow"
|
||||||
b8a = uint8(-1); // ERROR "overflow"
|
b8a = uint8(-1); // ERROR "overflow"
|
||||||
|
Loading…
Reference in New Issue
Block a user