Commit graph

3301 commits

Author SHA1 Message Date
Andrzej Warzynski 45e5214b43 [flang][driver] Add support for --version in the bash wrapper
The bash wrapper script, `flang`, calls `flang-new -fc1` under the hood,
which does not support `--version` (this is consistent with `clang -cc1
--version`). This change is needed for `flang --version` to work as
expected.

Note that `flang --version` (the Flang bash wrapper script for the
compiler driver) gives rather minimal output compared to `flang-new
--version` (the Flang compiler driver). As the wrapper script is just a
temporary solution for us, this should be sufficient.

Differential Revision: https://reviews.llvm.org/D105352
2021-07-03 10:47:41 +01:00
Andrzej Warzynski e77191c35e [flang][driver] Extend the flang bash script to act as a driver
Until now, `f18` would:
  1. Use Flang to unparse the input files
  2. Call an external Fortran compiler to compile the unparsed source
  files (generated in step 1)

With this patch, `f18` will stop after unparsing the input source files,
i.e. step 1 above. The `flang` bash script will take care of step 2,
i.e. calling an external Fortran compiler driver to compile them. This
way:
  * the functionality of `f18` is reduced - it will only drive Flang (as
  opposed to delegating code-generation to an external tool on top of
  this)
  * we will able to switch between `f18` and `flang-new` for unparsing before
  an external Fortran compiler is called for code-generation

The updated `flang` bash script needs to specify the output file when
using the `-fdebug-unparse` action. Both `f18` and `flang-new` have been
updated accordingly.

These changes were discussed in [1] as a requirement for replacing `f18`
with `flang-new`.

[1] https://lists.llvm.org/pipermail/flang-dev/2021-April/000677.html

Differential Revision: https://reviews.llvm.org/D103177
2021-07-01 13:56:38 +01:00
Andrzej Warzynski c1f068b8f1 [flang] Revert "PoC for Flang Driver Plugins"
This patch has not been reviewed and was commited by accident.

This reverts commit 788a5d4afe.
2021-07-01 08:27:31 +00:00
Andrzej Warzynski ea3698ded3 [flang][docs] Add documentation for the new Flang driver
Differential Revision: https://reviews.llvm.org/D104229
2021-07-01 08:14:54 +00:00
Stuart Ellis 788a5d4afe PoC for Flang Driver Plugins 2021-07-01 08:10:40 +00:00
Michael Kruse 5d933c0b0c [Flang][test] Fix Windows buildbot after D104930.
Add

    REQUIRES: shell

to the unpack.f90 test that executes a UNIX shell script.
2021-06-29 17:01:45 +00:00
Diana Picus b8bac6b33c [flang] Add runtime interface for SYSTEM_CLOCK
SYSTEM_CLOCK may take up to 3 optional parameters, all of which are
INTENT(OUT). The COUNT and COUNT_MAX parameters are integer scalars,
while COUNT_RATE may be a real or integer scalar.

This patch breaks up the interface into 3 different functions, one for
each parameter. All 3 return integers. It is up to lowering to convert
the results to the preferred type.

Differential Revision: https://reviews.llvm.org/D104851
2021-06-29 08:25:01 +00:00
peter klausler cd0a1226b5 [flang] Fix "non-advancing" I/O, support $ in FORMAT
Non-advancing I/O was failing; ExternalFileUnit was losing
track of what writes had been committed to the file.  Fixed.
Also, support the common extension of $ and \ in a FORMAT
as being equivalent to ADVANCE=NO.

Differential Revision: https://reviews.llvm.org/D105046
2021-06-28 12:18:25 -07:00
peter klausler 43fadefb0e [flang] Implement user-defined derived type runtime I/O
With derived type description tables now available to the
runtime library, it is possible to implement the concept
of "child" I/O statements in the runtime and use them to
convert instances of derived type I/O data transfers into
calls to user-defined subroutines when they have been specified
for a type.  (See Fortran 2018, subclauses 12.6.4.8 & 13.7.6).

 - Support formatted, list-directed, and NAMELIST
   transfers to internal parent units; support these, and unformatted
   transfers, for external parent units.
 - Support nested child defined derived type I/O.
 - Parse DT'foo'(v-list) FORMAT data edit descriptors and passes
   their strings &/or v-list values as arguments to the defined
   formatted I/O routines.
 - Fix problems with this feature encountered in semantics and
   FORMAT valiation during development and end-to-end testing.
 - Convert typeInfo::SpecialBinding from a struct to a class
   after adding a member function.

