| 1 |
! { dg-do run } |
| 2 |
! { dg-additional-options "-fdump-tree-original" } |
| 3 |
|
| 4 |
! F2018 - examples without array descriptor |
| 5 |
|
| 6 |
|
| 7 |
module m |
| 8 |
use iso_c_binding, only: c_char |
| 9 |
implicit none (type, external) |
| 10 |
|
| 11 |
contains |
| 12 |
|
| 13 |
! Scalar, nonallocatable/nonpointer |
| 14 |
subroutine s1 (x1) bind(C) |
| 15 |
character(kind=c_char, len=1) :: x1 |
| 16 |
if (len (x1) /= 1) stop |
| 17 |
if (x1 /= 'Z') stop |
| 18 |
x1 = 'A' |
| 19 |
end |
| 20 |
|
| 21 |
! Valid as Fortran code - but with BIND(C) |
| 22 |
! 18.3.6 (5) (bullet 5) requires interoperability, i.e. len=1 |
| 23 |
! which is not fullfilled. |
| 24 |
! |
| 25 |
! [It would work as with len=<const> the length is known |
| 26 |
! and only a bytestream is passed around.] |
| 27 |
!subroutine s2 (x2) bind(C) |
| 28 |
! character(kind=c_char, len=2) :: x2 |
| 29 |
! if (len (x2) /= 2) stop |
| 30 |
! if (x2 /= '42') stop |
| 31 |
! x2 = '64' |
| 32 |
!end |
| 33 |
|
| 34 |
! Assumed-size array, nonallocatable/nonpointer |
| 35 |
|
| 36 |
subroutine az1 (x1) bind(C) |
| 37 |
character(kind=c_char, len=1) :: x1(*) |
| 38 |
if (len(x1) /= 1) stop |
| 39 |
if (any (x1(:6) /= ['g', & |
| 40 |
'd', & |
| 41 |
'f', & |
| 42 |
's', & |
| 43 |
'3', & |
| 44 |
'5'])) stop 1 |
| 45 |
x1(:6) = ['1', & |
| 46 |
'h', & |
| 47 |
'f', & |
| 48 |
'3', & |
| 49 |
'4', & |
| 50 |
'h'] |
| 51 |
end |
| 52 |
|
| 53 |
! Valid as Fortran code - but with BIND(C) |
| 54 |
! 18.3.6 (5) (bullet 5) requires interoperability, i.e. len=1 |
| 55 |
! which is not fullfilled. |
| 56 |
! |
| 57 |
! [It would work as with len=<const> the length is known |
| 58 |
! and only a bytestream is passed around.] |
| 59 |
!subroutine az2 (x2) bind(C) |
| 60 |
! character(kind=c_char, len=2) :: x2(*) |
| 61 |
! if (len(x2) /= 2) stop |
| 62 |
! if (any (x2(:6) /= ['ab', & |
| 63 |
! 'fd', & |
| 64 |
! 'D4', & |
| 65 |
! '54', & |
| 66 |
! 'ga', & |
| 67 |
! 'hg'])) stop |
| 68 |
! x2(:6) = ['ab', & |
| 69 |
! 'hd', & |
| 70 |
! 'fj', & |
| 71 |
! 'a4', & |
| 72 |
! '4a', & |
| 73 |
! 'hf'] |
| 74 |
!end |
| 75 |
|
| 76 |
! Explicit-size array, nonallocatable/nonpointer |
| 77 |
|
| 78 |
subroutine ae1 (x1) bind(C) |
| 79 |
character(kind=c_char, len=1) :: x1(6) |
| 80 |
if (size(x1) /= 6) stop |
| 81 |
if (len(x1) /= 1) stop |
| 82 |
if (any (x1 /= ['g', & |
| 83 |
'd', & |
| 84 |
'f', & |
| 85 |
's', & |
| 86 |
'3', & |
| 87 |
'5'])) stop 1 |
| 88 |
x1 = ['1', & |
| 89 |
'h', & |
| 90 |
'f', & |
| 91 |
'3', & |
| 92 |
'4', & |
| 93 |
'h'] |
| 94 |
end |
| 95 |
|
| 96 |
! Valid as Fortran code - but with BIND(C) |
| 97 |
! 18.3.6 (5) (bullet 5) requires interoperability, i.e. len=1 |
| 98 |
! which is not fullfilled. |
| 99 |
! |
| 100 |
! [It would work as with len=<const> the length is known |
| 101 |
! and only a bytestream is passed around.] |
| 102 |
!subroutine ae2 (x2) bind(C) |
| 103 |
! character(kind=c_char, len=2) :: x2(6) |
| 104 |
! if (size(x2) /= 6) stop |
| 105 |
! if (len(x2) /= 2) stop |
| 106 |
! if (any (x2 /= ['ab', & |
| 107 |
! 'fd', & |
| 108 |
! 'D4', & |
| 109 |
! '54', & |
| 110 |
! 'ga', & |
| 111 |
! 'hg'])) stop |
| 112 |
! x2 = ['ab', & |
| 113 |
! 'hd', & |
| 114 |
! 'fj', & |
| 115 |
! 'a4', & |
| 116 |
! '4a', & |
| 117 |
! 'hf'] |
| 118 |
!end |
| 119 |
|
| 120 |
end module m |
| 121 |
|
| 122 |
program main |
| 123 |
use m |
| 124 |
implicit none (type, external) |
| 125 |
character(kind=c_char, len=1) :: str1 |
| 126 |
character(kind=c_char, len=2) :: str2 |
| 127 |
|
| 128 |
character(kind=c_char, len=1) :: str1a6(6) |
| 129 |
character(kind=c_char, len=2) :: str2a6(6) |
| 130 |
|
| 131 |
! Scalar - no array descriptor |
| 132 |
|
| 133 |
str1 = 'Z' |
| 134 |
call s1 (str1) |
| 135 |
if (str1 /= 'A') stop |
| 136 |
|
| 137 |
! str2 = '42' |
| 138 |
! call s2 (str2) |
| 139 |
! if (str2 /= '64') stop |
| 140 |
|
| 141 |
! assumed size - without array descriptor |
| 142 |
|
| 143 |
str1a6 = ['g', & |
| 144 |
'd', & |
| 145 |
'f', & |
| 146 |
's', & |
| 147 |
'3', & |
| 148 |
'5'] |
| 149 |
call az1 (str1a6) |
| 150 |
if (any (str1a6 /= ['1', & |
| 151 |
'h', & |
| 152 |
'f', & |
| 153 |
'3', & |
| 154 |
'4', & |
| 155 |
'h'])) stop |
| 156 |
! str2a6 = ['ab', & |
| 157 |
! 'fd', & |
| 158 |
! 'D4', & |
| 159 |
! '54', & |
| 160 |
! 'ga', & |
| 161 |
! 'hg'] |
| 162 |
! call az2 (str2a6) |
| 163 |
! if (any (str2a6 /= ['ab', & |
| 164 |
! 'hd', & |
| 165 |
! 'fj', & |
| 166 |
! 'a4', & |
| 167 |
! '4a', & |
| 168 |
! 'hf'])) stop |
| 169 |
|
| 170 |
! explicit size - without array descriptor |
| 171 |
|
| 172 |
str1a6 = ['g', & |
| 173 |
'd', & |
| 174 |
'f', & |
| 175 |
's', & |
| 176 |
'3', & |
| 177 |
'5'] |
| 178 |
call ae1 (str1a6) |
| 179 |
if (any (str1a6 /= ['1', & |
| 180 |
'h', & |
| 181 |
'f', & |
| 182 |
'3', & |
| 183 |
'4', & |
| 184 |
'h'])) stop |
| 185 |
! str2a6 = ['ab', & |
| 186 |
! 'fd', & |
| 187 |
! 'D4', & |
| 188 |
! '54', & |
| 189 |
! 'ga', & |
| 190 |
! 'hg'] |
| 191 |
! call ae2 (str2a6) |
| 192 |
! if (any (str2a6 /= ['ab', & |
| 193 |
! 'hd', & |
| 194 |
! 'fj', & |
| 195 |
! 'a4', & |
| 196 |
! '4a', & |
| 197 |
! 'hf'])) stop |
| 198 |
end |
| 199 |
|
| 200 |
! All argument shall be passed without descriptor |
| 201 |
! { dg-final { scan-tree-dump-not "dtype" "original" } } |
| 202 |
! { dg-final { scan-tree-dump-times "void s1 \\(character\\(kind=1\\)\\\[1:1\\\] & restrict x1\\)" 1 "original" } } |
| 203 |
! { dg-final { scan-tree-dump-not "void s2 " "original" } } |
| 204 |
! { dg-final { scan-tree-dump-times "void az1 \\(character\\(kind=1\\)\\\[0:\\\]\\\[1:1\\\] \\* restrict x1\\)" 1 "original" } } |
| 205 |
! { dg-final { scan-tree-dump-not "void az2 " "original" } } |
| 206 |
! { dg-final { scan-tree-dump-times "void ae1 \\(character\\(kind=1\\)\\\[6\\\]\\\[1:1\\\] \\* restrict x1\\)" 1 "original" } } |
| 207 |
! { dg-final { scan-tree-dump-not "void ae2 " "original" } } |