]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.fortran/type-kinds.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.fortran / type-kinds.exp
CommitLineData
1d506c26 1# Copyright 2019-2024 Free Software Foundation, Inc.
4d00f5d8
AB
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# This is a set of tests related to GDB's ability to parse and
17# correctly handle the (kind=N) type adjustment mechanism within
18# Fortran.
19
20load_lib "fortran.exp"
21
57b7402d 22require allow_fortran_tests
4d00f5d8 23
3be47f7a
AB
24# Cast the value 1 to the type 'BASE_TYPE (kind=TYPE_KIND)'. The
25# expected result of the cast is CAST_RESULT, and the size of the
36c8fb93
AB
26# value returned by the cast should be SIZE_RESULT. If TYPE_KIND is
27# the empty string then the cast is done to just 'BASE_TYPE'.
3be47f7a 28proc test_cast_1_to_type_kind {base_type type_kind cast_result size_result} {
36c8fb93
AB
29 if { $type_kind != "" } {
30 set kind_string " (kind=$type_kind)"
31 } else {
32 set kind_string ""
33 }
34 set type_string "${base_type}${kind_string}"
3be47f7a 35 gdb_test "p (($type_string) 1)" " = $cast_result"
3be47f7a
AB
36 gdb_test "p sizeof (($type_string) 1)" " = $size_result"
37}
38
4d00f5d8
AB
39# Test parsing of `(kind=N)` type modifiers.
40proc test_basic_parsing_of_type_kinds {} {
4a270568 41 test_cast_1_to_type_kind "character" "1" "1 '\\\\001'" "1"
3be47f7a 42
36c8fb93 43 test_cast_1_to_type_kind "complex" "" "\\(1,0\\)" "8"
3be47f7a
AB
44 test_cast_1_to_type_kind "complex" "4" "\\(1,0\\)" "8"
45 test_cast_1_to_type_kind "complex" "8" "\\(1,0\\)" "16"
46 test_cast_1_to_type_kind "complex" "16" "\\(1,0\\)" "32"
47
36c8fb93 48 test_cast_1_to_type_kind "real" "" "1" "4"
3be47f7a
AB
49 test_cast_1_to_type_kind "real" "4" "1" "4"
50 test_cast_1_to_type_kind "real" "8" "1" "8"
51 test_cast_1_to_type_kind "real" "16" "1" "16"
52
36c8fb93 53 test_cast_1_to_type_kind "logical" "" "\\.TRUE\\." "4"
3be47f7a
AB
54 test_cast_1_to_type_kind "logical" "1" "\\.TRUE\\." "1"
55 test_cast_1_to_type_kind "logical" "4" "\\.TRUE\\." "4"
56 test_cast_1_to_type_kind "logical" "8" "\\.TRUE\\." "8"
57
36c8fb93 58 test_cast_1_to_type_kind "integer" "" "1" "4"
d4c94842 59 test_cast_1_to_type_kind "integer" "1" "1" "1"
3be47f7a
AB
60 test_cast_1_to_type_kind "integer" "2" "1" "2"
61 test_cast_1_to_type_kind "integer" "4" "1" "4"
067630bd 62 test_cast_1_to_type_kind "integer" "8" "1" "8"
36c8fb93
AB
63
64 test_cast_1_to_type_kind "double precision" "" "1" "8"
65 test_cast_1_to_type_kind "single precision" "" "1" "4"
66
67 test_cast_1_to_type_kind "double complex" "" "\\(1,0\\)" "16"
68 test_cast_1_to_type_kind "single complex" "" "\\(1,0\\)" "8"
3be47f7a
AB
69}
70
71proc test_parsing_invalid_type_kinds {} {
72 foreach typename {complex real logical integer} {
73 foreach typesize {3 5 7 9} {
74 gdb_test "p (($typename (kind=$typesize)) 1)" "unsupported kind $typesize for type $typename.*"
75 }
76 }
4d00f5d8
AB
77}
78
efbecbc1
AB
79# Perform some basic checks that GDB can parse the older style
80# TYPE*SIZE type names.
81proc test_old_star_type_sizes {} {
82 gdb_test "p ((character*1) 1)" " = 1 '\\\\001'"
83
84 gdb_test "p ((complex*4) 1)" " = \\(1,0\\)"
85 gdb_test "p ((complex*8) 1)" " = \\(1,0\\)"
86 gdb_test "p ((complex*16) 1)" " = \\(1,0\\)"
87
88 gdb_test "p ((real*4) 1)" " = 1"
89 gdb_test "p ((real*8) 1)" " = 1"
90 gdb_test "p ((real*16) 1)" " = 1"
91
92 gdb_test "p ((logical*1) 1)" " = \\.TRUE\\."
93 gdb_test "p ((logical*4) 1)" " = \\.TRUE\\."
94 gdb_test "p ((logical*8) 1)" " = \\.TRUE\\."
95
d4c94842 96 gdb_test "p ((integer*1) 1)" " = 1"
efbecbc1
AB
97 gdb_test "p ((integer*2) 1)" " = 1"
98 gdb_test "p ((integer*4) 1)" " = 1"
99 gdb_test "p ((integer*8) 1)" " = 1"
100}
101
4d00f5d8
AB
102clean_restart
103
49bb4744 104if {[set_lang_fortran]} {
4d00f5d8 105 test_basic_parsing_of_type_kinds
3be47f7a 106 test_parsing_invalid_type_kinds
efbecbc1 107 test_old_star_type_sizes
4d00f5d8
AB
108} else {
109 warning "$test_name tests suppressed." 0
110}