Commit Graph

3008 Commits

Author SHA1 Message Date
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
Valentin Clement c823d74914 [flang][openacc] Add missing loop construct restriction and validity tests
Add restriction on loop construct associated with DO CONCURRENT. Add couple of tests to ensure
clause validity checks.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D92533
2020-12-08 14:12:12 -05:00
peter klausler 4fede8bc8a [flang] Implement derived type description table encoding
Define Fortran derived types that describe the characteristics
of derived types, and instantiations of parameterized derived
types, that are of relevance to the runtime language support
library.  Define a suite of corresponding C++ structure types
for the runtime library to use to interpret instances of the
descriptions.

Create instances of these description types in Semantics as
static initializers for compiler-created objects in the scopes
that define or instantiate user derived types.

Delete obsolete code from earlier attempts to package runtime
type information.

Differential Revision: https://reviews.llvm.org/D92802
2020-12-08 10:26:58 -08:00
Valentin Clement 1dd24e6ab7 [flang][openacc] Add clause validity tests for the update directive
Add couple of clause validity tests for the update directive and check for
the restriction where at least self, host or device clause must appear on the directive.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D92447
2020-12-08 10:47:06 -05:00
peter klausler 641ede93ef [flang] Improve initializer semantics, esp. for component default values
This patch plugs many holes in static initializer semantics, improves error
messages for default initial values and other component properties in
parameterized derived type instantiations, and cleans up several small
issues noticed during development.  We now do proper scalar expansion,
folding, and type, rank, and shape conformance checking for component
default initializers in derived types and PDT instantiations.
The initial values of named constants are now guaranteed to have been folded
when installed in the symbol table, and are no longer folded or
scalar-expanded at each use in expression folding.  Semantics documentation
was extended with information about the various kinds of initializations
in Fortran and when each of them are processed in the compiler.

Some necessary concomitant changes have bulked this patch out a bit:
* contextual messages attachments, which are now produced for parameterized
  derived type instantiations so that the user can figure out which
  instance caused a problem with a component, have been added as part
  of ContextualMessages, and their implementation was debugged
* several APIs in evaluate::characteristics was changed so that a FoldingContext
  is passed as an argument rather than just its intrinsic procedure table;
  this affected client call sites in many files
* new tools in Evaluate/check-expression.cpp to determine when an Expr
  actually is a single constant value and to validate a non-pointer
  variable initializer or object component default value
* shape conformance checking has additional arguments that control
  whether scalar expansion is allowed
* several now-unused functions and data members noticed and removed
* several crashes and bogus errors exposed by testing this new code
  were fixed
* a -fdebug-stack-trace option to enable LLVM's stack tracing on
  a crash, which might be useful in the future

TL;DR: Initialization processing does more and takes place at the right
times for all of the various kinds of things that can be initialized.

Differential Review: https://reviews.llvm.org/D92783
2020-12-07 14:40:41 -08:00
Valentin Clement 875b4fd5ee [flang][openacc] Add clause validity tests for the kernels directive
Add some clause validity tests for the kernels directive

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D91873
2020-12-07 14:27:18 -05:00
Valentin Clement a366188d80 [flang][openacc] Add clause validaty tests for data construct + fix default restriction
Add clause validity tests for the data construct. The default clause can appear only once
and this was not enforce in the ACC.td.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D91888
2020-12-04 15:12:15 -05:00
clementval f99e90f2c3 Revert "[flang][openacc] Add clause validity tests for the update directive"
This reverts commit e460654334.
2020-12-04 15:06:22 -05:00
Valentin Clement e460654334 [flang][openacc] Add clause validity tests for the update directive
Add couple of clause validity tests for the update directive and check for
the restriction where at least self, host or device clause must appear on the directive.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D92447
2020-12-04 14:38:49 -05:00
Rahul Joshi fe7fdcac87 [MLIR] Fix parseFunctionLikeOp() to fail parsing empty regions
- Change parseOptionalRegion to return an OptionalParseResult.
- Change parseFunctionLikeOp() to fail parsing if the function body was parsed but was
  empty.
- See https://llvm.discourse.group/t/funcop-parsing-bug/2164

Differential Revision: https://reviews.llvm.org/D91886
2020-12-04 09:09:59 -08:00
River Riddle c7cae0e4fa [mlir][Attributes][NFC] Move all builtin Attribute classes to BuiltinAttributes.h
This mirrors the file structure of Types.

Differential Revision: https://reviews.llvm.org/D92499
2020-12-03 18:02:11 -08:00
River Riddle 09f7a55fad [mlir][Types][NFC] Move all of the builtin Type classes to BuiltinTypes.h
This is part of a larger refactoring the better congregates the builtin structures under the BuiltinDialect. This also removes the problematic "standard" naming that clashes with the "standard" dialect, which is not defined within IR/. A temporary forward is placed in StandardTypes.h to allow time for downstream users to replaced references.

Differential Revision: https://reviews.llvm.org/D92435
2020-12-03 18:02:10 -08:00
River Riddle 672cc75cce [mlir][IR] Remove references to BuiltinOps from IR/
There isn't a good reason for anything within IR to specifically reference any of the builtin operations. The only place that had a good reason in the past was AsmPrinter, but the behavior there doesn't need to hardcode ModuleOp anymore.

Differential Revision: https://reviews.llvm.org/D92448
2020-12-03 15:47:01 -08:00
Peter Steinfeld f24c642178 [flang] Fix bogus message on interface procedure argument names
We were keeping the state of parsed equivalence sets in the class
DeclarationVisitor.  A problem happened when  analyzing the the specification
part of a declaration that contained an EQUIVALENCE statement followed by an
interface block.  The same DeclarationVisitor object that was created for the
outer declaration was being used to analyze the specification part
of a procedure body in the interface block.  When analyzing the specification
part of the procedure in the interface block, the names in the outer
declaration's EQUIVALENCE statement were erroneously compared with the names in
the arguments of the interface procedure.  This resulted in a bogus error
message.

I fixed this by not checking equivalence sets when we're in an interface
block.  I also added a test that will produce an error message without
this change.

Differential Revision: https://reviews.llvm.org/D92501
2020-12-03 12:08:55 -08:00
Tim Keith 86f59de13b [flang] Fix bugs related to merging generics during USE
When the same generic name is use-associated from two modules, the
generics are merged into a single one in the current scope. This change
fixes some bugs in that process.

When a generic is merged, it can have two specific procedures with the
same name as the generic (c.f. module m7c in modfile07.f90). We were
disallowing that by checking for duplicate names in the generic rather
than duplicate symbols. Changing `namesSeen` to `symbolsSeen` in
`ResolveSpecificsInGeneric` fixes that.

We weren't including each USE of those generics in the .mod file so in
some cases they were incorrect. Extend GenericDetails to specify all
use-associated symbols that are merged into the generic. This is used to
write out .mod files correctly.

The distinguishability check for specific procedures of a generic
sometimes have to refer to procedures from a use-associated generic in
error messages. In that case we don't have the source location of the
procedure so adapt the message to say where is was use-associated from.
This requires passing the scope through the checks to make that
determination.

Differential Revision: https://reviews.llvm.org/D92492
2020-12-02 15:13:50 -08:00
Tim Keith 1f525ece4a [flang][NFC] Add GetTopLevelUnitContaining functions
`GetTopLevelUnitContaining` returns the Scope nested in the global scope
that contains the given Scope or Symbol.

Use "Get" rather than "Find" in the name because "Find" implies it might
not be found, which can't happen. Following that logic, rename
`FindProgramUnitContaining` to `GetProgramUnitContaining` and have it
also return a reference rather that a pointer.

Note that the use of "ProgramUnit" is slightly confusing. In the Fortran
standard, "program-unit" refers to what is called a "TopLevelUnit" here.
What we are calling a "ProgramUnit" (here and in `ProgramTree`) includes
internal subprograms while "TopLevelUnit" does not.

Differential Revision: https://reviews.llvm.org/D92491
2020-12-02 10:28:49 -08:00
Praveen G 7a91794d5b [Flang][OpenMP] Add semantic checks for OpenMP Private clause.
Add the semantic checks for the OpenMP 4.5 - 2.15.3.3 Private clause.

1. Pointers with the INTENT(IN) attribute may not appear in a private clause.
2. Variables that appear in namelist statements may not appear in a private clause.
   A flag 'InNamelist' is added to the Symbol::Flag to identify the symbols
   in Namelist statemnts.

