From patchwork Thu Mar 2 08:08:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 65885 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C6E473858C83 for ; Thu, 2 Mar 2023 08:09:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C6E473858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677744547; bh=GJrYpt+0F9KZdXZmhxeXCeyLHaQ62/qMv95+5HpEth0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=rNxXBX4wX7LHByeHGkcU0gDp9tqSefhDNbka0gPpwhcSz3PuiQfX3ZcK2xLH655au LVSb390QRSaVVTCEIan5SL0sG4a2CxIYZtetm/1cOhYikMxN3H0ej6B8Z8gpv37m2j gBeJbF+9/vj6CIHQ0KaeGbvCv6XL9UM3nwmHgscA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 D67E13858D33 for ; Thu, 2 Mar 2023 08:08:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D67E13858D33 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-283-CsqTNN5jPxq9-sasLSaYMQ-1; Thu, 02 Mar 2023 03:08:37 -0500 X-MC-Unique: CsqTNN5jPxq9-sasLSaYMQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B55F81C29D4E for ; Thu, 2 Mar 2023 08:08:36 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7A5E1400EA93 for ; Thu, 2 Mar 2023 08:08:36 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 32288YQi3808990 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Thu, 2 Mar 2023 09:08:34 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32288X123808989 for gcc-patches@gcc.gnu.org; Thu, 2 Mar 2023 09:08:33 +0100 Date: Thu, 2 Mar 2023 09:08:33 +0100 To: gcc-patches@gcc.gnu.org Subject: [committed] openmp: Fix up error recovery for invalid structured bindings in OpenMP range for loops [PR105839] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.7 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_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! The PR108503 temporary DECL_HAS_VALUE_EXPR_P clearing code can ICE during recovery, because cp_finish_decomp when it detects errors and reports them clears DECL_HAS_VALUE_EXPR_P, clears DECL_VALUE_EXPR and sets TREE_TYPE of the structured binding vars to error_mark_node. The PR108503 code had an assertion that DECL_HAS_VALUE_EXPR_P is set so that it can clear it and restore later. The following patch allows DECL_HAS_VALUE_EXPR_P to be unset if type is error_mark_node and doesn't set it again in that case. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2023-03-02 Jakub Jelinek PR c++/105839 * parser.cc (cp_convert_omp_range_for): Allow in assert decomp_first_name without DECL_HAS_VALUE_EXPR_P if it has error_mark_node type. (cp_finish_omp_range_for): Don't set DECL_HAS_VALUE_EXPR_P back on decls which have error_mark_node type. * g++.dg/gomp/pr105839-1.C: New test. * g++.dg/gomp/pr105839-2.C: New test. Jakub --- gcc/cp/parser.cc.jj 2023-02-09 15:52:53.014025792 +0100 +++ gcc/cp/parser.cc 2023-03-01 12:20:59.970970342 +0100 @@ -43312,7 +43312,9 @@ cp_convert_omp_range_for (tree &this_pre name but the DECL_VALUE_EXPR will be dependent. Hide those from folding of other loop initializers e.g. for warning purposes until cp_finish_omp_range_for. */ - gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (decomp_first_name)); + gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (decomp_first_name) + || (TREE_TYPE (decomp_first_name) + == error_mark_node)); DECL_HAS_VALUE_EXPR_P (decomp_first_name) = 0; } TREE_VEC_ELT (v, i + 3) = decomp_first_name; @@ -43345,7 +43347,8 @@ cp_finish_omp_range_for (tree orig, tree tree d = decomp_first_name; for (unsigned i = 0; i < decomp_cnt; i++) { - DECL_HAS_VALUE_EXPR_P (d) = 1; + if (TREE_TYPE (d) != error_mark_node) + DECL_HAS_VALUE_EXPR_P (d) = 1; d = DECL_CHAIN (d); } } --- gcc/testsuite/g++.dg/gomp/pr105839-1.C.jj 2023-03-01 12:27:20.637439415 +0100 +++ gcc/testsuite/g++.dg/gomp/pr105839-1.C 2023-03-01 13:07:39.872273746 +0100 @@ -0,0 +1,25 @@ +// PR c++/105839 +// { dg-do compile { target c++11 } } +// { dg-options "-fopenmp" } + +template +void +foo (const T &x) +{ + [&] (auto &&y) // { dg-error "use of 'auto' in lambda parameter declaration only available with" "" { target c++11_only } } + { + #pragma omp parallel for + for (auto &&[v1, v2] : x) // { dg-error "cannot decompose non-array non-class type 'const int'" } + ; // { dg-error "invalid type for iteration variable" "" { target c++14 } .-1 } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-2 } + } ([]{}); // { dg-error "no match for call to" "" { target c++11_only } } + // { dg-error "invalid user-defined conversion from" "" { target c++11_only } .-1 } + // { dg-error "invalid conversion from" "" { target c++11_only } .-2 } +} + +void +bar () +{ + int a[10]; + foo (a); +} --- gcc/testsuite/g++.dg/gomp/pr105839-2.C.jj 2023-03-01 13:07:26.192472845 +0100 +++ gcc/testsuite/g++.dg/gomp/pr105839-2.C 2023-03-01 13:07:48.475148529 +0100 @@ -0,0 +1,24 @@ +// PR c++/105839 +// { dg-do compile { target c++14 } } +// { dg-options "-fopenmp" } + +template +void +foo (const T &x) +{ + [&] (auto &&y) + { + #pragma omp parallel for + for (auto &&[v1, v2] : x) // { dg-warning "structured bindings only available with" "" { target c++14_down } } + ; + } ([]{}); +} + +struct A { int a, b; }; + +void +bar () +{ + A a[10]; + foo (a); +}