This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[tree-ssa] minor c_warn_unused_result reorg
- From: Richard Henderson <rth at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 10 Nov 2003 10:14:05 -0800
- Subject: [tree-ssa] minor c_warn_unused_result reorg
This is needed once COMPOUND_EXPR is not how statements are connected.
Putting it in now means the future diff is smaller. I expect to be
putting in a lot more of these type patches.
Bootstrap and compare without regressions on i686-linux.
r~
* c-common.c (c_warn_unused_result): Restructure to use iterator
on COMPOUND_EXPR only.
Index: gcc/c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.344.2.47
diff -c -p -d -r1.344.2.47 c-common.c
*** gcc/c-common.c 31 Oct 2003 07:29:41 -0000 1.344.2.47
--- gcc/c-common.c 10 Nov 2003 09:22:57 -0000
*************** c_decl_uninit (tree t)
*** 5969,6018 ****
void
c_warn_unused_result (tree *top_p)
{
tree_stmt_iterator i;
tree fdecl, ftype;
! for (i = tsi_start (top_p); !tsi_end_p (i); tsi_next (&i))
{
! tree t = tsi_stmt (i);
! switch (TREE_CODE (t))
{
! case BIND_EXPR:
! c_warn_unused_result (&BIND_EXPR_BODY (t));
! break;
! case CALL_EXPR:
! /* This is a naked call, as opposed to a CALL_EXPR nested inside
! a MODIFY_EXPR. All calls whose value is ignored should be
! represented like this. Look for the attribute. */
! fdecl = get_callee_fndecl (t);
if (fdecl)
! ftype = TREE_TYPE (fdecl);
else
! {
! ftype = TREE_TYPE (TREE_OPERAND (t, 0));
! /* Look past pointer-to-function to the function type itself. */
! ftype = TREE_TYPE (ftype);
! }
!
! if (lookup_attribute ("warn_unused_result", TYPE_ATTRIBUTES (ftype)))
! {
! if (fdecl)
! warning ("%Hignoring return value of `%D', "
! "declared with attribute warn_unused_result",
! EXPR_LOCUS (t), fdecl);
! else
! warning ("%Hignoring return value of function "
! "declared with attribute warn_unused_result",
! EXPR_LOCUS (t));
! }
! break;
!
! default:
! /* Not a container, not a call, or a call whose value is used. */
! break;
}
}
}
--- 5969,6034 ----
void
c_warn_unused_result (tree *top_p)
{
+ tree t = *top_p;
tree_stmt_iterator i;
tree fdecl, ftype;
! switch (TREE_CODE (t))
{
! case COMPOUND_EXPR:
! for (i = tsi_start (top_p); !tsi_end_p (i); tsi_next (&i))
! c_warn_unused_result (tsi_stmt_ptr (i));
! break;
! case COND_EXPR:
! c_warn_unused_result (&COND_EXPR_THEN (t));
! c_warn_unused_result (&COND_EXPR_ELSE (t));
! break;
! case BIND_EXPR:
! c_warn_unused_result (&BIND_EXPR_BODY (t));
! break;
! case TRY_FINALLY_EXPR:
! case TRY_CATCH_EXPR:
! c_warn_unused_result (&TREE_OPERAND (t, 0));
! c_warn_unused_result (&TREE_OPERAND (t, 1));
! break;
! case CATCH_EXPR:
! c_warn_unused_result (&CATCH_BODY (t));
! break;
! case EH_FILTER_EXPR:
! c_warn_unused_result (&EH_FILTER_FAILURE (t));
! break;
!
! case CALL_EXPR:
! /* This is a naked call, as opposed to a CALL_EXPR nested inside
! a MODIFY_EXPR. All calls whose value is ignored should be
! represented like this. Look for the attribute. */
! fdecl = get_callee_fndecl (t);
! if (fdecl)
! ftype = TREE_TYPE (fdecl);
! else
{
! ftype = TREE_TYPE (TREE_OPERAND (t, 0));
! /* Look past pointer-to-function to the function type itself. */
! ftype = TREE_TYPE (ftype);
! }
! if (lookup_attribute ("warn_unused_result", TYPE_ATTRIBUTES (ftype)))
! {
if (fdecl)
! warning ("%Hignoring return value of `%D', "
! "declared with attribute warn_unused_result",
! EXPR_LOCUS (t), fdecl);
else
! warning ("%Hignoring return value of function "
! "declared with attribute warn_unused_result",
! EXPR_LOCUS (t));
}
+ break;
+
+ default:
+ /* Not a container, not a call, or a call whose value is used. */
+ break;
}
}