xref: /llvm-project/flang/test/Semantics/modfile71.F90 (revision 038b42ba5b47b1aa2d47ef5706a713f6bfbbc37c)
1!RUN: %flang_fc1 -fsyntax-only -fhermetic-module-files -DSTEP=1 %s
2!RUN: %flang_fc1 -fsyntax-only -DSTEP=2 %s
3!RUN: not %flang_fc1 -fsyntax-only -pedantic %s 2>&1 | FileCheck %s
4
5! Tests that a module captured in a hermetic module file is compatible when
6! USE'd with a module of the same name USE'd directly.
7
8#if STEP == 1
9module modfile71a
10  ! not errors
11  integer, parameter :: good_named_const = 123
12  integer :: good_var = 1
13  type :: good_derived
14    integer component
15  end type
16  procedure(), pointer :: good_proc_ptr
17  generic :: gen => bad_subroutine
18  ! bad, but okay if unused
19  integer, parameter :: unused_bad_named_const = 123
20  integer :: unused_bad_var = 1
21  type :: unused_bad_derived
22    integer component
23  end type
24  procedure(), pointer :: unused_bad_proc_ptr
25  ! errors
26  integer, parameter :: bad_named_const = 123
27  integer :: bad_var = 1
28  type :: bad_derived
29    integer component
30  end type
31  procedure(), pointer :: bad_proc_ptr
32 contains
33  subroutine good_subroutine
34  end
35  subroutine unused_bad_subroutine(x)
36    integer x
37  end
38  subroutine bad_subroutine(x)
39    integer x
40  end
41end
42
43module modfile71b
44  use modfile71a ! capture hermetically
45end
46
47#elif STEP == 2
48module modfile71a
49  ! not errors
50  integer, parameter :: good_named_const = 123
51  integer :: good_var = 1
52  type :: good_derived
53    integer component
54  end type
55  procedure(), pointer :: good_proc_ptr
56  generic :: gen => bad_subroutine
57  ! bad, but okay if unused
58  integer, parameter :: unused_bad_named_const = 666
59  real :: unused_bad_var = 1.
60  type :: unused_bad_derived
61    real component
62  end type
63  real, pointer :: unused_bad_proc_ptr
64  ! errors
65  integer, parameter :: bad_named_const = 666
66  real :: bad_var = 1.
67  type :: bad_derived
68    real component
69  end type
70  real, pointer :: bad_proc_ptr
71 contains
72  subroutine good_subroutine
73  end
74  subroutine unused_bad_subroutine(x)
75    real x
76  end
77  subroutine bad_subroutine(x)
78    real x
79  end
80end
81
82#else
83
84!CHECK: warning: 'bad_derived' is use-associated from 'bad_derived' in two distinct instances of module 'modfile71a'
85!CHECK: warning: 'bad_named_const' is use-associated from 'bad_named_const' in two distinct instances of module 'modfile71a'
86!CHECK: warning: 'bad_proc_ptr' is use-associated from 'bad_proc_ptr' in two distinct instances of module 'modfile71a'
87!CHECK: warning: 'bad_subroutine' is use-associated from 'bad_subroutine' in two distinct instances of module 'modfile71a'
88!CHECK: warning: 'bad_var' is use-associated from 'bad_var' in two distinct instances of module 'modfile71a'
89!CHECK: warning: 'good_derived' is use-associated from 'good_derived' in two distinct instances of module 'modfile71a'
90!CHECK: warning: 'good_named_const' is use-associated from 'good_named_const' in two distinct instances of module 'modfile71a'
91!CHECK: warning: 'good_proc_ptr' is use-associated from 'good_proc_ptr' in two distinct instances of module 'modfile71a'
92!CHECK: warning: 'good_subroutine' is use-associated from 'good_subroutine' in two distinct instances of module 'modfile71a'
93!CHECK: warning: 'good_var' is use-associated from 'good_var' in two distinct instances of module 'modfile71a'
94!CHECK: warning: 'unused_bad_derived' is use-associated from 'unused_bad_derived' in two distinct instances of module 'modfile71a'
95!CHECK: warning: 'unused_bad_named_const' is use-associated from 'unused_bad_named_const' in two distinct instances of module 'modfile71a'
96!CHECK: warning: 'unused_bad_proc_ptr' is use-associated from 'unused_bad_proc_ptr' in two distinct instances of module 'modfile71a'
97!CHECK: warning: 'unused_bad_subroutine' is use-associated from 'unused_bad_subroutine' in two distinct instances of module 'modfile71a'
98!CHECK: warning: 'unused_bad_var' is use-associated from 'unused_bad_var' in two distinct instances of module 'modfile71a'
99!CHECK: error: Reference to 'bad_derived' is ambiguous
100!CHECK: error: Reference to 'bad_named_const' is ambiguous
101!CHECK: error: Reference to 'bad_var' is ambiguous
102!CHECK: error: Reference to 'bad_proc_ptr' is ambiguous
103!CHECK: error: Reference to 'bad_subroutine' is ambiguous
104!CHECK-NOT: error:
105!CHECK-NOT: warning:
106
107program main
108  use modfile71a
109  use modfile71b
110  type(good_derived) goodx
111  type(bad_derived) badx
112  print *, good_named_const
113  good_var = 1
114  good_proc_ptr => null()
115  call good_subroutine
116  print *, bad_named_const
117  print *, bad_var
118  bad_proc_ptr => null()
119  call bad_subroutine(1)
120end
121#endif
122