Commit graph

1141 commits

Author SHA1 Message Date
Eric Schweitz
029b52a5e7 [flang] Add the Fortran IR document.
Original-commit: flang-compiler/f18@35a8c66e13
Reviewed-on: https://github.com/flang-compiler/f18/pull/259
Tree-same-pre-rewrite: false
2019-01-10 10:28:56 -08:00
Peter Klausler
409d26950b [flang] Merge pull request flang-compiler/f18#258 from flang-compiler/pmk1
cherrypick expression changes

Original-commit: flang-compiler/f18@470b03caee
Reviewed-on: https://github.com/flang-compiler/f18/pull/258
2019-01-09 16:46:35 -08:00
peter klausler
70d7ab8789 [flang] address review comments
Original-commit: flang-compiler/f18@e770e52cb1
Reviewed-on: https://github.com/flang-compiler/f18/pull/258
2019-01-09 16:39:58 -08:00
peter klausler
51dc18258b [flang] remove debugging output
Original-commit: flang-compiler/f18@3a156953c2
Reviewed-on: https://github.com/flang-compiler/f18/pull/258
Tree-same-pre-rewrite: false
2019-01-09 15:13:23 -08:00
peter klausler
dc9faa270f [flang] cherrypick expression changes
Original-commit: flang-compiler/f18@427e267722
Reviewed-on: https://github.com/flang-compiler/f18/pull/258
Tree-same-pre-rewrite: false
2019-01-09 15:06:07 -08:00
Tim Keith
003ab5d332 [flang] Merge pull request flang-compiler/f18#256 from flang-compiler/tsk6
More name resolution

Original-commit: flang-compiler/f18@3ea1c3bf4c
Reviewed-on: https://github.com/flang-compiler/f18/pull/256
2019-01-08 14:21:28 -08:00
Tim Keith
7ec0830abd [flang] Resolve %kind and %len on intrinsic types
A `part-ref` can be `%kind` on an entity of any intrinsic type or
`%len` on a character entity. During name resolution, recognize these
and don't report an error as if they are component references.

Create symbols for these names as well as `%re` and `%im`. This is
partly for completeness so that we don't get warnings about unresolve
names. It also allows us to avoid having to do string comparisons on
these names in more than one place.

Rework `AnalyzeExpr` on structure components to make use of these
symbols and also not treat `%kind` and `%len` as derived type component
references.

Original-commit: flang-compiler/f18@65ae81ebac
Reviewed-on: https://github.com/flang-compiler/f18/pull/256
2019-01-08 12:14:35 -08:00
Tim Keith
9ae71a0357 [flang] Fix crash evaluating kind expression
If we fail to evaluate the kind expression we were getting an invalid
optional reference. Instead, fail with an assert. This can happen if an
intrinsic function is not folded, but that will be implemented
eventually.

Original-commit: flang-compiler/f18@3bdbfc34bb
Reviewed-on: https://github.com/flang-compiler/f18/pull/256
Tree-same-pre-rewrite: false
2019-01-08 12:14:35 -08:00
Tim Keith
44e7fee6d0 [flang] Bug fix: pass right value as MiscDetails::Kind
Original-commit: flang-compiler/f18@94d63399bd
Reviewed-on: https://github.com/flang-compiler/f18/pull/256
Tree-same-pre-rewrite: false
2019-01-08 12:14:35 -08:00
Tim Keith
a1a55f007c [flang] Resolve name in PASS and BIND attributes
These are recognized along with other attributes and saved in
`passName_` and `bindName_`. The functions `SetPassNameOn()` and
`SetBindNameOn()` set them in a symbol if they are present.
They are also written to `.mod` files.

Add `MakePlaceholder()` to make symbols for names that otherwise
wouldn't have one. This allows us to assign a symbol to every name
and report errors for those that don't have one. Make use of this
for PASS names, which don't have explicit symbols.

Change `ObjectEntityDetails` and `ProcEntityDetails` to be sub-classes
of `EntityDetails`. They each contain a superset of the information in
`EntityDetails` so this reduces some duplication.

