From patchwork Thu Jan 26 09:50:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 48538 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp189376wrn; Thu, 26 Jan 2023 01:51:38 -0800 (PST) X-Google-Smtp-Source: AMrXdXvy6rSoYDB8ROt7ht8rd6JX07MZ/zV4bM6yECZ0SixlG3FxshsKv4TlDYcLcenOKBBJell9 X-Received: by 2002:a17:907:a648:b0:854:6e3:2388 with SMTP id vu8-20020a170907a64800b0085406e32388mr41469063ejc.12.1674726698390; Thu, 26 Jan 2023 01:51:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674726698; cv=none; d=google.com; s=arc-20160816; b=ysMYbz9B91k0ZYjWPE2yeYUK1gdOZMEmDNuLbFcmSv2VLCMG7OjrFXoAxKCcht0XtY ytlr5JkK7N8s5HhHLV/kAzSZHP8wZ3f8lehe2xUnOJ+YnqC4vzZ3q66q4qsKSOW76fq8 G6BOtRAzN3mdDZHb879VfT9nSlPLFlN/mUaBFzXYP6Cz0PIBFynQrruru6cP1ogOHLc2 ppRqxh+PiYItEN6SezMuO6WdB5x5OjikYWbPG5uwFRjXj3bR3ygH57Jy8IZiwjRf9WA3 RiWfwthsHWJL8fVsc1NirV+XOOMyWTw707SpkdKfA5HnRAIS8QCgtIrv7zqU8W1kdVdY M3sQ== 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=XUHDR6CdZKNAn6unzekbUkufyq/v6vEx1lRVmTAlz1I=; b=SnbYbayrjFAadLV433H8yrzOii74Sv86Ssp56iCtTyKaWI9KlutGtk6e3TwV4kuTet CAjZqP+gWQ095NOoihy8eRU/97Q8pZv4LvbbC28KvBVWwvwWvhXPBOpFpLHEXulNuzyJ LTqT5fM1sxJWQp1YjincgVeIS4fT+5gqU5cumTtGhGyYnMx2epQeE4SPXBq/sZOOKGt+ wq2PRt7Wrkzcb2jyWKS9yabtX/IUSE1ZtrNfswpYbaOpNDSFieUfULitKrI2+D7Q98/i eomA99mQGR1DjRcKC1zXQj+OtDr4Kj6kak/b7YeRVfQkIdUFQ69GwoK4q/gph7IrsjYV iZWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="DbHEyXR/"; 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 21-20020a170906009500b00870d2ca67absi824168ejc.218.2023.01.26.01.51.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Jan 2023 01:51:38 -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="DbHEyXR/"; 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 69CDE3858C00 for ; Thu, 26 Jan 2023 09:51:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 69CDE3858C00 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1674726694; bh=XUHDR6CdZKNAn6unzekbUkufyq/v6vEx1lRVmTAlz1I=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=DbHEyXR/4bBCAGuipaAVOa5GkeYDQt68sc56hUl9O1pQQRAuz9Tt0eDJvBT9EOGfO tKZVx0sowqecNbr7nl2q54xVUhnVqrePHbBjx+C1xs+E2XHp3dl9gBsE+GXLvxVxeZ 3zhH+JeBFzvCwAOqWRmCC5527+4UMcW6SVU34KHM= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 9CC123858C74 for ; Thu, 26 Jan 2023 09:50:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9CC123858C74 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-596-VS6EMUz-NDqmKRliNZsfEw-1; Thu, 26 Jan 2023 04:50:46 -0500 X-MC-Unique: VS6EMUz-NDqmKRliNZsfEw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C989F29ABA09 for ; Thu, 26 Jan 2023 09:50:45 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8A96351E5 for ; Thu, 26 Jan 2023 09:50:45 +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 30Q9ogoV605381 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT) for ; Thu, 26 Jan 2023 10:50:43 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 30Q9og1q605380 for gcc-patches@gcc.gnu.org; Thu, 26 Jan 2023 10:50:42 +0100 Date: Thu, 26 Jan 2023 10:50:42 +0100 To: gcc-patches@gcc.gnu.org Subject: [committed] openmp, c++: Workaround fold_for_warn ICE on invalid OpenMP collapsed loops [PR108503] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.8 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?1756078222560631137?= X-GMAIL-MSGID: =?utf-8?q?1756078222560631137?= Hi! My recent change to deduce structured binding vars earlier caused the following invalid testcase to ICE. The problem is that because at cp_convert_omp_range_for when !processing_template_decl we aren't yet ready to finalize the structured bindings (e.g. can't emit there associated code) but need to deduce types of the vars so that we don't get errors if we parse invalid uses of those vars in inner loops of the collapsed construct. This is done by temporarily bumping processing_template_decl around the call to cp_finish_decomp. Unfortunately, as we can't finalize it yet, the types of the vars will be deduced, but their DECL_VALUE_EXPR is not finalized yet and if say fold_for_warn tries to constant expression evaluate them, it recurses on DECL_VALUE_EXPR and ICEs because it sees e.g. ARRAY_REF (with NULL type) on a VAR_DECL with class type. The following patch works around that by temporarily hiding the DECL_VALUE_EXPRs by clearing DECL_HAS_VALUE_EXPR_P in that case during cp_convert_omp_range_for and arranging for cp_finish_omp_range_for to set it back before doing the final cp_finish_decomp. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2023-01-25 Jakub Jelinek PR c++/108503 * parser.cc (cp_convert_omp_range_for): If cp_finish_decomp has been called in !processing_template_decl with processing_template_decl temporarily set, clear DECL_HAS_VALUE_EXPR_P on the vars temporarily. (cp_finish_omp_range_for): And set it back again here. * g++.dg/gomp/pr108503.C: New test. Jakub --- gcc/cp/parser.cc.jj 2023-01-25 00:03:42.746684624 +0100 +++ gcc/cp/parser.cc 2023-01-25 13:49:35.128800077 +0100 @@ -43039,6 +43039,7 @@ cp_convert_omp_range_for (tree &this_pre { tree begin, end, range_temp_decl = NULL_TREE; tree iter_type, begin_expr, end_expr; + bool clear_has_value_expr = false; if (processing_template_decl) { @@ -43185,6 +43186,8 @@ cp_convert_omp_range_for (tree &this_pre ++processing_template_decl; cp_finish_decomp (orig_decl, decomp_first_name, decomp_cnt); --processing_template_decl; + if (!processing_template_decl) + clear_has_value_expr = true; } } } @@ -43193,8 +43196,20 @@ cp_convert_omp_range_for (tree &this_pre TREE_VEC_ELT (v, 0) = range_temp_decl; TREE_VEC_ELT (v, 1) = end; TREE_VEC_ELT (v, 2) = orig_decl; + if (clear_has_value_expr) + TREE_PUBLIC (v) = 1; for (unsigned i = 0; i < decomp_cnt; i++) { + if (clear_has_value_expr) + { + /* If cp_finish_decomp was called with processing_template_decl + temporarily set to 1, then decomp names will have deduced + 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)); + DECL_HAS_VALUE_EXPR_P (decomp_first_name) = 0; + } TREE_VEC_ELT (v, i + 3) = decomp_first_name; decomp_first_name = DECL_CHAIN (decomp_first_name); } @@ -43217,6 +43232,18 @@ cp_finish_omp_range_for (tree orig, tree { decomp_first_name = TREE_VEC_ELT (TREE_CHAIN (orig), 3); decomp_cnt = TREE_VEC_LENGTH (TREE_CHAIN (orig)) - 3; + if (TREE_PUBLIC (TREE_CHAIN (orig))) + { + /* Undo temporary clearing of DECL_HAS_VALUE_EXPR_P done + by cp_convert_omp_range_for above. */ + TREE_PUBLIC (TREE_CHAIN (orig)) = 0; + tree d = decomp_first_name; + for (unsigned i = 0; i < decomp_cnt; i++) + { + DECL_HAS_VALUE_EXPR_P (d) = 1; + d = DECL_CHAIN (d); + } + } cp_maybe_mangle_decomp (decl, decomp_first_name, decomp_cnt); } --- gcc/testsuite/g++.dg/gomp/pr108503.C.jj 2023-01-25 13:52:42.839086391 +0100 +++ gcc/testsuite/g++.dg/gomp/pr108503.C 2023-01-25 13:52:22.901374628 +0100 @@ -0,0 +1,27 @@ +// PR c++/108503 +// { dg-do compile { target c++17 } } +// { dg-additional-options "-Wall" } + +namespace std { + template struct tuple_size; + template struct tuple_element; +} +struct A { + template int get () { return 1; } +}; +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 +foo (B a) +{ + #pragma omp for collapse(2) + for (auto [i, j, k] : a) + for (int l = i; l < j; l += k) // { dg-error "initializer expression refers to iteration variable 'i'" } + ; // { dg-error "condition expression refers to iteration variable 'j'" "" { target *-*-* } .-1 } +} // { dg-error "increment expression refers to iteration variable 'k'" "" { target *-*-* } .-2 }