Commit graph

33 commits

Author SHA1 Message Date
Tim Keith
c37707a5b1 [flang] Move various Instantiate functions to tools.cc
Move these functions from scope.cc, symbol.cc, type.cc into tools.cc:
  Scope::FindOrInstantiateDerivedType
  Scope::InstantiateDerivedType
  Scope::InstantiateIntrinsicType
  Symbol::Instantiate
  DerivedTypeSpec::ProcessParameterExpressions
  DerivedTypeSpec::Instantiate

This eliminates some dependencies in these files on SemanticsContext,
FoldingContext, etc.

It also allows three of the functions to be private to tools.cc
because they are only called from the others.

Original-commit: flang-compiler/f18@48c6efbf95
Reviewed-on: https://github.com/flang-compiler/f18/pull/559
Tree-same-pre-rewrite: false
2019-07-11 08:51:40 -07:00
Peter Steinfeld
5b7b8866b8 [flang] Improved the implementation of "IsCoarray()" suggested by @tskeith.
Original-commit: flang-compiler/f18@efaf5fca2e
Reviewed-on: https://github.com/flang-compiler/f18/pull/542
2019-07-03 13:59:44 -07:00
Peter Steinfeld
02a395dcb7 [flang] Changes in response to comments on pull request flang-compiler/f18#542.
Original-commit: flang-compiler/f18@e156f977d8
Reviewed-on: https://github.com/flang-compiler/f18/pull/542
Tree-same-pre-rewrite: false
2019-07-03 13:50:57 -07:00
Peter Steinfeld
84b70d8b73 [flang] Enforce constraint C1128 for DO CONCURRENT locality-spec's
These changes implement most of the requirements for C1128, which says: "A
variable-name that appears in a LOCAL or LOCAL_INIT locality-spec shall not
have the ALLOCATABLE; INTENT (IN); or OPTIONAL attribute; shall not be of
finalizable type; shall not be a nonpointer polymorphic dummy argument; and
shall not be a coarray or an assumed-size array.  A variable-name that is not
permitted to appear in a variable definition context shall not appear in a
LOCAL or LOCAL_INIT locality-spec."

The changes do not implement the checking required to determine whether a
variable can appear in a "variable definition context".

Here's a summary of the changes:
 - I created the function 'PassesLocalityChecks()' to enforce C1128 along with
   C1124, C1125, and C1126.
 - I cleaned up the code to check if a type or symbol is a coarray.
 - I added functions to tools.[h,cc] to test if a symbol is OPTIONAL, INTENT
   IN, finalizable, a coarray, or an assumed size array.  Should these be
   member functions of the type "Symbol"?
 - Since I changed one of the locality related error messages, I needed to
   change the test resolve35.f90.
 - I added the test resolve55.f90 to test all of the checks implemented in this
   update.

Original-commit: flang-compiler/f18@4ca5d090b9
Reviewed-on: https://github.com/flang-compiler/f18/pull/542
Tree-same-pre-rewrite: false
2019-07-03 13:50:56 -07:00
Tim Keith
fe899298d0 [flang] Check constraints on passed-object dummy argument
The passed-object dummy argument cannot be checked until the
interfaces of contained subprograms are known. To accomplish this,
add `FinishSpecificationPart` pass to run after all specification
parts have been analyzed but before any of the execution parts.
This visits all derived types defined in each scope and performs
the checks on each procedure component and procedure binding.

Add a flag to `ParamValue` to distinguish kind from len parameters.

Fix some tests that had errors we now detect.

Original-commit: flang-compiler/f18@4789643c5b
Reviewed-on: https://github.com/flang-compiler/f18/pull/521
2019-06-23 10:59:32 -07:00
Tim Keith
377914d8b3 [flang] Add IsIsoCType()
It identifies the types `C_PTR` and `C_FUNPTR` from predefined
module `ISO_C_BINDING`.

Original-commit: flang-compiler/f18@fcbef2e18b
Reviewed-on: https://github.com/flang-compiler/f18/pull/521
Tree-same-pre-rewrite: false
2019-06-21 17:32:11 -07:00
Tim Keith
9ef62dbb6a [flang] Resolve and check names in equivalence sets
Collect sets of `parser::EquivalenceObject` to process at the end of
the specification part. This is so that names mentioned in the
EQUIVALENCE statement don't trigger implicit declarations.

The `EquivalenceSets` class performs most of the numerous checks
on objects that can be in equivalence sets at all and objects that
can be in them together. It also merges sets when the same object
appears in more than one.

