Debian Codegraph @

gcc/testsuite/gfortran.dg/intent_optimize_10.f90

raw
1 ! { dg-do run }
2 ! { dg-additional-options "-fno-inline -fno-ipa-modref -fdump-tree-optimized -fdump-tree-original" }
3 !
4 ! PR fortran/41453
5 ! Check that the INTENT(OUT) attribute causes in the case of non-polymorphic derived type arguments:
6 ! - one clobber to be emitted in the caller before calls to FOO in the *.original dump,
7 ! - no clobber to be emitted in the caller before calls to BAR in the *.original dump,
8 ! - the initialization constants to be optimized away in the *.optimized dump.
9
10 module x
11 implicit none
12 type :: t
13 integer :: c
14 end type t
15 type, extends(t) :: u
16 integer :: d
17 end type u
18 contains
19 subroutine foo(a)
20 type(t), intent(out) :: a
21 a = t(42)
22 end subroutine foo
23 subroutine bar(b)
24 class(t), intent(out) :: b
25 b%c = 24
26 end subroutine bar
27 end module x
28
29 program main
30 use x
31 implicit none
32 type(t) :: tc
33 type(u) :: uc, ud
34 class(t), allocatable :: te, tf
35
36 tc = t(123456789)
37 call foo(tc)
38 if (tc%c /= 42) stop 1
39
40 uc = u(987654321, 0)
41 call foo(uc%t)
42 if (uc%c /= 42) stop 2
43 if (uc%d /= 0) stop 3
44
45 ud = u(11223344, 0)
46 call bar(ud)
47 if (ud%c /= 24) stop 4
48
49 te = t(55667788)
50 call foo(te)
51 if (te%c /= 42) stop 5
52
53 tf = t(99887766)
54 call bar(tf)
55 if (tf%c /= 24) stop 6
56
57 end program main
58
59 ! We don't support class descriptors, neither derived type components, so there is a clobber for tc only;
60 ! no clobber for uc, ud, te, tf.
61 ! { dg-final { scan-tree-dump-times "CLOBBER" 1 "original" } }
62 ! { dg-final { scan-tree-dump "tc = {CLOBBER};" "original" } }
63
64 ! There is a clobber for tc, so we should manage to optimize away the associated initialization constant (but not other
65 ! initialization constants).
66 ! { dg-final { scan-tree-dump-not "123456789" "optimized" { target __OPTIMIZE__ } } }