From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id nbniNkILyWpcZCAAWB0awg (envelope-from ) for ; Fri, 09 Oct 2026 11:41:54 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ZcWdLvwp; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id C66061E04E; Fri, 09 Oct 2026 11:41:54 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,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 B0FA91E04E for ; Fri, 09 Oct 2026 11:41:52 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AB0794BA2E12 for ; Fri, 9 Oct 2026 15:41:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB0794BA2E12 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ZcWdLvwp Received: from mail-oa1-x31.google.com (mail-oa1-x31.google.com [IPv6:2001:4860:4864:20::31]) by sourceware.org (Postfix) with ESMTPS id 4AD604BA5436 for ; Fri, 9 Oct 2026 15:41:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4AD604BA5436 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4AD604BA5436 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2001:4860:4864:20::31 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791560485; cv=none; b=j9cR4FNNqGji3p68N9ooSVDrdAIN8zGhBL+FXxxBtJXsO+H/M87E5NmgMNeqCtT67prNagxFsIyp/lAsWtSXOpvnHuVMlHlmvEA6Wkizh5Sn5/3G/8BPlFcm/yB5tBFExXSJ/IsPvsI415mVymlU6n+EqMUINRgT4dzhcbB9llM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791560485; c=relaxed/simple; bh=qZcHcjUn8/OSgGapLh4vMU53KJudaNcble6mztg1SVU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jBMwTzGSGCCk4H/CiEpH0zYtpmV6fmgiP01LSOjitcpGSy7VX+OG5apzY7A6WQ4toC79ghuct+kVqWpQKuFMf/rv2FTPDSrS6mRCs9LaSeo9k/tGZVUyuXfNxq0RjAoYHx9vNUtGQ/riNN/stf/q0vHsYH1kg760amcKu1xhwaU= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ZcWdLvwp DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4AD604BA5436 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-483c607ccb4so3584301fac.0 for ; Fri, 09 Oct 2026 08:41:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1791560484; x=1792165284; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=YLM93EcTOps4aN1jIkrx8qCoArKSTDnTD9MsiagQIeQ=; b=ZcWdLvwpf5fmb6Vrvun6w8xDCzMOphy18pwngeZCkkm4jeJQ9I8+x7cmfYQSsOFmMk 39xZ0UQ4jvskkJ9dqPHHgJ06GEimXkuIgUca3lxpvtSMkTnC9TsvW8bGaKoj4RRd3UT3 TqilIvTyyoktOeyr3d2ID1wCNfPNcYhCR2He/JwmWB3W5al8JpogIHJT3BsXpPpkiNPo 3Twfm52W35Reon7F6KYgNhQfvq3PO2FJLdUN9Wqa8oR+0ZSza9qsORrrG9658Pt8SATG siGWOGLT/UwS6MvfK4WAIS/0+W1wk9lnEFFe1g0vBKYSrA3DMryUJv9IWnKjYsuvfjeH VDmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791560484; x=1792165284; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=YLM93EcTOps4aN1jIkrx8qCoArKSTDnTD9MsiagQIeQ=; b=2G37Vh5+zw1YTC76By33V8d8KvDLWrrLu1jQzl5KvgeaBKdKKPSSlQJWF4XIc8WvQV PMwG4qPhB+5M+tfZq9K2hneS6eruHC+sqtqwzQAlRpbGlcU7gI9YYmg7wD4W7J+VQkuI PydcCmphUBL7x2ehrJdrVUKKMP7YBuMOLBQsqy/4LxX9lzxa/4u3jO2dXmzF7FWvXZ2q MBmdCf8x2rq4s0dmpjzmeM7T4PEdYQ7OcpjE/vMcBpRy+mtUHFecGjLnwSba9fbMaNTk /QUOmaNUfQAptSD9iJxivBI4HQx0yEytDhnFvW957I3Ij/ueonHkvX7xK9jwgSYYsb8A +/RQ== X-Gm-Message-State: AFq9FYIg91EXbnzufxUKIbHXhh7cuwfxQrp9stlP+FKIWqaJYXTr+y7K 53+Sq6tuUW1YkESdIIV7tAXZwXtb9E3zSd9JH30hc8+HHFCJjnzNEBgL2yJaOxTF8Edhn6vAFMo U8Zmk X-Gm-Gg: AYBFou3LImYoPiH1eTKezkr2CD+KL9p6g3oXS4yNt3sKNRPc4STRfuuxPqDbvtxkBQI w535SSIY5rRbb34agwH8Be6tfFKeURf4TkCyPlucv1OjVlpUD8JcfQy3RAtPXLAkTK/ruQlIVQC HsYNIPwsbsy3SoFYdj9um+6o421AK7Kn3iqxF8/ovSdoBqW+I2dgqx0q8gUodwAsbicmqS72PPw T+SVDJvEa2xgRdihgyeDnwVt35Lh91PJG29bX+ckAchVaIsupHZaXamIZKI3esexPQ8VavpIkm2 jG2RYnAoHpI6YO42FtR+cos9yk6nL4nS708EhF5Oq9rU886YAoU4yd5rYlrWhfzw5j2BNboZ1q1 XAtTW5gBuT3pUsczlWLCYrx4cJNOaKfklBLw5r9RzeBN2UmOH9eIiq44P0wuzG5fa6vy0ciajSH SJRCO1nd6QP/SOxugqtBY8o8W/m6Kbv2xbq8QQP9CKr0Oj1Msva5rKsPOOlA2K/Vz7Ibj/lmZW2 mMuC86A0yTvXEP+z2mmZ8nbSQW6NTUX72dVfa+BkvxqobWcvwMGXtU= X-Received: by 2002:a05:6870:46a1:b0:48f:e0f6:bd66 with SMTP id 586e51a60fabf-4a2a8b30b74mr2111698fac.55.1791560484069; Fri, 09 Oct 2026 08:41:24 -0700 (PDT) Received: from localhost.localdomain ([177.62.70.126]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4a2a865a441sm1794121fac.18.2026.10.09.08.41.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2026 08:41:23 -0700 (PDT) From: Adhemerval Zanella To: gdb-patches@sourceware.org Cc: Thiago Bauermann Subject: [PATCH] gdb/fortran: print rank only for arrays with unresolved dynamic bounds Date: Fri, 9 Oct 2026 10:41:05 -0500 Message-ID: <20261009154119.1603855-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Printing the type of a Fortran subroutine whose array parameter has bounds given by other variables, e.g. 'integer :: a(n1:n2)', failed with "Lower bound may not be '*' in F77", since the bounds of the function's parameter types are never resolved. Print only the array rank in this case, as is already done for other unresolved dynamic array types. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34698 --- gdb/f-typeprint.c | 27 ++++++++ .../gdb.dwarf2/fortran-var-string.exp | 25 +++----- .../gdb.fortran/array-dynamic-bounds.exp | 61 +++++++++++++++++++ .../gdb.fortran/array-dynamic-bounds.f90 | 32 ++++++++++ 4 files changed, 127 insertions(+), 18 deletions(-) create mode 100644 gdb/testsuite/gdb.fortran/array-dynamic-bounds.exp create mode 100644 gdb/testsuite/gdb.fortran/array-dynamic-bounds.f90 diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c index 123d9995c39..887e243c9b2 100644 --- a/gdb/f-typeprint.c +++ b/gdb/f-typeprint.c @@ -85,6 +85,26 @@ f_language::print_type (struct type *type, const char *varstring, } } +/* Return true if any dimension of the Fortran array TYPE has a bound that + can only be computed from an object (e.g. a bound given by another + variable). */ + +static bool +f_array_has_dynamic_bounds (struct type *type) +{ + for (; type->code () == TYPE_CODE_ARRAY; type = type->target_type ()) + { + const range_bounds *bounds = type->bounds (); + + if (!bounds->low.is_constant () + || !(bounds->high.is_constant () + || bounds->high.kind () == PROP_UNDEFINED)) + return true; + } + + return false; +} + /* See f-lang.h. */ void @@ -184,6 +204,13 @@ f_language::f_type_print_varspec_suffix (struct type *type, properties but cannot be resolved as there is no object. */ print_rank_only = true; } + else if (f_array_has_dynamic_bounds (type)) + { + /* Likewise for bounds that cannot be resolved. PRINT_RANK_ONLY is + only passed down to the inner dimensions, so check all of them + here so that either all or none of them are printed. */ + print_rank_only = true; + } if (type->target_type ()->code () == TYPE_CODE_ARRAY) f_type_print_varspec_suffix (type->target_type (), stream, 0, diff --git a/gdb/testsuite/gdb.dwarf2/fortran-var-string.exp b/gdb/testsuite/gdb.dwarf2/fortran-var-string.exp index 925872bc2c8..28703b1cfcb 100644 --- a/gdb/testsuite/gdb.dwarf2/fortran-var-string.exp +++ b/gdb/testsuite/gdb.dwarf2/fortran-var-string.exp @@ -150,24 +150,13 @@ gdb_test_no_output "set language fortran" gdb_test "info functions test_1_func" \ "2:\\s+integer test_1_func\\(character\\*\\(\\*\\)\\);" -# We print `1` here as the bound because GDB treats this as an assumed -# size array, and just reports the lower bound value for the upper -# bound. -# -# We might, in the future, decide that there's a better way we could -# tell the user about the type of this array argument, when that -# happens it's OK to change the expected results here. +# The array bounds are dynamic and there is no object to resolve them +# against, so only the rank of the array is printed. gdb_test "info functions test_2_func" \ - "3:\\s+integer test_2_func\\(integer \\(1\\)\\);" + "3:\\s+integer test_2_func\\(integer \\(:\\)\\);" -# It's not completely clear that this error is correct here. Why -# can't the lower bound be a dynamic expression? -# -# This test was initially added to guard against the case where GDB -# was crashing if/when it saw this situation. -# -# If later on, GDB's handling of array types with a dynamic loewr -# bound changes, then it is possible that the expected result here -# should change. +# Likewise for a dynamic lower bound. This test was initially added to +# guard against the case where GDB was crashing if/when it saw this +# situation. gdb_test "info functions test_3_func" \ - "4:\\s+Lower bound may not be '\\*' in F77" + "4:\\s+integer test_3_func\\(integer \\(:\\)\\);" diff --git a/gdb/testsuite/gdb.fortran/array-dynamic-bounds.exp b/gdb/testsuite/gdb.fortran/array-dynamic-bounds.exp new file mode 100644 index 00000000000..c42df7bfeb8 --- /dev/null +++ b/gdb/testsuite/gdb.fortran/array-dynamic-bounds.exp @@ -0,0 +1,61 @@ +# 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 . + +# Test printing the type of a subroutine whose array parameters have +# bounds given by other parameters (PR fortran/34698). + +require allow_fortran_tests + +standard_testfile .f90 +load_lib fortran.exp + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile \ + {debug f90}]} { + return +} + +set int4 [fortran_int4] + +# The type of SUB has no associated object, so the bounds of its array +# parameters cannot be resolved, even when SUB is executing. Only the +# rank of these arrays is printed. +set sub_args "$int4 \\(:\\), $int4, $int4, $int4 \\(:,:\\)" +set sub_type "void \\($sub_args\\)" + +gdb_test "print sub" " = \\{$sub_type\\} $hex " \ + "print sub before running" +gdb_test "ptype sub" "type = $sub_type" "ptype sub before running" +gdb_test "whatis sub" "type = $sub_type" "whatis sub before running" +gdb_test "info functions ^sub\$" "$decimal:\\s+void sub\\($sub_args\\);" \ + "info functions sub before running" + +if {![fortran_runto_main]} { + return +} + +gdb_breakpoint [gdb_get_line_number "Break here"] +gdb_continue_to_breakpoint "Break here" + +gdb_test_no_output "set print frame-arguments all" + +gdb_test "frame" \ + [multi_line \ + "#0 sub \\(a=\\(2, 3, 4, 5, 6\\), n1=2, n2=6, b=\\(\\(1, 2, 3, 4, 5\\) \\(6, 7, 8, 9, 10\\) \\(11, 12, 13, 14, 15\\)\\)\\) at \[^\r\n\]+" \ + "$decimal\\s+print \\*, a\\s+! Break here\\."] +gdb_test "print a" " = \\(2, 3, 4, 5, 6\\)" +gdb_test "ptype a" "type = $int4 \\(2:6\\)" +gdb_test "ptype b" "type = $int4 \\(2:6,3\\)" +gdb_test "print sub" " = \\{$sub_type\\} $hex " \ + "print sub with frame" diff --git a/gdb/testsuite/gdb.fortran/array-dynamic-bounds.f90 b/gdb/testsuite/gdb.fortran/array-dynamic-bounds.f90 new file mode 100644 index 00000000000..560ace3f2a8 --- /dev/null +++ b/gdb/testsuite/gdb.fortran/array-dynamic-bounds.f90 @@ -0,0 +1,32 @@ +! 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 . + +subroutine sub (a, n1, n2, b) + integer :: n1, n2 + integer :: a(n1:n2) + integer :: b(n1:n2, 3) + print *, a ! Break here. + print *, b +end subroutine sub + +program test + integer :: array(2:6) + integer :: array2(2:6, 3) + integer :: i + + array = [2, 3, 4, 5, 6] + array2 = reshape ([(i, i = 1, 15)], [5, 3]) + call sub (array, 2, 6, array2) +end program test -- 2.47.3