diff mbox

Fix nullptr access in true_regnum

Message ID 1413495200.31394.132.camel@yam-132-YW-E178-FTW
State New
Headers show

Commit Message

Oleg Endo Oct. 16, 2014, 9:33 p.m. UTC
Hi,

While working on some SH builtins I ran into the issue that the function
true_regnum in jump.c tries to access the reg_renumber array without
checking for nullptr.  The particular use case here is using true_regnum
in a predicate that is invoked during builtin function expansion in the
TARGET_EXPAND_BUILTIN function.  It seems that at that time reg_renumber
hasn't been initialized yet.  Adding the nullptr check fixes the issue.

OK for trunk?

Cheers,
Oleg

gcc/ChangeLog:
	* jump.c (true_regnum): Check that reg_renumber is not null
	before accessing it.

Comments

Jeff Law Oct. 16, 2014, 10:10 p.m. UTC | #1
On 10/16/14 15:33, Oleg Endo wrote:
> Hi,
>
> While working on some SH builtins I ran into the issue that the function
> true_regnum in jump.c tries to access the reg_renumber array without
> checking for nullptr.  The particular use case here is using true_regnum
> in a predicate that is invoked during builtin function expansion in the
> TARGET_EXPAND_BUILTIN function.  It seems that at that time reg_renumber
> hasn't been initialized yet.  Adding the nullptr check fixes the issue.
>
> OK for trunk?
>
> Cheers,
> Oleg
>
> gcc/ChangeLog:
> 	* jump.c (true_regnum): Check that reg_renumber is not null
> 	before accessing it.
You're not supposed to be using true_regnum prior to register 
allocation.  You're probably better off with a new predicate to handle 
this case.

jeff
diff mbox

Patch

Index: gcc/jump.c
===================================================================
--- gcc/jump.c	(revision 216350)
+++ gcc/jump.c	(working copy)
@@ -1908,7 +1908,8 @@ 
   if (REG_P (x))
     {
       if (REGNO (x) >= FIRST_PSEUDO_REGISTER
-	  && (lra_in_progress || reg_renumber[REGNO (x)] >= 0))
+	  && (lra_in_progress ||
+	      (reg_renumber != NULL && reg_renumber[REGNO (x)] >= 0)))
 	return reg_renumber[REGNO (x)];
       return REGNO (x);
     }