Original-commit: flang-compiler/f18@404c920840
Reviewed-on: https://github.com/flang-compiler/f18/pull/256
Tree-same-pre-rewrite: false
2019-01-08 12:14:35 -08:00
Peter Klausler
845e02d1e1 [flang] Merge pull request flang-compiler/f18#248 from pjh40/pjh2
Define non-inline versions of ExpressionBase::derived()

Original-commit: flang-compiler/f18@f78bba7490
Reviewed-on: https://github.com/flang-compiler/f18/pull/248
2019-01-08 11:32:51 -08:00
Paul Henning
778e615158 [flang] Added preprocessor directives to limit the use of non-inline ExpressionBase<A>::derived to GCC on Mac (inlined on all other platforms)
Original-commit: flang-compiler/f18@b38b31909a
Reviewed-on: https://github.com/flang-compiler/f18/pull/248
2019-01-03 09:45:27 -07:00
Paul Henning
b61b31dfcd [flang] Addresses issue flang-compiler/f18#242 by making non-inline definitions for the two versions
of ExpressionBase::derived().  gcc-8.2 on macOS was choosing to create
non-inline instances of derived() during the explicit instantiations of
ExpressionBase in expression.cc and fold.cc.  During linking of any
executable, the linker failed when it found these duplicate definitions.

While this solution works, it removes the opportunity to inline the trivial
derived() functions.  Another solution would be to make all of the
templates related to ExpressionBase in expression.cc and fold.cc available
in a single .cc file, where the explicit instantiation
FOR_EACH_TYPE_AND_KIND(template class ExpressionBase) is done once. This
approach would allow inlining, but require something like template
implementation headers that could be included into the instantiation .cc
file.

Original-commit: flang-compiler/f18@074de39418
Reviewed-on: https://github.com/flang-compiler/f18/pull/248
Tree-same-pre-rewrite: false
2018-12-20 10:39:29 -07:00
Peter Klausler
eef439577c [flang] Merge pull request flang-compiler/f18#255 from flang-compiler/pmk1
Minor clean-up after a merge

Original-commit: flang-compiler/f18@4bd4a2045f
Reviewed-on: https://github.com/flang-compiler/f18/pull/255
2019-01-08 10:50:12 -08:00
peter klausler
4d115f2383 [flang] Restore readability improvement from code review comment that did not make it into a merge into master, and repair expected test results.
Original-commit: flang-compiler/f18@4f1946765e
Reviewed-on: https://github.com/flang-compiler/f18/pull/255
2019-01-08 09:56:57 -08:00
peter klausler
7e837d117f [flang] address review comment
Original-commit: flang-compiler/f18@3542f64813
Reviewed-on: https://github.com/flang-compiler/f18/pull/255
Tree-same-pre-rewrite: false
2019-01-07 17:01:49 -08:00
Peter Klausler
7673e0944c [flang] Merge pull request flang-compiler/f18#254 from flang-compiler/pmk3
Roll up small tweaks to parser and semantics.

Original-commit: flang-compiler/f18@36601dd6ec
Reviewed-on: https://github.com/flang-compiler/f18/pull/254
2019-01-07 16:45:08 -08:00
peter klausler
e30ef0ec8d [flang] Roll up small tweaks to parser and semantics.
Original-commit: flang-compiler/f18@57d823a809
Reviewed-on: https://github.com/flang-compiler/f18/pull/254
2019-01-07 15:38:48 -08:00
Peter Klausler
8416801439 [flang] Merge pull request flang-compiler/f18#253 from flang-compiler/pmk1
Symbol changes for PDT instantiation

