* Start Syncing Compilers with Plan 9
@ 2019-06-18 5:44 ori
0 siblings, 0 replies; only message in thread
From: ori @ 2019-06-18 5:44 UTC (permalink / raw)
To: 9front
This change imports a few warnings and minor fixes from Charles branch
here: https://bitbucket.org/plan9-from-bell-labs/plan9. More to come.
They're also merged in https://github.com/0intro/plan9-contrib
I've rebuilt my system with them (for both 386 and amd64), and am
running with them right now.
The changes here are:
changeset: 1374:9185dc017be0
summary: declare castucom; move a declaration into order;
use cast instead of ULL suffix
changeset: 1353:5fe8380b1818
summary: supporting functions:
1. castucom to match unlikely mask operation;
2. be sure to snap both sides of pointer subtraction completely;
3. add extra operators as side-effect free
changeset: 1352:90058c092d66
summary: 1. correct result type for mixed-mode assignment operators
2. detect divide by zero (erik);
3. detect masks misformed by sign-extension;
4. diagnose mixed old/new prototypes
The changes we already have are:
changeset: 1355:14671c7309d9
changeset: 1354:ecb4ca2742de
changeset: 1373:0ac002b1a150
changeset: 1362:776bd952517b
changeset: 1390:18a307053bec
And the ones we don't want:
changeset: 1356:d62af4395456
changeset: 1357:7c15c5656da0
diff -r 20bf56be7bd6 sys/src/cmd/cc/cc.h
--- a/sys/src/cmd/cc/cc.h Mon Jun 17 21:12:35 2019 -0700
+++ b/sys/src/cmd/cc/cc.h Mon Jun 17 22:34:51 2019 -0700
@@ -662,6 +662,7 @@
* sub.c
*/
void arith(Node*, int);
+int castucom(Node*);
int deadheads(Node*);
Type* dotsearch(Sym*, Type*, Node*, long*);
long dotoffset(Type*, Type*, Node*);
diff -r 20bf56be7bd6 sys/src/cmd/cc/com.c
--- a/sys/src/cmd/cc/com.c Mon Jun 17 21:12:35 2019 -0700
+++ b/sys/src/cmd/cc/com.c Mon Jun 17 22:34:51 2019 -0700
@@ -266,12 +266,15 @@
arith(n, 0);
while(n->left->op == OCAST)
n->left = n->left->left;
- if(!sametype(t, n->type) && !mixedasop(t, n->type)) {
- r = new1(OCAST, n->right, Z);
- r->type = t;
- n->right = r;
+ if(!mixedasop(t, n->type)) {
+ if(!sametype(t, n->type)) {
+ r = new1(OCAST, n->right, Z);
+ r->type = t;
+ n->right = r;
+ n->type = t;
+ }
+ }else
n->type = t;
- }
if(typeu[n->type->etype]) {
if(n->op == OASMOD)
n->op = OASLMOD;
@@ -1044,6 +1047,23 @@
case OASADD:
ccom(l);
ccom(r);
+ if(n->op == OASMOD || n->op == OASLMOD || n->op == OASDIV || n->op == OASLDIV)
+ if(r->op == OCONST){
+ if(!typefd[r->type->etype] && r->vconst == 0) {
+ if(n->op == OASMOD || n->op == OASLMOD)
+ diag(n, "modulo by zero");
+ else
+ diag(n, "divide by zero");
+ r->vconst = ~0;
+ }
+ if(typefd[r->type->etype] && r->fconst == 0.) {
+ if(n->op == OASMOD || n->op == OASLMOD)
+ diag(n, "modulo by zero");
+ else
+ diag(n, "divide by zero");
+ r->fconst = 1e10;
+ }
+ }
if(n->op == OASLSHR || n->op == OASASHR || n->op == OASASHL)
if(r->op == OCONST) {
t = n->type->width * 8; /* bits per byte */
@@ -1053,6 +1073,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);
diff -r 20bf56be7bd6 sys/src/cmd/cc/sub.c
--- a/sys/src/cmd/cc/sub.c Mon Jun 17 21:12:35 2019 -0700
+++ b/sys/src/cmd/cc/sub.c Mon Jun 17 22:34:51 2019 -0700
@@ -659,7 +659,7 @@
Type *t1, *t2;
int i, j, k;
Node *n1;
- long w;
+ long w, x;
t1 = n->left->type;
if(n->right == Z)
@@ -689,7 +689,19 @@
if(n->op == OSUB)
if(i == TIND && j == TIND) {
w = n->right->type->link->width;
- if(w < 1 || n->left->type->link == T || n->left->type->link->width < 1)
+ if(w < 1) {
+ snap(n->right->type->link);
+ w = n->right->type->link->width;
+ }
+ x = 0;
+ if(n->left->type->link != T) {
+ x = n->left->type->link->width;
+ if(x < 1) {
+ snap(n->left->type->link);
+ x = n->left->type->link->width;
+ }
+ }
+ if(w < 1 || x < 1)
goto bad;
n->type = types[ewidth[TIND] <= ewidth[TLONG]? TLONG: TVLONG];
if(w > 1) {
@@ -991,6 +1003,8 @@
case OOROR:
case OCOMMA:
case ODOT:
+ case OFAS:
+ case OINDEX:
if(side(n->left))
break;
n = n->right;
@@ -2074,3 +2088,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;
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-06-18 5:44 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-18 5:44 Start Syncing Compilers with Plan 9 ori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).