Once equivalence sets are checked they are added to the `Scope`.
Further checks will be necessary after the size and alignment of
variables are computed.

Add `FindUltimateComponent` to simplify checks on ultimate components
of derived types. Use it to implement `HasCoarrayUltimateComponent`
and checks on equivalence objects.

Make `ExpressionAnalyzer::Analyze(Designator)` public so that
`parser::EquivalenceObject` can be analyzed.

Add `GetDefaultKind`, `doublePrecisionKind`, and `quadPrecisionKind`
to `SemanticsContext` so that `defaultKinds_` does not need to be
accessed directly.

Original-commit: flang-compiler/f18@1cc898e5b8
Reviewed-on: https://github.com/flang-compiler/f18/pull/494
Tree-same-pre-rewrite: false
2019-06-11 18:26:48 -07:00
Peter Steinfeld
169b8272e8 [flang] These are additional changes for issue 458, to perform semantic checks on DO
variable and initial, final, and step expressions.

Here's a summary of the changes since my original pull request:

 - I've taken into account the possibility that the DO variable is declared in
   a MODULE.  This required a call to GetUltimate() on the Symbol for the DO
   variable.
 - The previous change exposed problems in the semantic checking for NULLIFY
   and DEALLOCATE statements, so I've included fixes and tests for those.  I
   also added a test for the ALLOCATE statement, even though it was already
   handling this case.
 - I now handle the case where a procedure name is erroneously used as a DO variable.
 - I now handle the case where a pointer to a procedure is erroneously used as
   a DO variable.
 - I now check that the DO expressions are not null.
 - I added tests for all cases listed above.

Original-commit: flang-compiler/f18@219d856fdb
Reviewed-on: https://github.com/flang-compiler/f18/pull/478
Tree-same-pre-rewrite: false
2019-06-10 13:31:31 -07:00
peter klausler
0ddea8ae24 [flang] Rearrange references to AllSources singleton, fix FindScope for module files
Original-commit: flang-compiler/f18@50ccc1c819
Reviewed-on: https://github.com/flang-compiler/f18/pull/477
Tree-same-pre-rewrite: false
2019-06-04 13:37:09 -07:00
peter klausler
d29530e1c4 [flang] Defer conversions to objects; fix some intrinsic table entries
more fixes

Access components of constant structures

Apply implicit typing to dummy args used in automatic array dimensions

SELECTED_INT_KIND and SELECTED_REAL_KIND

Finish SELECTED_{INT,REAL}_KIND and common cases of ALL()/ANY()

Original-commit: flang-compiler/f18@e9f8e53e55
Reviewed-on: https://github.com/flang-compiler/f18/pull/472
Tree-same-pre-rewrite: false
2019-05-28 13:29:29 -07:00
peter klausler
59342b0641 [flang] work in progress
checkpoint: changes build, tests all pass

many fixes, ready to test more

Further CLASS(*) support

More fixes for CLASS(*)

Hide data members of DynamicType

implement PRESENT() intrinsic

Original-commit: flang-compiler/f18@044ba12c20
Reviewed-on: https://github.com/flang-compiler/f18/pull/466
Tree-same-pre-rewrite: false
2019-05-20 13:37:28 -07:00
Jean Perier
c67710e5ae [flang] Allocate semantic checks (second part)
Implement semantic checks and realted tests for constraints:
C937, C938, C939, C940, C941, C942, C945 (second part),
C946, C947, C948, C949 and C950.

Original-commit: flang-compiler/f18@b4965d272b
Tree-same-pre-rewrite: false
2019-05-03 00:45:22 -07:00
peter klausler
25e6f03443 [flang] lib/evaluate work for structure constructors
Original-commit: flang-compiler/f18@76a192f9c9
Reviewed-on: https://github.com/flang-compiler/f18/pull/439
2019-05-03 11:29:15 -07:00
Tim Keith
776145492f [flang] Move HasError, SetError to SemanticsContext
Move HasError and SetError into SemanticsContext so that we can do
consistency checks: if a symbol has an error or we want to set the
error flag, check that an error has been reported.

Original-commit: flang-compiler/f18@4f6e3a04ca
Reviewed-on: https://github.com/flang-compiler/f18/pull/429
2019-04-25 14:47:39 -07:00
Tim Keith
0df7fa0496 [flang] Continue semantic checking after name resolution error
When an error occurs in name resolution, continue semantic processing
in order to detect other errors. This means we can no longer assume
that every `parser::Name` has a symbol even after name resolution
completes. In `RewriteMutator`, only report internal error for unresolved
symbol if there have been no fatal errors.