Differential Revision: https://reviews.llvm.org/D104930
2021-06-28 11:36:19 -07:00
Peter Steinfeld 57e53f0130 [flang] Fix conformability for intrinsic procedures
There are situations where the arguments of intrinsics must be
conformable, which is defined in section 3.36.  This means they must
have "the same shape, or one being an array and the other being scalar".
But the check we were actually making was that their ranks were the same.

This change fixes that and adds a test for the UNPACK intrinsic, where
the FIELD argument "shall be conformable with MASK".

Differential Revision: https://reviews.llvm.org/D104936
2021-06-28 11:09:24 -07:00
naromero77 d6cb0143cc [flang][docs] Minor update to Fortran LLVM Tests-suite docs.
Updated Fortran LLVM Test-suite docs to reflect latest changes.

Reviewed By: Meinersbur, xgupta

Differential Revision: https://reviews.llvm.org/D104961
2021-06-28 10:01:29 -05:00
peter klausler 3cc5d4ff8e [flang] Fix generic/specific procedure confusion
A recent change that extended semantic analysis for actual arguments
that associate with procedure dummy arguments exposed some bugs in
regression test suites due to points of confusion in symbol table
handling in situations where a generic interface contains a specific
procedure of the same name.  When passing that name as an actual
argument, for example, it's necessary to take this possibility into
account because the symbol for the generic interface shadows the
symbol of the same name for the specific procedure, which is
what needs to be checked.  So add a small utility that bypasses
the symbol for a generic interface in this case, and use it
where needed.

Differential Revision: https://reviews.llvm.org/D104929
2021-06-25 11:54:29 -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
Andrzej Warzynski 2a7bb8494e [flang][driver] Add -fno-analyzed-objects-for-unparse
This patch adds a new option for the new Flang driver:
`-fno-analyzed-objects-for-unparse`. The semantics are similar to
`-funparse-typed-exprs-to-f18-fc` from `f18`. For consistency, the
latter is replaced with `-fno-analyzed-objects-for-unparse`.

The new option controls the behaviour of the unparser (i.e. the action
corresponding to `-fdebug-unparse`). The default behaviour is to use the
analyzed objects when unparsing. The new flag can be used to turn this
off, so that the original parse-tree objects are used. The analyzed
objects are generated during the semantic checks [1].

This patch also updates the semantics of
`-fno-analyzed-objects-for-unparse`/`-funparse-typed-exprs-to-f18-fc`
in `f18`, so that this flag is always taken into account when `Unparse`
is used (this way the semantics in `f18` and `flang-new` are identical).

The added test file is based on example from Peter Steinfeld.

[1]
https://github.com/llvm/llvm-project/blob/main/flang/docs/Semantics.md

Differential Revision: https://reviews.llvm.org/D103612
2021-06-25 13:28:12 +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
Fangrui Song f1e2d5851b [OptTable] Rename PrintHelp to printHelp
To be consistent with other member functions and match the coding standard.
2021-06-24 14:47:03 -07:00
Martin Storsjö 2716c6faa4 [flang] Tweak the conditions for the GCC 7/libstdc++ workaround
This adjusts the workaround from D104731.

The issue lies in libstdc++'s classes, not GCC itself, and manifests
itself in the same way if building e.g. with clang while using
libstdc++ headers from GCC 7 (e.g. if building with Clang on Ubuntu 18.04,
while using the system default C++ library).

Therefore, change the condition to look for the version of libstdc++
instead of the compiler.

Differential Revision: https://reviews.llvm.org/D104779
2021-06-23 23:19:32 +03:00
River Riddle 00c93d8801 Fix flang build after D104167 2021-06-23 18:18:54 +00:00
peter klausler e3b2f1b682 [flang] [NFC] Repair build with GCC 7.3
Work around two problems with GCC 7.3.
One is its inability to implement "constexpr operator=(...) = default;"
in a class with a std::optional<> component; another is a legitimate-
looking warning about an unused variable.

