Skip to content

Commit 0ca74c3

Browse files
authored
[flang][NFC] Refactor MODULE definitions to not accidentally leak symbols (#80833)
This PR continues the work started with PR #79006, by setting visibility in MODULES to PRIVATE by default and explicitly exporting only the desired symbols. `omp_lib` needs more work, as it should maybe be compiled from `omp_lib.f90` in `openmp/runtime/src/incluce/omp_lib.f90.var` instead of simply using an INCLUDE for `omp_lib.h`
1 parent b1849a2 commit 0ca74c3

8 files changed

+194
-142
lines changed

flang/module/__cuda_builtins.f90

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,16 @@
1616
blockIdx => __builtin_blockIdx, &
1717
gridDim => __builtin_gridDim, &
1818
warpsize => __builtin_warpsize
19+
20+
implicit none
21+
22+
! Set PRIVATE by default to explicitly only export what is meant
23+
! to be exported by this MODULE.
24+
private
25+
26+
public :: threadIdx, &
27+
blockDim, &
28+
blockIdx, &
29+
gridDim, &
30+
warpsize
1931
end module

flang/module/__fortran_builtins.f90

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,60 @@
1111
! to USE the standard intrinsic modules in order to access the
1212
! standard names of the procedures.
1313
module __fortran_builtins
14+
implicit none
15+
16+
! Set PRIVATE by default to explicitly only export what is meant
17+
! to be exported by this MODULE.
18+
private
1419

1520
intrinsic :: __builtin_c_loc
21+
1622
intrinsic :: __builtin_c_f_pointer
23+
public :: __builtin_c_f_pointer
24+
1725
intrinsic :: sizeof ! extension
26+
public :: sizeof
1827

1928
intrinsic :: selected_int_kind
20-
private :: selected_int_kind
21-
integer, parameter, private :: int64 = selected_int_kind(18)
29+
integer, parameter :: int64 = selected_int_kind(18)
2230

23-
type, bind(c) :: __builtin_c_ptr
31+
type, bind(c), public :: __builtin_c_ptr
2432
integer(kind=int64), private :: __address
2533
end type
2634

27-
type, bind(c) :: __builtin_c_funptr
35+
type, bind(c), public :: __builtin_c_funptr
2836
integer(kind=int64), private :: __address
2937
end type
3038

31-
type :: __builtin_event_type
39+
type, public :: __builtin_event_type
3240
integer(kind=int64), private :: __count
3341
end type
3442

35-
type :: __builtin_notify_type
43+
type, public :: __builtin_notify_type
3644
integer(kind=int64), private :: __count
3745
end type
3846

39-
type :: __builtin_lock_type
47+
type, public :: __builtin_lock_type
4048
integer(kind=int64), private :: __count
4149
end type
4250

43-
type :: __builtin_team_type
51+
type, public :: __builtin_team_type
4452
integer(kind=int64), private :: __id
4553
end type
4654

47-
integer, parameter :: __builtin_atomic_int_kind = selected_int_kind(18)
48-
integer, parameter :: &
55+
integer, parameter, public :: __builtin_atomic_int_kind = selected_int_kind(18)
56+
integer, parameter, public :: &
4957
__builtin_atomic_logical_kind = __builtin_atomic_int_kind
5058

51-
procedure(type(__builtin_c_ptr)) :: __builtin_c_loc
59+
procedure(type(__builtin_c_ptr)), public :: __builtin_c_loc
5260

53-
type :: __builtin_dim3
61+
type, public :: __builtin_dim3
5462
integer :: x=1, y=1, z=1
5563
end type
56-
type(__builtin_dim3) :: &
64+
type(__builtin_dim3), public :: &
5765
__builtin_threadIdx, __builtin_blockDim, __builtin_blockIdx, &
5866
__builtin_gridDim
59-
integer, parameter :: __builtin_warpsize = 32
67+
integer, parameter, public :: __builtin_warpsize = 32
6068

6169
intrinsic :: __builtin_fma
6270
intrinsic :: __builtin_ieee_is_nan, __builtin_ieee_is_negative, &
@@ -71,8 +79,21 @@
7179
__builtin_ieee_support_nan, __builtin_ieee_support_sqrt, &
7280
__builtin_ieee_support_standard, __builtin_ieee_support_subnormal, &
7381
__builtin_ieee_support_underflow_control
82+
public :: __builtin_fma
83+
public :: __builtin_ieee_is_nan, __builtin_ieee_is_negative, &
84+
__builtin_ieee_is_normal
85+
public :: __builtin_ieee_next_after, __builtin_ieee_next_down, &
86+
__builtin_ieee_next_up
87+
public :: scale ! for ieee_scalb
88+
public :: __builtin_ieee_selected_real_kind
89+
public :: __builtin_ieee_support_datatype, &
90+
__builtin_ieee_support_denormal, __builtin_ieee_support_divide, &
91+
__builtin_ieee_support_inf, __builtin_ieee_support_io, &
92+
__builtin_ieee_support_nan, __builtin_ieee_support_sqrt, &
93+
__builtin_ieee_support_standard, __builtin_ieee_support_subnormal, &
94+
__builtin_ieee_support_underflow_control
7495

75-
type, private :: __force_derived_type_instantiations
96+
type :: __force_derived_type_instantiations
7697
type(__builtin_c_ptr) :: c_ptr
7798
type(__builtin_c_funptr) :: c_funptr
7899
type(__builtin_event_type) :: event_type
@@ -81,25 +102,34 @@
81102
end type
82103

83104
intrinsic :: __builtin_compiler_options, __builtin_compiler_version
105+
public :: __builtin_compiler_options, __builtin_compiler_version
84106

85107
interface operator(==)
86108
module procedure __builtin_c_ptr_eq
87109
end interface
110+
public :: operator(==)
111+
88112
interface operator(/=)
89113
module procedure __builtin_c_ptr_eq
90114
end interface
115+
public :: operator(/=)
91116

92117
interface __builtin_c_associated
93118
module procedure c_associated_c_ptr
94119
module procedure c_associated_c_funptr
95120
end interface
96-
private :: c_associated_c_ptr, c_associated_c_funptr
121+
public :: __builtin_c_associated
122+
! private :: c_associated_c_ptr, c_associated_c_funptr
97123

98-
type(__builtin_c_ptr), parameter :: __builtin_c_null_ptr = __builtin_c_ptr(0)
99-
type(__builtin_c_funptr), parameter :: &
124+
type(__builtin_c_ptr), parameter, public :: __builtin_c_null_ptr = __builtin_c_ptr(0)
125+
type(__builtin_c_funptr), parameter, public :: &
100126
__builtin_c_null_funptr = __builtin_c_funptr(0)
101127

102-
contains
128+
public :: __builtin_c_ptr_eq
129+
public :: __builtin_c_ptr_ne
130+
public :: __builtin_c_funloc
131+
132+
contains
103133

104134
elemental logical function __builtin_c_ptr_eq(x, y)
105135
type(__builtin_c_ptr), intent(in) :: x, y

flang/module/__fortran_ieee_exceptions.f90

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@
1414
include '../include/flang/Runtime/magic-numbers.h'
1515

1616
module __fortran_ieee_exceptions
17+
implicit none
1718

18-
type :: ieee_flag_type ! Fortran 2018, 17.2 & 17.3
19+
! Set PRIVATE by default to explicitly only export what is meant
20+
! to be exported by this MODULE.
21+
private
22+
23+
type, public :: ieee_flag_type ! Fortran 2018, 17.2 & 17.3
1924
private
2025
integer(kind=1) :: flag = 0
2126
end type ieee_flag_type
2227

23-
type(ieee_flag_type), parameter :: &
28+
type(ieee_flag_type), parameter, public :: &
2429
ieee_invalid = ieee_flag_type(_FORTRAN_RUNTIME_IEEE_INVALID), &
2530
ieee_overflow = ieee_flag_type(_FORTRAN_RUNTIME_IEEE_OVERFLOW), &
2631
ieee_divide_by_zero = &
@@ -29,16 +34,16 @@
2934
ieee_inexact = ieee_flag_type(_FORTRAN_RUNTIME_IEEE_INEXACT), &
3035
ieee_denorm = ieee_flag_type(_FORTRAN_RUNTIME_IEEE_DENORM) ! extension
3136

32-
type(ieee_flag_type), parameter :: &
37+
type(ieee_flag_type), parameter, public :: &
3338
ieee_usual(*) = [ ieee_overflow, ieee_divide_by_zero, ieee_invalid ], &
3439
ieee_all(*) = [ ieee_usual, ieee_underflow, ieee_inexact ]
3540

36-
type :: ieee_modes_type ! Fortran 2018, 17.7
41+
type, public :: ieee_modes_type ! Fortran 2018, 17.7
3742
private ! opaque fenv.h femode_t data
3843
integer(kind=4) :: __data(_FORTRAN_RUNTIME_IEEE_FEMODE_T_EXTENT)
3944
end type ieee_modes_type
4045

41-
type :: ieee_status_type ! Fortran 2018, 17.7
46+
type, public :: ieee_status_type ! Fortran 2018, 17.7
4247
private ! opaque fenv.h fenv_t data
4348
integer(kind=4) :: __data(_FORTRAN_RUNTIME_IEEE_FENV_T_EXTENT)
4449
end type ieee_status_type
@@ -54,18 +59,6 @@
5459
G(2) G(3) G(4) G(8) G(16)
5560
#endif
5661

57-
! Set PRIVATE accessibility for specifics with 1 LOGICAL or REAL argument for
58-
! generic G.
59-
#define PRIVATE_L(G) private :: \
60-
G##_l1, G##_l2, G##_l4, G##_l8
61-
#if __x86_64__
62-
#define PRIVATE_R(G) private :: \
63-
G##_a2, G##_a3, G##_a4, G##_a8, G##_a10, G##_a16
64-
#else
65-
#define PRIVATE_R(G) private :: \
66-
G##_a2, G##_a3, G##_a4, G##_a8, G##_a16
67-
#endif
68-
6962
#define IEEE_GET_FLAG_L(FVKIND) \
7063
elemental subroutine ieee_get_flag_l##FVKIND(flag, flag_value); \
7164
import ieee_flag_type; \
@@ -75,7 +68,7 @@ end subroutine ieee_get_flag_l##FVKIND;
7568
interface ieee_get_flag
7669
SPECIFICS_L(IEEE_GET_FLAG_L)
7770
end interface ieee_get_flag
78-
PRIVATE_L(IEEE_GET_FLAG)
71+
public :: ieee_get_flag
7972
#undef IEEE_GET_FLAG_L
8073

8174
#define IEEE_GET_HALTING_MODE_L(HKIND) \
@@ -87,7 +80,7 @@ end subroutine ieee_get_halting_mode_l##HKIND;
8780
interface ieee_get_halting_mode
8881
SPECIFICS_L(IEEE_GET_HALTING_MODE_L)
8982
end interface ieee_get_halting_mode
90-
PRIVATE_L(IEEE_GET_HALTING_MODE)
83+
public :: ieee_get_halting_mode
9184
#undef IEEE_GET_HALTING_MODE_L
9285

9386
interface ieee_get_modes
@@ -96,13 +89,15 @@ pure subroutine ieee_get_modes_0(modes)
9689
type(ieee_modes_type), intent(out) :: modes
9790
end subroutine ieee_get_modes_0
9891
end interface
92+
public :: ieee_get_modes
9993

10094
interface ieee_get_status
10195
pure subroutine ieee_get_status_0(status)
10296
import ieee_status_type
10397
type(ieee_status_type), intent(out) :: status
10498
end subroutine ieee_get_status_0
10599
end interface
100+
public :: ieee_get_status
106101

107102
#define IEEE_SET_FLAG_L(FVKIND) \
108103
elemental subroutine ieee_set_flag_l##FVKIND(flag, flag_value); \
@@ -113,7 +108,7 @@ end subroutine ieee_set_flag_l##FVKIND;
113108
interface ieee_set_flag
114109
SPECIFICS_L(IEEE_SET_FLAG_L)
115110
end interface ieee_set_flag
116-
PRIVATE_L(IEEE_SET_FLAG)
111+
public :: ieee_set_flag
117112
#undef IEEE_SET_FLAG_L
118113

119114
#define IEEE_SET_HALTING_MODE_L(HKIND) \
@@ -125,7 +120,7 @@ end subroutine ieee_set_halting_mode_l##HKIND;
125120
interface ieee_set_halting_mode
126121
SPECIFICS_L(IEEE_SET_HALTING_MODE_L)
127122
end interface ieee_set_halting_mode
128-
PRIVATE_L(IEEE_SET_HALTING_MODE)
123+
public :: ieee_set_halting_mode
129124
#undef IEEE_SET_HALTING_MODE_L
130125

131126
interface ieee_set_modes
@@ -134,13 +129,15 @@ subroutine ieee_set_modes_0(modes)
134129
type(ieee_modes_type), intent(in) :: modes
135130
end subroutine ieee_set_modes_0
136131
end interface
132+
public :: ieee_set_modes
137133

138134
interface ieee_set_status
139135
subroutine ieee_set_status_0(status)
140136
import ieee_status_type
141137
type(ieee_status_type), intent(in) :: status
142138
end subroutine ieee_set_status_0
143139
end interface
140+
public :: ieee_set_status
144141

145142
#define IEEE_SUPPORT_FLAG_R(XKIND) \
146143
pure logical function ieee_support_flag_a##XKIND(flag, x); \
@@ -155,7 +152,7 @@ pure logical function ieee_support_flag_0(flag)
155152
end function ieee_support_flag_0
156153
SPECIFICS_R(IEEE_SUPPORT_FLAG_R)
157154
end interface ieee_support_flag
158-
PRIVATE_R(IEEE_SUPPORT_FLAG)
155+
public :: ieee_support_flag
159156
#undef IEEE_SUPPORT_FLAG_R
160157

161158
interface ieee_support_halting
@@ -164,5 +161,6 @@ pure logical function ieee_support_halting_0(flag)
164161
type(ieee_flag_type), intent(in) :: flag
165162
end function ieee_support_halting_0
166163
end interface
164+
public :: ieee_support_halting
167165

168166
end module __fortran_ieee_exceptions

flang/module/__fortran_type_info.f90

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515

1616
use, intrinsic :: __fortran_builtins, &
1717
only: __builtin_c_ptr, __builtin_c_funptr
18+
implicit none
1819

20+
! Set PRIVATE by default to explicitly only export what is meant
21+
! to be exported by this MODULE.
1922
private
2023

2124
integer, parameter :: int64 = selected_int_kind(18)

flang/module/__ppc_types.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
!===------------------------------------------------------------------------===!
88

99
module __ppc_types
10+
implicit none
11+
12+
! Set PRIVATE by default to explicitly only export what is meant
13+
! to be exported by this MODULE.
1014
private
15+
1116
! Definition of derived-types that represent PowerPC vector types.
1217
type __builtin_ppc_intrinsic_vector(element_category, element_kind)
1318
integer, kind :: element_category, element_kind

0 commit comments

Comments
 (0)