From: Jakub Jelinek Date: Wed, 22 Jan 2020 16:48:05 +0000 (+0100) Subject: re PR ipa/93087 (Bogus `-Wsuggest-attribute=cold` on function already marked as ... X-Git-Tag: releases/gcc-9.3.0~203 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7bf1518f84d5e676dd5f4335783eaf7b742961a5;p=thirdparty%2Fgcc.git re PR ipa/93087 (Bogus `-Wsuggest-attribute=cold` on function already marked as `__attribute__((cold))`) PR ipa/93087 * predict.c (compute_function_frequency): Don't call warn_function_cold on functions that already have cold attribute. * c-c++-common/cold-1.c: New test. --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d31312299a89..d95b6af65731 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2020-01-22 Jakub Jelinek + + Backported from mainline + 2020-01-02 Jakub Jelinek + + PR ipa/93087 + * predict.c (compute_function_frequency): Don't call + warn_function_cold on functions that already have cold attribute. + 2020-01-20 Richard Biener Backport from mainline diff --git a/gcc/predict.c b/gcc/predict.c index 60a19d7edd12..eaab47f992ae 100644 --- a/gcc/predict.c +++ b/gcc/predict.c @@ -3937,12 +3937,14 @@ compute_function_frequency (void) if (profile_status_for_fn (cfun) != PROFILE_READ) { int flags = flags_from_decl_or_type (current_function_decl); - if ((ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa_p () - && ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa() == profile_count::zero ()) - || lookup_attribute ("cold", DECL_ATTRIBUTES (current_function_decl)) - != NULL) + if (lookup_attribute ("cold", DECL_ATTRIBUTES (current_function_decl)) + != NULL) + node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED; + else if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa_p () + && (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa () + == profile_count::zero ())) { - node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED; + node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED; warn_function_cold (current_function_decl); } else if (lookup_attribute ("hot", DECL_ATTRIBUTES (current_function_decl)) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c306cf6c296d..cd4f7f444848 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2020-01-22 Jakub Jelinek + + Backported from mainline + 2020-01-02 Jakub Jelinek + + PR ipa/93087 + * c-c++-common/cold-1.c: New test. + 2020-01-22 Jakub Jelinek Backported from mainline diff --git a/gcc/testsuite/c-c++-common/cold-1.c b/gcc/testsuite/c-c++-common/cold-1.c new file mode 100644 index 000000000000..3493623e1eba --- /dev/null +++ b/gcc/testsuite/c-c++-common/cold-1.c @@ -0,0 +1,22 @@ +/* PR ipa/93087 */ +/* { dg-do compile { target nonpic } } */ +/* { dg-options "-O1 -Wsuggest-attribute=cold" } */ + +extern void *getdata (void); +extern int set_error (char const *message) __attribute__((cold)); + +__attribute__((cold)) int +set_nomem (void) /* { dg-bogus "function might be candidate for attribute 'cold'" } */ +{ + return set_error ("Allocation failed"); +} + +void * +getdata_or_set_error (void) +{ + void *result; + result = getdata (); + if (!result) + set_nomem (); + return result; +}