[PATCH] gcc/reload.c: Initialize several arrays before use them in find_reloads()

Chen Gang S gang.chen@sunrus.com.cn
Sun Feb 22 11:14:00 GMT 2015


It is for Bug65117, after this fix, ".i" file can be passed compiling.

  - 'this_alternative_win' is not initialized before use it: for the
    first looping 0, it initializes 'this_alternative_win[0]', but
    'did_match' may use 'this_alternative_win[2]'.

  - 'this_alternative' may be not initialized before using: it
    initializes 'this_alternative[i]', but may use 'this_alternative[m]'
    (m > i).

  - After reading through the code, arrays 'this_alternative_match_win',
    'this_alternative_offmemok', and 'this_alternative_earlyclobber' may
    be not initialized either, so initialize them too.

This issue is found by cross compiling xtensa Linux kernel with the
latest gcc5. And after this patch, it can cross compile xtensa Linux
kernel with allmodconfig, successfully.


2015-02-22  Chen Gang  <gang.chen.5i5j@gmail.com>

	* reload.c (find_reloads): Initialize several arrays before use
	them.
---
 gcc/reload.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/gcc/reload.c b/gcc/reload.c
index 70b86a9..7e83c10 100644
--- a/gcc/reload.c
+++ b/gcc/reload.c
@@ -2666,10 +2666,10 @@ find_reloads (rtx_insn *insn, int replace, int ind_levels, int live_known,
   int no_input_reloads = 0, no_output_reloads = 0;
   int n_alternatives;
   reg_class_t this_alternative[MAX_RECOG_OPERANDS];
-  char this_alternative_match_win[MAX_RECOG_OPERANDS];
-  char this_alternative_win[MAX_RECOG_OPERANDS];
-  char this_alternative_offmemok[MAX_RECOG_OPERANDS];
-  char this_alternative_earlyclobber[MAX_RECOG_OPERANDS];
+  char this_alternative_match_win[MAX_RECOG_OPERANDS] = {0};
+  char this_alternative_win[MAX_RECOG_OPERANDS] = {0};
+  char this_alternative_offmemok[MAX_RECOG_OPERANDS] = {0};
+  char this_alternative_earlyclobber[MAX_RECOG_OPERANDS] = {0};
   int this_alternative_matches[MAX_RECOG_OPERANDS];
   reg_class_t goal_alternative[MAX_RECOG_OPERANDS];
   int this_alternative_number;
@@ -2692,6 +2692,8 @@ find_reloads (rtx_insn *insn, int replace, int ind_levels, int live_known,
   machine_mode operand_mode[MAX_RECOG_OPERANDS];
   int retval = 0;
 
+  for (i = 0; i < MAX_RECOG_OPERANDS; i++)
+    this_alternative[i] = NO_REGS;
   this_insn = insn;
   n_reloads = 0;
   n_replacements = 0;
-- 
1.9.3



More information about the Gcc-patches mailing list