From: Richard Sandiford Date: Sat, 20 Jul 2019 18:50:20 +0000 (+0000) Subject: Fix -Wreturn-type for static naked functions in C X-Git-Tag: releases/gcc-9.2.0~128 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=56544a47e0a36563ff12cbe3fb21ba9f36414fe6;p=thirdparty%2Fgcc.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-20 Richard Sandiford gcc/c/ Backport from mainline 2019-07-18 Richard Sandiford 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 * c-c++-common/pr53633-2.c: New test. From-SVN: r273635 --- diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 65e2f92792ba..0411099523c9 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,12 @@ +2019-07-20 Richard Sandiford + + Backport from mainline + 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-05-17 Jakub Jelinek Backported from mainline diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index c8e7cd01d9ec..04e0f4dc1981 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index de0b52ce248a..e57acad0d33f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2019-07-20 Richard Sandiford + + Backport from mainline + 2019-07-18 Richard Sandiford + + * c-c++-common/pr53633-2.c: New test. + 2019-07-18 Kito Cheng 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 index 000000000000..c26cb10cc838 --- /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 (); }