Patchwork comitted: fix our-of-bounds array access warnings in caller-save.c

login
register
mail settings
Submitter Joern Rennecke
Date Nov. 8, 2010, 3:18 p.m.
Message ID <20101108101853.sbmwpnku0owg8k8s-nzlynne@webmail.spamcop.net>
Download mbox | patch
Permalink /patch/70423/
State New
Headers show

Comments

Joern Rennecke - Nov. 8, 2010, 3:18 p.m.
lm32.h has:
#define FIRST_PSEUDO_REGISTER  32
...
#define G_REG_P(X)      ((X)<32)
...
HARD_REGNO_MODE_OK(REGNO, MODE) G_REG_P(REGNO)

Hence, after a test (!HARD_REGNO_MODE_OK (reg, mode))
in caller-save.c:reg_save_code, value range propagation knows that
regno is not a suitable index for cached_reg_save_code /  
cached_reg_restore_code,
thus we got two warnings about out-of-range array accesses.

The attached patch fixes this with an assert.

Bootstrapped & regtested on i686-pc-linux-gnu, with this additional patch:
http://gcc.gnu.org/ml/gcc-patches/2010-11/msg00720.html

Committed as obvious.
2010-11-08  Joern Rennecke  <amylaar@spamcop.net>

	* caller-save.c (reg_save_code): After HARD_REGNO_MODE_OK check fails,
	assert that REG is a hard register number before using it as an index.

Patch

Index: caller-save.c
===================================================================
--- caller-save.c	(revision 166429)
+++ caller-save.c	(working copy)
@@ -116,11 +116,15 @@  reg_save_code (int reg, enum machine_mod
   if (cached_reg_save_code[reg][mode])
      return cached_reg_save_code[reg][mode];
   if (!HARD_REGNO_MODE_OK (reg, mode))
-     {
-       cached_reg_save_code[reg][mode] = -1;
-       cached_reg_restore_code[reg][mode] = -1;
-       return -1;
-     }
+    {
+      /* Depending on how HARD_REGNO_MODE_OK is defined, range propagation
+	 might deduce here that reg >= FIRST_PSEUDO_REGISTER.  So the assert
+	 below silences a warning.  */
+      gcc_assert (reg < FIRST_PSEUDO_REGISTER);
+      cached_reg_save_code[reg][mode] = -1;
+      cached_reg_restore_code[reg][mode] = -1;
+      return -1;
+    }
 
   /* Update the register number and modes of the register
      and memory operand.  */