Commit Graph

3358 Commits

Author SHA1 Message Date
Ivan Zhechev 35249cb7b1 [Flang] Fix error messages on Windows.
Flang uses positional arguments for `messages::say()`, such as "%1$s" which is only supported in MS Compilers with the `_*printf_p` form of the function. This uses a conditional macro to convert the existing `vsnprintf` used to the one needed in MS-World.

7 tests in D107575 rely on this change.

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D107654
2021-08-12 18:35:54 +01:00
Kiran Chandramohan 4573c31f89 [Flang] Fix build failure on MacOS
std::clock_t can be an unsigned value on some platforms like MacOS and
therefore needs a cast when initializing an std::clock_t value with -1.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D107972
2021-08-12 18:14:46 +01:00
peter klausler 467525bd07 [flang] Fix crash in runtime-type-info.cpp
Recent work in runtime assignments failed an assertion in fir-dev
while running tests (flang/test/Semantics/defined-ops.f90).  This
test didn't fail in llvm-project/main because only the "new" Arm
driver is used now, and that only builds runtime derived type information
tables when some debug dumping options are enabled.

So add a reproducing test case to another test that is run with
-fdebug-dump-symbols, and fix the crash by emitting special procedure
binding information only for type-bound generic ASSIGNMENT(=) bindings
that are relevant to the runtime support library for use in intrinsic
assignment of derived types.

Differential Revision: https://reviews.llvm.org/D107918
2021-08-12 09:32:08 -07:00
Stuart Ellis f52fc591fa [flang][driver] Add support for Frontend Plugins
Introducing a plugin API and a simple HelloWorld Plugin example.
This patch adds the `-load` and `-plugin` flags to frontend driver and
the code around using custom frontend actions from within a plugin
shared library object.

It also adds to the Driver-help test to check the help option with the
updated driver flags.

Additionally, the patch creates a plugin-example test to check the
HelloWorld plugin example runs correctly. As part of this, a new CMake
flag (`FLANG_BUILD_EXAMPLES`) is added to allow the example to be built
and for the test to run.

This Plugin API has only been tested on Linux.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D106137
2021-08-12 11:42:16 +01: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
peter klausler 101b3fed5e [flang] Fix two typos in API names
Differential Revision: https://reviews.llvm.org/D107916
2021-08-11 12:43:37 -07:00
Peter Steinfeld 3ad9826dcd [flang] Fix the extent calculation when upper bounds are less than lower bounds
When the upper bound is less than the lower bound, the extent is zero.  This is
specified in section 8.5.8.2, paragraph 3.

Note that similar problems exist in the lowering code.  This change only fixes
the problem for the front end.

I also added a test.

Differential Revision: https://reviews.llvm.org/D107832
2021-08-10 10:34:22 -07:00
Jean Perier f2f6190960 [flang] Always create HostAssocDetails for host object symbols with UseDetails
https://reviews.llvm.org/D105464 did not correctly cover the case
where the symbol from the host procedure is use associated. Outside
of the mis-parsed ArrayRef case, flang was also creating a symbol with
HostAssociated details inside the internal procedure (pointing to the
use associated symbol in the host). That is what lowering expects.
This patch ensures the same logic is applied in the mis-parsed array-ref name
resolution (and the pointer target name resolution).

Differential Revision: https://reviews.llvm.org/D107759
2021-08-10 12:38:19 +02:00
peter klausler 511ac6f8b4 [flang] Silence new build warning
Some build environments complain about unused data members in some
C++ translations of Fortran derived types; those members don't really
need to be present, so remove them.

Fix pushed w/o review to get build bots running again.
2021-08-09 11:57:45 -07:00
Andrzej Warzynski 41f4d47484 [flang] Make `flang` translate `-M{fixed|free}` into `-f{fixed|free}-form`
We are only adding this in `flang` - the bash wrapper script for the
driver. We don't have any specific plans to support `-M{fixed|free}` in
`flang-new` (i.e. the actual driver).

That feature was requested by one of our users.

