2024-01-12 23:30:44 +08:00
|
|
|
# Copyright 2019-2024 Free Software Foundation, Inc.
|
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"
|
|
|
|
|
2023-01-09 01:52:25 +08:00
|
|
|
require allow_fortran_tests
|
2019-01-17 00:42:10 +08:00
|
|
|
|
|
|
|
standard_testfile .f90
|
|
|
|
|
|
|
|
if { [prepare_for_testing "failed to prepare" $testfile $srcfile {debug f90}] } {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
2020-05-11 03:12:00 +08:00
|
|
|
if { ![fortran_runto_main] } {
|
|
|
|
perror "Could not run to main."
|
2022-05-14 00:23:57 +08:00
|
|
|
return
|
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"
|
2019-01-18 22:44:48 +08:00
|
|
|
|
|
|
|
# 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"
|
gdb/fortran: Additional builtin procedures
Add some additional builtin procedures for Fortran, these are MOD,
CEILING, FLOOR, MODULO, and CMPLX.
gdb/ChangeLog:
* f-exp.y (BINOP_INTRINSIC): New token.
(exp): New parser rule handling BINOP_INTRINSIC.
(f77_keywords): Add new builtin procedures.
* f-lang.c (evaluate_subexp_f): Handle BINOP_MOD, UNOP_FORTRAN_CEILING,
UNOP_FORTRAN_FLOOR, BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX.
(operator_length_f): Handle UNOP_FORTRAN_CEILING,
UNOP_FORTRAN_FLOOR, BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX.
(print_unop_subexp_f): New function.
(print_binop_subexp_f): New function.
(print_subexp_f): Handle UNOP_FORTRAN_CEILING, UNOP_FORTRAN_FLOOR,
BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX.
(dump_subexp_body_f): Likewise.
(operator_check_f): Likewise.
* fortran-operator.def: Add UNOP_FORTRAN_CEILING, UNOP_FORTRAN_FLOOR,
BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX
gdb/testsuite/ChangeLog:
* gdb.fortran/intrinsics.exp: Extend to cover MOD, CEILING, FLOOR,
MODULO, CMPLX.
2019-02-14 01:10:18 +08:00
|
|
|
|
|
|
|
# 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"
|
|
|
|
|
gdb/fortran: rewrite intrinsic handling and add some missing overloads
The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND. This
parameter determines the kind of the associated return value. So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.
This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.
It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.
After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate. E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function. This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.
2022-04-11 20:06:56 +08:00
|
|
|
# Test CEILING and FLOOR.
|
gdb/fortran: Additional builtin procedures
Add some additional builtin procedures for Fortran, these are MOD,
CEILING, FLOOR, MODULO, and CMPLX.
gdb/ChangeLog:
* f-exp.y (BINOP_INTRINSIC): New token.
(exp): New parser rule handling BINOP_INTRINSIC.
(f77_keywords): Add new builtin procedures.
* f-lang.c (evaluate_subexp_f): Handle BINOP_MOD, UNOP_FORTRAN_CEILING,
UNOP_FORTRAN_FLOOR, BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX.
(operator_length_f): Handle UNOP_FORTRAN_CEILING,
UNOP_FORTRAN_FLOOR, BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX.
(print_unop_subexp_f): New function.
(print_binop_subexp_f): New function.
(print_subexp_f): Handle UNOP_FORTRAN_CEILING, UNOP_FORTRAN_FLOOR,
BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX.
(dump_subexp_body_f): Likewise.
(operator_check_f): Likewise.
* fortran-operator.def: Add UNOP_FORTRAN_CEILING, UNOP_FORTRAN_FLOOR,
BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX
gdb/testsuite/ChangeLog:
* gdb.fortran/intrinsics.exp: Extend to cover MOD, CEILING, FLOOR,
MODULO, CMPLX.
2019-02-14 01:10:18 +08:00
|
|
|
|
gdb/fortran: rewrite intrinsic handling and add some missing overloads
The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND. This
parameter determines the kind of the associated return value. So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.
This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.
It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.
After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate. E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function. This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.
2022-04-11 20:06:56 +08:00
|
|
|
gdb_test "p floor (3.7)" " = 3"
|
gdb/fortran: Additional builtin procedures
Add some additional builtin procedures for Fortran, these are MOD,
CEILING, FLOOR, MODULO, and CMPLX.
gdb/ChangeLog:
* f-exp.y (BINOP_INTRINSIC): New token.
(exp): New parser rule handling BINOP_INTRINSIC.
(f77_keywords): Add new builtin procedures.
* f-lang.c (evaluate_subexp_f): Handle BINOP_MOD, UNOP_FORTRAN_CEILING,
UNOP_FORTRAN_FLOOR, BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX.
(operator_length_f): Handle UNOP_FORTRAN_CEILING,
UNOP_FORTRAN_FLOOR, BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX.
(print_unop_subexp_f): New function.
(print_binop_subexp_f): New function.
(print_subexp_f): Handle UNOP_FORTRAN_CEILING, UNOP_FORTRAN_FLOOR,
BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX.
(dump_subexp_body_f): Likewise.
(operator_check_f): Likewise.
* fortran-operator.def: Add UNOP_FORTRAN_CEILING, UNOP_FORTRAN_FLOOR,
BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX
gdb/testsuite/ChangeLog:
* gdb.fortran/intrinsics.exp: Extend to cover MOD, CEILING, FLOOR,
MODULO, CMPLX.
2019-02-14 01:10:18 +08:00
|
|
|
gdb_test "p ceiling (3.7)" " = 4"
|
|
|
|
|
|
|
|
gdb_test "p floor (-3.7)" " = -4"
|
gdb/fortran: rewrite intrinsic handling and add some missing overloads
The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND. This
parameter determines the kind of the associated return value. So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.
This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.
It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.
After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate. E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function. This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.
2022-04-11 20:06:56 +08:00
|
|
|
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"
|
|
|
|
}
|
gdb/fortran: Additional builtin procedures
Add some additional builtin procedures for Fortran, these are MOD,
CEILING, FLOOR, MODULO, and CMPLX.
gdb/ChangeLog:
* f-exp.y (BINOP_INTRINSIC): New token.
(exp): New parser rule handling BINOP_INTRINSIC.
(f77_keywords): Add new builtin procedures.
* f-lang.c (evaluate_subexp_f): Handle BINOP_MOD, UNOP_FORTRAN_CEILING,
UNOP_FORTRAN_FLOOR, BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX.
(operator_length_f): Handle UNOP_FORTRAN_CEILING,
UNOP_FORTRAN_FLOOR, BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX.
(print_unop_subexp_f): New function.
(print_binop_subexp_f): New function.
(print_subexp_f): Handle UNOP_FORTRAN_CEILING, UNOP_FORTRAN_FLOOR,
BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX.
(dump_subexp_body_f): Likewise.
(operator_check_f): Likewise.
* fortran-operator.def: Add UNOP_FORTRAN_CEILING, UNOP_FORTRAN_FLOOR,
BINOP_FORTRAN_MODULO, BINOP_FORTRAN_CMPLX
gdb/testsuite/ChangeLog:
* gdb.fortran/intrinsics.exp: Extend to cover MOD, CEILING, FLOOR,
MODULO, CMPLX.
2019-02-14 01:10:18 +08:00
|
|
|
|
|
|
|
# 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\\)"
|
2021-03-09 18:34:55 +08:00
|
|
|
|
gdb/fortran: rewrite intrinsic handling and add some missing overloads
The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND. This
parameter determines the kind of the associated return value. So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.
This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.
It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.
After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate. E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function. This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.
2022-04-11 20:06:56 +08:00
|
|
|
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"
|
|
|
|
|
2021-03-09 18:34:55 +08:00
|
|
|
# Test LOC
|
|
|
|
|
|
|
|
gdb_test "p/x LOC(l)" "= $hex"
|
|
|
|
gdb_test "ptype loc(l)" "type = integer(\\*$decimal)?"
|