9d19a9ceb39a1f57c142067f7fc25864b7689be2
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.fortran / type-kinds.exp
1 # Copyright 2019 Free Software Foundation, Inc.
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
20 load_lib "fortran.exp"
21
22 if { [skip_fortran_tests] } { continue }
23
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
26 # value returned by the cast should be SIZE_RESULT.
27 proc test_cast_1_to_type_kind {base_type type_kind cast_result size_result} {
28 set type_string "$base_type (kind=$type_kind)"
29 gdb_test "p (($type_string) 1)" " = $cast_result"
30 gdb_test "p sizeof (($type_string) 1)" " = $size_result"
31 }
32
33 # Test parsing of `(kind=N)` type modifiers.
34 proc test_basic_parsing_of_type_kinds {} {
35 test_cast_1_to_type_kind "character" "1" "1 '\\\\001'" "1"
36
37 test_cast_1_to_type_kind "complex" "4" "\\(1,0\\)" "8"
38 test_cast_1_to_type_kind "complex" "8" "\\(1,0\\)" "16"
39 test_cast_1_to_type_kind "complex" "16" "\\(1,0\\)" "32"
40
41 test_cast_1_to_type_kind "real" "4" "1" "4"
42 test_cast_1_to_type_kind "real" "8" "1" "8"
43 test_cast_1_to_type_kind "real" "16" "1" "16"
44
45 test_cast_1_to_type_kind "logical" "1" "\\.TRUE\\." "1"
46 test_cast_1_to_type_kind "logical" "4" "\\.TRUE\\." "4"
47 test_cast_1_to_type_kind "logical" "8" "\\.TRUE\\." "8"
48
49 test_cast_1_to_type_kind "integer" "2" "1" "2"
50 test_cast_1_to_type_kind "integer" "4" "1" "4"
51 test_cast_1_to_type_kind "integer" "8" "1" "8"
52 }
53
54 proc test_parsing_invalid_type_kinds {} {
55 foreach typename {complex real logical integer} {
56 foreach typesize {3 5 7 9} {
57 gdb_test "p (($typename (kind=$typesize)) 1)" "unsupported kind $typesize for type $typename.*"
58 }
59 }
60 }
61
62 # Perform some basic checks that GDB can parse the older style
63 # TYPE*SIZE type names.
64 proc test_old_star_type_sizes {} {
65 gdb_test "p ((character*1) 1)" " = 1 '\\\\001'"
66
67 gdb_test "p ((complex*4) 1)" " = \\(1,0\\)"
68 gdb_test "p ((complex*8) 1)" " = \\(1,0\\)"
69 gdb_test "p ((complex*16) 1)" " = \\(1,0\\)"
70
71 gdb_test "p ((real*4) 1)" " = 1"
72 gdb_test "p ((real*8) 1)" " = 1"
73 gdb_test "p ((real*16) 1)" " = 1"
74
75 gdb_test "p ((logical*1) 1)" " = \\.TRUE\\."
76 gdb_test "p ((logical*4) 1)" " = \\.TRUE\\."
77 gdb_test "p ((logical*8) 1)" " = \\.TRUE\\."
78
79 gdb_test "p ((integer*2) 1)" " = 1"
80 gdb_test "p ((integer*4) 1)" " = 1"
81 gdb_test "p ((integer*8) 1)" " = 1"
82 }
83
84 clean_restart
85
86 if [set_lang_fortran] then {
87 test_basic_parsing_of_type_kinds
88 test_parsing_invalid_type_kinds
89 test_old_star_type_sizes
90 } else {
91 warning "$test_name tests suppressed." 0
92 }
This page took 0.035276 seconds and 3 git commands to generate.