aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2023-12-12 14:41:39 -0500
committerJason Merrill <jason@redhat.com>2023-12-12 18:49:04 -0500
commitb75683039960a621a0d7dd7c42eea32b7d2eff4d (patch)
tree9f080ab0c724aa656fc193d8aed0b07fcc4f7d35 /gcc
parent8501edba91ea63bdfc045f1cb66fb1c242e44e80 (diff)
downloadgcc-b75683039960a621a0d7dd7c42eea32b7d2eff4d.zip
gcc-b75683039960a621a0d7dd7c42eea32b7d2eff4d.tar.gz
gcc-b75683039960a621a0d7dd7c42eea32b7d2eff4d.tar.bz2
c++: class hotness attribute and member template
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>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/class.cc4
-rw-r--r--gcc/testsuite/g++.dg/ext/attr-hotness.C18
2 files changed, 15 insertions, 7 deletions
diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc
index 6fdb56a..1954e0a 100644
--- a/gcc/cp/class.cc
+++ b/gcc/cp/class.cc
@@ -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
diff --git a/gcc/testsuite/g++.dg/ext/attr-hotness.C b/gcc/testsuite/g++.dg/ext/attr-hotness.C
index f9a6930..24aa089 100644
--- a/gcc/testsuite/g++.dg/ext/attr-hotness.C
+++ b/gcc/testsuite/g++.dg/ext/attr-hotness.C
@@ -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" } } */