Skip to content

Commit

Permalink
Fix exit statement in Fortran with Intel compiler (#1624)
Browse files Browse the repository at this point in the history
The Intel compiler does not allow specifying the precision in a `stop`
statement. To fix this, a condition was added in `_print_SysExit` to
print `LiteralInteger` objects with default precision. Fixes
#1554.

---------

Co-authored-by: EmilyBourne <louise.bourne@gmail.com>
  • Loading branch information
harsha-mangena and EmilyBourne committed Jan 8, 2024
1 parent 6e6f088 commit b50a87d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ All notable changes to this project will be documented in this file.
- #1614 : Allow relative paths for custom compilation file.
- #1615 : Fixed infinite loop when passing slices while copying arrays.
- #1628 : Fixed segmentation fault when writing to optional scalars.
- #1554 : Fix exit statement in Fortran with Intel compiler.

### Changed

Expand Down
14 changes: 8 additions & 6 deletions pyccel/codegen/printing/fcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2626,15 +2626,17 @@ def _print_Header(self, expr):

def _print_SysExit(self, expr):
code = ""
if expr.status.dtype is not NativeInteger() or expr.status.rank > 0:
print_arg = FunctionCallArgument(expr.status)
exit_code = expr.status
if isinstance(exit_code, LiteralInteger):
arg = exit_code.python_value
elif exit_code.dtype is not NativeInteger() or exit_code.rank > 0:
print_arg = FunctionCallArgument(exit_code)
code = self._print(PythonPrint((print_arg, ), file="stderr"))
arg = "1"
else:
arg = expr.status
if arg.precision != 4:
arg = NumpyInt32(arg)
arg = self._print(arg)
if exit_code.precision != 4:
exit_code = NumpyInt32(exit_code)
arg = self._print(exit_code)
return f'{code}stop {arg}\n'

def _print_NumpyUfuncBase(self, expr):
Expand Down
7 changes: 7 additions & 0 deletions tests/pyccel/scripts/exits/error_message_exit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# pylint: disable=missing-function-docstring, missing-module-docstring

import sys

if __name__ == "__main__":
sys.exit("Exiting program")

1 change: 1 addition & 0 deletions tests/pyccel/test_pyccel.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,7 @@ def test_assert(language, test_file):
"scripts/exits/positive_exit2.py",
"scripts/exits/positive_exit3.py",
"scripts/exits/zero_exit.py",
"scripts/exits/error_message_exit.py",
] )

def test_exit(language, test_file):
Expand Down

0 comments on commit b50a87d

Please sign in to comment.