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]

[PATCH][OBVIOUS] Fix UBSAN in regrename.c (PR rtl-optimization/84635).


Hi.

It's quite obvious mistake, where we access an array variable before
we check index boundary.

I'll install it after bootstrap & regression tests.

Martin

gcc/ChangeLog:

2018-03-16  Martin Liska  <mliska@suse.cz>

	PR rtl-optimization/84635
	* regrename.c (build_def_use): Use matches_mode only when
	matches >= 0.
---
 gcc/regrename.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)


diff --git a/gcc/regrename.c b/gcc/regrename.c
index dcec77adf75..45754812f6c 100644
--- a/gcc/regrename.c
+++ b/gcc/regrename.c
@@ -1703,14 +1703,18 @@ build_def_use (basic_block bb)
 		     and we must instead make sure to make the operand visible
 		     to the machinery that tracks hard registers.  */
 		  machine_mode i_mode = recog_data.operand_mode[i];
-		  machine_mode matches_mode = recog_data.operand_mode[matches];
-		  if (matches >= 0
-		      && maybe_ne (GET_MODE_SIZE (i_mode),
-				   GET_MODE_SIZE (matches_mode))
-		      && !verify_reg_in_set (op, &live_in_chains))
+		  if (matches >= 0)
 		    {
-		      untracked_operands |= 1 << i;
-		      untracked_operands |= 1 << matches;
+		      machine_mode matches_mode
+			= recog_data.operand_mode[matches];
+
+		      if (maybe_ne (GET_MODE_SIZE (i_mode),
+				    GET_MODE_SIZE (matches_mode))
+			  && !verify_reg_in_set (op, &live_in_chains))
+			{
+			  untracked_operands |= 1 << i;
+			  untracked_operands |= 1 << matches;
+			}
 		    }
 		}
 #ifdef STACK_REGS


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