Original-commit: flang-compiler/f18@d3c16c6a80
Reviewed-on: https://github.com/flang-compiler/f18/pull/253
2019-01-07 16:44:42 -08:00
peter klausler
5cf5315343 [flang] fold analyzed bounds expressions
Original-commit: flang-compiler/f18@17810319ae
Reviewed-on: https://github.com/flang-compiler/f18/pull/253
2019-01-07 16:31:59 -08:00
peter klausler
e760aaa4e6 [flang] fix copyright dates
Original-commit: flang-compiler/f18@75818658d9
Reviewed-on: https://github.com/flang-compiler/f18/pull/253
Tree-same-pre-rewrite: false
2019-01-07 15:50:04 -08:00
peter klausler
e828e0c795 [flang] Update copyright dates.
Original-commit: flang-compiler/f18@8a7722621b
Reviewed-on: https://github.com/flang-compiler/f18/pull/253
Tree-same-pre-rewrite: false
2019-01-07 15:42:36 -08:00
peter klausler
32ba1a4a8c [flang] fix comment
Original-commit: flang-compiler/f18@2b06aff9b4
Reviewed-on: https://github.com/flang-compiler/f18/pull/253
Tree-same-pre-rewrite: false
2019-01-07 15:20:57 -08:00
peter klausler
13ed85789d [flang] Symbol changes for PDT instantiation
Original-commit: flang-compiler/f18@0c545a026d
Reviewed-on: https://github.com/flang-compiler/f18/pull/253
Tree-same-pre-rewrite: false
2019-01-07 15:05:53 -08:00
Peter Klausler
d3e451365f [flang] Merge pull request flang-compiler/f18#252 from flang-compiler/pmk3
Roll up folding & expression changes

Original-commit: flang-compiler/f18@608139c160
Reviewed-on: https://github.com/flang-compiler/f18/pull/252
2019-01-07 10:55:40 -08:00
peter klausler
67f13efa44 [flang] update copyright dates
Original-commit: flang-compiler/f18@99f4c98ccb
Reviewed-on: https://github.com/flang-compiler/f18/pull/252
2019-01-07 10:55:09 -08:00
peter klausler
fe3acf5ffc [flang] Roll up folding & expression changes
Original-commit: flang-compiler/f18@60affece05
Reviewed-on: https://github.com/flang-compiler/f18/pull/252
Tree-same-pre-rewrite: false
2019-01-07 10:15:27 -08:00
Peter Klausler
0a810d5207 [flang] Merge pull request flang-compiler/f18#251 from flang-compiler/pmk3
Support operator== for expressions.

Original-commit: flang-compiler/f18@b43f5fa583
Reviewed-on: https://github.com/flang-compiler/f18/pull/251
2019-01-04 14:35:05 -08:00
peter klausler
2ad9986698 [flang] Support operator== for expressions.
Original-commit: flang-compiler/f18@42013513e9
Reviewed-on: https://github.com/flang-compiler/f18/pull/251
2019-01-04 14:05:53 -08:00
Peter Klausler
b45b098d0f [flang] Merge pull request flang-compiler/f18#250 from flang-compiler/pmk1
Change expression constraint checking

Original-commit: flang-compiler/f18@c40ce62f12
Reviewed-on: https://github.com/flang-compiler/f18/pull/250
2018-12-28 16:54:57 -08:00
peter klausler
d1d894c907 [flang] final clean-up
Original-commit: flang-compiler/f18@b971754a20
Reviewed-on: https://github.com/flang-compiler/f18/pull/250
2018-12-28 16:52:57 -08:00
peter klausler
7187fbcc6d [flang] Remove a little now-dead code.
Original-commit: flang-compiler/f18@f000fb974c
Reviewed-on: https://github.com/flang-compiler/f18/pull/250
Tree-same-pre-rewrite: false
2018-12-28 16:36:46 -08:00
peter klausler
c6df6af013 [flang] update error message texts in test
Original-commit: flang-compiler/f18@42c0d5d950
Reviewed-on: https://github.com/flang-compiler/f18/pull/250
Tree-same-pre-rewrite: false
2018-12-28 16:01:46 -08:00
peter klausler
ee2a32e561 [flang] Rework expression constraint checking
Original-commit: flang-compiler/f18@7a31c1ed2b
Reviewed-on: https://github.com/flang-compiler/f18/pull/250
Tree-same-pre-rewrite: false
2018-12-28 15:58:17 -08:00
Tim Keith
6fe4f5a732 [flang] Merge pull request flang-compiler/f18#249 from flang-compiler/tsk3
Various name resolution improvements

