https://gcc.gnu.org/g:eff00046409a7289bfdc1861e68b532895f91c0e

commit r15-902-geff00046409a7289bfdc1861e68b532895f91c0e
Author: Jason Merrill <ja...@redhat.com>
Date:   Wed Feb 14 17:18:17 2024 -0500

    c++: pragma target and static init [PR109753]
    
     #pragma target and optimize should also apply to implicitly-generated
     functions like static initialization functions and defaulted special member
     functions.
    
    The handle_optimize_attribute change is necessary to avoid regressing
    g++.dg/opt/pr105306.C; maybe_clone_body creates a cgraph_node for the ~B
    alias before handle_optimize_attribute, and the alias never goes through
    finalize_function, so we need to adjust semantic_interposition somewhere
    else.
    
            PR c++/109753
    
    gcc/c-family/ChangeLog:
    
            * c-attribs.cc (handle_optimize_attribute): Set
            cgraph_node::semantic_interposition.
    
    gcc/cp/ChangeLog:
    
            * decl.cc (start_preparsed_function): Call decl_attributes.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/opt/always_inline1.C: New test.

Diff:
---
 gcc/c-family/c-attribs.cc                 | 4 ++++
 gcc/cp/decl.cc                            | 3 +++
 gcc/testsuite/g++.dg/opt/always_inline1.C | 8 ++++++++
 3 files changed, 15 insertions(+)

diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index 04e39b41bdf..605469dd7dd 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -5971,6 +5971,10 @@ handle_optimize_attribute (tree *node, tree name, tree 
args,
       if (prev_target_node != target_node)
        DECL_FUNCTION_SPECIFIC_TARGET (*node) = target_node;
 
+      /* Also update the cgraph_node, if it's already built.  */
+      if (cgraph_node *cn = cgraph_node::get (*node))
+       cn->semantic_interposition = flag_semantic_interposition;
+
       /* Restore current options.  */
       cl_optimization_restore (&global_options, &global_options_set,
                               &cur_opts);
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index a992d54dc8f..d481e1ec074 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -17832,6 +17832,9 @@ start_preparsed_function (tree decl1, tree attrs, int 
flags)
        doing_friend = true;
     }
 
+  /* Adjust for #pragma target/optimize.  */
+  decl_attributes (&decl1, NULL_TREE, 0);
+
   if (DECL_DECLARED_INLINE_P (decl1)
       && lookup_attribute ("noinline", attrs))
     warning_at (DECL_SOURCE_LOCATION (decl1), 0,
diff --git a/gcc/testsuite/g++.dg/opt/always_inline1.C 
b/gcc/testsuite/g++.dg/opt/always_inline1.C
new file mode 100644
index 00000000000..a042a1cf0c6
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/always_inline1.C
@@ -0,0 +1,8 @@
+// PR c++/109753
+// { dg-do compile { target x86_64-*-* } }
+
+#pragma GCC target("avx2")
+struct aa {
+    __attribute__((__always_inline__)) aa() {}
+};
+aa _M_impl;

Reply via email to