| 1 |
! { dg-do run } |
| 2 |
! { dg-additional-options "-fdump-tree-original -fsanitize=undefined" } |
| 3 |
! |
| 4 |
! PR fortran/101135 - Load of null pointer when passing absent |
| 5 |
! assumed-shape array argument for an optional dummy argument |
| 6 |
! |
| 7 |
! Based on testcase by Marcel Jacobse |
| 8 |
|
| 9 |
program main |
| 10 |
implicit none |
| 11 |
character(len=3) :: a(6) = ['abc', 'def', 'ghi', 'jlm', 'nop', 'qrs'] |
| 12 |
call as () |
| 13 |
call as (a(::2)) |
| 14 |
call as_c () |
| 15 |
call as_c (a(2::2)) |
| 16 |
call test_wrapper |
| 17 |
call test_wrapper_c |
| 18 |
call test_ar_wrapper |
| 19 |
call test_ar_wrapper_c |
| 20 |
contains |
| 21 |
subroutine as (xx) |
| 22 |
character(len=*), optional, intent(in) :: xx(*) |
| 23 |
if (.not. present (xx)) return |
| 24 |
print *, xx(1:3) |
| 25 |
end subroutine as |
| 26 |
|
| 27 |
subroutine as_c (zz) bind(c) |
| 28 |
character(len=*), optional, intent(in) :: zz(*) |
| 29 |
if (.not. present (zz)) return |
| 30 |
print *, zz(1:3) |
| 31 |
end subroutine as_c |
| 32 |
|
| 33 |
subroutine test_wrapper (x) |
| 34 |
real, dimension(1), intent(out), optional :: x |
| 35 |
call test (x) |
| 36 |
call test1 (x) |
| 37 |
call test_c (x) |
| 38 |
call test1_c (x) |
| 39 |
end subroutine test_wrapper |
| 40 |
|
| 41 |
subroutine test_wrapper_c (w) bind(c) |
| 42 |
real, dimension(1), intent(out), optional :: w |
| 43 |
call test (w) |
| 44 |
call test1 (w) |
| 45 |
call test_c (w) |
| 46 |
call test1_c (w) |
| 47 |
end subroutine test_wrapper_c |
| 48 |
|
| 49 |
subroutine test (y) |
| 50 |
real, dimension(:), intent(out), optional :: y |
| 51 |
if (present (y)) y=0. |
| 52 |
end subroutine test |
| 53 |
|
| 54 |
subroutine test_c (y) bind(c) |
| 55 |
real, dimension(:), intent(out), optional :: y |
| 56 |
if (present (y)) y=0. |
| 57 |
end subroutine test_c |
| 58 |
|
| 59 |
subroutine test1 (y) |
| 60 |
real, dimension(1), intent(out), optional :: y |
| 61 |
if (present (y)) y=0. |
| 62 |
end subroutine test1 |
| 63 |
|
| 64 |
subroutine test1_c (y) bind(c) |
| 65 |
real, dimension(1), intent(out), optional :: y |
| 66 |
if (present (y)) y=0. |
| 67 |
end subroutine test1_c |
| 68 |
|
| 69 |
subroutine test_ar_wrapper (p, q, r) |
| 70 |
real, intent(out), optional :: p |
| 71 |
real, dimension(1), intent(out), optional :: q |
| 72 |
real, dimension(:), intent(out), optional :: r |
| 73 |
call test_ar (p) |
| 74 |
call test_ar (q) |
| 75 |
call test_ar (r) |
| 76 |
call test_ar_c (p) |
| 77 |
call test_ar_c (q) |
| 78 |
call test_ar_c (r) |
| 79 |
end subroutine test_ar_wrapper |
| 80 |
|
| 81 |
subroutine test_ar_wrapper_c (u, v, s) bind(c) |
| 82 |
real, intent(out), optional :: u |
| 83 |
real, dimension(1), intent(out), optional :: v |
| 84 |
real, dimension(:), intent(out), optional :: s |
| 85 |
call test_ar (u) |
| 86 |
call test_ar (v) |
| 87 |
! call test_ar (s) ! Disabled due to runtime segfault, see pr114355 |
| 88 |
call test_ar_c (u) |
| 89 |
call test_ar_c (v) |
| 90 |
call test_ar_c (s) |
| 91 |
end subroutine test_ar_wrapper_c |
| 92 |
|
| 93 |
subroutine test_ar (z) |
| 94 |
real, dimension(..), intent(out), optional :: z |
| 95 |
end subroutine test_ar |
| 96 |
|
| 97 |
subroutine test_ar_c (z) bind(c) |
| 98 |
real, dimension(..), intent(out), optional :: z |
| 99 |
end subroutine test_ar_c |
| 100 |
end program |
| 101 |
|
| 102 |
! { dg-final { scan-tree-dump-times "data = v != 0B " 2 "original" } } |
| 103 |
! { dg-final { scan-tree-dump-times "data = w != 0B " 2 "original" } } |
| 104 |
! { dg-final { scan-tree-dump-times "data = q != 0B " 2 "original" } } |
| 105 |
! { dg-final { scan-tree-dump-times "data = x != 0B " 2 "original" } } |
| 106 |
! { dg-final { scan-tree-dump-times "data = xx.0 != 0B " 1 "original" } } |
| 107 |
! { dg-output " abcghinop(\n|\r\n|\r)" }" |
| 108 |
! { dg-output " defjlmqrs(\n|\r\n|\r)" }" |