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: 63266 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp4108638wrd; Thu, 2 Mar 2023 00:09:24 -0800 (PST) X-Google-Smtp-Source: AK7set+fcWqI+XU+a6S3aEZBs1LREMUC11RwGOk5gDpcdiwe8G+crZe5BSL52YRujbrhroChopc7 X-Received: by 2002:a17:907:162c:b0:85d:dd20:60a4 with SMTP id hb44-20020a170907162c00b0085ddd2060a4mr11991762ejc.40.1677744564267; Thu, 02 Mar 2023 00:09:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677744564; cv=none; d=google.com; s=arc-20160816; b=smfuInKo+lGTfeFU6U0ri1fQjqTG/3hS/owLclugzk4kN6c/FL4WlKtazgpBy11qVZ ObJELoYUc5erRe4N/ICBKhZTiSRYFg9/rZuCSM6Lx0Q6Ek827NHaYiF3Q36y9yqN8c4r M0pgb08TLDqsvhD8/XC2NWJK1/Vq3OW1NyzmlI3oAM1hTsfKALdL1qzheEC9BjuHedKY tJ3n3mNW6JwGYsJIaOPBK+JsuBOzKA96HhdGdl08ujUaAbBhmoU6Kcr6y20iVZbp60fb rBq7jQGwMJWiu+Fvbxi9cKw0PZdzKYlxar8U7MLi9Tt/rV8OQZsDKes2coTNC5rajsAj jHJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=GJrYpt+0F9KZdXZmhxeXCeyLHaQ62/qMv95+5HpEth0=; b=c3Tvx6LB+L/bIpEHgmu9Pi6lZ7Cv9tSwOXJ85iJRppM8EO76+GExBq9tsZLAvZRudf o269MIu2CxGpp1HgtL7NDO8NxLjMJkv+YJkTdTNlDlMX7NoGbXOPMZ2VzdG+6wPLtxKC urQCsEk6mT4rEpwPrp8uhJmNjkfzxjBxFfHsmFp1XSwwsWCUPRiUGE5crHBkv42ERlPG ah/c9BlDxNUuHc3BgtvM29OklcSfWX0FQ6UWPejYH0cL0Dsn43D8ZCRlgQ8761FqPwRH DuISrTW0INsjOsjOmnVJN1Mv8KLWQkgC/jIdlYos/6ItlqAI7vawRgKJxx8zHg4/wS2l 9l3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dbH+3mYA; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id hp21-20020a1709073e1500b008d0bfa97b4fsi4219121ejc.802.2023.03.02.00.09.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 00:09:24 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dbH+3mYA; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 332BE385842C for ; Thu, 2 Mar 2023 08:09:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 332BE385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677744563; 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=dbH+3mYAf+kDk43EzpCZxLusO2dBAlq7Kor6mPDj1E+dVBjsx30i5RmN26a14y7D+ YmppIgUwjqnK50jVgcq40OF6DB6dRBDbAKLxxjHezF4RqF5tAh3r368IU80bP0hFRm XC1ul3R6OiHynzttwYsJUVzmzCvdqryo3mCXpYIY= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759242684590298920?= X-GMAIL-MSGID: =?utf-8?q?1759242684590298920?= 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); +}