Commit graph

1158 commits

Author SHA1 Message Date
Tim Keith
409212cf43 [flang] Move ProgramTree to its own file
Original-commit: flang-compiler/f18@06913c38ca
Reviewed-on: https://github.com/flang-compiler/f18/pull/443
Tree-same-pre-rewrite: false
2019-05-06 10:12:27 -07:00
Tim Keith
14094c71c8 [flang] Process specification parts before execution parts
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
2019-05-06 07:26:43 -07:00
Tim Keith
12f1660117 [flang] Add DIE macro
`DIE()` is like `common::die()` but with the source location appended,
as in `CHECK()`.

Original-commit: flang-compiler/f18@ed586c3f38
Reviewed-on: https://github.com/flang-compiler/f18/pull/443
Tree-same-pre-rewrite: false
2019-05-03 08:02:31 -07:00
Tim Keith
28f80675e9 [flang] Change how Scopes are mapped to ImplicitRules
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
2019-05-02 11:19:01 -07:00
peter klausler
eebc7ba001 [flang] Fix or disable broken tests.
Original-commit: flang-compiler/f18@a54396e92e
Reviewed-on: https://github.com/flang-compiler/f18/pull/445
2019-05-06 11:33:33 -07:00
peter klausler
1733317ad9 [flang] Tweak error message grammar
Original-commit: flang-compiler/f18@4190b97ecc
Reviewed-on: https://github.com/flang-compiler/f18/pull/442
2019-05-06 08:22:22 -07:00
peter klausler
5a18e79d5a [flang] Remove OwningPointer and ForwardReference
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
2019-05-06 07:51:07 -07:00
Jean Perier
6370087abc [flang] Address comments
Original-commit: flang-compiler/f18@2a6473ce6a
2019-05-03 01:31:48 -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
9c369277a5 [flang] Prevent unhandled special formatting
Original-commit: flang-compiler/f18@378e0e2325
Reviewed-on: https://github.com/flang-compiler/f18/pull/441
2019-05-03 16:53:45 -07:00
peter klausler
1eece3d125 [flang] Support %zu and %ju before special codes; add comments
Original-commit: flang-compiler/f18@d237d4122b
Reviewed-on: https://github.com/flang-compiler/f18/pull/441
Tree-same-pre-rewrite: false
2019-05-03 16:07:37 -07:00
peter klausler
789b7d67b2 [flang] Add comments
Original-commit: flang-compiler/f18@3bd10af06b
Reviewed-on: https://github.com/flang-compiler/f18/pull/441
Tree-same-pre-rewrite: false
2019-05-03 15:17:59 -07:00
peter klausler
68209d4f87 [flang] Support std::string and CharBlock in formatted messages
fix off-by-one