Differential Revision: https://reviews.llvm.org/D104731
2021-06-22 13:52:30 -07:00
peter klausler 503c085e3b [flang] Fold more reduction intrinsic function calls
Refactor the recently-implemented MAXVAL/MINVAL folding so
that the parts that can be used to implement other reduction
transformational intrinsic function folding are exposed.

Use them to implement folding of IALL, IANY, IPARITY,
SUM. and PRODUCT.  Replace the folding of ALL & ANY to
use the new infrastructure and become able to handle DIM=
arguments.

Differential Revision: https://reviews.llvm.org/D104562
2021-06-21 10:13:59 -07:00
Peter Steinfeld e7f78fb917 [flang] Implement constant folding for the NOT intrinsic
I implemented constant folding for the NOT intrinsic and added some tests.

Differential Revision: https://reviews.llvm.org/D104587
2021-06-20 07:25:05 -07:00
Michael Kruse f075760317 [Flang][test] Fix Windows buildbot.
Add

    REQUIRES: shell

to tests that execute a UNIX shell script to not run on Windows.
2021-06-19 22:23:02 -05:00
peter klausler b3c1f53c98 [flang] Recode a switch() to dodge a sketchy warning
One of the buildbots uses a compiler (can't tell which) that
doesn't approve of a "default:" in a switch statement whose
cases appear to completely cover all possible values of an
enum class.  But this switch is in raw data dumping code that
needs to allow for incorrect values in memory.  So rewrite it
as a cascade of if statements; performance doesn't matter here.
2021-06-18 16:58:44 -07:00
peter klausler 36f93fc594 [flang] Fix clang build (struct/class mismatch warning)
A recent patch changed a struct into a class, but missed a
forward definition.  GCC didn't warn, but clang does.  Fix.
2021-06-18 15:12:51 -07:00
Arnamoy Bhattacharyya 8fdd475c85 [flang][OpenMP] Add semantic checks for occurrence of nested Barrier regions
This patch adds the following nesting check for `barrier` constructs:

```
A barrier region may not be closely nested inside a worksharing, loop, task, taskloop, critical, ordered, atomic, or master region.
```

Also adds a test case for the check,

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D99888
2021-06-18 16:24:36 -04:00
peter klausler 79caf69cc0 [flang] Runtime implementation for default derived type formatted I/O
This is *not* user-defined derived type I/O, but rather Fortran's
built-in capabilities for using derived type data in I/O lists
and NAMELIST groups.

This feature depends on having the derived type description tables
that are created by Semantics available, passed through compilation
as initialized static objects to which pointers can be targeted
in the descriptors of I/O list items and NAMELIST groups.

NAMELIST processing now handles component references on input
(e.g., "&GROUP x%component = 123 /").

The C++ perspectives of the derived type information records
were transformed into proper classes when it was necessary to add
member functions to them.

The code in Semantics that generates derived type information
was changed to emit derived type components in component order,
not alphabetic order.

Differential Revision: https://reviews.llvm.org/D104485
2021-06-18 10:30:28 -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
Jean Perier 1a4af2e45e [flang] preserve symbol in DescriptorInquiry
Do not use ultimate symbols in DescriptorInquiry. Using the ultimate
symbol may lead to issues later for at least two reasons:

- The original symbols may have volatile/asynchronous attributes that
  the ultimate may not have. Later phases working on the DescriptorInquiry
  would then not apply potential care required by these attributes.
- HostAssociatedDetails symbols are used by OpenMP for symbols with
  special OpenMP attributes inside OpenMP region (e.g variables with
  private attribute), so it is very important to preserve this
  aspect in the DescriptorInquiry, that would otherwise apply on the
  symbol outside of the region.

Differential Revision: https://reviews.llvm.org/D104385
2021-06-17 12:42:08 +02:00
peter klausler 562bfe1274 [flang] Complain about more cases of calls to insufficiently defined procedures
When a function is called in a specification expression, it must be
sufficiently defined, and cannot be a recursive call (10.1.11(5)).
The best fix for this is to change the contract for the procedure
characterization infrastructure to catch and report such errors,
and to guarantee that it does emit errors on failed characterizations.
Some call sites were adjusted to avoid cascades.

Differential Revision: https://reviews.llvm.org/D104330
2021-06-16 18:20:59 -07:00
peter klausler fc4f457fcc [flang] Fix ARM/POWER test failure (folding20.f90)
Recent code for folding MINVAL() didn't allow for architectures
whose C/C++ char type is unsigned, so the value of the maximum
Fortran character was incorrect.  This was caught by the
folding20.f90 test.  The fix is to avoid numeric_limits<> and
use hard values for max signed integers of various character kinds.

Pushing into llvm-project/main to restore ARM/POWER buildbots.
2021-06-16 16:41:08 -07: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 c375ec8613 [flang] Use a "double-double" accumulator in SUM
Use a "double-double" accumulator, a/k/a Kahan summation,
in the SUM intrinsic in the runtime for real & complex.
This seems to be the best-recommended technique for reducing
error, as opposed to the initial implementation of SUM's
distinct accumulators for positive and negative items.

Differential Revision: https://reviews.llvm.org/D104338
2021-06-16 14:29:39 -07:00
peter klausler 47f18af55f [flang] Fold MAXVAL & MINVAL
Implement constant folding for the reduction transformational
intrinsic functions MAXVAL and MINVAL.

In anticipation of more folding work to follow, with (I hope)
some common infrastructure, these two have been implemented in a
new header file.

Differential Revision: https://reviews.llvm.org/D104337
2021-06-16 14:06:34 -07:00
Andrzej Warzynski 46446e398b [flang][driver] Add missing ! REQUIRES LIT directive
The test added in https://reviews.llvm.org/D104305 will only work with
the new driver and should be marked as such.

Sending this without a review as it's fairly straightforward and fixes
test failures for developers that don't want to build the new driver.
2021-06-16 21:00:13 +00:00
peter klausler ec3049c79b [flang] Cope with errors with array constructors
When a program attempts to put something like a subprogram
into an array constructor, emit an error rather than crashing.

Differential Revision: https://reviews.llvm.org/D104336
2021-06-16 13:44:20 -07:00
peter klausler e5813a683a [flang] Fix crashes on calls to non-procedures
When a procedure reference is attempted to an entity that just
isn't a procedure, say so.

Differential Revision: https://reviews.llvm.org/D104329
2021-06-16 12:48:54 -07:00
peter klausler 3061334e0d [flang] Don't crash on some bogus expressions
Recover more gracefully from user errors in expressions.

Differential Revision: https://reviews.llvm.org/D104326
2021-06-16 12:26:39 -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 0ad051b5fc [flang] Check there's no dependency on C++ libs. NFC
Add a test to make sure the flang runtime doesn't pull in the C++
runtime libraries.

This is achieved by adding a C file that calls some functions from the
runtime (currently only CpuTime, but we should probably add anything
complicated enough, e.g. IO-related things). We force the C compiler to
use -std=c90 to make sure it's really in C mode (we don't really care
which version of the standard, this one is probably more widely
available). We only enable this test if CMAKE_C_COMPILER is set to
something (which is probably always true in practice).

