This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 10/11] fortran: Fix sizeof in case pointer is not associated and allocated.


From: Bernhard Heckel <bernhard.heckel@intel.com>

2016-03-04  Bernhard Heckel  <bernhard.heckel@intel.com>

gdb/Changelog:

	* eval.c (evaluate_subexp_for_sizeof): Dereference pointer when
associated and allocated.

gdb/testsuite/Changelog:

	* gdb fortran/vla-sizeof.exp: Adapt expected output.
	* gdb.fortran/pointers.exp: Likewise.
---
 gdb/eval.c                             | 9 +++++++++
 gdb/testsuite/gdb.fortran/pointers.exp | 8 ++++++++
 2 files changed, 17 insertions(+)

diff --git a/gdb/eval.c b/gdb/eval.c
index 047aba59ae..3413e208e5 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -3248,6 +3248,15 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos,
   if (exp->language_defn->la_language == language_cplus
       && (TYPE_IS_REFERENCE (type)))
     type = check_typedef (TYPE_TARGET_TYPE (type));
+  else if (exp->language_defn->la_language == language_fortran)
+    {
+      if (type_not_associated (type) || type_not_allocated (type))
+	return value_from_longest (size_type, 0);
+
+      if (TYPE_CODE (type) == TYPE_CODE_PTR)
+	type = check_typedef (TYPE_TARGET_TYPE (type));
+    }
+
   return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
 }
 
diff --git a/gdb/testsuite/gdb.fortran/pointers.exp b/gdb/testsuite/gdb.fortran/pointers.exp
index 287803120a..4dcc5c61e3 100644
--- a/gdb/testsuite/gdb.fortran/pointers.exp
+++ b/gdb/testsuite/gdb.fortran/pointers.exp
@@ -94,6 +94,10 @@ gdb_continue_to_breakpoint "Before value assignment"
 gdb_test "print *(twop)%ivla2" "= <not allocated>"
 
 
+gdb_test "print sizeof(intp)" "= 4"
+gdb_test "print sizeof(realp)" "= 4"
+gdb_test "print sizeof(charap)" "= 3"
+
 gdb_breakpoint [gdb_get_line_number "After value assignment"]
 gdb_continue_to_breakpoint "After value assignment"
 gdb_test "print logp" "= \\(PTR TO -> \\( $logical \\)\\) $hex\( <.*>\)?"
@@ -155,3 +159,7 @@ gdb_test "print *((integer*) &inta + 2)" "= 3" "print temporary pointer, array"
 gdb_test "print *((integer*) &intvla + 3)" "= 4" "print temporary pointer, allocated vla"
 gdb_test "print \$pc" "= \\(PTR TO -> \\( void \\(\\)\\(\\)\\)\\) $hex <pointers\\+\\d+>" \
     "Print program counter"
+
+gdb_test "print sizeof(intp)" "= 4"
+gdb_test "print sizeof(realp)" "= 4"
+gdb_test "print sizeof(charap)" "= 3"
-- 
2.17.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]