This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Another patch for bad warnings for inlined functions
Jeffrey A Law <law@redhat.com> writes:
> > 2005-01-27 Ian Lance Taylor <ian@airs.com>
> >
> > * gimple-low.c (block_may_fallthru): TRY_FINALLY_EXPR only falls
> > through if both operands fall through.
> This is fine. Though I would suggest a comment explaining why both
> the TRY and FINALLY must fall through.
>
> If you could add a test to the testsuite it would appreciated.
This is what I am checking in.
Ian
ChangeLog:
2005-01-28 Ian Lance Taylor <ian@airs.com>
PR middle-end/16558
PR middle-end/19583
* gimple-low.c (block_may_fallthru): TRY_FINALLY_EXPR only falls
through if both operands fall through.
testsuite/ChangeLog:
2005-01-28 Ian Lance Taylor <ian@airs.com>
PR middle-end/16558
* g++.dg/warn/Wreturn-type-2.C: New test.
Index: gimple-low.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gimple-low.c,v
retrieving revision 2.20
diff -u -r2.20 gimple-low.c
--- gimple-low.c 27 Jan 2005 14:36:17 -0000 2.20
+++ gimple-low.c 28 Jan 2005 17:28:27 -0000
@@ -348,7 +348,15 @@
return try_catch_may_fallthru (stmt);
case TRY_FINALLY_EXPR:
- return block_may_fallthru (TREE_OPERAND (stmt, 1));
+ /* The finally clause is always executed after the try clause,
+ so if it does not fall through, then the try-finally will not
+ fall through. Otherwise, if the try clause does not fall
+ through, then when the finally clause falls through it will
+ resume execution wherever the try clause was going. So the
+ whole try-finally will only fall through if both the try
+ clause and the finally clause fall through. */
+ return (block_may_fallthru (TREE_OPERAND (stmt, 0))
+ && block_may_fallthru (TREE_OPERAND (stmt, 1)));
case MODIFY_EXPR:
if (TREE_CODE (TREE_OPERAND (stmt, 1)) == CALL_EXPR)
Index: g++.dg/warn/Wreturn-type-2.C
===================================================================
RCS file: g++.dg/warn/Wreturn-type-2.C
diff -N g++.dg/warn/Wreturn-type-2.C
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ g++.dg/warn/Wreturn-type-2.C 28 Jan 2005 17:31:22 -0000
@@ -0,0 +1,20 @@
+// PR middle-end/16558
+// { dg-options "-Wreturn-type" }
+
+struct C
+{
+ C ();
+ ~C ();
+};
+
+int getref (int ndx)
+{
+ C d;
+
+ if (ndx != 0) {
+ C base;
+ return 0;
+ }
+ else
+ return 0;
+}