c++: ICE casting class to vector [PR100517]
authorJason Merrill <jason@redhat.com>
Tue, 11 May 2021 13:53:20 +0000 (09:53 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 11 May 2021 14:20:46 +0000 (10:20 -0400)
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.

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
gcc/testsuite/g++.dg/ext/vector41.C [new file with mode: 0644]

index 9002dd1..703ddd3 100644 (file)
@@ -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 (file)
index 0000000..bfc3bb6
--- /dev/null
@@ -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 "" }
+}