Commit Graph

130 Commits

Author SHA1 Message Date
peter klausler 3ce5f95716 fix clang build 2020-11-12 11:38:20 -08:00
peter klausler 8df28f0aa3 [flang] Implement runtime support for basic ALLOCATE/DEALLOCATE
Add error reporting infrastructure and support for ALLOCATE
and DEALLOCATE statements of intrinsic types without SOURCE=
or MOLD=.

Differential revision: https://reviews.llvm.org/D91215
2020-11-12 10:21:40 -08:00
Jean Perier 94d9a4fd88 [flang] Rework host runtime folding and enable REAL(2) folding with it.
- Rework the host runtime table so that it is constexpr to avoid
  having to construct it and to store/propagate it.
- Make the interface simpler (remove many templates and a file)
- Enable 16bits float folding using 32bits float host runtime
- Move StaticMultimapView into its own header to use it for host
  folding

Reviewed By: klausler, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D88981
2020-10-14 16:40:44 +02:00
peter klausler d56fdc8e95 [flang][msvc] Avoid dependence on long double
MSVC does not support a distinct 80-bit extended precision
"long double" type.  Rework the I/O runtime to avoid using
native C/C++ type names.  Centralize the mappings between
the KIND= type parameters of REAL and their binary precisions
in the common real.h header file, and use KIND type parameter
values rather than binary precisions for clarity where
appropriate.

This patch, if successful, should obviate the need for
Differential review D88511.

(This patch anticipates a successful review of D88688, which
fixes the function that maps each kind of real to its maximum
number of significant decimal digits.)

Differential revision: https://reviews.llvm.org/D88752
2020-10-07 15:12:08 -07:00
peter klausler 567462b48e [flang] Correct kP scaling on F output
The sign of the scaling factor was misinterpreted for output
as meaning what it does for input.  To be correct, they
should cancel each other out.

print '(1P,F4.3)', 1. ! printed 0.1 but should print 10.0

Differential revision: https://reviews.llvm.org/D88610
2020-10-05 13:58:42 -07:00
Tim Keith 11622d0fed [flang][NFC] Fix mis-matched struct/class declarations
The template `ListDirectedStatementState` was declared as a struct and then as a class.
Fix it so they match.

Differential Revision: https://reviews.llvm.org/D88711
2020-10-02 13:08:51 -07:00
peter klausler 3261aefc72 [flang] Extend runtime API for PAUSE to allow a stop code
Support integer and default character stop codes on PAUSE
statements.  Add length argument to STOP statement with a
character stop code.

Differential revision: https://reviews.llvm.org/D88692
2020-10-01 17:20:11 -07:00
peter klausler a94d943f1a [flang] Fix actions at end of output record
It turns out that unformatted fixed-size output records
do need to be padded out if short, in order to avoid a
spurious EOF crash on a short record at the end of the file.
While here in AdvanceRecord(), move the unformatted
variable-length record header/footer writing code to here
from EndIoStatement().

Differential revision: https://reviews.llvm.org/D88685
2020-10-01 17:18:20 -07:00
peter klausler 61687f3a48 [flang] Fix buffering read->write transition
The buffer needs to be Reset() after a Flush(), since the
Flush() can be a no-op after a read->write transition.
And record numbers are 1-based, not 0-based.
This fixes a bug with rewrites of records that have been
recently read.

Differential revision: https://reviews.llvm.org/D88612
2020-10-01 16:57:38 -07:00
peter klausler e99d184d54 [flang] Readability improvement in binary->decimal conversion
Tweak binary->decimal conversions to avoid an integer multiplication
in a hot loop to improve readability and get a minor (~5%) speed-up.
Use native integer division by constants for more readability, too,
since current build compilers seem to optimize it correctly now.
Delete the now needless temporary work-around facility in
Common/unsigned-const-division.h.

Differential revision: https://reviews.llvm.org/D88604
2020-10-01 15:49:27 -07:00
peter klausler e29c9d77f1 [flang] Fix WRITE after BACKSPACE
A WRITE to an unformatted sequential variable-length unit after
a BACKSPACE needs to forget its previous knowledge of the length
of the record that's about to be overwritten, and a BACKSPACE
after an ENDFILE or at the start of the file needs to be a no-op.

