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
Use better names for template parameters of `LoopBounds`, and also
for the constructor arguments.
Use two overloadings of `loopBounds()` instead of `std::is_same_v<>`.
Original-commit: flang-compiler/f18@a2c0c75462
Reviewed-on: https://github.com/flang-compiler/f18/pull/455
Tree-same-pre-rewrite: false
It is a common extension to allow DO loops with REAL variable and
bounds. The parse tree currently parses those with the variable
as `scalar-int-variable-name` and the bounds as `scalar-int-expr`.
That causes the INTEGER constraint to be enforced automatically.
Change the grammar and parse tree to treat them as `scalar-variable-name`
and `scalar-expr`. This allows the name and expression to be REAL,
but we will have to verify that they aren't any other type (in a future
change).
To accomplish this, add a template parameter to `LoopBounds` for the type
of the variable name (always `Scalar<Name>` or `Scalar<Integer<Name>>`).
We sometimes need names for the instantiations of `LoopBounds` so add
type aliases like `LoopControl::Bounds` for each one.
Original-commit: flang-compiler/f18@d75aa03970
Reviewed-on: https://github.com/flang-compiler/f18/pull/455
Tree-same-pre-rewrite: false
1. typo and trailing spaces within OpenMP-4.5-grammar.txt
2. parse (openmp-grammar.h) and unparse(unparse.cc) for:
SCHEDULE ([modifier [, modifier]:]kind[, chunk_size])
Modifier -> MONITONIC | NONMONOTONIC | SIMD
where ":" is optional except at least one modifier is present.
Original-commit: flang-compiler/f18@5cebae5039
Reviewed-on: https://github.com/flang-compiler/f18/pull/453
Preserve generated strings until consumed by formatting.
bugfix from premature push
Address review comments
Last fix(?)
Use %s formatting for CharBlocks and strings
Use new formatting and fix usage of std::forward<>()
Use forward_list rather than vector to save strings
Original-commit: flang-compiler/f18@8ea478420f
Reviewed-on: https://github.com/flang-compiler/f18/pull/444
Tree-same-pre-rewrite: false
Change the order in which names are resolved. Before resolving names
in the execution part of a subprogram we need to know the interface
of contained subprograms. This is because the type of some construct
entities can depend on the return type of contained functions, e.g.
```
associate(x => f())
end associate
contains
function f()...
```
To do this, we now build a tree rooted at each program unit with
child nodes corresponding to subprograms contained in the parent.
This provides flexibility in choosing an order to resolve names.
The current implementation processes all specification parts before
any execution parts. This ensures contained subprogram interfaces
are know before analyzing constructs like ASSOCIATE.
Resolving a specification part involves first adding
`SubprogramNameDetails` symbols for each contained subprogram, then
processing the statement that introduces the program unit (`ModuleStmt`,
`SubroutineStmt`, etc.), then visiting all of the statements in the
specification part.
If it proves necessary, we can add a phase to do implicit declarations
in the execution part before processing the specification part of
contained subprograms.
Original-commit: flang-compiler/f18@20e803fd92
Reviewed-on: https://github.com/flang-compiler/f18/pull/443
Tree-same-pre-rewrite: false
Previously we maintained a stack of ImplicitRules in parallel with
the Scope stack. Change to maintaining a mapping from Scope to
ImplicitRules.
This makes things simpler in some cases: Block scopes don't have their
own implicit rules. And submodule scopes aren't just pushed and popped.
This will also help with future changes to the order in which scopes
are processed.
Original-commit: flang-compiler/f18@443da50352
Reviewed-on: https://github.com/flang-compiler/f18/pull/443
Tree-same-pre-rewrite: false
Use std::unique_ptr<> with custom deleter for forward-referenced owned pointer.
Move CopyableIndirection into common, add documentation, clean up.
Remove OwningPointer and ForwardReference
Use std::unique_ptr<> with custom deleter for forward-referenced owned pointer.
Use CopyableIndirection
clean up from merge after split
Complete characterization
fold conversions of arrays
Clean up subscripts to constant arrays
Elemental unary operations complete
Support assumed type TYPE(*) in actual arguments
clean up some TODOs
recognize TYPE(*) arguments to intrinsics
Complete folding of array operations
Finish elementwise array folding, add test, debug
characterize intrinsics, fix some bugs
Clean up build
Type compatibility and shape conformance checks on pointer assignments
Original-commit: flang-compiler/f18@99d734c621
Reviewed-on: https://github.com/flang-compiler/f18/pull/442
Tree-same-pre-rewrite: false
* Clause 12 semantics
Check all constraints not otherwise checked during parsing or label scope
validation, except for C1201, C1231, and C1233-5. Obvious program
requirements are also checked, except for 12.6.2.2 constant format string
validation.
Original-commit: flang-compiler/f18@e4ec343618
Reviewed-on: https://github.com/flang-compiler/f18/pull/427
When a StmtFunctionStmt was rewritten as an array element assignment
the subscripts were not getting correct source locations. They need
to be copied from the function args.
Also, the entire array element expression (e.g. `a(i)`) did not have a
source position. This was tricky because there is no source position
in the original parse that matches what we need. So we take the source
position from the beginning of the function name to the end of the last
arg and extend it one more character to include the closing parenthesis.
Change `ActualArgToExpr()` to return `Expr` rather than
`std::optional<Expr>` because callers always call `.value()` on the
result anyway.
Add `WithSource()` utility to update the `source` data member of a
parse tree node.
This bug shows up as incorrect source positions for error messages. For
example, in this program the error (due to real subscript) did not have
a source position:
```
real :: a(10), x, y
a(x) = y
end
```
Original-commit: flang-compiler/f18@a9bcf68ceb
Reviewed-on: https://github.com/flang-compiler/f18/pull/433
In the parse tree dumper, add a compile-time option to dump source
locations for all nodes that have them. This is a useful way to check
if they are correct, especially after parse tree rewrites.
It is enabled by defining `SHOW_ALL_SOURCE_MEMBERS` in `dump-parse-tree.h`.
Original-commit: flang-compiler/f18@ceae5632e2
Reviewed-on: https://github.com/flang-compiler/f18/pull/433
Tree-same-pre-rewrite: false
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
This used to work but broke due to coarray spec changes.
The fix is to extend AnalyzeArraySpec to work on ComponentArraySpec
and to call it when we encounter one.
modfile24.f90 tested this case but had the wrong expected results.
Thanks to Jean for finding this.
Original-commit: flang-compiler/f18@7ef4c28a61
Reviewed-on: https://github.com/flang-compiler/f18/pull/430
Tree-same-pre-rewrite: false
ExprRef never returns a null pointer so change it to return a reference.
Add overloading for parser::Variable as they now also hold a typedExpr.
Change some of the functions that the result of ExprRef is passed to so
that they take references instead of pointers.
Original-commit: flang-compiler/f18@2cdab6b166
Reviewed-on: https://github.com/flang-compiler/f18/pull/424
When an Expr or Variable is analyzed, always fill in a GenericExprWrapper
for it. That now holds the result of expression analysis which is
std::nullopt when there is an error.
After the ExprChecker pass has finished, the typedExpr data member of
Variables and top-level Exprs should be filled in. Assert that is the
case when we access them.
Original-commit: flang-compiler/f18@192a4e0855
Reviewed-on: https://github.com/flang-compiler/f18/pull/424
Tree-same-pre-rewrite: false
Change statement semantics to continue with checks after an error
in expression analysis. This allows the compiler to report more
compilation errors. It requires that statement semantics not assume
that every parser::Expr has a valid evaluate::Expr.
For example, the test cases in coarrays02.f90 can now be moved to
coarrays01.f90. Previously the errors like "Must be a scalar value"
from ExprChecker prevented other errors from being detected by
CoarrayChecker.
Change to a stable sort of messages so that they come out in a
deterministic order. Otherwise when there are two errors at the
same location (e.g. line 71 of coarrays01.f90) the test can fail
randomly.
Original-commit: flang-compiler/f18@f420d21909
Reviewed-on: https://github.com/flang-compiler/f18/pull/422
Tree-same-pre-rewrite: false
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
Expression analysis enforces constraints implied by the grammar,
for example scalar-expr, scalar-int-expr, etc. These no longer need
to be checked during statement semantics.
Original-commit: flang-compiler/f18@35330b9a85
Reviewed-on: https://github.com/flang-compiler/f18/pull/422
Tree-same-pre-rewrite: false
Add typedExpr data member to Variable like that in Expr.
When expression analysis analyzed a Variable it stores the
resulting evaluate::Expr there.
Add GetExpr overloads in semantics/tools.h for using in statement
semantics. It gets an evaluate::Expr from an Expr, Variable, or
wrapper around one of those. It returns a const pointer so that
clients cannot modify the cached expression (and copies do not
have to be made).
Change CoarrayChecker to make use of GetExpr. It will eventually
replace all references to typedExpr in statement semantics.
Original-commit: flang-compiler/f18@b02a41efe1
Reviewed-on: https://github.com/flang-compiler/f18/pull/422
Tree-same-pre-rewrite: false
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
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.
Fixesflang-compiler/f18#391.
Original-commit: flang-compiler/f18@f165f8d38c
Reviewed-on: https://github.com/flang-compiler/f18/pull/417
Tree-same-pre-rewrite: false
Add CoarrayChecker to check for valid team-value in CHANGE TEAM,
SYNC TEAM, and image selector. Check that coarray names and selector
names are distinct in CHANGE TEAM.
Resolve the variable in a coarray-association.
Create a scope for the construct entities of a CHANGE TEAM construct.
Add ResolveSelector to resolve a parser::Selector into an Expr and
optional variable name (and a source location for messages). Make use of
ResolveSelector to handle coarray-association, as well as it's previous
use in associate-stmt.
Improve the check for C1157 in select-type-stmt and add a test.
Add a test for "Associate name must have a type".
Move ResolveName, ResolveDataRef, etc. from ResolveNamesVisitor
to DeclarationVisitor so that they are available in ConstructVisitor
as well. Add ResolveVariable and ResolveDesignator.
In the parse tree, change TeamValue from a type alias to a wrapper
class. We already had a wrapper class anyway, ImageSelectorSpec::Team,
so the new TeamValue can be used instead. This allows the member
of ImageSelectorSpec to be treated like other occurrences of TeamValue.
Original-commit: flang-compiler/f18@f856744b54
Reviewed-on: https://github.com/flang-compiler/f18/pull/414
Tree-same-pre-rewrite: false
so it can never be null. The condition should be
scope->kind() != Scope::Kind::Global.
And clang-format.
Original-commit: flang-compiler/f18@b686ab548a
Tree-same-pre-rewrite: false
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
indirection.h: Doesn't need ../common because it is in common.
expression.h: ../lib is the wrong path but the includes are needed.
They were probably coming in indirectly through other includes.
token-parsers.h: Include was not needed and parser shouldn't have
dependency on evaluate.
Original-commit: flang-compiler/f18@86f6b0023d
Reviewed-on: https://github.com/flang-compiler/f18/pull/405
When expressions are parsed iteratively they weren't getting the correct
source positions. For example, when parsing an `add-operand` as a sequence
of `mult-operand`s separated by `mult-op`.
This shows up when we report an error message referring to this kind
of expression:
```
t.f90:1:11: error: Expected a LOGICAL expression
if (i * j * k) then
^^^
```
The fix is to remember the location of the first operand and then
for each sub-expression (`i * j` and `i * j * k` in this example)
extend its location back to include that first operand.
Original-commit: flang-compiler/f18@e276f11f48
Reviewed-on: https://github.com/flang-compiler/f18/pull/395