]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.fortran/function-calls.exp
Automatic Copyright Year update after running gdb/copyright.py
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.fortran / function-calls.exp
CommitLineData
4a94e368 1# Copyright 2019-2022 Free Software Foundation, Inc.
aa3cfbda
RB
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/> .
15
16# Exercise passing and returning arguments in Fortran. This test case
17# is based on the GNU Fortran Argument passing conventions.
18
19if {[skip_fortran_tests]} { return -1 }
20
21standard_testfile ".f90"
22
23if {[prepare_for_testing ${testfile}.exp ${testfile} ${srcfile} {debug f90}]} {
24 return -1
25}
26
cf2b2075
TV
27with_complaints 5 {
28 set cmd "maint expand-symtabs $srcfile"
29 set cmd_regexp [string_to_regexp $cmd]
30 set re_kfail [concat "During symbol reading:" \
31 " unable to find array range"]
32 gdb_test_multiple $cmd "no complaints in srcfile" {
33 -re -wrap "$re_kfail.*" {
34 kfail symtab/27388 $gdb_test_name
35 }
36 -re "^$cmd_regexp\r\n$gdb_prompt $" {
37 pass $gdb_test_name
38 }
39 }
40}
41
aa3cfbda
RB
42if {![runto [gdb_get_line_number "post_init"]]} then {
43 perror "couldn't run to breakpoint post_init"
44 continue
45}
46
47# Use inspired by gdb.base/callfuncs.exp.
48gdb_test_no_output "set unwindonsignal on"
49
50# Baseline: function and subroutine call with no arguments.
51gdb_test "p no_arg()" " = .TRUE."
52gdb_test_no_output "call no_arg_subroutine()"
53
54# Argument class: literal, inferior variable, convenience variable,
55# function call return value, function.
56# Paragraph 3: Variables are passed by reference.
57gdb_test "p one_arg(.TRUE.)" " = .TRUE."
58gdb_test "p one_arg(untrue)" " = .FALSE."
59gdb_test_no_output "set \$var = .FALSE."
60gdb_test "p one_arg(\$var)" " = .FALSE."
61gdb_test "p one_arg(one_arg(.TRUE.))" " = .TRUE."
62gdb_test "p one_arg(one_arg(.FALSE.))" " = .FALSE."
63gdb_test_no_output "call run(no_arg_subroutine)"
64
65# Return: constant.
66gdb_test "p return_constant()" " = 17"
67# Return derived type and call a function in a module.
68gdb_test "p derived_types_and_module_calls::build_cart(7,8)" \
69 " = \\\( x = 7, y = 8 \\\)"
70
71# Two hidden arguments. 1. returned string and 2. string length.
72# Paragraph 1.
73gdb_test "p return_string(returned_string_debugger, 40)" ""
74gdb_test "p returned_string_debugger" "'returned in hidden first argument '"
75
76# Argument type: real(kind=4), complex, array, pointer, derived type,
77# derived type with allocatable, nested derived type.
78# Paragraph 4: pointer.
79gdb_test "p pointer_function(int_pointer)" " = 87"
80# Paragraph 4: array.
81gdb_test "call array_function(integer_array)" " = 17"
82gdb_test "p derived_types_and_module_calls::pass_cart(c)" \
83 " = \\\( x = 2, y = 4 \\\)"
84# Allocatable elements in a derived type. Technical report ISO/IEC 15581.
85gdb_test "p derived_types_and_module_calls::pass_cart_nd(c_nd)" " = 4"
86gdb_test "p derived_types_and_module_calls::pass_nested_cart(nested_c)" \
87 "= \\\( d = \\\( x = 1, y = 2 \\\), z = 3 \\\)"
88# Result within some tolerance.
89gdb_test "p real4_argument(real4)" " = 3.${decimal}"
90
91# Paragraph 2. Complex argument and return.
92gdb_test "p complex_argument(fft)" " = \\\(2.${decimal},3.${decimal}\\\)"
93
94# Function with optional arguments.
95# Paragraph 10: Option reference arguments.
96gdb_test "p sum_some(1,2,3)" " = 6"
97
98# There is currently no mechanism to call a function without all
99# optional parameters present.
100setup_kfail "gdb/24147" *-*-*
101gdb_test "p sum_some(1,2)" " = 3"
102
103# Paragraph 10: optional value arguments. There is insufficient DWARF
104# information to reliably make this case work.
105setup_kfail "gdb/24305" *-*-*
106gdb_test "p one_arg_value(10)" " = 10"
107
108# DW_AT_artificial formal parameters must be passed manually. This
109# assert will fail if the length of the string is wrapped in a pointer.
110# Paragraph 7: Character type.
111gdb_test "p hidden_string_length('arbitrary string', 16)" " = 16"
112
113# Several arguments.
114gdb_test "p several_arguments(2, 3, 5)" " = 10"
115gdb_test "p mix_of_scalar_arguments(5, .TRUE., 3.5)" " = 9"
116
117# Calling other functions: Recursive call.
118gdb_test "p fibonacci(6)" " = 8"