Commit Graph

3274 Commits

Author SHA1 Message Date
peter klausler bbd0dc3d65 [flang] Ensure pointer function results are acceptable variables
Fortran permits a reference to a function whose result is a pointer
to be used as a definable variable in any context where a
designator could appear.  This patch wrings out remaining bugs
with such usage and adds more testing.

The utility predicate IsProcedurePointer(expr) had a misleading
name which has been corrected to IsProcedurePointerTarget(expr).

Differential Revision: https://reviews.llvm.org/D98555
2021-03-12 16:04:36 -08:00
peter klausler 170e906159 [flang] Update DE/ALLOCATE statement runtime message processing
Make error message descriptors on runtime DE/ALLOCATE API calls constant.
Fix a bug in error message truncation/padding.

Differential Revision: https://reviews.llvm.org/D98551
2021-03-12 15:42:06 -08:00
Arnamoy Bhattacharyya a59665930b [flang][OpenMP][FIX] Fix function to check nesting level of current directive. 2021-03-12 15:01:47 -05:00
Peter Steinfeld 085d794c5f [flang] Make the symbol count used for collating symbols static
I changed the declaration of symbolCount_ in the type Symbols to be
static to avoid possible problems in the future when we might have
multiple objects of type Symbols.  Thanks to Peter for pointing out the
need for this change.

Differential Revision: https://reviews.llvm.org/D98357
2021-03-12 10:56:39 -08:00
Yashaswini 96716e6749 Add Semantic check for Flang OpenMP 4.5 - 2.15.3.6 Reduction clause
Implementation of Reduction clause restriction checks.

Files:

flang/lib/Semantics/check-directive-structure.h
flang/lib/Semantics/check-omp-structure.cpp
flang/lib/Semantics/check-omp-structure.h
flang/lib/Semantics/resolve-directives.cpp

Testcases:

flang/test/Semantics/omp-reduction01.f90
flang/test/Semantics/omp-reduction02.f90
flang/test/Semantics/omp-reduction03.f90
flang/test/Semantics/omp-reduction04.f90
flang/test/Semantics/omp-reduction05.f90
flang/test/Semantics/omp-reduction06.f90
flang/test/Semantics/omp-reduction07.f90
flang/test/Semantics/omp-reduction08.f90
flang/test/Semantics/omp-reduction09.f90
flang/test/Semantics/omp-reduction10.f90
flang/test/Semantics/omp-symbol08.f90

Reviewed by: Kiran Chandramohan @kiranchandramohan and Valentin Clement @clementval.

Differential Revision: https://reviews.llvm.org/D90697
2021-03-12 22:58:14 +05:30
River Riddle 31bb8efd69 [mlir][StorageUniquer] Properly call the destructor on non-trivially destructible storage instances
This allows for storage instances to store data that isn't uniqued in the context, or contain otherwise non-trivial logic, in the rare situations that they occur. Storage instances with trivial destructors will still have their destructor skipped. A consequence of this is that the storage instance definition must be visible from the place that registers the type.

Differential Revision: https://reviews.llvm.org/D98311
2021-03-11 11:35:32 -08:00
Peter Steinfeld 868187df21 [flang] Handle type-bound procedures with alternate returns
If you specify a type-bound procedure with an alternate return, there
will be no symbol associated with that dummy argument.  In such cases,
the compiler's list of dummy arguments will contain a nullptr.  In our
analysis of the PASS arguments of type-bound procedures, we were
assuming that all dummy arguments had non-null symbols associated with
them and were using that assumption to get the name of the dummy
argument.  This caused the compiler to try to dereference a nullptr.

I fixed this by explicitly checking for a nullptr and, in such cases, emitting
an error message.  I also added tests that contain type-bound procedures with
alternate returns in both legal and illegal constructs to ensure that semantic
analysis is working for them.

Differential Revision: https://reviews.llvm.org/D98430
2021-03-11 10:20:34 -08:00
Arnamoy Bhattacharyya e361afb6c5 [flang][OpenMP] Add semantic check for occurrence of multiple list items in aligned clause for simd directive
Reviewed By: kiranchandramohan, clementval

Differential Revision: https://reviews.llvm.org/D97964
2021-03-11 10:01:21 -05:00
Arnamoy Bhattacharyya 1fd4beecc8 [flang][driver] Add -fdebug-module-writer option 2021-03-11 08:04:37 -05:00
Leonard Chan baf637dcde Rename top-level LICENSE.txt files to LICENSE.TXT
This makes all the license filenames uniform across subprojects.

Differential Revision: https://reviews.llvm.org/D98380
2021-03-10 21:26:24 -08:00
Arnamoy Bhattacharyya 361e9bf97e [flang][driver] Formatting OpenMP sema check as per clang-format 2021-03-10 16:54:07 -05:00
Peter Steinfeld 40e261803b [flang] Fix call to CHECK() on overriding an erroneous type-bound procedure
You can define a base type with a type-bound procedure which is erroneously
missing a NOPASS attribute and then define another type that extends the base
type and overrides the erroneous procedure.  In this case, when we perform
semantic checking on the overriding procedure, we verify the "pass index" of
the overriding procedure.  The attempt to get the procedure's pass index fails
a call to CHECK().

I fixed this by calling SetError() on the symbol of the overridden procedure in
the base type.  Then, I check HasError() before executing the code that invokes
the failing call to CHECK().  I also added a test that will cause the compiler
to fail the call to CHECK() without this change.

Differential Revision: https://reviews.llvm.org/D98355
2021-03-10 09:38:29 -08:00
Andrzej Warzynski 547624af19 [flang][driver] Revert RUN-line change
In https://reviews.llvm.org/D98283, the RUN line in pre-fir-tree04.f90
was updated to use `%flang_fc1` instead of `%f18` (so that the test is
shared between the old and the new driver). Unfortunately, the new
driver does not know yet how to find standard intrinsics modules. As a
result, the test fails when `FLANG_BUILD_NEW_DRIVER` is set to On.

I'm restoring the original RUN line. This is rather straightforward, so
sending without a review. This should make Flang builders happy.
2021-03-10 16:58:24 +00:00
Eric Schweitz 987ee6e3cc [flang][fir] Upstream the pre-FIR tree changes.
The PFT has been updated to support Fortran 77.
clang-tidy cleanup.

Authors: Val Donaldson, Jean Perier, Eric Schweitz, et.al.

Differential Revision: https://reviews.llvm.org/D98283
2021-03-10 07:45:58 -08:00
Andrzej Warzynski 523d7bc6f4 [flang][driver] Add `-fdebug-dump-parsing-log`
This patch adds `-fdebug-dump-parsing-log` in the new driver. This option is
semantically identical to `-fdebug-instrumented-parse` in `f18` (the
former is added as an alias in `f18`).

As dumping the parsing log makes only sense for instrumented parses, we
set Fortran::parser::Options::instrumentedParse to `True` when
`-fdebug-dump-parsing-log` is used. This is consistent with `f18`.

To facilitate tweaking the configuration of the frontend based on the
action being requested, `setUpFrontendBasedOnAction` is introduced in
CompilerInvocation.cpp.

Differential Revision: https://reviews.llvm.org/D97457
2021-03-10 12:09:16 +00:00
Andrzej Warzynski 45da495f73 [flang][driver] Merge test/Driver and test/Flang-Driver directories
Until now we've been maintaining 2 test directories for Flang's drivers:
  * test/Driver for `f18` (the current driver)
  * test/Flang-Driver for `flang-new` (the new driver)
As we have started sharing tests between the drivers, this separation is
no longer required. This patch merges the two test directories. As
suggested in the review, moving forward we'll avoid having tests
specifically for the old driver.

A few notable changes:
  * Driver/version-test.f90 and Driver/no-files.f90 are deleted. The
  versions for the new driver are more robust, but tricky to share.
  * Driver/write-module.f90 is deleted in favour of
    Flang-Driver/write-module.f90 (see https://reviews.llvm.org/D97197
    for more context)

Differential Revision: https://reviews.llvm.org/D98257
2021-03-10 11:38:13 +00:00
Mehdi Amini 890afad954 Fix Flang build after MLIR API changes around `generatedTypeParser` 2021-03-09 23:19:30 +00:00
Peter Steinfeld 63200a058e [flang] Sort symbols by creation order
We have a "<" operator defined on the type semantics::Symbol that's based on
the symbols' locations in the cooked character stream.  This is potentially
problematic when comparing symbols from .mod files when the cooked character
streams themselves might be allocated to varying memory locations.

This change fixes that by using the order in which symbols are created as the
basis for the "<" operator.  Thanks to Tim and Peter for consultation on the
necessity of doing this and the idea for what to use as the basis of the sort.

This change in the "<" operator changed the expected results for three of the
tests.  I manually inspected the new results, and they look OK to me.  The
differences in data05.f90 and typeinfo01.f90 are entirely the order, offsets,
and sizes of the derived type components.  The changes in resolve102.f90 are
due to the new, different "<" operator used for sorting.

Differential Revision: https://reviews.llvm.org/D98225
2021-03-09 12:35:32 -08:00
Andrzej Warzynski b04fbc1913 [flang][driver] Refine tests for module search directories
This patch refactors include-module.f90:
  * rename the test file as use-module.f90 to better highlight which
  driver feature is being tested
  * move tests for diagnostics to use-module-error.f90 (it tests that
  `-J/-module-dir` can only be used once)
  * make sure that `f18` is tested when `FLANG_BUILD_NEW_DRIVER` is
  set to `Off`
  * add tests for when all module files are successfully discovered and
  loaded

With this patch, there should be a clear separation into 3 scenarios in
use-module.f90:
  * Everything is OK
  * One module file wasn't found (missing include path for
  basictestingmoduletwo.mod)
  * Two module files are found, but the test requires
  `basictestingmoduleone.mod` from both `Inputs` and `Inputs/module-dir`.
  Only the latter is found.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D97197
2021-03-09 15:26:48 +00:00
Asher Mancinelli 95193ac5ba [flang] update character tests to use gtest
Move character tests to gtest, according to reviews from revision
D97349. Create a new temporary directory parallel to old runtime
unittests directory to facilitate the transition. Once patches for all
tests have been accepted using GTest, the old directory may be removed.
The new directory is required because LLVM's CMake unit test
infrastructure requires that the test depends on all source files in
the `CMAKE_CURRENT_SOURCE_DIR` directory.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D97403
2021-03-09 08:31:20 +00:00
Peter Steinfeld cfd7d8123a [flang] Fix bad dereference of NULLIFY pointer object
When we have a subprogram that has been determined to contain errors, we do not
perform name resolution on its execution part.  In this case, if the subprogram
contains a NULLIFY statement, the parser::Name of a pointer object in a NULLIFY
statement will not have had name resolution performed on it.  Thus, its symbol
will not have been set.  Later, however, we do semantic checking on the NULLIFY
statement.  The code that did this assumed that the parser::Name of the
pointer object was non-null.

I fixed this by just removing the null pointer check for the "symbol" member of
the "parser::Name" of the pointer object when doing semantic checking for
NULLIFY statements.  I also added a test that will make the compiler crash
without this change.

Differential Revision: https://reviews.llvm.org/D98184
2021-03-08 15:01:36 -08:00
Yashaswini a89a3c2c7d Add Semantic check for Flang OpenMP 4.5 - 2.7.1 Do Loop restrictions for Threadprivate.
Implementation of Do loop threadprivate check.

Files:

resolve-directives.cpp

Testcases:

omp-do04-positivecase.f90
omp-do04.f90

Reviewed by: Kiran Chandramohan @kiranchandramohan

Differential Revision: https://reviews.llvm.org/D96686
2021-03-08 20:32:26 +05:30
Valentin Clement c3e5f504a0 [flang][fir] Add FIR Types parser diagnostic tests + cleanup
Add diagnostic tests for Types parsers and remove duplicated diagnostics handled by the MLIR
parser.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D97643
2021-03-05 14:58:44 -05:00
Valentin Clement d090f42778 [flang][fir] Add diagnostic tests for FIR ops verifier
Add diagnostic tests with fir-opt for the diagnostics emitted by the ops verifier

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D97996
2021-03-05 10:21:17 -05:00
Eric Schweitz 21c8e1b00a [flang][fir][NFC] Update comments. 2021-03-04 13:31:21 -08:00
Arnamoy Bhattacharyya ab971c29a5 [flang][driver] Add options for -fdefault* and -flarge-sizes
Add support for the following Fortran dialect options:
  - -default*
  - -flarge-sizes

It also adds two test cases:
  # For checking whether `flang-new` is passing options correctly to `flang-new -fc1`.
  # For checking if `fdefault-` arguments are processed properly.

Also moves the Dialect related option parsing to a dedicated function
and adds a member `defaultKinds()` to `CompilerInvocation`

Depends on: D96032

Differential Revision: https://reviews.llvm.org/D96344
2021-03-04 13:29:07 +00:00
Alex Zinenko 32c49c7d73 [mlir] ODS: change OpBuilderDAG to OpBuilder
We no longer have the non-DAG version.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D97856
2021-03-04 10:55:02 +01:00
Alex Zinenko 19db802e7b [mlir] make implementations of translation to LLVM IR interfaces private
There is no need for the interface implementations to be exposed, opaque
registration functions are sufficient for all users, similarly to passes.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D97852
2021-03-04 09:16:32 +01:00
River Riddle 64be3fcb7a Fix flang build after D97804 2021-03-03 15:07:03 -08:00
Peter Steinfeld 1c2935a772 [flang] Prohibit MODULE procedures in the global scope
We were allowing procedures with the MODULE prefix to be declared at the global
scope.  This is prohibited by C1547 and was causing an internal check of the
compiler to fail.

I fixed this by adding a check.  I also added a test that would trigger a crash
without this change.

Differential Revision: https://reviews.llvm.org/D97875
2021-03-03 11:50:50 -08:00
Peter Steinfeld 16005fd979 [flang] Detect circularly defined interfaces of procedures
It's possible to define a procedure whose interface depends on a procedure
which has an interface that depends on the original procedure.  Such a circular
definition was causing the compiler to fall into an infinite loop when
resolving the name of the second procedure.  It's also possible to create
circular dependency chains of more than two procedures.

I fixed this by adding the function HasCycle() to the class DeclarationVisitor
and calling it from DeclareProcEntity() to detect procedures with such
circularly defined interfaces.  I marked the associated symbols of such
procedures by calling SetError() on them.  When processing subsequent
procedures, I called HasError() before attempting to analyze their interfaces.
Unfortunately, this did not work.

With help from Tim, we determined that the SymbolSet used to track the
erroneous symbols was instantiated using a "<" operator which was defined using
the location of the name of the procedure.  But the location of the procedure
name was being changed by a call to ReplaceName() between the times that the
calls to SetError() and HasError() were made.  This caused HasError() to
incorrectly report that a symbol was not in the set of erroneous symbols.

I fixed this by changing SymbolSet to be an unordered set that uses the
contents of the name of the symbol as the basis for its hash function.  This
works because the contents of the name of the symbol is preserved by
ReplaceName() even though its location changes.

I also fixed the error message used when reporting recursively defined
dummy procedure arguments by removing extra apostrophes and sorting the
list of symbols.

I also added tests that will crash the compiler without this change.

Note that the "<" operator is used in other contexts, for example, in the map
of characterized procedures, maps of items in equivalence sets, maps of
structure constructor values, ...  All of these situations happen after name
resolution has been completed and all calls to ReplaceName() have already
happened and thus are not subject to the problem I ran into when ReplaceName()
was called when processing procedure entities.

