Blame SOURCES/gdb-rhbz1964167-move-fortran-expr-handling.patch

132741
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
132741
From: Kevin Buettner <kevinb@redhat.com>
132741
Date: Mon, 24 May 2021 17:00:17 -0700
132741
Subject: gdb-rhbz1964167-move-fortran-expr-handling.patch
132741
132741
;; [fortran] Backport Andrew Burgess's commit which moves Fortran
132741
;; expression handling to f-lang.c.
132741
132741
gdb/fortran: Move Fortran expression handling into f-lang.c
132741
132741
The Fortran specific OP_F77_UNDETERMINED_ARGLIST is currently handled
132741
in the generic expression handling code.  There's no reason why this
132741
should be the case, so this commit moves handling of this into Fortran
132741
specific files.
132741
132741
There should be no user visible changes after this commit.
132741
132741
gdb/ChangeLog:
132741
132741
	* eval.c: Remove 'f-lang.h' include.
132741
	(value_f90_subarray): Moved to f-lang.c.
132741
	(eval_call): Renamed to...
132741
	(evaluate_subexp_do_call): ...this, is no longer static, header
132741
	comment moved into header file.
132741
	(evaluate_funcall): Update call to eval_call.
132741
	(skip_undetermined_arglist): Moved to f-lang.c.
132741
	(fortran_value_subarray): Likewise.
132741
	(evaluate_subexp_standard): OP_F77_UNDETERMINED_ARGLIST handling
132741
	moved to evaluate_subexp_f.
132741
	(calc_f77_array_dims): Moved to f-lang.c
132741
	* expprint.c (print_subexp_funcall): New function.
132741
	(print_subexp_standard): OP_F77_UNDETERMINED_ARGLIST handling
132741
	moved to print_subexp_f, OP_FUNCALL uses new function.
132741
	(dump_subexp_body_funcall): New function.
132741
	(dump_subexp_body_standard): OP_F77_UNDETERMINED_ARGLIST handling
132741
	moved to dump_subexp_f, OP_FUNCALL uses new function.
132741
	* expression.h (evaluate_subexp_do_call): Declare.
132741
	* f-lang.c (value_f90_subarray): Moved from eval.c.
132741
	(skip_undetermined_arglist): Likewise.
132741
	(calc_f77_array_dims): Likewise.
132741
	(fortran_value_subarray): Likewise.
132741
	(evaluate_subexp_f): Add OP_F77_UNDETERMINED_ARGLIST support.
132741
	(operator_length_f): Likewise.
132741
	(print_subexp_f): Likewise.
132741
	(dump_subexp_body_f): Likewise.
132741
	* fortran-operator.def (OP_F77_UNDETERMINED_ARGLIST): Move
132741
	declaration of this operation to here.
132741
	* parse.c (operator_length_standard): OP_F77_UNDETERMINED_ARGLIST
132741
	support moved to operator_length_f.
132741
	* parser-defs.h (dump_subexp_body_funcall): Declare.
132741
	(print_subexp_funcall): Declare.
132741
	* std-operator.def (OP_F77_UNDETERMINED_ARGLIST): Moved to
132741
	fortran-operator.def.
132741
132741
diff --git a/gdb/eval.c b/gdb/eval.c
132741
--- a/gdb/eval.c
132741
+++ b/gdb/eval.c
132741
@@ -26,7 +26,6 @@
132741
 #include "frame.h"
132741
 #include "gdbthread.h"
132741
 #include "language.h"		/* For CAST_IS_CONVERSION.  */
132741
-#include "f-lang.h"		/* For array bound stuff.  */
132741
 #include "cp-abi.h"
132741
 #include "infcall.h"
132741
 #include "objc-lang.h"
132741
@@ -371,32 +370,6 @@ init_array_element (struct value *array, struct value *element,
132741
   return index;
132741
 }
132741
 
