From 7b67119fd03ebf1a3961377ac5d4e94e9b5d565b Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 30 May 2017 09:37:39 +0200 Subject: [PATCH] backport: re PR c++/78089 (__builtin_shuffle parsing bug) Backported from mainline 2016-10-31 Jakub Jelinek 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 | 7 ++++ gcc/cp/parser.c | 32 ++++++++++++------- gcc/testsuite/ChangeLog | 5 +++ .../c-c++-common/builtin-shuffle-1.c | 22 +++++++++++++ 4 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/builtin-shuffle-1.c diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 857a2a500840..223b029bf9e4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,6 +1,13 @@ 2017-05-30 Jakub Jelinek Backported from mainline + 2016-10-31 Jakub Jelinek + + 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 PR c++/77467 diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 2cfcd79d0505..0ff5cf1dc4b5 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 875d4f6913d3..9dd5bc29cd09 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,11 @@ 2017-05-30 Jakub Jelinek Backported from mainline + 2016-10-31 Jakub Jelinek + + PR c++/78089 + * c-c++-common/builtin-shuffle-1.c: New test. + 2016-10-29 Jakub Jelinek 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 index 000000000000..30fd69082dd9 --- /dev/null +++ b/gcc/testsuite/c-c++-common/builtin-shuffle-1.c @@ -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; +} -- 2.47.2