1 1.1.1.2 christos ! Copyright 2021-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 #define DO_TEST(ARRAY) \ 17 1.1 christos call do_test (lbound (ARRAY), ubound (ARRAY)) 18 1.1 christos 19 1.1 christos subroutine do_test (lb, ub) 20 1.1 christos integer*4, dimension (:) :: lb 21 1.1 christos integer*4, dimension (:) :: ub 22 1.1 christos 23 1.1 christos print *, "" ! Test Breakpoint 24 1.1 christos end subroutine do_test 25 1.1 christos 26 1.1 christos ! 27 1.1 christos ! Start of test program. 28 1.1 christos ! 29 1.1 christos program test 30 1.1 christos use ISO_C_BINDING, only: C_NULL_PTR, C_SIZEOF 31 1.1 christos 32 1.1 christos interface 33 1.1 christos subroutine do_test (lb, ub) 34 1.1 christos integer*4, dimension (:) :: lb 35 1.1 christos integer*4, dimension (:) :: ub 36 1.1 christos end subroutine do_test 37 1.1 christos end interface 38 1.1 christos 39 1.1 christos ! Declare variables used in this test. 40 1.1 christos integer, dimension (-8:-1,-10:-2) :: neg_array 41 1.1 christos integer, dimension (2:10,1:9), target :: array 42 1.1 christos integer, allocatable :: other (:, :) 43 1.1 christos character (len=26) :: str_1 = "abcdefghijklmnopqrstuvwxyz" 44 1.1 christos integer, dimension (-2:2,-3:3,-1:5) :: array3d 45 1.1 christos integer, dimension (-3:3,7:10,-4:2,-10:-7) :: array4d 46 1.1 christos integer, dimension (10:20) :: array1d 47 1.1 christos integer, dimension(:,:), pointer :: pointer2d => null() 48 1.1 christos integer, dimension(-2:6,-1:9), target :: tarray 49 1.1 christos integer :: an_int 50 1.1 christos 51 1.1 christos integer, dimension (:), pointer :: pointer1d => null() 52 1.1 christos 53 1.1 christos integer, parameter :: b1 = 127 - 10 54 1.1 christos integer, parameter :: b1_o = 127 + 2 55 1.1 christos integer, parameter :: b2 = 32767 - 10 56 1.1 christos integer, parameter :: b2_o = 32767 + 3 57 1.1 christos 58 1.1 christos ! This tests the GDB overflow behavior when using a KIND parameter too small 59 1.1 christos ! to hold the actual output argument. This is done for 1, 2, and 4 byte 60 1.1 christos ! overflow. On 32-bit machines most compilers will complain when trying to 61 1.1 christos ! allocate an array with ranges outside the 4 byte integer range. 62 1.1 christos ! We take the byte size of a C pointer as indication as to whether or not we 63 1.1 christos ! are on a 32 bit machine an skip the 4 byte overflow tests in that case. 64 1.1 christos integer, parameter :: bytes_c_ptr = C_SIZEOF(C_NULL_PTR) 65 1.1 christos 66 1.1 christos integer*8, parameter :: max_signed_4byte_int = 2147483647 67 1.1 christos integer*8, parameter :: b4 = max_signed_4byte_int - 10 68 1.1 christos integer*8 :: b4_o 69 1.1 christos logical :: is_64_bit 70 1.1 christos 71 1.1 christos integer, allocatable :: array_1d_1bytes_overflow (:) 72 1.1 christos integer, allocatable :: array_1d_2bytes_overflow (:) 73 1.1 christos integer, allocatable :: array_1d_4bytes_overflow (:) 74 1.1 christos integer, allocatable :: array_2d_1byte_overflow (:,:) 75 1.1 christos integer, allocatable :: array_2d_2bytes_overflow (:,:) 76 1.1 christos integer, allocatable :: array_3d_1byte_overflow (:,:,:) 77 1.1 christos 78 1.1 christos ! Set the 4 byte overflow only on 64 bit machines. 79 1.1 christos if (bytes_c_ptr < 8) then 80 1.1 christos b4_o = 0 81 1.1 christos is_64_bit = .FALSE. 82 1.1 christos else 83 1.1 christos b4_o = max_signed_4byte_int + 5 84 1.1 christos is_64_bit = .TRUE. 85 1.1 christos end if 86 1.1 christos 87 1.1 christos ! Allocate or associate any variables as needed. 88 1.1 christos allocate (other (-5:4, -2:7)) 89 1.1 christos pointer2d => tarray 90 1.1 christos pointer1d => array (3, 2:5) 91 1.1 christos 92 1.1 christos allocate (array_1d_1bytes_overflow (-b1_o:-b1)) 93 1.1 christos allocate (array_1d_2bytes_overflow (b2:b2_o)) 94 1.1 christos if (is_64_bit) then 95 1.1 christos allocate (array_1d_4bytes_overflow (-b4_o:-b4)) 96 1.1 christos end if 97 1.1 christos allocate (array_2d_1byte_overflow (-b1_o:-b1,b1:b1_o)) 98 1.1 christos allocate (array_2d_2bytes_overflow (b2:b2_o,-b2_o:b2)) 99 1.1 christos 100 1.1 christos allocate (array_3d_1byte_overflow (-b1_o:-b1,b1:b1_o,-b1_o:-b1)) 101 1.1 christos 102 1.1 christos DO_TEST (neg_array) 103 1.1 christos DO_TEST (neg_array (-7:-3,-5:-4)) 104 1.1 christos DO_TEST (array) 105 1.1 christos ! The following is disabled due to a bug in gfortran: 106 1.1 christos ! https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99027 107 1.1 christos ! gfortran generates the incorrect expected results. 108 1.1 christos ! DO_TEST (array (3, 2:5)) 109 1.1 christos DO_TEST (pointer1d) 110 1.1 christos DO_TEST (other) 111 1.1 christos DO_TEST (array3d) 112 1.1 christos DO_TEST (array4d) 113 1.1 christos DO_TEST (array1d) 114 1.1 christos DO_TEST (pointer2d) 115 1.1 christos DO_TEST (tarray) 116 1.1 christos 117 1.1 christos DO_TEST (array_1d_1bytes_overflow) 118 1.1 christos DO_TEST (array_1d_2bytes_overflow) 119 1.1 christos 120 1.1 christos if (is_64_bit) then 121 1.1 christos DO_TEST (array_1d_4bytes_overflow) 122 1.1 christos end if 123 1.1 christos DO_TEST (array_2d_1byte_overflow) 124 1.1 christos DO_TEST (array_2d_2bytes_overflow) 125 1.1 christos DO_TEST (array_3d_1byte_overflow) 126 1.1 christos 127 1.1 christos ! All done. Deallocate. 128 1.1 christos print *, "" ! Breakpoint before deallocate. 129 1.1 christos deallocate (other) 130 1.1 christos 131 1.1 christos deallocate (array_3d_1byte_overflow) 132 1.1 christos 133 1.1 christos deallocate (array_2d_2bytes_overflow) 134 1.1 christos deallocate (array_2d_1byte_overflow) 135 1.1 christos 136 1.1 christos if (is_64_bit) then 137 1.1 christos deallocate (array_1d_4bytes_overflow) 138 1.1 christos end if 139 1.1 christos deallocate (array_1d_2bytes_overflow) 140 1.1 christos deallocate (array_1d_1bytes_overflow) 141 1.1 christos 142 1.1 christos ! GDB catches this final breakpoint to indicate the end of the test. 143 1.1 christos print *, "" ! Final Breakpoint. 144 1.1 christos 145 1.1 christos ! Reference otherwise unused locals in order to keep them around. 146 1.1 christos ! GDB will make use of these for some tests. 147 1.1 christos print *, str_1 148 1.1 christos an_int = 1 149 1.1 christos print *, an_int 150 1.1 christos 151 1.1 christos end program test 152