This is a recommit of 7ddbf26, with 2 fixes:
* Replace C++ comments with C comments
* Only enable the test if libFortranRuntime.a exists (this might not be
the case if e.g. BUILD_SHARED_LIBS=On)

Differential Revision: https://reviews.llvm.org/D104290
2021-06-16 11:38:25 +00:00
Diana Picus dfa0f3ee0e Revert "[flang] Check there's no dependency on C++ libs"
This reverts commit 7ddbf26339.

This doesn't work if we're not building libFortranRuntime.a. I'll
recommit with a fix.
2021-06-16 11:09:08 +00:00
Diana Picus 10ae933b0b [flang] Fixup 7ddbf26339
Replace C++ comments with C-style comments (not sure why my C compiler
doesn't complain about this).
2021-06-16 09:43:07 +00: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
Diana Picus 7ddbf26339 [flang] Check there's no dependency on C++ libs
Add a test to make sure the flang runtime doesn't pull in the C++
runtime libraries.

This is achieved by adding a C file that calls some functions from the
runtime (currently only CpuTime, but we should probably add anything
complicated enough, e.g. IO-related things). We force the C compiler to
use -std=c90 to make sure it's really in C mode (we don't really care
which version of the standard, this one is probably more widely
available). We only enable this test if CMAKE_C_COMPILER is set to
something (which is probably always true in practice).