Test cases : omp-private01.f90, omp-private02.f90

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D90210
2020-11-30 11:46:36 -05:00
Johannes Doerfert c557f549ba [Flang][Docs] Update call information and add two more calls
Call information have been updated and the OpenMP in LLVM as well as
Classic Flang call have been added.
2020-11-25 11:52:35 -06:00
Valentin Clement e73d8c793a [flang][openacc] Semantic check for cache directive
Add semantic check for the cache directive. According to section 2.10 from the specification:
A var in a cache directive must be a single array element or a simple subarray.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D90184
2020-11-25 10:28:14 -05:00
Yashaswini 29dffb0c8a Add Semantic check for Flang OpenMP 4.5 - 2.7.1 ordered and collapse clause
Semantic check added to check and restrict the value of the parameter in the COLLAPSE or ORDERED clause
if it is larger than the number of nested loops following the construct.

Test Cases:
omp-do-collapse-positivecases.f90
omp-do-collapse.f90
omp-do-ordered-positivecases.f90
omp-do-ordered.f90

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

Differential Revision: https://reviews.llvm.org/D89860
2020-11-22 18:38:57 +05:30
Yashaswini 3ee08e3819 Add Semantic check for Flang OpenMP 4.5 - 2.15.3.2 and 2.15.3.3 shared and private clause
Semantic check to restrict the appearance of a variable that is part of another variable
 (as an array or structure element) in a PRIVATE or SHARED clause.

Test Cases:

omp-parallel-private01.f90
omp-parallel-private02.f90
omp-parallel-private03.f90
omp-parallel-private04.f90
omp-parallel-shared01.f90
omp-parallel-shared02.f90
omp-parallel-shared03.f90
omp-parallel-shared04.f90

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

Differential Revision: https://reviews.llvm.org/D89395
2020-11-22 12:50:17 +05:30
clementval 952c9d3a91 [NFC] Fix typo in atomic 2020-11-21 14:32:31 -05:00
Valentin Clement aa179d8099 [flang][openmp] Separate memory-order-clause parser creating OmpClause node
This patch introduce the separate parser for the memory-order-clause from the general
OmpClauseList. This parser still creates OmpClause node and therefore can use all the feature
from TableGen and the OmpStructureChecker.
This is applied only for the Flush construct in this patch and it should be applied for
atomic as well.

This is the approach we disscussed several time during the weekly call.

Reviewed By: kiranchandramohan, sameeranjoshi

Differential Revision: https://reviews.llvm.org/D91839
2020-11-21 14:31:33 -05:00
sameeran joshi 1df8fa78e6 [Flang][OpenMP][NFC][2/2] Reorder OmpStructureChecker and simplify it.
`OmpStructureChecker` has too much boilerplate code in source file.

This patch:
  1. Use helpers from `check-directive-structure.h` and reduces the boilerplate.
  2. Use TableGen infrastructure as much as possible.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D90834
2020-11-21 22:37:35 +05:30
sameeran joshi 42ecf188b5 [flang][openmp] Fix bug in `OmpClause::Hint` clause which was missing to generate inside in OMP.cpp.inc file.
Before this patch "Hint" isn't found inside the generated file.
./bin/llvm-tblgen --gen-directive-gen ../llvm-project/llvm/include/llvm/Frontend/OpenMP/OMP.td -I ../llvm-project/llvm/include/ > OMP.cpp.in

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D91909
2020-11-21 19:02:34 +05:30
Valentin Clement 553e364194 [flang][openacc] Add clause validity tests for the host_data directive
Add some clause validity tests for the host_data directive to avoid future regressions.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D91889
2020-11-20 20:17:37 -05:00
Valentin Clement 755674b715 [flang][openacc] Add clause validity tests for the parallel directive
Add some clause validity tests for parallel directive.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D91871
2020-11-20 20:05:10 -05:00
Pete Steinfeld da02327b9c
Update OptionComparison.md 2020-11-20 10:33:21 -08:00
Andrzej Warzynski 1b749c0cb5 [flang][driver] Remove unnecessary CMake dependencies (nfc)
Remove clangFrontend from the list of dependencies. These should have
been removed in: 8d51d37e06. See also
https://reviews.llvm.org/D87774.
2020-11-20 16:44:11 +00:00
River Riddle 65fcddff24 [mlir][BuiltinDialect] Resolve comments from D91571
* Move ops to a BuiltinOps.h
* Add file comments
2020-11-19 11:12:49 -08:00
peter klausler 5349f99114 [flang] Correct handling of null pointer initializers
Fortran defines "null-init" null pointer initializers as
being function references, syntactically, that have to resolve
to calls to the intrinsic function NULL() with no actual
arguments.

Differential revision: https://reviews.llvm.org/D91657
2020-11-18 13:57:25 -08:00
Peter Steinfeld ea4973f206 [flang] Improve error message on bad LOGICAL compare operations
When comparing LOGICAL operands using ".eq." or ".ne." we were not
guiding users to the ".eqv." and ".neqv." operations.

Differential Revision: https://reviews.llvm.org/D91736
2020-11-18 13:53:29 -08:00
Peter Steinfeld 3fd7774033 [flang] Fix FIR test failures
When doing out-of-tree builds, FIR tests were failing.  I made a change
similar to the one by @jurahul to fix this.

Differential Revision: https://reviews.llvm.org/D91654
2020-11-17 12:25:15 -08:00
Andrzej Warzynski e8356a79ff [flang][nfc] Add missing dependency in CMake
This missing dependency has been causing the Flang buildbots
(with BUILD_SHARED_LIBS set to ON) to fail:
  * http://lab.llvm.org:8011/#/builders/66/builds/542
  * http://lab.llvm.org:8011/#/builders/33/builds/764

This missing dependency was exposed by this change:
  * https://reviews.llvm.org/D91461
This change is fine - the root cause of the failing builds is the
missing dependency.
2020-11-17 14:32:39 +00:00
River Riddle 73ca690df8 [mlir][NFC] Remove references to Module.h and Function.h
These includes have been deprecated in favor of BuiltinDialect.h, which contains the definitions of ModuleOp and FuncOp.

Differential Revision: https://reviews.llvm.org/D91572
2020-11-17 00:55:47 -08:00
Peter Steinfeld 681978d3b4 [flang] Duplicate names for ac-implied-do variables erroneously cause errors
According to section 19.4, paragraph 5, the scope of an ac-implied-do variable
is the enclosing ac-implied-do.  But we were not creating new scopes upon
entry to an ac-implied-do.  This was causing error messages to be erroneously
emitted.

I fixed, the code, added a test to array-constr-values.f90, added the test
folding15.f90 and corrected the test symbol05.f90.

Differential Revision: https://reviews.llvm.org/D91560
2020-11-16 18:57:13 -08:00
Rahul Joshi ba3317d0ba Fix flang MLIR unit test verification failures
- Eliminate public function declarations in these tests
2020-11-16 17:32:28 -08:00
Praveen G 2e26459fab [Flang][OpenMP] Add semantic checks for OpenMP Depend clause.
Add the semantic checks for the OpenMP 4.5 - 2.13.9 Depend clause.

1. List items in depend clause should not be zero length array sections.
2. A variable that is part of another variable like structure component
   should not be specified on a depend clause.

Test cases : omp-depend01.f90, omp-depend02.f90, omp-depend03.f90

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D89934
2020-11-16 13:11:28 -05:00
peter klausler df62afd559 [flang] Unsplit COMPLEX operations
COMPLEX negation, addition, subtraction, conversions of kind, and
equality/inequality were represented as component-wise REAL
operations.  It turns out to be easier for lowering if we
do not split and recombine these COMPLEX operations, and it
avoids a potential problem with COMPLEX valued function calls
in these contexts.  So add this suite of operations to the
typed expression representation in place of the component-wise
transformations, and support them in folding.

Differential revision: https://reviews.llvm.org/D91443
2020-11-16 09:39:03 -08:00
Andrzej Warzynski 6c02835d6c [flang][f18] Remove "-fdebug-resolve-names"
This option doesn't enable any unique feature/code-patch. Also, it is
neither tested nor documented.

Differential Revision: https://reviews.llvm.org/D91537
2020-11-16 15:49:55 +00:00
Peter Steinfeld 5795a81cba [flang] Fix "EQ" comparison of arrays
When comparing arrays whose shapes do not conform, the contant folding
code ran into problems trying to get the value of an extent that did not
exist.  There were actually two problems.  First, the routine
"CheckConformance()" was returning "true" when the compiler was unable
to get the extent of an array.  Second, the function
"ApplyElementwise()" was calling "CheckConformance()" prior to folding
the elements of two arrays, but it was ignoring the return value.

Differential Revision: https://reviews.llvm.org/D91440
2020-11-13 15:18:13 -08:00
peter klausler c2bccd66f6 [flang] Document DO CONCURRENT's problems (NFC)
Differential Revision: https://reviews.llvm.org/D86556
2020-11-12 15:30:43 -08:00
peter klausler 04a147987a [flang] Include source information in an invalid file-unit-number message
An io-unit that is an internal-file-variable is syntactically identical
to a file-unit-number expression that is a variable reference.  An
ambiguous unit is initially parsed as an internal-file-variable.  If
semantic analysis determines that the unit is not of character type,
it is rewritten as an internal-file-variable.  This modification must
retain source coordinate information.

