Skip to content

Commit b6a7600

Browse files
committed
[flang] IEEE_ARITHMETIC must imply USE IEEE_EXCEPTIONS
The intrinsic module IEEE_ARITHMETIC must incorporate the public names from the intrisic module IEEE_EXCEPTIONS. Rename IEEE_EXCEPTIONS to __Fortran_ieee_exceptions so that it won't clash with the nonintrinsic namespace, establish a new intrinic IEEE_EXCEPTIONS module that USEs it, and add a USE to IEEE_ARITHMETIC. Differential Revision: https://reviews.llvm.org/D121490
1 parent c231deb commit b6a7600

File tree

5 files changed

+142
-116
lines changed

5 files changed

+142
-116
lines changed

flang/lib/Semantics/check-do-forall.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ class DoConcurrentBodyEnforce {
279279
" CONCURRENT"_err_en_US,
280280
doConcurrentSourcePosition_);
281281
}
282-
if (name->symbol && fromScope(*name->symbol, "ieee_exceptions"s)) {
282+
if (name->symbol &&
283+
fromScope(*name->symbol, "__fortran_ieee_exceptions"s)) {
283284
if (name->source == "ieee_set_halting_mode") {
284285
SayWithDo(context_, currentStatementSourcePosition_,
285286
"IEEE_SET_HALTING_MODE is not allowed in DO "
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
!===-- module/__fortran_ieee_exceptions.f90 --------------------------------===!
2+
!
3+
! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
! See https://llvm.org/LICENSE.txt for license information.
5+
! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
!
7+
!===------------------------------------------------------------------------===!
8+
9+
! See Fortran 2018, clause 17
10+
! The content of the standard intrinsic IEEE_EXCEPTIONS module is packaged
11+
! here under another name so that IEEE_ARITHMETIC can USE it and export its
12+
! declarations without clashing with a non-intrinsic module in a program.
13+
14+
module __Fortran_ieee_exceptions
15+
16+
type :: ieee_flag_type ! Fortran 2018, 17.2 & 17.3
17+
private
18+
integer(kind=1) :: flag = 0
19+
end type ieee_flag_type
20+
21+
type(ieee_flag_type), parameter :: &
22+
ieee_invalid = ieee_flag_type(1), &
23+
ieee_overflow = ieee_flag_type(2), &
24+
ieee_divide_by_zero = ieee_flag_type(4), &
25+
ieee_underflow = ieee_flag_type(8), &
26+
ieee_inexact = ieee_flag_type(16), &
27+
ieee_denorm = ieee_flag_type(32) ! PGI extension
28+
29+
type(ieee_flag_type), parameter :: &
30+
ieee_usual(*) = [ &
31+
ieee_overflow, ieee_divide_by_zero, ieee_invalid ], &
32+
ieee_all(*) = [ &
33+
ieee_usual, ieee_underflow, ieee_inexact, ieee_denorm ]
34+
35+
type :: ieee_modes_type ! Fortran 2018, 17.7
36+
private
37+
end type ieee_modes_type
38+
39+
type :: ieee_status_type ! Fortran 2018, 17.7
40+
private
41+
end type ieee_status_type
42+
43+
private :: ieee_support_flag_2, ieee_support_flag_3, &
44+
ieee_support_flag_4, ieee_support_flag_8, ieee_support_flag_10, &
45+
ieee_support_flag_16
46+
interface ieee_support_flag
47+
module procedure :: ieee_support_flag, &
48+
ieee_support_flag_2, ieee_support_flag_3, &
49+
ieee_support_flag_4, ieee_support_flag_8, ieee_support_flag_10, &
50+
ieee_support_flag_16
51+
end interface
52+
53+
contains
54+
elemental subroutine ieee_get_flag(flag, flag_value)
55+
type(ieee_flag_type), intent(in) :: flag
56+
logical, intent(out) :: flag_value
57+
end subroutine ieee_get_flag
58+
59+
elemental subroutine ieee_get_halting_mode(flag, halting)
60+
type(ieee_flag_type), intent(in) :: flag
61+
logical, intent(out) :: halting
62+
end subroutine ieee_get_halting_mode
63+
64+
subroutine ieee_get_modes(modes)
65+
type(ieee_modes_type), intent(out) :: modes
66+
end subroutine ieee_get_modes
67+
68+
subroutine ieee_get_status(status)
69+
type(ieee_status_type), intent(out) :: status
70+
end subroutine ieee_get_status
71+
72+
pure subroutine ieee_set_flag(flag, flag_value)
73+
type(ieee_flag_type), intent(in) :: flag
74+
logical, intent(in) :: flag_value
75+
end subroutine ieee_set_flag
76+
77+
pure subroutine ieee_set_halting_mode(flag, halting)
78+
type(ieee_flag_type), intent(in) :: flag
79+
logical, intent(in) :: halting
80+
end subroutine ieee_set_halting_mode
81+
82+
subroutine ieee_set_modes(modes)
83+
type(ieee_modes_type), intent(in) :: modes
84+
end subroutine ieee_set_modes
85+
86+
subroutine ieee_set_status(status)
87+
type(ieee_status_type), intent(in) :: status
88+
end subroutine ieee_set_status
89+
90+
pure logical function ieee_support_flag(flag)
91+
type(ieee_flag_type), intent(in) :: flag
92+
ieee_support_flag = .true.
93+
end function
94+
pure logical function ieee_support_flag_2(flag, x)
95+
type(ieee_flag_type), intent(in) :: flag
96+
real(kind=2), intent(in) :: x(..)
97+
ieee_support_flag_2 = .true.
98+
end function
99+
pure logical function ieee_support_flag_3(flag, x)
100+
type(ieee_flag_type), intent(in) :: flag
101+
real(kind=3), intent(in) :: x(..)
102+
ieee_support_flag_3 = .true.
103+
end function
104+
pure logical function ieee_support_flag_4(flag, x)
105+
type(ieee_flag_type), intent(in) :: flag
106+
real(kind=4), intent(in) :: x(..)
107+
ieee_support_flag_4 = .true.
108+
end function
109+
pure logical function ieee_support_flag_8(flag, x)
110+
type(ieee_flag_type), intent(in) :: flag
111+
real(kind=8), intent(in) :: x(..)
112+
ieee_support_flag_8 = .true.
113+
end function
114+
pure logical function ieee_support_flag_10(flag, x)
115+
type(ieee_flag_type), intent(in) :: flag
116+
real(kind=10), intent(in) :: x(..)
117+
ieee_support_flag_10 = .true.
118+
end function
119+
pure logical function ieee_support_flag_16(flag, x)
120+
type(ieee_flag_type), intent(in) :: flag
121+
real(kind=16), intent(in) :: x(..)
122+
ieee_support_flag_16 = .true.
123+
end function
124+
125+
pure logical function ieee_support_halting(flag)
126+
type(ieee_flag_type), intent(in) :: flag
127+
end function ieee_support_halting
128+
129+
end module __Fortran_ieee_exceptions

flang/module/ieee_arithmetic.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ module ieee_arithmetic
2929
ieee_support_subnormal => __builtin_ieee_support_subnormal, &
3030
ieee_support_underflow_control => __builtin_ieee_support_underflow_control
3131

32+
! 17.1: "The module IEEE_ARITHMETIC behaves as if it contained a USE statement
33+
! for IEEE_EXCEPTIONS; everything that is public in IEEE_EXCEPTIONS is public
34+
! in IEEE_ARITHMETIC."
35+
use __Fortran_ieee_exceptions
36+
3237
implicit none
3338

3439
type :: ieee_class_type

flang/module/ieee_exceptions.f90

Lines changed: 1 addition & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -6,120 +6,6 @@
66
!
77
!===------------------------------------------------------------------------===!
88

9-
! See Fortran 2018, clause 17
109
module ieee_exceptions
11-
12-
type :: ieee_flag_type ! Fortran 2018, 17.2 & 17.3
13-
private
14-
integer(kind=1) :: flag = 0
15-
end type ieee_flag_type
16-
17-
type(ieee_flag_type), parameter :: &
18-
ieee_invalid = ieee_flag_type(1), &
19-
ieee_overflow = ieee_flag_type(2), &
20-
ieee_divide_by_zero = ieee_flag_type(4), &
21-
ieee_underflow = ieee_flag_type(8), &
22-
ieee_inexact = ieee_flag_type(16), &
23-
ieee_denorm = ieee_flag_type(32) ! PGI extension
24-
25-
type(ieee_flag_type), parameter :: &
26-
ieee_usual(*) = [ &
27-
ieee_overflow, ieee_divide_by_zero, ieee_invalid ], &
28-
ieee_all(*) = [ &
29-
ieee_usual, ieee_underflow, ieee_inexact, ieee_denorm ]
30-
31-
type :: ieee_modes_type ! Fortran 2018, 17.7
32-
private
33-
end type ieee_modes_type
34-
35-
type :: ieee_status_type ! Fortran 2018, 17.7
36-
private
37-
end type ieee_status_type
38-
39-
private :: ieee_support_flag_2, ieee_support_flag_3, &
40-
ieee_support_flag_4, ieee_support_flag_8, ieee_support_flag_10, &
41-
ieee_support_flag_16
42-
interface ieee_support_flag
43-
module procedure :: ieee_support_flag, &
44-
ieee_support_flag_2, ieee_support_flag_3, &
45-
ieee_support_flag_4, ieee_support_flag_8, ieee_support_flag_10, &
46-
ieee_support_flag_16
47-
end interface
48-
49-
contains
50-
elemental subroutine ieee_get_flag(flag, flag_value)
51-
type(ieee_flag_type), intent(in) :: flag
52-
logical, intent(out) :: flag_value
53-
end subroutine ieee_get_flag
54-
55-
elemental subroutine ieee_get_halting_mode(flag, halting)
56-
type(ieee_flag_type), intent(in) :: flag
57-
logical, intent(out) :: halting
58-
end subroutine ieee_get_halting_mode
59-
60-
subroutine ieee_get_modes(modes)
61-
type(ieee_modes_type), intent(out) :: modes
62-
end subroutine ieee_get_modes
63-
64-
subroutine ieee_get_status(status)
65-
type(ieee_status_type), intent(out) :: status
66-
end subroutine ieee_get_status
67-
68-
pure subroutine ieee_set_flag(flag, flag_value)
69-
type(ieee_flag_type), intent(in) :: flag
70-
logical, intent(in) :: flag_value
71-
end subroutine ieee_set_flag
72-
73-
pure subroutine ieee_set_halting_mode(flag, halting)
74-
type(ieee_flag_type), intent(in) :: flag
75-
logical, intent(in) :: halting
76-
end subroutine ieee_set_halting_mode
77-
78-
subroutine ieee_set_modes(modes)
79-
type(ieee_modes_type), intent(in) :: modes
80-
end subroutine ieee_set_modes
81-
82-
subroutine ieee_set_status(status)
83-
type(ieee_status_type), intent(in) :: status
84-
end subroutine ieee_set_status
85-
86-
pure logical function ieee_support_flag(flag)
87-
type(ieee_flag_type), intent(in) :: flag
88-
ieee_support_flag = .true.
89-
end function
90-
pure logical function ieee_support_flag_2(flag, x)
91-
type(ieee_flag_type), intent(in) :: flag
92-
real(kind=2), intent(in) :: x(..)
93-
ieee_support_flag_2 = .true.
94-
end function
95-
pure logical function ieee_support_flag_3(flag, x)
96-
type(ieee_flag_type), intent(in) :: flag
97-
real(kind=3), intent(in) :: x(..)
98-
ieee_support_flag_3 = .true.
99-
end function
100-
pure logical function ieee_support_flag_4(flag, x)
101-
type(ieee_flag_type), intent(in) :: flag
102-
real(kind=4), intent(in) :: x(..)
103-
ieee_support_flag_4 = .true.
104-
end function
105-
pure logical function ieee_support_flag_8(flag, x)
106-
type(ieee_flag_type), intent(in) :: flag
107-
real(kind=8), intent(in) :: x(..)
108-
ieee_support_flag_8 = .true.
109-
end function
110-
pure logical function ieee_support_flag_10(flag, x)
111-
type(ieee_flag_type), intent(in) :: flag
112-
real(kind=10), intent(in) :: x(..)
113-
ieee_support_flag_10 = .true.
114-
end function
115-
pure logical function ieee_support_flag_16(flag, x)
116-
type(ieee_flag_type), intent(in) :: flag
117-
real(kind=16), intent(in) :: x(..)
118-
ieee_support_flag_16 = .true.
119-
end function
120-
121-
pure logical function ieee_support_halting(flag)
122-
type(ieee_flag_type), intent(in) :: flag
123-
end function ieee_support_halting
124-
10+
use __Fortran_ieee_exceptions
12511
end module ieee_exceptions

flang/tools/f18/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set(LLVM_LINK_COMPONENTS
66

77
set(MODULES
88
"__fortran_builtins"
9+
"__fortran_ieee_exceptions"
910
"__fortran_type_info"
1011
"ieee_arithmetic"
1112
"ieee_exceptions"
@@ -27,6 +28,10 @@ foreach(filename ${MODULES})
2728
if(NOT ${filename} MATCHES "__fortran_type_info")
2829
set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__fortran_type_info.mod)
2930
endif()
31+
if(${filename} MATCHES "ieee_arithmetic" OR
32+
${filename} MATCHES "ieee_exceptions")
33+
set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__fortran_ieee_exceptions.mod)
34+
endif()
3035
endif()
3136
add_custom_command(OUTPUT ${base}.mod
3237
COMMAND ${CMAKE_COMMAND} -E make_directory ${FLANG_INTRINSIC_MODULES_DIR}

0 commit comments

Comments
 (0)