This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[ast-optimizer-branch] PATCH for some sanity checks
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 08 Jun 2002 08:32:31 +0100
- Subject: [ast-optimizer-branch] PATCH for some sanity checks
Replacing the lhs of an assignment with a temporary doesn't work very
well. This happened at one point while working on a previous patch; this
should help to avoid such things in future.
Booted i686-pc-linux-gnu.
2002-06-08 Jason Merrill <jason@redhat.com>
* c-simplify.c (create_tmp_var): Refuse to create an array temp.
(simple_tmp_var_p): New fn.
(simplify_lvalue_expr): Use it; make sure we don't return a temp.
* tree-simple.h: Declare it.
*** c-simplify.c.~1~ Sat Jun 8 07:15:13 2002
--- c-simplify.c Sat Jun 8 07:05:37 2002
*************** simplify_lvalue_expr (expr_p, pre_p, pos
*** 1816,1821 ****
--- 1816,1825 ----
}
else
abort ();
+
+ /* If we end up with a temporary variable, we've done something wrong. */
+ if (simple_tmp_var_p (*expr_p))
+ abort ();
}
/* }}} */
*************** create_tmp_var (type)
*** 2083,2092 ****
ASM_FORMAT_PRIVATE_NAME (tmp_name, "T", id_num++);
! /* If the type is an array, use TYPE_POINTER_TO to create a valid pointer
! that can be used in the LHS of an assignment. */
if (TREE_CODE (type) == ARRAY_TYPE)
! type = TYPE_POINTER_TO (TREE_TYPE (type));
tmp_var = build_decl (VAR_DECL, get_identifier (tmp_name), type);
--- 2087,2095 ----
ASM_FORMAT_PRIVATE_NAME (tmp_name, "T", id_num++);
! /* If the type is an array, something is wrong. */
if (TREE_CODE (type) == ARRAY_TYPE)
! abort ();
tmp_var = build_decl (VAR_DECL, get_identifier (tmp_name), type);
*************** create_tmp_var (type)
*** 2110,2118 ****
/* }}} */
/** {{{ make_type_writable ()
! Change the flags for the type of the node T to make it writtable. */
static void
make_type_writable (t)
--- 2113,2134 ----
/* }}} */
+ /** {{{ simple_tmp_var_p ()
+
+ Returns true if T is a SIMPLE temporary variable, false otherwise. */
+
+ bool
+ simple_tmp_var_p (t)
+ tree t;
+ {
+ /* FIXME this could trigger for other local artificials, too. */
+ return (TREE_CODE (t) == VAR_DECL && DECL_ARTIFICIAL (t)
+ && !TREE_STATIC (t) && !DECL_EXTERNAL (t));
+ }
+
/** {{{ make_type_writable ()
! Change the flags for the type of the node T to make it writable. */
static void
make_type_writable (t)
*** tree-simple.h.~1~ Sat Jun 8 07:15:13 2002
--- tree-simple.h Sat Jun 8 07:18:26 2002
*************** Boston, MA 02111-1307, USA. */
*** 26,31 ****
--- 26,32 ----
extern void insert_before_continue_end PARAMS ((tree, tree, int));
extern void tree_build_scope PARAMS ((tree *));
extern tree create_tmp_var PARAMS ((tree));
+ extern bool simple_tmp_var_p PARAMS ((tree));
extern tree declare_tmp_vars PARAMS ((tree, tree));
extern tree deep_copy_list PARAMS ((tree));
extern tree deep_copy_node PARAMS ((tree));