Files
binutils-gdb/gdb/testsuite/gdb.fortran/short-circuit-argument-list.f90
Richard Bunt 23be8da739 Logical short circuiting with argument lists
When evaluating Fortran expressions such as the following:

	print truth_table(1,1) .OR. truth_table(2,1)

where truth_table(1,1) evaluates to true, the debugger would report that
it could not perform substring operations on this type. This patch
addresses this issue.

Investigation revealed that EVAL_SKIP was not being handled correctly
for all types serviced by the OP_F77_UNDETERMINED_ARGLIST case in
evaluate_subexp_standard. While skipping an undetermined argument list
the type is resolved to be an integer (as this is what evaluate_subexp
returns when skipping) and so it was not possible to delegate to the
appropriate case (e.g. array, function call).

The solution implemented here updates OP_VAR_VALUE to return correct
type information when skipping. This way OP_F77_UNDETERMINED_ARGLIST
can delegate the skipping to the appropriate case or routine, which
should know how to skip/evaluate the type in question.

koenig.exp was updated to include a testcase which exercises the
modified skip logic in OP_VAR_VALUE, as it falls through from
OP_ADL_FUNC.

This patch has been tested for regressions with GCC 7.3 on aarch64,
ppc64le and x86_64.

gdb/ChangeLog:

	* eval.c (skip_undetermined_arglist): Skip argument list helper.
	(evaluate_subexp_standard): Return a dummy type when
	honoring EVAL_SKIP in OP_VAR_VALUE and handle skipping in the
	OP_F77_UNDETERMINED_ARGLIST case.
	* expression.h (enum noside): Update comment.

gdb/testsuite/ChangeLog:

	* gdb.cp/koenig.exp: Extend to test logical short circuiting.
	* gdb.fortran/short-circuit-argument-list.exp: New file.
	* gdb.fortran/short-circuit-argument-list.f90: New test.
2018-09-19 10:43:56 +01:00

79 lines
2.6 KiB
Fortran

! Copyright 2018 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 <http://www.gnu.org/licenses/> .
! Source code for short-circuit-argument-list.exp.
logical function function_no_arg()
print *, "No, return true."
function_no_arg = .TRUE.
end function function_no_arg
logical function function_no_arg_false()
function_no_arg_false = .FALSE.
end function function_no_arg_false
logical function function_one_arg(x)
logical, intent(in) :: x
print *, "One, return true."
function_one_arg = .TRUE.
end function function_one_arg
logical function function_two_arg(x, y)
logical, intent(in) :: x, y
print *, "Two, return true."
function_two_arg = .TRUE.
end function function_two_arg
logical function function_array(logical_array)
logical, dimension(4,2), target, intent(in) :: logical_array
logical, dimension(:,:), pointer :: p
p => logical_array
print *, "Array, return true.", p(1,1), logical_array(1,1)
function_array = .TRUE.
end function function_array
program generate_truth_table
implicit none
interface
logical function function_no_arg()
end function function_no_arg
logical function function_no_arg_false()
end function
logical function function_one_arg(x)
logical, intent(in) :: x
end function
logical function function_two_arg(x, y)
logical, intent(in) :: x, y
end function
logical function function_array(logical_array)
logical, dimension(4,2), target, intent(in) :: logical_array
end function function_array
end interface
logical, dimension (4,2) :: truth_table
logical :: a, b, c, d, e
character(2) :: binary_string
binary_string = char(0) // char(1)
truth_table = .FALSE.
truth_table(3:4,1) = .TRUE.
truth_table(2::2,2) = .TRUE.
a = function_no_arg() ! post_truth_table_init
b = function_no_arg_false()
c = function_one_arg(b)
d = function_two_arg(a, b)
e = function_array(truth_table)
print *, truth_table(:, 1), a, b, e
print *, truth_table(:, 2), c, d
end program generate_truth_table