Commit graph

135 commits

Author SHA1 Message Date
Peter Klausler 830c0b9023 [flang] Move runtime API headers to flang/include/flang/Runtime
Move the closure of the subset of flang/runtime/*.h header files that
are referenced by source files outside flang/runtime (apart from unit tests)
into a new directory (flang/include/flang/Runtime) so that relative
include paths into ../runtime need not be used.

flang/runtime/pgmath.h.inc is moved to flang/include/flang/Evaluate;
it's not used by the runtime.

Differential Revision: https://reviews.llvm.org/D109107
2021-09-03 11:08:34 -07:00
V Donaldson 29c3ef5a0e Remove blank from NaN string representation
Flang front end function DumpHexadecimal generates a string
representation of a REAL value.  When the value is a NaN, the string
contains a blank, as in "NaN 0x7fc00000".  This function is used by
lowering to generate a string that is then passed to llvm Support
function convertFromStringSpecials, which does not expect a blank
in the string.  Remove the blank to allow correct recognition of a
NaN by this llvm function.

Note that function DumpHexadecimal is not exercised by the front end
itself.  This functionality is only exercised by code that is not yet
present in llvm.
2021-09-03 08:09:55 -07:00
Diana Picus 0c375296cc [flang] COMMAND_ARGUMENT_COUNT runtime implementation
Grab whatever ProgramStart has stored in executionEnvironment.argc and
subtract 1 (based on the assumption that ProgramStart is called with
a C-style argc that counts the command name as an argument).

Spoiler alert: The tests will evolve into fixtures when we implement
GET_COMMAND_ARGUMENT etc.

Differential Revision: https://reviews.llvm.org/D109048
2021-09-03 07:29:39 +00:00
Jean Perier b3e392c081 [flang] Implement Posix version of DATE_AND_TIME runtime
Use gettimeofday and localtime_r to implement DATE_AND_TIME intrinsic.
The Windows version fallbacks to the "no date and time information
available" defined by the standard (strings set to blanks and values to
-HUGE).

The implementation uses an ifdef between windows and the rest because
from my tests, the SFINAE approach leads to undeclared name bogus errors
with clang 8 that seems to ignore failure to instantiate is not an error
for the function names (i.e., it understands it should not instantiate
the version using gettimeofday if it is not there, but still yields an
error that it is not declared on the spot where it is called in the
uninstantiated version).

Differential Revision: https://reviews.llvm.org/D108622
2021-08-25 11:16:52 +02:00
Diana Picus 0104cc85b1 [flang] Add default implementation for SYSTEM_CLOCK
Add an implementation for the runtime functions related to SYSTEM_CLOCK.
As with CPU_TIME, this is based on std::clock(), which should be
available everywhere, but it is highly recommended to add
platform-specific implementations for systems where std::clock() behaves
poorly (e.g. POSIX).

The documentation for std::clock() doesn't specify a maximum value and
in fact wrap around behaviour is non-conforming.  Therefore, this
implementation of SYSTEM_CLOCK is not guaranteed to wrap around either,
and after std::clock reaches its maximum value we will likely just
return failure rather than wrap around. If this happens often on your
system, please add a new platform-specific implementation.

We define COUNT_MAX as either the maximum value that can be stored in
a std::clock_t or in a 64-bit integer (whichever is smaller), and
COUNT_RATE as CLOCKS_PER_SEC. For POSIX systems, the value of
CLOCKS_PER_SEC is hardcoded to 10^6 and irrelevant for the values
returned by std::clock.

Differential Revision: https://reviews.llvm.org/D105969
2021-08-18 07:39:13 +00:00
Peter Steinfeld b8ecdcdd81 [flang] Fix the vector version of EOSHIFT with a BOUNDARY argument
When the vector version of EOSHIFT was called, the BOUNDARY argument was being
ignored.  I fixed that and added a test that would not pass without this fix.

Differential Revision: https://reviews.llvm.org/D108249
2021-08-17 15:20:15 -07:00
peter klausler a05bae6163 [flang] Correct off-by-one error in SET_EXPONENT
SET_EXPONENT is returning values that are too large by a factor
of two.

Differential Revision: https://reviews.llvm.org/D107986
2021-08-12 12:50:16 -07:00
peter klausler 39c38c2152 [flang] Fix list-directed plural repeated null values at end of record
A repeated null value at the end of an input record with a count > 1
would incorrectly advance to the next record when resumed.  Fix.

Improve some poor naming and code flow noticed while debugging, so
next time will be easier.

Extend a unit test to check this case.

Differential Revision: https://reviews.llvm.org/D107917
2021-08-11 13:14:07 -07:00
Andrzej Warzynski 7b73ca3043 [flang][driver] Delete f18 (i.e. the old Flang driver)
This patch removes `f18`, a.k.a. the old driver. It is being replaced
with the new driver, `flang-new`, which has reached feature parity with
`f18` a while ago. This was discussed in [1] and also in [2].

With this change, `FLANG_BUILD_NEW_DRIVER` is no longer needed and is
also deleted. This means that we are making the dependency on Clang permanent
(i.e. it cannot be disabled with a CMake flag).

LIT set-up is updated accordingly. All references to `f18` or `f18.cpp`
are either updated or removed.

The `F18_FC` variable from the `flang` bash script is replaced with
`FLANG_FC`. The former is still supported for backwards compatibility.

[1] https://lists.llvm.org/pipermail/flang-dev/2021-June/000742.html
[2] https://reviews.llvm.org/D103177

Differential Revision: https://reviews.llvm.org/D105811
2021-08-05 12:57:15 +00:00
peter klausler 4876520eef [flang] runtime: For Fw.d formatting, don't oscillate forever
The algorithm for Fw.d output will drive binary to decimal conversion for
an initial fixed number of digits, then adjust that number based on the
result's exposent.  For value close to a power of ten, this adjustment
process wouldn't terminate; e.g., formatting 9.999 as F10.2 would start
with 1e2, boost the digits to 2, get 9.99e1, decrease the digits, and loop.
Solve by refusing to boost the digits a second time.

Differential Revision: https://reviews.llvm.org/D107490
2021-08-04 12:19:23 -07:00
Andrzej Warzynski 23d4c4f3fb [flang][nfc] Fix variable names in FrontendOptions & PreprocessorOptions
As all member variables in `FrontendOptions` and `PreprocessorOptions`
are public, we should be naming them as `variable` rather than
`variable_` [1]. This patch fixes that.

Also, `FrontendOptions` & `PreprocessorOptions` are re-defined as a
structs rather than classes (all fields are meant to be public).

[1]
https://github.com/llvm/llvm-project/blob/main/flang/docs/C%2B%2Bstyle.md#naming

Differential Revision: https://reviews.llvm.org/D107062
2021-08-02 10:08:31 +00:00
peter klausler 3338ef93b0 [flang] Produce proper "preprocessor output" for -E option
Rename the current -E option to "-E -Xflang -fno-reformat".

Add a new Parsing::EmitPreprocessedSource() routine to convert the
cooked character stream output of the prescanner back to something
more closely resembling output from a traditional preprocessor;
call this new routine when -E appears.

The new -E output is suitable for use as fixed form Fortran source to
compilation by (one hopes) any Fortran compiler.  If the original
top-level source file had been free form source, the output will be
suitable for use as free form source as well; otherwise there may be
diagnostics about missing spaces if they were indeed absent in the
original fixed form source.

Unless the -P option appears, #line directives are interspersed
with the output (but be advised, f18 will ignore these if presented
with them in a later compilation).

An effort has been made to preserve original alphabetic character case
and source indentation.

Add -P and -fno-reformat to the new drivers.

Tweak test options to avoid confusion with prior -E output; use
-fno-reformat where needed, but prefer to keep -E, sometimes
in concert with -P, on most, updating expected results accordingly.

Differential Revision: https://reviews.llvm.org/D106727
2021-07-30 15:13:56 -07:00
Asher Mancinelli 65436e6ba1 [flang] Move External IO tests to use GTest
Port external-io test to use GTest. Remove Runtime tests directory.
Rename RuntimeGTest directory to Runtime.

This is the last in a series of patches which ported tests from the old
flang/unittests/Runtime test directory to use GTest in a temporary
unittest directory under flang/unittests/RuntimeGTest. Now that all the
tests in the old directory have been ported to use GTest, the old
directory has been removed and the GTest directory has been renamed to
flang/unittests/Runtime.

Differential Revision: https://reviews.llvm.org/D105315
Reviewed by: Meinersbur, awarzynski
2021-07-30 10:22:01 -06:00
Mark Leair dfe9895a52 Fix scalar unit tests for all, any, maxloc, etc. that caused the ARM build
to fail due to warnings as errors. Note that I could not reproduce the
problem locally, but based on the messages, I think this change will fix
the errors.

Differential Revision: https://reviews.llvm.org/D107120
2021-07-29 21:15:57 -07:00
Mark Leair 2ca8295c86 Fix unit test checks for the scalar cases of all/any intrinsics. I
accidentally used int64 when they should have been int32. This lead to
a Windows build unit test error (Linux did not catch the problem).

Differential Revision: https://reviews.llvm.org/D107107
2021-07-29 15:07:19 -07:00
Mark Leair 1dbc9b534b Fix runtime internal error with certain intrinsics that can take a scalar
result descriptor (e.g., maxloc, minloc, maxval, minval, all, any, count,
parity, findloc, etc.)

Also add a scalar case for these intrinsic unit tests.

Differential Revision: https://reviews.llvm.org/D106820
2021-07-29 13:08:41 -07:00
Diana Picus dc721064b4 [flang] Fix minor style issues. NFC 2021-07-27 10:29:50 +00:00
Diana Picus a5b2ec9c26 [flang] Fix thinko in CPU_TIME test
We used to test that end > start, but it can well be >= (otherwise the
loop doesn't make sense).
2021-07-27 10:29:50 +00:00
peter klausler 4d42e16eb8 [flang] runtime: fix problems with I/O around EOF & delimited characters
When a WRITE overwrites an endfile record, we need to forget
that there was an endfile record.  When doing a BACKSPACE
after an explicit ENDFILE statement, the position afterwards
must be upon the endfile record.

Attempts to join list-directed delimited character input across
record boundaries was due to a bad reading of the standard
and has been deleted, now that the requirements are better understood.
This problem would cause a read attempt past EOF if a delimited
character input value was at the end of a record.

It turns out that delimited list-directed (and NAMELIST) character
output is required to emit contiguous doubled instances of the
delimiter character when it appears in the output value.  When
fixed-size records are being emitted, as is the case with internal
output, this is not possible when the problematic character falls
on the last position of a record.  No two other Fortran compilers
do the same thing in this situation so there is no good precedent
to follow.

Because it seems least wrong, with this patch we now emit one copy
of the delimiter as the last character of the current record and
another as the first character of the next record.  (The
second-least-wrong alternative might be to flag a runtime error,
but that seems harsh since it's not an explicit error in the standard,
and the output may not have to be usable later as input anyway.)
Consequently, the output is not suitable for use as list-directed or
NAMELIST input.

If a later standard were to clarify this case, this behavior will of
course change as needed to conform.

Differential Revision: https://reviews.llvm.org/D106695
2021-07-23 18:23:26 -07:00
Peter Steinfeld 7898e7c82d [flang] Implement the runtime portion of the CSHIFT intrinsic
This change fixes a bug in  the runtime portion of the CSHIFT intrinsic
that happens when the value of the SHIFT argument is negative.

Differential Revision: https://reviews.llvm.org/D106292
2021-07-21 13:39:21 -07:00
Peter Steinfeld ece9aa29ff [flang] Implement the runtime portion of the UNPACK intrinsic
I'd previously merged this into the fir-dev branch.  This change is to
do the same thing to the main branch of llvm-project.

Differential Revision: https://reviews.llvm.org/D106294
2021-07-21 08:03:49 -07:00
Mark Leair d0f1ae6eb6 Add a scalar argument case for the Fortran spread intrinsic unit test. 2021-07-16 12:19:08 -07:00
Andrzej Warzynski c3ebb53eab [flang][unittest] Add a missing dependency
In https://reviews.llvm.org/D103612, a definition of an instance of
`Fortran::parser::AnalyzedObjectsAsFortran` was moved (that object is
used in unparsing). That, in turn, introduced a dependency of the unit
tests on the `FortranEvaluate` library, which defines
`AnalyzedObjectsAsFortran`.

That dependency was missed in D103612 and has caused shared-library
builds to fail. I'm submitting this without a review, as it's rather
straightforward omission.
2021-06-25 16:42:45 +01:00
Mark Leair a103402288 Change the flang reshape runtime routine interface to use a result
argument instead of a result result object.

Change the reshape flang unit test to use the new interface. Also, add an
order argument to exercise the order subscript code in the rehsape runtime
routine.

Differential Revision: https://reviews.llvm.org/D104586
2021-06-24 17:05:12 -07:00
Diana Picus 4498137bd7 [flang] Rewrite test for CPU_TIME
Don't rely on volatile writes to keep the CPU busy - it seems MSVC
optimizes them out, so we don't get different values for 'start' and
'end' on Windows. Rewrite the test to loop until we get a different
value for 'end'.

Fix suggested by Michael Kruse in
https://reviews.llvm.org/rG57e85622bbdb2eb18cc03df2ea457019c58f6912#inline-6002

Committing to fix the Windows buildbot, post-commit comments welcome!
2021-06-18 09:12:24 +00:00
peter klausler fdf33771fe [flang] Implement runtime for IALL & IANY
We had IPARITY (xor-reduction) but I missed IALL (and)
and IANY (or).

Differential Revision: https://reviews.llvm.org/D104339
2021-06-16 14:54:36 -07:00
peter klausler 8ba9ee46e4 [flang] Correct the subscripts used for arguments to character intrinsics
When chasing down another unrelated bug, I noticed that the
implementations of various character intrinsic functions assume
that the lower bounds of (some of) their arguments were 1.
This isn't necessarily the case, so I've cleaned them up, tweaked
the unit tests to exercise the fix, and regularized the allocation
pattern used for results to use SetBounds() before Allocate() rather
than the old original Descriptor::Allocate() wrapper around
CFI_allocate().

Since there were few other remaining uses of the old original
Descriptor::Allocate() wrapper, I also converted them to the
new one and deleted the old one.

Differential Revision: https://reviews.llvm.org/D104325
2021-06-16 10:26:25 -07:00
Diana Picus 45cd405dc0 [flang] Add clang-tidy check for braces around if
Flang diverges from the llvm coding style in that it requires braces
around the bodies of if/while/etc statements, even when the body is
a single statement.

This commit adds the readability-braces-around-statements check to
flang's clang-tidy config file. Hopefully the premerge bots will pick it
up and report violations in Phabricator.

We also explicitly disable the check in the directories corresponding to
the Lower and Optimizer libraries, which rely heavily on mlir and llvm
and therefore follow their coding style. Likewise for the tools
directory.

We also fix any outstanding violations in the runtime and in
lib/Semantics.

Differential Revision: https://reviews.llvm.org/D104100
2021-06-16 09:13:53 +00:00
Andrzej Warzynski 062644bb39 [flang][nfc] Move external-hello-world to flang/examples
As `external-hello-world` is not really a test, I am moving it from
`flang/unittest/Runtime` to `flang/examples` (it makes a lot of sense as
an example). I've not modified the source code (apart from adjusting the
include paths).

Differential Revision: https://reviews.llvm.org/D104320
2021-06-16 08:00:50 +00:00
Asher Mancinelli c58cf692f4 [flang] Move buffer runtime test to GTest
Move buffer unit test from Runtime directory to RuntimeGtest
directory and use GTest. Test coverage is only maintained.

Differential Revision: https://reviews.llvm.org/D102335
Reviewed By: awarzynski, klausler
2021-06-14 10:13:32 -07:00
Diana Picus 57e85622bb [flang] Add initial implementation for CPU_TIME
Add an implementation for CPU_TIME based on std::clock(), which should
be available on all the platforms that we support.

Also add a test that's basically just a sanity check to make sure we
return positive values and that the value returned at the start of some
amount of work is larger than the one returned after the end.

Differential Revision: https://reviews.llvm.org/D104019
2021-06-14 07:48:09 +00:00
Michael Kruse 0112f6ac71 [Flang][Runtime][tests] Escape regex special character.
The second argument of `ASSERT_DEATH` describes a regular expression, in
which parentheses have special meaning. Matches of literal parentheses
need to be escaped.

Fixes failure of InvalidFormatFailure.ParenMismatch and
InvalidFormatFailure.ParenMismatch when gtest is compiled with MSVC's
regex implementation.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D104011
2021-06-10 11:30:23 -05:00
Diana Picus 263a89c9b7 [flang] Change capitalization for Adjustl/r
Rename the definitions of the character runtime functions Adjustl and
Adjustr (used to be AdjustL and AdjustR respectively).

Also add unit tests (and move some of the helpers to the top of the
file, since they're now used in more than one place).

Differential Revision: https://reviews.llvm.org/D103392
2021-06-04 08:34:53 +00:00
Diana Picus 5f25145306 [flang] Add tests for REPEAT. NFC
These should already pass with the current implementation.

Differential Revision: https://reviews.llvm.org/D103402
2021-06-02 08:20:21 +00:00
peter klausler c1db35f0c2 [flang] Implement more transformational intrinsic functions in runtime
Define APIs, naively implement, and add basic sanity unit tests for
the transformational intrinsic functions CSHIFT, EOSHIFT, PACK,
SPREAD, TRANSPOSE, and UNPACK.  These are the remaining transformational
intrinsic functions that rearrange data without regard to type
(except for default boundary values in EOSHIFT); RESHAPE was already
in place as a stress test for the runtime's descriptor handling
facilities.

Code is in place to create copies of allocatable/automatic
components when transforming arrays of derived type, but it won't
do anything until we have derived type information being passed to the
runtime from the frontend.

Differential Revision: https://reviews.llvm.org/D102857
2021-05-20 13:22:01 -07:00
peter klausler 5e1421b22f [flang] Implement MATMUL in the runtime
Define an API for the transformational intrinsic function MATMUL,
implement it, and add some basic unit tests.  The large number of
possible argument type combinations are covered by a set of
generalized templates that are instantiated for each valid
pair of possible argument types.

Places where BLAS-2/3 routines could be called for acceleration
are marked with TODOs.  Handling for other special cases (e.g.,
known-shape 3x3 matrices and vectors) are deferred.

Some minor tweaks were made to the recent related implementation
of DOT_PRODUCT to reflect lessons learned.

Differential Revision: https://reviews.llvm.org/D102652
2021-05-18 10:59:52 -07:00
Benjamin Kramer 05de4b4139 Put back the trailing commas on TYPED_TEST_SUITE
This avoids a -pedantic warning:
warning: ISO C++11 requires at least one argument for the "..." in a variadic macro

See also https://github.com/google/googletest/issues/2271
2021-05-17 14:14:13 +02:00
Benjamin Kramer 17ef1017f0 [flang] s/TYPED_TEST_CASE/TYPED_TEST_SUITE/ as the former is deprecated 2021-05-14 20:39:48 +02:00
Benjamin Kramer d4d80a2903 Bump googletest to 1.10.0 2021-05-14 19:16:31 +02:00
peter klausler 50e0b2985e [flang] Implement DOT_PRODUCT in the runtime
API, implementation, and basic tests for the transformational
reduction intrinsic function DOT_PRODUCT in the runtime support
library.

Differential Revision: https://reviews.llvm.org/D102351
2021-05-13 10:40:07 -07:00
peter klausler 01c78a0b07 [flang] Implement NORM2 in the runtime
Implement the reduction transformational intrinsic function NORM2 in
the runtime, using infrastructure already in place for MAXVAL & al.

Differential Revision: https://reviews.llvm.org/D102024
2021-05-07 13:23:21 -07:00
Diana Picus 2ea36e9492 [flang] Remove redundant reallocation
The MaxMinHelper used to implement MIN and MAX for character types would
reallocate the accumulator whenever the number of characters in it was
different from that in the other input. This is unnecessary if the
accumulator is already larger than the other input. This patch fixes the
issue and adds a unit test to make sure we don't reallocate if we don't
need to.

Differential Revision: https://reviews.llvm.org/D101984
2021-05-07 08:54:09 +00:00
Diana Picus 778487a221 [flang] Add tests for MIN for character arrays. NFC
We used to test only scalar character types. This commit adds tests for
arrays with a few simple shapes.

Differential Revision: https://reviews.llvm.org/D101983
2021-05-07 08:54:09 +00:00
peter klausler 6a1c3efa05 [flang] Implement NAMELIST I/O in the runtime
Add InputNamelist and OutputNamelist as I/O data transfer APIs
to be used with internal & external list-directed I/O; delete the
needless original namelist-specific Begin... calls.
Implement NAMELIST output and input; add basic tests.

Differential Revision: https://reviews.llvm.org/D101931
2021-05-06 11:18:36 -07:00
Diana Picus 5112bd6b6e [flang] Fix a bug in the character runtime
The number of bytes copied in CopyAndPad should depend on the size of
the type being copied, not on its shift value (which in the case of char
is 0, leading to no bytes at all being copied).

Add unit tests for CharacterMin and CharacterMax, which exercise this
code path.

Differential Revision: https://reviews.llvm.org/D101355
2021-05-03 08:08:08 +00:00
Diana Picus aaab70407b [flang] Fix handling of elem_len in CFI_establish
The current code computes the minimum element length based on the `type`
used to create the descriptor and uses that as the element length
whenever it is greater than 0. This means that the `elem_len` parameter
is essentially ignored for any type where we can compute a minimum
element length (which includes `CFI_type_char[16|32]_t`), and we may
therefore end up with descriptors with a lower element length than
expected.

This patch fixes the issue by explicitly doing what the standard says,
i.e. it uses the given `elem_len` for character types, `CFI_type_struct`
and `CFI_type_other`, and ignores it (falls back to the minimum element
length) for everything else.

Differential Revision: https://reviews.llvm.org/D101659
2021-05-03 08:08:07 +00:00
Diana Picus 32f901bdf9 [flang] Use CFI_TYPE_LAST instead of CFI_type_struct
It looks like CFI_type_struct was once used as the last valid CFI_type
value, but in the meantime CFI_type_char16_t and CFI_type_char32_t were
added, making that assumption no longer true. Luckily, in the meantime
we also got a define for CFI_TYPE_LAST, which we can now use to allow
CFI_establish and CFI_allocate to work with descriptors of
CFI_type_char16_t, CFI_type_char32_t and any other future types.

Differential Revision: https://reviews.llvm.org/D101658
2021-05-03 08:08:07 +00:00
Asher Mancinelli 4abba775a3 [flang] Add format test to GTest suite
Reviewed by: awarzynski
Differential Revision: https://reviews.llvm.org/D100765
2021-04-27 07:45:18 -07:00
Mehdi Chinoune 0a7d2b5f50 [flang][msvc] Fix compilation of external-hello-world test with MSVC.
MSVC doesn't accept division by zero.

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D96069
2021-04-21 15:18:24 -05:00
Mehdi Chinoune 080d48f279 [flang][msvc] Fix compilation of RuntimeGtest
Removes alternate spelling 'not' with '!'.

Reviewed by: ashermancinelli, awarzynski, Meinersbur

Differential revision: https://reviews.llvm.org/D100442
2021-04-20 15:36:38 -06:00