public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Marek Polacek <polacek@redhat.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>, Jason Merrill <jason@redhat.com>
Subject: C++ PATCH for c++/90265 - ICE with generic lambda
Date: Mon, 06 May 2019 16:32:00 -0000	[thread overview]
Message-ID: <20190506163206.GF4334@redhat.com> (raw)

This new code

  vec_safe_push (call_args, (*call_args)[nargs-1]);

doesn't seem to work well because "obj" points to garbage after the vec_safe_reserve
call:

template<typename T, typename A>
inline T *
vec_safe_push (vec<T, A, vl_embed> *&v, const T &obj CXX_MEM_STAT_INFO)
{
  vec_safe_reserve (v, 1, false PASS_MEM_STAT);
  return v->quick_push (obj);
}

But using a dedicated variable works even when vec_safe_reserve actually
extends.

Bootstrapped/regtested on x86_64-linux, ok for trunk/9?

2019-05-06  Marek Polacek  <polacek@redhat.com>

	PR c++/90265 - ICE with generic lambda.
	* pt.c (tsubst_copy_and_build): Use a dedicated variable for the last
	element in the vector.

	* g++.dg/cpp1y/lambda-generic-90265.C: New test.

diff --git gcc/cp/pt.c gcc/cp/pt.c
index 3e8c70b0d15..2f2066e297c 100644
--- gcc/cp/pt.c
+++ gcc/cp/pt.c
@@ -18881,7 +18881,8 @@ tsubst_copy_and_build (tree t,
 	    if (thisarg)
 	      {
 		/* Shift the other args over to make room.  */
-		vec_safe_push (call_args, (*call_args)[nargs-1]);
+		tree last = (*call_args)[nargs - 1];
+		vec_safe_push (call_args, last);
 		for (int i = nargs-1; i > 0; --i)
 		  (*call_args)[i] = (*call_args)[i-1];
 		(*call_args)[0] = thisarg;
diff --git gcc/testsuite/g++.dg/cpp1y/lambda-generic-90265.C gcc/testsuite/g++.dg/cpp1y/lambda-generic-90265.C
new file mode 100644
index 00000000000..d9ab9b7f55f
--- /dev/null
+++ gcc/testsuite/g++.dg/cpp1y/lambda-generic-90265.C
@@ -0,0 +1,4 @@
+// PR c++/90265
+// { dg-do compile { target c++14 } }
+
+void (*a)(int, int, int, void *) = [](auto, auto, auto, auto) {};

             reply	other threads:[~2019-05-06 16:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-06 16:32 Marek Polacek [this message]
2019-05-06 16:46 ` 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=20190506163206.GF4334@redhat.com \
    --to=polacek@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --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).