public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* GDB/Fortran: Support for Assumed Rank Zero.
@ 2022-04-13  9:55 Potharla, Rupesh
  2022-04-13 18:27 ` Kevin Buettner
  0 siblings, 1 reply; 21+ messages in thread
From: Potharla, Rupesh @ 2022-04-13  9:55 UTC (permalink / raw)
  To: gdb-patches
  Cc: George, Jini Susan, Parasuraman, Hariharan, Sharma, Alok Kumar

[-- Attachment #1: Type: text/plain, Size: 784 bytes --]

[AMD Official Use Only]


Hi,



Requesting to review the attached patch.





If a variable is passed to function in FORTRAN as an argument the
variable is treated as an array with rank zero. GDB currently does
not support the case for assumed rank 0. This patch provides support
for assumed rank 0 and updates the testcase as well.

Without patch:
Breakpoint 1, arank::sub1 (a=<error reading variable:
  failed to resolve dynamic array rank>) at assumedrank.f90:11
11       PRINT *, RANK(a)
(gdb) p a
failed to resolve dynamic array rank
(gdb) p rank(a)
failed to resolve dynamic array rank

With patch:
Breakpoint 1, arank::sub1 (a=0) at assumedrank.f90:11
11       PRINT *, RANK(a)
(gdb) p a
$1 = 0
(gdb) p rank(a)
$2 = 0

Regards,
Rupesh P


[-- Attachment #2: 0001-gdb-fortran-Support-for-assumed-rank-zero.patch --]
[-- Type: application/octet-stream, Size: 3360 bytes --]

From 33e5f26535788bc413ff48ae58d9d82faefcf439 Mon Sep 17 00:00:00 2001
From: rupothar <rupesh.potharla@amd.com>
Date: Fri, 8 Apr 2022 16:05:41 +0530
Subject: [PATCH] gdb/fortran: Support for assumed rank zero

If a variable is passed to function in FORTRAN as an argument the
variable is treated as an array with rank zero. GDB currently does
not support the case for assumed rank 0. This patch provides support
for assumed rank 0 and updates the testcase as well.

Without patch:
Breakpoint 1, arank::sub1 (a=<error reading variable:
  failed to resolve dynamic array rank>) at assumedrank.f90:11
11       PRINT *, RANK(a)
(gdb) p a
failed to resolve dynamic array rank
(gdb) p rank(a)
failed to resolve dynamic array rank

With patch:
Breakpoint 1, arank::sub1 (a=0) at assumedrank.f90:11
11       PRINT *, RANK(a)
(gdb) p a
$1 = 0
(gdb) p rank(a)
$2 = 0
---
 gdb/gdbtypes.c                            | 10 ++++++----
 gdb/testsuite/gdb.fortran/assumedrank.exp |  7 +++++++
 gdb/testsuite/gdb.fortran/assumedrank.f90 |  3 +++
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 49ecb199b07..c2d142ac3cc 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2398,10 +2398,12 @@ resolve_dynamic_array_or_string (struct type *type,
 
       if (rank == 0)
 	{
-	  /* The dynamic property list juggling below was from the original
-	     patch.  I don't understand what this is all about, so I've
-	     commented it out for now and added the following error.  */
-	  error (_("failed to resolve dynamic array rank"));
+	  /* Rank is zero, if a variable is passed as an argument to a
+	     function. GDB considers the variable as an array so discard
+	     the array type and return the target type which is of variable. */
+          TYPE_DYN_PROP(TYPE_TARGET_TYPE(type)) = TYPE_DYN_PROP(type);
+          type = TYPE_TARGET_TYPE(type);
+          return type;
 	}
       else if (type->code () == TYPE_CODE_STRING && rank != 1)
 	{
diff --git a/gdb/testsuite/gdb.fortran/assumedrank.exp b/gdb/testsuite/gdb.fortran/assumedrank.exp
index 69cd168125f..49b03e2f87f 100644
--- a/gdb/testsuite/gdb.fortran/assumedrank.exp
+++ b/gdb/testsuite/gdb.fortran/assumedrank.exp
@@ -14,6 +14,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/> .
 
 # Testing GDB's implementation of ASSUMED RANK arrays.
+#Until the assumed rank zero is fixed in clang, XFAIL this case for clang.
 
 if {[skip_fortran_tests]} { return -1 }
 
@@ -58,6 +59,12 @@ while { $test_count < 500 } {
 	    }
 	}
 
+	# xfail rank 0 for clang
+	if {$test_count == 1 && [test_compiler_info {clang-*}]} {
+	   xfail "clang compiler does not support rank0"
+           continue
+	}
+
 	if ($found_final_breakpoint) {
 	    break
 	}
diff --git a/gdb/testsuite/gdb.fortran/assumedrank.f90 b/gdb/testsuite/gdb.fortran/assumedrank.f90
index 7f077c3f014..7f7cf2c1f3e 100644
--- a/gdb/testsuite/gdb.fortran/assumedrank.f90
+++ b/gdb/testsuite/gdb.fortran/assumedrank.f90
@@ -19,16 +19,19 @@
 
 PROGRAM  arank
 
+  REAL :: array0
   REAL :: array1(10)
   REAL :: array2(1, 2)
   REAL :: array3(3, 4, 5)
   REAL :: array4(4, 5, 6, 7)
 
+  array0 = 0
   array1 = 1.0
   array2 = 2.0
   array3 = 3.0
   array4 = 4.0
 
+  call test_rank (array0)
   call test_rank (array1)
   call test_rank (array2)
   call test_rank (array3)
-- 
2.17.1


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2022-04-25  8:47 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-13  9:55 GDB/Fortran: Support for Assumed Rank Zero Potharla, Rupesh
2022-04-13 18:27 ` Kevin Buettner
2022-04-14 10:30   ` Potharla, Rupesh
2022-04-14 21:28     ` Kevin Buettner
2022-04-15 13:33       ` Potharla, Rupesh
2022-04-15 19:31         ` Kevin Buettner
2022-04-16 18:29           ` Potharla, Rupesh
2022-04-18 13:31             ` Tom Tromey
2022-04-18 15:25               ` Potharla, Rupesh
2022-04-20 15:22                 ` Andrew Burgess
2022-04-20 19:08                   ` Potharla, Rupesh
2022-04-22 14:38                     ` Andrew Burgess
2022-04-25  6:33                       ` Potharla, Rupesh
2022-04-25  8:47                         ` Andrew Burgess
2022-04-18 15:33             ` Kevin Buettner
2022-04-19 17:30               ` Kevin Buettner
2022-04-20  0:29                 ` Potharla, Rupesh
2022-04-20  6:32                   ` Kempke, Nils-Christian
2022-04-20 15:38                     ` Kevin Buettner
2022-04-20 15:29                   ` Andrew Burgess
2022-04-20 19:20                     ` Potharla, Rupesh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).