This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.

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.  */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]