public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] gdb/fortran: Support for assumed rank zero
@ 2022-04-25  9:29 Alok Kumar Sharma
  0 siblings, 0 replies; only message in thread
From: Alok Kumar Sharma @ 2022-04-25  9:29 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5f59e7e0c75a35f32f11bf6998c2e3de333fe3b2

commit 5f59e7e0c75a35f32f11bf6998c2e3de333fe3b2
Author: rupothar <rupesh.potharla@amd.com>
Date:   Fri Apr 8 16:05:41 2022 +0530

    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

Diff:
---
 gdb/gdbtypes.c                            | 22 ++++++++++++++++++----
 gdb/gdbtypes.h                            |  1 -
 gdb/testsuite/gdb.fortran/assumedrank.exp |  6 ++++++
 gdb/testsuite/gdb.fortran/assumedrank.f90 |  3 +++
 4 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 49ecb199b07..2a51372a037 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -47,6 +47,9 @@
 /* The value of an invalid conversion badness.  */
 #define INVALID_CONVERSION 100
 
+static struct dynamic_prop_list *
+copy_dynamic_prop_list (struct obstack *, struct dynamic_prop_list *);
+
 /* Initialize BADNESS constants.  */
 
 const struct rank LENGTH_MISMATCH_BADNESS = {INVALID_CONVERSION,0};
@@ -2398,10 +2401,21 @@ 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.  In this case the resolved type should not be an
+	     array, but should instead be that of an array element.  */
+	  struct type *dynamic_array_type = type;
+	  type = copy_type (TYPE_TARGET_TYPE (dynamic_array_type));
+	  struct dynamic_prop_list *prop_list
+	    = TYPE_MAIN_TYPE (dynamic_array_type)->dyn_prop_list;
+	  if (prop_list != nullptr)
+	    {
+	      struct obstack *obstack
+		= &type->objfile_owner ()->objfile_obstack;
+	      TYPE_MAIN_TYPE (type)->dyn_prop_list
+		= copy_dynamic_prop_list (obstack, prop_list);
+	    }
+	  return type;
 	}
       else if (type->code () == TYPE_CODE_STRING && rank != 1)
 	{
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 769328cc9cd..7437e1db8ab 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -2092,7 +2092,6 @@ extern void allocate_gnat_aux_type (struct type *);
 #define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type
 #define TYPE_RVALUE_REFERENCE_TYPE(thistype) (thistype)->rvalue_reference_type
 #define TYPE_CHAIN(thistype) (thistype)->chain
-#define TYPE_DYN_PROP(thistype)  TYPE_MAIN_TYPE(thistype)->dyn_prop_list
 /* * Note that if thistype is a TYPEDEF type, you have to call check_typedef.
    But check_typedef does set the TYPE_LENGTH of the TYPEDEF type,
    so you only have to call check_typedef once.  Since allocate_value
diff --git a/gdb/testsuite/gdb.fortran/assumedrank.exp b/gdb/testsuite/gdb.fortran/assumedrank.exp
index 69cd168125f..e9429b44a9a 100644
--- a/gdb/testsuite/gdb.fortran/assumedrank.exp
+++ b/gdb/testsuite/gdb.fortran/assumedrank.exp
@@ -58,6 +58,12 @@ while { $test_count < 500 } {
 	    }
 	}
 
+	# Currently, flang does not support rank0.
+	if {$test_count == 1 && [test_compiler_info {clang-*}]} {
+	   unsupported "compiler does not support rank 0"
+	   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)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-25  9:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-25  9:29 [binutils-gdb] gdb/fortran: Support for assumed rank zero Alok Kumar Sharma

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).