]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix -Wreturn-type for static naked functions in C
authorRichard Sandiford <richard.sandiford@arm.com>
Sat, 20 Jul 2019 18:50:20 +0000 (18:50 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Sat, 20 Jul 2019 18:50:20 +0000 (18:50 +0000)
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++.

2019-07-20  Richard Sandiford  <richard.sandiford@arm.com>

gcc/c/
Backport from mainline
2019-07-18  Richard Sandiford  <richard.sandiford@arm.com>

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

gcc/testsuite/
Backport from mainline
2019-07-18  Richard Sandiford  <richard.sandiford@arm.com>

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

From-SVN: r273635

gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr53633-2.c [new file with mode: 0644]

index 65e2f92792ba4dbf821cc51ba8b8e91ebd8ab4a2..0411099523c96af48f21b01c6a62328daed6f303 100644 (file)
@@ -1,3 +1,12 @@
+2019-07-20  Richard Sandiford  <richard.sandiford@arm.com>
+
+       Backport from mainline
+       2019-07-18  Richard Sandiford  <richard.sandiford@arm.com>
+
+       PR c/53633
+       * c-decl.c (finish_function): Check targetm.warn_func_return
+       before issuing a -Wreturn-type warning.
+
 2019-05-17  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
index c8e7cd01d9ec1abe5c6255ea2f41b282b474e0f0..04e0f4dc1981d1b2b49a4a40ec9326826f36900c 100644 (file)
@@ -9685,6 +9685,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 de0b52ce248a59ddef850b4fa610745d2301683a..e57acad0d33f8b329e6c235e1f13dff88670d430 100644 (file)
@@ -1,3 +1,10 @@
+2019-07-20  Richard Sandiford  <richard.sandiford@arm.com>
+
+       Backport from mainline
+       2019-07-18  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * c-c++-common/pr53633-2.c: New test.
+
 2019-07-18  Kito Cheng  <kito.cheng@sifive.com>
 
        Backport from mainline
diff --git a/gcc/testsuite/c-c++-common/pr53633-2.c b/gcc/testsuite/c-c++-common/pr53633-2.c
new file mode 100644 (file)
index 0000000..c26cb10
--- /dev/null
@@ -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 (); }