continue
}
+# Non-zero value to use as the function call count base. Using zero is avoided
+# as this is a common value in memory.
+set prime 17
+
+# Reset all call counts to the initial value ($prime).
+proc reset_called_flags { } {
+ global prime
+ foreach counter {no_arg no_arg_false one_arg two_arg array} {
+ gdb_test_no_output "set var calls%function_${counter}_called=$prime"
+ }
+}
+
+reset_called_flags
+
# Vary conditional and input over the standard truth table.
# Test that the debugger can evaluate expressions of the form
# a(x,y) .OR./.AND. a(a,b) correctly.
set trimmed_args [string trimright $argument_list ,]
set arg_lower [string tolower $arg]
gdb_test "p function_no_arg_false() .OR. function_${arg_lower}_arg($trimmed_args)" \
- " $arg, return true.\r\n\\\$$decimal = .TRUE."
- # Check the skipped function has not printed anything by asserting the
- # absence of the full stop from its message.
+ " = .TRUE."
+ reset_called_flags
gdb_test "p .TRUE. .OR. function_${arg_lower}_arg($trimmed_args)" \
- "\[^.\]\r\n\\\$$decimal = .TRUE."
+ " = .TRUE."
+ # Check that none of the short-circuited functions have been called.
+ gdb_test "p calls" \
+ " = \\\( function_no_arg_called = $prime, function_no_arg_false_called = $prime, function_one_arg_called = $prime, function_two_arg_called = $prime, function_array_called = $prime \\\)"
append argument_list " .TRUE.,"
}
-# Check nested calls
-gdb_test "p function_one_arg(.FALSE. .OR. function_no_arg())" \
- " No, return true.\r\n One, return true.\r\n\\\$$decimal = .TRUE."
+with_test_prefix "nested call not skipped" {
+ reset_called_flags
+ # Check nested calls
+ gdb_test "p function_one_arg(.FALSE. .OR. function_no_arg())" \
+ " = .TRUE."
+ gdb_test "p calls" \
+ " = \\\( function_no_arg_called = [expr $prime + 1], function_no_arg_false_called = $prime, function_one_arg_called = [expr $prime + 1], function_two_arg_called = $prime, function_array_called = $prime \\\)"
+}
-gdb_test "p function_one_arg(.TRUE. .OR. function_no_arg())" \
- "\[^.\]\r\n One, return true.\r\n\\\$$decimal = .TRUE."
+with_test_prefix "nested call skipped" {
+ gdb_test "p function_one_arg(.TRUE. .OR. function_no_arg())" \
+ " = .TRUE."
+ gdb_test "p calls" \
+ " = \\\( function_no_arg_called = [expr $prime + 1], function_no_arg_false_called = $prime, function_one_arg_called = [expr $prime + 2], function_two_arg_called = $prime, function_array_called = $prime \\\)"
+}
# Vary number of components in the expression to skip.
set expression "p .TRUE."
foreach_with_prefix expression_components {1 2 3 4} {
set expression "$expression .OR. function_one_arg(.TRUE.)"
gdb_test "$expression" \
- "\\\$$decimal = .TRUE."
+ " = .TRUE."
}
# Check parsing skipped substring operations.
-gdb_test "p .TRUE. .OR. binary_string(1)" "\\\$$decimal = .TRUE."
+gdb_test "p .TRUE. .OR. binary_string(1)" " = .TRUE."
# Check parsing skipped substring operations with ranges. These should all
# return true as the result is > 0.
foreach_with_prefix range1 {"1:2" ":" ":2" "1:"} {
foreach_with_prefix range2 {"1:2" ":" ":2" "1:"} {
gdb_test "p .TRUE. .OR. binary_string($range1) .OR. binary_string($range2)" \
- "\\\$$decimal = .TRUE."
+ " = .TRUE."
}
}
foreach_with_prefix range1 {"1:2" ":" ":2" "1:"} {
foreach_with_prefix range2 {"1:2" ":" ":2" "1:"} {
gdb_test "p .TRUE. .OR. binary_string($range1) .OR. truth_table($range2, 1)" \
- "\\\$$decimal = .TRUE."
+ " = .TRUE."
}
}
# Check evaluation of substring operations in logical expressions.
-gdb_test "p .FALSE. .OR. binary_string(1)" "\\\$$decimal = .FALSE."
-
-# Function call and substring skip.
-gdb_test "p .TRUE. .OR. function_one_arg(binary_string(1))" \
- "\\\$$decimal = .TRUE."
+gdb_test "p .FALSE. .OR. binary_string(1)" " = .FALSE."
+
+with_test_prefix "binary string skip" {
+ reset_called_flags
+ # Function call and substring skip.
+ gdb_test "p .TRUE. .OR. function_one_arg(binary_string(1))" \
+ " = .TRUE."
+ gdb_test "p calls%function_one_arg_called" " = $prime"
+}
-# Function call and array skip.
-gdb_test "p .TRUE. .OR. function_array(binary_string)" \
- "\\\$$decimal = .TRUE."
+with_test_prefix "array skip" {
+ # Function call and array skip.
+ reset_called_flags
+ gdb_test "p .TRUE. .OR. function_array(binary_string)" \
+ " = .TRUE."
+ gdb_test "p calls%function_array_called" " = $prime"
+}
! Source code for short-circuit-argument-list.exp.
+module called_state
+ implicit none
+ type called_counts
+ integer :: function_no_arg_called = 0
+ integer :: function_no_arg_false_called = 0
+ integer :: function_one_arg_called = 0
+ integer :: function_two_arg_called = 0
+ integer :: function_array_called = 0
+ end type
+ type(called_counts) :: calls
+end module called_state
+
logical function function_no_arg()
- print *, "No, return true."
+ use called_state
+ implicit none
+ calls%function_no_arg_called = calls%function_no_arg_called + 1
function_no_arg = .TRUE.
end function function_no_arg
logical function function_no_arg_false()
+ use called_state
+ implicit none
+ calls%function_no_arg_false_called = calls%function_no_arg_false_called + 1
function_no_arg_false = .FALSE.
end function function_no_arg_false
logical function function_one_arg(x)
+ use called_state
+ implicit none
logical, intent(in) :: x
- print *, "One, return true."
+ calls%function_one_arg_called = calls%function_one_arg_called + 1
function_one_arg = .TRUE.
end function function_one_arg
logical function function_two_arg(x, y)
+ use called_state
+ implicit none
logical, intent(in) :: x, y
- print *, "Two, return true."
+ calls%function_two_arg_called = calls%function_two_arg_called + 1
function_two_arg = .TRUE.
end function function_two_arg
logical function function_array(logical_array)
+ use called_state
+ implicit none
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)
+ calls%function_array_called = calls%function_array_called + 1
function_array = .TRUE.
end function function_array
program generate_truth_table
+ use called_state
implicit none
interface
logical function function_no_arg()