Note also that the implementation of the "<" operator uses the relative
location in the cooked character stream as the basis of its implementation.
This is potentially problematic when symbols from diffent compilation units
(for example symbols originating in .mod files) are put into the same map since
their names will appear in two different source streams which may not be
allocated in the same relative positions in memory.  But I was unable to create
a test that caused a problem.  Using a direct comparison of the content of the
name of the symbol in the "<" operator has problems.  Symbols in enclosing or
parallel scopes can have the same name.  Also using the location of the symbol
in the cooked character stream has the advantage that it preserves the the
order of the symbols in a structure constructor constant, which makes matching
the values with the symbols relatively easy.

This patch supersedes D97749.

Differential Revision: https://reviews.llvm.org/D97774
2021-03-02 15:18:12 -08:00
Peter Steinfeld 95540f9dbf [flang] Detect circularly defined interfaces of procedures
It's possible to define a procedure whose interface depends on a procedure
which has an interface that depends on the original procedure.  Such a circular
definition was causing the compiler to fall into an infinite loop when
resolving the name of the second procedure.  It's also possible to create
circular dependency chains of more than two procedures.

I fixed this by adding the function HasCycle() to the class DeclarationVisitor
and calling it from DeclareProcEntity() to detect procedures with such
circularly defined interfaces.  I marked the associated symbols of such
procedures by calling SetError() on them.  When processing subsequent
procedures, I called HasError() before attempting to analyze their interfaces.
Unfortunately, this did not work.

With help from Tim, we determined that the SymbolSet used to track the
erroneous symbols was instantiated using a "<" operator which was defined using
the location of the name of the procedure.  But the location of the procedure
name was being changed by a call to ReplaceName() between the times that the
calls to SetError() and HasError() were made.  This caused HasError() to
incorrectly report that a symbol was not in the set of erroneous symbols.

I fixed this by changing SymbolSet to be an unordered set that uses the
contents of the name of the symbol as the basis for its hash function.  This
works because the contents of the name of the symbol is preserved by
ReplaceName() even though its location changes.

I also fixed the error message used when reporting recursively defined
dummy procedure arguments by removing extra apostrophes and sorting the
list of symbols.

I also added tests that will crash the compiler without this change.

Note that the "<" operator is used in other contexts, for example, in the map
of characterized procedures, maps of items in equivalence sets, maps of
structure constructor values, ...  All of these situations happen after name
resolution has been completed and all calls to ReplaceName() have already
happened and thus are not subject to the problem I ran into when ReplaceName()
was called when processing procedure entities.

Note also that the implementation of the "<" operator uses the relative
location in the cooked character stream as the basis of its implementation.
This is potentially problematic when symbols from diffent compilation units
(for example symbols originating in .mod files) are put into the same map since
their names will appear in two different source streams which may not be
allocated in the same relative positions in memory.  But I was unable to create
a test that caused a problem.  Using a direct comparison of the content of the
name of the symbol in the "<" operator has problems.  Symbols in enclosing or
parallel scopes can have the same name.  Also using the location of the symbol
in the cooked character stream has the advantage that it preserves the the
order of the symbols in a structure constructor constant, which makes matching
the values with the symbols relatively easy.

This patch supersedes D97749.

Differential Revision: https://reviews.llvm.org/D97774
2021-03-02 10:53:44 -08:00
Andrzej Warzynski bf4dbc4984 [flang][f18] Add missing line in help text (nfc) 2021-03-02 18:14:21 +00:00
Arnamoy Bhattacharyya 563ea45052 [flang][driver] Fix -fdefault* family bug
This patch provides a fix for the `fdefault-*` family in f18

(Please consult `D96344` for details)

Differential Revision: https://reviews.llvm.org/D97724
2021-03-02 17:37:02 +00:00
Andrzej Warzynski 1253009eb2 Revert "[flang] Detect circularly defined interfaces of procedures"
This reverts commit 93c5e6bb49.

This patch updates resolve102.f90 which is now failing in 6 out 8 of our
public buildbots:
  * http://lab.llvm.org:8011/#/builders/21/builds/9625
  * http://lab.llvm.org:8011/#/builders/134/builds/2395
  * http://lab.llvm.org:8011/#/builders/79/builds/6298
  * http://lab.llvm.org:8011/#/builders/66/builds/2084
  * http://lab.llvm.org:8011/#/builders/135/builds/2485
  * http://lab.llvm.org:8011/#/builders/32/builds/3551

Please see the following revisions for more context:
  * https://reviews.llvm.org/D97201
  * https://reviews.llvm.org/D97749
2021-03-02 14:55:41 +00:00
Peter Steinfeld 93c5e6bb49 [flang] Detect circularly defined interfaces of procedures
It's possible to define a procedure whose interface depends on a procedure
which has an interface that depends on the original procedure.  Such a circular
definition was causing the compiler to fall into an infinite loop when
resolving the name of the second procedure.  It's also possible to create
circular dependency chains of more than two procedures.

I fixed this by adding the function HasCycle() to the class DeclarationVisitor
and calling it from DeclareProcEntity() to detect procedures with such
circularly defined interfaces.  I marked the associated symbols of such
procedures by calling SetError() on them.  When processing subsequent
procedures, I called HasError() before attempting to analyze their interfaces.
Unfortunately, this did not work.

With help from Tim, we determined that the SymbolSet used to track the
erroneous symbols was instantiated using a "<" operator which was defined using
the location of the name of the procedure.  But the location of the procedure
name was being changed by a call to ReplaceName() between the times that the
calls to SetError() and HasError() were made.  This caused HasError() to
incorrectly report that a symbol was not in the set of erroneous symbols.

I fixed this by changing SymbolSet to be an unordered set that uses the
contents of the name of the symbol as the basis for its hash function.  This
works because the contents of the name of the symbol is preserved by
ReplaceName() even though its location changes.

I also fixed the error message used when reporting recursively defined dummy
procedure arguments.

I also added tests that will crash the compiler without this change.

Note that the "<" operator is used in other contexts, for example, in the map
of characterized procedures, maps of items in equivalence sets, maps of
structure constructor values, ...  All of these situations happen after name
resolution has been completed and all calls to ReplaceName() have already
happened and thus are not subject to the problem I ran into when ReplaceName()
was called when processing procedure entities.

Note also that the implementation of the "<" operator uses the relative
location in the cooked character stream as the basis of its implementation.
This is potentially problematic when symbols from diffent compilation units
(for example symbols originating in .mod files) are put into the same map since
their names will appear in two different source streams which may not be
allocated in the same relative positions in memory.  But I was unable to create
a test that caused a problem.  Using a direct comparison of the content of the
name of the symbol in the "<" operator has problems.  Symbols in enclosing or
parallel scopes can have the same name.  Also using the location of the symbol
in the cooked character stream has the advantage that it preserves the the
order of the symbols in a structure constructor constant, which makes matching
the values with the symbols relatively easy.

This change supersedes D97201.

Differential Revision: https://reviews.llvm.org/D97749
2021-03-01 19:07:03 -08:00
peter klausler 5a451a4289 [flang] Runtime: SCAN and VERIFY
Implement the related character intrinsic functions
SCAN and VERIFY.

Differential Revision: https://reviews.llvm.org/D97580
2021-03-01 12:15:29 -08:00
Praveen 75ef78ffee [Flang][OpenMP] Add semantic checks for OpenMP clauses.
Semantic checks for the following OpenMP 4.5 clauses.

1. 2.15.4.2 - Copyprivate clause
2. 2.15.3.4 - Firstprivate clause
3. 2.15.3.5 - Lastprivate clause

Add related test cases and resolve test cases marked as XFAIL.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D91920
2021-03-01 19:54:41 +05:30
Andrzej Warzynski 00e6513374 Revert "[flang] Detect circularly defined interfaces of procedures"
This reverts commit 07de0846a5.

The original patch has caused 6 out 8 of Flang's public buildbots to
fail. As I'm not sure what the fix should be, I'm reverting this for
now. Please see https://reviews.llvm.org/D97201 for more context and
discussion.
2021-03-01 10:34:49 +00:00
Eric Schweitz ac473bb2b2 [flang][fir] Upstream utility function valueHasFirAttribute()
This function will be used in subsequent upstreaming merges.

Author: Jean Perier

Differential Revision: https://reviews.llvm.org/D97502
2021-02-26 18:31:32 -08:00
Eric Schweitz 0b785a46b7 [flang][fir] Add remaining Ops. Updates to pre-existing Ops.
- add ops: rebox, insert_on_range, absent, is_present
  - embox, coordinate_of: replace old hand-written parser/pretty-printer with assembly format
  - remove dead floating point ops, since buitlins work for all types
  - update call op
  - update documentation
  - misc. NFC to formatting
  - add op round trip tests

Authors: Eric Schweitz, Jean Perier, Zachary Selk, Kiran Chandramohan, et.al.

Differential Revision: https://reviews.llvm.org/D97500
2021-02-26 17:21:35 -08:00
Eric Schweitz 5077d42cfa [flang][fir][NFC] Removes deprecated messages in builds. 2021-02-26 16:12:49 -08:00
Peter Steinfeld 07de0846a5 [flang] Detect circularly defined interfaces of procedures
It's possible to define a procedure whose interface depends on a procedure
which has an interface that depends on the original procedure.  Such a circular
definition was causing the compiler to fall into an infinite loop when
resolving the name of the second procedure.  It's also possible to create
circular dependency chains of more than two procedures.

I fixed this by adding the function HasCycle() to the class DeclarationVisitor
and calling it from DeclareProcEntity() to detect procedures with such
circularly defined interfaces.  I marked the associated symbols of such
procedures by calling SetError() on them.  When processing subsequent
procedures, I called HasError() before attempting to analyze their interfaces.
Unfortunately, this did not work.

With help from Tim, we determined that the SymbolSet used to track the
erroneous symbols was instantiated using a "<" operator which was
defined using the name of the procedure.  But the procedure name was
being changed by a call to ReplaceName() between the times that the
calls to SetError() and HasError() were made.  This caused HasError() to
incorrectly report that a symbol was not in the set of erroneous
symbols.  I fixed this by making SymbolSet be an ordered set, which does
not use the "<" operator.

I also added tests that will crash the compiler without this change.
And I fixed the formatting on an error message from a previous update.

Differential Revision: https://reviews.llvm.org/D97201
2021-02-26 14:44:35 -08:00
Eric Schweitz 67360decc3 [flang][fir] Add array value operations.
We lower expressions with rank > 0 to a set of high-level array operations.
These operations are then analyzed and refined to more primitve
operations in subsequent pass(es).

This patch upstreams these array operations and some other helper ops.

Authors: Eric Schweitz, Rajan Walia, Kiran Chandramohan, et.al.

https://github.com/flang-compiler/f18-llvm-project/pull/565

Differential Revision: https://reviews.llvm.org/D97421
2021-02-25 19:16:43 -08:00
Christian Sigg 8c074cb0b7 [mlir] Mark OpState::getAttrs() deprecated.
Fix call sites.

The method will be removed 2 weeks later.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D97464
2021-02-25 20:54:42 +01:00
Shao-Ce Sun ad14ccc8c2 [clang][flang] Improve the consistency of the code-base
In clang:
Replace argc_ with Argc
Replace argv_ with Argv
Replace argv with Args
In flang:
Replace argc_ with argc
Replace argv_ with argv
Replace argv with args

Reviewed By: awarzynski, aganea

Differential Revision: https://reviews.llvm.org/D97138
2021-02-25 21:25:43 +08:00
Andrzej Warzynski baebc1162f [clang][driver] Set the input type to Fortran when reading from stdin
This patch makes sure that for the following invocation of the new Flang
driver, clangDriver sets the input type to Fortran:
```
flang-new -E -
```
This change does not affect `clang`, i.e. for the following invocation
the input type is set to C:
```
clang -E -
```

This change leverages the fact that for `flang-new` the driver is in
Flang mode.

Differential Revision: https://reviews.llvm.org/D96777
2021-02-25 13:13:42 +00:00
Eric Schweitz 082ec3ab07 [flang][fir][NFC] Remove dead code.
This patch removes OpaqueAttr as it is no longer used.

Differential Revision: https://reviews.llvm.org/D97424
2021-02-24 17:31:23 -08:00
Valentin Clement 841f6995cd [flang][fir][NFC] Move remaining types to TableGen type definition
Move the remaing of FIR types to TableGen type definition. This follow suggestion in D96422.

Reviewed By: schweitz, jeanPerier, rriddle

Differential Revision: https://reviews.llvm.org/D96987
2021-02-24 20:23:31 -05:00
Jean Perier b146dfe527 [flang] add attribute to trim runtime implementation establish call
CFI allocatable attribute is needed so that the descriptor for the
result can be allocated/deallocated.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D97395
2021-02-24 18:53:55 +01:00
Eric Schweitz 3304061432 [flang][fir] Add zero_bits operation.
This patch adds the new zero_bits operation and upstrams other changes
including the following:

  - update tablegen syntax to newer forms
  - update memory effects annotations
  - update documentation [NFC]
  - other NFC, such as whitespace and formatting

Differential revision: https://reviews.llvm.org/D97331
2021-02-24 08:15:16 -08:00
Eric Schweitz 6740694742 [flang][fir][NFC] remove dead code
Removes unused function from FatalError.h.

Differential revision: https://reviews.llvm.org/D97328
2021-02-23 13:21:15 -08:00
Andrzej Warzynski 5e54bef4d2 [flang][test] Share all driver test dirs between `f18` and `flang-new`
Originally, when we added the new driver, we created dedicated test
directories for `flang-new`. This way we separated the tests for the
`throwaway` and the new driver.

As we are increasing test coverage and starting to share tests between
the two drivers, it makes sense to share all directories and instead
rely on:
```
! REQUIRES: new-flang-driver
```
to mark tests as exclusively for the new driver.

Differential Revision: https://reviews.llvm.org/D97207
2021-02-23 18:21:32 +00:00
Jean Perier 36ea1cac1a [flang][NFC] Add source line to lowering TODO messages
- Add a fatal error handler that can print a message with source location
  before aborting.
- Update TODO macro to take an mlir location argument and to use the
  newly introduced fatal error handler.
- Introduce TODO_NOLOC for the few places where no source location is
  easily accessible.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D97190
2021-02-23 09:01:35 +01:00
River Riddle 06e25d5645 [mlir][IR] Refactor the `getChecked` and `verifyConstructionInvariants` methods on Attributes/Types
`verifyConstructionInvariants` is intended to allow for verifying the invariants of an attribute/type on construction, and `getChecked` is intended to enable more graceful error handling aside from an assert. There are a few problems with the current implementation of these methods:
* `verifyConstructionInvariants` requires an mlir::Location for emitting errors, which is prohibitively costly in the situations that would most likely use them, e.g. the parser.
This creates an unfortunate code duplication between the verifier code and the parser code, given that the parser operates on llvm::SMLoc and it is an undesirable overhead to pre-emptively convert from that to an mlir::Location.
* `getChecked` effectively requires duplicating the definition of the `get` method, creating a quite clunky workflow due to the subtle different in its signature.

This revision aims to talk the above problems by refactoring the implementation to use a callback for error emission. Using a callback allows for deferring the costly part of error emission until it is actually necessary.