Original-commit: flang-compiler/f18@58eb11c5c7
Reviewed-on: https://github.com/flang-compiler/f18/pull/441
Tree-same-pre-rewrite: false
2019-05-03 15:10:03 -07:00
peter klausler
80602cdb74 [flang] Changes from review
Original-commit: flang-compiler/f18@feafc0c216
Reviewed-on: https://github.com/flang-compiler/f18/pull/440
2019-05-03 14:42:33 -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
peter klausler
14b5cdd4d0 [flang] Fix f90_correct test failure
Original-commit: flang-compiler/f18@ff7a5af50b
Reviewed-on: https://github.com/flang-compiler/f18/pull/438
2019-05-02 15:19:37 -07:00
peter klausler
b3682933f3 [flang] Fix bug flang-compiler/f18#437, func-like macro call with no arguments
Original-commit: flang-compiler/f18@d106290f19
Reviewed-on: https://github.com/flang-compiler/f18/pull/438
Tree-same-pre-rewrite: false
2019-05-02 14:29:52 -07:00
vdonaldson
408cfc1c4d [flang] reformat Fortran.h (flang-compiler/f18#435)
Original-commit: flang-compiler/f18@cdbb214339
Reviewed-on: https://github.com/flang-compiler/f18/pull/435
2019-04-30 20:22:02 -07:00
vdonaldson
2741d016c6 [flang] Clause 12 semantics -- Check all constraints not otherwise checked (flang-compiler/f18#427)
* 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
2019-04-30 11:28:16 -07:00
Tim Keith
55cb1ac4db [flang] Fix source positions during parse tree rewriting
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
2019-04-29 07:32:59 -07:00
Tim Keith
e9b4cf42e4 [flang] Optionally dump all source members of parse tree
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
2019-04-26 15:06:58 -07:00
Tim Keith
876bf77a3c [flang] Walk source member of Call and Designator
A `source` data member was added to `Call` and `Designator` so
the parse tree visitor needs to visit them.

Original-commit: flang-compiler/f18@0a620f1a5e
Reviewed-on: https://github.com/flang-compiler/f18/pull/433
Tree-same-pre-rewrite: false
2019-04-26 15:01:09 -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
Tim Keith
048d56cf5f [flang] Bug fix: resolve ComponentArraySpec
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
2019-04-25 15:05:41 -07:00
Eric Schweitz
777b89fdee [flang] revert last pushes
Original-commit: flang-compiler/f18@39335746a9
2019-04-24 11:41:40 -07:00
Eric Schweitz
1c15fa61a8 [flang] fix merge issues
Original-commit: flang-compiler/f18@20a6d8a159
2019-04-24 11:14:28 -07:00
Eric Schweitz
ff9123927c [flang] clang-format
Original-commit: flang-compiler/f18@faa7ccf905
2019-04-24 11:14:27 -07:00
Eric Schweitz
0b7fa133ae [flang] Some initial bridge code
add QualifiedStmt class

Original-commit: flang-compiler/f18@b2d89fe696
2019-04-24 11:14:25 -07:00
Eric Schweitz
bb832078a1 [flang] start splitting up afforestation so it isn't monolithic
Original-commit: flang-compiler/f18@ea42c9df5a
2019-04-24 11:14:20 -07:00
Eric Schweitz
ac525ded21 [flang] fix interface
Original-commit: flang-compiler/f18@668fd8338d
2019-04-24 11:14:17 -07:00
Jean Perier
aa6155adea [flang] fix comment layout
Original-commit: flang-compiler/f18@ad874f0152
2019-04-23 06:06:33 -07:00
Jean Perier
c61c03c32e [flang] Address review comments
Original-commit: flang-compiler/f18@0c975ed88c
Tree-same-pre-rewrite: false
2019-04-23 05:57:50 -07:00
Jean Perier
ce05ebf748 [flang] First batch of semantics checks for allocate
Original-commit: flang-compiler/f18@1019a84ac8
Tree-same-pre-rewrite: false
2019-04-23 03:05:56 -07:00
peter klausler
337d8f8b5a [flang] Use parameter packs to simplify parser combinators. Work around g++ bug better.
Original-commit: flang-compiler/f18@eaa65cd60a
Reviewed-on: https://github.com/flang-compiler/f18/pull/423
2019-04-19 16:59:28 -07:00
Tim Keith
2dbd0dfb1c [flang] Change ExprRef to return reference
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
2019-04-21 20:46:15 -07:00
Tim Keith
510671c8c1 [flang] Distinguish between unanalyzed and error expressions
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
2019-04-19 17:14:50 -07:00
peter klausler
6d93fd2e54 [flang] Fix flang-compiler/f18#425, build fail with libc++
Original-commit: flang-compiler/f18@96a553b189
Reviewed-on: https://github.com/flang-compiler/f18/pull/426
2019-04-22 10:10:27 -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
b12a146b1b [flang] Share code for analyzing Expr and Variable
Move check for empty CharBlock from here to SetLocation.
(Can an Expr ever have an empty source location?)

Original-commit: flang-compiler/f18@7fd422f025
Reviewed-on: https://github.com/flang-compiler/f18/pull/422
2019-04-19 12:55:36 -07:00
Tim Keith
ed26a23f8a [flang] Continue semantics checks after expression error
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
2019-04-19 09:21:12 -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
Tim Keith
a426477d37 [flang] Remove redundant checks enforced in the grammar
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
2019-04-19 07:11:19 -07:00
Tim Keith
54c42cfa89 [flang] Preserve source location when rewriting parse tree
When a Designator is created from a FunctionReference or
StmtFunctionStmt, copy the source data member too.

Original-commit: flang-compiler/f18@bf91c0630f
Reviewed-on: https://github.com/flang-compiler/f18/pull/422
Tree-same-pre-rewrite: false
2019-04-19 06:39:50 -07:00
Tim Keith
5094c3c584 [flang] Save and fetch analyzed Expr in Variable
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
2019-04-18 17:48:55 -07:00
peter klausler
146e13ce22 [flang] Fold array operations
Original-commit: flang-compiler/f18@e6c86ecfd1
Reviewed-on: https://github.com/flang-compiler/f18/pull/420
2019-04-18 14:48:05 -07:00
peter klausler
f832a4d3ee [flang] Return a missing result
Original-commit: flang-compiler/f18@04f9fd39b9
Reviewed-on: https://github.com/flang-compiler/f18/pull/419
2019-04-18 14:27:59 -07:00
peter klausler
e58aa3837f [flang] Use Attr_enumSize rather than an arbitrary 32.
Original-commit: flang-compiler/f18@b6de9c6e47
Reviewed-on: https://github.com/flang-compiler/f18/pull/419
Tree-same-pre-rewrite: false
2019-04-18 14:25:22 -07:00
peter klausler
1cc33da57e [flang] More work on classes to represent characteristics of procedures.
Original-commit: flang-compiler/f18@abd3922a88
Reviewed-on: https://github.com/flang-compiler/f18/pull/419
Tree-same-pre-rewrite: false
2019-04-18 13:25:20 -07:00
Paul Osmialowski
994e90ce1e [flang] Semantics checker for STOP and ERROR STOP statements - trust in implied check
Signed-off-by: Paul Osmialowski <pawel.osmialowski@arm.com>

Original-commit: flang-compiler/f18@7a98732f72
Reviewed-on: https://github.com/flang-compiler/f18/pull/367
2019-04-17 14:13:23 -07:00