This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [tree-ssa] fix spec2k perl miscompilation [patch]
On Wed, 2003-06-18 at 13:07, Jason Merrill wrote:
> This patch only warns about a return statement as the last thing in a
> statement-expression; it should handle other non-expressions, too, and void
> expressions, for that matter.
>
> Looking at this again, the last_expr_stmt stuff is unnecessarily
> complicated; we are interested in the last statement period, not the last
> expression statement.
>
OK, thanks. This is the new version of the patch. It's in the last
stages of bootstrapping, fixes SPEC's perl and emits the warning:
universal.c: In function `XS_UNIVERSAL_VERSION':
universal.c:202: warning: statement-expressions should end with a non-void expression
OK if it passes all tests?
Thanks. Diego.
* c-simplify.c (gimplify_stmt_expr): Handle statement-expressions
that don't end in a non-void expression. Emit a warning in that
case.
Index: c-simplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/c-simplify.c,v
retrieving revision 1.1.4.61
diff -d -c -p -r1.1.4.61 c-simplify.c
*** c-simplify.c 25 Jun 2003 07:32:19 -0000 1.1.4.61
--- c-simplify.c 26 Jun 2003 16:33:02 -0000
*************** gimplify_stmt_expr (expr_p)
*** 962,987 ****
c_gimplify_stmt (&body);
else
{
! tree substmt, last_expr_stmt, last_expr, bind;
bind = NULL_TREE; /* [GIMPLE] Avoid uninitialized use warning. */
/* Splice the last expression out of the STMT chain. */
! last_expr_stmt = NULL_TREE;
for (substmt = COMPOUND_BODY (body); substmt;
substmt = TREE_CHAIN (substmt))
{
! if (TREE_CODE (substmt) == EXPR_STMT)
! last_expr_stmt = substmt;
}
- last_expr = EXPR_STMT_EXPR (last_expr_stmt);
- if (stmts_are_full_exprs_p ())
- last_expr = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (last_expr),
- last_expr);
- EXPR_STMT_EXPR (last_expr_stmt) = build_empty_stmt ();
#if defined ENABLE_CHECKING
! if (!is_last_stmt_of_scope (last_expr_stmt))
abort ();
#endif
--- 962,1000 ----
c_gimplify_stmt (&body);
else
{
! tree substmt, last_stmt, last_expr, bind;
bind = NULL_TREE; /* [GIMPLE] Avoid uninitialized use warning. */
/* Splice the last expression out of the STMT chain. */
! last_stmt = NULL_TREE;
for (substmt = COMPOUND_BODY (body); substmt;
substmt = TREE_CHAIN (substmt))
+ if (TREE_CODE (substmt) != SCOPE_STMT)
+ last_stmt = substmt;
+
+ if (TREE_CODE (last_stmt) != EXPR_STMT
+ || (TREE_TYPE (last_stmt)
+ && VOID_TYPE_P (TREE_TYPE (last_stmt))))
{
! location_t loc;
! loc.file = input_filename;
! loc.line = STMT_LINENO (last_stmt);
! warning ("%Hstatement-expressions should end with a non-void expression", &loc);
! last_expr = NULL_TREE;
! }
! else
! {
! last_expr = EXPR_STMT_EXPR (last_stmt);
!
! if (stmts_are_full_exprs_p ())
! last_expr = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (last_expr),
! last_expr);
! EXPR_STMT_EXPR (last_stmt) = build_empty_stmt ();
}
#if defined ENABLE_CHECKING
! if (!is_last_stmt_of_scope (last_stmt))
abort ();
#endif
*************** gimplify_stmt_expr (expr_p)
*** 989,1015 ****
c_gimplify_stmt (&body);
/* Now retrofit that last expression into the BIND_EXPR. */
! if (!STMT_EXPR_NO_SCOPE (*expr_p))
{
! bind = body;
! substmt = BIND_EXPR_BODY (bind);
! }
! else
! substmt = body;
! if (IS_EMPTY_STMT (substmt))
! substmt = last_expr;
! else
! substmt = build (COMPOUND_EXPR, TREE_TYPE (last_expr),
! substmt, last_expr);
! if (!STMT_EXPR_NO_SCOPE (*expr_p))
! {
! BIND_EXPR_BODY (bind) = substmt;
! TREE_TYPE (bind) = TREE_TYPE (body) = TREE_TYPE (last_expr);
}
- else
- body = substmt;
}
*expr_p = body;
--- 1002,1031 ----
c_gimplify_stmt (&body);
/* Now retrofit that last expression into the BIND_EXPR. */
! if (last_expr)
{
! if (!STMT_EXPR_NO_SCOPE (*expr_p))
! {
! bind = body;
! substmt = BIND_EXPR_BODY (bind);
! }
! else
! substmt = body;
! if (IS_EMPTY_STMT (substmt))
! substmt = last_expr;
! else
! substmt = build (COMPOUND_EXPR, TREE_TYPE (last_expr),
! substmt, last_expr);
! if (!STMT_EXPR_NO_SCOPE (*expr_p))
! {
! BIND_EXPR_BODY (bind) = substmt;
! TREE_TYPE (bind) = TREE_TYPE (body) = TREE_TYPE (last_expr);
! }
! else
! body = substmt;
}
}
*expr_p = body;