Due to the necessary signature change in each instance of these methods, this revision also takes this opportunity to cleanup the definition of these methods by:
* restructuring the signature of `getChecked` such that it can be generated from the same code block as the `get` method.
* renaming `verifyConstructionInvariants` to `verify` to match the naming scheme of the rest of the compiler.

Differential Revision: https://reviews.llvm.org/D97100
2021-02-22 17:37:49 -08:00
Renaud-K 7d1397f7ad Making FindCommonBlock a const member
https://reviews.llvm.org/D97093
2021-02-22 10:10:11 -08:00
Tim Keith 8720ec6b9a [flang] Add -J and -module-dir to f18 driver
Add -J to the f18 driver for compatibility with gfortran.
Add -module-dir for compatibility with the new flang driver.

They both set the output directory for .mod files and add the
directory to the search list. -module still only does the former.

Clean up the new driver test to match.

Differential Revision: https://reviews.llvm.org/D97164
2021-02-22 09:03:31 -08:00
Andrzej Warzynski d81f633fe2 [flang][driver] Add -Xflang and make -test-io a frontend-only flang
This patch adds support for `-Xflang` in `flang-new`. The semantics are
identical to `-Xclang`.

With the addition of `-Xflang`, we can modify `-test-io` to be a
compiler-frontend only flag. This makes more sense, this flag is:
  * very frontend specific
  * to be used for development and testing only
  * not to be exposed to the end user
Originally we added it to the compiler driver, `flang-new`, in order to
facilitate testing. With `-Xflang` this is no longer needed. Tests are
updated accordingly.

Differential Revision: https://reviews.llvm.org/D96864
2021-02-22 10:11:43 +00:00
Eric Schweitz c68d2895a1 [flang][fir] Update flang test tool support classes.
This updates the various classes that support the compliation of
Fortran. These classes are shared by the test tools.

Authors: Eric Schweitz, Sameeran Joshi, et.al.

Differential Revision: https://reviews.llvm.org/D97073
2021-02-19 16:02:39 -08:00
Eric Schweitz a88991d782 [flang][fir][NFC] run clang-format
cleanup post-merge
2021-02-19 12:07:13 -08:00
Faris Rehman 529f71811b [flang][driver] Add debug measure-parse-tree and pre-fir-tree options
Add the following options:
* -fdebug-measure-parse-tree
* -fdebug-pre-fir-tree

Summary of changes:
- Add 2 new frontend actions: DebugMeasureParseTreeAction and DebugPreFIRTreeAction
- Add MeasurementVisitor to FrontendActions.h
- Make reportFatalSemanticErrors return true if there are any fatal errors
- Port most of the `-fdebug-pre-fir-tree` tests to use the new driver if built, otherwise use f18.

Differential Revision: https://reviews.llvm.org/D96884
2021-02-19 11:27:54 +00:00
peter klausler ea2ff54ccc [flang] Extension: forward refs to dummy args under IMPLICIT NONE
Most Fortran compilers accept the following benign extension,
and it appears in some applications:

  SUBROUTINE FOO(A,N)
    IMPLICIT NONE
    REAL A(N) ! N is used before being typed
    INTEGER N
  END

Allow it in f18 only for default integer scalar dummy arguments.

Differential Revesion: https://reviews.llvm.org/D96982
2021-02-18 13:14:34 -08:00
Andrzej Warzynski c0deb81cd1 [flang][driver] Add missing dependency (nfc)
These dependencies were introduced via the `ParseTreeDumper` API in:
  * https://reviews.llvm.org/D96716
They manifested themselves in buildbot builders that set
`BUILD_SHARED_LIBS` to `On`.
2021-02-18 17:16:57 +00:00
Faris Rehman 4bd08dab5f [flang][driver] Add debug dump options
Add the following options:
* -fdebug-dump-symbols
* -fdebug-dump-parse-tree
* -fdebug-dump-provenance

Summary of changes:
- Add 3 new frontend actions: DebugDumpSymbolsAction, DebugDumpParseTreeAction and DebugDumpProvenanceAction
- Add a unique pointer to the Semantics instance created in PrescanAndSemaAction
- Move fatal semantic error reporting to its own method, FrontendActions#reportFatalSemanticErrors
- Port most tests using `-fdebug-dump-symbols` and `-fdebug-dump-parse-tree` to the new driver if built, otherwise default to f18

Differential Revision: https://reviews.llvm.org/D96716
2021-02-18 11:33:24 +00:00
Mehdi Chinoune 8cfe9c02a0 [Flang] Fix compilation on MinGW-w64
Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D94707
2021-02-17 21:53:48 -06:00
Eric Schweitz fd3297dc32 [flang][fir][NFC] clang-tidy change. Add include.
Differential Revision: https://reviews.llvm.org/D96912
2021-02-17 17:52:04 -08:00
Eric Schweitz 930150781d [flang][fir][NFC] Merge tablegen files.
Differential Revision: https://reviews.llvm.org/D96908
2021-02-17 17:51:14 -08:00
Eric Schweitz 0d4534237d [flang][fir][NFC] clang-tidy change
Differential Revision: https://reviews.llvm.org/D96911
2021-02-17 15:41:20 -08:00
peter klausler b82a8c3f23 [flang] Warn about useless explicit typing of intrinsics
Fortran 2018 explicitly permits an ignored type declaration
for the result of a generic intrinsic function.  See the comment
added to Semantics/expression.cpp for an explanation of why this
is somewhat dangerous and worthy of a warning.

Differential Revision: https://reviews.llvm.org/D96879
2021-02-17 13:13:59 -08:00
peter klausler 452d7ebc09 [flang] Ensure that intrinsic procedures are PURE &/or ELEMENTAL
The intrinsic procedure table properly classify the various
intrinsics, but the PURE and ELEMENTAL attributes that these
classifications imply don't always make it to the utility
predicates that test symbols for them, leading to spurious
error messages in some contexts.  So set those attribute flags
as appropriate in name resolution, using a new function to
isolate the tests.

An alternate solution, in which the predicates would query
the intrinsic procedure table for these attributes on demand,
was something I also tried, so that this information could
come directly from an authoritative source; but it would have
required references to the intrinsic table to be passed along
on too many seemingly unrelated APIs and ended up looking messy.

Several symbol table tests needed to have their expected outputs
augmented with the PURE and ELEMENTAL flags.  Some bogus messages
that were flagged as such in test/Semantics/doconcurrent01.f90 were
removed, since they are now correctly not emitted.

Differential Revision: https://reviews.llvm.org/D96878
2021-02-17 11:31:33 -08:00
Valentin Clement 5ef029d267 [flang][fir][NFC] Move ComplexType to TableGen type definition
This patch is a follow up of D96422 and move ComplexType to
TableGen.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D96575
2021-02-16 21:52:38 -05:00
Valentin Clement 61b8a3e7c5 [flang][fir][NFC] Move BoxProcType to TableGen type definition
This patch is a follow up of D96422 and move BoxProcType to TableGen.

Reviewed By: schweitz, mehdi_amini

Differential Revision: https://reviews.llvm.org/D96514
2021-02-16 21:27:30 -05:00
Valentin Clement 209bc67b78 [flang][fir][NFC] Move CharacterType and BoxCharType to TableGen type definition
This patch is a follow up of D96422 and move CharacterType and BoxCharType to
TableGen.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D96446
2021-02-16 21:15:25 -05:00
Peter Steinfeld 77dc203cd0 [flang] Detect circularly defined procedures
It's possible to define a procedure that has a procedure dummy argument which
names the procedure that contains it.  This was causing the compiler to fall
into an infinite loop when characterizing a call to the procedure.

Following a suggestion from Peter, I fixed this be maintaining a set of
procedure symbols that had already been seen while characterizing a procedure.
This required passing a new parameter to the functions that characterized a
Procedure, a DummyArgument, and a DummyProcedure.

I also added several tests that will crash the compiler without this change.

Differential Revision: https://reviews.llvm.org/D96631
2021-02-16 14:40:35 -08:00
Valentin Clement b86dbe0c23 Fix flang after D76342
Fix Flang build after addition of a new OpenMP clauses for a clang patch (D76342).
Flang is using TableGen to generation the declaration of clause checks and the new clause
was missing a definiton.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D96808
2021-02-16 15:37:58 -05:00
clementval 8260232cdd [flang][fir] Add fir-opt tool
This patch introduce the fir-opt tool. Similar to mlir-opt for FIR.
It will be used in following patches to test fir opt and round-trip.

Reviewed By: schweitz, mehdi_amini

Differential Revision: https://reviews.llvm.org/D96535
2021-02-16 11:48:40 -05:00
Faris Rehman 10826ea7b1 [flang][driver] Add extension options and -finput-charset
Add the following options:
* -fimplicit-none and -fno-implicit-none
* -fbackslash and -fno-backslash
* -flogical-abbreviations and -fno-logical-abbreviations
* -fxor-operator and -fno-xor-operator
* -falternative-parameter-statement
* -finput-charset=<value>

Summary of changes:
- Enable extensions in CompilerInvocation#ParseFrontendArgs
- Add encoding_ to Fortran::frontend::FrontendOptions
- Add encoding to Fortran::parser::Options

Differential Revision: https://reviews.llvm.org/D96407
2021-02-16 11:27:06 +00:00
Andrzej Warzynski df22133a8a [flang][driver] Remove unused code (nfc) 2021-02-16 10:00:41 +00:00
Andrzej Warzynski 96d229c9ab [flang][driver] Add options for unparsing
This patch adds the following compiler frontend driver options:
  * -fdebug-unparse (f18 spelling: -funparse)
  * -fdebug-unparse-with-symbols (f18 spelling: -funparse-with-symbols)
The new driver will only accept the new spelling. `f18` will accept both
the original and the new spelling.

A new base class for frontend actions is added: `PrescanAndSemaAction`.
This is added to reduce code duplication that otherwise these new
options would lead to. Implementation from
  * `ParseSyntaxOnlyAction::ExecutionAction`
is moved to:
  * `PrescanAndSemaAction::BeginSourceFileAction`
This implementation is now shared between:
  * PrescanAndSemaAction
  * ParseSyntaxOnlyAction
  * DebugUnparseAction
  * DebugUnparseWithSymbolsAction

All tests that don't require other yet unimplemented options are
updated. This way `flang-new -fc1` is used instead of `f18` when
`FLANG_BUILD_NEW_DRIVER` is set to `On`. In order to facilitate this,
`%flang_fc1` is added in the LIT configuration (lit.cfg.py).

`asFortran` from f18.cpp is duplicated as `getBasicAsFortran` in
FrontendOptions.cpp. At this stage it's hard to find a good place to
share this method. I suggest that we revisit this once a switch from
`f18` to `flang-new` is complete.

Differential Revision: https://reviews.llvm.org/D96483
2021-02-16 09:32:51 +00:00
Andrzej Warzynski 548549e88a [flang][f18] Make -fdebug-dump-{symbols|parse-tree} imply -fsyntax-only
The following _action_ options are always used with `-fsyntax-only`
(also an _action_ option):
  * -fdebug-dump-symbols
  * -fdebug-dump-parse-tree
This patch makes the above options imply `-fsyntax-only`.

From the perspective of `f18` this change saves typing and is otherwise
a non-functional change. But it will simplify things in the new driver,
`flang-new`, in which only the last action option is taken into account
and executed. In other words, the following would only run
`-fsyntax-only`:
```
flang-new -fdebug-dump-symbols -fsyntax-only <input>
```
whereas this would only run `-fdebug-dump-symbols`:
```
flang-new -fsyntax-only -fdebug-dump-symbols <input>
```

Differential Revision: https://reviews.llvm.org/D96528
2021-02-16 09:22:32 +00:00
Yashaswini 20e3a6cb62 Add Semantic check for Flang OpenMP 4.5 - 2.7.1 Do Loop restrictions.
Implementation of Do loop iteration variable check, Do while loop check, Do loop cycle restrictions.
Also to check whether the ordered clause is present on the loop construct if any ordered region ever
 binds to a loop region arising from the loop construct.

Files:

check-omp-structure.h
check-omp-structure.cpp
resolve-directives.cpp

Testcases:

omp-do06-positivecases.f90
omp-do06.f90
omp-do08.f90
omp-do09.f90
omp-do10.f90
omp-do11.f90
omp-do12.f90
omp-do13.f90
omp-do14.f90
omp-do15.f90
omp-do16.f90
omp-do17.f90

Reviewed by: Kiran Chandramohan @kiranchandramohan , Valentin Clement @clementval

Differential Revision: https://reviews.llvm.org/D92732
2021-02-15 18:39:14 +05:30
clementval af186e9372 Revert "[flang][fir] Add fir-opt tool"
This reverts commit df1eeaa7b4.

Buildbot failure.
2021-02-12 22:27:48 -05:00
Valentin Clement 8c1b63307f [flang][fir][NFC] Move FieldType to TableGen type definition
This patch is a follow up of D96422 and move ComplexType to TableGen.

Reviewed By: schweitz, mehdi_amini

Differential Revision: https://reviews.llvm.org/D96610
2021-02-12 22:23:05 -05:00
Valentin Clement df1eeaa7b4 [flang][fir] Add fir-opt tool
This patch introduce the fir-opt tool. Similar to mlir-opt for FIR.
It will be used in following patches to test fir opt and round-trip.

Reviewed By: schweitz, mehdi_amini

Differential Revision: https://reviews.llvm.org/D96535
2021-02-12 22:20:38 -05:00
Eric Schweitz 8fc219d58f [flang][fir][NFC] Minor format changes to FIROps.td.
Differential Revision: https://reviews.llvm.org/D96633
2021-02-12 15:20:18 -08:00
Eric Schweitz f800a9bd42 [flang][fir][NFC] Move code from FIRDialect.h into a new header.
Differential Revision: https://reviews.llvm.org/D96630
2021-02-12 15:15:46 -08:00
Valentin Clement a48bee2294 [flang][fir][NFC] Move BoxType to TableGen type definition
This patch is a follow up of D96422 and move BoxType to TableGen.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D96476
2021-02-11 18:10:22 -05:00
Eric Schweitz f47d7c145b [flang][fir][NFC] Rename WhereOp to IfOp. 2021-02-11 11:33:37 -08:00
peter klausler 8880a63a15 [flang] Don't perform macro replacement unless *.F, *.F90, &c.
Avoid spurious and confusing macro replacements from things like
-DPIC on Fortran source files whose suffixes indicate that preprocessing
is not expected.

Add gfortran-like "-cpp" and "-nocpp" flags to f18 to force predefinition
of macros independent of the source file suffix.

Differential Revision: https://reviews.llvm.org/D96464
2021-02-11 11:25:41 -08:00
Eric Schweitz 4dc87d1010 [flang][fir] Update the kind mapping class.
The kind mapper provides a portable mechanism to map Fortran type KIND values
independent of the front-end to their corresponding MLIR and LLVM types.

Differential Revision: https://reviews.llvm.org/D96362
2021-02-11 11:11:52 -08:00
peter klausler 0bfa4ac6c6 [flang] Improve "Error reading module file" error message
Instead of using a message attachment with further details,
emit the details as part of a single message.

Differential Revision: https://reviews.llvm.org/D96465
2021-02-11 11:08:12 -08:00
Leandro Vaz 204360fd71 [flang] Fix typo in FlangConfig.cmake.in.
`find_package(Flang)` does not work as there is a missing `@` in the
FlangConfig.cmake.in file. This patch fixes the issue.

Reviewed By: thopre

