From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id l77PKy938mk5SQQAWB0awg (envelope-from ) for ; Wed, 29 Apr 2026 17:25:03 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=n+/EQ4A7; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id A020B1E093; Wed, 29 Apr 2026 17:25:03 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 0FCBA1E093 for ; Wed, 29 Apr 2026 17:25:02 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 0F7784BBC0C1 for ; Wed, 29 Apr 2026 21:25:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F7784BBC0C1 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=n+/EQ4A7 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) by sourceware.org (Postfix) with ESMTPS id 4D25F4BB3BCF for ; Wed, 29 Apr 2026 21:24:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4D25F4BB3BCF Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4D25F4BB3BCF Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.21 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777497874; cv=none; b=uZYu5sNr/MDW4Wlkn6q/0d1AO/HBPUCqCoypIXuFtScpi1GQDRa/24LyEpPvr4jI9kNN+qk1MKAFCS+gwXB5imKUd4G7pa4s9womepDgA+Bap8pb1KbK7HFIPODo2cuFT+rwo9g693ramMzudGzouuBehzwmE6lgjoS5FW9k1J0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777497874; c=relaxed/simple; bh=wUlM0MCUGUgVy34VJLoqVfogbbeJ8hX1gLc8pzcM/s8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=F7+sHyyarvgSQGAvxr78JbwIIrLkTvlo1cZJGcASL7eIFJlhYtcU6ZsLNdxpxY2LVOapiS5H1h/kPdUSQWm3eEJycVPzWFV/pngfxgCd2llY6ICuwBHkU+EgUOvzTF9jbsBfVDSn7nR/QSb8J8NXhh+e4SR4Yk/k7Uwa0TWj0T8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D25F4BB3BCF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1777497875; x=1809033875; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=wUlM0MCUGUgVy34VJLoqVfogbbeJ8hX1gLc8pzcM/s8=; b=n+/EQ4A7V0tLRMC8QNQ1lpvBqkX8+dcFrskEekq5EM9YIsYUEBBS77H+ 4Yz3ARvCyk9nSTvfIQFSaL/0/FCHhweCskJXDsgdRlohw/dgE9waei+2Z QVY78C6vF1iNyY16NO5Ehn+rRNSAQLFZb1f1vnl+M9qg4nOm5lITpXeue GMLtYv41AnSS649lOt9D1bWzhpNAPYl8uDYum/QosEqTUmYtk7L8JBgLk hsVejwv3woHnY1ZlXk/eX/fRyRNTUVyCkpCC2KKC5mjMd3XMnay2OggEX 03OfBeLpy5BA8WQFiObi7QmPha4VuKqYe3f+iYXPvBAEOOM2JCIuHZ2e7 w==; X-CSE-ConnectionGUID: jsYAAqg6ScmVtg4r3SQxqw== X-CSE-MsgGUID: mnYaxRZmS6KmISk20Fgg/Q== X-IronPort-AV: E=McAfee;i="6800,10657,11771"; a="78333527" X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="78333527" Received: from fmviesa010.fm.intel.com ([10.60.135.150]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 14:24:34 -0700 X-CSE-ConnectionGUID: OmxB+v9gTtSKaZ7d5Ou3dw== X-CSE-MsgGUID: g+GpAki1QTS5EkPbtrj77w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,206,1770624000"; d="scan'208";a="230028548" Received: from unknown (HELO localhost) ([10.245.116.136]) by fmviesa010-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2026 14:24:32 -0700 From: Abdul Basit Ijaz To: gdb-patches@sourceware.org Cc: abdul.b.ijaz@intel.com Subject: [PATCH 1/1] gdb/dwarf, fortran: Use the function scope for DW_TAG_imported_declaration Date: Wed, 29 Apr 2026 23:24:13 +0200 Message-Id: <20260429212413.150679-1-abdul.b.ijaz@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org All Fortran imported variable aliases (`use module, alias => var`) were being added to "global scope", regardless of whether they appeared in: - Program/module scope (should be global) - Function scope (should be local) This caused conflicts when different functions had the same alias name pointing to different variables. DW_TAG_imported_declaration and DW_TAG_namespace cases are now handled separately. The issue is Fortran-specific and does not affect DW_TAG_namespace. This patch modifies the case for DW_TAG_imported_ declaration in the function new_symbol () to use cu->list_in_scope instead of global symbols for Fortran. This ensures that function-scoped aliases use the current scope rather than being forced into the global scope. Bug Scenario: subroutine sub1 use mod1, var_i_alias=>var_i ! alias points to mod1::var_i var_i_alias = 3 var_i = 4 end subroutine subroutine sub2 use mod2, var_i_alias=>var_i ! alias points to mod2::var_i var_i_alias = 23 var_i = 25 end subroutine Before: var_i_alias in sub2 incorrectly resolved to mod1::var_i (value 25) After: Each function's alias correctly resolves to its own imported variable (value 23) New test files verify the fix and include regression tests for global program-scope imports: - gdb/testsuite/gdb.fortran/module_declarations.exp - gdb/testsuite/gdb.fortran/module_declarations.f90 Before the change: (gdb) print var_i_alias $4 = 25 FAIL: gdb.fortran/module_declarations.exp: sub2_test: print var_i_alias After the change: (gdb) print var_i_alias $4 = 23 PASS: gdb.fortran/module_declarations.exp: sub2_test: print var_i_alias --- gdb/dwarf2/read.c | 12 ++++ .../gdb.fortran/module_declarations.exp | 62 +++++++++++++++++++ .../gdb.fortran/module_declarations.f90 | 59 ++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 gdb/testsuite/gdb.fortran/module_declarations.exp create mode 100644 gdb/testsuite/gdb.fortran/module_declarations.f90 diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 1288c076aba..b7c96acc854 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -15858,6 +15858,18 @@ new_symbol (struct die_info *die, struct dwarf2_cu *cu, struct symbol *sym, : cu->list_in_scope); break; case DW_TAG_imported_declaration: + sym->set_domain (TYPE_DOMAIN); + sym->set_loc_class_index (LOC_TYPEDEF); + /* For Fortran imported declarations, use current scope context + rather than forcing global scope. This ensures variable aliases + are scoped correctly (function-level, module-level, or + program-level). */ + if (cu->lang () == language_fortran) + list_to_add = cu->list_in_scope; + else + list_to_add = &cu->get_builder ()->get_global_symbols (); + + break; case DW_TAG_namespace: sym->set_domain (TYPE_DOMAIN); sym->set_loc_class_index (LOC_TYPEDEF); diff --git a/gdb/testsuite/gdb.fortran/module_declarations.exp b/gdb/testsuite/gdb.fortran/module_declarations.exp new file mode 100644 index 00000000000..8953841c599 --- /dev/null +++ b/gdb/testsuite/gdb.fortran/module_declarations.exp @@ -0,0 +1,62 @@ +# Copyright 2026 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +load_lib "fortran.exp" + +require allow_fortran_tests + +standard_testfile .f90 + +if { [prepare_for_testing "failed to prepare" $testfile $srcfile {debug f90}] } { + return +} + +if {![fortran_runto_main]} { + return +} + +# Test global alias at program scope +gdb_breakpoint [gdb_get_line_number "bp-main"] +gdb_continue_to_breakpoint "bp-main" ".*bp-main.*" + +with_test_prefix "global_test" { + gdb_test "print global_alias" " = 200" + gdb_test "print global_var_i_from_mod1" " = 300" +} + +gdb_breakpoint [gdb_get_line_number "bp-sub1"] +gdb_continue_to_breakpoint "bp-sub1" ".*bp-sub1.*" + +with_test_prefix "sub1_test" { + gdb_test "print var_i_alias" " = 3" + gdb_test "print var_i" " = 4" +} + +gdb_breakpoint [gdb_get_line_number "bp-sub2"] +gdb_continue_to_breakpoint "bp-sub2" ".*bp-sub2.*" + +with_test_prefix "sub2_test" { + gdb_test "print var_i_alias" " = 23" + gdb_test "print var_i" " = 25" +} + +# Test same-name variables shadowed within same function +gdb_breakpoint [gdb_get_line_number "bp-sub3"] +gdb_continue_to_breakpoint "bp-sub3" ".*bp-sub3.*" + +with_test_prefix "sub3_shadow_test" { + gdb_test "print var_i_from_mod1" " = 31" + gdb_test "print var_i_from_mod2" " = 32" +} diff --git a/gdb/testsuite/gdb.fortran/module_declarations.f90 b/gdb/testsuite/gdb.fortran/module_declarations.f90 new file mode 100644 index 00000000000..314e2405b34 --- /dev/null +++ b/gdb/testsuite/gdb.fortran/module_declarations.f90 @@ -0,0 +1,59 @@ +! Copyright 2026 Free Software Foundation, Inc. +! +! This program is free software; you can redistribute it and/or modify +! it under the terms of the GNU General Public License as published by +! the Free Software Foundation; either version 3 of the License, or +! (at your option) any later version. +! +! This program is distributed in the hope that it will be useful, +! but WITHOUT ANY WARRANTY; without even the implied warranty of +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +! GNU General Public License for more details. +! +! You should have received a copy of the GNU General Public License +! along with this program. If not, see . + +module mod1 + implicit none + integer :: var_i = 1 + integer :: global_var = 100 +end module mod1 + +module mod2 + implicit none + integer :: var_i = 2 +end module mod2 + +subroutine sub1 + use mod1, var_i_alias=>var_i + use mod2 + implicit none + var_i_alias = 3 + var_i = 4 +end subroutine ! bp-sub1 + +subroutine sub2 + use mod1 + use mod2, var_i_alias=>var_i + implicit none + var_i_alias = 23 + var_i = 25 +end subroutine ! bp-sub2 + +subroutine sub3 + use mod1, var_i_from_mod1=>var_i + use mod2, var_i_from_mod2=>var_i + implicit none + var_i_from_mod1 = 31 + var_i_from_mod2 = 32 +end subroutine ! bp-sub3 + +program main + use mod1, global_alias=>global_var, global_var_i_from_mod1=>var_i + implicit none + global_alias = 200 + global_var_i_from_mod1 = 300 + call sub1 ! bp-main + call sub2 + call sub3 +end -- 2.34.1 Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 89 991 430, www.intel.de Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell Chairperson of the Supervisory Board: Nicole Lau Registered Seat: Munich Commercial Register: Amtsgericht Muenchen HRB 186928