Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Fortran 2018 error stop

awvwgk
Novice
2,108 Views

Following example should use Fortran 2018 error stop feature:

integer :: return_code
return_code = 77
error stop return_code
end

Using ifort 2021.1 Beta 20200827 on a Manjaro Linux, the program compiles without error but the return code is not propagated to the shell:

> gfortran-10 mwe.f90 && ./a.out
ERROR STOP 77

Error termination. Backtrace:
#0  0x562d2fa17176 in ???
#1  0x562d2fa171ac in ???
#2  0x7fa6e2a48151 in ???
#3  0x562d2fa1708d in ???
#4  0xffffffffffffffff in ???
> echo $?
77
> ifort mwe.f90 && ./a.out
77
> echo $?
128

Is the Fortran 2018 error stop opt-in for ifort and I'm missing a flag or is this an issue with the beta version of ifort?

Note: same issue is observed with the ifx compiler.

0 Kudos
5 Replies
Steve_Lionel
Honored Contributor III
2,080 Views

The standard says, "If the stop-code is an integer, it is recommended that the value be used as the process exit status, if the processor supports that concept."  It's not a requirement. That said, I would expect it to be implemented and would recommend you submit a request that this be done.

awvwgk
Novice
2,060 Views

Thanks for the clarification. If I understood correctly this means that even if the integer variable I'm passing is zero it is implementation dependent whether or not actually a zero exit status is actually reported?

I also created a service request for this.

0 Kudos
Steve_Lionel
Honored Contributor III
2,044 Views

Right. The standard requires only that the value of the stop code be "made available in a processor-dependent manner". The traditional method was to print a message with the code (which can now be suppressed with the optional QUIET specifier.) 

Interestingly, the code is used for the process exit status on Windows:

:\Projects>type t.f90
error stop 42
end
D:\Projects>ifort t.f90
Intel(R) Visual Fortran Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 19.1.3.311 Build 20201010_000000
Copyright (C) 1985-2020 Intel Corporation.  All rights reserved.

Microsoft (R) Incremental Linker Version 14.28.29334.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:t.exe
-subsystem:console
t.obj

D:\Projects>t.exe
42

D:\Projects>echo %errorlevel%
42

I have a vague memory of this being an issue on Linux from years ago. Creating the service request was the right thing to do.

awvwgk
Novice
2,016 Views

There are some scenarios were this is working as expected and than there is this odd inconsistency between the printout and the return code on Linux:

> cat <<EOF > error_stop_std08.f90
error stop 0
end
> ifort error_stop_std08.f90 && ./a.out
0
> echo $?
0
> cat <<EOF > error_stop_std18.f90
i = 0
error stop i
end
> ifort error_stop_std18.f90 && ./a.out
0
> echo $?
128

Which I would almost consider a bug in ifort.

Also, my support request has been rejected, because I don't own a serial number for working with Intel compilers at https://github.com/fortran-lang/stdlib.

0 Kudos
awvwgk
Novice
1,969 Views

After the misunderstanding has been cleared this seems to be successfully reported with Service Request #:04894932. Note that this issue is still present in the just released version of the oneAPI Fortran compilers.

0 Kudos
Reply