Differential Revision: https://reviews.llvm.org/D107081
2021-08-09 18:06:09 +01:00
peter klausler 65f5290432 [flang] Implement runtime Assign()
Define an API for, and implement, runtime support for arbitrary
assignment of one descriptor's data to another, with full support for
(re)allocation of allocatables with finalization when necessary,
user-defined derived type assignment TBP calls, and intrinsic (default)
componentwise assignment of derived type instances with allocation of
automatic components.  Also clean up API and implementation of
finalization/destruction using knowledge gained while studying
edge cases for assignment in the 2018 standard.

The look-up procedure for special procedure bindings in derived
types has been optimized from O(N) to O(1) since it will probably
matter more.  This required some analysis in runtime derived type
description table construction in semantics and some changes to the
table schemata.

Executable Fortran tests have been developed; they'll be added
to the test base once they can be lowered and run by f18.

Differential Revision: https://reviews.llvm.org/D107678
2021-08-09 09:31:32 -07:00
Ivan Zhechev eabae4cf57 [Flang] Ported test_symbols to Python
Due to unavailability of Flang testing on Windows, the shell scripts
are being ported to Python. The following changes are being made in
this patch: removed test_symbols.sh and common.sh, and ported them
to Python. Changes to the tests themselves so that they use the
python scripts instead of the shell script.

Reviewed By: Meinersbur, awarzynski, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D107041
2021-08-09 16:20:06 +01:00
Asher Mancinelli dfce2909ee [flang] Lift -Werror checks into local functions
Lift checks for -Werror into local functions.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D101261
2021-08-06 12:43:19 -06:00
Andrzej Warzynski 3709822d26 [flang][docs] Document the `flang` wrapper script
Differential Revision: https://reviews.llvm.org/D107543
2021-08-06 12:45:32 +00: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
Andrzej Warzynski 55a9615599 [flang][driver] Refactor boolean options
For boolean options, e.g. `-fxor-operator`/`-fno-xor-operator`, we ought
to be using TableGen multi-classes. This way, we only have to write one
definition to have both forms auto-generated. This patch refactors all
of Flang's boolean options to use two new multi-classes:
`OptInFC1FFOption` and `OptOutFC1FFOption`. These multi-classes are
based on `OptInFFOption`/`OptOutFFOption`, respectively. I've also
simplified the processing of the updated options in
CompilerInvocation.cpp.

With the new approach, "empty" help text (i.e. no `HelpText`) is now
replaced with an empty string (i.e. HelpText<"">). When running
flang-new --help, that's considered as non-empty help messages, which is
then printed (that's controlled by `printHelp` from
llvm/lib/Option/OptTable.cpp). This means that with this patch,
flang-new --help will start printing e.g. -fno-backslash, even though
there is no actual help text to print for this option (apart from the
empty string ""). Tests are updated accordingly.

Note that with this patch, both `-fxor-operator` and `-fno-xor-operator`
(and other boolean options refactored here) remain available in
`flang-new` and `flang-new -fc1`. In this respect, nothing changes. In a
forthcoming patch, I will refine this so that `flang-new -fc1` only
accepts `-ffoo` (`OptInFC1FFOption`) or `-fno-foo` (`OptOutCC1FFOption`).

For clarity, `OptInFFOption`/`OptOutFFOption` are renamed as
`OptInCC1FFOption`/`OptOutCC1FFOption`, respectively. Otherwise, this is
an NFC from Clang's perspective.

Differential Revision: https://reviews.llvm.org/D105881
2021-08-05 10:20:47 +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
peter klausler 617be2756f [flang] Support DFLOAT legacy extension intrinsic function
Like the similar legacy extension FLOAT(), DFLOAT() represents a
conversion from default integer to DOUBLE PRECISION.  Rewrite
into a conversion operation.

Differential Revision: https://reviews.llvm.org/D107489
2021-08-04 12:18:41 -07:00
Matthias Springer b44eb5a149 [flang] Add missing FileSystem.h
This file was previously included transitively via `mlir/Transforms/Passes.h`, but the include has been removed from that file.

Differential Revision: https://reviews.llvm.org/D107455
2021-08-04 22:22:26 +09:00
Chirag Khandelwal 77ebfba68b [Flang][Openmp] Upgrade TASKGROUP construct to 5.0.
In OMP 5.0 specification clause-list with
* task_reduction
* allocate
were allowed on taskgroup construct.

