From: Richard Sandiford Date: Thu, 18 Jul 2019 08:22:50 +0000 (+0000) Subject: Fix -Wreturn-type for static naked functions in C X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d119bf79862015d4ba3c7f8774835c216c9a26ed;p=gcc.git Fix -Wreturn-type for static naked functions in C 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-18 Richard Sandiford 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. From-SVN: r273568 --- diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 927fa914bfb..ee0c55970a2 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2019-07-18 Richard Sandiford + + PR c/53633 + * c-decl.c (finish_function): Check targetm.warn_func_return + before issuing a -Wreturn-type warning. + 2019-07-12 Alexandre Oliva * gimple-parser.c (c_parser_gimple_try_stmt): New. diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index d75648aa273..0d107adf85f 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 69e82b59a9e..f9f17893295 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-07-18 Richard Sandiford + + * c-c++-common/pr53633-2.c: New test. + 2019-07-17 Alexandre Oliva PR middle-end/81824 diff --git a/gcc/testsuite/c-c++-common/pr53633-2.c b/gcc/testsuite/c-c++-common/pr53633-2.c new file mode 100644 index 00000000000..c26cb10cc83 --- /dev/null +++ b/gcc/testsuite/c-c++-common/pr53633-2.c @@ -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 (); }