]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR ipa/93087 (Bogus `-Wsuggest-attribute=cold` on function already marked as ...
authorJakub Jelinek <jakub@redhat.com>
Wed, 22 Jan 2020 16:48:05 +0000 (17:48 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 22 Jan 2020 19:12:55 +0000 (20:12 +0100)
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.

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

index d31312299a89c724c6d33570065a9af05c1e66cc..d95b6af657319a2dcf56f87f42fa0e91e1d6bb76 100644 (file)
@@ -1,3 +1,12 @@
+2020-01-22  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2020-01-02  Jakub Jelinek  <jakub@redhat.com>
+
+       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  <rguenther@suse.de>
 
        Backport from mainline
index 60a19d7edd12f9e67025ea3c699f98323e1f0034..eaab47f992aea18a045be3fe97fa8f9ab589dbfc 100644 (file)
@@ -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))
index c306cf6c296ddb6a12400bc165c15d32e51d699f..cd4f7f4448489514a237bcabf07ef99cb0964046 100644 (file)
@@ -1,3 +1,11 @@
+2020-01-22  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2020-01-02  Jakub Jelinek  <jakub@redhat.com>
+
+       PR ipa/93087
+       * c-c++-common/cold-1.c: New test.
+
 2020-01-22  Jakub Jelinek  <jakub@redhat.com>
 
        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 (file)
index 0000000..3493623
--- /dev/null
@@ -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;
+}