Fix XFAIL - omp-taskloop01.f90.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D93373
2021-08-03 10:27:47 +05:30
Andrzej Warzynski ad2e830fe2 [flang][nfc] Add a regression test for #50993
https://bugs.llvm.org/show_bug.cgi?id=50993 was effectively fixed in
https://reviews.llvm.org/D106727. This patch adds a regression
test specifically for the use case reported in 50993.

Differential Revision: https://reviews.llvm.org/D107260
2021-08-02 18:21:23 +00:00
peter klausler c4a65434d8 [flang] Symbol representation for dummy SubprogramDetails
Dummy procedures can be defined as subprograms with explicit
interfaces, e.g.

  subroutine subr(dummy)
    interface
      subroutine dummy(x)
        real :: x
      end subroutine
    end interface
    ! ...
  end subroutine

but the symbol table had no means of marking such symbols as dummy
arguments, so predicates like IsDummy(dummy) would fail.  Add an
isDummy_ flag to SubprogramNameDetails, analogous to the corresponding
flag in EntityDetails, and set/test it as needed.

Differential Revision: https://reviews.llvm.org/D106697
2021-08-02 10:44:27 -07:00
peter klausler bab86463df [flang] Fix IsSimplyContiguous() for the case of a pointer component
The result expression for the analysis of a Component is not (longer)
valid in the expression traversal framework used by IsSimplyContiguousHelper
now that it has a tri-state result.  Fix so that any result of
analyzing the component symbol is required to be true, not just
present.

Differential Revision: https://reviews.llvm.org/D106693
2021-08-02 09:43:43 -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
Andrzej Warzynski 1a7ed9561a [flang] Fix `flang` (the bash wrapper script for the Flang driver)
Remove erroneous `||` at the end of an `if` condition. This was
introduced in https://reviews.llvm.org/D106871.
2021-07-30 09:02:35 +01: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
Fangrui Song 72a83674dd Replace LLVM_ATTRIBUTE_NORETURN with C++11 [[noreturn]]. NFC
[[noreturn]] can be used since Oct 2016 when the minimum compiler requirement was bumped to GCC 4.8/MSVC 2015.
2021-07-29 09:59:45 -07:00
Andrzej Warzynski 8bf0a40608 [flang][driver] Forward `-fopenmp`/`-fopenacc` to the host compiler
This patch only modifies `flang` - the bash wrapper script.

`-fopenmp`/`-fopenacc` are required to enable the OpenMP/OpenACC
extension in the frontend and to make sure that the required libraries
are linked when generating the final binary. This patch makes sure that
`-fopnemp`/`-fopenacc` is used for both unparsing and the code
generation (via the host compiler).

Differential Revision: https://reviews.llvm.org/D106871
2021-07-29 11:21:56 +01:00
River Riddle f8479d9de5 [mlir] Set the namespace of the BuiltinDialect to 'builtin'
Historically the builtin dialect has had an empty namespace. This has unfortunately created a very awkward situation, where many utilities either have to special case the empty namespace, or just don't work at all right now. This revision adds a namespace to the builtin dialect, and starts to cleanup some of the utilities to no longer handle empty namespaces. For now, the assembly form of builtin operations does not require the `builtin.` prefix. (This should likely be re-evaluated though)

Differential Revision: https://reviews.llvm.org/D105149
2021-07-28 21:00:10 +00:00
Peter Steinfeld 571673ce39 [flang] Disallow BOZ literal constants as output list items
According to C7109, "A boz-literal-constant shall appear only as a
data-stmt-constant in a DATA statement, or where explicitly allowed in
16.9 as an actual argument of an intrinsic procedure."  This change
enforces that constraint for output list items.

I also added a general interface to determine if an expression is a BOZ
literal constant and changed all of the places I could find where it
could be used.

I also added a test.

This change stemmed from the following issue --
  https://gitlab-master.nvidia.com/fortran/f18-stage/issues/108

Differential Revision: https://reviews.llvm.org/D106893
2021-07-27 13:01:26 -07:00
Andrzej Warzynski cad2affb78 [flang][driver] Make `flang` ignore `-Mfree/-Mfixed`
`-Mfixed` is not supported by the new driver and hence
`flang`, the bash wrapper script, forwards it to the host compiler.
The forwarded options are used by the host compiler when compiling the
unparsed files. As the unparsed source files are always in the free
form, forwarding `-Mfixed` is problematic.

