binutils-gdb/gdb/testsuite/gdb.fortran/intrinsics.exp

128 lines
4.1 KiB
Plaintext
Raw Normal View History

# Copyright 2019-2024 Free Software Foundation, Inc.
gdb/fortran: Add Fortran 'kind' intrinsic and keyword The 'kind' keyword has two uses in Fortran, it is the name of a builtin intrinsic function, and it is also a keyword used to create a type of a specific kind. This commit adds support for using kind as an intrinsic function, and also adds some initial support for using kind to create types of a specific kind. This commit only allows the creation of the type 'character(kind=1)', however, it will be easy enough to extend this in future to support more type kinds. The kind of any expression can be queried using the kind intrinsic function. At the moment the kind returned corresponds to the size of the type, this matches how gfortran handles kinds. However, the correspondence between kind and type size depends on the compiler and/or the specific target, so this might not be correct for everyone. If we want to support different compilers/targets in future the code to compute the kind from a type will need to be updated. gdb/ChangeLog: * expprint.c (dump_subexp_body_standard): Support UNOP_KIND. * f-exp.y: Define 'KIND' token. (exp): New pattern for KIND expressions. (ptype): Handle types with a kind extension. (direct_abs_decl): Extend to spot kind extensions. (f77_keywords): Add 'kind' to the list. (push_kind_type): New function. (convert_to_kind_type): New function. * f-lang.c (evaluate_subexp_f): Support UNOP_KIND. * parse.c (operator_length_standard): Likewise. * parser-defs.h (enum type_pieces): Add tp_kind. * std-operator.def: Add UNOP_KIND. gdb/testsuite/ChangeLog: * gdb.fortran/intrinsics.exp: New file. * gdb.fortran/intrinsics.f90: New file. * gdb.fortran/type-kinds.exp: New file.
2019-01-17 00:42:10 +08:00
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This file tests GDB's handling of Fortran builtin intrinsic functions.
load_lib "fortran.exp"
require allow_fortran_tests
gdb/fortran: Add Fortran 'kind' intrinsic and keyword The 'kind' keyword has two uses in Fortran, it is the name of a builtin intrinsic function, and it is also a keyword used to create a type of a specific kind. This commit adds support for using kind as an intrinsic function, and also adds some initial support for using kind to create types of a specific kind. This commit only allows the creation of the type 'character(kind=1)', however, it will be easy enough to extend this in future to support more type kinds. The kind of any expression can be queried using the kind intrinsic function. At the moment the kind returned corresponds to the size of the type, this matches how gfortran handles kinds. However, the correspondence between kind and type size depends on the compiler and/or the specific target, so this might not be correct for everyone. If we want to support different compilers/targets in future the code to compute the kind from a type will need to be updated. gdb/ChangeLog: * expprint.c (dump_subexp_body_standard): Support UNOP_KIND. * f-exp.y: Define 'KIND' token. (exp): New pattern for KIND expressions. (ptype): Handle types with a kind extension. (direct_abs_decl): Extend to spot kind extensions. (f77_keywords): Add 'kind' to the list. (push_kind_type): New function. (convert_to_kind_type): New function. * f-lang.c (evaluate_subexp_f): Support UNOP_KIND. * parse.c (operator_length_standard): Likewise. * parser-defs.h (enum type_pieces): Add tp_kind. * std-operator.def: Add UNOP_KIND. gdb/testsuite/ChangeLog: * gdb.fortran/intrinsics.exp: New file. * gdb.fortran/intrinsics.f90: New file. * gdb.fortran/type-kinds.exp: New file.
2019-01-17 00:42:10 +08:00
standard_testfile .f90
if { [prepare_for_testing "failed to prepare" $testfile $srcfile {debug f90}] } {
return -1
}
gdb/fortran: Allow Flang MAIN_ in Fortran testing Name of fortran main function for Flang compiler is MAIN_ while for gfortran it is MAIN__ . In test cases MAIN__ is hardcoded for the purpose of inserting breakpoint. New proc is added to detect main function name depending on the compiler used. Fortran specific version of runto_main named fortran_runto_main is added. This commit adds support for Flang main function, there should be no change for gfortran. gdb/testsuite/ChangeLog * lib/fortran.exp (fortran_main): New Proc, handle flang MAIN_, (fortran_runto_main): New Proc, fortran version of runto_main. * gdb.fortran/array-bounds-high.exp: Handle flang MAIN_. * gdb.fortran/array-bounds.exp: Likewise. * gdb.fortran/array-slices.exp: Likewise. * gdb.fortran/block-data.exp: Likewise. * gdb.fortran/charset.exp: Likewise. * gdb.fortran/common-block.exp: Likewise. * gdb.fortran/complex.exp: Likewise. * gdb.fortran/derived-type-function.exp: Likewise. * gdb.fortran/derived-type.exp: Likewise. * gdb.fortran/info-modules.exp: Likewise. * gdb.fortran/info-types.exp: Likewise. * gdb.fortran/intrinsics.exp: Likewise. * gdb.fortran/library-module.exp: Likewise. * gdb.fortran/logical.exp: Likewise. * gdb.fortran/max-depth.exp: Likewise. * gdb.fortran/module.exp: Likewise. * gdb.fortran/multi-dim.exp: Likewise. * gdb.fortran/nested-funcs.exp: Likewise. * gdb.fortran/print-formatted.exp: Likewise. * gdb.fortran/print_type.exp: Likewise. * gdb.fortran/printing-types.exp: Likewise. * gdb.fortran/ptr-indentation.exp: Likewise. * gdb.fortran/ptype-on-functions.exp: Likewise. * gdb.fortran/subarray.exp: Likewise. * gdb.fortran/vla-alloc-assoc.exp: Likewise. * gdb.fortran/vla-datatypes.exp: Likewise. * gdb.fortran/vla-history.exp: Likewise. * gdb.fortran/vla-ptr-info.exp: Likewise. * gdb.fortran/vla-ptype-sub.exp: Likewise. * gdb.fortran/vla-ptype.exp: Likewise. * gdb.fortran/vla-sizeof.exp: Likewise. * gdb.fortran/vla-type.exp: Likewise. * gdb.fortran/vla-value-sub-arbitrary.exp: Likewise. * gdb.fortran/vla-value-sub-finish.exp: Likewise. * gdb.fortran/vla-value-sub.exp: Likewise. * gdb.fortran/vla-value.exp: Likewise. * gdb.fortran/whatis_type.exp: Likewise. * gdb.mi/mi-var-child-f.exp: Likewise.
2020-05-11 03:12:00 +08:00
if { ![fortran_runto_main] } {
perror "Could not run to main."
return
gdb/fortran: Add Fortran 'kind' intrinsic and keyword The 'kind' keyword has two uses in Fortran, it is the name of a builtin intrinsic function, and it is also a keyword used to create a type of a specific kind. This commit adds support for using kind as an intrinsic function, and also adds some initial support for using kind to create types of a specific kind. This commit only allows the creation of the type 'character(kind=1)', however, it will be easy enough to extend this in future to support more type kinds. The kind of any expression can be queried using the kind intrinsic function. At the moment the kind returned corresponds to the size of the type, this matches how gfortran handles kinds. However, the correspondence between kind and type size depends on the compiler and/or the specific target, so this might not be correct for everyone. If we want to support different compilers/targets in future the code to compute the kind from a type will need to be updated. gdb/ChangeLog: * expprint.c (dump_subexp_body_standard): Support UNOP_KIND. * f-exp.y: Define 'KIND' token. (exp): New pattern for KIND expressions. (ptype): Handle types with a kind extension. (direct_abs_decl): Extend to spot kind extensions. (f77_keywords): Add 'kind' to the list. (push_kind_type): New function. (convert_to_kind_type): New function. * f-lang.c (evaluate_subexp_f): Support UNOP_KIND. * parse.c (operator_length_standard): Likewise. * parser-defs.h (enum type_pieces): Add tp_kind. * std-operator.def: Add UNOP_KIND. gdb/testsuite/ChangeLog: * gdb.fortran/intrinsics.exp: New file. * gdb.fortran/intrinsics.f90: New file. * gdb.fortran/type-kinds.exp: New file.
2019-01-17 00:42:10 +08:00
}
gdb_breakpoint [gdb_get_line_number "stop-here"]
gdb_continue_to_breakpoint "stop-here" ".*stop-here.*"
# Test KIND
gdb_test "p kind (l1)" " = 1"
gdb_test "p kind (l2)" " = 2"
gdb_test "p kind (l4)" " = 4"
gdb_test "p kind (l8)" " = 8"
gdb_test "p kind (s1)" "argument to kind must be an intrinsic type"
# Test ABS
gdb_test "p abs (-11)" " = 11"
gdb_test "p abs (11)" " = 11"
# Use `$decimal` to match here as we depend on host floating point
# rounding, which can vary.
gdb_test "p abs (-9.1)" " = 9.$decimal"
gdb_test "p abs (9.1)" " = 9.$decimal"
# Test MOD
gdb_test "p mod (3.0, 2.0)" " = 1"
gdb_test "ptype mod (3.0, 2.0)" "type = real\\*8"
gdb_test "p mod (2.0, 3.0)" " = 2"
gdb_test "p mod (8, 5)" " = 3"
gdb_test "ptype mod (8, 5)" "type = int"
gdb_test "p mod (-8, 5)" " = -3"
gdb_test "p mod (8, -5)" " = 3"
gdb_test "p mod (-8, -5)" " = -3"
# Test CEILING and FLOOR.
gdb_test "p floor (3.7)" " = 3"
gdb_test "p ceiling (3.7)" " = 4"
gdb_test "p floor (-3.7)" " = -4"
gdb_test "p ceiling (-3.7)" " = -3"
gdb_test "p ceiling (3)" "argument to CEILING must be of type float"
gdb_test "p floor (1)" "argument to FLOOR must be of type float"
foreach op {floor ceiling} {
gdb_test "ptype ${op} (3.7)" "integer\\*4"
gdb_test "ptype ${op} (-1.1, 1)" "type = integer\\*1"
gdb_test "ptype ${op} (-1.1, 2)" "type = integer\\*2"
gdb_test "ptype ${op} (-1.1, 3)" "unsupported kind 3 for type integer\\*4"
gdb_test "ptype ${op} (-1.1, 4)" "type = integer\\*4"
gdb_test "ptype ${op} (-1.1, 8)" "type = integer\\*8"
# The actual overflow behavior differs in ifort/ifx/gfortran - this tests
# the GDB internal overflow behavior - not a compiler dependent one.
gdb_test "p ${op} (129.0,1)" " = -127"
gdb_test "p ${op} (129.0,2)" " = 129"
gdb_test "p ${op} (-32770.0,1)" " = -2"
gdb_test "p ${op} (-32770.0,2)" " = 32766"
gdb_test "p ${op} (-32770.0,4)" " = -32770"
gdb_test "p ${op} (2147483652.0,1)" " = 4"
gdb_test "p ${op} (2147483652.0,2)" " = 4"
gdb_test "p ${op} (2147483652.0,4)" " = -2147483644"
gdb_test "p ${op} (2147483652.0,8)" " = 2147483652"
}
# Test MODULO
gdb_test "p MODULO (8,5)" " = 3"
gdb_test "ptype MODULO (8,5)" "type = int"
gdb_test "p MODULO (-8,5)" " = 2"
gdb_test "p MODULO (8,-5)" " = -2"
gdb_test "p MODULO (-8,-5)" " = -3"
gdb_test "p MODULO (3.0,2.0)" " = 1"
gdb_test "ptype MODULO (3.0,2.0)" "type = real\\*8"
# Test CMPLX
gdb_test "p CMPLX (4.1, 2.0)" " = \\(4.$decimal,2\\)"
gdb_test "p cmplx (4,4)" "= \\(4,4\\)"
gdb_test "ptype cmplx (4,4)" "= complex\\*4"
gdb_test "p cmplx (-14,-4)" "= \\(-14,-4\\)"
gdb_test "p cmplx (4,4,4)" "\\(4,4\\)"
gdb_test "p cmplx (4,4,8)" "\\(4,4\\)"
gdb_test "p cmplx (4,4,16)" "\\(4,4\\)"
gdb_test "ptype cmplx (4,4,4)" "= complex\\*4"
gdb_test "ptype cmplx (4,4,8)" "= complex\\*8"
gdb_test "ptype cmplx (4,4,16)" "= complex\\*16"
gdb_test "p cmplx (4,4,1)" "unsupported kind 1 for type complex\\*4"
gdb_test "p cmplx (4,4,-1)" "unsupported kind -1 for type complex\\*4"
gdb_test "p cmplx (4,4,2)" "unsupported kind 2 for type complex\\*4"
# Test LOC
gdb_test "p/x LOC(l)" "= $hex"
gdb_test "ptype loc(l)" "type = integer(\\*$decimal)?"