A substring of an array element is legal as an equivalence object,
e.g. `a(2,3)[4:5]`. Extend `EquivalenceObject` to include the start
of the substring, if any. Split `CheckBound` into `CheckArrayBound`
and `CheckSubstringBound`.
When evaluating bounds in `AddToSet` we can assert they are constant
because all of the error cases should have been detected already.
Original-commit: flang-compiler/f18@0b4050b2d5
Reviewed-on: https://github.com/flang-compiler/f18/pull/494
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
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
Specifically, that the conversion of warnings to errors will happen in a
single place in the compiler once we implement warnings as distinct from
errors. This change made on of the tests invalid.
Also, there's no need to check whether the extension to allow
REAL DO controls is enabled.
Original-commit: flang-compiler/f18@2fae9edd77
Reviewed-on: https://github.com/flang-compiler/f18/pull/478
Tree-same-pre-rewrite: false
parse-tree.cc
- Cleaned up the use of "const" in several declarations.
check-do-stmt.cc
- Replaced uses of parser::Messages with SemanticsContext.
- Removed unused "==" operator from the DoStmtContext class.
- Reduced the size of the GetBounds function by calling GetLoopControl().
- Changed the warning message for REAL DO controls to not mention standard
extensions.
check-do-stmt.h
- Restored the forward reference to Fortran::parser::DoConstruct and removed
the include of parse-tree.h
dosemantics*.f90
- Removed extraneous references to the "RUN" command.
test_errors.sh
- Simplified and generalized the extraction of the OPTIONS specification.
Original-commit: flang-compiler/f18@04a0712766
Reviewed-on: https://github.com/flang-compiler/f18/pull/478
Tree-same-pre-rewrite: false
and initial, final, and step expressions. As a new extension, we want to allow
REAL and DOUBLE PRECISION values for them by default.
Here's a summary of the changes:
- There already existed infrastructure for semantic checking of DO loops that
was partially specific to DO CONCURRENT loops. Because I re-used some of
this infrastructure, I renamed some files and classes from "concurrent" to
"stmt".
- I added some functions to distinguish among the different kinds of DO
statements.
- I added the functions to check-do-stmt.cc to produce the necessary warnins
and errors. Note that there are no tests for the warnings since the
necessary testing infrastructure does not yet exist.
- I changed test-errors.sh so that additional compilation options can be
specified in the test source.
- I added two new tests to test for the various kinds of values that can be
used for the DO variables and control expressions. The two tests are
identical except for the use of different compilation options.
dosemantics03.f90 specifies the options "-Mstandard -Werror" to produce
error messages for the use of REAL and DOUBLE PRECISION DO variables and
controls. dosemantics04.f90 uses the default options and only produces
error messages for contructs that are erroneous by default.
Original-commit: flang-compiler/f18@f484660c75
Reviewed-on: https://github.com/flang-compiler/f18/pull/478
Tree-same-pre-rewrite: false
In a function without a function result specified, the name in the
`FunctionStmt` was resolved to the function result symbol rather than
the function symbol itself. That is inconsistent with subroutines and
other functions.
The fix is to explicitly set the function name symbol after the result
has been resolved.
Original-commit: flang-compiler/f18@b0172d3284
Reviewed-on: https://github.com/flang-compiler/f18/pull/487
There were a couple of small incompatibilities:
- There is no `ldd` on MacOS; instead use `otools -L`.
This has not been tested when libpgmath is linked in to f18.
- `wc` outputs spaces where on Linux it outputs tabs; change how
the number of lines is extracted to work on both.
Also, fix a bug: change `passed_warnings` to `$passed_warnings`.
Original-commit: flang-compiler/f18@5bede9e188
Reviewed-on: https://github.com/flang-compiler/f18/pull/475
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
- Add location to non-fatal error message (context was not given
a location before folding in semantics).
- Avoid refolding expression from scratch several times (update GenericExprWrapper
after folding). So far, warning messages were generated twice per parametere init
expressions.
Original-commit: flang-compiler/f18@bf7f6cf9cd
Reviewed-on: https://github.com/flang-compiler/f18/pull/468
Tree-same-pre-rewrite: false
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