from forsyth: /* * (uvlong)~ul creates a ul mask with top bits zero, which is usually wrong * an explicit cast to ulong after ~ suppresses the diagnostic */ Reference: /n/atom/patch/applied/castucom Date: Sat Aug 15 23:18:59 CES 2015 Signed-off-by: quanstro@quanstr.net --- /sys/src/cmd/cc/com.c Sat Aug 15 23:15:33 2015 +++ /sys/src/cmd/cc/com.c Sat Aug 15 23:15:35 2015 @@ -1059,6 +1059,8 @@ 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 Sat Aug 15 23:15:38 2015 +++ /sys/src/cmd/cc/sub.c Sat Aug 15 23:15:40 2015 @@ -2027,3 +2027,21 @@ { 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; +} --- /sys/src/cmd/cc/cc.h Sat Aug 15 23:15:43 2015 +++ /sys/src/cmd/cc/cc.h Sat Aug 15 23:15:44 2015 @@ -665,6 +665,7 @@ * sub.c */ void arith(Node*, int); +int castucom(Node*); int deadheads(Node*); Type* dotsearch(Sym*, Type*, Node*, long*); long dotoffset(Type*, Type*, Node*);