From patchwork Fri Mar 5 22:07:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1448270 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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@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 ozlabs.org (Postfix) with ESMTPS id 4DshhK5N0Fz9sRf for ; Sat, 6 Mar 2021 09:08:33 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F2713835416; Fri, 5 Mar 2021 22:08:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa4.mentor.iphmx.com (esa4.mentor.iphmx.com [68.232.137.252]) by sourceware.org (Postfix) with ESMTPS id 24B3638618CC for ; Fri, 5 Mar 2021 22:08:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 24B3638618CC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Tobias_Burnus@mentor.com IronPort-SDR: kuF+0KbNukdMTRhowPdS2EfLef4TVBze3wTbyqGgojTYwCM0vS2obsWKi4WQt4i/bZy1uUXI4s ojIKUiR7ev+cVTgI97ZOVM8QdLsUDVo/BAJdjoC5YNRgcWBW/7knx3T4Qzk2Fbxe7YaV63ItCF uzpCG2CI/BUH9xqBqQ4AbiWK4w/o0iDjzFj7PXUziFhp+IDCdTaw9FfuQqRkWBes2kGn9xiiE1 +qK/bFCnAWqjkBGbz9qldzR8S9BcFU0qTBXdOjWFXQ/RUyJTsg9THYheTJ30XiVLBqD2m42FeW f2s= X-IronPort-AV: E=Sophos;i="5.81,226,1610438400"; d="diff'?scan'208";a="58950047" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 05 Mar 2021 14:08:27 -0800 IronPort-SDR: ggGsfb9Ss9IsVILpMueDJ4bzeFs+WbAxuUkLxa/SJp+POFHsZl9wJrSm/WjyQqQcrTkix0JlfD 57r8rYue4nn+Up/hMUGtkpHjgdjXNg/Ze3rNsyKEdIPNk9s2QwzqBi68I6D0fERB/nwvOCyztm EgiH1TcwK50UAgTCK2ifg72Q/3X+SBc3cBUS7LWbm3Y5RdVsXlK6YJC0EMsK2DnkC7RvIUvZRK thzPG2HFXpITPaLj8mdzstQspUiSJz0hd00/iOxA1VseG2qiZgAGmbaiNFWtY5NYQBlPb4gfwF xdw= To: gcc-patches , Richard Biener , Jakub Jelinek From: Tobias Burnus Subject: [Patch] tree-nested: Update assert for Fortran module vars [PR97927] Message-ID: <961971c0-9b01-4a38-6ac7-243c29f7051e@codesourcery.com> Date: Fri, 5 Mar 2021 23:07:59 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-06.mgc.mentorg.com (139.181.222.6) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Nested functions are permitted for C but not C++ as extension. They are also permitted for Fortran, which generates DECL_CONTEXT == NAMESPACE_DECL for module variables. That causes the gcc_assert (decl_function_context (decl) == info->context) to fail in tree-nested.c's lookup_field_for_decl. The call happens in convert_local_reference_stmt for: 2524 case GIMPLE_ASSIGN: 2525 if (gimple_clobber_p (stmt)) 2528 if (DECL_P (lhs) 2529 && !use_pointer_in_frame (lhs) 2530 && lookup_field_for_decl (info, lhs, NO_INSERT)) The latter runs into the assert mentioned above. And the '= {CLOBBER}' occurs in gfortran due to the intent(out). As additional ingredient, a nested (internal) procedure involved, obviously as otherwise tree-nested.c wouldn't be involved. The patch fixes the assert and in terms of the assert it makes sense, but I am not sure whether there are assumptions elsewhere which are wrong for NAMESPACE_DECL. OK for mainline? GCC 10? Tobias ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf tree-nested: Update assert for Fortran module vars [PR97927] gcc/ChangeLog: PR fortran/97927 * tree-nested.c (lookup_field_for_decl): Also permit that the var is a Fortran module var (= namespace context). gcc/testsuite/ChangeLog: PR fortran/97927 * gfortran.dg/module_variable_3.f90: New test. gcc/testsuite/gfortran.dg/module_variable_3.f90 | 37 +++++++++++++++++++++++++ gcc/tree-nested.c | 3 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gfortran.dg/module_variable_3.f90 b/gcc/testsuite/gfortran.dg/module_variable_3.f90 new file mode 100644 index 00000000000..0dae6d5bdd5 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/module_variable_3.f90 @@ -0,0 +1,37 @@ +! { dg-do compile } +! { dg-additional-options "-fdump-tree-original" } +! +! PR fortran/97927 +! +! Did ICE due to the in tree-nested.c due to {clobber} +! + +module mpi2 + interface + subroutine MPI_Allreduce(i) + implicit none + INTEGER, OPTIONAL, INTENT(OUT) :: i + end subroutine MPI_Allreduce + end interface +end module + +module modmpi + implicit none + integer ierror ! module variable = context NAMESPACE_DECL +end module + +subroutine exxengy + use modmpi + use mpi2, only: mpi_allreduce + implicit none + + ! intent(out) implies: ierror = {clobber} + call mpi_allreduce(ierror) + +contains + subroutine zrho2 + return + end subroutine +end subroutine + +! { dg-final { scan-tree-dump "ierror = {CLOBBER};" "original" } } diff --git a/gcc/tree-nested.c b/gcc/tree-nested.c index addd6eef9ab..cedeccac40b 100644 --- a/gcc/tree-nested.c +++ b/gcc/tree-nested.c @@ -382,7 +382,8 @@ static tree lookup_field_for_decl (struct nesting_info *info, tree decl, enum insert_option insert) { - gcc_checking_assert (decl_function_context (decl) == info->context); + gcc_checking_assert (decl_function_context (decl) == info->context + || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL); if (insert == NO_INSERT) {