diff options
author | Anders Magnusson <ragge@cvs.openbsd.org> | 2007-10-05 15:58:24 +0000 |
---|---|---|
committer | Anders Magnusson <ragge@cvs.openbsd.org> | 2007-10-05 15:58:24 +0000 |
commit | a60f66be4967fede613f962c7cd70c1cee3e4645 (patch) | |
tree | 34f295447273865a6a9748ee5c2d2f233e883ba3 /usr.bin | |
parent | 442d882dd26ea2bd3737e433981c74b28d6028dc (diff) |
From master repository log:
Do not optimize away a cast if constant too large for target type.
Should remove branch but need to check for side effects in that case.
Also correct possible incorrect min constant.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/pcc/arch/x86/local.c | 30 | ||||
-rw-r--r-- | usr.bin/pcc/arch/x86/macdefs.h | 4 |
2 files changed, 31 insertions, 3 deletions
diff --git a/usr.bin/pcc/arch/x86/local.c b/usr.bin/pcc/arch/x86/local.c index fd16b49078b..ab5290b82e9 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.3 2007/09/24 17:56:17 otto Exp $ */ +/* $OpenBSD: local.c,v 1.4 2007/10/05 15:58:23 ragge Exp $ */ /* * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se). * All rights reserved. @@ -29,6 +29,32 @@ #include "pass1.h" +/* + * Check if a constant is too large for a type. + */ +static int +toolarge(TWORD t, CONSZ con) +{ + U_CONSZ ucon = con; + + switch (t) { + case ULONGLONG: + case LONGLONG: + break; /* cannot be too large */ +#define SCHK(i) case i: if (con > MAX_##i || con < MIN_##i) return 1; break +#define UCHK(i) case i: if (ucon > MAX_##i) return 1; break + SCHK(INT); + SCHK(SHORT); + SCHK(CHAR); + UCHK(UNSIGNED); + UCHK(USHORT); + UCHK(UCHAR); + default: + cerror("toolarge"); + } + return 0; +} + /* this file contains code which is dependent on the target machine */ /* clocal() is called to do local transformations on @@ -121,6 +147,8 @@ clocal(NODE *p) r = l->n_left->n_left; if (r->n_type >= FLOAT && r->n_type <= LDOUBLE) break; + if (toolarge(r->n_type, l->n_right->n_lval)) + break; /* Type must be correct */ t = r->n_type; nfree(l->n_left); diff --git a/usr.bin/pcc/arch/x86/macdefs.h b/usr.bin/pcc/arch/x86/macdefs.h index eee3dae9b8c..6b17ec0404c 100644 --- a/usr.bin/pcc/arch/x86/macdefs.h +++ b/usr.bin/pcc/arch/x86/macdefs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: macdefs.h,v 1.2 2007/09/15 22:04:38 ray Exp $ */ +/* $OpenBSD: macdefs.h,v 1.3 2007/10/05 15:58:23 ragge Exp $ */ /* * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se). * All rights reserved. @@ -77,7 +77,7 @@ #define MIN_SHORT -32768 #define MAX_SHORT 32767 #define MAX_USHORT 65535 -#define MIN_INT -1 +#define MIN_INT (-0x7fffffff-1) #define MAX_INT 0x7fffffff #define MAX_UNSIGNED 0xffffffff #define MIN_LONG MIN_INT |