]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: pragma target and static init [PR109753]
authorJason Merrill <jason@redhat.com>
Wed, 14 Feb 2024 22:18:17 +0000 (17:18 -0500)
committerJason Merrill <jason@redhat.com>
Wed, 29 May 2024 13:51:40 +0000 (09:51 -0400)
 #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.

gcc/c-family/c-attribs.cc
gcc/cp/decl.cc
gcc/testsuite/g++.dg/opt/always_inline1.C [new file with mode: 0644]

index 04e39b41bdf30a6539112da6e85cd059436f2a0e..605469dd7dd42c0be5f77a257eb8f223751d44c5 100644 (file)
@@ -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);
index a992d54dc8f0a14ce2b8c8b3b07b93e3a6076f19..d481e1ec074bc94bb7d2e8d3d6e0ee4b620dd051 100644 (file)
@@ -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 (file)
index 0000000..a042a1c
--- /dev/null
@@ -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;