diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2d68c4139cb..733ff95fea9 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2003-07-08 Roger Sayle + + 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. + 2003-07-08 Geoffrey Keating * expr.c (MOVE_MAX_PIECES): Move from here... diff --git a/gcc/calls.c b/gcc/calls.c index 04157447114..700564a33db 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -529,6 +529,10 @@ emit_call_1 (rtx funexp, tree fndecl ATTRIBUTE_UNUSED, tree funtype ATTRIBUTE_UN 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) @@ -3074,6 +3078,10 @@ expand_call (tree exp, rtx target, int ignore) } 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) @@ -3304,8 +3312,9 @@ expand_call (tree exp, rtx target, int ignore) normal_call_insns = insns; /* Verify that we've deallocated all the stack we used. */ - if (old_stack_allocated != - stack_pointer_delta - pending_stack_adjust) + if (! (flags & (ECF_NORETURN | ECF_LONGJMP)) + && old_stack_allocated != stack_pointer_delta + - pending_stack_adjust) abort (); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5884c7fd56e..cbd7cae9c1f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2003-07-08 Roger Sayle + + PR c/11370 + * gcc.dg/Wunreachable-6.c: New testcase. + * gcc.dg/Wunreachable-7.c: New testcase. + 2003-07-08 Jakub Jelinek PR c/11420 diff --git a/gcc/testsuite/gcc.dg/Wunreachable-6.c b/gcc/testsuite/gcc.dg/Wunreachable-6.c new file mode 100644 index 00000000000..77b6228fc86 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wunreachable-6.c @@ -0,0 +1,18 @@ +/* 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; +} + diff --git a/gcc/testsuite/gcc.dg/Wunreachable-7.c b/gcc/testsuite/gcc.dg/Wunreachable-7.c new file mode 100644 index 00000000000..a19c94a1760 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wunreachable-7.c @@ -0,0 +1,18 @@ +/* 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; +} +