From patchwork Wed Mar 30 07:48:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1610967 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=wQIU1tWi; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KSz8d6RGSz9sFk for ; Wed, 30 Mar 2022 18:49:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B5B4E388458B for ; Wed, 30 Mar 2022 07:49:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B5B4E388458B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1648626541; bh=Hu5KAa0LLpmsVFKD4lmwp1KzsXk0ZnwNnnz08QJoDeU=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=wQIU1tWi+825qHIAtHEpdl5RNz86qHvrXyT9hUkjzz8rVlA3ZyO0Flyw3YzrdL19R W6CgrkHLvqs0o3/FJln6YSAkLQ7Y/JV/74QRK14V4OaKbwpN44zyWjMUcEYVbMrfTe IPYJGgTFw+dznvHJN/W3+spNjsdNW6tvAJE0mFH8= 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 20D6D3858403 for ; Wed, 30 Mar 2022 07:48:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 20D6D3858403 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-250-sHYHWnpUPn6wq5igm3i7yg-1; Wed, 30 Mar 2022 03:48:25 -0400 X-MC-Unique: sHYHWnpUPn6wq5igm3i7yg-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 C91A78001EA for ; Wed, 30 Mar 2022 07:48:24 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8817B1400B18; Wed, 30 Mar 2022 07:48:24 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 22U7mMuW152800 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 30 Mar 2022 09:48:22 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 22U7mL9q152799; Wed, 30 Mar 2022 09:48:21 +0200 Date: Wed, 30 Mar 2022 09:48:21 +0200 To: gcc-patches@gcc.gnu.org Subject: [committed] openmp: Ensure DECL_CONTEXT of OpenMP iterators in templates [PR105092] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi! cp_parser_omp_iterators does: DECL_ARTIFICIAL (iter_var) = 1; DECL_CONTEXT (iter_var) = current_function_decl; pushdecl (iter_var); on the newly created iterator vars, but when we instantiate templates containing them, we just tsubst_decl them (which apparently for automatic vars clears DECL_CONTEXT with a comment that pushdecl should be called on them later). The result is that we have automatic vars in the IL which have NULL DECL_CONTEXT and the analyzer is upset about those. Fixed by setting DECL_CONTEXT and calling pushdecl during the instantiation. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2022-03-30 Jakub Jelinek PR c++/105092 * pt.cc (tsubst_omp_clause_decl): When handling iterators, set DECL_CONTEXT of the iterator var to current_function_decl and call pushdecl. * g++.dg/gomp/pr105092.C: New test. Jakub --- gcc/cp/pt.cc.jj 2022-03-25 11:19:25.974038692 +0100 +++ gcc/cp/pt.cc 2022-03-29 16:59:55.427004951 +0200 @@ -17538,6 +17538,8 @@ tsubst_omp_clause_decl (tree decl, tree *tp = copy_node (it); TREE_VEC_ELT (*tp, 0) = tsubst_decl (TREE_VEC_ELT (it, 0), args, complain); + DECL_CONTEXT (TREE_VEC_ELT (*tp, 0)) = current_function_decl; + pushdecl (TREE_VEC_ELT (*tp, 0)); TREE_VEC_ELT (*tp, 1) = tsubst_expr (TREE_VEC_ELT (it, 1), args, complain, in_decl, /*integral_constant_expression_p=*/false); --- gcc/testsuite/g++.dg/gomp/pr105092.C.jj 2022-03-29 17:07:31.481517752 +0200 +++ gcc/testsuite/g++.dg/gomp/pr105092.C 2022-03-29 17:12:15.190482108 +0200 @@ -0,0 +1,26 @@ +// PR c++/105092 +// { dg-do compile { target analyzer } } +// { dg-options "-fanalyzer -fopenmp" } + +struct S { S () {} }; + +template +struct U { + T c[10]; + U () { +#pragma omp task affinity (iterator (i = 0 : 10 : 1): c[i]) + ; + } +}; + +template +struct V { + T c[10]; + V () { +#pragma omp task depend (iterator (i = 0 : 10 : 1), inout: c[i]) + ; + } +}; + +U u; +V v;