public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Cc: jason@redhat.com, Jakub Jelinek <jakub@redhat.com>
Subject: [PATCH] c++/114409 - ANNOTATE_EXPR and templates
Date: Wed, 10 Apr 2024 18:43:02 +0200 (CEST)	[thread overview]
Message-ID: <20240410164306.EFDB113942@imap1.dmz-prg2.suse.org> (raw)

The following fixes a mismatch in COMPOUND_EXPR handling in
tsubst_expr vs tsubst_stmt where the latter allows a stmt in
operand zero but the former doesn't.  This makes a difference
for the case at hand because when the COMPOUND_EXPR is wrapped
inside an ANNOTATE_EXPR it gets handled by tsubst_expr and when
not, tsubst_stmt successfully handles it and the contained
DECL_EXPR in operand zero.

The following makes handling of COMPOUND_EXPR in tsubst_expr
consistent with that of tsubst_stmt for the operand that doesn't
specify the result and thus the reason we choose either or the
other for substing.

Bootstrapped and tested on x86_64-unknown-linux-gnu, OK?

Thanks,
Richard.

	PR c++/114409
gcc/cp/
	* pt.cc (tsubst_expr): Recurse to COMPOUND_EXPR operand
	zero using tsubst_stmt, when that returns NULL return
	the subst operand one, mimicing what tsubst_stmt does.

gcc/testsuite/
	* g++.dg/pr114409.C: New testcase.
---
 gcc/cp/pt.cc                    | 5 ++++-
 gcc/testsuite/g++.dg/pr114409.C | 8 ++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/pr114409.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index bf4b89d8413..dae423a751f 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -20635,8 +20635,11 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
 
     case COMPOUND_EXPR:
       {
-	tree op0 = tsubst_expr (TREE_OPERAND (t, 0), args,
+	tree op0 = tsubst_stmt (TREE_OPERAND (t, 0), args,
 				complain & ~tf_decltype, in_decl);
+	if (op0 == NULL_TREE)
+	  /* If the first operand was a statement, we're done with it.  */
+	  RETURN (RECUR (TREE_OPERAND (t, 1)));
 	RETURN (build_x_compound_expr (EXPR_LOCATION (t),
 				       op0,
 				       RECUR (TREE_OPERAND (t, 1)),
diff --git a/gcc/testsuite/g++.dg/pr114409.C b/gcc/testsuite/g++.dg/pr114409.C
new file mode 100644
index 00000000000..6343fe8d9f3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pr114409.C
@@ -0,0 +1,8 @@
+// { dg-do compile }
+
+template <int> int t() {
+#pragma GCC unroll 4
+    while (int ThisEntry = 0) { } // { dg-bogus "ignoring loop annotation" "" { xfail *-*-* } }
+    return 0;
+}
+int tt = t<1>();
-- 
2.35.3

             reply	other threads:[~2024-04-10 16:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-10 16:43 Richard Biener [this message]
2024-04-10 16:50 ` Jakub Jelinek
2024-04-10 17:10   ` Richard Biener
2024-04-10 17:24     ` Jakub Jelinek
2024-04-10 17:25     ` Jason Merrill

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=20240410164306.EFDB113942@imap1.dmz-prg2.suse.org \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jason@redhat.com \
    /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).