Skip to content

Commit 35b4c9f

Browse files
authored
Merge pull request #51 from sourceryinstitute/fix-ibm-build
Fix IBM XL Fortran build
2 parents f497d79 + 1815c43 commit 35b4c9f

File tree

8 files changed

+78
-11
lines changed

8 files changed

+78
-11
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ fpm test --compiler nagfor --flag -fpp
9999

100100
### IBM (`xlf2003_r`)
101101
```
102-
fpm test --compiler xlf2003_r
102+
fpm test --compiler xlf2003_r --flag -DXLF
103103
```
104104

105105
### Intel (`ifort`)
106106
```
107-
fpm test --compiler ifort --flag -coarray=shared
107+
fpm test --compiler ifort --flag
108108
```
109109

110110
### GCC (`gfortran`)

Diff for: example/test-support/specification_expression_finalization.f90 renamed to example/test-support/specification_expression_finalization.F90

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
module finalizable_m
2-
!! This module supports the specification_expression_finalization main program
3-
!! (at the bottom of this file), which in turn supports the check_specification_expression
4-
!! unit-test function in ../test/compiler_test.f90.
2+
!! This module supports the main program at the bottom of this file, which
3+
!! tests compiler conformance with clause 7.5.6.3, paragraph 6 in the Fortran
4+
!! Interpretation Document (https://j3-fortran.org/doc/year/18/18-007r1.pdf):
5+
!! "If a specification expression in a scoping unit references
6+
!! a function, the result is finalized before execution of the executable
7+
!! constructs in the scoping unit." (The same statement appears in clause
8+
!! 4.5.5.2, paragraph 5 of the Fortran 2003 standard.) In such a scenario,
9+
!! the final subroutine must be pure. The only way to observe output from
10+
!! a pure final subroutine is for the subroutine to execute an error stop
11+
!! statement. A correct execution of this test will error-terminate and ouput
12+
!! the text "finalize: intentional error termination to verify finalization".
513
implicit none
614

715
private
@@ -29,14 +37,22 @@ pure function construct(component) result(finalizable)
2937
pure function component(self) result(self_component)
3038
type(finalizable_t), intent(in) :: self
3139
integer self_component
40+
#ifdef XLF
41+
if (.not. associated(self%component_)) error stop 1 ! work around xlf2003_r bug reported via OLCF (Ticket OLCFHELP-9069)
42+
#else
3243
if (.not. associated(self%component_)) error stop "component: unassociated component"
44+
#endif
3345
self_component = self%component_
3446
end function
3547

3648
pure subroutine finalize(self)
3749
type(finalizable_t), intent(inout) :: self
3850
if (associated(self%component_)) deallocate(self%component_)
51+
#ifdef XLF
52+
error stop 2 ! work around xlf2003_r bug reported via OLCF (Ticket OLCFHELP-9069)
53+
#else
3954
error stop "finalize: intentional error termination to verify finalization"
55+
#endif
4056
end subroutine
4157

4258
end module
@@ -52,6 +68,8 @@ program specification_expression_finalization
5268

5369
subroutine finalize_specification_expression_result
5470
real tmp(component(finalizable_t(component=0))) !! Finalizes the finalizable_t function result
71+
real eliminate_unused_variable_warning
72+
tmp = eliminate_unused_variable_warning
5573
end subroutine
5674

5775
end program

Diff for: fpm.toml

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
name = "reference_counter"
2-
version = "1.0.0"
1+
name = "smart_pointers"
2+
version = "2.1.0"
33
license = "BSD"
44
author = ["Damian Rouson, Karla Morris, and Jim Xia"]
55
maintainer = "damian@archaeologic.codes"
66
copyright = "2020-2022 Sourcery Institute"
7-
8-
[dependencies]
9-
assert = {git = "https://github.com/sourceryinstitute/assert", tag = "1.3.0"}

Diff for: src/smart_pointer/assert_m.F90

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module assert_m
2+
!! Enforce logical assertions that can be toggled on/off at compile-time
3+
!! To turn off assertions, building with the flag -DUSE_ASSERTIONS=.false.
4+
implicit none
5+
6+
private
7+
public :: assert
8+
9+
#ifndef USE_ASSERTIONS
10+
# define USE_ASSERTIONS .true.
11+
#endif
12+
logical, parameter :: enforce_assertions = USE_ASSERTIONS
13+
14+
interface
15+
16+
pure module subroutine assert(assertion, description)
17+
!! Error terminate on .false. assertion with the stop code given by description
18+
!! With IBM XL Fortran, the stop code is an integer due to for character stop codes being unsupported.
19+
implicit none
20+
logical, intent(in) :: assertion
21+
character(len=*), intent(in) :: description
22+
end subroutine
23+
24+
end interface
25+
26+
end module assert_m

Diff for: src/smart_pointer/assert_s.F90

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
submodule(assert_m) assert_s
2+
implicit none
3+
4+
contains
5+
6+
module procedure assert
7+
8+
if (enforce_assertions) then
9+
#ifdef XLF
10+
if (.not. assertion) error stop 999
11+
#else
12+
if (.not. assertion) error stop description
13+
#endif
14+
end if
15+
16+
end procedure
17+
18+
end submodule assert_s

Diff for: src/smart_pointer/sp_smart_pointer_s.f90 renamed to src/smart_pointer/sp_smart_pointer_s.F90

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
submodule(sp_smart_pointer_m) sp_smart_pointer_s
2+
#ifdef XLF
3+
use sp_reference_counter_m, only : sp_reference_counter_t
4+
#endif
25
implicit none
36

47
contains

Diff for: test/compiler_test_m.f90

+3-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@ function fpm_compiler_arguments() result(args)
232232
else if (scan(compiler_identity, "NAG")==1) then
233233
args = "--compiler nagfor --flag -fpp"
234234
else if (scan(compiler_identity, "Intel")==1) then
235-
args = "--compiler ifort --flag -coarray=shared"
235+
args = "--compiler ifort --flag"
236+
else if (scan(compiler_identity, "IBM")==1) then
237+
args = "--compiler xlf2003_r --flag -DXLF"
236238
else
237239
error stop "----> Unrecognized compiler_version() in function fpm_compiler_arguments. <----"
238240
end if

Diff for: test/test_m.f90 renamed to test/test_m.F90

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ module subroutine report(test)
3838
end module test_m
3939

4040
submodule(test_m) test_s
41+
#ifdef XLF
42+
use test_result_m, only : test_result_t
43+
#endif
4144
implicit none
4245

4346
contains

0 commit comments

Comments
 (0)