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 C424F3858CDA for ; Tue, 29 Nov 2022 21:38:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C424F3858CDA 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=1669757934; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r+PPINI4UznQRMjYSPAbxS/QMXaxqCAx25JbcJOOnr0=; b=La+KVY7qAwMyIpM+dFmpHdsQqwISWD9KTPp7DjOiKedPbP6gjt6iux8mvQNUM3QpTw0PgA e/sdjgXpZwYEFwXOC8vJvgbCrIQRvW8qVI382+wkcrdA00JDe9AMJqBsyFDwdKBWaEUJUU FE1gDjZPYNiXN+Xj8jq7vg+giny1v/4= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-14-N_kp2s2zNjqsr3yYGFst1A-1; Tue, 29 Nov 2022 16:38:53 -0500 X-MC-Unique: N_kp2s2zNjqsr3yYGFst1A-1 Received: by mail-qk1-f197.google.com with SMTP id o13-20020a05620a2a0d00b006cf9085682dso31898927qkp.7 for ; Tue, 29 Nov 2022 13:38:53 -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:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=r+PPINI4UznQRMjYSPAbxS/QMXaxqCAx25JbcJOOnr0=; b=Ot/6QBe1dPvMQy17iZU6+esPN7J5s2ukbHWJ86cSVJgzJ0ri4JkmILDRHBhSZFRO0C by9Vd3vaRCJeSKho5jZ9ftvClt9+0gEuEmoaTlRtaWHqmScQKv1+xGbgxNdOWawXKecq f4hYOOCQldFoOyU/cebzHSzDZ5b+OHvroae+lYZ4YrkgV6WIPLqYLNmSSGzd6b2i7RZa jqMgnoCocJ8967z+CCDf5KJa7r++HT5RSQ2Y7lecJMSV7RRGfOn0xFRPf8w48kr3nbEJ VvDKIH/YfuLD+u7EAKNOtPYjqnei3TmA6Z51PAnRnFMdzy9kn33Bp+TE+vOMVEmssBg/ x12g== X-Gm-Message-State: ANoB5pmh4sW5cDp1B8BU2wV25agte7PYIDtsFpDxJgJX/m46vrGkyvlj P62HZkqcxSfbPaeEAdsiHFpxrlx2e3hZ9wHTaB+ssu6q/+sOn/FFu95Sp5T+FbVZ7qkGbUDRePS 4lKEt3vF9gTwh6kdOGQ== X-Received: by 2002:a05:620a:11ab:b0:6fa:3133:f6ae with SMTP id c11-20020a05620a11ab00b006fa3133f6aemr53222524qkk.115.1669757932786; Tue, 29 Nov 2022 13:38:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf5CkBdZdNyRk8rT4a8o7kqbLQOtvJ+qeAQJoGk0Cbf+sOM/XlVgXNeoX7dmRLZ2JhZXta0DnQ== X-Received: by 2002:a05:620a:11ab:b0:6fa:3133:f6ae with SMTP id c11-20020a05620a11ab00b006fa3133f6aemr53222496qkk.115.1669757932382; Tue, 29 Nov 2022 13:38:52 -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 x30-20020a05620a0b5e00b006fa4b111c76sm11187051qkg.36.2022.11.29.13.38.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 29 Nov 2022 13:38:51 -0800 (PST) Message-ID: <029221ef-74ce-12a4-29f9-599bf4efaa20@redhat.com> Date: Tue, 29 Nov 2022 16:38:50 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH] c++: Incremental fix for g++.dg/gomp/for-21.C [PR84469] To: Jakub Jelinek , gcc-patches@gcc.gnu.org References: 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,KAM_SHORT,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 11/29/22 07:32, Jakub Jelinek wrote: > Hi! > > The PR84469 patch I've just posted regresses the for-21.C testcase, > when in OpenMP loop there are at least 2 associated loops and > in a template outer structured binding with non type dependent expression > is used in the expressions of some inner loop, we don't diagnose those > any longer, as the (weirdly worded) diagnostics was only done during > finish_id_expression -> mark_used which for the inner loop expressions > happens before the structured bindings are finalized. When in templates, > mark_used doesn't diagnose uses of non-deduced variables, and if the > range for expression is type dependent, it is similarly diagnosed during > instantiation. But newly with the PR84469 fix if the range for expression > is not type dependent, there is no place that would diagnose it, as during > instantiation the structured bindings are already deduced. > > The following patch diagnoses it in that case during finish_omp_for (for > consistency with the same weird message). > > I'll commit this to trunk if the other patch is approved and it passes > bootstrap/regtest. > > 2022-11-29 Jakub Jelinek > > PR c++/84469 > * semantics.cc: Define INCLUDE_MEMORY before including system.h. > (struct finish_omp_for_data): New type. > (finish_omp_for_decomps_r): New function. > (finish_omp_for): Diagnose uses of non-type-dependent range for > loop decompositions in inner OpenMP associated loops in templates. > > * g++.dg/gomp/for-21.C (f6): Adjust lines of expected diagnostics. > * g++.dg/gomp/for-22.C: New test. > > --- gcc/cp/semantics.cc.jj 2022-11-19 09:21:14.897436616 +0100 > +++ gcc/cp/semantics.cc 2022-11-29 12:58:36.165771985 +0100 > @@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. > . */ > > #include "config.h" > +#define INCLUDE_MEMORY > #include "system.h" > #include "coretypes.h" > #include "target.h" > @@ -10401,6 +10402,47 @@ handle_omp_for_class_iterator (int i, lo > return false; > } > > +struct finish_omp_for_data { > + std::unique_ptr> decomps; > + bool fail; > + location_t loc; > +}; > + > +/* Helper function for finish_omp_for. Diagnose uses of structured > + bindings of OpenMP collapsed loop range for loops in the associated > + loops. If not processing_template_decl, this is diagnosed by > + finish_id_expression -> mark_used before the range for is deduced. > + And if processing_template_decl and the range for expression is > + type dependent, it is similarly diagnosed during instantiation. > + Only when processing_template_decl and range for expression is > + not type dependent, we wouldn't diagnose it at all, so do it > + from finish_omp_for in that case. */ > + > +static tree > +finish_omp_for_decomps_r (tree *tp, int *, void *d) > +{ > + if (VAR_P (*tp) > + && DECL_DECOMPOSITION_P (*tp) > + && !type_dependent_expression_p (*tp) > + && DECL_HAS_VALUE_EXPR_P (*tp)) > + { > + tree v = DECL_VALUE_EXPR (*tp); > + if (TREE_CODE (v) == ARRAY_REF > + && VAR_P (TREE_OPERAND (v, 0)) > + && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0))) > + { > + finish_omp_for_data *data = (finish_omp_for_data *) d; > + if (data->decomps->contains (TREE_OPERAND (v, 0))) > + { > + error_at (data->loc, "use of %qD before deduction of %", > + *tp); > + data->fail = true; > + } > + } > + } > + return NULL_TREE; > +} > + > /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR > are directly for their associated operands in the statement. DECL > and INIT are a combo; if DECL is NULL then INIT ought to be a > @@ -10419,6 +10461,7 @@ finish_omp_for (location_t locus, enum t > int i; > int collapse = 1; > int ordered = 0; > + finish_omp_for_data data; > > gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv)); > gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv)); > @@ -10479,7 +10522,25 @@ finish_omp_for (location_t locus, enum t > elocus = EXPR_LOCATION (init); > > if (cond == global_namespace) > - continue; > + { > + gcc_assert (processing_template_decl); > + if (TREE_VEC_LENGTH (declv) > 1 > + && VAR_P (decl) > + && DECL_DECOMPOSITION_P (decl) > + && !type_dependent_expression_p (decl)) > + { > + gcc_assert (DECL_HAS_VALUE_EXPR_P (decl)); > + tree v = DECL_VALUE_EXPR (decl); > + gcc_assert (TREE_CODE (v) == ARRAY_REF > + && VAR_P (TREE_OPERAND (v, 0)) > + && DECL_DECOMPOSITION_P (TREE_OPERAND (v, 0))); > + if (!data.decomps) > + data.decomps > + = std::unique_ptr> (new hash_set); > + data.decomps->add (TREE_OPERAND (v, 0)); > + } > + continue; > + } > > if (cond == NULL) > { > @@ -10497,6 +10558,37 @@ finish_omp_for (location_t locus, enum t > TREE_VEC_ELT (initv, i) = init; > } > > + if (data.decomps) > + { > + data.fail = false; > + data.loc = locus; > + hash_set pset; > + for (i = 0; i < TREE_VEC_LENGTH (declv); i++) > + { > + init = TREE_VEC_ELT (initv, i); > + cond = TREE_VEC_ELT (condv, i); > + incr = TREE_VEC_ELT (incrv, i); > + data.loc = EXPR_LOC_OR_LOC (init, locus); > + cp_walk_tree (&init, finish_omp_for_decomps_r, &data, &pset); > + data.loc = EXPR_LOC_OR_LOC (cond, locus); > + cp_walk_tree (&cond, finish_omp_for_decomps_r, &data, &pset); > + data.loc = EXPR_LOC_OR_LOC (incr, locus); > + cp_walk_tree (&incr, finish_omp_for_decomps_r, &data, &pset); > + } > + if (orig_inits && !data.fail) > + { > + tree orig_init; > + FOR_EACH_VEC_ELT (*orig_inits, i, orig_init) > + { > + data.loc = EXPR_LOC_OR_LOC (orig_init, locus); > + cp_walk_tree (&orig_init, finish_omp_for_decomps_r, > + &data, &pset); > + } > + } > + if (data.fail) > + return NULL; > + } > + > if (orig_inits) > { > bool fail = false; > --- gcc/testsuite/g++.dg/gomp/for-21.C.jj 2020-01-12 11:54:37.178401867 +0100 > +++ gcc/testsuite/g++.dg/gomp/for-21.C 2022-11-29 13:06:59.038410557 +0100 > @@ -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 (auto [i, j, k] : a) // { dg-error "use of 'i' before deduction of 'auto'" } > 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 } > + ; // { dg-error "use of 'k' before deduction of 'auto'" "" { target *-*-* } .-1 } Hmm, this error is surprising: since the initializer is non-dependent, we should have deduced immediately. I'd expect the same error as in the non-structured-binding cases, "* expression refers to iteration variable". > } > > template > --- gcc/testsuite/g++.dg/gomp/for-22.C.jj 2022-11-29 13:07:10.859237506 +0100 > +++ gcc/testsuite/g++.dg/gomp/for-22.C 2022-11-29 13:09:50.743897003 +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 "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 } > +} > + > +template > +void > +f2 (B a) > +{ > + #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 } > +} > + > +template > +void > +f3 (T a) > +{ > + #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 } > +} > + > +void > +test () > +{ > + B b; > + f1 (b); > + f2 <0> (b); > + f3 (b); > +} > > Jakub >