From patchwork Thu Nov 5 21:57:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1395311 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 4CRy7d2ZD2z9sSn for ; Fri, 6 Nov 2020 08:58:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 840D33892016; Thu, 5 Nov 2020 21:58:01 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id BA13E3857831; Thu, 5 Nov 2020 21:57:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BA13E3857831 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: 2eTEdlngaCQb+yfYm90LWhUroJFe/P63ZqZYPW0rm+I14EWGVpD8rpPjMV1a8jWmhJiY7hygFA ZeWLoWfrEossywgNbKdTzm4TNAkAfiiXkY4GKfq/sNPLemDIhiU1ooE2MxV/9k2JAS9WylwiWq 9V0LhfSr1pP/6hTIi5j6a0NvPCZoS3wZkssPtIvhZGzD85vvf40rDRRL0ud/iLJnhowOYa15L/ +TFmeRw59rMAWK9zIpabhoxHgilJQl2LO0jgdk/ENlmLuhs3am+jV2gh++XLhmReu1KF6nt6Xh CQo= X-IronPort-AV: E=Sophos;i="5.77,454,1596528000"; d="diff'?scan'208";a="57032083" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 05 Nov 2020 13:57:57 -0800 IronPort-SDR: 33cZ1y9qgsjoIJUj5GlyMCyxOAzjP50ddLutrNzFyYGbdS1h8cytXe3p4AHziUxA6QJoGe7WMb VeBSkyO0wrsrJdlBI9K3RJsp0weC5L4nVjXB0se3HLt86gwpJgrEVDB34x0k8lN6sEpbJo0qj4 a2tvfoZkhk1xAj8Gy/mnkgpKEOcsroj0gssnWIv6k9zsNneevLwIR5rd3iCkd9U43gupvWnYTJ GHJp36CmuSaQjOhtiwqnmob/EgEWMPHVvhMN0AngwyzyE1x1JZt0C0jDF6IG6XCoPicDtN6vpd AM0= To: gcc-patches , =?utf-8?q?Martin_Li=C5=A1ka?= , fortran From: Tobias Burnus Subject: [Patch] Fortran: Fix function decl's location [PR95847] Message-ID: <6fa8e869-cdbe-2b6b-eab8-c76ea5eac022@codesourcery.com> Date: Thu, 5 Nov 2020 22:57:51 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-02.mgc.mentorg.com (139.181.222.2) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-12.5 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" In gfc_get_symbol_decl, if an external procedure is invoked and sym->backend_decl is NULL_TREE, gfc_get_extern_function_decl is called. This searches the translation unit (or gsym) to find the declaration – and if found, it returns it. Well, that worked and the module procedure's decl is returned with DECL_SOURCE_LOCATION() matching the original declaration and the associated cfun->function_end_location is also properly set. But before this patch, the location is reset to the sym->declared_at, which is the location of the "use foo" line in the example from the PR. Result: The DECL_SOURCE_LOCATION(cfun->decl) is *after* cfun->function_end_location, which runs with --coverage into an assert. The other changes to BIND_EXPR is unrelated. It was just that I did run with '-fdump-tree-original-lineno' and got: foo_suite () [coverage.f90:17:22] { integer(kind=4) res; [coverage.f90:16:17] res = bar ([coverage.f90:16:17] sbr); } Where line 17 for '{' looked odd. With the patch, we now have: foo_suite () [coverage.f90:12:0] { integer(kind=4) res; [coverage.f90:16:17] res = bar ([coverage.f90:16:17] sbr); } OK for the trunk? Tobias ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter Fortran: Fix function decl's location [PR95847] gcc/fortran/ChangeLog: PR fortran/95847 * trans-decl.c (gfc_get_symbol_decl): Do not (re)set the location of an external procedure. (build_entry_thunks, generate_coarray_init, create_main_function, gfc_generate_function_code): Use fndecl's location in BIND_EXPR. gcc/testsuite/ChangeLog: PR fortran/95847 * gfortran.dg/coverage.f90: New test. gcc/fortran/trans-decl.c | 19 ++++++++++--------- gcc/testsuite/gfortran.dg/coverage.f90 | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c index cdef753ea8d..71d5c670e55 100644 --- a/gcc/fortran/trans-decl.c +++ b/gcc/fortran/trans-decl.c @@ -1749,7 +1749,6 @@ gfc_get_symbol_decl (gfc_symbol * sym) || sym->attr.if_source != IFSRC_DECL) { decl = gfc_get_extern_function_decl (sym); - gfc_set_decl_location (decl, &sym->declared_at); } else { @@ -3021,8 +3020,9 @@ build_entry_thunks (gfc_namespace * ns, bool global) poplevel (1, 1); BLOCK_SUPERCONTEXT (DECL_INITIAL (thunk_fndecl)) = thunk_fndecl; DECL_SAVED_TREE (thunk_fndecl) - = build3_v (BIND_EXPR, tmp, DECL_SAVED_TREE (thunk_fndecl), - DECL_INITIAL (thunk_fndecl)); + = fold_build3_loc (DECL_SOURCE_LOCATION (thunk_fndecl), BIND_EXPR, + void_type_node, tmp, DECL_SAVED_TREE (thunk_fndecl), + DECL_INITIAL (thunk_fndecl)); /* Output the GENERIC tree. */ dump_function (TDI_original, thunk_fndecl); @@ -5786,8 +5786,8 @@ generate_coarray_init (gfc_namespace * ns __attribute((unused))) BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; DECL_SAVED_TREE (fndecl) - = build3_v (BIND_EXPR, decl, DECL_SAVED_TREE (fndecl), - DECL_INITIAL (fndecl)); + = fold_build3_loc (DECL_SOURCE_LOCATION (fndecl), BIND_EXPR, void_type_node, + decl, DECL_SAVED_TREE (fndecl), DECL_INITIAL (fndecl)); dump_function (TDI_original, fndecl); cfun->function_end_locus = input_location; @@ -6512,8 +6512,9 @@ create_main_function (tree fndecl) BLOCK_SUPERCONTEXT (DECL_INITIAL (ftn_main)) = ftn_main; DECL_SAVED_TREE (ftn_main) - = build3_v (BIND_EXPR, decl, DECL_SAVED_TREE (ftn_main), - DECL_INITIAL (ftn_main)); + = fold_build3_loc (DECL_SOURCE_LOCATION (ftn_main), BIND_EXPR, + void_type_node, decl, DECL_SAVED_TREE (ftn_main), + DECL_INITIAL (ftn_main)); /* Output the GENERIC tree. */ dump_function (TDI_original, ftn_main); @@ -7004,8 +7005,8 @@ gfc_generate_function_code (gfc_namespace * ns) BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl; DECL_SAVED_TREE (fndecl) - = build3_v (BIND_EXPR, decl, DECL_SAVED_TREE (fndecl), - DECL_INITIAL (fndecl)); + = fold_build3_loc (DECL_SOURCE_LOCATION (fndecl), BIND_EXPR, void_type_node, + decl, DECL_SAVED_TREE (fndecl), DECL_INITIAL (fndecl)); /* Output the GENERIC tree. */ dump_function (TDI_original, fndecl); diff --git a/gcc/testsuite/gfortran.dg/coverage.f90 b/gcc/testsuite/gfortran.dg/coverage.f90 new file mode 100644 index 00000000000..e0800f869c1 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/coverage.f90 @@ -0,0 +1,17 @@ +! { dg-do compile } +! { dg-additional-options "-fprofile-arcs -ftest-coverage" } +! +! PR fortran/95847 +! +module foo +contains + subroutine sbr() + end subroutine sbr +end module foo + +function foo_suite() result(suite) + use foo + integer :: bar + integer :: res + res = bar(sbr) +end function foo_suite