public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] c++: ICE casting class to vector [PR100517]
@ 2021-05-11 14:20 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-05-11 14:20 UTC (permalink / raw)
  To: gcc-patches

My recent change to reject calling rvalue() with an argument of class type
crashes on this testcase, where we use rvalue() on what we expect to be an
argument of integer or vector type.  Fixed by checking first.

Tested x86_64-pc-linux-gnu, applying to trunk.

gcc/cp/ChangeLog:

	PR c++/100517
	* typeck.c (build_reinterpret_cast_1): Check intype on
	cast to vector.

gcc/testsuite/ChangeLog:

	PR c++/100517
	* g++.dg/ext/vector41.C: New test.
---
 gcc/cp/typeck.c                     |  2 +-
 gcc/testsuite/g++.dg/ext/vector41.C | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/ext/vector41.C

diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 9002dd14fae..703ddd3cc7a 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -8114,7 +8114,7 @@ build_reinterpret_cast_1 (location_t loc, tree type, tree expr,
 		    "pointer-to-object is conditionally-supported");
       return build_nop_reinterpret (type, expr);
     }
-  else if (gnu_vector_type_p (type))
+  else if (gnu_vector_type_p (type) && scalarish_type_p (intype))
     return convert_to_vector (type, rvalue (expr));
   else if (gnu_vector_type_p (intype)
 	   && INTEGRAL_OR_ENUMERATION_TYPE_P (type))
diff --git a/gcc/testsuite/g++.dg/ext/vector41.C b/gcc/testsuite/g++.dg/ext/vector41.C
new file mode 100644
index 00000000000..bfc3bb6db4b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/vector41.C
@@ -0,0 +1,12 @@
+// PR c++/100517
+// { dg-options "" }
+
+typedef int __v2si __attribute__ ((__vector_size__ (8)));
+
+struct S { };
+
+void
+f (S s)
+{
+  (void) reinterpret_cast<__v2si> (s); // { dg-error "" }
+}

base-commit: 2301a394607b88f8996efe864350c5f841000f76
-- 
2.27.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-11 14:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-11 14:20 [pushed] c++: ICE casting class to vector [PR100517] Jason Merrill

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).