From patchwork Thu Dec 1 10:32:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 28295 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp184263wrr; Thu, 1 Dec 2022 02:32:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf4we1CMkr8yjLY8hOL2VPGXJ9H7jUP4m/J73b+4LOOGvAOwaR/w8tLs/W9nV+2z9deMmsD9 X-Received: by 2002:a17:907:1387:b0:7bd:b901:4b86 with SMTP id vs7-20020a170907138700b007bdb9014b86mr21607193ejb.712.1669890779406; Thu, 01 Dec 2022 02:32:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669890779; cv=none; d=google.com; s=arc-20160816; b=TDk3srNuJBUXhaOmPnapp1zkJpdJqICedm1yyogrYWY9/ZF2bqCl4POUtAKUV0NIwd QbLJ9/ET9l1tk/sDcwUGUJ5iDngFiRAiZQqsyJEDxncASRdMK0zya1FaItrBPzwcFu5L 9CwqseBPI2NxWSe7wV37URHUpNWNcQrBjNpJ2pwlfKAY6ft72MSwD9byZeL4QGNZEd7t IOngOcqD9JgcI6ZUAuZ3zSINmBcN6VeuuvIwZCcIj2SSGLNwFIber69ruDmGkBGLfTat Zil84ILiNWy+SQWndQbGzPj01HB3O4vIBOKKEPkT+q5x50tJRsT+aEOOP6Cxho7dEqFi 5LkQ== 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:in-reply-to:mime-version:references:message-id :subject:cc:to:date:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=K40Y6Mkm+JOzrJHsDhUXNSLL6dKfE/Gr0SwFFK0P3MY=; b=qzNvtYnc/CPsREBQynZqW9Wc3P7aG1iCh/JtSc/KMrLJwYetv8b2T6Tm7GtsievYSb fjOCtnpQ0Il5pcoUwvHcbW/De83+jjA5+5aN2SeW8vlpwnj8ImjPOpgVHmhc9+NAlD5z gBhp1UqMI8b8pfAj3756QVxC0vjlwnV93A4enpv2kj36oac4dKVqzmDsBcdPj89tkIbx BfQsdy6wD1toFy5iDwEDIGEDqyX3CA7uV0O37AZJIZ4lf98v9MUac/CQUrVktoepP+HW YamYyd1+YPTY6OpcctIoW/0LQcnW/CIN05QsQi14Nty3vAoZUjwDx6LKCUY6wCVuLu3O 6Eww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dQsSIUze; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id f20-20020a0564021e9400b004691125c420si4040800edf.264.2022.12.01.02.32.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 02:32:59 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dQsSIUze; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 392F53857C71 for ; Thu, 1 Dec 2022 10:32:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 392F53857C71 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669890778; bh=K40Y6Mkm+JOzrJHsDhUXNSLL6dKfE/Gr0SwFFK0P3MY=; h=Date:To:Cc:Subject:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=dQsSIUzeMvDPXgQ5pNQNchKOiTnbEd1/EqBALGcuKB5L/BFOqblOivEY/DNqyW9q6 Pwq4RRBAcfsR9g8/NobF9ENMnTWV6LWYBa/ACqHgOiGZigzuY4a+5bwjpssxDZhVbX d1s6xTSvcCE294qcf3ENYNBU0Et0EYUWo0Z3OxqM= 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 9133D385B526 for ; Thu, 1 Dec 2022 10:32:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9133D385B526 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-651-qMcpUnTYP0y1IohvrYf7OA-1; Thu, 01 Dec 2022 05:32:12 -0500 X-MC-Unique: qMcpUnTYP0y1IohvrYf7OA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8C66B38343C0 for ; Thu, 1 Dec 2022 10:32:12 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.114]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4CE3C140EBF5; Thu, 1 Dec 2022 10:32:12 +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 2B1AW7th3837784 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 1 Dec 2022 11:32:08 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 2B1AW7US3837783; Thu, 1 Dec 2022 11:32:07 +0100 Date: Thu, 1 Dec 2022 11:32:06 +0100 To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++, v2: Incremental fix for g++.dg/gomp/for-21.C [PR84469] Message-ID: References: <029221ef-74ce-12a4-29f9-599bf4efaa20@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.9 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?1751007393677443446?= X-GMAIL-MSGID: =?utf-8?q?1751007393677443446?= On Wed, Nov 30, 2022 at 01:52:08PM -0500, Jason Merrill wrote: > It looks like we're already deducing the type for the underlying S variable > in cp_convert_omp_range_for, we just aren't updating the types of the > individual bindings. You're right. With this patch (still incremental against the base PR84469 patch) we get the nicer diagnostics in all cases. Regtested successfully on x86_64-linux (g++ gomp.exp/goacc.exp/goacc-gomp.exp and libgomp's c++.exp), ok for trunk (including the base patch) if it passes full bootstrap/regtest? 2022-12-01 Jakub Jelinek PR c++/84469 gcc/c-family/ * c-omp.cc (c_omp_is_loop_iterator): For range for with structured binding return TREE_VEC_LENGTH (d->declv) even if decl is equal to any of the structured binding decls. gcc/cp/ * parser.cc (cp_convert_omp_range_for): After do_auto_deduction if !processing_template_decl call cp_finish_decomp with processing_template_decl temporarily incremented. gcc/testsuite/ * g++.dg/gomp/for-21.C (f3, f6, f9): Adjust expected diagnostics. * g++.dg/gomp/for-22.C: New test. Jakub --- gcc/c-family/c-omp.cc.jj 2022-10-04 10:36:46.515414485 +0200 +++ gcc/c-family/c-omp.cc 2022-12-01 10:57:56.365253302 +0100 @@ -1311,10 +1311,11 @@ c_omp_is_loop_iterator (tree decl, struc else if (TREE_CODE (TREE_VEC_ELT (d->declv, i)) == TREE_LIST && TREE_CHAIN (TREE_VEC_ELT (d->declv, i)) && (TREE_CODE (TREE_CHAIN (TREE_VEC_ELT (d->declv, i))) - == TREE_VEC) - && decl == TREE_VEC_ELT (TREE_CHAIN (TREE_VEC_ELT (d->declv, - i)), 2)) - return TREE_VEC_LENGTH (d->declv); + == TREE_VEC)) + for (int j = 2; + j < TREE_VEC_LENGTH (TREE_CHAIN (TREE_VEC_ELT (d->declv, i))); j++) + if (decl == TREE_VEC_ELT (TREE_CHAIN (TREE_VEC_ELT (d->declv, i)), j)) + return TREE_VEC_LENGTH (d->declv); return -1; } --- gcc/cp/parser.cc.jj 2022-12-01 10:19:27.000000000 +0100 +++ gcc/cp/parser.cc 2022-12-01 10:21:30.760450093 +0100 @@ -43126,8 +43126,16 @@ cp_convert_omp_range_for (tree &this_pre tree t = build_x_indirect_ref (input_location, begin, RO_UNARY_STAR, NULL_TREE, tf_none); if (!error_operand_p (t)) - TREE_TYPE (orig_decl) = do_auto_deduction (TREE_TYPE (orig_decl), - t, auto_node); + { + TREE_TYPE (orig_decl) = do_auto_deduction (TREE_TYPE (orig_decl), + t, auto_node); + if (decomp_first_name) + { + ++processing_template_decl; + cp_finish_decomp (orig_decl, decomp_first_name, decomp_cnt); + --processing_template_decl; + } + } } tree v = make_tree_vec (decomp_cnt + 3); --- gcc/testsuite/g++.dg/gomp/for-21.C.jj 2022-11-30 10:29:09.332186135 +0100 +++ gcc/testsuite/g++.dg/gomp/for-21.C 2022-12-01 11:05:40.888414600 +0100 @@ -24,9 +24,9 @@ void f3 (S (&a)[10]) { #pragma omp for collapse (2) - for (auto [i, j, k] : a) // { dg-error "use of 'i' before deduction of 'auto'" "" { target *-*-* } .+1 } - for (int l = i; l < j; l += k) // { dg-error "use of 'j' before deduction of 'auto'" } - ; // { dg-error "use of 'k' before deduction of 'auto'" "" { target *-*-* } .-1 } + for (auto [i, j, k] : a) // { dg-error "initializer expression refers to iteration variable 'i'" } + for (int l = i; l < j; l += k) // { dg-error "condition expression refers to iteration variable 'j'" } + ; // { dg-error "increment expression refers to iteration variable 'k'" "" { target *-*-* } .-2 } } template @@ -54,9 +54,9 @@ void f6 (S (&a)[10]) { #pragma omp for collapse (2) - for (auto [i, j, k] : a) // { dg-error "use of 'i' before deduction of 'auto'" "" { target *-*-* } .-1 } - for (int l = i; l < j; l += k) // { dg-error "use of 'j' before deduction of 'auto'" } - ; // { dg-error "use of 'k' before deduction of 'auto'" "" { target *-*-* } .-3 } + for (auto [i, j, k] : a) // { dg-error "initializer expression refers to iteration variable 'i'" "" { target *-*-* } .-1 } + for (int l = i; l < j; l += k) // { dg-error "condition expression refers to iteration variable 'j'" } + ; // { dg-error "increment expression refers to iteration variable 'k'" "" { target *-*-* } .-3 } } template @@ -84,9 +84,9 @@ void f9 (U (&a)[10]) { #pragma omp for collapse (2) - for (auto [i, j, k] : a) // { dg-error "use of 'i' before deduction of 'auto'" "" { target *-*-* } .-1 } - for (T l = i; l < j; l += k) // { dg-error "use of 'j' before deduction of 'auto'" } - ; // { dg-error "use of 'k' before deduction of 'auto'" "" { target *-*-* } .-3 } + for (auto [i, j, k] : a) // { dg-error "initializer expression refers to iteration variable 'i'" "" { target *-*-* } .-1 } + for (T l = i; l < j; l += k) // { dg-error "condition expression refers to iteration variable 'j'" } + ; // { dg-error "increment expression refers to iteration variable 'k'" "" { target *-*-* } .-3 } } void --- gcc/testsuite/g++.dg/gomp/for-22.C.jj 2022-12-01 10:17:47.117785354 +0100 +++ gcc/testsuite/g++.dg/gomp/for-22.C 2022-12-01 11:08:19.578078371 +0100 @@ -0,0 +1,57 @@ +// { dg-do compile { target c++17 } } + +namespace std { + template struct tuple_size; + template struct tuple_element; +} + +struct A { + int i; + template int& get() { return i; } +}; + +template<> struct std::tuple_size { static const int value = 3; }; +template struct std::tuple_element { using type = int; }; + +struct B { + A *begin(); + A *end(); +}; + +void +f1 (B a) +{ + #pragma omp for collapse (2) + for (auto [i, j, k] : a) // { dg-error "initializer expression refers to iteration variable 'i'" "" { target *-*-* } .+1 } + for (int l = i; l < j; l += k) // { dg-error "condition expression refers to iteration variable 'j'" } + ; // { dg-error "increment expression refers to iteration variable 'k'" "" { target *-*-* } .-1 } +} + +template +void +f2 (B a) +{ + #pragma omp for collapse (2) + for (auto [i, j, k] : a) // { dg-error "initializer expression refers to iteration variable 'i'" "" { target *-*-* } .-1 } + for (int l = i; l < j; l += k) // { dg-error "condition expression refers to iteration variable 'j'" } + ; // { dg-error "increment expression refers to iteration variable 'k'" "" { target *-*-* } .-3 } +} + +template +void +f3 (T a) +{ + #pragma omp for collapse (2) + for (auto [i, j, k] : a) // { dg-error "initializer expression refers to iteration variable 'i'" "" { target *-*-* } .-1 } + for (int l = i; l < j; l += k) // { dg-error "condition expression refers to iteration variable 'j'" } + ; // { dg-error "increment expression refers to iteration variable 'k'" "" { target *-*-* } .-3 } +} + +void +test () +{ + B b; + f1 (b); + f2 <0> (b); + f3 (b); +}