132741
-static struct value *
132741
-value_f90_subarray (struct value *array,
132741
-		    struct expression *exp, int *pos, enum noside noside)
132741
-{
132741
-  int pc = (*pos) + 1;
132741
-  LONGEST low_bound, high_bound;
132741
-  struct type *range = check_typedef (value_type (array)->index_type ());
132741
-  enum range_type range_type
132741
-    = (enum range_type) longest_to_int (exp->elts[pc].longconst);
132741
- 
132741
-  *pos += 3;
132741
-
132741
-  if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
132741
-    low_bound = range->bounds ()->low.const_val ();
132741
-  else
132741
-    low_bound = value_as_long (evaluate_subexp (nullptr, exp, pos, noside));
132741
-
132741
-  if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
132741
-    high_bound = range->bounds ()->high.const_val ();
132741
-  else
132741
-    high_bound = value_as_long (evaluate_subexp (nullptr, exp, pos, noside));
132741
-
132741
-  return value_slice (array, low_bound, high_bound - low_bound + 1);
132741
-}
132741
-
132741
-
132741
 /* Promote value ARG1 as appropriate before performing a unary operation
132741
    on this argument.
132741
    If the result is not appropriate for any particular language then it
132741
@@ -749,17 +722,13 @@ eval_skip_value (expression *exp)
132741
   return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1);
132741
 }
132741
 
132741
-/* Evaluate a function call.  The function to be called is in
132741
-   ARGVEC[0] and the arguments passed to the function are in
132741
-   ARGVEC[1..NARGS].  FUNCTION_NAME is the name of the function, if
132741
-   known.  DEFAULT_RETURN_TYPE is used as the function's return type
132741
-   if the return type is unknown.  */
132741
+/* See expression.h.  */
132741
 
132741
-static value *
132741
-eval_call (expression *exp, enum noside noside,
132741
-	   int nargs, value **argvec,
132741
-	   const char *function_name,
132741
-	   type *default_return_type)
132741
+value *
132741
+evaluate_subexp_do_call (expression *exp, enum noside noside,
132741
+			 int nargs, value **argvec,
132741
+			 const char *function_name,
132741
+			 type *default_return_type)
132741
 {
132741
   if (argvec[0] == NULL)
132741
     error (_("Cannot evaluate function -- may be inlined"));
132741
@@ -1230,20 +1199,8 @@ evaluate_funcall (type *expect_type, expression *exp, int *pos,
132741
       /* Nothing to be done; argvec already correctly set up.  */
132741
     }
132741
 
132741
-  return eval_call (exp, noside, nargs, argvec, var_func_name, expect_type);
132741
-}
132741
-
132741
-/* Helper for skipping all the arguments in an undetermined argument list.
132741
-   This function was designed for use in the OP_F77_UNDETERMINED_ARGLIST
132741
-   case of evaluate_subexp_standard as multiple, but not all, code paths
132741
-   require a generic skip.  */
132741
-
132741
-static void
132741
-skip_undetermined_arglist (int nargs, struct expression *exp, int *pos,
132741
-			   enum noside noside)
132741
-{
132741
-  for (int i = 0; i < nargs; ++i)
132741
-    evaluate_subexp (nullptr, exp, pos, noside);
132741
+  return evaluate_subexp_do_call (exp, noside, nargs, argvec,
132741
+				  var_func_name, expect_type);
132741
 }
132741
 
132741
 /* Return true if type is integral or reference to integral */
132741
@@ -1260,67 +1217,6 @@ is_integral_or_integral_reference (struct type *type)
132741
 	  && is_integral_type (TYPE_TARGET_TYPE (type)));
132741
 }
132741
 
132741
-/* Called from evaluate_subexp_standard to perform array indexing, and
132741
-   sub-range extraction, for Fortran.  As well as arrays this function
132741
-   also handles strings as they can be treated like arrays of characters.
132741
-   ARRAY is the array or string being accessed.  EXP, POS, and NOSIDE are
132741
-   as for evaluate_subexp_standard, and NARGS is the number of arguments
132741
-   in this access (e.g. 'array (1,2,3)' would be NARGS 3).  */
132741
-
132741
-static struct value *
132741
-fortran_value_subarray (struct value *array, struct expression *exp,
132741
-			int *pos, int nargs, enum noside noside)
132741
-{
132741
-  if (exp->elts[*pos].opcode == OP_RANGE)
132741
-    return value_f90_subarray (array, exp, pos, noside);
132741
-
132741
-  if (noside == EVAL_SKIP)
132741
-    {
132741
-      skip_undetermined_arglist (nargs, exp, pos, noside);
132741
-      /* Return the dummy value with the correct type.  */
132741
-      return array;
132741
-    }
132741
-
132741
-  LONGEST subscript_array[MAX_FORTRAN_DIMS];
132741
-  int ndimensions = 1;
132741
-  struct type *type = check_typedef (value_type (array));
132741
-
132741
-  if (nargs > MAX_FORTRAN_DIMS)
132741
-    error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
132741
-
132741
-  ndimensions = calc_f77_array_dims (type);
132741
-
132741
-  if (nargs != ndimensions)
132741
-    error (_("Wrong number of subscripts"));
132741
-
132741
-  gdb_assert (nargs > 0);
132741
-
132741
-  /* Now that we know we have a legal array subscript expression let us
132741
-     actually find out where this element exists in the array.  */
132741
-
132741
-  /* Take array indices left to right.  */
132741
-  for (int i = 0; i < nargs; i++)
132741
-    {
132741
-      /* Evaluate each subscript; it must be a legal integer in F77.  */
132741
-      value *arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
132741
-
132741
-      /* Fill in the subscript array.  */
132741
-      subscript_array[i] = value_as_long (arg2);
132741
-    }
132741
-
132741
-  /* Internal type of array is arranged right to left.  */
132741
-  for (int i = nargs; i > 0; i--)
132741
-    {
132741
-      struct type *array_type = check_typedef (value_type (array));
132741
-      LONGEST index = subscript_array[i - 1];
132741
-
132741
-      array = value_subscripted_rvalue (array, index,
132741
-					f77_get_lowerbound (array_type));
132741
-    }
132741
-
132741
-  return array;
132741
-}
132741
-
132741
 struct value *
