[3.3 PATCH] PR c/11370: Backport from mainline
Roger Sayle
roger@eyesopen.com
Sun Jul 13 18:09:00 GMT 2003
The following patch is a backport to 3.3 from mainline of my fix
for PR c/11370, which are bogus warnings following noreturn function
calls with -Wunreachable. I realize this has very recently been
triaged for 3.3.2, but I was already testing it against 3.3 anyway.
The original patch:
http://gcc.gnu.org/ml/gcc-patches/2003-07/msg00556.html
was approved for mainline by Richard Henderson:
http://gcc.gnu.org/ml/gcc-patches/2003-07/msg00886.html
and has been on mainline for several days without problems.
The following patch has been tested against the gcc-3_3-branch on
i686-pc-linux-gnu with a complete bootstrap, all languages except
treelang, and regression tested with a top-level "make -k check"
with no new failures.
Ok for the 3.3 branch?
2003-07-13 Roger Sayle <roger@eyesopen.com>
PR c/11370
* calls.c (emit_call_1): Don't bother popping the arguments off of
the stack after a noreturn function call; The adjustment is dead.
(expand_call): Likewise.
* gcc.dg/Wunreachable-6.c: New testcase.
* gcc.dg/Wunreachable-7.c: New testcase.
Index: calls.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/calls.c,v
retrieving revision 1.244.2.8
diff -c -3 -p -r1.244.2.8 calls.c
*** calls.c 10 Jun 2003 18:34:06 -0000 1.244.2.8
--- calls.c 13 Jul 2003 13:52:16 -0000
*************** emit_call_1 (funexp, fndecl, funtype, st
*** 641,646 ****
--- 641,650 ----
if the context of the call as a whole permits. */
inhibit_defer_pop = old_inhibit_defer_pop;
+ /* Don't bother cleaning up after a noreturn function. */
+ if (ecf_flags & (ECF_NORETURN | ECF_LONGJMP))
+ return;
+
if (n_popped > 0)
{
if (!already_popped)
*************** expand_call (exp, target, ignore)
*** 3098,3103 ****
--- 3102,3108 ----
/* Verify that we've deallocated all the stack we used. */
if (pass
+ && ! (flags & (ECF_NORETURN | ECF_LONGJMP))
&& old_stack_allocated != stack_pointer_delta - pending_stack_adjust)
abort ();
*************** expand_call (exp, target, ignore)
*** 3191,3196 ****
--- 3196,3205 ----
}
emit_barrier_after (last);
+
+ /* Stack adjustments after a noreturn call are dead code. */
+ stack_pointer_delta = old_stack_allocated;
+ pending_stack_adjust = 0;
}
if (flags & ECF_LONGJMP)
/* PR c/11370 */
/* { dg-do compile } */
/* { dg-options "-Wunreachable-code" } */
int main(int argc, char *argv[])
{
if (argc != 1)
exit(1);
{
int ix; /* { dg-bogus "will never be executed" } */
ix = printf("hello\n");
printf("%d\n", ix);
}
return 0;
}
/* PR c/11370 */
/* { dg-do compile } */
/* { dg-options "-O2 -Wunreachable-code" } */
int main(int argc, char *argv[])
{
if (argc != 1)
exit(1);
{
int ix; /* { dg-bogus "will never be executed" } */
ix = printf("hello\n");
printf("%d\n", ix);
}
return 0;
}
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833
More information about the Gcc-patches
mailing list