c++: Fix warmth propagation for member function templates

Message ID a6a844a01ebf4b6bb72efbc5f1c3e919@DRWHoldings.com
State Not Applicable
Headers
Series c++: Fix warmth propagation for member function templates |

Checks

Context Check Description
snail/gcc-patch-check fail Git am fail log

Commit Message

Jason Xu Dec. 12, 2023, 7:29 p.m. UTC
  Support was recently added for class-level warmth attributes that are
propagated to member functions. The current implementation ignores
member function templates and this patch fixes that.

gcc/cp/ChangeLog:

        * class.cc (propagate_class_warmth_attribute): fix warmth
          propagation for member function templates
---
 gcc/cp/class.cc | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

--
2.40.0
This e-mail and any attachments may contain information that is confidential and proprietary and otherwise protected from disclosure. If you are not the intended recipient of this e-mail, do not read, duplicate or redistribute it by any means. Please immediately delete it and any attachments and notify the sender that you have received it by mistake. Unintended recipients are prohibited from taking action on the basis of information in this e-mail or any attachments. The DRW Companies make no representations that this e-mail or any attachments are free of computer viruses or other defects.
  

Comments

Marek Polacek Dec. 12, 2023, 7:45 p.m. UTC | #1
On Tue, Dec 12, 2023 at 07:29:40PM +0000, Jason Xu wrote:
> Support was recently added for class-level warmth attributes that are
> propagated to member functions. The current implementation ignores
> member function templates and this patch fixes that.

Thanks for the patch.  Is there a bug in the Bugzilla for this?
 
> gcc/cp/ChangeLog:
> 
>         * class.cc (propagate_class_warmth_attribute): fix warmth
>           propagation for member function templates

Nit, but s/fix/Fix/, and add a full stop at the end.

> ---
>  gcc/cp/class.cc | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc
> index 6fdb56abfb9..68e0f2e9e13 100644
> --- a/gcc/cp/class.cc
> +++ b/gcc/cp/class.cc
> @@ -7805,8 +7805,13 @@ 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);
> +      {
> +tree real_f = f;
> +if (TREE_CODE (f) == TEMPLATE_DECL)
> +  real_f = DECL_TEMPLATE_RESULT (f);
> +if (TREE_CODE (real_f) == FUNCTION_DECL)
> +  maybe_propagate_warmth_attributes (real_f, t);
> +      }

Don't you want just:

--- a/gcc/cp/class.cc
+++ b/gcc/cp/class.cc
@@ -7805,7 +7805,7 @@ 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)
+      if (TREE_CODE (STRIP_TEMPLATE (f)) == FUNCTION_DECL)
    maybe_propagate_warmth_attributes (f, t);
 }


Also, can you add a test for this?

Marek
  
Jason Merrill Dec. 12, 2023, 11:48 p.m. UTC | #2
On 12/12/23 14:29, Jason Xu wrote:
> Support was recently added for class-level warmth attributes that are
> propagated to member functions. The current implementation ignores
> member function templates and this patch fixes that.

Thanks!  I'm applying this variant of the patch:
  

Patch

diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc
index 6fdb56abfb9..68e0f2e9e13 100644
--- a/gcc/cp/class.cc
+++ b/gcc/cp/class.cc
@@ -7805,8 +7805,13 @@  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);
+      {
+tree real_f = f;
+if (TREE_CODE (f) == TEMPLATE_DECL)
+  real_f = DECL_TEMPLATE_RESULT (f);
+if (TREE_CODE (real_f) == FUNCTION_DECL)
+  maybe_propagate_warmth_attributes (real_f, t);
+      }
 }

 tree