Differential Revision: https://reviews.llvm.org/D96484
2021-02-11 18:09:47 +00:00
Sourabh Singh Tomar 6a7deff58e [flang] Remove `LINK_WITH_FIR` cmake switch
Most components required for this are already there.

Build and Testing clean.
ninja check-flang

Reviewed By: clementval, tskeith

Differential Revision: https://reviews.llvm.org/D96411
2021-02-11 22:52:13 +05:30
clementval 661f9e2a92 Revert "[flang][fir][NFC] Move BoxType to TableGen type definition"
This reverts commit d96bb48f78.
2021-02-11 11:36:35 -05:00
Valentin Clement d96bb48f78 [flang][fir][NFC] Move BoxType to TableGen type definition
This patch is a follow up of D96422 and move BoxType to TableGen.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D96476
2021-02-11 11:09:52 -05:00
Andrzej Warzynski 0feff71eab [flang][driver] Move standard macro predefs to a dedicated method (nfc)
This patch just addresses one of the outstanding TODOs. More
specifically, it moves all the outstanding standard macro predefinitions
from `SetDefaultFortranOpts` to `setDefaultPredefinitions`. This
dedicated method for standard macro predefs was introduced in:
  * https://reviews.llvm.org/D96032
2021-02-11 11:42:57 +00:00
Valentin Clement 5ad416ca78 [flang][fir] Fix Werror build failure after D96422 2021-02-10 21:44:16 -05:00
Valentin Clement 550f251e47 [flang][fir][NFC] Move ShapeShiftType to TableGen type definition
This patch is a follow up of D96422 and move the ShapeShiftType to
TableGen.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D96442
2021-02-10 20:32:28 -05:00
peter klausler 9895ba86a8 [flang] Cope with specific procedures with same name as generic
When accessing a specific procedure of a USE-associated generic
interface, we need to allow for the case in which that specific
procedure has the same name as the generic when testing for
its availability in the current scope.

Differential Revision: https://reviews.llvm.org/D96467
2021-02-10 17:30:22 -08:00
peter klausler 47b97d4bfb [flang] Manage per-specification-part state better
Some state in name resolution is stored in the DeclarationVisitor
instance and processed at the end of the specification part.
This state needs to accommodate nested specification parts, namely
the ones that can be nested in a subroutine or function interface
body.

Differential Revision: https://reviews.llvm.org/D96466
2021-02-10 17:23:53 -08:00
Valentin Clement edd365c709 [flang][fir][NFC] Move ShapeType to TableGen type definition
This is the first patch of a serie to move FIR types to TableGen format as suggested in D96172.
This patch is setting up the files for FIR types and move the ShapeType to TableGen.

As discussed with @schweitz, I'm taking over this task to help the FIR upstreaming effort.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D96422
2021-02-10 19:48:23 -05:00
Andrzej Warzynski cf471632b1 [flang][driver] Add missing dependency in unit tests (nfc)
The following patch revealed a missing dependency in the CMake script
for Flang driver unit tests:
  * https://reviews.llvm.org/D96032
The following buildbots are failing ("BUILD_SHARED_LIBS" is set to ON):
  * http://lab.llvm.org:8011/#/builders/134/builds/1840
  * http://lab.llvm.org:8011/#/builders/66/builds/1785
  * http://lab.llvm.org:8011/#/builders/33/builds/2436

This patch adds the missing dependency.

From what I can see, FortranSemantics and FortranParser are only
indirect dependencies of FlangFrontendTests and IIUC shouldn't be
required here. This is something that we should revisit at some point.
In this patch I focus on fixing the build.
2021-02-10 13:31:49 +00:00
Alex Zinenko 2996a8d675 [mlir] avoid exposing mutable DialectRegistry from MLIRContext
MLIRContext allows its users to access directly to the DialectRegistry it
contains. While sometimes useful for registering additional dialects on an
already existing context, this breaks the encapsulation by essentially giving
raw accesses to a part of the context's internal state. Remove this mutable
access and instead provide a method to append a given DialectRegistry to the
one already contained in the context. Also provide a shortcut mechanism to
construct a context from an already existing registry, which seems to be a
common use case in the wild. Keep read-only access to the registry contained in
the context in case it needs to be copied or used for constructing another
context.

With this change, DialectRegistry is no longer concerned with loading the
dialects and deciding whether to invoke delayed interface registration. Loading
is concentrated in the MLIRContext, and the functionality of the registry
better reflects its name.

Depends On D96137

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D96331
2021-02-10 12:07:34 +01:00
Faris Rehman 6d48a1a53f [flang][driver] Add support for -fopenmp and -fopenacc
Add support for the following options:
* -fopenmp
* -fopenacc

Update OpenMP and OpenACC semantics tests to use the new driver if it is built, otherwise use f18.
OpenMP tests that include `use omp_lib` or run `test_symbols.sh` have not been updated as they require options `-intrinsic-module-directory` and `-funparse-with-symbols` which are currently not implemented in the new driver.
Similarly OpenACC tests that run `test_symbols.sh` have not been updated.

This patch also moves semanticsContext to CompilerInvocation and creates it in CompilerInvocation#setSemanticsOpts so that the semantics context can use Fortran::parser::Options#features.

Summary of changes:
- Move semanticsContext to CompilerInvocation.h
- Update OpenMP and OpenACC semantics tests that do not rely on `-intrinsic-module-directory` and `-funparse-with-symbols` to use %flang

Differential Revision: https://reviews.llvm.org/D96032
2021-02-10 09:59:35 +00:00
Eric Schweitz e090182fe1 [flang][fir] Updates to internal name uniquer.
https://github.com/flang-compiler/f18-llvm-project/pull/474

Differential Revision: https://reviews.llvm.org/D96361
2021-02-09 14:43:33 -08:00
Eric Schweitz 399c3d5b29 [flang][fir] Add shape, shape_shift, and slice types.
Adding the FIR types used to describe the Fortran semantics of indexing
FIR arrays.

https://github.com/flang-compiler/f18-llvm-project/pull/267

Differential Revision: https://reviews.llvm.org/D96172
2021-02-09 08:55:47 -08:00
Eric Schweitz 2cd0a113df [flang][fir] Add OpaqueAttr.
Add the opaque attribute class used in flang.

https://github.com/flang-compiler/f18-llvm-project/pull/402

Differential Revision: https://reviews.llvm.org/D96293
2021-02-08 16:02:22 -08:00
Eric Schweitz e892109c3e [flang][NFC] Add comment. 2021-02-08 13:49:16 -08:00
Eric Schweitz bdf3ad582e [flang][NFC] Update comments. 2021-02-08 12:11:49 -08:00
Eric Schweitz 7e20a41348 [flang][fir] Update FIR's character type.
Upstream the changes made to the !fir.char type.

https://github.com/flang-compiler/f18-llvm-project/pull/269
https://github.com/flang-compiler/f18-llvm-project/pull/557

Author: Eric Schweitz, Jean Perier

Differention Revision: https://reviews.llvm.org/D96183
2021-02-08 08:20:04 -08:00
Tres Popp c2c83e97c3 Revert "Revert "Reorder MLIRContext location in BuiltinAttributes.h""
This reverts commit 511dd4f438 along with
a couple fixes.

Original message:
Now the context is the first, rather than the last input.

This better matches the rest of the infrastructure and makes
it easier to move these types to being declaratively specified.

Phabricator: https://reviews.llvm.org/D96111
2021-02-08 10:39:58 +01:00
Tres Popp 511dd4f438 Revert "Reorder MLIRContext location in BuiltinAttributes.h"
This reverts commit 7827753f98.
2021-02-08 09:32:42 +01:00
Tres Popp 7827753f98 Reorder MLIRContext location in BuiltinAttributes.h
Now the context is the first, rather than the last input.

This better matches the rest of the infrastructure and makes
it easier to move these types to being declaratively specified.

Differential Revision: https://reviews.llvm.org/D96111
2021-02-08 09:28:09 +01:00
Eric Schweitz f6342806db [flang][fir] Add FIR's vector type.
This patch adds support for `!fir.vector`, a rank one, constant length
data type.

https://github.com/flang-compiler/f18-llvm-project/pull/413

Differential Revision: https://reviews.llvm.org/D96162
2021-02-05 12:44:19 -08:00
Eric Schweitz a1a1d338e9 [flang][NFC] Make KindTy consistent and consistently used.
Differential Revision: https://reviews.llvm.org/D96154
2021-02-05 10:54:58 -08:00
Eric Schweitz ea35745610 [flang][NFC] Update comments.
Differential Revision: https://reviews.llvm.org/D96152
2021-02-05 10:54:58 -08:00
Sourabh Singh Tomar bca0619a1b [flang] Adapt mlir based error status handling in `tco` tool
Earlier scheme was using negative integers for communicating error status,
switch to canonical MLIR style.

f18 commit authored by @schweitz:
c1af08d6e7

Reviewed By: mehdi_amini, clementval, svedanayagam

Differential Revision: https://reviews.llvm.org/D96068
2021-02-05 11:07:10 +05:30
Eric Schweitz 807a8daf1b fix -Werror build issue. 2021-02-04 16:58:33 -08:00
Eric Schweitz 9673a00995 [flang] Remove dims type and gendims op.
These are no longer part of FIR.
https://github.com/flang-compiler/f18-llvm-project/pull/267

Differential Revision: https://reviews.llvm.org/D96077
2021-02-04 14:37:07 -08:00
Mehdi Chinoune bdb40dd14e [flang][msvc] Reapply "Explicitly reference "this" inside closure"
Reapply {D88052}

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D96066
2021-02-04 16:33:51 -06:00
Eric Schweitz ae7e84285f [flang][NFC] Rename IntType to IntegerType.
https://github.com/flang-compiler/f18-llvm-project/pull/413

Differential Revision: https://reviews.llvm.org/D96072
2021-02-04 12:48:03 -08:00
Andrzej Warzynski ba000628bd [flang][driver] Fix reading from stdin when using `-test-io`
This patch adds logic in the InputOutputTestAction frontend action for
reading input from stdin. Without this patch the following fails:
```
    flang-new -fc1 -test-io -
```

The implementation of `InputOutputTestAction` is cleaned-up and a test
for reading from stdin is added.

Note that there's a difference between `-test-io` and e.g. `-E` in terms
of file I/O. The frontend action for the former handles all file I/O on
it's own. Conversely, the action corresponding to -E relies on the
prescanner API to handle this.

Currently we can't test reading from stdin for `flang-new -`. In this
case `libclangDriver` assumes `-x -c`. This in turn leads to `flang-new
-cc1`, which is not supported.
2021-02-04 16:51:59 +00:00
Arnamoy Bhattacharyya 985a42fdf8 [flang][driver] Add support for `-J/-module-dir`
Add support for option -J/-module-dir in the new Flang driver.  This
will allow for including module files in other directories, as the
default search path is currently the working folder. This also provides
an option of storing the output module in the specified folder.

Differential Revision: https://reviews.llvm.org/D95448
2021-02-04 16:31:40 +00:00
Andrzej Warzynski d06e94031b [flang][driver] Add PrescanAction frontend action (nfc)
This new action encapsulates all actions that require the prescanner to
be run before proceeding with other processing. By adding this new
action, we are better equipped to control which actions _do_ run the
prescanner and which _do not_.

The following actions that require the prescanner are refactored to
inherit from `PrescanAction`:
  * `PrintPreprocessedAction`
  * `ParseSyntaxOnlyAction` .

New virtual method is introduced to facilitate all this:
  * `BeginSourceFileAction`
Like in Clang, this method is run inside `BeginSourceFile`. In other
words, it is invoked before `ExecuteAction` for the corresponding
frontend action is run. This method allows us to:
  * carry out any processing that is always required by the action (e.g.
    run the prescanner)
  * fine tune the settings/options on a file-by-file basis (e.g. to
    decide between fixed-form and free-form based on file extension)

This patch implements non-functional-changes.

Reviewed By: FarisRehman

Differential Revision: https://reviews.llvm.org/D95464
2021-02-04 14:23:33 +00:00
Faris Rehman 3a1513c142 [flang][driver] Add forced form flags and -ffixed-line-length
Add support for the following layout options:
* -ffree-form
* -ffixed-form
- -ffixed-line-length=n (alias -ffixed-line-length-n)
Additionally remove options `-fno-free-form` and `-fno-fixed-form` as they were initially added to forward to gfortran but gfortran does not support these flags.

This patch adds the flag FlangOnlyOption to the existing options `-ffixed-form`, `-ffree-form` and `-ffree-line-length-` in Options.td. As of commit 6a75496836, these flags are not currently forwarded to gfortran anyway.

The default fixed line length in FrontendOptions is 72, based off the current default in Fortran::parser::Options. The line length cannot be set to a negative integer, or a positive integer less than 7 excluding 0, consistent with the behaviour of gfortran.

This patch does not add `-ffree-line-length-n` as Fortran::parser::Options does not have a variable for free form columns.
Whilst the `fixedFormColumns` variable is used in f18 for `-ffree-line-length-n`, f18 only allows `-ffree-line-length-none`/`-ffree-line-length-0` and not a user-specified value. `fixedFormcolumns` cannot be used in the new driver as it is ignored in the frontend when dealing with free form files.

Summary of changes:
- Remove -fno-fixed-form and -fno-free-form from Options.td
- Make -ffixed-form, -ffree-form and -ffree-line-length-n FlangOnlyOption in Options.td
- Create AddFortranDialectOptions method in Flang.cpp
- Create FortranForm enum in FrontendOptions.h
- Add fortranForm_ and fixedFormColumns_ to Fortran::frontend::FrontendOptions
- Update fixed-form-test.f so that it guarantees that it fails when forced as a free form file to better facilitate testing.

Differential Revision: https://reviews.llvm.org/D95460
2021-02-04 12:24:15 +00:00
Peter Steinfeld 2018dafce5 [flang] Fix calls to LBOUND() intrinsic for arrays with lower bounds not 1
Constant folding for calls to LBOUND() was not working when the lower bound of
a constant array was not 1.

I fixed this and re-enabled the test in Evaluate/folding16.f90 that previously
was silently failing.  I slightly changed the test to parenthesize the first
argument to exercise all of the new code.

Differential Revision: https://reviews.llvm.org/D95894
2021-02-03 10:53:32 -08:00
Sourabh Singh Tomar f2879559ac [flang] Enable FIR types and Dialect round trip tests
Reviewed By: schweitz, mehdi_amini

Differential Revision: https://reviews.llvm.org/D95958
2021-02-03 23:46:55 +05:30
Sourabh Singh Tomar 4463e39d91 [flang][NFCI] Relpace `LoopOp` Op with `DoLoopOp` Op in FIR Dialect
Part of upstreaming effort,
PR: https://github.com/flang-compiler/f18-llvm-project/pull/296

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D95950
2021-02-03 22:57:49 +05:30
peter klausler 34eb0adaa9 [flang] Add -fsyntax-only to f18; retain -fparse-only synonym
Now that semantics is working, the standard -fsyntax-only option of
GNU and Clang should be used as the name of the option that causes
f18 to just run the front-end.  Support both options in f18, silently
accepting the old option as a synonym for the new one (as
preferred by the code owner), and replace all instances of the
old -fparse-only option with -fsyntax-only throughout the source base.

Differential Revision: https://reviews.llvm.org/D95887
2021-02-03 09:01:39 -08:00
Praveen 5bc6e75386 [Flang][OpenMP] Add semantic checks for invalid branches into or out of OpenMP constructs
OpenMP 4.5 - Check invalid branches into OpenMP strucutred blocks.
             Check invalid branches leaving OpenMP structured blocks.

