]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix up __builtin_convertvector parsing
authorJakub Jelinek <jakub@redhat.com>
Sat, 26 Mar 2022 07:11:58 +0000 (08:11 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 10 May 2022 08:14:35 +0000 (10:14 +0200)
Jonathan reported on IRC that we don't parse
__builtin_bit_cast (type, val).field
etc.
The problem is that for these 2 builtins we return from
cp_parser_postfix_expression instead of setting postfix_expression
to the cp_build_* value and falling through into the postfix regression
suffix handling loop.

2022-03-26  Jakub Jelinek  <jakub@redhat.com>

* parser.c (cp_parser_postfix_expression)
<case RID_BILTIN_CONVERTVECTOR>: Don't
return cp_build_vec_convert result right away, instead
set postfix_expression to it and break.

* c-c++-common/builtin-convertvector-3.c: New test.

(cherry picked from commit 1806829e08f14e4cacacec43d7845cc2dad2ddc8)

gcc/cp/parser.c
gcc/testsuite/c-c++-common/builtin-convertvector-3.c [new file with mode: 0644]

index f48c856fa943fb0e65ba276ae34ae38a8567434d..61f2af3468899e746024804dc891959a0091334f 100644 (file)
@@ -7162,8 +7162,10 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
        }
        /* Look for the closing `)'.  */
        parens.require_close (parser);
-       return cp_build_vec_convert (expression, type_location, type,
-                                    tf_warning_or_error);
+       postfix_expression
+         = cp_build_vec_convert (expression, type_location, type,
+                                 tf_warning_or_error);
+       break;
       }
 
     default:
diff --git a/gcc/testsuite/c-c++-common/builtin-convertvector-3.c b/gcc/testsuite/c-c++-common/builtin-convertvector-3.c
new file mode 100644 (file)
index 0000000..882cd55
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+typedef int v4si __attribute__((vector_size (4 * sizeof (int))));
+typedef double v4df __attribute__((vector_size (4 * sizeof (double))));
+double
+foo (void)
+{
+  v4si a = { 1, 2, 3, 4 };
+  return __builtin_convertvector (a, v4df)[1];
+}