* [pushed] c++: #pragma target and deferred instantiation [PR115403]
@ 2024-07-25 23:54 Jason Merrill
2024-07-26 17:56 ` Patrick Palka
0 siblings, 1 reply; 2+ messages in thread
From: Jason Merrill @ 2024-07-25 23:54 UTC (permalink / raw)
To: gcc-patches
Tested x86_64-pc-linux-gnu, applying to trunk.
Also built highway to check.
-- 8< --
My patch for 109753 applies the current #pragma target/optimize to a
function when we compile it, which was a problem for a template
instantiation deferred until EOF, where different #pragmas are active. So
let's only do this for artificial functions.
PR c++/115403
PR c++/109753
gcc/cp/ChangeLog:
* decl.cc (start_preparsed_function): Only call decl_attributes for
artificial functions.
gcc/testsuite/ChangeLog:
* g++.dg/ext/pragma-target1.C: New test.
---
gcc/cp/decl.cc | 7 +++++--
gcc/testsuite/g++.dg/ext/pragma-target1.C | 6 ++++++
2 files changed, 11 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/ext/pragma-target1.C
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 6b686d75a49..279af21eed0 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -17882,8 +17882,11 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
doing_friend = true;
}
- /* Adjust for #pragma target/optimize. */
- decl_attributes (&decl1, NULL_TREE, 0);
+ /* Adjust for #pragma target/optimize if this is an artificial function that
+ (probably) didn't go through grokfndecl. We particularly don't want this
+ for deferred instantiations, which should match their template. */
+ if (DECL_ARTIFICIAL (decl1))
+ decl_attributes (&decl1, NULL_TREE, 0);
if (DECL_DECLARED_INLINE_P (decl1)
&& lookup_attribute ("noinline", attrs))
diff --git a/gcc/testsuite/g++.dg/ext/pragma-target1.C b/gcc/testsuite/g++.dg/ext/pragma-target1.C
new file mode 100644
index 00000000000..0ce2438da2f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/pragma-target1.C
@@ -0,0 +1,6 @@
+// PR c++/115403
+// { dg-do compile { target x86_64-*-* } }
+
+template <typename> __attribute__((always_inline)) inline void AssertEqual() {}
+void TestAllF16FromF32() { AssertEqual<float>(); }
+#pragma GCC target "sse4.1"
base-commit: 29341f21ce1eb7cdb8cd468e4ceb0d07cf2775e0
--
2.45.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [pushed] c++: #pragma target and deferred instantiation [PR115403]
2024-07-25 23:54 [pushed] c++: #pragma target and deferred instantiation [PR115403] Jason Merrill
@ 2024-07-26 17:56 ` Patrick Palka
0 siblings, 0 replies; 2+ messages in thread
From: Patrick Palka @ 2024-07-26 17:56 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
On Thu, 25 Jul 2024, Jason Merrill wrote:
> Tested x86_64-pc-linux-gnu, applying to trunk.
>
> Also built highway to check.
>
> -- 8< --
>
> My patch for 109753 applies the current #pragma target/optimize to a
> function when we compile it, which was a problem for a template
> instantiation deferred until EOF, where different #pragmas are active. So
> let's only do this for artificial functions.
>
> PR c++/115403
> PR c++/109753
>
> gcc/cp/ChangeLog:
>
> * decl.cc (start_preparsed_function): Only call decl_attributes for
> artificial functions.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/ext/pragma-target1.C: New test.
> ---
> gcc/cp/decl.cc | 7 +++++--
> gcc/testsuite/g++.dg/ext/pragma-target1.C | 6 ++++++
> 2 files changed, 11 insertions(+), 2 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/ext/pragma-target1.C
>
> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
> index 6b686d75a49..279af21eed0 100644
> --- a/gcc/cp/decl.cc
> +++ b/gcc/cp/decl.cc
> @@ -17882,8 +17882,11 @@ start_preparsed_function (tree decl1, tree attrs, int flags)
> doing_friend = true;
> }
>
> - /* Adjust for #pragma target/optimize. */
> - decl_attributes (&decl1, NULL_TREE, 0);
> + /* Adjust for #pragma target/optimize if this is an artificial function that
> + (probably) didn't go through grokfndecl. We particularly don't want this
> + for deferred instantiations, which should match their template. */
> + if (DECL_ARTIFICIAL (decl1))
> + decl_attributes (&decl1, NULL_TREE, 0);
Couldn't an artificial function get synthesized at EOF if e.g. it's
needed by a deferred instantiation? In that case we'll still call
decl_attributes on it which will inherit the last active #pragma,
which seems unintended. Maybe we should clear #pragma before
processing deferred instantiations?
>
> if (DECL_DECLARED_INLINE_P (decl1)
> && lookup_attribute ("noinline", attrs))
> diff --git a/gcc/testsuite/g++.dg/ext/pragma-target1.C b/gcc/testsuite/g++.dg/ext/pragma-target1.C
> new file mode 100644
> index 00000000000..0ce2438da2f
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/ext/pragma-target1.C
> @@ -0,0 +1,6 @@
> +// PR c++/115403
> +// { dg-do compile { target x86_64-*-* } }
> +
> +template <typename> __attribute__((always_inline)) inline void AssertEqual() {}
> +void TestAllF16FromF32() { AssertEqual<float>(); }
> +#pragma GCC target "sse4.1"
>
> base-commit: 29341f21ce1eb7cdb8cd468e4ceb0d07cf2775e0
> --
> 2.45.2
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-07-26 17:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-25 23:54 [pushed] c++: #pragma target and deferred instantiation [PR115403] Jason Merrill
2024-07-26 17:56 ` Patrick Palka
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).