Test cases : omp-do-cycle.f90, omp-invalid-branch.f90

Resolve related test cases marked as XFAIL

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D92735
2021-02-03 16:09:34 +05:30
peter klausler efc5926c20 [flang] Add TypeAndShape::MeasureElementSizeInBytes()
Split up MeasureSizeInBytes() so that array element sizes can be
calculated accurately; use the new API in some places where
DynamicType::MeasureSizeInBytes() was being used but the new
API performs better due to TypeAndShape having precise CHARACTER
length information.

Differential Revision: https://reviews.llvm.org/D95897
2021-02-02 15:15:20 -08:00
Eric Schweitz e2bd29a0d6 [flang][NFC] Update the CG rewrite pass.
Add description and dependencies.

Differential Revision: https://reviews.llvm.org/D95888
2021-02-02 11:56:21 -08:00
Eric Schweitz d395007216 [flang][NFC] Update #include.
Differential Revision: https://reviews.llvm.org/D95882
2021-02-02 11:52:55 -08:00
peter klausler aa39ddd0a3 [flang] Implement IEEE_SUPPORT_xxx inquiry functions
Implement IEEE_SUPPORT_DATATYPE() and other inquiry intrinisic
functions from the intrinsic module IEEE_ARITHMETIC, folding all of
their results to .TRUE.

Differential Revision: https://reviews.llvm.org/D95830
2021-02-02 11:38:19 -08:00
peter klausler dc6fadf708 [flang] Detect UBOUND() error on assumed-size array
UBOUND() is not allowed on the last dimension of an
assumed-size array dummy argument.

Differential Revision: https://reviews.llvm.org/D95831
2021-02-02 11:37:44 -08:00
Eric Schweitz af43440bd2 [flang][NFC] Update #include and comment.
Differential Revision: https://reviews.llvm.org/D95828
2021-02-02 08:49:04 -08:00
Andrzej Warzynski 760e6c4ce5 [flang][driver] Disallow non-existent input files in the frontend driver
This patch adds a check that verifies that the input file used when
calling the frontend driver (i.e. `flang-new -fc1`) actually exists.
This was not required for the compiler driver, `flang-new`, as that's
already handled in libclangDriver.

Once all input/output file management is moved to the driver, we should
also check that for input from `stdin` the corresponding file descriptor
was successfully acquired.

This patch also makes sure that the default action in the frontend is
`ParseSyntaxOnly`. This is consistent with Clang. Before this change
`flang-new -fc1` would do nothing, which makes testing changes like the
one introduced here a bit tricky.

Reviewed By: SouraVX

Differential Revision: https://reviews.llvm.org/D95127
2021-02-02 10:03:45 +00:00
Eric Schweitz 5918690255 [flang][NFC] Rename complex type.
This change renames the CplxType class to ComplexType.
2021-02-01 15:31:48 -08:00
Valentin Clement 3f46c209f1 [flang][directive] Enforce basic semantic check for all clauses
This patch is a follow up to D94821 to ensure the correct behavior of the
general directive structure checker.
This patch add the generation of the Enter function declaration for clauses in
the TableGen backend.
This helps to ensure each clauses declared in the TableGen file has at least
a basic check.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D95108
2021-02-01 13:33:30 -05:00
peter klausler f0ffc690d5 [flang] Fix parsing of WRITE(I+J) with more accurate look-ahead
The parsing of I/O units uses look-ahead to discriminate between
keywords, variables and expressions as part of distinguishing internal
from external I/O.  The look-ahead was inaccurate for variables that
appear as the initial parts of expressions.

