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.133.124]) by sourceware.org (Postfix) with ESMTPS id 6C7493858421 for ; Thu, 1 Dec 2022 18:21:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6C7493858421 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669918898; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ur5VAICof3ti/N+Z011vGoa5RU28VLlNpApq93Fi10E=; b=OVmL2SvzJLdbO5YOyuJT2yYxj+WKo8j9GtIv8xD6BRGrusbMx/EdCakTx3qdDkr/uxak7S 90yo5u+3UL20EQA2slew/7VfBM2+maQxW58xT0IBXy8zPYb85gUzFK67G76IwywL1A5qy3 PGv/aeMZXzwz4fPmPjqX9A1kDTLFv1c= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-128-Bm84UvozMCOzq6z4xJvXAw-1; Thu, 01 Dec 2022 13:21:37 -0500 X-MC-Unique: Bm84UvozMCOzq6z4xJvXAw-1 Received: by mail-qt1-f197.google.com with SMTP id b20-20020ac844d4000000b003a542f9de3dso6469025qto.7 for ; Thu, 01 Dec 2022 10:21:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ur5VAICof3ti/N+Z011vGoa5RU28VLlNpApq93Fi10E=; b=nysiuKwe7rmjUowdym07z0HVAdSMBBa2XBoZT9wtkJilqneejy6y7ylCufjOpl12s7 m5aoB12JldX05wyX6vuQ5p7MNn0fn8UrtzOvBwry16g/kv3Dj+4pIWrZvQ5+65mFhKLR h8wOkjpDavMzbEHa8LSpPBbu/51EPs71crxVK7+PHMUuKW84e2rCFe83poN51F1r8t/S Hgx9HVQMeooHphOohMHd849rPGmHvPxNHQOOwQXlFzNkV1mBZOutjX6576/iho+UA8LM lG3Ww8IVa/yD8Lcid5K4rpw+T3SF6Ga1BRjpXerkQPUCA/dY07X7W9Ti6ruV/NFLI4wC caVQ== X-Gm-Message-State: ANoB5pmE7lpVjGT2KJvFobd0PiwNbX/ruMD+x9khsCHX09G8SuqKJlSA 0GAxAAKrYSgfKl5DebiQX76HGMno6knADJhjPSR3I3JRbnmsHKt4DVaG3cB1B+eoC50CEAg69HT z0xLAV6tTZXfbTIjSrA== X-Received: by 2002:a05:620a:b83:b0:6fa:1da9:94e6 with SMTP id k3-20020a05620a0b8300b006fa1da994e6mr59393666qkh.122.1669918896534; Thu, 01 Dec 2022 10:21:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf4kJ95lzQFfk8VK/F2Ld7a/6iwFlnNpHZQ0vQjLK7YJoy/LRvNqbJqlsoW1G1iB8fnyp7Zsrw== X-Received: by 2002:a05:620a:b83:b0:6fa:1da9:94e6 with SMTP id k3-20020a05620a0b8300b006fa1da994e6mr59393643qkh.122.1669918896171; Thu, 01 Dec 2022 10:21:36 -0800 (PST) Received: from [192.168.1.108] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id e20-20020ac845d4000000b003a582090530sm2920252qto.83.2022.12.01.10.21.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 01 Dec 2022 10:21:35 -0800 (PST) Message-ID: <4ef94b26-a3d5-9d85-7bff-fc7062d03c19@redhat.com> Date: Thu, 1 Dec 2022 13:21:34 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH] c++, v2: Incremental fix for g++.dg/gomp/for-21.C [PR84469] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: <029221ef-74ce-12a4-29f9-599bf4efaa20@redhat.com> From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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 List-Id: On 12/1/22 05:32, Jakub Jelinek wrote: > 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? OK, thanks. > 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. > > --- 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); > +} > > > Jakub >