* Fix -Wreturn-type for static naked functions in C
@ 2019-07-16 8:54 Richard Sandiford
2019-07-16 20:58 ` Marek Polacek
0 siblings, 1 reply; 2+ messages in thread
From: Richard Sandiford @ 2019-07-16 8:54 UTC (permalink / raw)
To: gcc-patches
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.sandiford@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 (); }
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Fix -Wreturn-type for static naked functions in C
2019-07-16 8:54 Fix -Wreturn-type for static naked functions in C Richard Sandiford
@ 2019-07-16 20:58 ` Marek Polacek
0 siblings, 0 replies; 2+ messages in thread
From: Marek Polacek @ 2019-07-16 20:58 UTC (permalink / raw)
To: gcc-patches, richard.sandiford
On Tue, Jul 16, 2019 at 09:50:31AM +0100, Richard Sandiford wrote:
> 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.
Ok, thanks.
> 2019-07-16 Richard Sandiford <richard.sandiford@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 (); }
Marek
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-07-16 20:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-16 8:54 Fix -Wreturn-type for static naked functions in C Richard Sandiford
2019-07-16 20:58 ` Marek Polacek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).