Differential Revision: https://reviews.llvm.org/D95743
2021-02-01 09:07:40 -08:00
xgupta 94fac81fcc [Branch-Rename] Fix some links
According to the [[ https://foundation.llvm.org/docs/branch-rename/ | status of branch rename ]], the master branch of the LLVM repository is removed on 28 Jan 2021.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D95766
2021-02-01 16:43:21 +05:30
peter klausler 6f3d322f25 [flang] Improve shape & length characterization
Analyze the shape of the result of TRANSFER(ptr,array) correctly
when "ptr" is an array of deferred shape.  Fixing this bug led to
some refactoring and concentration of common code in TypeAndShape
member functions with code in general shape and character length
analysis, and this led to some regression test failures that have
all been cleaned up.

Differential Revision: https://reviews.llvm.org/D95744
2021-01-30 16:14:27 -08:00
peter klausler ebe74d9592 [flang] Support disabled alternative PARAMETER statement
Legacy Fortran implementations support an alternative form of the
PARAMETER statement; it differs syntactically from the standard's
PARAMETER statement by lacking parentheses, and semantically by
using the type and shape of the initialization expression to define
the attributes of the named constant.  (GNU Fortran gets that part
wrong; Intel Fortran and nvfortran have full support.)

This patch disables the old style PARAMETER statement by default, as
it is syntactically ambiguous with conforming assignment statements;
adds a new "-falternative-parameter-statement" option to enable it;
and implements it correctly when enabled.

Fixes https://bugs.llvm.org/show_bug.cgi?id=48774, in which a user
tripped over the syntactic ambiguity.

Differential Revision: https://reviews.llvm.org/D95697
2021-01-29 15:30:06 -08:00
Andrzej Warzynski 9b64e0e205 [flang][docs] Add New Flang Driver Biweekly call 2021-01-29 16:57:20 +00:00
Peter Steinfeld 543cd89d3f [flang] Fix problems with constant arrays with lower bounds that are not 1
There were two problems with constant arrays whose lower bound is not 1.
First, when folding the arrays, we were creating the folded array to have lower
bounds of 1 but, we were not re-adjusting their lower bounds to the
declared values.  Second, we were not calculating the extents correctly.
Both of these problems led to bogus error messages.

I fixed the first problem by adjusting the lower bounds in
NonPointerInitializationExpr() in Evaluate/check-expression.cpp.  I wrote the
class ArrayConstantBoundChanger, which is similar to the existing class
ScalarConstantExpander.  In the process of implementing and testing it, I found
a bug that I fixed in ScalarConstantExpander which caused it to infinitely
recurse on parenthesized expressions.  I also removed the unrelated class
ScalarExpansionVisitor, which was not used.

I fixed the second problem by changing the formula that calculates upper bounds
in in the function ComputeUpperBound() in Evaluate/shape.cpp.

I added tests that trigger the bogus error messages mentioned above along with
a constant folding tests that uses array operands with shapes that conform but
have different bounds.

In the process of adding tests, I discovered that tests in
Evaluate/folding09.f90 and folding16.f90 were written incorrectly, and I
fixed them.  This also revealed a bug in contant folding of the
intrinsic "lbounds" which I plan to fix in a later change.

Differential Revision: https://reviews.llvm.org/D95449
2021-01-29 08:05:10 -08:00
peter klausler 6110e7716c [flang] Search for #include "file" in right directory (take 2)
Make the #include "file" preprocessing directive begin its
search in the same directory as the file containing the directive,
as other preprocessors and our Fortran INCLUDE statement do.

Avoid current working directory for all source files except the original.

Resolve tests.

Differential Revision: https://reviews.llvm.org/D95481
2021-01-27 15:41:29 -08:00
Valentin Clement f30c523660 [flang][openacc] Allow multiple wait clauses
kernels loop and enter data had a too restrictive constraint for the wait clause.
The wait clause is allowed multiple times and not only once. This patch fix this problem.

Reviewed By: SouraVX

Differential Revision: https://reviews.llvm.org/D95469
2021-01-27 13:18:46 -05:00
Valentin Clement b65896ef8b [flang][openacc] Fix clause restriction for exit data directive
Restriction on clauses for the EXIT DATA directive were not fully correct.
This patch fixes the situation. The async, if and finalize clauses are allowed
only once.

Reviewed By: SouraVX

Differential Revision: https://reviews.llvm.org/D95470
2021-01-27 10:07:19 -05:00
Valentin Clement 5e09a02527 [flang][openacc] Fix clause restriction for host_data directive
Restriction on clauses for the HOST_DATA directive were not fully correct.
This patch fixes the situation. The if and if_present clauses are allowed
only once.

Reviewed By: SouraVX

Differential Revision: https://reviews.llvm.org/D95473
2021-01-27 10:06:33 -05:00
Faris Rehman a8f51ea212 [flang][driver] Report prescanning diags during syntax-only parsing
Ensure diagnostics from the prescanner are reported when running `flang-new -fsyntax-only` (i.e. only syntax parsing).
This keeps the diagnostics output of flang-new consistent with `f18 -fparse-only` when running the syntax parsing action, ParseSyntaxOnlyAction.

Summary of changes:
- Modify ParseSyntaxOnlyAction::ExecuteAction to report diagnostics

Differential Revision: https://reviews.llvm.org/D95220
2021-01-27 10:27:21 +00:00
Valentin Clement d2abd62b9d [flang][openacc][NFC] Organize clause validity tests by directive
Split the tests from acc-clause-validity.f90 in dedicated files by directives.
The file acc-clause-validity.f90 was getting too big to be correctly maintained.
Tests are identical.

Reviewed By: SouraVX

Differential Revision: https://reviews.llvm.org/D95328
2021-01-26 14:54:05 -05:00
Andrzej Warzynski e878589098 Revert "[flang] Search for #include "file" in right directory"
This reverts commit d987b61b1d.

As pointed out in https://reviews.llvm.org/D95388, the reverted commit
causes build failures in the following Flang buildbots:
  * http://lab.llvm.org:8011/#/builders/32/builds/2642
  * http://lab.llvm.org:8011/#/builders/33/builds/2131
  * http://lab.llvm.org:8011/#/builders/135/builds/1473
  * http://lab.llvm.org:8011/#/builders/66/builds/1559
  * http://lab.llvm.org:8011/#/builders/134/builds/1409
  * http://lab.llvm.org:8011/#/builders/132/builds/1817
I'm guessing that the patch was only tested with
`FLANG_BUILD_NEW_DRIVER=Off` (i.e. the default). The builders listed
above set `FLANG_BUILD_NEW_DRIVER` to `On`.

Although fixing the build is relatively easy, the reverted patch
modifies the behaviour of the frontend, which breaks driver tests. In
particular, in https://reviews.llvm.org/D93453 support for `-I` was
added that depends on the current behaviour. The reverted patch
changes that behaviour. Either the tests have to be updated or the
change fine-tuned.
2021-01-26 13:07:14 +00:00
peter klausler 03f1c9fa85 [flang] Fix errors in ISO_FORTRAN_ENV module for REAL128
Some parameters of 128-bit IEEE floating-point numbers were
incorrect, leading to a failure to define REAL128 to 16.

Differential Revision: https://reviews.llvm.org/D95387
2021-01-25 13:41:32 -08:00
peter klausler d987b61b1d [flang] Search for #include "file" in right directory
Make the #include "file" preprocessing directive begin its
search in the same directory as the file containing the directive,
as other preprocessors and our Fortran INCLUDE statement do.

Avoid current working directory for all source files after the original.

Differential Revision: https://reviews.llvm.org/D95388
2021-01-25 13:39:37 -08:00
Faris Rehman 1c8f199f44 [flang][driver] Update PP tests to use the new driver
Update the preprocessor regression tests to use the new driver if the new driver is built (FLANG_BUILD_NEW_DRIVER=On), otherwise the tests will still run using f18.

Summary of changes:
- Introduce %flang to the regression tests, which points to the new driver if it is built or otherwise points to f18
- Update all tests in flang/test/Preprocessing/ to use %flang

Differential Revision: https://reviews.llvm.org/D94805
2021-01-25 12:32:23 +00:00
Faris Rehman 8e3adda820 [flang][driver] Remove newline in CompilerInvocation
Remove a new line in CompilerInvocation, to now follow the style when clang-format is applied.
2021-01-25 11:58:52 +00:00
peter klausler f187d64c80 [flang][nfc] Fix comments, remove needless API, tweak script
* Remove an unimplemented and unused member function declaration
* Remove a misleading comment about an unrelated constraint number
* Fix a comment
* Add f18 crash message to "flang" driver script

Differential Revision: https://reviews.llvm.org/D95180
2021-01-22 10:55:53 -08:00
peter klausler 07f1e1f44c [flang] Correct shape analysis for transformational intrinsic functions
Correct the analysis of references to transformational intrinsic
functions that have different semantics based on the presence or
absence of a DIM= argument; add shape analysis for UNPACK().

Differential Revision: https://reviews.llvm.org/D94716
2021-01-22 10:48:58 -08:00
peter klausler 59bf9a89d8 [flang] Remove some needless operations in expr rewriting
Expressions emitted to module files and error messages
sometimes contain conversions of integer results of inquiry
intrinsics; these are usually not needed, and can conflict
with "int" in the user's namespace.  Improve folding so that
these conversions don't appear, and do some other clean-up
in adjacent code.

Differential Revision: https://reviews.llvm.org/D95172
2021-01-22 10:08:51 -08:00
Peter Steinfeld 02e174e8f7 [flang] Fix typo in error message
The title says it all.

Differential Revision: https://reviews.llvm.org/D95233
2021-01-22 07:28:37 -08:00
peter klausler 2de5ea3b3e [flang] Fix bogus error message with binding
ProcedureDesignator::GetInterfaceSymbol() needs to return
the procedure bound to a bindings.

Differential Revision: https://reviews.llvm.org/D95178
2021-01-21 16:59:51 -08:00
peter klausler 0cfadb37f4 [flang] Allow NULL() actual argument for pointer dummy
Fixes a bogus error message about an actual argument not being an
object.

Differential Revision: https://reviews.llvm.org/D95176
2021-01-21 16:37:35 -08:00
peter klausler 3738447c96 [flang] Address name resolution problems
Don't emit a bogus error message about a bad forward reference
when it's an IMPORT of a USE-associated symbol; don't ignore
intrinsic functions when USE-associating the contents of a
module when the intrinsic has been explicitly USE'd; allow
PUBLIC or PRIVATE accessibility attribute to be specified
for an enumerator before the declaration of the enumerator.

Differential Revision: https://reviews.llvm.org/D95175
2021-01-21 16:15:38 -08:00
peter klausler a75840a09c [flang] Better C_LOC and C_ASSOCIATED in flang/module
The place-holding implementation of C_LOC just didn't work
when used with our more complete semantic checking, specifically
in the case of a polymorphic argument; convert it to an external
function with an implicit interface.  C_ASSOCIATED needs to be
a generic interface with specific implementations for C_PTR and
C_FUNPTR.

Differential Revision: https://reviews.llvm.org/D94714
2021-01-21 09:41:05 -08:00
Andrzej Warzynski aba24c1580 [flang][driver] Move fixed/free from detection out of FrontendAction API
All Fortran options should be set in `CompilerInstance` (via its
`CompilerInvocation`) before any of `FrontendAction` is entered -
that's one of the tasks of the driver. However, this is a bit tricky
with fixed and free from detection introduced in
https://reviews.llvm.org/D94228.

Fixed-free form detection needs to happen:
  * before any frontend action (we need to specify `isFixedForm` in
    `Fortran::parser::Options` before running any actions)
  * separately for every input file (we might be compiling multiple
    Fortran files, some in free form, some in fixed form)
In other words, we need this to happen early (before any
`FrontendAction`), but not too early (we need to know what the current
input file is). In practice, `isFixedForm` can only be set later
than other options (other options are inferred from compiler flags). So
we can't really set all of them in one place, which is not ideal.

All changes in this patch are NFCs (hence no new tests). Quick summary:
  * move fixed/free form detection from `FrontendAction::ExecuteAction` to
    `CompilerInstance::ExecuteAction`
  * add a bool flag in `FrontendInputFile` to mark a file as fixed/free
    form
  * updated a few comments

Differential Revision: https://reviews.llvm.org/D95042
2021-01-21 16:57:22 +00:00
Andrzej Warzynski 0eeb15741b [flang][driver] Make the driver report diagnostics from the prescanner
This patch makes sure that diagnostics from the prescanner are reported
when running `flang-new -E` (i.e. only the preprocessor phase is
requested). More specifically, the `PrintPreprocessedAction` action is
updated.

With this patch we make sure that the `f18` and `flang-new` provide
identical output when running the preprocessor and the prescanner
generates diagnostics.

Differential Revision: https://reviews.llvm.org/D94782
2021-01-21 15:06:32 +00:00
Peter Steinfeld bebbe64075 [flang] Fix creation of deferred shape arrays by POINTER statement
It's possible to  declare deferred shape array using the POINTER
statement, for example:

  POINTER :: var(:)

When analyzing POINTER declarations, we were not capturing the array
specification information, if present.  I fixed this by changing the
"Post" function for "parser::PointerDecl" to check to see if the
declaration contained a "DeferredShapeSpecList".  In such cases, I
analyzed the shape and used to information to declare an "ObjectEntity"
that contains the shape information rather than an "UnknownEntity".

I also added a couple of small tests that fail to compile without these
changes.

Differential Revision: https://reviews.llvm.org/D95080
2021-01-20 13:08:11 -08:00
peter klausler 0996b590aa [flang] Infrastructure improvements in utility routines
* IsArrayElement() needs another option to control whether it
  should ignore trailing component references.
* Add IsObjectPointer().
* Add const Scope& variants of IsFunction() and IsProcedure().
* Make TypeAndShape::Characterize() work with procedure bindings.
* Handle CHARACTER length in MeasureSizeInBytes().
* Fine-tune FindExternallyVisibleObject()'s handling of dummy arguments
  to conform with Fortran 2018: only INTENT(IN) and dummy pointers
  in pure functions signify; update two tests accordingly.

Also: resolve some stylistic inconsistencies and add a missing
"const" in the expression traversal template framework.

Differential Revision: https://reviews.llvm.org/D95011
2021-01-20 12:40:25 -08:00
Andrzej Warzynski b564b12bc6 [flang][driver] Refactor one unit-test case to use fixtures (nfc)
Move the unit test from InputOutputTest.cpp to FrontendActionTest.cpp
and re-implement it in terms of the FrontendActionTest fixture. This is
just a small code clean-up and a continuation of:
  * https://reviews.llvm.org/D93544

Moving forward, we should try be implementing all unit-test cases for
Flang's frontend actions in terms of FrontendActionTest.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D94922
2021-01-20 19:36:38 +00:00
peter klausler ff3b51b054 [flang] Fix ASSOCIATE statement name resolution
F18 Clause 19.4p9 says:

  The associate names of an ASSOCIATE construct have the scope of the
  block.

Clause 11.3.1p1 says the ASSOCIATE statement is not itself in the block:

  R1102 associate-construct is:  associate-stmt block end-associate-stmt

Associate statement associations are currently fully processed from left
to right, incorrectly interposing associating entities earlier in the
list on same-named entities in the host scope.

    1  program p
    2    logical :: a = .false.
    3    real :: b = 9.73
    4    associate (b => a, a => b)
    5      print*, a, b
    6    end associate
    7    print*, a, b
    8  end

Associating names 'a' and 'b' at line 4 in this code are now both
aliased to logical host entity 'a' at line 2.  This happens because the
reference to 'b' in the second association incorrectly resolves 'b' to
the entity in line 4 (already associated to 'a' at line 2), rather than
the 'b' at line 3.  With bridge code to process these associations,
f18 output is:

 F F
 F 9.73

It should be:

 9.73 F
 F 9.73

To fix this, names in right-hand side selector variables/expressions
must all be resolved before any left-hand side entities are resolved.
This is done by maintaining a stack of lists of associations, rather
than a stack of associations.  Each ASSOCIATE statement's list of
assocations is then visited once for right-hand side processing, and
once for left-hand side processing.

Note that other construct associations do not have this problem.
SELECT RANK and SELECT TYPE each have a single assocation, not a list.
Constraint C1113 prohibits the right-hand side of a CHANGE TEAM
association from referencing any left-hand side entity.

Differential Revision: https://reviews.llvm.org/D95010
2021-01-20 11:18:27 -08:00
peter klausler 24e8e21f19 [flang] Refine WhyNotModifiable()
The utility routine WhyNotModifiable() needed to become more
aware of the use of pointers in data-refs; the targets of
pointer components are sometimes modifiable even when the
leftmost ("base") symbol of a data-ref is not.

Added a new unit test for WhyNotModifiable() that uses internal
READ statements (mostly), since I/O semantic checking uses
WhyNotModifiable() for all its definability checking.

Differential Revision: https://reviews.llvm.org/D94849
2021-01-19 11:44:51 -08:00
Andrzej Warzynski cea3abc26f [flang][driver] Move isFixedFormSuffix and isFreeFormSuffix to flangFrontend
isFixedFormSuffix and isFreeFormSuffix should be defined in
flangFrontend rather than flangFrontendTool library. That's for 2
reasons:
  * these methods are used in flangFrontend rather than flangFrontendTool
  * flangFrontendTool depends on flangFrontend

As mentioned in the post-commit review for D94228, without this change
shared library builds fail.

Differential Revision: https://reviews.llvm.org/D94968
2021-01-19 17:47:40 +00:00
Valentin Clement 6bd0a4451c [flang][directive] Get rid of flangClassValue in TableGen
The TableGen emitter for directives has two slots for flangClass information and this was mainly
to be able to keep up with the legacy openmp parser at the time. Now that all clauses are encapsulated in
AccClause or OmpClause, these two strings are not necessary anymore and were the the source of couple
of problem while working with the generic structure checker for OpenMP.
This patch remove the flangClassValue string from DirectiveBase.td and use the string flangClass as the
placeholder for the encapsulated class.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D94821
2021-01-19 10:28:46 -05:00
Raul Tambre 480643a95c [CMake] Remove dead code setting policies to NEW
cmake_minimum_required(VERSION) calls cmake_policy(VERSION),
which sets all policies up to VERSION to NEW.
LLVM started requiring CMake 3.13 last year, so we can remove
a bunch of code setting policies prior to 3.13 to NEW as it
no longer has any effect.

Reviewed By: phosek, #libunwind, #libc, #libc_abi, ldionne

Differential Revision: https://reviews.llvm.org/D94374
2021-01-19 17:19:36 +02:00
Praveen c42f5ca3d8 [Flang][OpenMP] Add semantic checks for OpenMP Workshare Construct
Add Semantic checks for OpenMP 4.5 - 2.7.4 Workshare Construct.

 - The structured block in a workshare construct may consist of only
   scalar or array assignments, forall or where statements,
   forall, where, atomic, critical or parallel constructs.

 - All array assignments, scalar assignments, and masked array
   assignments must be intrinsic assignments.

 - The construct must not contain any user defined function calls unless
   the function is ELEMENTAL.

Test cases : omp-workshare03.f90, omp-workshare04.f90, omp-workshare05.f90

Resolve test cases (omp-workshare01.f90 and omp-workshare02.f90) marked as XFAIL

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D93091
2021-01-19 20:00:12 +05:30
Faris Rehman 197d9a55f1 [flang][driver] Add standard macro predefinitions for compiler version
Add the following standard predefinitions that f18 supports:
  * `__flang__`,
  * `__flang_major__`,
  * `__flang_minor__`,
  * `__flang_patchlevel__`

Summary of changes:
- Populate Fortran::parser::Options#predefinitions with the default
  supported predefinitions

Differential Revision: https://reviews.llvm.org/D94516
2021-01-19 13:22:59 +00:00
Faris Rehman 443d6957ca [flang][driver] Add support for fixed form detection
Currently the new flang driver always runs in free form mode. This patch
adds support for fixed form mode detection based on the file extensions.

Like `f18`, `flang-new` will treat files ending with ".f", ".F" and
".ff" as fixed form. Additionally, ".for", ".FOR", ".fpp" and ".FPP"
file extensions are recognised as fixed form files. This is consistent
with gfortran [1]. In summary, files with the following extensions are
treated as fixed-form:
  * ".f", ".F", ".ff", ".for", ".FOR", ".fpp", ".FPP"

For consistency with flang/test/lit.cfg.py and f18, this patch also adds
support for the following file extensions:
  * ".ff", ".FOR", ".for", ".ff90", ".fpp", ".FPP"
This is added in flang/lib/Frontend/FrontendOptions.cpp. Additionally,
the following extensions are included:
  * ".f03", ".F03", ".f08", ".F08"
This is for compatibility with gfortran [1] and other popular Fortran
compilers [2].

NOTE: internally Flang will only differentiate between fixed and free
form files. Currently Flang does not support switching between language
standards, so in this regard file extensions are irrelevant. More
specifically, both `file.f03` and `file.f18` are represented with
`Language::Fortran` (as opposed to e.g. `Language::Fortran03`).

Summary of changes:
- Set Fortran::parser::Options::sFixedForm according to the file type
- Add isFixedFormSuffix and isFreeFormSuffix helper functions to
  FrontendTool/Utils.h
- Change FrontendOptions::GetInputKindForExtension to support the missing
  file extensions that f18 supports and some additional ones
- FrontendActionTest.cpp is updated to make sure that the test input is
  treated as free-form

[1] https://gcc.gnu.org/onlinedocs/gfortran/GNU-Fortran-and-GCC.html
[2] https://github.com/llvm/llvm-project/blob/master/flang/docs/OptionComparison.md#notes

Differential Revision: https://reviews.llvm.org/D94228
2021-01-19 12:58:01 +00:00
Faris Rehman 87dfd5e012 [flang][driver] Add support for `-I` in the new driver
Add support for option -I in the new Flang driver. This will allow for
included headers and module files in other directories, as the default
search path is currently the working folder. The behaviour of this is
consistent with the current f18 driver, where the current folder (i.e.
".") has the highest priority followed by the order of '-I's taking
priority from first to last.

Summary of changes:
- Add SearchDirectoriesFromDashI to PreprocessorOptions, to be forwarded
  into the parser's searchDirectories
- Add header files and non-functional module files to be used in
  regression tests. The module files are just text files and are used to
  demonstrated that paths specified with `-I` are taken into account when
  searching for .mod files.

Differential Revision: https://reviews.llvm.org/D93453
2021-01-19 11:20:56 +00:00
peter klausler 1bd083b5d6 [flang] Create names to allow access to inaccessible specifics
When a reference to a generic interface occurs in a specification
expression that must be emitted to a module file, we have a problem
when the generic resolves to a function whose name is inaccessible
due to being PRIVATE or due to a conflict with another use of the
same name in the scope.  In these cases, construct a new name for
the specific procedure and emit a renaming USE to the module file.
Also, relax enforcement of PRIVATE when analyzing module files.

Differential Revision: https://reviews.llvm.org/D94815
2021-01-15 16:56:38 -08:00
Andrzej Warzynski b6e06a740c [flang][driver] Copy test file into a temp dir when testing (nfc)
The following driver invocation will generate an output file
in the same directory as the input file:

```
flang-new -fc1 -test-io test-input.f90
```

This is the desired behaviour. However, when testing we need to make
sure that we don't pollute the source directory. To this end, copy the
input file into a temporary directory before testing.

This is similar to https://reviews.llvm.org/D94243.
2021-01-15 17:12:42 +00:00
Peter Steinfeld 1e1a011b09 [flang] Disallow INTENT attribute on procedure dummy arguments
C843 states that "An entity with the INTENT attribute shall be a dummy
data object or a dummy procedure pointer."  This change enforces that
and fixes some tests that erroneously violated this rule.

Differential Revision: https://reviews.llvm.org/D94781
2021-01-15 08:53:43 -08:00
Yashaswini 39665d9aab Add Semantic check for Flang OpenMP 4.5 - 2.7.1 Do Loop restrictions on single directive and firstprivate clause.
Semantic checks added to check the worksharing 'single' region closely nested inside a worksharing 'do' region. And also to check whether the 'do' iteration variable is a variable in 'Firstprivate' clause.

Files:
check-directive-structure.h
check-omp-structure.h
check-omp-structure.cpp

Testcases:
omp-do01-positivecase.f90
omp-do01.f90
omp-do05-positivecase.f90
omp-do05.f90

Reviewed by: Kiran Chandramohan @kiranchandramohan , Valentin Clement @clementval

Differential Revision: https://reviews.llvm.org/D93205
2021-01-15 11:16:25 +05:30
Tim Keith d6acf3c201 [flang] Fix use-associated procedure in generic
When a use-associated procedure was included in a generic, we weren't
correctly recording that fact. The ultimate symbol was added rather than
the local symbol.

Also, improve the message emitted for the specific procedure by
mentioning the module it came from.

This fixes one of the problems in https://bugs.llvm.org/show_bug.cgi?id=48648.

Differential Revision: https://reviews.llvm.org/D94696
2021-01-14 16:31:52 -08:00
Valentin Clement ca98baa042 [openacc] Rename generated file from ACC.cpp.inc to ACC.inc to match D92955
This patch rename the tablegen generated file ACC.cpp.inc to ACC.inc in order
to match what was done in D92955. This file is included in header file as well as .cpp
file so it make more sense.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D93485
2021-01-14 14:19:53 -05:00
peter klausler 4864d9f7e9 [flang] Fix some module file issues exposed by Whizard
Generic type-bound interfaces for user-defined operators need to be formatted
as "OPERATOR(.op.)", not just ".op."

PRIVATE generics need to be marked as such.

Declaration ordering: when a generic interface shadows a
derived type of the same name, it needs to be emitted to the
module file at the point of definition of the derived type;
otherwise, the derived type's definition may appear after its
first use.

The module symbol for a module read from a module file needs
to be marked as coming from a module file before semantic
processing is performed on the contents of the module so that
any special handling for declarations in module files can be
properly activated.

IMPORT statements were sometimes missing for use-associated
symbols in surrounding scopes; fine-tune NeedImport().

Differential Revision: https://reviews.llvm.org/D94636
2021-01-14 09:44:50 -08:00
Andrzej Warzynski 0afdbb4d2d [flang][driver] Use __FLANG_VERISION__ in f18.cpp (nfc)
Just a minor improvement suggested in a post-commit review here:
https://reviews.llvm.org/D94422
2021-01-14 16:51:49 +00:00
Tim Keith 3e41ab18db [flang] Fix dangling pointer in LabelEnforce
`DirectiveStructureChecker` was passing in a pointer to a temporary
string for the `construct` argument to the constructor for `LabelEnforce`.
The `LabelEnforce` object had a lifetime longer than the temporary,
resulting in accessing a dangling pointer when emitting an error message
for `omp-parallell01.f90`.

The fix is to make the lifetime of the temporary as long as the lifetime
of the `LabelEnforce` object.

Differential Revision: https://reviews.llvm.org/D94618
2021-01-14 06:52:21 -08:00
Andrzej Warzynski a1bbd1ef1d [flang][driver] Unify f18_version.h.in and Version.inc.in
Flang has two CMake configurable header files that define compiler
version numbers:
* f18_version.h.in - only used in f18.cpp (uses version numbers from
  LLVM's macro definitions)
* Version.inc.in - not currently used (uses version numbers hard-coded
  in Flang's top CMake script)

Currently only f18_version.h.in provides version numbers consistent with
other subprojects in llvm-project. However, its location and name are
inconsistent with e.g. Clang. This patch merges the two headers
together:
  * hard-coded version numbers in Flang's top CMake script are deleted
  * Version.inc.in is updated to provide string versions of version
  numbers (required by f18.cpp)
  * f18_version.h.in is deleted as it's no longer needed

Differential Revision: https://reviews.llvm.org/D94422
2021-01-14 13:50:46 +00:00
Peter Steinfeld 3de92ca78c [flang] Add tests for procedure arguments with implicit interfaces
It's possible to declare an external procedure and then pass it as an
actual argument to a subprogram expecting a procedure argument.  I added
tests for this and added an error message to distinguish passing an
actual argument with an implicit interface from passing an argument with
a mismatched explicit interface.

Differential Revision: https://reviews.llvm.org/D94505
2021-01-13 16:43:09 -08:00
Tim Keith 18278ff1aa [flang] Fix accessibility of USEd name in .mod file
If a module specifies default private accessibility, names that have
been use-associated are private by default. This was not reflected in
.mod files.

Differential Revision: https://reviews.llvm.org/D94602
2021-01-13 12:52:44 -08:00
peter klausler 166e5c335c [flang] Do not create HostAssoc symbols in derived type scopes
When needed due to a specification expression in a derived type,
the host association symbols should be created in the surrounding
subprogram's scope instead.

Differential Revision: https://reviews.llvm.org/D94567
2021-01-13 11:01:27 -08:00
peter klausler a50bb84ec0 [flang] Fix classification of shape inquiries in specification exprs
In some contexts, including the motivating case of determining whether
the expressions that define the shape of a variable are "constant expressions"
in the sense of the Fortran standard, expression rewriting via Fold()
is not necessary, and should not be required.  The inquiry intrinsics LBOUND,
UBOUND, and SIZE work correctly now in specification expressions and are
classified correctly as being constant expressions (or not).  Getting this right
led to a fair amount of API clean-up as a consequence, including the
folding of shapes and TypeAndShape objects, and new APIs for shapes
that do not fold for those cases where folding isn't needed.  Further,
the symbol-testing predicate APIs in Evaluate/tools.h now all resolve any
associations of their symbols and work transparently on use-, host-, and
construct-association symbols; the tools used to resolve those associations have
been defined and documented more precisely, and their clients adjusted as needed.

Differential Revision: https://reviews.llvm.org/D94561
2021-01-13 10:05:14 -08:00
sameeran joshi 6f4d460762 [Flang][openmp][openacc] Extend CheckNoBranching to handle branching provided by LabelEnforce.
`CheckNoBranching` is currently handling only illegal branching out for constructs
with `Parser::Name` in them.
Extend the same for handling illegal branching out caused by `Parser::Label` based statements.
This patch could possibly solve one of the issues(typically branching out) mentioned in D92735.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D93447
2021-01-13 00:04:45 +05:30
Valentin Clement 47567ca5fa [flang][openxx][NFC] Remove duplicated function to check required clauses
Remove duplicated function to check for required clauses on a directive. This was
still there from the merging of OpenACC and OpenMP common semantic checks and it can now be
removed so we use only one function.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D93575
2021-01-11 14:08:51 -05:00
Andrzej Warzynski 8298ec2d62 [flang][driver] Copy input files into a temp dir when testing
The following frontend driver invocation will generate 2 output files
in the same directory as the input files:
```
flang-new -fc1 input-1.f input-2.f
```
This is the desired behaviour. However, when testing we need to make
sure that we don't pollute the source directory. To this end, copy test
input files into a temporary directory.

Differential Revision: https://reviews.llvm.org/D94243
2021-01-11 13:54:19 +00:00
Peter Steinfeld ae0d1d2e5c [flang] Fix bogus message on internal subprogram with alternate return
Internal subprograms have explicit interfaces.  If an internal subprogram has
an alternate return, we check its explicit interface.  But we were not
putting the label values of alternate returns into the actual argument.

I fixed this by changing the definition of actual arguments to be able
to contain a common::Label and putting the label for an alternate return
into the actual argument.

I also verified that we were already doing all of the semantic checking
required for alternate returns and removed a "TODO" for this.

I also added the test altreturn06.f90.

Differential Revision: https://reviews.llvm.org/D94017
2021-01-08 10:14:21 -08:00
Valentin Clement b73736a404 [flang][openacc] Enforce delcare directive restriction
Add semantic check for most of the restrictions for the declare directive.

Reviewed By: kiranktp

Differential Revision: https://reviews.llvm.org/D92741
2021-01-07 09:28:55 -05:00
Andrzej Warzynski a2957f80f8 [flang][driver] Rename driver tests (nfc)
As per [1]:
```
File names should use dashes, not underscores.
```

This patch updates the names of Flang driver tests accordingly.

[1] https://github.com/llvm/llvm-project/blob/main/flang/docs/C%2B%2Bstyle.md
2021-01-07 14:05:48 +00:00
Andrzej Warzynski e5cdb6c56e [flang][driver] Add support for `-c` and `-emit-obj`
This patch adds a frontend action for emitting object files. While Flang
does not support code-generation, this action remains a placeholder.
This patch simply provides glue-code to connect the compiler driver
with the appropriate frontend action.

The new action is triggered with the `-c` compiler driver flag, i.e.
`flang-new -c`. This is then translated to `flang-new -fc1 -emit-obj`,
so `-emit-obj` has to be marked as supported as well.

As code-generation is not available yet, `flang-new -c` results in a
driver error:
```
error: code-generation is not available yet
```
Hopefully this will help communicating the level of available
functionality within Flang.

The definition of `emit-obj` is updated so that it can be shared between
Clang and Flang. As the original definition was enclosed within a
Clang-specific TableGen `let` statement, it is extracted into a new `let`
statement. That felt like the cleanest option.

I also commented out `-triple` in Flang::ConstructJob and updated some
comments there. This is similar to https://reviews.llvm.org/D93027. I
wanted to make sure that it's clear that we can't support `-triple`
until we have code-generation. However, once code-generation is
available we _will need_ `-triple`.

As this patch adds `-emit-obj`, the emit-obj.f90 becomes irrelevant and
is deleted. Instead, phases.f90 is added to demonstrate that users can
control compilation phases (indeed, `-c` is a phase control flag).

Reviewed By: SouraVX, clementval

Differential Revision: https://reviews.llvm.org/D93301
2021-01-07 10:52:38 +00:00
Valentin Clement 322e98bc27 [flang][openacc] Add more parsing/sema tests for init and shutdown directives
This patch adds some positive and failure tests for init and shutdown directives.

Reviewed By: kiranktp

Differential Revision: https://reviews.llvm.org/D90786
2021-01-06 14:15:19 -05:00
Faris Rehman 7809fa2040 [flang][driver] Add support for `-D`, `-U`
Add support for options -D and -U in the new Flang driver.

Summary of changes:
  - Create PreprocessorOptions, to be used by the driver then translated
    into Fortran::parser::Options
  - Create CompilerInvocation::setFortranOpts to pass preprocessor
    options into the parser options
  - Add a dedicated method, Flang::AddPreprocessingOptions, to extract
    preprocessing options from the driver arguments into the preprocessor
    command arguments

Macros specified like -DName will default to definition 1.

When defining macros, the new driver will drop anything after an
end-of-line character. This is consistent with gfortran and clang, but
different to what currently f18 does. However, flang (which is a bash
wrapper for f18), also drops everything after an end-of-line character.
So gfortran-like behaviour felt like the natural choice. Test is added
to demonstrate this behaviour.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D93401
2021-01-06 16:17:13 +00:00
Andrzej Warzynski fa1e543e0b [flang][driver] Update error messages (nfc)
As per Flang's coding guidelines
(flang/docs/C++style.md#error-messages):
```
Messages should start with a capital letter.
```

This patch updates error messages in the driver (new and old) so that
they conform with the guideline above.

This change was suggested in one of the recent reviews:
https://reviews.llvm.org/D93712. It felt like this deserved a dedicated
patch, so sending it separately.
2021-01-06 10:41:27 +00:00
Andrzej Warzynski e49dc2981c [flang][driver] Add checks for errors from `Prescan` and `Parse`
If either `Prescan` or `Parse` generate any fatal errors, the new driver
will:
  * report it (i.e. issue an error diagnostic)
  * exit early
  * return non-zero exit code
This behaviour is consistent with f18 (i.e. the old driver).

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D93712
2021-01-06 10:19:44 +00:00
Valentin Clement 4d0aad96e4 [flang][openmp] Make Reduction clause part of OmpClause
After discussion in D93105 we found that the reduction clause was not following
the common OmpClause convention. This patch makes reduction clause part of OmpClause
with a value of OmpReductionClause in a similar way than task_reduction.
The unparse function for OmpReductionClause is adapted since the keyword and parenthesis
are issued by the corresponding unparse function for parser::OmpClause::Reduction.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D93482
2021-01-04 15:19:00 -05:00
sameeran joshi 6280bc1cc3 [Flang][openmp][5.0] Add task_reduction clause.
See OMP-5.0 2.19.5.5 task_reduction Clause.
To add a positive test case we need `taskgroup` directive which is not added hence skipping the test.
This is a dependency for `taskgroup` construct.

Reviewed By: clementval

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

Co-authored-by: Valentin Clement <clementval@gmail.com>
2021-01-04 08:48:11 +05:30
Tim Keith f782d5ea86 [flang] Detect call to abstract interface
A subroutine call or function reference to an abstract interface is
not legal.

Differential Revision: https://reviews.llvm.org/D93872
2020-12-28 16:36:34 -08:00
Tim Keith d55627d221 [flang] Fix bugs in .mod file for abstract interface
When an abstract interface is defined, add the ABSTRACT attribute to
subprogram symbols that define the interface body. Make use of that
when writing .mod files to include "abstract" on the interface statement.

Also, fix a problem with the order of symbols in a .mod file. Sometimes
a name is mentioned before the "real" declaration, e.g. in an access
statement. We want the order to be based on the real definitions. In
these cases we replace the symbol name with an identical name with a
different source location. Then by sorting based on the source location
we get symbols in the right order.

Differential Revision: https://reviews.llvm.org/D93572
2020-12-28 08:50:32 -08:00
Praveen a2ca6bbda6 [Flang][OpenMP] Add semantic check for OpenMP Private, Firstprivate and Lastprivate clauses.
OpenMP 4.5 - Variables that appear in expressions for statement function definitions
             may not appear in OpenMP Private, Firstprivate or Lastprivate clauses.

Test case : omp-private03.f90

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D93213
2020-12-25 14:43:41 +05:30
AlexisPerry 3b3a9d2418 Updated GettingInvolved.md to reflect Flang Biweekly Call changes
- updated the link to join the meeting to reflect the new WebEx information
   - Added a note about the new Google Doc for keeping track of notes, and who
     to contact if you experience access issues with the document
   - Left a reference to the minutes from previous meetings being available
     through a search of the flang-dev mailing list

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D93770
2020-12-23 11:59:12 -07:00
sameeran joshi 1aa10ab2e1 Revert "[Flang][openmp][5.0] Add task_reduction clause."
This reverts commit 9a7895dc20.
Reverting due to missing Co-author attribution.

https://reviews.llvm.org/D93105
2020-12-22 23:53:51 +05:30
sameeran joshi 9a7895dc20 [Flang][openmp][5.0] Add task_reduction clause.
See OMP-5.0 2.19.5.5 task_reduction Clause.
To add a positive test case we need `taskgroup` directive which is not added hence skipping the test.
This is a dependency for `taskgroup` construct.

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D93105
2020-12-22 22:34:38 +05:30
Andrzej Warzynski 31b67d2deb [flang][driver] Fix formatting in a test (nfc) 2020-12-22 13:38:13 +00:00
Andrzej Warzynski 44e74c75e6 [flang][driver] Refactor unit tests for frontend actions (nfc)
These patch implements a few non-functional-changes:
  * switch to using test fixtures for better code sharing
  * rename some variables (e.g. to communicate their purpose a bit better)
This patch doesn't change _what_ is being tested.

Differential Revision: https://reviews.llvm.org/D93544
2020-12-22 13:06:56 +00:00
sameeran joshi 1a6f43991f [Flang][openmp][5/5] Make dist_schedule clause part of OmpClause
After discussion in `D93482` we found that the some of the clauses were not
following the common OmpClause convention.

The benefits of using OmpClause:
- Functionalities from structure checker are mostly aligned to work with
  `llvm::omp::Clause`.
- The unparsing as well can take advantage.
- Homogeneity with OpenACC and rest of the clauses in OpenMP.
- Could even generate the parser with TableGen, when there is homogeneity.
- It becomes confusing when to use `flangClass` and `flangClassValue` inside
  TableGen, if incase we generate parser using TableGen we could have only a
  single `let expression`.

This patch makes `OmpDistScheduleClause` clause part of `OmpClause`.
The unparse function for `OmpDistScheduleClause` is adapted since the keyword
and parenthesis are issued by the corresponding unparse function for
`parser::OmpClause::DistSchedule`.

Reviewed By: clementval, kiranktp

Differential Revision: https://reviews.llvm.org/D93644
2020-12-22 14:32:33 +05:30
sameeran joshi e282ae57da [Flang][openmp][4/5] Make nowait clause part of OmpClause
After discussion in `D93482` we found that the some of the clauses were not
following the common OmpClause convention.

The benefits of using OmpClause:
- Functionalities from structure checker are mostly aligned to work with
  `llvm::omp::Clause`.
- The unparsing as well can take advantage.
- Homogeneity with OpenACC and rest of the clauses in OpenMP.
- Could even generate the parser with TableGen, when there is homogeneity.
- It becomes confusing when to use `flangClass` and `flangClassValue` inside
  TableGen, if incase we generate parser using TableGen we could have only a
  single `let expression`.

This patch makes `OmpNoWait` clause part of `OmpClause`.

Reviewed By: clementval, kiranktp

Differential Revision: https://reviews.llvm.org/D93643
2020-12-22 14:02:19 +05:30
sameeran joshi 34958d11c3 [Flang][openmp][3/5] Make ProcBind clause part of OmpClause
After discussion in `D93482` we found that the some of the clauses were not
following the common OmpClause convention.

The benefits of using OmpClause:
- Functionalities from structure checker are mostly aligned to work with
  `llvm::omp::Clause`.
- The unparsing as well can take advantage.
- Homogeneity with OpenACC and rest of the clauses in OpenMP.
- Could even generate the parser with TableGen, when there is homogeneity.
- It becomes confusing when to use `flangClass` and `flangClassValue` inside
  TableGen, if incase we generate parser using TableGen we could have only a
  single `let expression`.

This patch makes `OmpProcBindClause` clause part of `OmpClause`.
The unparse function is dropped as the unparsing is done by `WALK_NESTED_ENUM`
for `OmpProcBindClause`.

Reviewed By: clementval, kiranktp

Differential Revision: https://reviews.llvm.org/D93642
2020-12-22 13:40:38 +05:30
sameeran joshi f72c384b5b [Flang][openmp][2/5] Make Default clause part of OmpClause
After discussion in `D93482` we found that the some of the clauses were not
following the common OmpClause convention.

The benefits of using OmpClause:
- Functionalities from structure checker are mostly aligned to work with
  `llvm::omp::Clause`.
- The unparsing as well can take advantage.
- Homogeneity with OpenACC and rest of the clauses in OpenMP.
- Could even generate the parser with TableGen, when there is homogeneity.
- It becomes confusing when to use `flangClass` and `flangClassValue` inside
  TableGen, if incase we generate parser using TableGen we could have only a
  single `let expression`.

This patch makes `OmpDefaultClause` clause part of `OmpClause`.
The unparse function is dropped as the unparsing is done by `WALK_NESTED_ENUM`
for `OmpDefaultClause`.

Reviewed By: clementval, kiranktp

Differential Revision: https://reviews.llvm.org/D93641
2020-12-22 13:17:44 +05:30
sameeran joshi 442aac5da6 [Flang][openmp][1/5] Make Allocate clause part of OmpClause
After discussion in `D93482` we found that the some of the clauses were not
following the common OmpClause convention.

The benefits of using OmpClause:
- Functionalities from structure checker are mostly aligned to work with
  `llvm::omp::Clause`.
- The unparsing as well can take advantage.
- Homogeneity with OpenACC and rest of the clauses in OpenMP.
- Could even generate the parser with TableGen, when there is homogeneity.
- It becomes confusing when to use `flangClass` and `flangClassValue` inside
  TableGen, if incase we generate parser using TableGen we could have only a
  single `let expression`.

This patch makes `allocate` clause part of `OmpClause`.The unparse function for
`OmpAllocateClause` is adapted since the keyword and parenthesis are issued by
the corresponding unparse function for `parser::OmpClause::Allocate`.

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D93640
2020-12-22 12:53:34 +05:30
Valentin Clement 8f933a4e93 [openacc] Use TableGen enum for default clause value
Use the TableGen feature to have enum values for clauses.
Next step will be to extend the MLIR part used currently by OpenMP
to use the same enum on the dialect side.

This patch also add function that convert the enum to StringRef to be
used on the dump-parse-tree from flang.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D93576
2020-12-21 15:07:27 -05:00
Andrzej Warzynski d6abd7317a [flang][driver] Make the names of files created in unit tests unique (nfc)
Using files with identical names leads to unexpected failures when tests
are run in parallel. This is tricky to reproduce, but has been happening
on some buildbots since merging https://reviews.llvm.org/D92854. In that
patch I added a unit test with a non-unique test file. This patch fixes
that.
2020-12-21 11:20:06 +00:00
Tim Keith bf0870d864 [flang] Fix bug in IMPLICIT NONE(EXTERNAL)
We were only checking the restrictions of IMPLICIT NONE(EXTERNAL) when a
procedure name is first encountered. But it can also happen with an
existing symbol, e.g. if an external function's return type is declared
before is it called. This change adds a check in that branch too.

Differential Revision: https://reviews.llvm.org/D93552
2020-12-18 17:43:53 -08:00
Andrzej Warzynski db2195bc5b [flang][driver] Rename unittest file (nfc)
This patch renames PrintPreprocessedTest.cpp as FrontendActionTest.cpp.
The latter reflects the contents of the file more accurately.
2020-12-18 15:35:45 +00:00
Andrzej Warzynski 7d246cb19d [flang][driver] Add support for `-fsyntax-only`
The behaviour triggered with this flag is consistent with `-fparse-only`
in `flang` (i.e. the throwaway driver). This new spelling is consistent
with Clang and gfortran, and was proposed and agreed on for the new
driver in [1].

This patch also adds some minimal logic to communicate whether the
semantic checks have failed or not. When semantic checks fail, a
frontend driver error is generated. The return code from the frontend
driver is then determined by checking the driver diagnostics - the
presence of driver errors means that the compilation has failed. This
logic is consistent with `clang -cc1`.

[1] http://lists.llvm.org/pipermail/flang-dev/2020-November/000588.html

Differential Revision: https://reviews.llvm.org/D92854
2020-12-18 09:35:02 +00:00
Tim Keith f6b577ed5b [flang] Fix -intrinsic-module-directory in flang script
The flang wrapper script that was created as bin/flang in an in-tree
build did not have a correct -intrinsic-module-directory option.
It was correct for out-of-tree builds and for both kinds of installs.

The fix is to pick the correct directory based on what exists.

The script is no longer configured by cmake (just copied) so that
mechanism can be deleted from the cmake file.

Differential Revision: https://reviews.llvm.org/D93496
2020-12-17 19:08:19 -08:00
River Riddle fc5cf50e89 [mlir] Remove the MutableDictionaryAttr class
This class used to serve a few useful purposes:
* Allowed containing a null DictionaryAttr
* Provided some simple mutable API around a DictionaryAttr

The first of which is no longer an issue now that there is much better caching support for attributes in general, and a cache in the context for empty dictionaries. The second results in more trouble than it's worth because it mutates the internal dictionary on every action, leading to a potentially large number of dictionary copies. NamedAttrList is a much better alternative for the second use case, and should be modified as needed to better fit it's usage as a DictionaryAttrBuilder.

Differential Revision: https://reviews.llvm.org/D93442
2020-12-17 17:18:42 -08:00
River Riddle 1b97cdf885 [mlir][IR][NFC] Move context/location parameters of builtin Type::get methods to the start of the parameter list
This better matches the rest of the infrastructure, is much simpler, and makes it easier to move these types to being declaratively specified.

Differential Revision: https://reviews.llvm.org/D93432
2020-12-17 13:01:36 -08:00
Valentin Clement f4c8b80318 [openmp] Remove clause from OMPKinds.def and use OMP.td info
Remove the OpenMP clause information from the OMPKinds.def file and use the
information from the new OMP.td file. There is now a single source of truth for the
directives and clauses.

To avoid generate lots of specific small code from tablegen, the macros previously
used in OMPKinds.def are generated almost as identical. This can be polished and
possibly removed in a further patch.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D92955
2020-12-17 14:08:12 -05:00
Valentin Clement 71699a998d [flang][openacc] Enforce restriction on routine directive and clauses
This patch add some checks for the restriction on the routine directive
and fix several issue at the same time.

Validity tests have been added in a separate file than acc-clause-validity.f90 since this one
became quite large. I plan to split the larger file once on-going review are done.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D92672
2020-12-17 11:33:34 -05:00
Valentin Clement 36bf2de8d8 [flang][openacc] Update serial construct clauses for OpenACC 3.1
Update the allowed clauses for the SERIAL construct for the new OpenACC 3.1
specification.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D92123
2020-12-17 10:50:47 -05:00
sameeran joshi a4e47cd185 [Flang][openmp]Fix crash in OpenMP semantic check( bug 48308)
Fixes the bug reported in https://bugs.llvm.org/show_bug.cgi?id=48308

Reviewed By: kiranchandramohan, clementval

Differential Revision: https://reviews.llvm.org/D92638
2020-12-17 15:17:13 +05:30
Peter Steinfeld 4e90cad6a6 [flang] Handle undeclared names in EQUIVALENCE statements
Names in EQUIVALENCE statements are only allowed to indicate local
objects as per 19.5.1.4, paragraph 2, item (10).  Thus, a name appearing
in an EQUIVALENCE statement with no corresponding declaration in the
same scope is an implicit declaration of the name.  If that scope
contains an IMPLICIT NONE, it's an error.

I implemented this by adding a state variable to ScopeHandler to
indicate if we're resolving the names in an EQUIVALENCE statement and
then checked this state when resolving names.  I also added a test to
the existing tests for EQUIVALENCE statements.

Differential Revision: https://reviews.llvm.org/D93345
2020-12-16 11:04:27 -08:00
peter klausler 0775131058 [flang] Fix crash in folding (#48437)
Elemental intrinsic function folding was not taking the lower
bounds of constant array arguments into account; these lower bounds
can be distinct from 1 when named constants appear as arguments.

LLVM bugzilla #48437.

Differential Revision: https://reviews.llvm.org/D93321
2020-12-16 07:55:44 -08:00
Tim Keith 7082de56b7 [flang] Handle multiple names for same operator
Some operators have more than one name, e.g. operator(==), operator(.eq).
That was working correctly in generic definitions but they can also
appear in other contexts: USE statements and access statements, for
example.

This changes FindInScope to always look for each of the names for
a symbol. So an operator may be use-associated under one name but
declared private under another name and it will be the same symbol.
This replaces GenericSpecInfo::FindInScope which was only usable in
some cases.

Add a version of FindInScope() that looks in the current scope to
simplify many of the calls.

Differential Revision: https://reviews.llvm.org/D93344
2020-12-16 07:06:55 -08:00
peter klausler 6aa3591e98 [flang] Implement STORAGE_SIZE(), SIZEOF(), C_SIZEOF()
STORAGE_SIZE() is a standard inquiry intrinsic (size in bits
of an array element of the same type as the argument); SIZEOF()
is a common extension that returns the size in bytes of its
argument; C_SIZEOF() is a renaming of SIZEOF() in module ISO_C_BINDING.

STORAGE_SIZE() and SIZEOF() are implemented via rewrites to
expressions; these expressions will be constant when the necessary
type parameters and bounds are also constant.

Code to calculate the sizes of types (with and without alignment)
was isolated into Evaluate/type.* and /characteristics.*.
Code in Semantics/compute-offsets.* to calculate sizes and alignments
of derived types' scopes was exposed so that it can be called at type
instantiation time (earlier than before) so that these inquiry intrinsics
could be called from specification expressions.

Differential Revision: https://reviews.llvm.org/D93322
2020-12-15 17:26:20 -08:00
peter klausler d6a74ec826 [flang] Fix false error message for "ptr => func()" array conformance
Pointers must have deferred shapes, so CheckConformance must be
extended to allow for them.

Differential Revision: https://reviews.llvm.org/D93320
2020-12-15 16:26:18 -08:00
Tim Keith 3a0352b85c [flang] Fix bug with USE of USE of generic
When merging use associations into a generic, we weren't handling
the case where the name that was use associated was itself a use
association. This is fixed by following that association to its
ultimate symbol (`useUltimate` in `DoAddUse`).

An example of the bug is `m12d` in `resolve17.f90`. `g` is associated
with `gc` in `m12c` which is associated with `gb` in `m12b`. It was that
last association that we weren't correctly following.

Differential Revision: https://reviews.llvm.org/D93343
2020-12-15 16:11:59 -08:00
peter klausler 9a883bfa11 [flang] Clean up TODO comments and fix one (DATA constant ambiguity)
Remove resolved & moot TODO comments in Common/, Parser/,
and Evaluate/.  Address a pending one relating to parsing
ambiguity in DATA statement constants, handling it with
symbol table information in Semantics and adding a test.

Differential Revision: https://reviews.llvm.org/D93323
2020-12-15 13:36:07 -08:00
peter klausler b1afbceb92 [flang] Minor fix to list-directed REAL output editing
Always emit the letter 'E' in list-directed REAL output;
the library was omitting it for exponents greater than 99,
as should be done for E and D formatting of large exponents
without an Ed exponent digit count.

Differential Revision: https://reviews.llvm.org/D93319
2020-12-15 13:04:44 -08:00
Michael Kruse 2aa4335806 [flang] Fix copy elision assumption.
Before this patch, the Restorer depended on copy elision to happen.
Without copy elision, the function ScopedSet calls the move constructor
before its dtor. The dtor will prematurely restore the reference to the
original value.

Instead of relying the compiler to not use the Restorer's copy
constructor, delete its copy and assign operators. Hence, callers cannot
move or copy a Restorer object anymore, and have to explicitly provide
the reset state. ScopedSet avoids calling move/copy operations by
relying on unnamed return value optimization, which is mandatory in
C++17.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D88797
2020-12-14 14:07:05 -06:00
Christian Sigg a1eb154421 [flang] Use mlir::OpState::operator->() to get to methods of mlir::Operation.
This is a preparation step to remove those methods from OpState.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D93194
2020-12-14 20:04:53 +01:00
Andrzej Warzynski 6bbbe4a574 [flang][driver] Fix a small bug (auto vs auto&)
This bug hasn't affected us yet as our usage is too basic, i.e. we don't
rely on the defaults provided by `SetDefaultFortranOpts` just yet. This
will change shortly.
2020-12-14 16:10:07 +00:00
sameeran joshi f1569b1ece [Flang][OpenMP-5.0] Semantic checks for flush construct.
From OMP 5.0 [2.17.8]
Restriction:
If memory-order-clause is release,acquire, or acq_rel, list items must not be specified on the flush directive.

Reviewed By: kiranchandramohan, clementval

Differential Revision: https://reviews.llvm.org/D89879
2020-12-14 13:30:48 +05:30
sameeran joshi e43b3b08cc [Flang][OpenMP] Semantic checks for Atomic construct.
Patch implements restrictions from 2.17.7  of OpenMP 5.0 standard for atomic Construct. Tests for the same are added.

One of the restriction
`OpenMP constructs may not be encountered during execution of an atomic region.`
Is mentioned in 5.0 standard to be a semantic restriction, but given the stricter nature of parser in F18 it's caught at parsing itself.

This patch is a next patch in series from D88965.

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D89583
2020-12-14 13:03:57 +05:30
Christian Sigg 1ffc1aaa09 [mlir] Use mlir::OpState::operator->() to get to methods of mlir::Operation.
This is a preparation step to remove those methods from OpState.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D93098
2020-12-13 09:58:16 +01:00
Peter Steinfeld 84c09ab445 [flang] Removed an absolute path from the "flang" script
The "flang" script that gets put into "install/bin" had an absolute path
in it.  This precuded moving the install directory to a new location.

Differential Revision: https://reviews.llvm.org/D93131
2020-12-11 14:01:59 -08:00
Irina Dobrescu c9e967af3f [flang]Add Parser Support for Allocate Directive
Differential Revision: https://reviews.llvm.org/D89562
2020-12-10 16:21:19 +00:00
Peter Steinfeld 9168a0f515 [flang] Fix bogus message on index-names in the presence of associated entities
The semantic analysis of index-names of FORALL statements looks up symbols with
the same name as the index-name.  This is needed to exclude symbols that are
not objects.  But if the symbol found is host-, use-, or construct-associated
with another entity, the check fails.

I fixed this by getting the root symbol of the symbol found and doing the check
on the root symbol.  This required creating a non-const version of
"GetAssociationRoot()".

Differential Revision: https://reviews.llvm.org/D92970
2020-12-10 07:36:41 -08:00
Christian Sigg 0bf4a82a5a [mlir] Use mlir::OpState::operator->() to get to methods of mlir::Operation. This is a preparation step to remove the corresponding methods from OpState.
Reviewed By: silvas, rriddle

Differential Revision: https://reviews.llvm.org/D92878
2020-12-09 12:11:32 +01:00
Valentin Clement b53115b6c8 [flang][openacc] Avoid use of init, shutdown and set in compute construct
init, shutdown and set directive are not allowed in compute construct.

Reviewed By: SouraVX

Differential Revision: https://reviews.llvm.org/D92443
2020-12-08 15:14:44 -05:00
Valentin Clement d553243fe4 [flang][openacc] Update reference to OpenACC 3.1 specification
Update all reference from the specification to the new OpenACC 3.1
document.

Reviewed By: SouraVX

Differential Revision: https://reviews.llvm.org/D92120
2020-12-08 14:36:38 -05:00