With this patch, `-Mfixed` (and `-Mfree` for consistency) will be
ignored altogether. The user will only see a warning. This is not a
particularly sound approach, but `flang` is only a temporary solution
for us and this workaround is a fair compromise.

Differential Revision: https://reviews.llvm.org/D106428
2021-07-27 13:12:28 +01: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 Steinfeld 8f41431654 [flang] Disallow BOZ literal constants as arguments of implicit interfaces
Since BOZ literal arguments are typeless, we cannot know how to pass them as
actual arguments to procedures with implicit interfaces.  This change avoids
the problem by emitting an error message in such situations.

This change stemmed from the following issue --
  https://github.com/flang-compiler/f18-llvm-project/issues/794

Differential Revision: https://reviews.llvm.org/D106831
2021-07-26 15:04:05 -07:00
Michael Kruse cbad57613e [flang][msvc] Fix external-io unittest.
Fix the external-io unittest under Windows.

In particular, fixes the following issues:

 1.  When creating a temporary file, open it with read+write permissions
     using the _O_RDWR flag. _S_IREAD and _S_IWRITE are for the file
     permissions of the created file.

 2. _chsize returns 0 on success (just like ftruncate).

 3. To set a std::optional, use its assign-operator overload instead of
    getting a reference to its value and overwrite that. The latter is
    invalid if the std::optional has no value, and is caught by
    msvc's debug STL.

The non-GTest unittest is currently not executed under Windows because
of the added .exe extension to the output file: external-io.text.exe.
llvm-lit skips the file because .exe is not in the lists of test
suffixes (.test is). D105315 is going to change that by converting it
to a GTest-test.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D106726
2021-07-26 15:34:35 -05: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 klausler e093cbb7ae [flang] Runtime: Reset list-directed input state for each NAMELIST item
NAMELIST I/O formatting uses the runtime infrastructure for
list-directed I/O.  List-directed input processing has same state
that requires reinitialization for each successive NAMELIST input
item.  This patch fixes bugs with "null" items and repetition counts
on NAMELIST input items after the first in the group.

Differential Revision: https://reviews.llvm.org/D106694
2021-07-23 18:21:33 -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
peter klausler 13e08de91d [flang] Two tweaks to mollify buildbots
One test's expected output needs adjustment, and one new compiler
warning needs to be silenced.
2021-07-20 19:42:05 -07:00
peter klausler 0fab536900 [flang] Remove now-unused private data member, silence warning
A field in DescriptorAddendum became unused during a recent
change but was not removed from the definition; it now elicits
a legitimate warning that's affecting some buildbots.  Remove it.
2021-07-20 17:24:39 -07:00
peter klausler b43e083bb6 [flang] Don't require newline at EOF in unformatted sequential runtime input
F18 was sigalling an end-of-file error condition when reading an
unformatted sequential input file without an ultimate newline
(or CR-LF). Other Fortran implementations can handle it, so change
the runtime to support it.

Differential Revision: https://reviews.llvm.org/D106321
2021-07-20 15:25:09 -07:00
peter klausler a48e41683a [flang] Run-time derived type initialization and destruction
Use derived type information tables to drive default component
initialization (when needed), component destruction, and calls to
final subroutines.  Perform these operations automatically for
ALLOCATE()/DEALLOCATE() APIs for allocatables, automatics, and
pointers.  Add APIs for use in lowering to perform these operations
for non-allocatable/automatic non-pointer variables.
Data pointer component initialization supports arbitrary constant
designators, a F'2008 feature, which may be a first for Fortran
implementations.

Differential Revision: https://reviews.llvm.org/D106297
2021-07-20 15:24:16 -07:00
peter klausler 4e92962127 [flang] Fix legitimate warning from latest GCC
A rank-0 static descriptor needs to be a vector; it's for
"v-list" values in defined derived type formatted I/O.

(Pushed without pre-review due to high confidence and an
unwell buildbot.)
2021-07-20 11:40:34 -07:00
peter klausler ad424cf1ed [flang] Runtime API for data pointers
Define and implement an API for use by lowering to
implement operations on pointers.

Differential Revision: https://reviews.llvm.org/D106170
2021-07-19 08:23:06 -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