From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 5ADD03858C74; Sat, 26 Mar 2022 07:12:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5ADD03858C74 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-7823] c++: Fix up __builtin_{bit_cast, convertvector} parsing X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: 75d1c8fea9541dee5a4ce0aa7d8c199574fd42b9 X-Git-Newrev: 1806829e08f14e4cacacec43d7845cc2dad2ddc8 Message-Id: <20220326071238.5ADD03858C74@sourceware.org> Date: Sat, 26 Mar 2022 07:12:38 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 Mar 2022 07:12:38 -0000 https://gcc.gnu.org/g:1806829e08f14e4cacacec43d7845cc2dad2ddc8 commit r12-7823-g1806829e08f14e4cacacec43d7845cc2dad2ddc8 Author: Jakub Jelinek Date: Sat Mar 26 08:11:58 2022 +0100 c++: Fix up __builtin_{bit_cast,convertvector} parsing 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 * parser.cc (cp_parser_postfix_expression) : Don't return cp_build_{vec,convert,bit_cast} result right away, instead set postfix_expression to it and break. * c-c++-common/builtin-convertvector-3.c: New test. * g++.dg/cpp2a/bit-cast15.C: New test. Diff: --- gcc/cp/parser.cc | 12 ++++++++---- gcc/testsuite/c-c++-common/builtin-convertvector-3.c | 11 +++++++++++ gcc/testsuite/g++.dg/cpp2a/bit-cast15.C | 19 +++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 15ad6400730..d3c22ee6227 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -7525,8 +7525,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; } case RID_BUILTIN_BIT_CAST: @@ -7551,8 +7553,10 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p, expression = cp_parser_assignment_expression (parser); /* Look for the closing `)'. */ parens.require_close (parser); - return cp_build_bit_cast (type_location, type, expression, - tf_warning_or_error); + postfix_expression + = cp_build_bit_cast (type_location, type, expression, + 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 index 00000000000..882cd551ef8 --- /dev/null +++ b/gcc/testsuite/c-c++-common/builtin-convertvector-3.c @@ -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]; +} diff --git a/gcc/testsuite/g++.dg/cpp2a/bit-cast15.C b/gcc/testsuite/g++.dg/cpp2a/bit-cast15.C new file mode 100644 index 00000000000..5326af0503d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/bit-cast15.C @@ -0,0 +1,19 @@ +// { dg-do compile } + +struct S { short a, b; }; +struct T { float a[4]; }; +struct U { int b[4]; }; + +#if __SIZEOF_FLOAT__ == __SIZEOF_INT__ +int +f1 (T &x) +{ + return __builtin_bit_cast (U, x).b[1]; +} + +float +f2 (int (&x)[4]) +{ + return __builtin_bit_cast (T, x).a[2]; +} +#endif