| 1 |
! { dg-do compile } |
| 2 |
! { dg-options "-fdump-tree-original -fcheck=bounds" } |
| 3 |
! |
| 4 |
! Test the fix forPR119273, which caused false bounds check errors. |
| 5 |
! |
| 6 |
! Contributed by Jingwei Xing <[email protected]> |
| 7 |
! |
| 8 |
module test_module |
| 9 |
type :: test_type_father |
| 10 |
integer :: val |
| 11 |
contains |
| 12 |
procedure :: test_function3 |
| 13 |
end type test_type_father |
| 14 |
|
| 15 |
type, extends(test_type_father) :: test_type_child |
| 16 |
contains |
| 17 |
procedure :: test_function1 |
| 18 |
end type test_type_child |
| 19 |
|
| 20 |
integer :: ii |
| 21 |
|
| 22 |
contains |
| 23 |
function test_function1(a) result(out) |
| 24 |
class(test_type_child), intent(in) :: a |
| 25 |
integer :: out |
| 26 |
ii = a%val ! Make this function implicitly impure. |
| 27 |
out = a%val |
| 28 |
end function |
| 29 |
pure function test_function2(a) result(out) |
| 30 |
type(test_type_child), intent(in) :: a |
| 31 |
integer :: out |
| 32 |
out = a%val |
| 33 |
end function |
| 34 |
pure function test_function3(a) result(out) |
| 35 |
class(test_type_father), intent(in) :: a |
| 36 |
integer :: out |
| 37 |
out = a%val |
| 38 |
end function |
| 39 |
end module |
| 40 |
|
| 41 |
program test |
| 42 |
use test_module |
| 43 |
implicit none |
| 44 |
type(test_type_child) :: a |
| 45 |
type(test_type_father) :: b |
| 46 |
class(test_type_child), allocatable :: c |
| 47 |
integer, target :: temp_int(1,1) |
| 48 |
integer, pointer :: d(:) |
| 49 |
a%val = 0 |
| 50 |
associate(temp => temp_int(:,a%test_function1() + 1)) ! { dg-warning "is not implicitly pure" } |
| 51 |
end associate |
| 52 |
a%val = 1 |
| 53 |
associate(temp => temp_int(:,test_function2(a))) |
| 54 |
end associate |
| 55 |
b%val = 1 |
| 56 |
associate(temp => temp_int(:,b%test_function3())) |
| 57 |
end associate |
| 58 |
associate(temp => temp_int(:,test_function3(b))) |
| 59 |
end associate |
| 60 |
allocate (c, source = a) |
| 61 |
associate(temp => temp_int(:,c%test_function1())) ! { dg-warning "is not implicitly pure" } |
| 62 |
end associate |
| 63 |
|
| 64 |
! Demonstrate that this bug was not specific to the ASSOCIATE statement but, |
| 65 |
! rather to it being a pointer assignment, when the selector is a variable. |
| 66 |
d => temp_int(:,a%test_function1()) ! { dg-warning "is not implicitly pure" } |
| 67 |
|
| 68 |
end program test |
| 69 |
! Test for the missing vptr assignments to the class actual temporaries. |
| 70 |
! { dg-final { scan-tree-dump-times "class..._vptr =" 8 "original" } } |