[rl78] add rtx paranoia
diff mbox

Message ID 201310162255.r9GMtbLs019642@greed.delorie.com
State New
Headers show

Commit Message

DJ Delorie Oct. 16, 2013, 10:55 p.m. UTC
Building newlib uncovered a few invalid assumptions...  Committed.

	* config/rl78/rl78.c (rl78_alloc_address_registers_macax): Verify
	op is a REG before checking REGNO.
	(rl78_alloc_physical_registers): Verify pattern is a SET before
	checking SET_SRC.

Patch
diff mbox

Index: config/rl78/rl78.c
===================================================================
--- config/rl78/rl78.c	(revision 203732)
+++ config/rl78/rl78.c	(working copy)
@@ -3047,13 +3047,14 @@  rl78_alloc_address_registers_macax (rtx 
 	      replace_in_op0 = (op > 0 && rtx_equal_p (OP (op), OP (0)));
 	      replace_in_op1 = (op > 1 && rtx_equal_p (OP (op), OP (1)));
 
 	      OP (op) = transcode_memory_rtx (OP (op), HL, insn);
 	      if (op == 2
 		  && MEM_P (OP (op))
-		  && (REGNO (XEXP (OP (op), 0)) == SP_REG
+		  && ((GET_CODE (XEXP (OP (op), 0)) == REG
+		       && REGNO (XEXP (OP (op), 0)) == SP_REG)
 		      || (GET_CODE (XEXP (OP (op), 0)) == PLUS
 			  && REGNO (XEXP (XEXP (OP (op), 0), 0)) == SP_REG)))
 		{
 		  emit_insn_before (gen_movhi (HL, gen_rtx_REG (HImode, SP_REG)), insn);
 		  OP (op) = replace_rtx (OP (op), gen_rtx_REG (HImode, SP_REG), HL);
 		}
@@ -3137,13 +3138,14 @@  rl78_alloc_physical_registers (void)
 	pattern = XVECEXP (pattern, 0, 0);
       if (JUMP_P (insn) || CALL_P (insn) || GET_CODE (pattern) == CALL)
 	clear_content_memory ();
       if (GET_CODE (pattern) != SET
 	  && GET_CODE (pattern) != CALL)
 	continue;
-      if (GET_CODE (SET_SRC (pattern)) == ASM_OPERANDS)
+      if (GET_CODE (pattern) == SET
+	  && GET_CODE (SET_SRC (pattern)) == ASM_OPERANDS)
 	continue;
 
       valloc_method = get_attr_valloc (insn);
 
       PATTERN (insn) = copy_rtx_if_shared (PATTERN (insn));