Commit graph

1889 commits

Author SHA1 Message Date
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
c1fa835a71 [flang] Merge pull request flang-compiler/f18#438 from flang-compiler/pmk-fix-pp-noargs
Fix bug flang-compiler/f18#437

Original-commit: flang-compiler/f18@3dbcc78d77
Reviewed-on: https://github.com/flang-compiler/f18/pull/438
2019-05-02 19:07:01 -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
psteinfeld
4245cae846 [flang] Merge pull request flang-compiler/f18#434 from flang-compiler/ps
Tests for C1131, DO loop names

Original-commit: flang-compiler/f18@d1c94d97ff
Reviewed-on: https://github.com/flang-compiler/f18/pull/434
2019-05-01 13:12:49 -07:00
Peter Steinfeld
b77f059862 [flang] Changed the test for unmatched DO loop names to use test_errors.sh
rather than test_any.sh.

Original-commit: flang-compiler/f18@c02aff4570
Reviewed-on: https://github.com/flang-compiler/f18/pull/434
2019-05-01 12:53:16 -07:00
Peter Steinfeld
bbc092553c [flang] Tests for C1131, making sure that names of DO loops match between the loop header and the END DO statement.
Original-commit: flang-compiler/f18@f42ad1c2fd
Reviewed-on: https://github.com/flang-compiler/f18/pull/434
Tree-same-pre-rewrite: false
2019-05-01 12:53:15 -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
13caf04846 [flang] Merge pull request flang-compiler/f18#433 from flang-compiler/tsk4
Fix source positions during parse tree rewriting

Original-commit: flang-compiler/f18@0bb7289ade
Reviewed-on: https://github.com/flang-compiler/f18/pull/433
2019-04-29 14:48:22 -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
e51108c138 [flang] Merge pull request flang-compiler/f18#429 from flang-compiler/tsk1
Continue semantic checking after name resolution error

Original-commit: flang-compiler/f18@f17c9caf8e
Reviewed-on: https://github.com/flang-compiler/f18/pull/429
2019-04-26 09:16:20 -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
8e2339dab9 [flang] Merge pull request flang-compiler/f18#430 from flang-compiler/tsk2
Bug fix: resolve ComponentArraySpec

Original-commit: flang-compiler/f18@612638e404
Reviewed-on: https://github.com/flang-compiler/f18/pull/430
2019-04-26 09:04:57 -07:00
Tim Keith
08321507e8 [flang] Fix test
Original-commit: flang-compiler/f18@dfd8cdfdec
Reviewed-on: https://github.com/flang-compiler/f18/pull/430
2019-04-26 08:51:17 -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
jeanPerier
9425afd6b5 [flang] First batch of semantic checks for allocate
Merge pull request flang-compiler/f18#418 from flang-compiler/jpr-check-allocate

Original-commit: flang-compiler/f18@ab7d7c5dc0
2019-04-24 00:53:49 -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
1cc1ef2629 [flang] Fix allocate in deallocate01.f90 test
Original-commit: flang-compiler/f18@681e51f50b
Tree-same-pre-rewrite: false
2019-04-23 03:05:57 -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
2cc4cba96e [flang] Merge pull request flang-compiler/f18#423 from flang-compiler/pmk-packs
Use parameter packs to simplify parser combinators.  Work around g++ …

Original-commit: flang-compiler/f18@9e178f2525
Reviewed-on: https://github.com/flang-compiler/f18/pull/423
2019-04-22 13:58:22 -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
e020976483 [flang] Merge pull request flang-compiler/f18#424 from flang-compiler/tsk-expr
Distinguish between unanalyzed and error expressions

Original-commit: flang-compiler/f18@0978d17010
Reviewed-on: https://github.com/flang-compiler/f18/pull/424
2019-04-22 12:58:20 -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
ba60bd6c1c [flang] Merge pull request flang-compiler/f18#426 from flang-compiler/pmk-425
Fix flang-compiler/f18#425, build fail with libc++

Original-commit: flang-compiler/f18@b21b3da808
Reviewed-on: https://github.com/flang-compiler/f18/pull/426
2019-04-22 10:37:07 -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
ffb2704be1 [flang] Merge pull request flang-compiler/f18#421 from flang-compiler/pmk3
Add some utility functions to semantics/tools

Original-commit: flang-compiler/f18@80ef214fb8
Reviewed-on: https://github.com/flang-compiler/f18/pull/421
2019-04-22 10:08:20 -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
d129f93148 [flang] Merge pull request flang-compiler/f18#422 from flang-compiler/tsk-expr
Continue semantics checks after expression errors

Original-commit: flang-compiler/f18@55cf9ee7aa
Reviewed-on: https://github.com/flang-compiler/f18/pull/422
2019-04-19 14:33:04 -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
f4f02c2725 [flang] Merge pull request flang-compiler/f18#420 from flang-compiler/pmk2
Flatten and fold array operations

Original-commit: flang-compiler/f18@8693c80f33
Reviewed-on: https://github.com/flang-compiler/f18/pull/420
2019-04-18 15:09:25 -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
567480a4d7 [flang] Merge pull request flang-compiler/f18#419 from flang-compiler/pmk1
More work on classes to represent characteristics of procedures.

Original-commit: flang-compiler/f18@4db875f1db
Reviewed-on: https://github.com/flang-compiler/f18/pull/419
2019-04-18 14:32:22 -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