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]

Re: PATCH: PR tree-optimization/60024: global-buffer-overflow in init_regs_for_mode


Hello,

On 01.02.2014 19:16, H.J. Lu wrote:
Hi,

init_regs_for_mode accesses global_regs before checking if regno is OK
for a mode, which leads to buffer overflow.  This patch moves
HARD_REGNO_MODE_OK for checking global_regs.  There is no functional
change.  OK for trunk?

This is fine, you'd need to change tree-optimization/60024 to rtl-optimization/60024 in the ChangeLog. Thanks for doing this.

Yours,
Andrey


Thanks.


H.J.
---
2014-02-01  H.J. Lu  <hongjiu.lu@intel.com>

	PR tree-optimization/60024
	* sel-sched.c (init_regs_for_mode): Check if mode is OK first.

diff --git a/gcc/sel-sched.c b/gcc/sel-sched.c
index ad4a0aa..7b1a183 100644
--- a/gcc/sel-sched.c
+++ b/gcc/sel-sched.c
@@ -1116,9 +1116,16 @@ init_regs_for_mode (enum machine_mode mode)

    for (cur_reg = 0; cur_reg < FIRST_PSEUDO_REGISTER; cur_reg++)
      {
-      int nregs = hard_regno_nregs[cur_reg][mode];
+      int nregs;
        int i;

+      /* See whether it accepts all modes that occur in
+         original insns.  */
+      if (! HARD_REGNO_MODE_OK (cur_reg, mode))
+        continue;
+
+      nregs = hard_regno_nregs[cur_reg][mode];
+
        for (i = nregs - 1; i >= 0; --i)
          if (fixed_regs[cur_reg + i]
                  || global_regs[cur_reg + i]
@@ -1140,11 +1147,6 @@ init_regs_for_mode (enum machine_mode mode)
        if (i >= 0)
          continue;

-      /* See whether it accepts all modes that occur in
-         original insns.  */
-      if (! HARD_REGNO_MODE_OK (cur_reg, mode))
-        continue;
-
        if (HARD_REGNO_CALL_PART_CLOBBERED (cur_reg, mode))
          SET_HARD_REG_BIT (sel_hrd.regs_for_call_clobbered[mode],
                            cur_reg);



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