132741
 evaluate_subexp_standard (struct type *expect_type,
132741
 			  struct expression *exp, int *pos,
132741
@@ -1335,7 +1231,6 @@ evaluate_subexp_standard (struct type *expect_type,
132741
   struct type *type;
132741
   int nargs;
132741
   struct value **argvec;
132741
-  int code;
132741
   int ix;
132741
   long mem_offset;
132741
   struct type **arg_types;
132741
@@ -1976,84 +1871,6 @@ evaluate_subexp_standard (struct type *expect_type,
132741
     case OP_FUNCALL:
132741
       return evaluate_funcall (expect_type, exp, pos, noside);
132741
 
132741
-    case OP_F77_UNDETERMINED_ARGLIST:
132741
-
132741
-      /* Remember that in F77, functions, substring ops and 
132741
-         array subscript operations cannot be disambiguated 
132741
-         at parse time.  We have made all array subscript operations, 
132741
-         substring operations as well as function calls  come here 
132741
-         and we now have to discover what the heck this thing actually was.
132741
-         If it is a function, we process just as if we got an OP_FUNCALL.  */
132741
-
132741
-      nargs = longest_to_int (exp->elts[pc + 1].longconst);
132741
-      (*pos) += 2;
132741
-
132741
-      /* First determine the type code we are dealing with.  */
132741
-      arg1 = evaluate_subexp (nullptr, exp, pos, noside);
132741
-      type = check_typedef (value_type (arg1));
132741
-      code = type->code ();
132741
-
132741
-      if (code == TYPE_CODE_PTR)
132741
-	{
132741
-	  /* Fortran always passes variable to subroutines as pointer.
132741
-	     So we need to look into its target type to see if it is
132741
-	     array, string or function.  If it is, we need to switch
132741
-	     to the target value the original one points to.  */ 
132741
-	  struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
132741
-
132741
-	  if (target_type->code () == TYPE_CODE_ARRAY
132741
-	      || target_type->code () == TYPE_CODE_STRING
132741
-	      || target_type->code () == TYPE_CODE_FUNC)
132741
-	    {
132741
-	      arg1 = value_ind (arg1);
132741
-	      type = check_typedef (value_type (arg1));
132741
-	      code = type->code ();
132741
-	    }
132741
-	} 
132741
-
132741
-      switch (code)
132741
-	{
132741
-	case TYPE_CODE_ARRAY:
132741
-	case TYPE_CODE_STRING:
132741
-	  return fortran_value_subarray (arg1, exp, pos, nargs, noside);
132741
-
132741
-	case TYPE_CODE_PTR:
132741
-	case TYPE_CODE_FUNC:
132741
-	case TYPE_CODE_INTERNAL_FUNCTION:
132741
-	  /* It's a function call.  */
132741
-	  /* Allocate arg vector, including space for the function to be
132741
-	     called in argvec[0] and a terminating NULL.  */
132741
-	  argvec = (struct value **)
132741
-	    alloca (sizeof (struct value *) * (nargs + 2));
132741
-	  argvec[0] = arg1;
132741
-	  tem = 1;
132741
-	  for (; tem <= nargs; tem++)
132741
-	    {
132741
-	      argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
132741
-	      /* Arguments in Fortran are passed by address.  Coerce the
132741
-		 arguments here rather than in value_arg_coerce as otherwise
132741
-		 the call to malloc to place the non-lvalue parameters in
132741
-		 target memory is hit by this Fortran specific logic.  This
132741
-		 results in malloc being called with a pointer to an integer
132741
-		 followed by an attempt to malloc the arguments to malloc in
132741
-		 target memory.  Infinite recursion ensues.  */
132741
-	      if (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC)
132741
-		{
132741
-		  bool is_artificial
132741
-		    = TYPE_FIELD_ARTIFICIAL (value_type (arg1), tem - 1);
132741
-		  argvec[tem] = fortran_argument_convert (argvec[tem],
132741
-							  is_artificial);
132741
-		}
132741
-	    }
132741
-	  argvec[tem] = 0;	/* signal end of arglist */
132741
-	  if (noside == EVAL_SKIP)
132741
-	    return eval_skip_value (exp);
132741
-	  return eval_call (exp, noside, nargs, argvec, NULL, expect_type);
132741
-
132741
-	default:
132741
-	  error (_("Cannot perform substring on this type"));
132741
-	}
132741
-
132741
     case OP_COMPLEX:
132741
       /* We have a complex number, There should be 2 floating 
132741
          point numbers that compose it.  */
132741
@@ -3346,27 +3163,3 @@ parse_and_eval_type (char *p, int length)
132741
     error (_("Internal error in eval_type."));
132741
   return expr->elts[1].type;
132741
 }
132741
-
132741
-/* Return the number of dimensions for a Fortran array or string.  */
132741
-
132741
-int
132741
-calc_f77_array_dims (struct type *array_type)
132741
-{
132741
-  int ndimen = 1;
132741
-  struct type *tmp_type;
132741
-
132741
-  if ((array_type->code () == TYPE_CODE_STRING))
132741
-    return 1;
132741
-
132741
-  if ((array_type->code () != TYPE_CODE_ARRAY))
132741
-    error (_("Can't get dimensions for a non-array type"));
132741
-
132741
-  tmp_type = array_type;
132741
-
132741
-  while ((tmp_type = TYPE_TARGET_TYPE (tmp_type)))
132741
-    {
132741
-      if (tmp_type->code () == TYPE_CODE_ARRAY)
132741
-	++ndimen;
132741
-    }
132741
-  return ndimen;
132741
-}
132741
diff --git a/gdb/expprint.c b/gdb/expprint.c
132741
--- a/gdb/expprint.c
132741
+++ b/gdb/expprint.c
132741
@@ -53,6 +53,25 @@ print_subexp (struct expression *exp, int *pos,
132741
   exp->language_defn->la_exp_desc->print_subexp (exp, pos, stream, prec);
132741
 }
132741
 
132741
+/* See parser-defs.h.  */
132741
+
132741
+void
132741
+print_subexp_funcall (struct expression *exp, int *pos,
132741
+		      struct ui_file *stream)
132741
+{
132741
+  (*pos) += 2;
132741
+  unsigned nargs = longest_to_int (exp->elts[*pos].longconst);
132741
+  print_subexp (exp, pos, stream, PREC_SUFFIX);
132741
+  fputs_filtered (" (", stream);
132741
+  for (unsigned tem = 0; tem < nargs; tem++)
132741
+    {
132741
+      if (tem != 0)
132741
+	fputs_filtered (", ", stream);
132741
+      print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
132741
+    }
132741
+  fputs_filtered (")", stream);
132741
+}
132741
+
132741
 /* Standard implementation of print_subexp for use in language_defn
132741
    vectors.  */
132741
 void
132741
@@ -187,18 +206,7 @@ print_subexp_standard (struct expression *exp, int *pos,
132741
       return;
132741
 
132741
     case OP_FUNCALL:
132741
-    case OP_F77_UNDETERMINED_ARGLIST:
132741
-      (*pos) += 2;
132741
-      nargs = longest_to_int (exp->elts[pc + 1].longconst);
132741
-      print_subexp (exp, pos, stream, PREC_SUFFIX);
132741
-      fputs_filtered (" (", stream);
132741
-      for (tem = 0; tem < nargs; tem++)
132741
-	{
132741
-	  if (tem != 0)
132741
-	    fputs_filtered (", ", stream);
132741
-	  print_subexp (exp, pos, stream, PREC_ABOVE_COMMA);
132741
-	}
132741
-      fputs_filtered (")", stream);
132741
+      print_subexp_funcall (exp, pos, stream);
132741
       return;
132741
 
132741
     case OP_NAME:
132741
@@ -796,6 +804,22 @@ dump_subexp_body (struct expression *exp, struct ui_file *stream, int elt)
132741
   return exp->language_defn->la_exp_desc->dump_subexp_body (exp, stream, elt);
132741
 }
132741
 
132741
+/* See parser-defs.h.  */
132741
+
132741
+int
132741
+dump_subexp_body_funcall (struct expression *exp,
132741
+			  struct ui_file *stream, int elt)
132741
+{
132741
+  int nargs = longest_to_int (exp->elts[elt].longconst);
132741
+  fprintf_filtered (stream, "Number of args: %d", nargs);
132741
+  elt += 2;
132741
+
132741
+  for (int i = 1; i <= nargs + 1; i++)
132741
+    elt = dump_subexp (exp, stream, elt);
132741
+
132741
+  return elt;
132741
+}
132741
+
132741
 /* Default value for subexp_body in exp_descriptor vector.  */
132741
 
132741
 int
132741
@@ -931,18 +955,7 @@ dump_subexp_body_standard (struct expression *exp,
132741
       elt += 2;
132741
       break;
132741
     case OP_FUNCALL:
132741
-    case OP_F77_UNDETERMINED_ARGLIST:
132741
-      {
132741
-	int i, nargs;
132741
-
132741
-	nargs = longest_to_int (exp->elts[elt].longconst);
132741
-
132741
-	fprintf_filtered (stream, "Number of args: %d", nargs);
132741
-	elt += 2;
132741
-
132741
-	for (i = 1; i <= nargs + 1; i++)
132741
-	  elt = dump_subexp (exp, stream, elt);
132741
-      }
132741
+      elt = dump_subexp_body_funcall (exp, stream, elt);
132741
       break;
132741
     case OP_ARRAY:
132741
       {
132741
diff --git a/gdb/expression.h b/gdb/expression.h
132741
--- a/gdb/expression.h
132741
+++ b/gdb/expression.h
132741
@@ -155,6 +155,18 @@ enum noside
132741
 extern struct value *evaluate_subexp_standard
132741
   (struct type *, struct expression *, int *, enum noside);
132741
 
132741
+/* Evaluate a function call.  The function to be called is in ARGVEC[0] and
132741
+   the arguments passed to the function are in ARGVEC[1..NARGS].
132741
+   FUNCTION_NAME is the name of the function, if known.
132741
+   DEFAULT_RETURN_TYPE is used as the function's return type if the return
132741
+   type is unknown.  */
132741
+
132741
+extern struct value *evaluate_subexp_do_call (expression *exp,
132741
+					      enum noside noside,
132741
+					      int nargs, value **argvec,
132741
+					      const char *function_name,
132741
+					      type *default_return_type);
132741
+
132741
 /* From expprint.c */
132741
 
132741
 extern void print_expression (struct expression *, struct ui_file *);
132741
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
132741
--- a/gdb/f-lang.c
132741
+++ b/gdb/f-lang.c
132741
@@ -114,6 +114,134 @@ enum f_primitive_types {
132741
   nr_f_primitive_types
132741
 };
132741
 
132741
+/* Called from fortran_value_subarray to take a slice of an array or a
132741
+   string.  ARRAY is the array or string to be accessed.  EXP, POS, and
132741
+   NOSIDE are as for evaluate_subexp_standard.  Return a value that is a
132741
+   slice of the array.  */
132741
+
132741
+static struct value *
132741
+value_f90_subarray (struct value *array,
132741
+		    struct expression *exp, int *pos, enum noside noside)
132741
+{
132741
+  int pc = (*pos) + 1;
132741
+  LONGEST low_bound, high_bound;
132741
+  struct type *range = check_typedef (value_type (array)->index_type ());
132741
+  enum range_type range_type
132741
+    = (enum range_type) longest_to_int (exp->elts[pc].longconst);
132741
+
132741
+  *pos += 3;
132741
+
132741
+  if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
132741
+    low_bound = range->bounds ()->low.const_val ();
132741
+  else
132741
+    low_bound = value_as_long (evaluate_subexp (nullptr, exp, pos, noside));
132741
+
132741
+  if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
132741
+    high_bound = range->bounds ()->high.const_val ();
132741
+  else
132741
+    high_bound = value_as_long (evaluate_subexp (nullptr, exp, pos, noside));
132741
+
132741
+  return value_slice (array, low_bound, high_bound - low_bound + 1);
132741
+}
132741
+
132741
+/* Helper for skipping all the arguments in an undetermined argument list.
132741
+   This function was designed for use in the OP_F77_UNDETERMINED_ARGLIST
132741
+   case of evaluate_subexp_standard as multiple, but not all, code paths
132741
+   require a generic skip.  */
132741
+
132741
+static void
132741
+skip_undetermined_arglist (int nargs, struct expression *exp, int *pos,
132741
+			   enum noside noside)
132741
+{
132741
+  for (int i = 0; i < nargs; ++i)
132741
+    evaluate_subexp (nullptr, exp, pos, noside);
132741
+}
132741
+
132741
+/* Return the number of dimensions for a Fortran array or string.  */
132741
+
132741
+int
132741
+calc_f77_array_dims (struct type *array_type)
132741
+{
132741
+  int ndimen = 1;
132741
+  struct type *tmp_type;
132741
+
132741
+  if ((array_type->code () == TYPE_CODE_STRING))
132741
+    return 1;
132741
+
132741
+  if ((array_type->code () != TYPE_CODE_ARRAY))
132741
+    error (_("Can't get dimensions for a non-array type"));
132741
+
132741
+  tmp_type = array_type;
132741
+
132741
+  while ((tmp_type = TYPE_TARGET_TYPE (tmp_type)))
132741
+    {
132741
+      if (tmp_type->code () == TYPE_CODE_ARRAY)
132741
+	++ndimen;
132741
+    }
132741
+  return ndimen;
132741
+}
132741
+
132741
+/* Called from evaluate_subexp_standard to perform array indexing, and
132741
+   sub-range extraction, for Fortran.  As well as arrays this function
132741
+   also handles strings as they can be treated like arrays of characters.
132741
+   ARRAY is the array or string being accessed.  EXP, POS, and NOSIDE are
132741
+   as for evaluate_subexp_standard, and NARGS is the number of arguments
132741
+   in this access (e.g. 'array (1,2,3)' would be NARGS 3).  */
132741
+
132741
+static struct value *
132741
+fortran_value_subarray (struct value *array, struct expression *exp,
132741
+			int *pos, int nargs, enum noside noside)
132741
+{
132741
+  if (exp->elts[*pos].opcode == OP_RANGE)
132741
+    return value_f90_subarray (array, exp, pos, noside);
132741
+
132741
+  if (noside == EVAL_SKIP)
132741
+    {
132741
+      skip_undetermined_arglist (nargs, exp, pos, noside);
132741
+      /* Return the dummy value with the correct type.  */
132741
+      return array;
132741
+    }
132741
+
132741
+  LONGEST subscript_array[MAX_FORTRAN_DIMS];
132741
+  int ndimensions = 1;
132741
+  struct type *type = check_typedef (value_type (array));
132741
+
132741
+  if (nargs > MAX_FORTRAN_DIMS)
132741
+    error (_("Too many subscripts for F77 (%d Max)"), MAX_FORTRAN_DIMS);
132741
+
132741
+  ndimensions = calc_f77_array_dims (type);
132741
+
132741
+  if (nargs != ndimensions)
132741
+    error (_("Wrong number of subscripts"));
132741
+
132741
+  gdb_assert (nargs > 0);
132741
+
132741
+  /* Now that we know we have a legal array subscript expression let us
132741
+     actually find out where this element exists in the array.  */
132741
+
132741
+  /* Take array indices left to right.  */
132741
+  for (int i = 0; i < nargs; i++)
132741
+    {
132741
+      /* Evaluate each subscript; it must be a legal integer in F77.  */
132741
+      value *arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
132741
+
132741
+      /* Fill in the subscript array.  */
132741
+      subscript_array[i] = value_as_long (arg2);
132741
+    }
132741
+
132741
+  /* Internal type of array is arranged right to left.  */
132741
+  for (int i = nargs; i > 0; i--)
132741
+    {
132741
+      struct type *array_type = check_typedef (value_type (array));
132741
+      LONGEST index = subscript_array[i - 1];
132741
+
132741
+      array = value_subscripted_rvalue (array, index,
132741
+					f77_get_lowerbound (array_type));
132741
+    }
132741
+
132741
+  return array;
132741
+}
132741
+
132741
 /* Special expression evaluation cases for Fortran.  */
132741
 
132741
 static struct value *
132741
@@ -285,6 +413,87 @@ evaluate_subexp_f (struct type *expect_type, struct expression *exp,
132741
 				   TYPE_LENGTH (type));
132741
       return value_from_longest (builtin_type (exp->gdbarch)->builtin_int,
132741
 				 TYPE_LENGTH (TYPE_TARGET_TYPE (type)));
132741
+
132741
+
132741
+    case OP_F77_UNDETERMINED_ARGLIST:
132741
+      /* Remember that in F77, functions, substring ops and array subscript
132741
+         operations cannot be disambiguated at parse time.  We have made
132741
+         all array subscript operations, substring operations as well as
132741
+         function calls come here and we now have to discover what the heck
132741
+         this thing actually was.  If it is a function, we process just as
132741
+         if we got an OP_FUNCALL.  */
132741
+      int nargs = longest_to_int (exp->elts[pc + 1].longconst);
132741
+      (*pos) += 2;
132741
+
132741
+      /* First determine the type code we are dealing with.  */
132741
+      arg1 = evaluate_subexp (nullptr, exp, pos, noside);
132741
+      type = check_typedef (value_type (arg1));
132741
+      enum type_code code = type->code ();
132741
+
132741
+      if (code == TYPE_CODE_PTR)
132741
+	{
132741
+	  /* Fortran always passes variable to subroutines as pointer.
132741
+	     So we need to look into its target type to see if it is
132741
+	     array, string or function.  If it is, we need to switch
132741
+	     to the target value the original one points to.  */
132741
+	  struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
132741
+
132741
+	  if (target_type->code () == TYPE_CODE_ARRAY
132741
+	      || target_type->code () == TYPE_CODE_STRING
132741
+	      || target_type->code () == TYPE_CODE_FUNC)
132741
+	    {
132741
+	      arg1 = value_ind (arg1);
132741
+	      type = check_typedef (value_type (arg1));
132741
+	      code = type->code ();
132741
+	    }
132741
+	}
132741
+
132741
+      switch (code)
132741
+	{
132741
+	case TYPE_CODE_ARRAY:
132741
+	case TYPE_CODE_STRING:
132741
+	  return fortran_value_subarray (arg1, exp, pos, nargs, noside);
132741
+
132741
+	case TYPE_CODE_PTR:
132741
+	case TYPE_CODE_FUNC:
132741
+	case TYPE_CODE_INTERNAL_FUNCTION:
132741
+	  {
132741
+	    /* It's a function call.  Allocate arg vector, including
132741
+	    space for the function to be called in argvec[0] and a
132741
+	    termination NULL.  */
132741
+	    struct value **argvec = (struct value **)
132741
+	      alloca (sizeof (struct value *) * (nargs + 2));
132741
+	    argvec[0] = arg1;
132741
+	    int tem = 1;
132741
+	    for (; tem <= nargs; tem++)
132741
+	      {
132741
+		argvec[tem] = evaluate_subexp_with_coercion (exp, pos, noside);
132741
+		/* Arguments in Fortran are passed by address.  Coerce the
132741
+		   arguments here rather than in value_arg_coerce as
132741
+		   otherwise the call to malloc to place the non-lvalue
132741
+		   parameters in target memory is hit by this Fortran
132741
+		   specific logic.  This results in malloc being called
132741
+		   with a pointer to an integer followed by an attempt to
132741
+		   malloc the arguments to malloc in target memory.
132741
+		   Infinite recursion ensues.  */
132741
+		if (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC)
132741
+		  {
132741
+		    bool is_artificial
132741
+		      = TYPE_FIELD_ARTIFICIAL (value_type (arg1), tem - 1);
132741
+		    argvec[tem] = fortran_argument_convert (argvec[tem],
132741
+							    is_artificial);
132741
+		  }
132741
+	      }
132741
+	    argvec[tem] = 0;	/* signal end of arglist */
132741
+	    if (noside == EVAL_SKIP)
132741
+	      return eval_skip_value (exp);
132741
+	    return evaluate_subexp_do_call (exp, noside, nargs, argvec, NULL,
132741
+					    expect_type);
132741
+	  }
132741
+
132741
+	default:
132741
+	  error (_("Cannot perform substring on this type"));
132741
+	}
132741
     }
132741
 
132741
   /* Should be unreachable.  */
132741
@@ -318,6 +527,11 @@ operator_length_f (const struct expression *exp, int pc, int *oplenp,
132741
       oplen = 1;
132741
       args = 2;
132741
       break;
132741
+
132741
+    case OP_F77_UNDETERMINED_ARGLIST:
132741
+      oplen = 3;
132741
+      args = 1 + longest_to_int (exp->elts[pc - 2].longconst);
132741
+      break;
132741
     }
132741
 
132741
   *oplenp = oplen;
132741
@@ -390,6 +604,10 @@ print_subexp_f (struct expression *exp, int *pos,
132741
     case BINOP_FORTRAN_MODULO:
132741
       print_binop_subexp_f (exp, pos, stream, prec, "MODULO");
132741
       return;
132741
+
132741
+    case OP_F77_UNDETERMINED_ARGLIST:
132741
+      print_subexp_funcall (exp, pos, stream);
132741
+      return;
132741
     }
132741
 }
132741
 
132741
@@ -432,6 +650,9 @@ dump_subexp_body_f (struct expression *exp,
132741
     case BINOP_FORTRAN_MODULO:
132741
       operator_length_f (exp, (elt + 1), &oplen, &nargs);
132741
       break;
132741
+
132741
+    case OP_F77_UNDETERMINED_ARGLIST:
132741
+      return dump_subexp_body_funcall (exp, stream, elt);
132741
     }
132741
 
132741
   elt += oplen;
132741
diff --git a/gdb/fortran-operator.def b/gdb/fortran-operator.def
132741
--- a/gdb/fortran-operator.def
132741
+++ b/gdb/fortran-operator.def
132741
@@ -17,6 +17,14 @@
132741
    You should have received a copy of the GNU General Public License
132741
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
132741
 
132741
+/* This is EXACTLY like OP_FUNCALL but is semantically different.
132741
+   In F77, array subscript expressions, substring expressions and
132741
+   function calls are all exactly the same syntactically.  They
132741
+   may only be disambiguated at runtime.  Thus this operator,
132741
+   which indicates that we have found something of the form
132741
+   <name> ( <stuff> ).  */
132741
+OP (OP_F77_UNDETERMINED_ARGLIST)
132741
+
132741
 /* Single operand builtins.  */
132741
 OP (UNOP_FORTRAN_KIND)
132741
 OP (UNOP_FORTRAN_FLOOR)
132741
diff --git a/gdb/parse.c b/gdb/parse.c
132741
--- a/gdb/parse.c
132741
+++ b/gdb/parse.c
132741
@@ -817,7 +817,6 @@ operator_length_standard (const struct expression *expr, int endpos,
132741
       break;
132741
 
132741
     case OP_FUNCALL:
132741
-    case OP_F77_UNDETERMINED_ARGLIST:
132741
       oplen = 3;
132741
       args = 1 + longest_to_int (expr->elts[endpos - 2].longconst);
132741
       break;
132741
diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
132741
--- a/gdb/parser-defs.h
132741
+++ b/gdb/parser-defs.h
132741
@@ -338,6 +338,13 @@ extern int dump_subexp (struct expression *, struct ui_file *, int);
132741
 extern int dump_subexp_body_standard (struct expression *, 
132741
 				      struct ui_file *, int);
132741
 
132741
+/* Dump (to STREAM) a function call like expression at position ELT in the
132741
+   expression array EXP.  Return a new value for ELT just after the
132741
+   function call expression.  */
132741
+
132741
+extern int dump_subexp_body_funcall (struct expression *exp,
132741
+				     struct ui_file *stream, int elt);
132741
+
132741
 extern void operator_length (const struct expression *, int, int *, int *);
132741
 
132741
 extern void operator_length_standard (const struct expression *, int, int *,
132741
@@ -440,6 +447,15 @@ extern void print_subexp (struct expression *, int *, struct ui_file *,
132741
 extern void print_subexp_standard (struct expression *, int *, 
132741
 				   struct ui_file *, enum precedence);
132741
 
132741
+/* Print a function call like expression to STREAM.  This is called as a
132741
+   helper function by which point the expression node identifying this as a
132741
+   function call has already been stripped off and POS should point to the
132741
+   number of function call arguments.  EXP is the object containing the
132741
+   list of expression elements.  */
132741
+
132741
+extern void print_subexp_funcall (struct expression *exp, int *pos,
132741
+				  struct ui_file *stream);
132741
+
132741
 /* Function used to avoid direct calls to fprintf
132741
    in the code generated by the bison parser.  */
132741
 
132741
diff --git a/gdb/std-operator.def b/gdb/std-operator.def
132741
--- a/gdb/std-operator.def
132741
+++ b/gdb/std-operator.def
132741
@@ -168,14 +168,6 @@ OP (OP_FUNCALL)
132741
    pointer.  This is an Objective C message.  */
132741
 OP (OP_OBJC_MSGCALL)
132741
 
132741
-/* This is EXACTLY like OP_FUNCALL but is semantically different.
132741
-   In F77, array subscript expressions, substring expressions and
132741
-   function calls are all exactly the same syntactically.  They
132741
-   may only be disambiguated at runtime.  Thus this operator,
132741
-   which indicates that we have found something of the form
132741
-   <name> ( <stuff> ).  */
132741
-OP (OP_F77_UNDETERMINED_ARGLIST)
132741
-
132741
 /* OP_COMPLEX takes a type in the following element, followed by another
132741
    OP_COMPLEX, making three exp_elements.  It is followed by two double
132741
    args, and converts them into a complex number of the given type.  */