Home | History | Annotate | Line # | Download | only in gdb.fortran
      1  1.1.1.3  christos # Copyright 2019-2024 Free Software Foundation, Inc.
      2      1.1  christos #
      3      1.1  christos # This program is free software; you can redistribute it and/or modify
      4      1.1  christos # it under the terms of the GNU General Public License as published by
      5      1.1  christos # the Free Software Foundation; either version 3 of the License, or
      6      1.1  christos # (at your option) any later version.
      7      1.1  christos #
      8      1.1  christos # This program is distributed in the hope that it will be useful,
      9      1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10      1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11      1.1  christos # GNU General Public License for more details.
     12      1.1  christos #
     13      1.1  christos # You should have received a copy of the GNU General Public License
     14      1.1  christos # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15      1.1  christos 
     16      1.1  christos # This file tests GDB's handling of Fortran builtin intrinsic functions.
     17      1.1  christos 
     18      1.1  christos load_lib "fortran.exp"
     19      1.1  christos 
     20  1.1.1.3  christos require allow_fortran_tests
     21      1.1  christos 
     22      1.1  christos standard_testfile .f90
     23      1.1  christos 
     24      1.1  christos if { [prepare_for_testing "failed to prepare" $testfile $srcfile {debug f90}] } {
     25      1.1  christos     return -1
     26      1.1  christos }
     27      1.1  christos 
     28      1.1  christos if { ![fortran_runto_main] } {
     29      1.1  christos     perror "Could not run to main."
     30  1.1.1.2  christos     return
     31      1.1  christos }
     32      1.1  christos 
     33      1.1  christos gdb_breakpoint [gdb_get_line_number "stop-here"]
     34      1.1  christos gdb_continue_to_breakpoint "stop-here" ".*stop-here.*"
     35      1.1  christos 
     36      1.1  christos # Test KIND
     37      1.1  christos 
     38      1.1  christos gdb_test "p kind (l1)" " = 1"
     39      1.1  christos gdb_test "p kind (l2)" " = 2"
     40      1.1  christos gdb_test "p kind (l4)" " = 4"
     41      1.1  christos gdb_test "p kind (l8)" " = 8"
     42      1.1  christos gdb_test "p kind (s1)" "argument to kind must be an intrinsic type"
     43      1.1  christos 
     44      1.1  christos # Test ABS
     45      1.1  christos 
     46      1.1  christos gdb_test "p abs (-11)" " = 11"
     47      1.1  christos gdb_test "p abs (11)" " = 11"
     48      1.1  christos # Use `$decimal` to match here as we depend on host floating point
     49      1.1  christos # rounding, which can vary.
     50      1.1  christos gdb_test "p abs (-9.1)" " = 9.$decimal"
     51      1.1  christos gdb_test "p abs (9.1)" " = 9.$decimal"
     52      1.1  christos 
     53      1.1  christos # Test MOD
     54      1.1  christos 
     55      1.1  christos gdb_test "p mod (3.0, 2.0)" " = 1"
     56      1.1  christos gdb_test "ptype mod (3.0, 2.0)" "type = real\\*8"
     57      1.1  christos gdb_test "p mod (2.0, 3.0)" " = 2"
     58      1.1  christos gdb_test "p mod (8, 5)" " = 3"
     59      1.1  christos gdb_test "ptype mod (8, 5)" "type = int"
     60      1.1  christos gdb_test "p mod (-8, 5)" " = -3"
     61      1.1  christos gdb_test "p mod (8, -5)" " = 3"
     62      1.1  christos gdb_test "p mod (-8, -5)" " = -3"
     63      1.1  christos 
     64  1.1.1.2  christos # Test CEILING and FLOOR.
     65      1.1  christos 
     66  1.1.1.2  christos gdb_test "p floor (3.7)" " = 3"
     67      1.1  christos gdb_test "p ceiling (3.7)" " = 4"
     68  1.1.1.2  christos 
     69  1.1.1.2  christos gdb_test "p floor (-3.7)" " = -4"
     70      1.1  christos gdb_test "p ceiling (-3.7)" " = -3"
     71      1.1  christos 
     72  1.1.1.2  christos gdb_test "p ceiling (3)" "argument to CEILING must be of type float"
     73  1.1.1.2  christos gdb_test "p floor (1)" "argument to FLOOR must be of type float"
     74      1.1  christos 
     75  1.1.1.2  christos foreach op {floor ceiling} {
     76  1.1.1.2  christos     gdb_test "ptype ${op} (3.7)" "integer\\*4"
     77  1.1.1.2  christos     gdb_test "ptype ${op} (-1.1, 1)" "type = integer\\*1"
     78  1.1.1.2  christos     gdb_test "ptype ${op} (-1.1, 2)" "type = integer\\*2"
     79  1.1.1.2  christos     gdb_test "ptype ${op} (-1.1, 3)" "unsupported kind 3 for type integer\\*4"
     80  1.1.1.2  christos     gdb_test "ptype ${op} (-1.1, 4)" "type = integer\\*4"
     81  1.1.1.2  christos     gdb_test "ptype ${op} (-1.1, 8)" "type = integer\\*8"
     82  1.1.1.2  christos 
     83  1.1.1.2  christos     # The actual overflow behavior differs in ifort/ifx/gfortran - this tests
     84  1.1.1.2  christos     # the GDB internal overflow behavior - not a compiler dependent one.
     85  1.1.1.2  christos     gdb_test "p ${op} (129.0,1)" " = -127"
     86  1.1.1.2  christos     gdb_test "p ${op} (129.0,2)" " = 129"
     87  1.1.1.2  christos     gdb_test "p ${op} (-32770.0,1)" " = -2"
     88  1.1.1.2  christos     gdb_test "p ${op} (-32770.0,2)" " = 32766"
     89  1.1.1.2  christos     gdb_test "p ${op} (-32770.0,4)" " = -32770"
     90  1.1.1.2  christos     gdb_test "p ${op} (2147483652.0,1)" " = 4"
     91  1.1.1.2  christos     gdb_test "p ${op} (2147483652.0,2)" " = 4"
     92  1.1.1.2  christos     gdb_test "p ${op} (2147483652.0,4)" " = -2147483644"
     93  1.1.1.2  christos     gdb_test "p ${op} (2147483652.0,8)" " = 2147483652"
     94  1.1.1.2  christos }
     95      1.1  christos 
     96      1.1  christos # Test MODULO
     97      1.1  christos 
     98      1.1  christos gdb_test "p MODULO (8,5)" " = 3"
     99      1.1  christos gdb_test "ptype MODULO (8,5)" "type = int"
    100      1.1  christos gdb_test "p MODULO (-8,5)" " = 2"
    101      1.1  christos gdb_test "p MODULO (8,-5)" " = -2"
    102      1.1  christos gdb_test "p MODULO (-8,-5)" " = -3"
    103      1.1  christos gdb_test "p MODULO (3.0,2.0)" " = 1"
    104      1.1  christos gdb_test "ptype MODULO (3.0,2.0)" "type = real\\*8"
    105      1.1  christos 
    106      1.1  christos # Test CMPLX
    107      1.1  christos 
    108      1.1  christos gdb_test "p CMPLX (4.1, 2.0)" " = \\(4.$decimal,2\\)"
    109  1.1.1.2  christos 
    110  1.1.1.2  christos gdb_test "p cmplx (4,4)" "= \\(4,4\\)"
    111  1.1.1.2  christos gdb_test "ptype cmplx (4,4)" "= complex\\*4"
    112  1.1.1.2  christos gdb_test "p cmplx (-14,-4)" "= \\(-14,-4\\)"
    113  1.1.1.2  christos gdb_test "p cmplx (4,4,4)" "\\(4,4\\)"
    114  1.1.1.2  christos gdb_test "p cmplx (4,4,8)" "\\(4,4\\)"
    115  1.1.1.4  christos set re_unsupported_kind_16 \
    116  1.1.1.4  christos     [string_to_regexp "unsupported kind 16 for type complex*4"]
    117  1.1.1.4  christos gdb_test "p cmplx (4,4,16)" \
    118  1.1.1.4  christos     ([string_to_regexp " = (4,4)"]|$re_unsupported_kind_16)
    119  1.1.1.2  christos gdb_test "ptype cmplx (4,4,4)" "= complex\\*4"
    120  1.1.1.2  christos gdb_test "ptype cmplx (4,4,8)" "= complex\\*8"
    121  1.1.1.4  christos gdb_test "ptype cmplx (4,4,16)" \
    122  1.1.1.4  christos     ([string_to_regexp " = complex*16"]|$re_unsupported_kind_16)
    123  1.1.1.2  christos 
    124  1.1.1.2  christos gdb_test "p cmplx (4,4,1)" "unsupported kind 1 for type complex\\*4"
    125  1.1.1.2  christos gdb_test "p cmplx (4,4,-1)" "unsupported kind -1 for type complex\\*4"
    126  1.1.1.2  christos gdb_test "p cmplx (4,4,2)" "unsupported kind 2 for type complex\\*4"
    127  1.1.1.2  christos 
    128  1.1.1.2  christos # Test LOC
    129  1.1.1.2  christos 
    130  1.1.1.2  christos gdb_test "p/x LOC(l)" "= $hex"
    131  1.1.1.2  christos gdb_test "ptype loc(l)" "type = integer(\\*$decimal)?"
    132