From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 493283861C74 for ; Fri, 25 Mar 2022 15:58:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 493283861C74 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-63-6EhCgx52OYO96zlSLponLw-1; Fri, 25 Mar 2022 11:58:38 -0400 X-MC-Unique: 6EhCgx52OYO96zlSLponLw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 12F711044562 for ; Fri, 25 Mar 2022 15:58:38 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C44E72026D4C; Fri, 25 Mar 2022 15:58:37 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 22PFwZ811800231 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 25 Mar 2022 16:58:35 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 22PFwZTf1800230; Fri, 25 Mar 2022 16:58:35 +0100 Date: Fri, 25 Mar 2022 16:58:34 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix up __builtin_{bit_cast,convertvector} parsing Message-ID: Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Mar 2022 15:58:48 -0000 Hi! 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. Ok for trunk if it passes bootstrap/regtest? 2022-03-25 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. --- gcc/cp/parser.cc.jj 2022-03-15 09:15:21.366108714 +0100 +++ gcc/cp/parser.cc 2022-03-25 16:04:21.464248103 +0100 @@ -7525,8 +7525,10 @@ cp_parser_postfix_expression (cp_parser } /* 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 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: --- gcc/testsuite/c-c++-common/builtin-convertvector-3.c.jj 2022-03-25 16:23:18.033120090 +0100 +++ gcc/testsuite/c-c++-common/builtin-convertvector-3.c 2022-03-25 16:23:40.633799410 +0100 @@ -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]; +} --- gcc/testsuite/g++.dg/cpp2a/bit-cast15.C.jj 2022-03-25 16:26:22.271505979 +0100 +++ gcc/testsuite/g++.dg/cpp2a/bit-cast15.C 2022-03-25 16:26:15.907596274 +0100 @@ -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 Jakub