re PR c/9862 (spurious warnings with -W -finline-functions)
authorSteven Bosscher <steven@gcc.gnu.org>
Sat, 6 Sep 2003 13:34:00 +0000 (13:34 +0000)
committerSteven Bosscher <steven@gcc.gnu.org>
Sat, 6 Sep 2003 13:34:00 +0000 (13:34 +0000)
PR c/9862
* c-decl.c (c_expand_body_1): Move return warning from here...
(finish_function): ...to here.

* gcc.dg/20030906-1.c: New test.
* gcc.dg/20030906-2.c: Likewise.

From-SVN: r71134

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/20030906-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/20030906-2.c [new file with mode: 0644]

index 0d57ffd9c961635bd88100a5909cfeed4a7d19ed..8d7e360d68fbcabbd2825bc947fd0494390ff5c5 100644 (file)
@@ -1,3 +1,9 @@
+2003-09-06  Steven Bosscher  <steven@gcc.gnu.org>
+
+       PR c/9862
+       * c-decl.c (c_expand_body_1): Move return warning from here...
+       (finish_function): ...to here.
+
 2003-09-05  Geoffrey Keating  <geoffk@apple.com>
 
        * config/rs6000/darwin.h (PREFERRED_RELOAD_CLASS): Always return
index f16fe7cd2f606351f8da520ff17b92017184e2f3..f4896f3f8bc3cca132a0fccfcd802fbc9a12dd7b 100644 (file)
@@ -6129,6 +6129,13 @@ finish_function ()
       && DECL_INLINE (fndecl))
     warning ("no return statement in function returning non-void");
 
+  /* With just -Wextra, complain only if function returns both with
+     and without a value.  */
+  if (extra_warnings
+      && current_function_returns_value
+      && current_function_returns_null)
+    warning ("this function may return with or without a value");
+
   /* We're leaving the context of this function, so zap cfun.  It's still in
      DECL_SAVED_INSNS, and we'll restore it in tree_rest_of_compilation.  */
   cfun = NULL;
@@ -6178,13 +6185,6 @@ c_expand_body_1 (tree fndecl, int nested_p)
 
   tree_rest_of_compilation (fndecl);
 
-  /* With just -Wextra, complain only if function returns both with
-     and without a value.  */
-  if (extra_warnings
-      && current_function_returns_value
-      && current_function_returns_null)
-    warning ("this function may return with or without a value");
-
   if (DECL_STATIC_CONSTRUCTOR (fndecl))
     {
       if (targetm.have_ctors_dtors)
index d28f2d11645a5fda6efa1f01413e2336f72d6c87..65f499d18346b6e829b3ff65767db6ea3b7538bd 100644 (file)
@@ -1,3 +1,9 @@
+2003-09-06  Steven Bosscher  <steven@gcc.gnu.org>
+
+       PR c/9862
+       * gcc.dg/20030906-1.c: New test.
+       * gcc.dg/20030906-2.c: Likewise.
+
 2003-09-06  Nathan Sidwell  <nathan@codesourcery.com>
 
        PR c++/12167
diff --git a/gcc/testsuite/gcc.dg/20030906-1.c b/gcc/testsuite/gcc.dg/20030906-1.c
new file mode 100644 (file)
index 0000000..57d80f0
--- /dev/null
@@ -0,0 +1,21 @@
+/* Bug 9862 -- Spurious warnings with -finline-functions.
+   Copyright (C) 2003 Free Software Foundation Inc.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O -finline-functions -Wextra" } */
+
+extern int i;
+extern int foo (void);
+extern int bar (void);
+
+int foo (void)
+{
+  if( i ) return 0;
+  else    return 1;
+}              /* { dg-bogus "may return with or without a value" } */
+
+int bar (void)
+{
+  if( i ) return;
+  else    return 1;
+}              /* { dg-warning "may return with or without a value" } */
diff --git a/gcc/testsuite/gcc.dg/20030906-2.c b/gcc/testsuite/gcc.dg/20030906-2.c
new file mode 100644 (file)
index 0000000..8f3d378
--- /dev/null
@@ -0,0 +1,21 @@
+/* Bug 9862 -- Spurious warnings with -finline-functions.
+   Copyright (C) 2003 Free Software Foundation Inc.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O -finline-functions -Wextra" } */
+
+extern int i;
+extern int foo (void);
+extern int bar (void);
+
+int foo (void)
+{
+  if( i ) return;
+  else    return 1;
+}              /* { dg-warning "may return with or without a value" } */
+
+int bar (void)
+{
+  if( i ) return 0;
+  else    return 1;
+}