Differential revision: https://reviews.llvm.org/D91375
2020-11-12 13:12:17 -08:00
peter klausler 6c516cda39 [flang] Recognize END FILE as ENDFILE in free form source
The ENDFILE statement may be spelled as two words.

Differential revision: https://reviews.llvm.org/D91377
2020-11-12 12:46:04 -08:00
peter klausler 3ce5f95716 fix clang build 2020-11-12 11:38:20 -08:00
peter klausler 8df28f0aa3 [flang] Implement runtime support for basic ALLOCATE/DEALLOCATE
Add error reporting infrastructure and support for ALLOCATE
and DEALLOCATE statements of intrinsic types without SOURCE=
or MOLD=.

Differential revision: https://reviews.llvm.org/D91215
2020-11-12 10:21:40 -08:00
peter klausler cc575dd2ce [flang][MSVC] Use list<Message> rather than forward_list<> in Messages
The implementation of Messages with forward_list<> makes some
nonstandard assumptions about the validity of iterators that don't
hold up with MSVC's implementation.  Use list<> instead.  The
measured performance is comparable.

This change obviated a distinction between two member functions
of Messages, and the uses of one have been replaced with calls
to the other.

Similar usage in CharBuffer was also replaced for consistency.

Differential revision: https://reviews.llvm.org/D91210
2020-11-11 16:38:38 -08:00
peter klausler 67b13e9785 [flang] Fix CheckSpecificationExpr handling of associated names
Avoid a spurious error message about a dummy procedure reference
in a specification expression by restructuring the handling of
use-associated and host-associated symbols.

Updated to fix a circular dependence between shared library
binaries that was introduced by the original patch.

Differential revision: https://reviews.llvm.org/D91286
2020-11-11 13:51:42 -08:00
peter klausler b781a04f6a [flang] Allow labels on END statements.
F18 clause 5.3.3 explicitly allows labels on program unit END statements.
Label resolution code accounts for this for singleton program units,
but incorrectly generates an error for host subprograms with internal
subprograms.

   subroutine s(n)
      call s1(n)
      if (n == 0) goto 88 ! incorrect error
      print*, 's'
   contains
      subroutine s1(n)
         if (n == 0) goto 77 ! ok
         print*, 's1'
   77 end subroutine s1
   88 end

Label resolution code makes a sequential pass over an entire file to
collect label information for all subprograms, followed by a pass through
that information for semantics checks.  The problem is that END statements
may be separated from prior subprogram code by internal subprogram
definitions, so an END label can be associated with the wrong subprogram.

There are several ways to fix this.  Labels are always local to a
subprogram.  So the two separate passes over the entire file could probably
instead be interleaved to perform analysis on a subprogram as soon as the
end of the subprogram is reached, using a small stack.  The stack structure
would account for the "split" code case.  This might work.

It is possible that there is some not otherwise apparent advantage to
the current full-file pass design.  The parse tree has productions that
provide access to a subprogram END statement "in advance".  An alternative
is to access this information to solve the problem.  This PR implements
this latter option.

Differential revision: https://reviews.llvm.org/D91217
2020-11-11 13:06:19 -08:00
peter klausler 2d5b850751 [flang] Use IMPLICIT from scope of external function reference
Implicitly typed references to external functions are applying
the IMPLICIT typing rules of the global scope in which their
symbols were created, not the IMPLICIT typing rules in force in
the scope from which they were referenced.

Differential revision: https://reviews.llvm.org/D91214
2020-11-11 12:12:24 -08:00
peter klausler 29fa451870 [flang] Add isnan() extension intrinsic function, with folding
It's nonstandard, but commonly implemented.

Differential revision: https://reviews.llvm.org/D91213
2020-11-11 11:40:57 -08:00
Andrzej Warzynski fdbc7e505c [flang][driver] Make sure that `-###` is marked as supported (NFC)
`-###` has always been supported in the new flang driver. This patch
merely makes sure that it's included when printing the help screen (i.e.
`flang-new -help`).
2020-11-11 13:12:51 +00:00
Andrzej Warzynski eae2d63571 Revert "[flang] Fix CheckSpecificationExpr handling of associated names"
This reverts commit b670189975.

This patch causes shared library builds (BUILD_SHARED_LIBS=ON) to fail:
* http://lab.llvm.org:8011/#/builders/33/builds/626

I wasn't able to identify any easy fix, hence reverting.
2020-11-11 11:33:16 +00:00
Yashaswini c3b1395384 Add Semantic check for Flang OpenMP 4.5 - 2.7.1 schedule clause
Semantic check for the positive chunk size.

Test Cases:
omp-do-schedule01.f90
omp-do-schedule02.f90
omp-do-schedule03.f90
omp-do-schedule04.f90

Reviewed by: Kiran Chandramohan @kiranchandramohan

Differential Revision: https://reviews.llvm.org/D89546
2020-11-11 15:56:18 +05:30
peter klausler b670189975 [flang] Fix CheckSpecificationExpr handling of associated names
Avoid a spurious error message about a dummy procedure reference
in a specification expression by restructuring the handling of
use-associated and host-associated symbols.

Differential revision: https://reviews.llvm.org/D91209
2020-11-10 16:19:13 -08:00
sameeran joshi 2f7a41b2a7 [Flang][OpenMP] Fix 'Internal: no symbol found' for OpenMP aligned and linear clause.
The initial approach was to go with changing parser nodes from `std::list<parser::Name>` to `OmpObjectList`, but that might have lead to illegal programs.
Resolving the symbols inside `OmpAttributeVisitor`.
Fix a couple of `XFAIL` tests.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D90538
2020-11-10 22:47:13 +05:30
sameeran joshi 7282d9e170 [Flang][Docs] Fix warnings when building docs.
Following warning were seen with recommonmark(0.5.0) and sphinx(1.8.5).
`parser.py:75: UserWarning: Container node skipped: type=document warn("Container node skipped: type={0}".format(mdnode.t))`

The warnings are due to an issue in recommonmark's(a python package) older versions.
A better solution is to use the latest version of recommonmark(>=0.6.0) to avoid
these issue in the first place.
This patch fixes the warnings for older versions.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D91117
2020-11-10 22:24:49 +05:30
Peter Steinfeld 66a9607557 [flang] Avoid calling the linker when "-c" option is used
The title says it all.
2020-11-09 10:22:13 -08:00
Valentin Clement 9914a8737f [flang][openacc] Add parsing tests and semantic check for set directive
This patch add some parsing and clause validity tests for the set directive.
It makes use of the possibility introduces in patch D90770 to check the restriction
were one of the default_async, device_num and device_type clauses is required but also
not more than once on the set directive.

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D90771
2020-11-05 22:57:58 -05:00
Andrzej Warzynski 93c94139e6 [flang][f18] Remove unimplemented options (NFC)
These options are in practice passes to the external tool (defined with
F18_FC), i.e. fall into "unrecognised" category. No need to keep them
among other options that are actually parsed.
2020-11-05 18:35:35 +00:00
Andrzej Warzynski a7bcb3b9eb [Flang][f18] Remove unimplemented options from `flang -help` (NFC) 2020-11-05 12:47:42 +00:00
Alex Zinenko cc2a2bb5ce [flang] update ODS syntax to use OpBuidlerDAG instead of OpBuilder
Upstream MLIR has deprecated OpBuilder in ODS.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D90226
2020-11-05 09:28:20 +01:00
Valentin Clement 1dad9d4282 [flang][openacc] Lower wait directive
This patch upstream the lowering of Wait directive that was initially done in
https://github.com/flang-compiler/f18-llvm-project/pull/532

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D90489
2020-11-04 21:15:52 -05:00
Valentin Clement 4ec7f7e45a [flang][openacc] Lower init and shutdown directive
This patch upstream the lowering of Init and Shutdown directives that was initially done in
https://github.com/flang-compiler/f18-llvm-project/pull/529

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D90488
2020-11-04 19:30:46 -05:00
Valentin Clement b45ea4451a [flang][openacc] Lower update directive
This patch upstream the lowering of Update directive that was initially done in
https://github.com/flang-compiler/f18-llvm-project/pull/528

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D90472
2020-11-04 15:48:07 -05:00
Valentin Clement c71adeff24 [flang][openacc] Lower enter data directive
This patch upstream the lowering of Enter Data directive that was initially done in
https://github.com/flang-compiler/f18-llvm-project/pull/526

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D90470
2020-11-04 15:17:50 -05:00
Valentin Clement 2e73a1f9fa [flang][openacc] Lower exit data directive
This patch upstream the lowering of Exit Data construct that was initially done in
https://github.com/flang-compiler/f18-llvm-project/pull/527

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D90467
2020-11-04 14:34:43 -05:00
Praveen G a4a4c50370 [Flang][OpenMP] Add semantic checks for OpenMP copyin clause.
Add the semantic checks for the OpenMP 4.5 - 2.15.4.1 copyin clause.