Differential revision: https://reviews.llvm.org/D88675
2020-10-01 10:33:31 -07:00
peter klausler df6de2222c [flang] Fix INQUIRE of access and formatting possibilities
Don't give false positives from INQUIRE about possible
access mode changes on connected units.  DIRECT and SEQUENTIAL
cannot be intermixed, apart from allowing DIRECT on a SEQUENTIAL
file with fixed-size records and positioning.  Nor can
FORMATTED and UNFORMATTED be interchanged.  On unconnected
files, the best that we can do is "UNKNOWN".

Differential revision: https://reviews.llvm.org/D88673
2020-10-01 10:27:20 -07:00
peter klausler cdfb95ad58 [flang] Add checks for misuse of formatted I/O APIs in unformatted I/O statement
Add checking to I/O statement APIs to catch cases where the formatted
I/O data item transfer routines like OutputInteger64 are being
incorrectly used for unformatted I/O, which should use the
unformatted block or descriptor-based data item interfaces.

Differential revision: https://reviews.llvm.org/D88672
2020-10-01 09:58:04 -07:00
peter klausler 4fb679d3b1 [flang] Fix Gw.d format output
The estimation of the decimal exponent needs to allow for all
'd' of the requested significant digits.

Also accept a plus sign on a "+kP" scaling factor in a format.

Differential revision: https://reviews.llvm.org/D88618
2020-09-30 18:02:25 -07:00
peter klausler e24f0ac7a3 [flang] Allow record advancement in external formatted sequential READ
The '/' control edit descriptor causes a runtime crash for an
external formatted sequential READ because the AdvanceRecord()
member function for external units implemented only the tasks
to finish reading the current record.  Split those out into
a new FinishReadingRecord() member function, call that instead
from EndIoStatement(), and change AdvanceRecord() to both
finish reading the current record and to begin reading the next
one.

Differential revision: https://reviews.llvm.org/D88607
2020-09-30 17:16:55 -07:00
peter klausler 0c3c8f4ae6 [flang] Fix descriptor-based array data item I/O for list-directed CHARACTER & LOGICAL
These types have to distinguish list-directed I/O from formatted I/O,
and the subscript incrementation call was in the formatted branch
of the if() rather than after the if().

Differential revision: https://reviews.llvm.org/D88606
2020-09-30 14:01:45 -07:00
Michael Kruse bcd05599d0 [flang][msvc] Define access flags under Windows. NFC.
The flags F_OK, R_OK and W_OK are defined in unistd.h, which does not exist under the Windows platform. Windows still defines the `access` function. Its access flags are documented at https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/access-waccess. For compatibility, define the flags F_OK, R_OK and W_OK using these constants.

This patch is part of the series to make flang compilable with MS Visual Studio <http://lists.llvm.org/pipermail/flang-dev/2020-July/000448.html>.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D88508
2020-09-29 17:01:36 -05:00
peter klausler b2cf572b56 [flang] Respect BZ mode in exponent parts, too
The Fortran standard discusses BZ mode (treat blanks as zero digits)
explicitly in its effect on the editing of the digits prior to the
exponent part, but doesn't mention it in description of the
exponent part.  Other compilers honor BZ mode in the exponent,
so we should do so too.  So "1 e 1 " is 1.E11 in BZ mode.

Differential Revision: https://reviews.llvm.org/D87653
2020-09-14 17:03:21 -07:00
peter klausler c963757783 [flang] Implement nonstandard OPEN statement CARRIAGECONTROL specifier
Differential Revision: https://reviews.llvm.org/D87052
2020-09-02 13:07:45 -07:00
peter klausler 5c9aca1e93 [flang] Descriptor-based I/O using wrong size for contiguous unformatted I/O
The descriptor-based I/O routine was using the size of the descriptor
rather than the size of the described data for the transfer.  Fix,
and add a comment to the relevant API.

Differential Revision: https://reviews.llvm.org/D85863
2020-08-13 10:46:43 -07:00
peter klausler f09a2244ba [flang] Correct the default value for PAD= to PAD='YES'. 2020-08-13 08:57:53 -07:00
Michael Kruse e3d38b7b88 [flang][msvc] Tell windows.h to not define min/max macros.
Defining macros for min and max breaks using std::min and std::max. Defining NOMINMAX before including the header stops them from being defined.

See https://web.archive.org/web/20170911092732/https://support.microsoft.com/en-us/help/143208/prb-using-stl-in-windows-program-can-cause-min-max-conflicts for details.