Original-commit: flang-compiler/f18@a7c41c0ccd
Reviewed-on: https://github.com/flang-compiler/f18/pull/249
2018-12-28 10:33:51 -08:00
Tim Keith
8d959bb943 [flang] Add support for type-bound generics
Record the bindings in a symbol with GenericBindingDetails, including
bindings inherited from extended types. Check that they have consistent
accessibility.

Original-commit: flang-compiler/f18@0f780abcea
Reviewed-on: https://github.com/flang-compiler/f18/pull/249
2018-12-26 14:31:26 -08:00
Tim Keith
37364331fb [flang] Handle structure constructor in entity-decl
As with array constructors, we can encounter a decl-type-spec for a
structure-constructor while the decl-type-spec for the
type-declaration-stmt is still active. So here too we need to save and
restore the state.

In this case, it is done in DeclarationVisitor, so add
SetDeclTypeSpecState() to get and set the state.

Example where this occurs:
```
type(t(2)) :: x = t(2)()
```

Original-commit: flang-compiler/f18@aa5ca8d7b2
Reviewed-on: https://github.com/flang-compiler/f18/pull/249
Tree-same-pre-rewrite: false
2018-12-18 17:19:41 -08:00
Tim Keith
a7e91f2335 [flang] Fix bug making symbol for external procedure
When we encounter a ProcedureDesignator, if it is an external procedure
(i.e. there is no visible declaration) it must be implicitly created in
the global scope, not the current scope.

If there is already a symbol there (i.e. a module) it is an error, even
if that symbol is not visible due to an IMPORT statement.

Original-commit: flang-compiler/f18@835e234ded
Reviewed-on: https://github.com/flang-compiler/f18/pull/249
Tree-same-pre-rewrite: false
2018-12-18 16:35:31 -08:00
Tim Keith
4f8d0d8d9b [flang] Handle array constructor in entity-decl
We can encounter a decl-type-spec for an array constructor while the
decl-type-spec for type-declaration-stmt is still active:
```
integer, allocatable :: a(:) = [integer :: 1, 2, 3]
```

To handle this, save the state of the current decl-type-spec while
processing the second one, then restore when done.

Original-commit: flang-compiler/f18@d125a0f612
Reviewed-on: https://github.com/flang-compiler/f18/pull/249
Tree-same-pre-rewrite: false
2018-12-18 14:35:58 -08:00
Tim Keith
bc469ef570 [flang] Resolve names in ProcedureStmt and GenericStmt
We need to save the names of specific procedures that appear in a
ProcedureStmt or GenericStmt to resolve at the end of the specification
section. They may be forward references to interface bodies.

We were saving them in the GenericDetails but that was not the right
place: we need to save the parser::Name so that we can eventually
resolve it to a Symbol, but the symbol table should not contains
references to Name because they go away with the parse tree.

The fix is to save the mapping in a new multimap, specificProcs_ in
InterfaceVisitor. We can reference parser::Names there and resolve them
during ResolveSpecificsInGenerics(). We no longer need to clutter
GenericDetails with data structures for unresolved names.

Also handle the case where a specific procedure is use-associated from
another module.

Original-commit: flang-compiler/f18@c7f7b1e72d
Reviewed-on: https://github.com/flang-compiler/f18/pull/249
Tree-same-pre-rewrite: false
2018-12-18 07:59:40 -08:00
Tim Keith
a040d7462e [flang] Merge pull request flang-compiler/f18#247 from flang-compiler/tsk3
Support character types

Original-commit: flang-compiler/f18@2884608901
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
2018-12-18 07:45:39 -08:00
Tim Keith
9c35cb8948 [flang] Handle TypeStar and ClassStar in GetSymbolType()
Add DeclTypeSpec::AsDerived() to get the DerivedTypeSpec from a
DeclTypeSpec when it has one.

