[all-commits] [llvm/llvm-project] c58c64: [flang] Add runtime API to catch unit number out o...

jeanPerier via All-commits all-commits at lists.llvm.org
Wed Apr 6 06:39:17 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c58c64d05c51b75df3d803d293d386d8e7ae02b4
      https://github.com/llvm/llvm-project/commit/c58c64d05c51b75df3d803d293d386d8e7ae02b4
  Author: Jean Perier <jperier at nvidia.com>
  Date:   2022-04-06 (Wed, 06 Apr 2022)

  Changed paths:
    M flang/include/flang/Runtime/io-api.h
    M flang/include/flang/Runtime/iostat.h
    M flang/runtime/io-api.cpp
    M flang/runtime/iostat.cpp
    M flang/unittests/Runtime/ExternalIOTest.cpp

  Log Message:
  -----------
  [flang] Add runtime API to catch unit number out of range

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.

Differential Revision: https://reviews.llvm.org/D123157




More information about the All-commits mailing list