Differential Revision: https://reviews.llvm.org/D104290
2021-06-16 08:23:43 +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
Andrzej Warzynski a6be6e31f1 [flang][driver] Add -fdebug-dump-all
The new option will run the semantic checks and then dump the parse tree
and all the symbols. This is equivalent to running the driver twice,
once with `-fdebug-dump-parse-tree` and then with
the `-fdebug-dump-symbols` action flag.

Currently we wouldn't be able to achieve the same by simply running:
```
flang-new -fc1 -fdebug-dump-parse-tree -fdebug-dump-symbols <input-file>
```
That's because the new driver will only run one frontend action per
invocation (both of the flags used here are action flags). Diverging
from this design would lead to costly compromises and it's best avoided.

We may want to consider re-designing our debugging actions (and action
options) in the future so that there's more code re-use. For now, I'm
focusing on making sure that we support all the major cases requested by
our users.

Differential Revision: https://reviews.llvm.org/D104305
2021-06-16 07:54:27 +00:00
Peter Steinfeld bda1f2936e [flang] Add semantic check for the RANDOM_SEED intrinsic
I added the only check that wasn't already tested along with tests for
many valid and invalid arguments.

Differential Revision: https://reviews.llvm.org/D104318
2021-06-15 21:27:54 -07:00
Isaac Perry 80ea006ef9 [flang] [openmp] Add Fortran specific semantic check 4 for OpenMP Allocate directive.
This patch adds the 4th Fortran specific semantic check for the OpenMP
allocate directive: "If a list item has the SAVE attribute, is a common
block name, or is declared in the scope of a module, then only predefined
memory allocator parameters can be used in the allocator clause".

Code in this patch was based on code from https://reviews.llvm.org/D93549/new/.

Differential Revision: https://reviews.llvm.org/D102400
2021-06-15 16:04:04 +01: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
Peter Steinfeld b88fa0e39f [flang] Fix compilation problem with rename of "MemRefDataFlow"
Revision https://reviews.llvm.org/D104190 renamed MemRefDataFlow -> AffineScalarReplacement.  After this rename, mlir failed to build.  With this change, all of clang, mlir, and flang build and test correctly.

Differential Revision: https://reviews.llvm.org/D104223
2021-06-14 07:01:11 -07:00
Diana Picus 166192eb78 [flang] Add POSIX implementation for CPU_TIME
Add an implementation for CPU_TIME using the POSIX function
clock_gettime. I think on most POSIX systems this will be included for
free via <ctime>, which corresponds to "time.h" (YMMV, we can fix the
code if the need arises).

Detecting that clock_gettime is available is tricky. For instance, commit
827407a86a used the following incantation in f18-parse-demo.cpp:

  #if _POSIX_C_SOURCE >= 199309L && _POSIX_TIMERS > 0 && _POSIX_CPUTIME && \
    defined CLOCK_PROCESS_CPUTIME_ID

This doesn't work on my AArch64 Ubuntu system, which provides
clock_gettime but doesn't define _POSIX_TIMERS. Since finding the right
combination of macros requires infinite time, patience and access to
sundry POSIX systems, we should probably try a different approach.

This patch attempts to use SFINAE instead of the preprocessor to choose
an implementation for CPU_TIME. We define a helper function template
which helps us check if clock_gettime is available (and has the
interface we expect). I hope the comments explain it well enough.

This approach has the advantage that it keeps the detection of
clock_gettime close to the code that uses it. An alternative would be to
use CMake to check for the symbol (I personally haven't used this before
so I don't know if there are any quirks).

Differential Revision: https://reviews.llvm.org/D104020
2021-06-14 09:41:11 +00:00