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]

Re: [PATCH] Fix PR c++/28266: ICE on invalid default variable


Hi.

> > The attached patch fixes this problem the following way: if a default
> > argument is not valid (i.e. is parsed into error_mark_node), then we act
> > as if there was no default argument in the first place by setting
> > TREE_PURPOSE(...) to NULL_TREE instead of error_mark_node.
>
> Seems to me that you should just robustify the gimplifier.  These
> error_mark_nodes mark errors, and the rest of the compiler should
> just handle them.
The problem is that 'gimplify_target_expr' is called a first time, and calls 
'gimple_add_tmp_var', that will set "DECL_SEEN_IN_BIND_EXPR (tmp)" to 1. The 
gimplification of 'init' will fail, so GS_ERROR is returned.
'gimplify_target_expr' is called a second time, so is 'gimple_add_tmp_var', 
and the "!DECL_SEEN_IN_BIND_EXPR (tmp)" assertion fails.
The following patch ensures that 'gimple_add_tmp_var' is called only once by 
setting "TARGET_EXPR_INITIAL (targ)" to NULL_TREE before returning GS_ERROR 
the first time 'gimplify_target_expr' is called (just like it is done at the 
end of the block when no error occurs).

This has been successfully bootstrapped and regtested with no new unexpected 
failures on i686-pc-linux-gnu. Is it OK? If so, could someone commit it for 
me please?

Thanks in advance.

Best regards,
Simon
2006-10-10  Simon Martin  <simartin@users.sourceforge.net>

	PR c++/28266
	* gimplify.c (gimplify_target_expr): Make sure that the TARGET_EXPR is
	expanded only once even if an error occurs.
Index: gcc/gimplify.c
===================================================================
--- gcc/gimplify.c	(revision 117607)
+++ gcc/gimplify.c	(working copy)
@@ -4230,7 +4230,11 @@ gimplify_target_expr (tree *expr_p, tree
 			       fb_none);
 	}
       if (ret == GS_ERROR)
-	return GS_ERROR;
+	{
+	  /* PR c++/28266 Make sure this is expanded only once. */
+	  TARGET_EXPR_INITIAL (targ) = NULL_TREE;
+	  return GS_ERROR;
+	}
       append_to_statement_list (init, pre_p);
 
       /* If needed, push the cleanup for the temp.  */
2006-10-10  Simon Martin  <simartin@users.sourceforge.net>

	PR c++/28266
	* g++.dg/parse/defarg12.C: New test.
/* PR28266 This used to ICE in gimple_add_tmp_var */
/* { dg-do "compile" } */

struct A
{
  int i;
  A(int = X); /* { dg-error "was not declared in this scope" }*/
};

void foo()
{
  A().i;
}

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