[PATCH 07/11] gdb/fortran: Expand the set of types that support (kind=N)

Andrew Burgess
2019-02-12T16:11:23Z

Expand the number of types that can be adjusted with a (kind=N) type
extension.

gdb/ChangeLog:

* f-exp.y (convert_to_kind_type): Handle more type kinds.

gdb/testsuite/ChangeLog:

* gdb.fortran/type-kinds.exp (test_basic_parsing_of_type_kinds):
Expand types tested.
(test_parsing_invalid_type_kinds): New function.
---
gdb/ChangeLog | 4 ++++
gdb/f-exp.y | 36 ++++++++++++++++++++++++++++++++
gdb/testsuite/ChangeLog | 6 ++++++
gdb/testsuite/gdb.fortran/type-kinds.exp | 24 +++++++++++++++++++++
4 files changed, 70 insertions(+)

diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index 327f13736bd..980ee4b4adb 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -830,6 +830,42 @@ convert_to_kind_type (struct type *basetype, int kind)
if (kind == 1)
return parse_f_type (pstate)->builtin_character;
}
+ else if (basetype == parse_f_type (pstate)->builtin_complex_s8)
+ {
+ if (kind == 4)
+ return parse_f_type (pstate)->builtin_complex_s8;
+ else if (kind == 8)
+ return parse_f_type (pstate)->builtin_complex_s16;
+ else if (kind == 16)
+ return parse_f_type (pstate)->builtin_complex_s32;
+ }
+ else if (basetype == parse_f_type (pstate)->builtin_real)
+ {
+ if (kind == 4)
+ return parse_f_type (pstate)->builtin_real;
+ else if (kind == 8)
+ return parse_f_type (pstate)->builtin_real_s8;
+ else if (kind == 16)
+ return parse_f_type (pstate)->builtin_real_s16;
+ }
+ else if (basetype == parse_f_type (pstate)->builtin_logical)
+ {
+ if (kind == 1)
+ return parse_f_type (pstate)->builtin_logical_s1;
+ else if (kind == 2)
+ return parse_f_type (pstate)->builtin_logical_s2;
+ else if (kind == 4)
+ return parse_f_type (pstate)->builtin_logical;
+ else if (kind == 8)
+ return parse_f_type (pstate)->builtin_logical_s8;
+ }
+ else if (basetype == parse_f_type (pstate)->builtin_integer)
+ {
+ if (kind == 2)
+ return parse_f_type (pstate)->builtin_integer_s2;
+ else if (kind == 4)
+ return parse_f_type (pstate)->builtin_integer;
+ }

error (_("unsupported kind %d for type %s"),
kind, TYPE_SAFE_NAME (basetype));
diff --git a/gdb/testsuite/gdb.fortran/type-kinds.exp b/gdb/testsuite/gdb.fortran/type-kinds.exp
index b60b8044110..b2e64d77081 100644
--- a/gdb/testsuite/gdb.fortran/type-kinds.exp
+++ b/gdb/testsuite/gdb.fortran/type-kinds.exp
@@ -24,12 +24,36 @@ if { [skip_fortran_tests] } { continue }
# Test parsing of `(kind=N)` type modifiers.
proc test_basic_parsing_of_type_kinds {} {
gdb_test "p ((character (kind=1)) 1)" " = 1"
+
+ gdb_test "p ((complex (kind=4)) 1)" " = \\(1,0\\)"
+ gdb_test "p ((complex (kind=8)) 1)" " = \\(1,0\\)"
+ gdb_test "p ((complex (kind=16)) 1)" " = \\(1,0\\)"
+
+ gdb_test "p ((real (kind=4)) 1)" " = 1"
+ gdb_test "p ((real (kind=8)) 1)" " = 1"
+ gdb_test "p ((real (kind=16)) 1)" " = 1"
+
+ gdb_test "p ((logical (kind=1)) 1)" " = \\.TRUE\\."
+ gdb_test "p ((logical (kind=4)) 1)" " = \\.TRUE\\."
+ gdb_test "p ((logical (kind=8)) 1)" " = \\.TRUE\\."
+
+ gdb_test "p ((integer (kind=2)) 1)" " = 1"
+ gdb_test "p ((integer (kind=4)) 1)" " = 1"
+}
+
+proc test_parsing_invalid_type_kinds {} {
+ foreach typename {complex real logical integer} {
+ foreach typesize {3 5 7 9} {
+ gdb_test "p (($typename (kind=$typesize)) 1)" "unsupported kind $typesize for type $typename.*"
+ }
+ }
}

clean_restart

if [set_lang_fortran] then {
test_basic_parsing_of_type_kinds
+ test_parsing_invalid_type_kinds
} else {
warning "$test_name tests suppressed." 0
}
--
2.14.5