summaryrefslogtreecommitdiff
path: root/usr.bin/pcc
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2007-09-24 17:56:18 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2007-09-24 17:56:18 +0000
commit81ef67f0a424060bb9b28f3c0565ef21e2927ab0 (patch)
tree5e7fbdf2ea1ad5987993957b7e5f3b0ddff3adad /usr.bin/pcc
parent007a3e7fc7cc91acab5158927a2ea9c7289ff9c0 (diff)
Pull from ragge's repo:
Add support for signed bitfields, this has been missing ~forever. Bug reported by TAKAHASHI Tamotsu. Fix bitfield overflow bug, reported by TAKAHASHI Tamotsu.
Diffstat (limited to 'usr.bin/pcc')
-rw-r--r--usr.bin/pcc/arch/x86/local.c4
-rw-r--r--usr.bin/pcc/mip/reader.c35
2 files changed, 24 insertions, 15 deletions
diff --git a/usr.bin/pcc/arch/x86/local.c b/usr.bin/pcc/arch/x86/local.c
index bbf822c834b..fd16b49078b 100644
--- a/usr.bin/pcc/arch/x86/local.c
+++ b/usr.bin/pcc/arch/x86/local.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: local.c,v 1.2 2007/09/15 22:04:38 ray Exp $ */
+/* $OpenBSD: local.c,v 1.3 2007/09/24 17:56:17 otto Exp $ */
/*
* Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
* All rights reserved.
@@ -495,7 +495,7 @@ infld(CONSZ off, int fsz, CONSZ val)
if (idebug)
printf("infld off %lld, fsz %d, val %lld inbits %d\n",
off, fsz, val, inbits);
- val &= (1 << fsz)-1;
+ val &= ((CONSZ)1 << fsz)-1;
while (fsz + inbits >= SZCHAR) {
inval |= (val << inbits);
printf("\t.byte %d\n", inval & 255);
diff --git a/usr.bin/pcc/mip/reader.c b/usr.bin/pcc/mip/reader.c
index 11b980e8988..f157b046eef 100644
--- a/usr.bin/pcc/mip/reader.c
+++ b/usr.bin/pcc/mip/reader.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: reader.c,v 1.3 2007/09/22 14:41:41 otto Exp $ */
+/* $OpenBSD: reader.c,v 1.4 2007/09/24 17:56:17 otto Exp $ */
/*
* Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
* All rights reserved.
@@ -785,18 +785,27 @@ ffld(NODE *p, int down, int *down1, int *down2 )
/* make & mask part */
- p->n_left->n_type = ty;
-
- p->n_op = AND;
- p->n_right = mklnode(ICON, (1 << s)-1, 0, ty);
-
- /* now, if a shift is needed, do it */
-
- if( o != 0 ){
- shp = mkbinode(RS, p->n_left,
- mklnode(ICON, o, 0, INT), ty);
- p->n_left = shp;
- /* whew! */
+ if (ISUNSIGNED(ty)) {
+
+ p->n_left->n_type = ty;
+ p->n_op = AND;
+ p->n_right = mklnode(ICON, ((CONSZ)1 << s)-1, 0, ty);
+
+ /* now, if a shift is needed, do it */
+ if( o != 0 ){
+ shp = mkbinode(RS, p->n_left,
+ mklnode(ICON, o, 0, INT), ty);
+ p->n_left = shp;
+ /* whew! */
+ }
+ } else {
+ /* must sign-extend, assume RS will do */
+ /* if not, arch must use rewfld() */
+ p->n_left->n_type = INT; /* Ok? */
+ p->n_op = RS;
+ p->n_right = mklnode(ICON, SZINT-s, 0, INT);
+ p->n_left = mkbinode(LS, p->n_left,
+ mklnode(ICON, SZINT-s-o, 0, INT), INT);
}
}
}