diff mbox

Update check after force_const_mem call in the plus_constant function to see if the value returned is not a NULL_RTX.

Message ID 0DA23CC379F5F945ACB41CF394B9827720FC1045@LEMAIL01.le.imgtec.org
State New
Headers show

Commit Message

Andrew Bennett June 2, 2015, 2:19 p.m. UTC
Hi,

In the plus_constant function in explow.c the code to update a constant pool value
does not deal with the case where the value returned from force_const_mem is a 
NULL_RTX.  This occurs for the MIPS target because its 
cannot_force_const_mem target function does not allow constants (so that the 
move expanders can deal with them later on), this then causes the force_const_mem 
function to return a NULL_RTX and then causes GCC to segmentation fault when calling
the memory_address_p function.

The fix is to add a check that the tem variable is not a NULL_RTX before
the memory_address_p function call.  I have tested the fix on the mips-mti-linux-gnu
target for both mips32r2 o32 and mips64r2 n64 and there have been no regressions.

The patch and ChangeLog are below.

Ok to commit?


Many thanks,



Andrew



	* explow.c (plus_constant): Update check after force_const_mem call to see if the
	value returned is not a NULL_RTX.

Comments

Jeff Law June 2, 2015, 8:08 p.m. UTC | #1
On 06/02/2015 08:19 AM, Andrew Bennett wrote:
> Hi,
>
> In the plus_constant function in explow.c the code to update a constant pool value
> does not deal with the case where the value returned from force_const_mem is a
> NULL_RTX.  This occurs for the MIPS target because its
> cannot_force_const_mem target function does not allow constants (so that the
> move expanders can deal with them later on), this then causes the force_const_mem
> function to return a NULL_RTX and then causes GCC to segmentation fault when calling
> the memory_address_p function.
>
> The fix is to add a check that the tem variable is not a NULL_RTX before
> the memory_address_p function call.  I have tested the fix on the mips-mti-linux-gnu
> target for both mips32r2 o32 and mips64r2 n64 and there have been no regressions.
>
> The patch and ChangeLog are below.
>
> Ok to commit?
>
>
> Many thanks,
>
>
>
> Andrew
>
>
>
> 	* explow.c (plus_constant): Update check after force_const_mem call to see if the
> 	value returned is not a NULL_RTX.
OK.  Please install.

Thanks,
Jeff
Andrew Bennett June 3, 2015, 9:16 a.m. UTC | #2
> OK.  Please install.

Committed as SVN revision 224064.

Many thanks,


Andrew
Andrew Bennett June 3, 2015, 9:46 a.m. UTC | #3
> > OK.  Please install.
> 
> Committed as SVN revision 224064.

Hi Jeff,

Are you also happy for me to backport the patch on to the 4.9 and 5 branches?

Many thanks,


Andrew
Jeff Law June 3, 2015, 12:48 p.m. UTC | #4
On 06/03/2015 03:46 AM, Andrew Bennett wrote:
>>> OK.  Please install.
>>
>> Committed as SVN revision 224064.
>
> Hi Jeff,
>
> Are you also happy for me to backport the patch on to the 4.9 and 5 branches?
Jakub, Joseph or Richi would need to make that decision as the release 
managers.  I think the patch is quite safe from a backporting standpoint.

jeff
diff mbox

Patch

diff --git a/gcc/explow.c b/gcc/explow.c
index d1a2bf8..8745aea 100644
--- a/gcc/explow.c
+++ b/gcc/explow.c
@@ -132,7 +132,9 @@  plus_constant (machine_mode mode, rtx x, HOST_WIDE_INT c,
 	{
 	  tem = plus_constant (mode, get_pool_constant (XEXP (x, 0)), c);
 	  tem = force_const_mem (GET_MODE (x), tem);
-	  if (memory_address_p (GET_MODE (tem), XEXP (tem, 0)))
+	  /* Targets may disallow some constants in the constant pool, thus
+	     force_const_mem may return NULL_RTX.  */
+	  if (tem && memory_address_p (GET_MODE (tem), XEXP (tem, 0)))
 	    return tem;
 	}
       break;