This patch extends the fix for PR53633 to include static functions,
which were giving a bogus -Wreturn-type warning for C but not for C++.

Tested on aarch64-linux-gnu, x86_64-linux-gnu and armeb-eabi.
OK for trunk?  OK for GCC 8 and 9 too?  I don't think it's
a regression, but the current behaviour's very inconsistent
and it's affecting real code.

Richard


2019-07-16  Richard Sandiford  <richard.sandif...@arm.com>

gcc/c/
        PR c/53633
        * c-decl.c (finish_function): Check targetm.warn_func_return
        before issuing a -Wreturn-type warning.

gcc/testsuite/
        * c-c++-common/pr53633-2.c: New test.

Index: gcc/c/c-decl.c
===================================================================
--- gcc/c/c-decl.c      2019-07-10 19:41:20.543944894 +0100
+++ gcc/c/c-decl.c      2019-07-16 09:46:23.220645712 +0100
@@ -9687,6 +9687,7 @@ finish_function (void)
       /* Normally, with -Wreturn-type, flow will complain, but we might
          optimize out static functions.  */
       && !TREE_PUBLIC (fndecl)
+      && targetm.warn_func_return (fndecl)
       && warning (OPT_Wreturn_type,
                  "no return statement in function returning non-void"))
     TREE_NO_WARNING (fndecl) = 1;
Index: gcc/testsuite/c-c++-common/pr53633-2.c
===================================================================
--- /dev/null   2019-06-14 15:59:19.298479944 +0100
+++ gcc/testsuite/c-c++-common/pr53633-2.c      2019-07-16 09:46:23.220645712 
+0100
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target naked_functions } */
+/* { dg-options "-O2 -Wall" } */
+/* Check that we do not get warnings about missing return statements
+   or bogus looking noreturn functions.  */
+static int __attribute__((naked))
+foo (void)
+{
+  __asm__ ("");
+}
+
+static int __attribute__((naked,noreturn))
+bar (void)
+{
+  __asm__ ("");
+}
+
+int foo_caller (void) { return foo (); }
+int bar_caller (void) { return bar (); }

Reply via email to