public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] pragma: respect pragma in lambda functions
Date: Thu, 16 Dec 2021 12:07:31 +0100	[thread overview]
Message-ID: <9cedfef0-dd5f-7dbd-e7fb-cb64e427dd30@suse.cz> (raw)

In g:01ad8c54fdca we started supporting target pragma changes
that are primarily caused by optimization option. The same can happen
in the opposite way and we need to check for changes both
in optimization_current_node and target_option_current_node.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

	PR c++/103696

gcc/ChangeLog:

	* attribs.c (decl_attributes): Check if
	target_option_current_node is changed.

gcc/testsuite/ChangeLog:

	* g++.target/i386/pr103696.C: New test.
---
  gcc/attribs.c                            |  3 ++-
  gcc/testsuite/g++.target/i386/pr103696.C | 25 ++++++++++++++++++++++++
  2 files changed, 27 insertions(+), 1 deletion(-)
  create mode 100644 gcc/testsuite/g++.target/i386/pr103696.C

diff --git a/gcc/attribs.c b/gcc/attribs.c
index 01a9ed66485..29703e75fba 100644
--- a/gcc/attribs.c
+++ b/gcc/attribs.c
@@ -605,7 +605,8 @@ decl_attributes (tree *node, tree attributes, int flags,
      }
  
    if (TREE_CODE (*node) == FUNCTION_DECL
-      && optimization_current_node != optimization_default_node
+      && (optimization_current_node != optimization_default_node
+	  || target_option_current_node != target_option_default_node)
        && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node))
      {
        DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node) = optimization_current_node;
diff --git a/gcc/testsuite/g++.target/i386/pr103696.C b/gcc/testsuite/g++.target/i386/pr103696.C
new file mode 100644
index 00000000000..de7d5c68be9
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/pr103696.C
@@ -0,0 +1,25 @@
+// PR c++/103696
+// { dg-options "-O2 -std=c++14 -fdump-tree-optimized" }
+
+int global_var;
+
+void fn() {
+}
+
+#pragma GCC optimize("finite-math-only")
+#pragma GCC target("sse3")
+
+void fn2() {
+}
+
+void fn3() {
+}
+
+int solve() {
+    auto nested = []() {
+        return global_var;
+    };
+    return nested();
+}
+
+/* { dg-final { scan-tree-dump-not "lambda" "optimized" } } */
-- 
2.34.1


             reply	other threads:[~2021-12-16 11:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-16 11:07 Martin Liška [this message]
2021-12-16 16:43 ` Jeff Law

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9cedfef0-dd5f-7dbd-e7fb-cb64e427dd30@suse.cz \
    --to=mliska@suse.cz \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).