diff options
author | Jason Merrill <jason@redhat.com> | 2024-02-14 17:18:17 -0500 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2024-05-29 09:51:40 -0400 |
commit | eff00046409a7289bfdc1861e68b532895f91c0e (patch) | |
tree | 9d5484d42bfc3c309f7f0ff94c33dc8abcbd1c7c /gcc | |
parent | 3ae02dcb108df426838bbbcc73d7d01855bc1196 (diff) | |
download | gcc-eff00046409a7289bfdc1861e68b532895f91c0e.zip gcc-eff00046409a7289bfdc1861e68b532895f91c0e.tar.gz gcc-eff00046409a7289bfdc1861e68b532895f91c0e.tar.bz2 |
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c-family/c-attribs.cc | 4 | ||||
-rw-r--r-- | gcc/cp/decl.cc | 3 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/opt/always_inline1.C | 8 |
3 files changed, 15 insertions, 0 deletions
diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 04e39b4..605469d 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 a992d54..d481e1e 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 0000000..a042a1c --- /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; |