]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/78089 (__builtin_shuffle parsing bug)
authorJakub Jelinek <jakub@redhat.com>
Tue, 30 May 2017 07:37:39 +0000 (09:37 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 30 May 2017 07:37:39 +0000 (09:37 +0200)
Backported from mainline
2016-10-31  Jakub Jelinek  <jakub@redhat.com>

PR c++/78089
* parser.c (cp_parser_postfix_expression): Replace return statement in
the first switch with setting postfix_expression to the return
expression and break;.

* c-c++-common/builtin-shuffle-1.c: New test.

From-SVN: r248620

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/builtin-shuffle-1.c [new file with mode: 0644]

index 857a2a5008409af537a6a9d93e4d081d89379aeb..223b029bf9e4ee26d33b636cc372b84940565125 100644 (file)
@@ -1,6 +1,13 @@
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-10-31  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/78089
+       * parser.c (cp_parser_postfix_expression): Replace return statement in
+       the first switch with setting postfix_expression to the return
+       expression and break;.
+
        2016-09-28  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/77467
index 2cfcd79d05056e128543516a6f2090517ee6fc2f..0ff5cf1dc4b53bfc69c5f150c67a04f9703204b5 100644 (file)
@@ -5894,7 +5894,10 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
           can be used in constant-expressions.  */
        if (!cast_valid_in_integral_constant_expression_p (type)
            && cp_parser_non_integral_constant_expression (parser, NIC_CAST))
-         return error_mark_node;
+         {
+           postfix_expression = error_mark_node;
+           break;
+         }
 
        switch (keyword)
          {
@@ -5966,7 +5969,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
        parser->type_definition_forbidden_message = saved_message;
        /* `typeid' may not appear in an integral constant expression.  */
        if (cp_parser_non_integral_constant_expression (parser, NIC_TYPEID))
-         return error_mark_node;
+         postfix_expression = error_mark_node;
       }
       break;
 
@@ -6045,23 +6048,28 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
                    /*cast_p=*/false, /*allow_expansion_p=*/true,
                    /*non_constant_p=*/NULL);
        if (vec == NULL)
-         return error_mark_node;
+         {
+           postfix_expression = error_mark_node;
+           break;
+         }
 
        FOR_EACH_VEC_ELT (*vec, i, p)
          mark_exp_read (p);
 
        if (vec->length () == 2)
-         return build_x_vec_perm_expr (loc, (*vec)[0], NULL_TREE, (*vec)[1],
-                                        tf_warning_or_error);
+         postfix_expression
+           = build_x_vec_perm_expr (loc, (*vec)[0], NULL_TREE, (*vec)[1],
+                                    tf_warning_or_error);
        else if (vec->length () == 3)
-         return build_x_vec_perm_expr (loc, (*vec)[0], (*vec)[1], (*vec)[2],
-                                        tf_warning_or_error);
+         postfix_expression
+           = build_x_vec_perm_expr (loc, (*vec)[0], (*vec)[1], (*vec)[2],
+                                    tf_warning_or_error);
        else
-       {
-         error_at (loc, "wrong number of arguments to "
-             "%<__builtin_shuffle%>");
-         return error_mark_node;
-       }
+         {
+           error_at (loc, "wrong number of arguments to "
+                          "%<__builtin_shuffle%>");
+           postfix_expression = error_mark_node;
+         }
        break;
       }
 
index 875d4f6913d39bbaacbfe87155ad623e616963d1..9dd5bc29cd097f5a0fbbbaebfb8edacfd8e98119 100644 (file)
@@ -1,6 +1,11 @@
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-10-31  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/78089
+       * c-c++-common/builtin-shuffle-1.c: New test.
+
        2016-10-29  Jakub Jelinek  <jakub@redhat.com>
 
        PR rtl-optimization/77919
diff --git a/gcc/testsuite/c-c++-common/builtin-shuffle-1.c b/gcc/testsuite/c-c++-common/builtin-shuffle-1.c
new file mode 100644 (file)
index 0000000..30fd690
--- /dev/null
@@ -0,0 +1,22 @@
+/* PR c++/78089 */
+/* { dg-do run } */
+
+typedef int V __attribute__((vector_size (16)));
+V a, b, c;
+
+int
+foo ()
+{
+  return __builtin_shuffle (a, b, c)[3];
+}
+
+int
+main ()
+{
+  a = (V) { 1, 2, 3, 4 };
+  b = (V) { 5, 6, 7, 8 };
+  c = (V) { 7, 2, 5, 6 };
+  if (foo () != 7)
+    __builtin_abort ();
+  return 0;
+}