This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[ast-optimizer-branch]: Fix for incorrect scope building
- From: Daniel Berlin <dberlin at dberlin dot org>
- To: dnovillo at redhat dot com
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sat, 4 May 2002 15:46:59 -0400 (EDT)
- Subject: [ast-optimizer-branch]: Fix for incorrect scope building
For
if (a)
win:
return 1;
we build
if (a)
{
win:;
}
and lose the return 1.
This causes things like infinite loops in reg_class_subset_p, which jumps
to win when it finds something (and thus, falls back through, rather than
returning 1).
The problem is that when building the scope, we chain the end scope to *t,
replacing whatever it was chained to already, rather than chain it to the
last thing in the chain of *t.
This only probably hits LABEL_STMTS, where for the purposes of turning
something without a compound statement, into something with one, we need
to ignore the label_stmt, since it's not counted.
So if we convert non-compounds into compounds anywhere else, we need to
watch this.
Index: c-simplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/c-simplify.c,v
retrieving revision 1.1.2.15
diff -c -3 -p -w -B -b -r1.1.2.15 c-simplify.c
*** c-simplify.c 2 May 2002 19:42:00 -0000 1.1.2.15
--- c-simplify.c 4 May 2002 19:43:52 -0000
*************** tree_build_scope (t)
*** 1902,1908 ****
{
/* Construct a compound statement and a scope. */
tree body, start_scope, end_scope;
!
body = make_node (COMPOUND_STMT);
start_scope = make_node (SCOPE_STMT);
end_scope = make_node (SCOPE_STMT);
--- 2033,2039 ----
{
/* Construct a compound statement and a scope. */
tree body, start_scope, end_scope;
! tree endplace;
body = make_node (COMPOUND_STMT);
start_scope = make_node (SCOPE_STMT);
end_scope = make_node (SCOPE_STMT);
*************** tree_build_scope (t)
*** 1910,1916 ****
SCOPE_BEGIN_P (end_scope) = 0;
COMPOUND_BODY (body) = start_scope;
TREE_CHAIN (start_scope) = *t;
! TREE_CHAIN (*t) = end_scope;
*t = body;
}
}
--- 2041,2050 ----
SCOPE_BEGIN_P (end_scope) = 0;
COMPOUND_BODY (body) = start_scope;
TREE_CHAIN (start_scope) = *t;
! endplace = *t;
! while (TREE_CHAIN (endplace))
! endplace = TREE_CHAIN (endplace);
! TREE_CHAIN (endplace) = end_scope;
*t = body;
}
}