Skip to content

Commit 600943e

Browse files
committed
fix(check_specification_expression): nagfor passes
This commit contains the first demonstration that a compiler, nagfor 7.1 (Build 7113), passes all reference-counter tests!
1 parent a2d369d commit 600943e

File tree

2 files changed

+89
-25
lines changed

2 files changed

+89
-25
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
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.
5+
implicit none
6+
7+
private
8+
public :: finalizable_t, component
9+
10+
type finalizable_t
11+
private
12+
integer, pointer :: component_ => null()
13+
contains
14+
final :: finalize
15+
end Type
16+
17+
interface finalizable_t
18+
module procedure construct
19+
end interface
20+
21+
contains
22+
23+
pure function construct(component) result(finalizable)
24+
integer, intent(in) :: component
25+
type(finalizable_t) finalizable
26+
allocate(finalizable%component_, source = component)
27+
end function
28+
29+
pure function component(self) result(self_component)
30+
type(finalizable_t), intent(in) :: self
31+
integer self_component
32+
if (.not. associated(self%component_)) error stop "component: unassociated component"
33+
self_component = self%component_
34+
end function
35+
36+
pure subroutine finalize(self)
37+
type(finalizable_t), intent(inout) :: self
38+
if (associated(self%component_)) deallocate(self%component_)
39+
error stop "finalize: intentional error termination to verify finalization"
40+
end subroutine
41+
42+
end module
43+
44+
program specification_expression_finalization
45+
!! Test the finalization of a function result in a specification expression
46+
use finalizable_m, only : finalizable_t, component
47+
implicit none
48+
49+
call finalize_specification_expression_result
50+
51+
contains
52+
53+
subroutine finalize_specification_expression_result
54+
real tmp(component(finalizable_t(component=0))) !! Finalizes the finalizable_t function result
55+
end subroutine
56+
57+
end program

test/compiler_test.f90

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module compiler_test
2-
use veggies, only: result_t, test_item_t, describe, it, assert_equals
2+
!! Test compiler conformance with each scenario in which the Fortran 2018
3+
!! standard mandates type finalization.
4+
use veggies, only: result_t, test_item_t, describe, it, assert_equals, assert_that
35
implicit none
46

57
private
@@ -54,7 +56,8 @@ subroutine count_finalizations(self)
5456
end subroutine
5557

5658
function check_lhs_object() result(result_)
57-
!! Verify Fortran 2018 clause 7.5.6.3, paragraph 1 behavior: "not an unallocated allocatable variable"
59+
!! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 1 behavior:
60+
!! "not an unallocated allocatable variable"
5861
type(object_t) lhs, rhs
5962
type(result_t) result_
6063
integer initial_tally
@@ -68,7 +71,8 @@ function check_lhs_object() result(result_)
6871
end function
6972

7073
function check_allocated_allocatable_lhs() result(result_)
71-
!! Verify Fortran 2018 clause 7.5.6.3, paragraph 1 behavior: "allocated allocatable variable"
74+
!! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 1 behavior:
75+
!! "allocated allocatable variable"
7276
type(object_t), allocatable :: lhs
7377
type(object_t) rhs
7478
type(result_t) result_
@@ -84,7 +88,8 @@ function check_allocated_allocatable_lhs() result(result_)
8488
end function
8589

8690
function check_target_deallocation() result(result_)
87-
!! Verify Fortran 2018 clause 7.5.6.3, paragraph 2 behavior: "pointer is deallocated"
91+
!! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 2 behavior:
92+
!! "pointer is deallocated"
8893
type(object_t), pointer :: object_ptr => null()
8994
type(result_t) result_
9095
integer initial_tally
@@ -98,7 +103,7 @@ function check_target_deallocation() result(result_)
98103
end function
99104

100105
function check_allocatable_component_finalization() result(result_)
101-
!! Tests 7.5.6.3, para. 2 ("allocatable entity is deallocated")
106+
!! Test conformance with Fortran 2018 clause 7.5.6.3, para. 2 ("allocatable entity is deallocated")
102107
!! + 9.7.3.2, para. 6 ("INTENT(OUT) allocatable dummy argument is deallocated")
103108
type(wrapper_t), allocatable :: wrapper
104109
type(result_t) result_
@@ -124,7 +129,8 @@ subroutine finalize_intent_out_component(output)
124129
end function
125130

126131
function check_finalize_on_deallocate() result(result_)
127-
!! Tests 7.5.6.3, paragraph 2: "allocatable entity is deallocated"
132+
!! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 2:
133+
!! "allocatable entity is deallocated"
128134
type(object_t), allocatable :: object
129135
type(result_t) result_
130136
integer initial_tally
@@ -139,7 +145,8 @@ function check_finalize_on_deallocate() result(result_)
139145
end function
140146

141147
function check_finalize_on_end() result(result_)
142-
!! Tests 7.5.6.3, paragraph 3: "before return or END statement"
148+
!! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 3:
149+
!! "before return or END statement"
143150
type(result_t) result_
144151
integer initial_tally
145152

@@ -159,7 +166,8 @@ subroutine finalize_on_end_subroutine()
159166
end function
160167

161168
function check_block_finalization() result(result_)
162-
!! Tests 7.5.6.3, paragraph 4: "termination of the BLOCK construct"
169+
!! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 4:
170+
!! "termination of the BLOCK construct"
163171
type(result_t) result_
164172
integer initial_tally
165173

@@ -174,7 +182,8 @@ function check_block_finalization() result(result_)
174182
end function
175183

176184
function check_rhs_function_reference() result(result_)
177-
!! Verify Fortran 2018 clause 7.5.6.3, paragraph 5 behavior: "nonpointer function result"
185+
!! Test conformance with Fortran 2018 clause 7.5.6.3, paragraph 5 behavior:
186+
!! "nonpointer function result"
178187
type(object_t), allocatable :: object
179188
type(result_t) result_
180189
integer initial_tally
@@ -187,27 +196,25 @@ function check_rhs_function_reference() result(result_)
187196
end function
188197

189198
function check_specification_expression() result(result_)
190-
!! Tests 7.5.6.3, paragraph 6: "specification expression function result"
199+
!! Test conformance with Fortran 2018 standard clause 7.5.6.3, paragraph 6:
200+
!! "specification expression function result"
191201
type(result_t) result_
192-
integer initial_tally
193-
194-
initial_tally = finalizations
195-
call finalize_specification_expression
196-
associate(delta => finalizations - initial_tally)
197-
result_ = assert_equals(1, delta)
198-
end associate
199-
200-
contains
201-
202-
subroutine finalize_specification_expression
203-
character(len=size([object_t(dummy=this_image())])) :: string ! Finalizes RHS function reference
204-
string = ""
205-
end subroutine
202+
integer exit_status
203+
logical error_termination_occurred
204+
205+
call execute_command_line( &
206+
command = "fpm run --example specification_expression_finalization > /dev/null 2>&1", &
207+
wait = .true., &
208+
exitstat = exit_status &
209+
)
210+
error_termination_occurred = exit_status /=0
211+
result_ = assert_that(error_termination_occurred)
206212

207213
end function
208214

209215
function check_intent_out_finalization() result(result_)
210-
!! Tests 7.5.6.3, paragraph 7: "nonpointer, nonallocatable, INTENT (OUT) dummy argument"
216+
!! Test conformance with Fortran 2018 standard clause 7.5.6.3, paragraph 7:
217+
!! "nonpointer, nonallocatable, INTENT (OUT) dummy argument"
211218
type(result_t) result_
212219
type(object_t) object
213220
integer initial_tally

0 commit comments

Comments
 (0)