This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[patch] rx range checking
- From: DJ Delorie <dj at redhat dot com>
- To: binutils at sourceware dot org
- Date: Mon, 14 May 2012 23:23:40 -0400
- Subject: [patch] rx range checking
Adds some rudimentary range checking to constants. Applied.
* config/rx-parse.y (rx_range): declare.
(O1,O2,O3,O4): Add calls to rx_range.
(UO1,UO2,UO3): Likewise.
(IMM2,IMMB): Likewise.
(rx_range): New.
Index: gas/config/rx-parse.y
===================================================================
RCS file: /cvs/src/src/gas/config/rx-parse.y,v
retrieving revision 1.8
diff -p -U5 -r1.8 gas/config/rx-parse.y
--- gas/config/rx-parse.y 30 Apr 2012 22:09:09 -0000 1.8
+++ gas/config/rx-parse.y 15 May 2012 03:22:26 -0000
@@ -70,18 +70,18 @@ static int sizemap[] = { BSIZE, WSIZE, L
/* POS is bits from the MSB of the first byte to the LSB of the last byte. */
#define F(val,pos,sz) rx_field (val, pos, sz)
#define FE(exp,pos,sz) rx_field (exp_val (exp), pos, sz);
-#define O1(v) rx_op (v, 1, RXREL_SIGNED)
-#define O2(v) rx_op (v, 2, RXREL_SIGNED)
-#define O3(v) rx_op (v, 3, RXREL_SIGNED)
+#define O1(v) rx_op (v, 1, RXREL_SIGNED); rx_range (v, -128, 255)
+#define O2(v) rx_op (v, 2, RXREL_SIGNED); rx_range (v, -32768, 65536)
+#define O3(v) rx_op (v, 3, RXREL_SIGNED); rx_range (v, -8388608, 16777216)
#define O4(v) rx_op (v, 4, RXREL_SIGNED)
-#define UO1(v) rx_op (v, 1, RXREL_UNSIGNED)
-#define UO2(v) rx_op (v, 2, RXREL_UNSIGNED)
-#define UO3(v) rx_op (v, 3, RXREL_UNSIGNED)
+#define UO1(v) rx_op (v, 1, RXREL_UNSIGNED); rx_range (v, 0, 255)
+#define UO2(v) rx_op (v, 2, RXREL_UNSIGNED); rx_range (v, 0, 65536)
+#define UO3(v) rx_op (v, 3, RXREL_UNSIGNED); rx_range (v, 0, 16777216)
#define UO4(v) rx_op (v, 4, RXREL_UNSIGNED)
#define NO1(v) rx_op (v, 1, RXREL_NEGATIVE)
#define NO2(v) rx_op (v, 2, RXREL_NEGATIVE)
#define NO3(v) rx_op (v, 3, RXREL_NEGATIVE)
@@ -92,12 +92,12 @@ static int sizemap[] = { BSIZE, WSIZE, L
#define PC3(v) rx_op (v, 3, RXREL_PCREL)
#define IMM_(v,pos,size) F (immediate (v, RXREL_SIGNED, pos, size), pos, 2); \
if (v.X_op != O_constant && v.X_op != O_big) rx_linkrelax_imm (pos)
#define IMM(v,pos) IMM_ (v, pos, 32)
-#define IMMW(v,pos) IMM_ (v, pos, 16)
-#define IMMB(v,pos) IMM_ (v, pos, 8)
+#define IMMW(v,pos) IMM_ (v, pos, 16); rx_range (v, -32768, 65536)
+#define IMMB(v,pos) IMM_ (v, pos, 8); rx_range (v, -128, 255)
#define NIMM(v,pos) F (immediate (v, RXREL_NEGATIVE, pos, 32), pos, 2)
#define NBIMM(v,pos) F (immediate (v, RXREL_NEGATIVE_BORROW, pos, 32), pos, 2)
#define DSP(v,pos,msz) if (!v.X_md) rx_relax (RX_RELAX_DISP, pos); \
else rx_linkrelax_dsp (pos); \
F (displacement (v, msz), pos, 2)
@@ -112,10 +112,11 @@ static int rx_disp5op0 (expressi
static int exp_val (expressionS exp);
static expressionS zero_expr (void);
static int immediate (expressionS, int, int, int);
static int displacement (expressionS, int);
static void rtsd_immediate (expressionS);
+static void rx_range (expressionS, int, int);
static int need_flag = 0;
static int rx_in_brackets = 0;
static int rx_last_token = 0;
static char * rx_init_start;
@@ -1613,5 +1614,18 @@ rtsd_immediate (expressionS exp)
val >>= 2;
exp.X_add_number = val;
O1 (exp);
}
+
+static void
+rx_range (expressionS exp, int minv, int maxv)
+{
+ int val;
+
+ if (exp.X_op != O_constant)
+ return;
+
+ val = exp.X_add_number;
+ if (val < minv || val > maxv)
+ as_warn (_("Value %d out of range %d..%d"), val, minv, maxv);
+}