RISC-V: Regenerate opt urls.
[official-gcc.git] / gcc / testsuite / gfortran.dg / alloc_comp_result_3.f90
blob8c4c982c67f293068105e5bfca49f360aeb50fa7
1 ! { dg-do run }
3 ! Test the fix for PR96495 - segfaults at runtime at locations below.
5 ! Contributed by Paul Luckner <paul.luckner@rwth-aachen.de>
7 module foo_m
9 implicit none
11 type foo
12 integer, allocatable :: j(:)
13 end type
15 interface operator(.unary.)
16 module procedure neg_foo
17 end interface
19 interface operator(.binary.)
20 module procedure foo_sub_foo
21 end interface
23 interface operator(.binaryElemental.)
24 module procedure foo_add_foo
25 end interface
27 contains
29 elemental function foo_add_foo(f, g) result(h)
30 !! an example for an elemental binary operator
31 type(foo), intent(in) :: f, g
32 type(foo) :: h
34 allocate (h%j(size(f%j)), source = f%j+g%j)
35 end function
37 elemental function foo_sub_foo(f, g) result(h)
38 !! an example for an elemental binary operator
39 type(foo), intent(in) :: f, g
40 type(foo) :: h
42 allocate (h%j(size(f%j)), source = f%j-3*g%j)
43 end function
45 pure function neg_foo(f) result(g)
46 !! an example for a unary operator
47 type(foo), intent(in) :: f
48 type(foo) :: g
50 allocate (g%j(size(f%j)), source = -f%j)
51 end function
53 end module
55 program main_tmp
57 use foo_m
59 implicit none
61 type(foo) f, g(2)
63 allocate (f%j(3))
64 f%j = [2, 3, 4]
66 g = f
67 if (any (g(2)%j .ne. [2, 3, 4])) stop 1
69 g = g .binaryElemental. (f .binary. f) ! threw "Segmentation fault"
70 if (any (g(2)%j .ne. [-2,-3,-4])) stop 2
72 g = g .binaryElemental. ( .unary. f) ! threw "Segmentation fault"
73 if (any (g(2)%j .ne. [-4,-6,-8])) stop 3
75 end program