Add `Error` flag to `Symbol` to indicate that an error occcurred related
to it. Once we report an error about a symbol we should avoid reporting
any more to prevent cascading errors. Add `HasError()` and `SetError()`
to simplify working with this flag.

Change some places that we assume that a `parser::Name` has a non-null
symbol. There are probably more.

`resolve-names.cc`: Set the `Error` flag when we report a fatal error
related to a symbol. (This requires making some symbols non-const.)
Remove `CheckScalarIntegerType()` as `ExprChecker` will take care of
those constraints if they are expressed in the parse tree. One exception
to that is the name in a `ConcurrentControl`. Explicitly perform that
check using `EvaluateExpr()` and constraint classes so we get consistent
error messages.

In expression analysis, when a constraint is violated (like `Scalar<>`
or `Integer<>`), reset the wrapped expression so that we don't assume it
is valid. A `GenericExprWrapper` holding a std::nullopt indicates error.
Change `EnforceTypeConstraint()` to return false when the constraint
fails to enable this.

check-do-concurrent.cc: Reorganize the Gather*VariableNames functions
into one to simplify the task of filtering out unresolved names. Remove
`CheckNoDuplicates()` and `CheckNoCollisions()` as those checks is
already done in name resolution when the names are added to the scope.

Original-commit: flang-compiler/f18@bcdb679405
Reviewed-on: https://github.com/flang-compiler/f18/pull/429
Tree-same-pre-rewrite: false
2019-04-25 13:18:33 -07:00
peter klausler
68d89b6383 [flang] Add some utility functions to semantics/tools
Original-commit: flang-compiler/f18@59006b3a5c
Reviewed-on: https://github.com/flang-compiler/f18/pull/421
2019-04-22 09:25:24 -07:00
Tim Keith
2107b223cb [flang] Use SomeExpr rather than GenericExprWrapper in checkers
Use GetExpr in checker classes to get analyzed expressions out of parse
tree nodes. Don't assume that they are always present. Change the
utility functions in tools.h to use SomeExpr rather than
GenericExprWrapper.

Original-commit: flang-compiler/f18@594e30d462
Reviewed-on: https://github.com/flang-compiler/f18/pull/422
Tree-same-pre-rewrite: false
2019-04-19 08:22:28 -07:00
Paul Osmialowski
306873e7a8 [flang] Semantics checker for STOP and ERROR STOP statements - one more batch of post-review tweaks
Signed-off-by: Paul Osmialowski <pawel.osmialowski@arm.com>

Original-commit: flang-compiler/f18@f49ee0df05
Reviewed-on: https://github.com/flang-compiler/f18/pull/367
Tree-same-pre-rewrite: false
2019-04-17 14:13:23 -07:00
Paul Osmialowski
a8dabf752d [flang] Semantics checker for STOP and ERROR STOP statements - remove one more function from tools
Signed-off-by: Paul Osmialowski <pawel.osmialowski@arm.com>

Original-commit: flang-compiler/f18@9937b524fa
Reviewed-on: https://github.com/flang-compiler/f18/pull/367
Tree-same-pre-rewrite: false
2019-04-17 14:13:23 -07:00
Paul Osmialowski
9579f55836 [flang] Semantics checker for STOP and ERROR STOP statements - remove tools function not needed after recent commit
Signed-off-by: Paul Osmialowski <pawel.osmialowski@arm.com>

Original-commit: flang-compiler/f18@1a3dbd9752
Reviewed-on: https://github.com/flang-compiler/f18/pull/367
Tree-same-pre-rewrite: false
2019-04-17 14:13:23 -07:00
Paul Osmialowski
ec322c9588 [flang] Semantics checker for STOP and ERROR STOP statements - ExprTypeKindIsDefault added to the tools
Signed-off-by: Paul Osmialowski <pawel.osmialowski@arm.com>

Original-commit: flang-compiler/f18@669b05b27d
Reviewed-on: https://github.com/flang-compiler/f18/pull/367
Tree-same-pre-rewrite: false
2019-04-17 14:13:23 -07:00
Paul Osmialowski
d1e409ab09 [flang] Semantics checker for STOP and ERROR STOP statements.
This commit introduces a new checker (StopChecker) for STOP
and ERROR STOP Fortran statements along with a test code.

Signed-off-by: Paul Osmialowski <pawel.osmialowski@arm.com>

