re PR other/11370 (-Wunreachable-code gives false complaints)
authorRoger Sayle <roger@eyesopen.com>
Wed, 9 Jul 2003 01:17:28 +0000 (01:17 +0000)
committerRoger Sayle <sayle@gcc.gnu.org>
Wed, 9 Jul 2003 01:17:28 +0000 (01:17 +0000)
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.

From-SVN: r69119

gcc/ChangeLog
gcc/calls.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wunreachable-6.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/Wunreachable-7.c [new file with mode: 0644]

index 2d68c4139cb2c88ff09bc9f10acd7267c6c25a45..733ff95fea9b9a997128b87ac61b30f814a77793 100644 (file)
@@ -1,3 +1,10 @@
+2003-07-08  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.
+
 2003-07-08  Geoffrey Keating  <geoffk@apple.com>
 
        * expr.c (MOVE_MAX_PIECES): Move from here...
index 0415744711403c2a97f488cccf6175e5046c3a60..700564a33dbcb49dd775e78fee514dbaba26b072 100644 (file)
@@ -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 ();
        }
 
index 5884c7fd56e146e3689fa9e965d1f8d573d957dd..cbd7cae9c1f8d84c1525b37a74e278d5cbdad997 100644 (file)
@@ -1,3 +1,9 @@
+2003-07-08  Roger Sayle  <roger@eyesopen.com>
+
+       PR c/11370
+       * gcc.dg/Wunreachable-6.c: New testcase.
+       * gcc.dg/Wunreachable-7.c: New testcase.
+
 2003-07-08  Jakub Jelinek  <jakub@redhat.com>
 
        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 (file)
index 0000000..77b6228
--- /dev/null
@@ -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 (file)
index 0000000..a19c94a
--- /dev/null
@@ -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;
+}
+