]> gcc.gnu.org Git - gcc.git/commitdiff
c++: class hotness attribute and member template
authorJason Merrill <jason@redhat.com>
Tue, 12 Dec 2023 19:41:39 +0000 (14:41 -0500)
committerJason Merrill <jason@redhat.com>
Tue, 12 Dec 2023 23:49:04 +0000 (18:49 -0500)
The FUNCTION_DECL check ignored member function templates.

gcc/cp/ChangeLog:

* class.cc (propagate_class_warmth_attribute): Handle
member templates.

gcc/testsuite/ChangeLog:

* g++.dg/ext/attr-hotness.C: Add member templates.

Co-authored-by: Jason Xu <rxu@DRWHoldings.com>
gcc/cp/class.cc
gcc/testsuite/g++.dg/ext/attr-hotness.C

index 6fdb56abfb9f8227f7abbd15f7376ac29e58025b..1954e0a5ed3f752f07c21cc1935a2dbf74689b7a 100644 (file)
@@ -7805,8 +7805,8 @@ propagate_class_warmth_attribute (tree t)
 
   if (class_has_cold_attr || class_has_hot_attr)
     for (tree f = TYPE_FIELDS (t); f; f = DECL_CHAIN (f))
-      if (TREE_CODE (f) == FUNCTION_DECL)
-       maybe_propagate_warmth_attributes (f, t);
+      if (DECL_DECLARES_FUNCTION_P (f))
+       maybe_propagate_warmth_attributes (STRIP_TEMPLATE (f), t);
 }
 
 tree
index f9a6930304dea10fb2c7958c7ee5182ff9ab9e14..24aa089ead305e9a4d8fbd47c2b01d5c360ffb10 100644 (file)
@@ -2,15 +2,23 @@
 /* { dg-options "-O0 -Wattributes -fdump-tree-gimple" } */
 
 
-struct __attribute((cold)) A { __attribute((noinline, used)) void foo(void) { } };
-
-struct __attribute((hot)) B { __attribute((noinline, used)) void foo(void) { } };
+struct __attribute((cold)) A {
+  __attribute((noinline, used)) void foo(void) { }
+  template <class T> void bar() {}
+};
+template void A::bar<int>();
+
+struct __attribute((hot)) B {
+  __attribute((noinline, used)) void foo(void) { }
+  template <class T> void bar() {}
+};
+template void B::bar<int>();
 
 struct __attribute((hot, cold)) C { __attribute((noinline, used)) void foo(void) { } }; /* { dg-warning "ignoring attribute .cold. because it conflicts with attribute .hot." } */
 
 struct __attribute((cold, hot)) D { __attribute((noinline, used)) void foo(void) { } }; /* { dg-warning "ignoring attribute .hot. because it conflicts with attribute .cold." } */
 
 
-/* { dg-final { scan-tree-dump-times "cold" 2 "gimple" } } */
-/* { dg-final { scan-tree-dump-times "hot" 2 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "cold" 3 "gimple" } } */
+/* { dg-final { scan-tree-dump-times "hot" 3 "gimple" } } */
 
This page took 0.076266 seconds and 5 git commands to generate.