--- /sys/src/cmd/cc/cc.h +++ /sys/src/cmd/cc/cc.h @@ -665,6 +665,7 @@ void dclfunct(Type*, Sym*); * sub.c */ void arith(Node*, int); +int castucom(Node*); int deadheads(Node*); Type* dotsearch(Sym*, Type*, Node*, long*); long dotoffset(Type*, Type*, Node*); --- /sys/src/cmd/cc/com.c +++ /sys/src/cmd/cc/com.c @@ -1055,6 +1055,8 @@ loop: break; case OCAST: + if(castucom(n)) + warn(n, "32-bit unsigned complement zero-extended to 64 bits"); ccom(l); if(l->op == OCONST) { evconst(n); --- /sys/src/cmd/cc/sub.c +++ /sys/src/cmd/cc/sub.c @@ -2030,3 +2030,21 @@ mixedasop(Type *l, Type *r) { return !typefd[l->etype] && typefd[r->etype]; } + + +/* + * (uvlong)~ul creates a ul mask with top bits zero, which is usually wrong + * an explicit cast to ulong after ~ suppresses the diagnostic + */ +int +castucom(Node *r) +{ + Node *rl; + + if(r->op == OCAST && + (rl = r->left)->op == OCOM && + (r->type->etype == TVLONG || r->type->etype == TUVLONG) && + typeu[rl->type->etype] && typechl[rl->type->etype]) + return 1; + return 0; +}