[flang-commits] [PATCH] D123157: [flang] Add runtime API to catch unit number out of range

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue Apr 5 14:07:26 PDT 2022


jeanPerier created this revision.
jeanPerier added a reviewer: klausler.
jeanPerier added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
jeanPerier requested review of this revision.

Unit numbers must fit on a default integer. It is however possible that
the user provides the unit number in UNIT with a wider integer type.
In such case, lowering was previously silently narrowing
the value and passing the result to the BeginXXX runtime entry points.
Cases where the conversion caused overflow were not reported/caught.
Most existing compilers catch these errors and raise an IO error.
Add a CheckUnitNumberInRange runtime API to do the same in f18.

This runtime API has its own error management interface (i.e., does not
use GetIoMsg, EndIo, and EnableHandlers) because the usual error
management requires BeginXXX to be called to set up the error
management. But in this case, the BeginXXX cannot be called since
the bad unit number that would be provided to it overflew (and in the worst
case scenario, the narrowed value could point to a different valid unit
already in use). Hence I decided to make an API that must be called
before the BeginXXX and should trigger the whole BeginXXX/.../EndIoStatement
to be skipped in case the unit number is too big and the user enabled
error recovery.

Note that CheckUnitNumberInRange accepts negative numbers (as long as
they can fit on a default integer), because unit numbers may be negative
if they were created by NEWUNIT.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123157

Files:
  flang/include/flang/Runtime/io-api.h
  flang/include/flang/Runtime/iostat.h
  flang/runtime/io-api.cpp
  flang/unittests/Runtime/ExternalIOTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123157.420630.patch
Type: text/x-patch
Size: 5822 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220405/6290db3b/attachment.bin>


More information about the flang-commits mailing list