]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
predict: Don't emit -Wsuggest-attribute=cold warning for functions which already...
authorJakub Jelinek <jakub@redhat.com>
Sun, 26 Mar 2023 18:15:05 +0000 (20:15 +0200)
committerJakub Jelinek <jakub@redhat.com>
Wed, 3 May 2023 13:12:07 +0000 (15:12 +0200)
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  <jakub@redhat.com>

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)

gcc/predict.c
gcc/testsuite/c-c++-common/cold-2.c [new file with mode: 0644]

index a7ae977c866cd1927bda328882a4f060a043ff8c..b28474a0977a46fda486a6068fab113b3ee82b4e 100644 (file)
@@ -3941,7 +3941,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 (file)
index 0000000..7f78496
--- /dev/null
@@ -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);
+}