Resolve OpenMPThreadprivate directive since the list of items specified
in copyin clause should be threadprivate.

Test cases : omp-copyin01.f90, omp-copyin02.f90, omp-copyin03.f90,
             omp-copyin04.f90, omp-copyin05.f90

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D89385
2020-11-04 03:12:35 -05:00
peter klausler 7ba393efe5 [flang] Dodge gcc 8.2.0 build problem (NFC)
Add explicit member initializers to the declarations of
some constexpr values added in a recent patch to avoid an
apparent problem with gcc 8.2.0 with default initializers.

Differential revision: https://reviews.llvm.org/D90696
2020-11-03 16:31:15 -08:00
Sameeran joshi 855a32d9e5 [Flang][OpenMP][NFC][1/2] Reorder OmpStructureChecker and simplify it.
`OmpStructureChecker` has too much boilerplate code in source file.
It was not easy to figure out the seperation of clauses inside 'OmpClause' and
the ones which had a seperate node in parse-tree.h.

This patch:
1. Removes the boilerplate by defining a few macros.
2. Makes seperation between constructs, directives and clauses(sub classes are seperated).
3. Macros could have been shared between OMP and OACC, template specilizations might have
   been costly hence used macros.
Follows the same strategy used for `AccStructureChecker`.

Next patch in series to simplify OmpStructureChecker would try to simplify
boilerplates inside the functions and either create abstractions or use if
something is available inside check-directive-structure.h

Reviewed By: kiranchandramohan, clementval

Differential Revision: https://reviews.llvm.org/D90324
2020-11-03 11:50:32 +05:30
peter klausler 934b27a9da [flang] Fix actual argument character length and length error reporting
Ensure that character length is properly calculated for
actual arguments to intrinsics, and that source provenance
information is available when expression analysis calls
folding in cases where the length is invalid.

Differential revision: https://reviews.llvm.org/D90636
2020-11-02 13:39:15 -08:00
peter klausler e8f96899e1 [flang] Allow array constructor implied DO loop indices as constant expressions
When the bounds of an implied DO loop in an array constructor are
constant, the index variable of that loop is considered a constant
expression and can be used as such in the items in the value list
of the implied DO loop.  Since the KIND type parameter values of items
in the value list can depend on the various values taken by such an
index, it is not possible to represent those values with a single
typed expression.  So implement such loops by taking multiple passes
over the parse tree of the implied DO loop instead.