Original-commit: flang-compiler/f18@3bd921d8f3
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
2018-12-17 17:22:42 -08:00
Tim Keith
8a1fbef21b [flang] Treat CHARACTER like other intrinsic types with default kind
Character decl-type-specs with no kind specified had no kind written to
the .mod file. That was different from the other intrinsic types which
always have an explicit type. This change make character like the other
intrinsic types.

Original-commit: flang-compiler/f18@5b4f047a13
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
Tree-same-pre-rewrite: false
2018-12-17 15:46:30 -08:00
Tim Keith
20e2003009 [flang] Simplify creation of Expr values from ints.
Original-commit: flang-compiler/f18@56f007493b
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
Tree-same-pre-rewrite: false
2018-12-17 15:19:11 -08:00
Tim Keith
b8b53ba2f4 [flang] Refactoring: improve some names
IntrinsicTypeSpec was used for all intrinsics except for character.
Change it to be a common base class for NumericTypeSpec,
LogicalTypeSpec, and CharacterTypeSpec.

Change DeclTypeSpec to categorize the intrinsics as Numeric, Logical,
and Character. Add some utility methods: AsIntrinsic() and IsNumeric().

In scope.h, give the functions that create DeclTypeSpecs better names.

In semantics.h, replace MakeIntrinsicTypeSpec() with MakeNumericType()
and MakeLogicalType() as it does not apply to character types.

Original-commit: flang-compiler/f18@8ad92d069c
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
Tree-same-pre-rewrite: false
2018-12-17 12:41:43 -08:00
Tim Keith
de78ae3f09 [flang] Add support for character type specs
Recognize the various ways of specifying character lengths.

Define CharacterTypeSpec with length and kind and store them in the
current scope, as is done with DerivedTypeSpec (which can also have
length parameters).

Note: IntrinsicTypeSpec is no longer used for characters, so it
should have a different name. Similarly, in DeclTypeSpec::Category,
Intrinsic does not include Character.

Original-commit: flang-compiler/f18@5f84785193
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
Tree-same-pre-rewrite: false
2018-12-14 14:04:15 -08:00
Tim Keith
396b3fde60 [flang] Rework how DeclTypeSpecs are stored
Now DeclTypeSpecs are stored in the scope so that they remain available
as long as the scope exists. DeclTypeSpecs for intrinsic types are
stored in the global scope; those for derived types are in the current
scope. They can contains type parameter values so they can't be reused.

Add `Semantics::MakeIntrinsicTypeSpec` to simplify creating
DeclTypeSpecs for intrinsic types.

Replace `std::optional<DeclTypeSpec>` with `DeclTypeSpec *` as they do
not need to be copied around.

Also fix a small bug with writing `class(t(...))` to the module file --
the type parameters were missing.

Original-commit: flang-compiler/f18@e4744418fc
Reviewed-on: https://github.com/flang-compiler/f18/pull/247
Tree-same-pre-rewrite: false
2018-12-14 07:17:12 -08:00
Peter Klausler
4cf72e2f25 [flang] Merge pull request flang-compiler/f18#244 from flang-compiler/pmk1
fix bug noticed by Jean

Original-commit: flang-compiler/f18@c4c54f05f3
Reviewed-on: https://github.com/flang-compiler/f18/pull/244
2018-12-17 10:21:25 -08:00
peter klausler
8b34535de7 [flang] fix bug noticed by Jean
Original-commit: flang-compiler/f18@9acbff7585
Reviewed-on: https://github.com/flang-compiler/f18/pull/244
2018-12-14 13:19:12 -08:00
Peter Klausler
2c33ef58cf [flang] Merge pull request flang-compiler/f18#245 from flang-compiler/pmk3
fix crash that Tim ran into

Original-commit: flang-compiler/f18@d7e914719e
Reviewed-on: https://github.com/flang-compiler/f18/pull/245
2018-12-14 13:18:21 -08:00