|
| 1 | +!RUN: %python %S/test_errors.py %s %flang_fc1 -Werror -Wpass-global-variable |
| 2 | +module test_mod |
| 3 | + implicit none (type, external) |
| 4 | + |
| 5 | + type :: wt |
| 6 | + integer :: ival |
| 7 | + end type wt |
| 8 | + type :: qt |
| 9 | + type(wt) :: w |
| 10 | + end type qt |
| 11 | + type(wt) :: w(2) |
| 12 | + type(qt) :: q |
| 13 | + |
| 14 | + integer, parameter :: ipar = 1 |
| 15 | + integer, private :: ipri |
| 16 | + integer, public :: ipub |
| 17 | + |
| 18 | + common /ex/ ic |
| 19 | + integer :: ic |
| 20 | + |
| 21 | +contains |
| 22 | + subroutine pass_int_in(i) |
| 23 | + integer, intent(in) :: i |
| 24 | + end subroutine pass_int_in |
| 25 | + subroutine pass_int(i) |
| 26 | + integer, intent(inout) :: i |
| 27 | + end subroutine pass_int |
| 28 | + pure subroutine pure_int(i) |
| 29 | + integer, intent(inout) :: i |
| 30 | + end subroutine pure_int |
| 31 | + subroutine pass_ival(i) |
| 32 | + integer, value :: i |
| 33 | + end subroutine pass_ival |
| 34 | + subroutine pass_qt(q) |
| 35 | + type(qt), intent(in) :: q |
| 36 | + end subroutine pass_qt |
| 37 | + |
| 38 | + subroutine tests() |
| 39 | + |
| 40 | + call pass_ival(ipub) !< ok: pass to value |
| 41 | + call pass_int_in(ipar) !< ok: pass parameter |
| 42 | + call pass_int(ipri) !< ok: pass private |
| 43 | + !WARNING: Passing global variable 'ipub' from MODULE 'test_mod' as function argument [-Wpass-global-variable] |
| 44 | + call pass_int(ipub) !< warn: pass public |
| 45 | + call pure_int(ipub) !< ok: pass to pure |
| 46 | + call pass_int(w(1)%ival) !< ok: comes from derived |
| 47 | + call pass_qt(q) !< ok: derived |
| 48 | + |
| 49 | + ipub = iand(ipub, ipar) !< ok: passed to intrinsic |
| 50 | + |
| 51 | + call pass_ival(ic) !< ok: passed to value |
| 52 | + !WARNING: Passing global variable 'ic' from COMMON 'ex' as function argument [-Wpass-global-variable] |
| 53 | + call pass_int_in(ic) !< warn: intent(in) does not guarantee that ic is not changing during call |
| 54 | + !WARNING: Passing global variable 'ic' from COMMON 'ex' as function argument [-Wpass-global-variable] |
| 55 | + call pass_int(ic) !< warn: global variable may be changed during call |
| 56 | + call pure_int(ic) !< ok: pure keeps value |
| 57 | + |
| 58 | + ic = iand(ic, ic) !< ok: passed to intrinsic |
| 59 | + |
| 60 | + end subroutine tests |
| 61 | +end module test_mod |
0 commit comments