Skip to content

Commit 6f4ddfd

Browse files
committed
fix: work around flang issue blocking test
This commit works around a LLVM Flang (flang-new) issue that prevents test-assert-subroutine-error-termination.F90 from 1. Quietly executing false-assertion.f90 and 2. Detecting the exit status from false-assertion.f90.
1 parent b243aff commit 6f4ddfd

5 files changed

Lines changed: 56 additions & 22 deletions

File tree

README.md

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@ The [examples/README.md] file shows examples of writing constraints in notes on
5252
Downloading, Building, and Running Examples
5353
-------------------------------------------
5454

55-
### Prerequisites
56-
1. A Fortran 2018 compiler.
57-
2. The [Fortran Package Manager].
58-
3. _Optional_: [OpenCoarrays] for parallel execution with the GNU Fortran compiler.
59-
60-
Assert was developed primarily with `gfortran` 11.2.0 and `nagfor` 7.1.
61-
Recent versions of the Cray and Intel compilers should also suffice.
62-
6355
### Downloading Assert
6456
```
6557
git clone [email protected]:sourceryinstitute/assert
@@ -70,29 +62,34 @@ cd assert
7062
#### Single-image (serial) execution
7163
The following command builds Assert and runs the full test suite in a single image:
7264
```
73-
fpm test
65+
fpm test --profile release
7466
```
75-
where `fpm test` builds the Assert library and runs the test suite, including the tests.
67+
which builds the Assert library and runs the test suite.
7668

7769
#### Multi-image (parallel) execution
7870
With `gfortran` and OpenCoarrays installed,
7971
```
80-
fpm test --compiler caf --runner "cafrun -n 2"
72+
fpm test --compiler caf --profile release --runner "cafrun -n 2"
8173
```
8274
To build and test with the Numerical Algorithms Group (NAG) Fortran compiler version
8375
7.1 or later, use
8476
```
85-
fpm test --compiler=nagfor --flag="-coarray=cosmp -fpp -f2018"
77+
fpm test --compiler=nagfor --profile release --flag="-coarray=cosmp -fpp -f2018"
8678
```
8779

8880
### Building and testing with the Intel `ifx` compiler
8981
```
90-
fpm test --compiler ifx --flag -coarray
82+
fpm test --compiler ifx --profile release --flag -coarray
83+
```
84+
### Building and testing with the LLVM `flang-new` compiler
85+
```
86+
fpm test --compiler flang-new --flag "-mmlir -allow-assumed-rank -O3"
87+
9188
```
9289

9390
### Building and testing with the Numerical Algorithms Group (NAG) compiler
9491
```
95-
fpm test --compiler nagfor --flag "-fpp -coarray=cosmp"
92+
fpm test --compiler nagfor --profile release --flag "-fpp -coarray=cosmp"
9693
```
9794

9895
### Building and testing with the Cray Compiler Environment (CCE)
@@ -108,7 +105,7 @@ ftn $@
108105
```
109106
Then build and test Assert with the command
110107
```
111-
fpm test --compiler crayftn.sh
108+
fpm test --compiler crayftn.sh --profile release
112109
```
113110

114111

example/intentionally_false_assertions.f90 renamed to example/false_assertion.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
program intentionally_false_assertions
1+
program false_assertion
22
use assert_m, only : assert
33
implicit none
44

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
program check_exit_status
2+
! Despite its location in the example subdirectory, this program is _not_ intended to
3+
! be a user-facing example. This program exists to work around an LLVM Flang (flang-new)
4+
! compiler issue. This program is invoked by test/test-assert-subroutine-error-termination.F90,
5+
! which reads the file this program writes to determine the exist status of the program
6+
! example/false-assertion.f90. The latter program intentionally error terminates in order
7+
! to test the case wehn assertion = .false.
8+
implicit none
9+
integer exit_status, unit
10+
read(*,*) exit_status
11+
open(newunit=unit, file="build/exit_status", status="unknown")
12+
write(unit,*) exit_status
13+
close(unit)
14+
end program

test/run-false-assertion.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
output=$(fpm run --example false_assertion --compiler flang-new --flag '-mmlir -allow-assumed-rank -O3' > /dev/null 2>&1)
3+
echo $?

test/test-assert-subroutine-error-termination.F90

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,52 @@ program test_assert_subroutine_error_termination
55

66
integer exit_status
77

8+
! TODO: add '--profile release' if used in the 'fpm test' invocation that causes the program
9+
! ../example/test-assert-subroutine-error-termination.F90 to excute this example program.
10+
811
print *
912
print *,"The assert subroutine"
1013
call execute_command_line( &
11-
command = "fpm run --example intentionally_false_assertions > /dev/null 2>&1", &
14+
#ifdef __GFORTRAN__
15+
command = "fpm run --example false_assertion > /dev/null 2>&1", &
16+
#elif NAGFOR
17+
command = "fpm run --example false_assertion --compiler nagfor --flag -fpp > /dev/null 2>&1", &
18+
#elif __flang__
19+
command = "./test/run-false-assertion.sh | fpm run --example check-exit-status", &
20+
#elif __INTEL_COMPILER
21+
command = "fpm run --example false_assertion --compiler ifx --flag -O3 > /dev/null 2>&1", &
22+
#elif __CRAYFTN
23+
command = "fpm run --example false_assertion --compiler crayftn.sh > /dev/null 2>&1", &
24+
#else
25+
command = "echo 'example/false_assertion.F90: unsupported compiler' && exit 1", &
26+
#endif
1227
wait = .true., &
1328
exitstat = exit_status &
1429
)
1530

31+
#ifndef __flang__
1632
block
1733
logical error_termination
1834

1935
error_termination = exit_status /=0
20-
#ifndef __flang__
2136
call co_all(error_termination)
22-
2337
if (this_image()==1) then
24-
#endif
2538
if (error_termination) then
2639
print *," passes on error-terminating when assertion = .false."
2740
else
2841
print *," FAILS to error-terminate when assertion = .false. (Yikes! Who designed this OS?)"
2942
end if
30-
#ifndef __flang__
3143
end if
32-
#endif
3344
end block
45+
#else
46+
block
47+
integer unit
48+
open(newunit=unit, file="build/exit_status", status="old")
49+
read(unit,*) exit_status
50+
print *,trim(merge("passes","FAILS ",exit_status/=0)) // " on error-terminating when assertion = .false."
51+
close(unit)
52+
end block
53+
#endif
3454

3555
contains
3656

0 commit comments

Comments
 (0)