Original-commit: flang-compiler/f18@c554174562
Reviewed-on: https://github.com/flang-compiler/f18/pull/367
Tree-same-pre-rewrite: false
2019-04-17 14:13:23 -07:00
Tim Keith
fab062244b [flang] Fix bug resolving internal and module functions
When analyzing a function call in an expression we weren't properly
recognizing a ProcedureDesignator that was the name of an internal
or module function, i.e. a symbol with SubprogramDetails.

The fix is to add IsProcedure to identify symbols that correspond
to procedures. IsFunction and GetType also need to be extended to
handle this case.

Fixes flang-compiler/f18#391.

Original-commit: flang-compiler/f18@f165f8d38c
Reviewed-on: https://github.com/flang-compiler/f18/pull/417
Tree-same-pre-rewrite: false
2019-04-17 07:42:16 -07:00
peter klausler
a8bf4d488f [flang] More clean-up
Original-commit: flang-compiler/f18@ba2365f5f7
Reviewed-on: https://github.com/flang-compiler/f18/pull/416
2019-04-16 16:14:14 -07:00
peter klausler
32424cad2d [flang] reformatting
Original-commit: flang-compiler/f18@d9bfa6f48e
Reviewed-on: https://github.com/flang-compiler/f18/pull/406
Tree-same-pre-rewrite: false
2019-04-15 09:44:54 -07:00
Tim Keith
b69c2c6997 [flang] Remove ObjectName alternative from Designator
A simple name in a `Designator` is always parsed as a `DataRef`, not
an `ObjectName`. So remove that alternative.

`StmtFunctionStmt::ConvertToAssignment` was creating a `Designator` with
that alternative: change it to do the same thing as the parser.

Add `GetSimpleName` utility functions to check if an `Expr` or `Variable`
represents a simple name. Many of the places that checked for `ObjectName`
in `Designator` are trying to do that.

Clean up includes and forward declarations in `tools.h`.

Original-commit: flang-compiler/f18@97d44de7b1
Reviewed-on: https://github.com/flang-compiler/f18/pull/410
2019-04-12 16:30:03 -07:00
Steve Scalpone
70285af0ad [flang] Implement semantic checks for DEALLOCATE statements.
The parser checks for duplicate dealloc-opts and expr
analysis checks that dealloc-opts are the right type.

Original-commit: flang-compiler/f18@1ade7f6617
Reviewed-on: https://github.com/flang-compiler/f18/pull/401
Tree-same-pre-rewrite: false
2019-04-10 22:17:44 -07:00
Steve Scalpone
37a53df82c [flang] Check semantic contraints for the nullify statement. The full
legality check is up to the user; however, some checks could
be done at compile time and others at runtime.  We choose to
skip any checking at compile time because it would not be
complete.

Note the instantiation of ExtractDataRef in expressions.cc.
This instantiation satifies the reference in check-nullify.cc
because expression.h just has a declaration of ExtractDataRef
instead of the definition.

Original-commit: flang-compiler/f18@b7199219fb
Reviewed-on: https://github.com/flang-compiler/f18/pull/388
Tree-same-pre-rewrite: false
2019-04-07 11:29:48 -07:00
Steve Scalpone
3d892d56e9 [flang] Remove the IF specific context classes; in these cases they
added no value. Change several error messages to better say
what is expected.  Adjust tests for new messages.  Reformat
with llvm7 clang-format.

Original-commit: flang-compiler/f18@706b506e26
Reviewed-on: https://github.com/flang-compiler/f18/pull/356
Tree-same-pre-rewrite: false
2019-03-26 18:03:33 -07:00
Steve Scalpone
f01caa3833 [flang] Implement semantic checks for if statements, if constructs and
arithmetic ifs.

Original-commit: flang-compiler/f18@deb2726aad
Reviewed-on: https://github.com/flang-compiler/f18/pull/356
Tree-same-pre-rewrite: false
2019-03-26 00:43:08 -07:00
peter klausler
0987d31f3e [flang] Tweak API per review
Original-commit: flang-compiler/f18@c0ab787cd1
Reviewed-on: https://github.com/flang-compiler/f18/pull/311
2019-03-05 13:11:57 -08:00
peter klausler
da2ebb6063 [flang] Improve error messages
Original-commit: flang-compiler/f18@4046134512
Reviewed-on: https://github.com/flang-compiler/f18/pull/311
Tree-same-pre-rewrite: false
2019-03-04 16:30:25 -08:00
peter klausler
6acfa11fda [flang] Add lib/semantics/tools.{h,cc}
Original-commit: flang-compiler/f18@c9823da207
Reviewed-on: https://github.com/flang-compiler/f18/pull/311
Tree-same-pre-rewrite: false
2019-03-04 16:30:25 -08:00