[patch] arm,rx: don't ICE on naked functions with local vars

DJ Delorie dj@redhat.com
Tue Jul 26 20:21:00 GMT 2011


This patch tests for at least one user-caused reason for this
assertion failing - requiring a local frame in a naked function.  For
this case at least, it would be better to trigger an error than to
ICE.  OK?

static int bar;
void __attribute__((naked)) function(void) {
   int foo, result;
   result = subFunction(&foo, &bar);   // ICE here
}

	* expr.c (expand_expr_addr_expr_1): Detect a user request for
	a local frame in a naked function, and produce a suitable
	error for that specific case.

Index: expr.c
===================================================================
--- expr.c	(revision 176766)
+++ expr.c	(working copy)
@@ -6943,13 +6943,22 @@ expand_expr_addr_expr_1 (tree exp, rtx t
 				modifier == EXPAND_INITIALIZER
 				? EXPAND_INITIALIZER : EXPAND_CONST_ADDRESS);
 
 	  /* If the DECL isn't in memory, then the DECL wasn't properly
 	     marked TREE_ADDRESSABLE, which will be either a front-end
 	     or a tree optimizer bug.  */
-	  gcc_assert (MEM_P (result));
+
+	  if (TREE_ADDRESSABLE (exp)
+	      && ! MEM_P (result)
+	      && ! targetm.calls.allocate_stack_slots_for_args())
+	    {
+	      error ("local frame unavailable (naked function?)");
+	      return result;
+	    }
+	  else
+	    gcc_assert (MEM_P (result));
 	  result = XEXP (result, 0);
 
 	  /* ??? Is this needed anymore?  */
 	  if (DECL_P (exp) && !TREE_USED (exp) == 0)
 	    {
 	      assemble_external (exp);



More information about the Gcc-patches mailing list