This patch is part of the series to [[ http://lists.llvm.org/pipermail/flang-dev/2020-July/000448.html | make flang compilable with MS Visual Studio ]].

Reviewed By: isuruf

Differential Revision: https://reviews.llvm.org/D85656
2020-08-12 14:36:21 -05:00
peter klausler cc01194c2f [flang] Descriptor-based I/O data item transfers
Add support for OutputDescriptor() and InputDescriptor()
in the I/O runtime.  Change existing scalar formatted I/O
functions to drive descriptor-based I/O routines internally.

Differential Revision: https://reviews.llvm.org/D85491
2020-08-07 13:09:09 -07:00
peter klausler 675ad1bc6a [flang] Implement runtime support for INQUIRE statements
Differential Revision: https://reviews.llvm.org/D85166
2020-08-03 17:15:08 -07:00
peter klausler d879ac8a6e [flang] Defer "next input record" processing until handlers established
External input was detecting "end of file" conditions in
BeginExternal...Input() and BeginUnformattedInput() routines
before EnableHandlers() could have been called.  Defer the
"start next record" processing to the input data item
handlers (and EndIoStatement() for when there are no data
items).

Differential Revision: https://reviews.llvm.org/D85161
2020-08-03 16:44:37 -07:00
peter klausler d8334c4360 [flang] Acquire file accessibility, size, positioning
Extend the raw file wrapper to get accessibility, positioning,
and size information.  This is needed for INQUIRE (to follow).

Differential Revision: https://reviews.llvm.org/D85160
2020-08-03 16:42:48 -07:00
peter klausler 7c5630fe99 [flang] Handle spaces (more) correctly in REAL input
Fixes problems in FCVS test fm110.f.
Add more comments, too.

Differential Revision: https://reviews.llvm.org/D85163
2020-08-03 16:12:30 -07:00
peter klausler e57464151d [flang] Allow omission of comma in FORMAT(1PE5.2) in runtime
A comma is not required between a scale factor and a following
data edit descriptor (C1302).

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D84369
2020-07-27 15:02:54 -07:00
peter klausler 3bc2ae951a [flang] Add runtime I/O APIs for COMPLEX formatted input
It turns out that COMPLEX formatted input needs its own runtime APIs
so that null values in list-directed input skip the entire COMPLEX
datum rather than just a real or imaginary part thereof.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D84370
2020-07-22 17:52:19 -07:00
peter klausler c6cb726a8c [flang] Replay a FORMAT at the right position
When FORMAT control reaches the final parenthesis and data items
remain, we advance a record and revert to the beginning of the
FORMAT for further items.  But when the FORMAT contains any
nested parenthesized group of editing descriptors, possibly
repeated, reversion must be to the beginning of the last such
top-level parenthesized group, including its repetition count.

Reviewed By: sscalpone, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D84281
2020-07-21 18:59:49 -07:00
peter klausler 8f2c5c4314 [flang] Implement byte-swapped external unformatted I/O in runtime
Add SetConvert() to the OPEN statement's runtime API.
Add ByteswapOption() to the main program's runtime API.
Check a $FORT_CONVERT environment variable, too, for
a swapping specifier.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D84284
2020-07-21 18:14:46 -07:00
peter klausler 9bb091a8fc [flang] Handle leading zeroes after decimal in REAL formatted input
Leading zero digits after the decimal mark were being dropped.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D84282
2020-07-21 18:03:24 -07:00
peter klausler cbff0c75b9 [flang] Improve output from a STOP statement
Add a missing newline to IEEE FP flag formatting, and
don't neglect to emit STOP when there's no code number.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D84060
2020-07-18 11:33:46 -07:00
peter klausler e79a86e45b [flang] Insert leading blanks in LOGICAL formatted output fields
Summary: For Lw output editing, emit (w-1) blanks before the T or the F.

Reviewed By: sscalpone, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D84059
2020-07-18 10:44:16 -07:00
peter klausler b0a971d25c [flang] Prevent bogus runtime I/O error message
The runtime was requiring that STATUS='OLD' be explicitly specified
on an OPEN statement for a connected unit.  There error should issue
only if a STATUS= other than 'OLD' is specified; an OPEN with no
STATUS= specifier is okay.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D84079
2020-07-17 17:21:54 -07:00
peter klausler 8305a92a47 [flang] Treat tabs like spaces in formatted input.
Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D84078
2020-07-17 17:19:20 -07:00
peter klausler ea4758a125 [flang] Rework read/write permission management for runtime file opening
Anonymous Fortran unit files (e.g., "./fort.7") need to be created
O_RDWR so that they can be written, rewound, and read.  Other
files opened with no ACTION= specifier need to set read/write
permissions based on the file, if it exists.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D84063
2020-07-17 14:44:58 -07:00
peter klausler b30fa1c3da [flang] Add entry points for internal scalar list-directed I/O
BeginInternalListInput and BeginInternalListOutput were missing
from the I/O API implementation; add them.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D84066
2020-07-17 12:49:06 -07:00
peter klausler 8dbc86adf3 [flang] Fix list-directed input (repeated nulls and LOGICAL)
Allow repeated nulls in list-directed input (e.g., "4*,") and
ignore excess characters in list-directed LOGICAL input after the
T or F.

Fixes FCVS test fm923.f.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D83810
2020-07-14 16:59:50 -07:00
peter klausler bd43fa29e3 [flang] Implement anonymous units in the runtime
I/O from/to an unopened unit number needs to open &/or create
a "fort.$UNIT" file.

Fixes FCVS test fm401.f.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D83809
2020-07-14 16:12:06 -07:00
Eric Schweitz 7cd1b0ff34 [flang] partially revert upstreamed code to support complex values in runtime support to avoid warnings. 2020-07-09 07:39:44 -07:00
peter klausler cffc603617 [flang] Fix negative unit number hashing
Ensure that external unit number hashing produces a valid
index for a negative unit number, viz. a NEWUNIT=.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D83428
2020-07-08 17:59:00 -07:00
Zachary Selk 4b9b64d561 [flang] Added missing runtime I/O definitions
Added runtime function definitions for 32-bit real I/O and 32-bit complex output

Differential Revision: https://reviews.llvm.org/D83112
2020-07-07 12:33:51 -07:00
Tim Keith 1b18391818 [flang] Add missing include for std::min
This was causing the build to fail on macos.

Differential Revision: https://reviews.llvm.org/D83237
2020-07-06 13:03:02 -07:00
peter klausler a39e9cf6be [flang] Basic tests of external I/O runtime (part 9/9)
Add new unit tests for external Fortran I/O that drive the
Fortran I/O runtime API from C++ and exercise basic writing
and read-back in the various combinations of access modes,
record length variability, and formatting.  Sequential modes
are tested with positioning.  More thorough tests written in
Fortran will follow when they can be compiled and run.

The Fortran runtime's error termination callback registration
was extended with source file and line number positions for
better failure messages in unit testing.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D83164
2020-07-06 10:37:13 -07:00
peter klausler 5d5b968252 [flang] Add fixes and missing stmts to I/O runtime API handlers (ext. I/O part 8)
Complete the rework of the initial implementation of external I/O
to fix problems found in testing (tests to follow); add handlers
for hitherto unimplemented PAUSE, FLUSH, ENDFILE, BACKSPACE, and
REWIND statements.

Reviewed By: tskeith, sscalpone

Differential Revision: https://reviews.llvm.org/D83162
2020-07-04 12:53:31 -07:00
peter klausler 45b5c79a31 [flang] Extend & fix per-I/O-statement state (ext. I/O work part 7)
The per-I/O-statement state structures need to support missing
external I/O statements, and some bugs found in testing with
formatted input and record advancement are fixed.  The effects
of these changes will not be visible until further patches to
the I/O API handlers are pushed.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D83151
2020-07-04 10:49:00 -07:00
peter klausler 0006354c3b [flang] Further implementation of external I/O unit operations (part 6)
Rework initial implementation of external I/O unit operations to
fix problems exposed in unit tests (in a later patch).  Add flushing.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D83147
2020-07-03 17:31:01 -07:00
peter klausler 7926969afc [flang] Track known file size, add IsATerminal (ext. I/O work part 5)
Add a data member knownSize_ and an accessor to allow the size of
an external file to be tracked when known.  Also add a wrapper for
::isatty() here in the filesystem encapsulation module.  These
features are needed for the external I/O rework changes still
to come.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D83141
2020-07-03 13:04:18 -07:00
peter klausler c7cabf9d60 [flang] Define new runtime error IOSTAT values (I/O runtime work part 4)
Add more IOSTAT= values for errors that can arise in external I/O.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D83140
2020-07-03 12:41:33 -07:00