From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id CE7883940CFB; Tue, 2 May 2023 20:16:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CE7883940CFB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683058578; bh=4EymSx1ZzYnbiHSPR/zJDQ8BWhOlvj2FlNm3EeFMTXc=; h=From:To:Subject:Date:From; b=Hb4oz/nHKYCE6tfUVV24PtIAmXthaju+1pG4wm3SG6uX+0eLJSZTtOg2S5kHBlrkV qGtx0v8GDvLaMROfupuB9mG+jK9PISX8/xDaCujhMVCExvf3rXCziEC+si6vNp369W nqtU41ngJPpZMtx+mlG24yEFVVbwB9E2iN69Krkw= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-10730] predict: Don't emit -Wsuggest-attribute=cold warning for functions which already have that attribute X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 3384fb5024e05cfd429e2fb619ae8d51eba69661 X-Git-Newrev: c448f0d85c778eade1d8ae597744f6455285346f Message-Id: <20230502201618.CE7883940CFB@sourceware.org> Date: Tue, 2 May 2023 20:16:18 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c448f0d85c778eade1d8ae597744f6455285346f commit r11-10730-gc448f0d85c778eade1d8ae597744f6455285346f Author: Jakub Jelinek Date: Sun Mar 26 20:15:05 2023 +0200 predict: Don't emit -Wsuggest-attribute=cold warning for functions which already have that attribute [PR105685] In the following testcase, we predict baz to have cold entry regardless of the user supplied attribute (as it call unconditionally a cold function), but still issue a -Wsuggest-attribute=cold warning despite it having that attribute already. The following patch avoids that. 2023-03-26 Jakub Jelinek PR ipa/105685 * predict.c (compute_function_frequency): Don't call warn_function_cold if function already has cold attribute. * c-c++-common/cold-2.c: New test. (cherry picked from commit 7eca91d4781bb3df941f25c30b971dac66ba1b3d) Diff: --- gcc/predict.c | 4 +++- gcc/testsuite/c-c++-common/cold-2.c | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/gcc/predict.c b/gcc/predict.c index d0a8e5f8e04..75b09fa9e1b 100644 --- a/gcc/predict.c +++ b/gcc/predict.c @@ -4023,7 +4023,9 @@ compute_function_frequency (void) } node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED; - warn_function_cold (current_function_decl); + if (lookup_attribute ("cold", DECL_ATTRIBUTES (current_function_decl)) + == NULL) + warn_function_cold (current_function_decl); if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa() == profile_count::zero ()) return; FOR_EACH_BB_FN (bb, cfun) diff --git a/gcc/testsuite/c-c++-common/cold-2.c b/gcc/testsuite/c-c++-common/cold-2.c new file mode 100644 index 00000000000..7f78496fb82 --- /dev/null +++ b/gcc/testsuite/c-c++-common/cold-2.c @@ -0,0 +1,19 @@ +/* PR ipa/105685 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wsuggest-attribute=cold" } */ + +extern void foo (char *, char const *, int); + +__attribute__((cold)) char * +bar (int x) +{ + static char b[42]; + foo (b, "foo", x); + return b; +} + +__attribute__((cold)) char * +baz (int x) /* { dg-bogus "function might be candidate for attribute 'cold'" } */ +{ + return bar (x); +}