Differential revision: https://reviews.llvm.org/D90494
2020-11-02 11:00:17 -08:00
peter klausler 8fc07fed32 [flang] Design document for runtime derived type descriptions (NFC)
Differential revision: https://reviews.llvm.org/D90500
2020-11-02 09:23:22 -08:00
Caroline Concatto d28de0d7f2 [Flang][Driver] Add PrintPreprocessedInput FrontendAction (`flang-new -E`)
This patch implements the first frontend action for the Flang parser (i.e.
Fortran::parser). This action runs the preprocessor and is invoked with the
`-E` flag. (i.e. `flang-new -E <input-file>). The generated output is printed
to either stdout or the output file (specified with `-` or `-o <output-file>`).

Note that currently there is no mechanism to map options for the
frontend driver (i.e. Fortran::frontend::FrontendOptions) to options for
the parser (i.e. Fortran::parser::Options). Instead,
Frotran::parser::options are hard-coded to:

```
std::vector<std::string> searchDirectories{"."s};
searchDirectories = searchDirectories;
isFixedForm = false;
_encoding(Fortran::parser::Encoding::UTF_8);
```

These default settings are compatible with the current Flang driver. Further
work is required in order for CompilerInvocation to read and map
clang::driver::options to Fortran::parser::options.

Co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com>

Differential Revision: https://reviews.llvm.org/D88381
2020-11-02 14:03:35 +00:00
Andrzej Warzynski 9ffb5b0469 [flang][driver] Rename the accessors/mutators (NFC)
As per point 3 in [1]:

```
Accessor member functions are named with the non-public data member's
name, less the trailing underscore.  Mutator member functions are named
set_...
```

Originally we just followed the LLVM's style, which is incompatible with
Flang. This patch renames the accessors and mutators accordingly.

`getDiagnostics` and `GetDiagnostics` are replaced with one accessor:
`diagnostics`. `SetDiagnostics` was neither implemented nor used, so
it's deleted.

[1] https://github.com/llvm/llvm-project/blob/master/flang/docs/C++style.md#naming

Differential Revision: https://reviews.llvm.org/D90300
2020-11-02 10:55:13 +00:00
Andrzej Warzynski 1ed2ca6819 [flang][driver] Use --match-full-lines in tests for `-test-io`
Use `--match-full-lines` to make sure that FileCheck doesn't match the
output against the `CHECK` lines (which, like other comments, are also
printed).

More specifically, we want to make sure that the following `check` in the
input file:
```
! CHECK: <some-fortran-input>
```
is matched by FileCheck with `<some-fortran-input>` in the generated
output. Without `--match-full-lines`, that check-line will be matched
with `!CHECK:  <some-fortran-input>` instead (which is also
printed together with other contents of the file).

Adding `--match-full-lines` makes the tests stricter and this change
revealed that some `check`s were passing only because that flag was
missing. These are updated accordingly.

Reviewed By: CarolineConcatto, sameeranjoshi

Differential Revision: https://reviews.llvm.org/D90306
2020-11-02 10:00:42 +00:00
peter klausler 93d10919c8 [flang] Plug error recovery hole for erroneous subscripts
Avoid a crash in folding an empty vector of subscripts
that resulted from a semantic error.

Differential revision: https://reviews.llvm.org/D90499
2020-10-30 17:32:27 -07:00
peter klausler 882fa241f1 [flang] Better error messages & more cases caught for bad forward refs
Subclause 10.1.12 in F'2018 prohibits forward references from
a specification expression to an object declared later in the
same specification part.  Catch this error better and emit
specific error messages about the violation.

Differential revision: https://reviews.llvm.org/D90492
2020-10-30 17:11:37 -07:00
peter klausler c1168676a0 [flang] Add warning for FINAL pitfall
Fortran's FINAL feature is sensitive to object rank.
When an object's rank excludes it from finalization, but
the type has FINAL subroutines for other ranks, emit
a warning.  This should be especially helpful in the
case of a scalar FINAL subroutine not being declared
(IMPURE) ELEMENTAL.

Differential revision: https://reviews.llvm.org/D90495
2020-10-30 16:42:12 -07:00
peter klausler 4acd8f7f0a [flang] Detect and rewrite ambiguous READ(CVAR)[,item-list]
READ(CVAR)[,item-list] with a character variable CVAR
could be parsed as an unformatted READ from an internal
unit or as a formatted READ from the default external unit
with a needlessly parenthesized variable format.  We parse
it as the former, but Fortran doesn't have unformatted
internal I/O.

Differential revision: https://reviews.llvm.org/D90493
2020-10-30 15:47:28 -07:00
Andrzej Warzynski b7d1271a01 [Flang] Fix build failures (NFC)
Some changes introduced in https://reviews.llvm.org/D88655 cause compiler
warnings. Since in Flang warnings are treated as errors (`-Werror` is on by
default), these are in practice compiler errors (verified with clang-10 and
clang-11, gcc-10). This patches fixes these warning/failures.

Warning/error 1:
```
llvm-project/flang/lib/Semantics/check-omp-structure.cpp:107:3: error:
unannotated fall-through between switch labels [-Werror,-Wimplicit-fallthrough]
```

Warning/error 2:
```
llvm-project/flang/lib/Semantics/check-directive-structure.h:39:9: error: field
'currentDirective_' will be initialized after field 'upperCaseDirName_'
[-Werror,-Wreorder-ctor]
```

Failing buildbot:
* http://lab.llvm.org:8011/#/builders/33/builds/386
2020-10-30 11:50:13 +00:00
sameeran joshi 61f11f807c [Flang][OpenMP][OpenACC] Fix exit out of a region in OpenMP parallel construct.
From below mentioned standard references
OpenACC 3.0 Standards document
840 • A program may not branch into or out of an OpenACC parallel construct

OpenMP 5.0 Standards document
A program that branches into or out of a parallel region is non-conforming.

This patch
Resolves the issue of exit out of a parallel region, other branching out issues like goto statements are not handled with this patch.
Moves code from D87906 to be reused by other OpenMP/OpenACC to check-directive-structure.h.
Adds support in OpenMP parallel construct and a test case to verify.

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D88655
2020-10-30 11:03:30 +05:30
Valentin Clement 75ba29ac56 [flang][openacc] Enforce no modifier on enter data and exit data clauses
Enter data can have the copyin clause and exit data can have the copyout clause.
Both clauses support modifier with other directive but for these two directives no modifier
are supported. This semantic check enforce this rule.

Reviewed By: kiranktp

Differential Revision: https://reviews.llvm.org/D90280
2020-10-29 09:53:22 -04:00
Valentin Clement 990222931b [flang][openacc] Fix ambiguity in the self clause parsing
In the OpenACC specification, there are two different self clause. One for the
update directive with a var-list argument. This clause is a synonym of the host clause.
The second self clause is present for most of the compute construct and takes an optional
condition. To solve this ambiguity, the self clause for the update directive is directly
translated to a host clause during the parsing. The self clause in AccClause refers always
to the compute construct clause.

Reviewed By: kiranktp

Differential Revision: https://reviews.llvm.org/D90185
2020-10-27 21:10:00 -04:00
Yashaswini Hegde 3fa20baf00 [Flang][OpenMP 4.5] Add semantic check for OpenMP default clause 2020-10-27 12:38:47 -04:00
Jean Perier 878b526409 [flang] Tighten rules to resolve procedure as intrinsic procedure
2 Bug fixes:

- Do not resolve procedure as intrinsic if they appeared in an
  EXTERNAL attribute statement (one path was not considering this flag)

- Emit an error if a procedure resolved to be an intrinsic function
  (resp. subroutine) is used as a subroutine (resp. function).
  Lowering was attempted while the evaluate::Expression for the
  call was missing without any errors.

1 behavior change:

- Do not implicitly resolve subroutines (resp. functions) as intrinsics
  because their name is the name of an intrinsic function (resp.
  subroutine). Add justification in documentation.

Reviewed By: klausler, tskeith

Differential Revision: https://reviews.llvm.org/D90049
2020-10-26 11:25:40 +01:00
Andrzej Warzynski cbb7f1420b [flang][tests] Fix Python bug in the lit config
Without this change LIT tests for Flang fail with:
```
TypeError: append() takes exactly one argument (2 given)
```
2020-10-24 17:04:25 +01:00
Caroline Concatto 4c5906cffd [Flang][Driver] Add infrastructure for basic frontend actions and file I/O
This patch introduces the dependencies required to read and manage input files
provided by the command line option. It also adds the infrastructure to create
and write to output files. The output is sent to either stdout or a file
(specified with the `-o` flag).

Separately, in order to be able to test the code for file I/O, it adds
infrastructure to create frontend actions. As a basic testable example, it adds
the `InputOutputTest` FrontendAction. The sole purpose of this action is to
read a file from the command line and print it either to stdout or the output
file.  This action is run by using the `-test-io` flag also introduced in this
patch (available for `flang-new` and `flang-new -fc1`). With this patch:
```
flang-new -test-io input-file.f90
```
will read input-file.f90 and print it in the output file.

The `InputOutputTest` frontend action has been introduced primarily to
facilitate testing. It is hidden from users (i.e. it's only displayed with
`--help-hidden`). Currently Clang doesn’t have an equivalent action.

`-test-io` is used to trigger the InputOutputTest action in the Flang frontend
driver. This patch makes sure that “flang-new” forwards it to “flang-new -fc1"
by creating a preprocessor job. However, in Flang.cpp, `-test-io` is passed to
“flang-new -fc1” without `-E`. This way we make sure that the preprocessor is
_not_ run in the frontend driver. This is the desired behaviour: `-test-io`
should only read the input file and print it to the output stream.

co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com>

Differential Revision: https://reviews.llvm.org/D87989
2020-10-24 14:58:32 +01:00
Michael Kruse d590c85430 [flang] Fix pimpl idiom for IntrinsicProcTable.
The class IntrinsicProcTable uses the pimpl idiom and manages its own pointer-to-implementation.  However, it violates the rule-of-five and does not implement a move-constructor or assignment-operator. Due to differences between compilers in implementation copy elision, these may or may not be used. Due to the missing user implementation for resource handling, using the results in runtime errors.

Fix my using `std::unique_ptr` instead of custom resource management.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D88794
2020-10-24 00:28:05 -05:00
Michael Kruse 0b671a44ad [flang][msvc] Fix lambda capture ambiguity. NFC.
Patch D88695 introduces a new local variable inside a lambda with the same name as a variable outside of it. In some of the if constexpr regions, msvc prioritizes the outer declaration and emits the error.
```
C:\Users\meinersbur\src\llvm-project\flang\lib\Evaluate\fold-implementation.h(1200): error C3493: 'context' cannot be implicitly captured because no default capture mode has been specified
```

This is fixed by giving the inner variable a different name.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D89367
2020-10-23 22:58:40 -05:00
Michael Kruse b57937861f [flang][windows] Support platform-specific path separator.
Remove the assumption that the path separator is `/`. Use functions from `llvm::sys::path` instead.

Reviewed By: isuruf, klausler

Differential Revision: https://reviews.llvm.org/D89369
2020-10-23 22:22:37 -05:00
Peter Steinfeld b6b589ca84 [flang] An erroneous type bound procedure was causing a call to CHECK()
I added a test to verify that the associated symbol did not have errors before
doing the anaylsis of a call to a component ref along with a test that
triggers the original problem.

Differential Revision: https://reviews.llvm.org/D90074
2020-10-23 13:53:58 -07:00
Sourabh Singh Tomar e7d37742a2 [flang][OpenMP] Upstream lowering of OpenMP `Flush` construct
Note: This patch reflects the work that can be upstreamed from PR's(merged):

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

Reviewed By: kiranchandramohan, clementval

Differential Revision: https://reviews.llvm.org/D90048
2020-10-23 21:09:50 +05:30
Sourabh Singh Tomar 1d328446bf [flang][OpenMP] Upstream lowering of `ParallelOp` clauses
Note: This patch reflects the work that can be upstreamed from PR's(merged):

1. https://github.com/flang-compiler/f18-llvm-project/pull/456
2. https://github.com/flang-compiler/f18-llvm-project/pull/485

Also replaced TODO with new TODO.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D89769
2020-10-23 20:21:39 +05:30
Valentin Clement 676ff75d60 [flang][openacc] Fix semantic check for wait and atomic directives
wait and atomic directives are represented by OpenACCWaitConstruct, OpenACCAtmicConstruct in the parser. Those contrsuct were
not taken into account in the semantic check so far.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D88628
2020-10-23 10:31:50 -04:00
Peter Steinfeld 6b66f1cd9b [flang] Another validity of the TARGET= argument of ASSOCIATED() for objects
In my previous implementation of the semantic checks for ASSOCIATED(), I
had neglected to check the TARGET= argument for objects to ensure that
it has either the POINTER or TARGET attributes.

I added an implementation and a test.

Differential Revision: https://reviews.llvm.org/D89717
2020-10-21 10:17:27 -07:00
Peter Steinfeld 29d838310d [flang] Fix call to CHECK() on erroneous subroutine declaration
When processing declarations in resolve-names.cpp, we were returning a
symbol that had SubprogramName details to PushSubprogramScope(), which
expects a symbol with Subprogram details.

I adjusted the code and added a test.

Differential Revision: https://reviews.llvm.org/D89829
2020-10-20 18:09:15 -07:00
Jean Perier 29d1a49447 [flang] Document and use intrinsic subroutine argument intents
Check INTENT(OUT)/INTENT(INOUT) constraints for actual argument
of intrinsic procedure calls.
- Adding a common::Intent field to the IntrinsicDummyArgument
in the intrinsic table.
- Propagating it to the DummyDataObject intent field so that it can
later be used in CheckExplicitDataArg semantic checks.
- Add related tests.
- Fix regression (C846 false error), C846 INTENT(OUT) rule does
  not apply to intrinsic call. Propagate the information that we
  are in an intrinsic call up to CheckExplicitDataArg (that is
  doing this check). Still enforce C846 on intrinsics other than MOVE_ALLOC (for which
  allocatable coarrays are explicitly allowed) since it's not clear it is allowed in all
  intrinsics and allowing this would lead to runtime penalties in the intrinsic runtime.

Differential Revision: https://reviews.llvm.org/D89473
2020-10-20 14:09:46 +02:00
Valentin Clement 340181f29a [flang][openacc] Switch to use TODO from D88909
Use the Todo.h header file introduce in D88909 to marke part of the lowering that are
not done yet.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D88915
2020-10-19 14:47:37 -04:00
sameeran joshi 4a51691a85 [Flang][OpenACC] Fix for branching out issue in OpenACC parallel construct.
From OpenACC 3.0 Standards document
	840 • A program may not branch into or out of an OpenACC parallel construct.
	Exits are allowed provided it does not cause an exit outside the parallel region.

	Test case exits out of the inner do loop, but it is still inside the parallel region.
	Patch tries to extract labels from block attached to a construct,
	If the exit is to a label not in the collected list then flags an error.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D87906
2020-10-19 21:46:47 +05:30
Peter Steinfeld 0047f6aed3 [flang] Add name match checks for interface procedures
We had neglected to check for name mismatches for procedure definitions that
appear in interfaces.

I also changed label11.f90 to an error test since I think they're better than
"FileCheck" tests.

Differential Revision: https://reviews.llvm.org/D89611
2020-10-19 07:51:17 -07:00
Peter Steinfeld f2897b8f45 [flang] Disallow pointer constants
None of the other Fortran compilers allow them.

Differential Revision: https://reviews.llvm.org/D89581
2020-10-16 12:31:42 -07:00
Peter Steinfeld c757418869 [flang] Failed call to CHECK() for call to ASSOCIATED(NULL())
Calling "ASSOCATED(NULL()) was causing an internal check of the compiler to
fail.

I fixed this by changing the entry for "ASSOCIATED" in the intrinsics table to
accept "AnyPointer" which contains a new "KindCode" of "pointerType".  I also
changed the function "FromActual()" to return a typeless intrinsic when called
on a pointer, which duplicates its behavior for BOZ literals.  This required
changing the analysis of procedure arguments.  While testing processing for
procedure arguments, I found another bad call to `CHECK()` which I fixed.

I made several other changes:
  -- I implemented constant folding for ASSOCIATED().
  -- I fixed handling of NULL() in relational operations.
  -- I implemented semantic analysis for ASSOCIATED().
    -- I noticed that the semantics for ASSOCIATED() are similar to those for
       pointer assignment.  So I extracted the code that pointer assignment uses
       for procedure pointer compatibility to a place where it could be used by
       the semantic analysis for ASSOCIATED().
    -- I couldn't figure out how to make the general semantic analysis for
       procedure arguments work with ASSOCIATED()'s second argument, which can
       be either a pointer or a target.  So I stopped using normal semantic
       analysis for arguments for ASSOCIATED().
  -- I added tests for all of this.

Differential Revision: https://reviews.llvm.org/D88313
2020-10-16 07:12:57 -07:00
peter klausler 2aad6a0884 [flang][msvc] Avoid a reinterpret_cast
The call to the binary->decimal formatter in real.cpp was cheating
by using a reinterpret_cast<> to extract its binary value.
Use a more principled and portable approach by extending the
API of evaluate::Integer<> to include ToUInt<>()/ToSInt<>()
member function templates that do the "right" thing.  Retain
ToUInt64()/ToSInt64() for compatibility.

Differential revision: https://reviews.llvm.org/D89435
2020-10-15 10:38:48 -07:00
Serge Guelton 50df5f24dc [flang] Fix build with BUILD_SHARED_LIBS=ON and FLANG_BUILD_NEW_DRIVER=ON
As usual, it's difficult to handle all different configuration in the first row,
but this one has been extensively tested

Differential Revision: https://reviews.llvm.org/D89452
2020-10-15 13:03:55 +02:00
Andrzej Warzynski 42e89ab2a6 [flang] Fix CMake bug in the definition of flang-new
Recent patch that improved Flang's compatibility with respect to how LLVM
dynamic libraries should be linked (and specified in CMake recipes),
introduced a bug in the definition of `flang-new`:
  * https://reviews.llvm.org/D87893
More specifically, `add_flang_tool` does not support the
`LINK_COMPONENTS` CMake argument.  Instead, one should set
`LLVM_LINK_COMPONENTS` before calling `add_flang_tool`.

This patch reverts the change for `flang-new` from
https://reviews.llvm.org/D87893, and instead:
  * sets `LLVM_LINK_COMPONENTS`
  * calls `clang_target_link_libraries` to add Clang dependencies

Differential Revision: https://reviews.llvm.org/D89403
2020-10-14 19:24:10 +01:00
Irina Dobrescu 65b9b9aa50 Add Allocate Clause to MLIR Parallel Operation Definition
Differential Revision: https://reviews.llvm.org/D87684
2020-10-14 17:13:48 +01:00
Jean Perier 94d9a4fd88 [flang] Rework host runtime folding and enable REAL(2) folding with it.
- Rework the host runtime table so that it is constexpr to avoid
  having to construct it and to store/propagate it.
- Make the interface simpler (remove many templates and a file)
- Enable 16bits float folding using 32bits float host runtime
- Move StaticMultimapView into its own header to use it for host
  folding

Reviewed By: klausler, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D88981
2020-10-14 16:40:44 +02:00
Serge Guelton cde06f783c [flang] Make flang build compatible with LLVM dylib
Harmonize usage of LLVM components througout Flang.

Explicit LLVM Libs where used across several CMakeFIles, which led to
incompatibilities with LLVM shlibs.
Fortunately, the LLVM component system can be relied on to harmoniously handle
both cases.

Differential Revision: https://reviews.llvm.org/D87893
2020-10-14 14:27:25 +02:00
sameeran joshi 3291041641 [Flang][OpenMP] Fix issue in only a single nowait clause can appear on a sections directive.
The OpenMP 5.0 standard restricts nowait clause to appear only once on sections
directive.
See OpenMP 5.0
  - 2.8.1
  - point 3 in restrictions.

Added a test with fix.

Reviewed By: DavidTruby

Differential Revision: https://reviews.llvm.org/D88556
2020-10-14 16:22:57 +05:30
sameeran joshi d95d3d2a42 [Flang][OpenMP] Rework parser changes for OpenMP atomic construct.
`OmpStructureChecker` is supposed to work only with `parser::OmpClause`
after tablegen changes for OpenMP and OpenACC were introduced.
Hence `OmpMemoryOrderClause`, `OmpAtomicMemoryOrderClause` and similar ones were failing
to catch semantic errors, inspite of having code for semantic checks.
This patch tries to change parser for `OmpMemoryOrderClause` and similar dependent ones
and use `OmpClauseList` which resides/comes from common tablegen for OpenMP/OpenACC eventually using `parser::OmpClause`.

This patch also tries to :
1. Change `OmpCriticalDirective` in `openmp-parsers.cpp` to support `OmpClauseList`.
2. Check-flang regresses when changes were introduced due to missing semantic checks in OmpCritical, patch implements them at the minimal level to pass the regression.
3. Change tablegen to support Hint clause.
4. Adds missing source locations `CharBlock Source` in each atomic construct.
5. Remove dead code realted to `memory-order-clauses` after moving to `OmpClauseList`.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D88965
2020-10-14 14:19:49 +05:30
Valentin Clement 388d373294 [flang][openacc] Lower data construct
This patch upstream the lowering of Data construct that was initially done in
https://github.com/flang-compiler/f18-llvm-project/pull/460.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D88918
2020-10-12 15:04:06 -04:00
brett koonce f09587c64c update .txt --> .md links 2020-10-12 20:49:51 +02:00
Valentin Clement e944455eaf [flang][openacc] Lower parallel construct
This patch upstream the lowering of Parallel construct that was initially done in
https://github.com/flang-compiler/f18-llvm-project/pull/460.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D88917
2020-10-12 13:23:23 -04:00
Valentin Clement 726a6e84be [flang][openacc] Update Loop Construct lowering to use fir::getBase
This patch update the loop construct lowring to match fir-dev changes.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D88914
2020-10-12 13:19:57 -04:00
Mehdi Amini 16580d791f Remove -gen-pass-doc from Flang CMake configuration: the documentation generation is broken
`ninja mlir-doc` fails when Flang is configured with this.
2020-10-09 06:17:53 +00:00
peter klausler 3e86eda18c [flang] Allow "name: value" in compiler directives
Some legacy compiler directives use colons rather than
equals signs.

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

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

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

Differential revision: https://reviews.llvm.org/D88752
2020-10-07 15:12:08 -07:00
peter klausler 88afb6e867 [flang] Semantic checks for bad usage of whole assumed-size arrays
The semantics pass currently checks for several constraints
that apply to the use of whole assumed-size arrays in various
contexts, but C1002 wasn't really implemented.  This patch
implements C1002 by disallowing the use of whole assumed-size
arrays in expressions and variables unless specifically
allowed by the context.  This centralizes the error reporting,
which has been improved with a link to the array's declaration.

Differential revision: https://reviews.llvm.org/D88691
2020-10-07 14:42:36 -07:00
Valentin Clement 2f40e20613 [flang][openacc] Fix device_num and device_type clauses for init directive
This patch fix the device_num and device_type clauses used in the init clause. device_num was not
spelled correctly in the parser and was to restrictive with scalarIntConstantExpr instead of scalarIntExpr.
device_type is now taking a list of ScalarIntExpr.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D88571
2020-10-06 21:27:01 -04:00
Eric Schweitz 0f8294072f [NFC][flang] Add the header file Todo.h. This file is being upstreamed to satisfy dependencies and enable continued progress on lowering of OpenMP, OpenACC, etc.
Differential Revision: https://reviews.llvm.org/D88909
2020-10-06 11:31:46 -07:00
peter klausler 53bf28b80c [flang] Track CHARACTER length better in TypeAndShape
CHARACTER length expressions were not always being
captured or computed as part of procedure "characteristics",
leading to test failures due to an inability to compute
memory size expressions accurately.

Differential revision: https://reviews.llvm.org/D88689
2020-10-06 08:45:46 -07:00
Andrzej Warzynski 25692b7765 [flang][NFC] Remove redundant `;`
Sadly this has been causing gcc-10 builds to fail.
2020-10-06 08:45:53 +01:00
peter klausler 567462b48e [flang] Correct kP scaling on F output
The sign of the scaling factor was misinterpreted for output
as meaning what it does for input.  To be correct, they
should cancel each other out.

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

Differential revision: https://reviews.llvm.org/D88610
2020-10-05 13:58:42 -07:00
peter klausler 07cb4c013c [flang] Make binary->decimal conversion buffer sizes accurate
The binary values that produce the most significant decimal
digits in an exact conversion are those with the least normal
biased exponent (1) and all fractional bits set, not the
least-valued subnormals.  So the binary->decimal conversion
buffer sizes were a little short, and could cause a overrun crash.

Differential revision: https://reviews.llvm.org/D88688
2020-10-05 13:11:58 -07:00
Andrzej Warzynski 8d51d37e06 [flang] Introduce DiagnosticConsumer classes in libflangFrontend
Currently Flang uses TextDiagnostic, TextDiagnosticPrinter &
TestDiagnosticBuffer classes from Clang (more specifically, from
libclangFrontend). This patch introduces simplified equivalents of these
classes in Flang (i.e. it removes the dependency on libclangFrontend).

Flang only needs these diagnostics classes for the compiler driver
diagnostics. This is unlike in Clang in which similar diagnostic classes
are used for e.g. Lexing/Parsing/Sema diagnostics. For this reason, the
implementations introduced here are relatively basic. We can extend them
in the future if this is required.

This patch also enhances how the diagnostics are printed. In particular,
this is the diagnostic that you'd get _before_  the changes introduced here
(no text formatting):

```
$ bin/flang-new
error: no input files
```

This is the diagnostic that you get _after_ the changes introduced here
(in terminals that support it, the text is formatted - bold + red):

```
$ bin/flang-new
flang-new: error: no input files
```

Tests are updated accordingly and options related to enabling/disabling
color diagnostics are flagged as supported by Flang.

Reviewed By: sameeranjoshi, CarolineConcatto

Differential Revision: https://reviews.llvm.org/D87774
2020-10-05 17:46:44 +01:00
Andrzej Warzynski 35a2a042dd [flang][NFC] Fix build errors for clang-10
This patch fixes one worning. Since Flang sets `-Werror`, that's
sufficient for a build to fail. As per flang/README.md, Clang-10 is one
of the officially supported compilers.

Differential Revision: https://reviews.llvm.org/D88723
2020-10-03 15:10:17 +01:00
Tim Keith 11622d0fed [flang][NFC] Fix mis-matched struct/class declarations
The template `ListDirectedStatementState` was declared as a struct and then as a class.
Fix it so they match.

Differential Revision: https://reviews.llvm.org/D88711
2020-10-02 13:08:51 -07:00
Valentin Clement c1dcb573a8 [flang][openacc] Update loop construct lowering
Update the loop construct lowering to support multiple occurences of the same clauses
such as private. Add some utility functions used by other constructs.

Upstreaming part of https://github.com/flang-compiler/f18-llvm-project/pull/438/

Reviewed By: schweitz

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

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

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

Differential revision: https://reviews.llvm.org/D88612
2020-10-01 16:57:38 -07:00
peter klausler 75a5ec1bad [flang][msvc] Rework a MSVC work-around to avoid clang warning
A recent MSVC work-around patch is eliciting unused variable
warnings from clang; package the lambda reference arguments
into a struct to avoid the warning.

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

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

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

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

Differential revision: https://reviews.llvm.org/D88672
2020-10-01 09:58:04 -07:00
Valentin Clement 91b49fc257 [flang][openacc] Fix unparsing of combined construct (bug 47659)
This patch fixes the bug report in https://bugs.llvm.org/show_bug.cgi?id=47659

Reviewed By: sameeranjoshi

Differential Revision: https://reviews.llvm.org/D88597
2020-10-01 10:35:06 -04:00
Michael Kruse d4a1db4f3f [flang][msvc] Workaround 'forgotten' symbols in FoldOperation. NFC.
This resolves an issue where the Microsoft compiler 'forgets' symbols when using constexpr in a lambda in a templated function. The symbols are:

1. The implicit lambda captures `context` and `convert`. Fix by making them explicit captures. The error message was:
```
fold-implementation.h(1220): error C2065: 'convert': undeclared identifier
```

2. The function template argument FROMCAT. Fix by storing it in a temporary constexpr variable inside the function. The error message was:
```
fold-implementation.h(1216): error C2065: 'FROMCAT': undeclared identifier
```

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

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D88504
2020-09-30 21:28:34 -05:00
Michael Kruse b656189e6a [flang][msvc] Avoid ReferenceVariantBase ctor ambiguity. NFC.
Msvc reports the following error when a ReferenceVariantBase is constructed using an r-value reference or instantiated as std::vector template parameter.  The error message is:
```
PFTBuilder.h(59,1): error C2665: 'std::variant<...>::variant': none of the 2 overloads could convert all the argument types
variant(1248,1): message : could be 'std::variant<...>::variant(std::variant<...> &&) noexcept(false)'
variant(1248,1): message : or       'std::variant<...>::variant(const std::variant<...> &) noexcept(false)'
PFTBuilder.h(59,1): message : while trying to match the argument list '(common::Reference<lower::pft::ReferenceVariantBase<false,...>>)'
```

Work around the ambiguity by only taking `common::Reference` arguments in the constructor. That is, conversion to common::Reference has to be done be the caller instead of being done inside the ctor. Unfortunately, with this change clang/gcc (but not msvc) insist on that the ReferenceVariantBase is stored in a `std::initializer_list`-initialized variable before being used, like being passed to a function or returned.

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

Reviewed By: DavidTruby

Differential Revision: https://reviews.llvm.org/D88109
2020-09-30 20:54:09 -05:00
peter klausler 4fb679d3b1 [flang] Fix Gw.d format output
The estimation of the decimal exponent needs to allow for all
'd' of the requested significant digits.

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

Differential revision: https://reviews.llvm.org/D88618
2020-09-30 18:02:25 -07:00
Geoffrey Martin-Noble d4e889f1f5 Remove `Ops` suffix from dialect library names
Dialects include more than just ops, so this suffix is outdated. Follows
discussion in
https://llvm.discourse.group/t/rfc-canonical-file-paths-to-dialects/621

Reviewed By: stellaraccident

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

Differential revision: https://reviews.llvm.org/D88607
2020-09-30 17:16:55 -07:00
peter klausler 37b2e2b04c [flang] Semantic analysis for FINAL subroutines
Represent FINAL subroutines in the symbol table entries of
derived types.  Enforce constraints.  Update tests that have
inadvertent violations or modified messages.  Added a test.

The specific procedure distinguishability checking code for generics
was used to enforce distinguishability of FINAL procedures.
(Also cleaned up some confusion and redundancy noticed in the
type compatibility infrastructure while digging into that area.)

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

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

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

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D88508
2020-09-29 17:01:36 -05:00
Michael Kruse b5543063e1 [flang][msvc] Define implicit conversion from UnsignedInt128 to int64_t.
The custom implementation of UnsignedInt128 has an implicit conversion operator to unit64_t, but not int64_t. Considering that the former is already truncating, and C++ implicitly converts uint64_t to int64_t, UnsignedInt128  should also support an implicit conversion to int64_t. An analogous conversion would be from uint32_t to int16_t.

Without the conversion operator overload, the msvc emits the following error:
```
descriptor-io.h(44): error C2440: 'static_cast': cannot convert from 'A' to 'int64_t'
        with
        [
            A=Fortran::common::uint128_t
        ]
```

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

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D88509
2020-09-29 16:41:46 -05:00
Michael Kruse d2d7a44fac [flang][msvc] Avoid templated initializer list initialization of vector. NFC.
The Microsoft compiler emits an error when populating the vector with a single element of a templated argument using the brace syntax. The error is:
```
constant.h(102,1): error C2664: 'std::vector<Fortran::evaluate::value::Complex<...>, ...>::vector(std::initializer_list<_Ty>,const _Alloc &)': cannot convert argument 1 from 'initializer list' to 'std::initializer_list<_Ty>'
```
To work around this error, we replace the templated constructor with one for the expected type. Conversion to the element type has to be done by the caller.

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

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D88163
2020-09-29 11:40:42 -05:00
Riccardo Bertossa c2921d148e [flang] SAVE statement should not apply to nested scoping units
SAVE statement, according to 8.6.14, must apply to the same scoping
unit, that excludes nested scoping units. For example, if the SAVE
statement is found in a MODULE, the functions contained in that module
should not inherit the SAVE attribute. I think that the code was doing
this, failing the following source:

```
MODULE pippo
SAVE

CONTAINS
PURE FUNCTION fft_stick_index( )
   IMPLICIT NONE
   INTEGER :: fft_stick_index
   INTEGER :: mc  !error: A pure subprogram may not have a variable with the SAVE attribute
END FUNCTION

END MODULE
```

Differential Revision: https://reviews.llvm.org/D88279
2020-09-26 12:42:14 -07:00
Sourabh Singh Tomar d2f1f53043 [flang][OpenMP] Place the insertion point to the start of the block
After skeleton of the `Parallel Op` is created set the insertion point to start of the block. So that later `CodeGen` can proceed.

Note: This patch reflects the work that can be upstreamed from PR(merged)
PR: https://github.com/flang-compiler/f18-llvm-project/pull/424

Reviewed By: schweitz, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D88221
2020-09-25 23:56:41 +05:30
Andrzej Warzynski 6f10998ad8 [flang][driver] Add missing dependency (shared library builds, NFC)
`FlangFrontendTests` depends on libclangFrontend (it uses
DiagnosticConsumer classes from there). This patch adds the missing
dependency in CMake.

The missing dependency manifests itself only with BUILD_SHARED_LIBS=ON.
This symbol is linked in statically with libflangFrontend when
BUILD_SHARED_LIBS=OFF.
2020-09-25 09:52:49 +01:00
Andrzej Warzynski b9a2837f16 [flang][driver] Add missing dependency (shared library builds, NFC)
`flang-new` depends on libclangFrontend (it uses DiagnosticConsumer
classes from there). This patch adds the missing dependency in CMake.

clang::TextDiagnosticBuffer is only reported as missing when compiling
`flang-new` with BUILD_SHARED_LIBS=ON. This symbol is linked in
statically with libflangFrontend when BUILD_SHARED_LIBS=OFF.
2020-09-24 21:11:32 +01:00
Praveen G 956a84da06 [flang] [OpenMP 4.5] Adding lit test cases for OpenMP Constructs.
1. Section 2.5   : Parallel Construct
 2. Section 2.7.1 : Loop Construct
 3. Section 2.7.2 : Sections Construct
 4. Section 2.7.3 : Single Construct
 5. Section 2.7.4 : Workshare Construct
 6. Section 2.8.1 : Simd Construct
 7. Section 2.8.3 : Loop Simd Construct
 8. Section 2.9.1 : Task Construct
 9. Section 2.9.2 : Taskloop Construct
10. Section 2.9.3 : Taskloop Simd Construct

Most of the test cases added as part of this change contains semantic errors except few cases which are semantically correct but thrown a semantic error.

Currently flang is not throwing the errors for these cases and throwing semantic errors for the following correct test cases

{omp-do03.f90 , omp-loop-simd01.f90 , omp-simd02.f90 , omp-taskloop01.f90}

Hence, all the test cases are marked as XFAIL.

Reviewed By: DavidTruby

Differential Revision: https://reviews.llvm.org/D87908
2020-09-24 13:09:20 +01:00
Andrzej Warzynski 10c94d8cf8 [flang][driver] Remove unnecessary includes in the unittest (NFC)
Differential Revision: https://reviews.llvm.org/D88219
2020-09-24 13:03:58 +01:00
Andrzej Warzynski 27da287507 [flang][NFC] Fix CMake variable name in README.md
The CMake variable for the new flang driver is FLANG_BUILD_NEW_DRIVER
rather than BUILD_FLANG_NEW_DRIVER.
2020-09-24 09:39:20 +01:00
Andrzej Warzynski 2f90e01a96 [flang][driver] Add missing dependency in CMake files
The Flang driver depends on libclangBasic. This means, among other
things, that some of the tablegen files (e.g. diagnostic definitions)
need to be generated before various libclangBasic header files can be
included (e.g. DiagnosticIDs.h). If we are lucky, libclangBasic is
indeed built before various flang driver libraries that depend on it
are. This patch makes sure that this is deterministic - i.e.
libclangBasic is built before the Flang driver libraries are.

Differential Revision: https://reviews.llvm.org/D88110
2020-09-24 09:32:16 +01:00
Andrzej Warzynski 99edb9b79c [flang][driver] Fix options flag in the frontend driver
In the frontend driver we should be using FC1Option (frontend driver
options) instead of FlangOption (flang driver options).

Differential Revision: https://reviews.llvm.org/D88108
2020-09-24 08:44:26 +01:00
Sourabh Singh Tomar dfa9065ad7 [NFCI][flang] Renamed a variable name to a more descriptive name 2020-09-23 18:21:05 +05:30
Sourabh Singh Tomar be1197c403 [flang] Removed OpenMP lowering unittests
These tests aren't adding much value and consensus has been reached for
there removal.
For more context, please refer to discussion in this revision:
https://reviews.llvm.org/D87846
2020-09-23 18:15:34 +05:30
Sourabh Singh Tomar 34b08487f0 [OpenMP][flang]Lower NUM_THREADS clause for parallel construct
This patch reflects the work that can be upstreamed from PR(merged)
PR: https://github.com/flang-compiler/f18-llvm-project/pull/411

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D87846
2020-09-23 17:57:25 +05:30
Jean Perier bd72ed93d2 [flang] CHARACTER(*) return does not require explicit interface
Fortran 2018 15.4.2.2(4)(c) says nonassumed or explicit non-constant
length parameter require explicit interface. The "nonassumed" part was
missing in f18 characteristic analysis causing CanBeCalledViaImplicitInterface
to return false for `CHARACTER(*) function foo()` like interfaces.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D88075
2020-09-23 13:38:10 +02:00
Michael Kruse 62afc3129d [flang][msvc] Explicitly reference "this" inside closure. NFC.
The Microsoft compiler seems to have difficulties to decide between a const/non-const method of a captured object context in a closure. The error message is:
```
symbol.cpp(261): error C2668: 'Fortran::semantics::Symbol::detailsIf': ambiguous call to overloaded function
symbol.h(535): note: could be 'const D *Fortran::semantics::Symbol::detailsIf<Fortran::semantics::DerivedTypeDetails>(void) const'
symbol.h(534): note: or       'D *Fortran::semantics::Symbol::detailsIf<Fortran::semantics::DerivedTypeDetails>(void)'
symbol.cpp(261): note: while trying to match the argument list '()'
```
Explicitly using the this-pointer resolves this problem.

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

Reviewed By: DavidTruby

Differential Revision: https://reviews.llvm.org/D88052
2020-09-22 14:22:08 -05:00
Michael Kruse 97ca41e1dd [flang][msvc] Add explicit function template argument to applyLamda. NFC.
Like in D87961, msvc has difficulties deducing the template argument. The error message is:
```
expr-parsers.cpp(383): error C2672: 'applyLambda': no matching overloaded function found
```
Explicitly pass the first template argument to help it.

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

Reviewed By: DavidTruby

Differential Revision: https://reviews.llvm.org/D88001
2020-09-22 14:22:08 -05:00
Michael Kruse 2bc589bbb8 [flang][msvc] Add explicit function template argument to applyFunction. NFC.
Msvc has difficulties deducing the template argument here. The error message is:
```
basic-parsers.h(790,12): error C2672: 'applyFunction': no matching overloaded function found
```
Explicitly pass the first template argument to help it.

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

Reviewed By: DavidTruby

Differential Revision: https://reviews.llvm.org/D87961
2020-09-22 14:22:08 -05:00
Dave Lee b36bdfe5ca [cmake] Centralize LLVM_ENABLE_WARNINGS option
Configure default value of `LLVM_ENABLE_WARNINGS` in `HandleLLVMOptions.cmake`.

`LLVM_ENABLE_WARNINGS` is documented as ON by default, but `HandleLLVMOptions` assumes the default has been set somewhere else. If it has not been explicitly set, then `HandleLLVMOptions` implicitly uses OFF as a default.

This removes the various `option()` declarations in favor of a single declaration in `HandleLLVMOptions`. This will prevent the unwanted use of `-w` that is mentioned in a couple of the comments.

Reviewed By: DavidTruby, #libunwind, JDevlieghere, compnerd

Differential Revision: https://reviews.llvm.org/D87243
2020-09-21 10:23:17 -07:00
serge-sans-paille 2a77441117 Do not dereference an array out of bound just to take its address
This is UB by the standard, and caught by the libstdc++ asserts

Differential Revision: https://reviews.llvm.org/D87892
2020-09-21 12:08:30 +02:00
SuJunda 000eb1f314 [docs][flang] Fix typos
Reviewed By: SouraVX

Differential Revision: https://reviews.llvm.org/D87885
2020-09-21 11:05:58 +05:30