Commit graph

2118 commits

Author SHA1 Message Date
peter klausler 64ea224ace [flang] Fix bug flang-compiler/f18#843, bad recovery from failed opens of source files
Original-commit: flang-compiler/f18@27d9db610f
Reviewed-on: https://github.com/flang-compiler/f18/pull/850
2019-12-03 10:47:46 -08:00
Tim Keith 203627d3a5 [flang] Fix PURE check on procedure binding
A symbol that represents a procedure binding is PURE if the procedure
it is bound to is PURE. Fix `IsPureProcedure` to check that.

Make use of `IsPureProcedure` in `CheckSpecificationExprHelper`.

Original-commit: flang-compiler/f18@c95f2eb4fb
Reviewed-on: https://github.com/flang-compiler/f18/pull/849
2019-12-03 08:43:05 -08:00
peter klausler b1e7ec6620 [flang] Dodge GCC 7.2 bug
Original-commit: flang-compiler/f18@bde158343a
Reviewed-on: https://github.com/flang-compiler/f18/pull/848
2019-12-02 15:56:00 -08:00
peter klausler 780c2aea65 [flang] Implement forward references to derived types (fix flang-compiler/f18#573)
Restructuring PDT instantiation in preparation for forward references

Complete tests, pass them

Address review comments

Original-commit: flang-compiler/f18@b66ba55a73
Reviewed-on: https://github.com/flang-compiler/f18/pull/847
2019-12-02 13:53:57 -08:00
Pete Steinfeld 7139a04e31 [flang] Add a check for DO step expressions being zero
This is prohibited by Section 11.1.7.4.1, paragraph 1.

Note also that we allow for REAL step expressions.  But the check I
added only works for INTEGER step expressions.

I added a function to tools.cc to test to see if an expression is zero,
and I added calls to check-do.cc for regular and CONCURRENT DO
statements to this function.  I made the regular DO a warning and the DO
CONCURRENT message an error.  I added tests for the DO CONCURRENT case,
including a test that uses an integer constant.

Original-commit: flang-compiler/f18@8c4fadfe00
Reviewed-on: https://github.com/flang-compiler/f18/pull/834
2019-12-02 13:26:31 -08:00
Tim Keith b0823c7b69 [flang] Check functions that implement defined operators (flang-compiler/f18#846)
Section 15.4.3.4.2 specifies restrictions on functions that may be used
to implement an "extended-intrinsic-op". These checkw are implemented in
`CheckHelper::CheckDefinedOperator`.

Move `IsIntrinsicRelational` et al. to `semantics/tools.h` so that
the same logic is used to check both dummy and actual arguments.

Fix up tests that had errors that are now detected.

Original-commit: flang-compiler/f18@b900762eed
Reviewed-on: https://github.com/flang-compiler/f18/pull/846
2019-12-02 08:55:44 -08:00
kiranchandramohan 201119217f [flang] Minor fix in folding of reshape intrinsic (flang-compiler/f18#842)
The standard permits source to have more elements than the
result (as specified by the SHAPE arg). While copying, ensure
that we do not copy more than the number of elements of the
result.

Original-commit: flang-compiler/f18@6b8284f4f2
Reviewed-on: https://github.com/flang-compiler/f18/pull/842
2019-11-26 15:34:03 -06:00
Tim Keith 18f3a2beef [flang] Analyze intrinsic and user-defined assignments
Change expression analysis to do assignment statements as it currently
does call statements. Check there for defined assignment and set
`typedAssignment` in the `AssignmentStmt` node to contain the analyzed
assignment, either intrinsic or user-defined.
When `var = expr` is implemented by subroutine `sub`, the analyzed
assignment contains a procedure reference to `sub(var, (expr))`.

Add `IsDefinedAssignment` to decide based on types and ranks of lhs
and rhs whether is can be a defined assignment. The result is
tri-state because when they are both the same derived type it can
be either intrinsic or defined. Use this where a similar decision
is made in `check-declarations.cc`.

Change "Procedure referenced in PURE subprogram" error message to
contain the name of the procedure. If the reference is from a defined
assignment that name won't appear on the highlighted source line.

Original-commit: flang-compiler/f18@5c87071210
Reviewed-on: https://github.com/flang-compiler/f18/pull/841
2019-11-26 13:22:17 -08:00
Tim Keith ddb4f259f6 [flang] Add analyzed assignment to parse tree
Add `typedAssignment` to the `AssignmentStmt` node, analagous to
`typedExpr` in `Expr`. This represents the analyzed form of an assignment.
It may be a subroutine call in the case of a user-defined assignment.
Add `GetAssignment` function to get it from the parse tree node if present.

Original-commit: flang-compiler/f18@675b0b9bb7
Reviewed-on: https://github.com/flang-compiler/f18/pull/841
Tree-same-pre-rewrite: false
2019-11-26 11:19:04 -08:00
Tim Keith e67f6a775e [flang] Extract Parenthesize function
Move the code to parenthesize an expression from `ExpressionAnalyzer`
into `evaluate/tools.h` so that it can be used to parenthesize an
`ActualArgument`. This will be needed for defined assignment calls.

Original-commit: flang-compiler/f18@6180d1fb9b
Reviewed-on: https://github.com/flang-compiler/f18/pull/841
Tree-same-pre-rewrite: false
2019-11-26 11:19:04 -08:00
Tim Keith b51673cab9 [flang] Add checks for valid defined assignment procedures
Perform the checks from 15.4.3.4.3 to determine what procedures are
valid to implement defined assignment. This requires characterizing
procedures, so share the result of that with
`CheckSpecificsAreDistinguishable`.

Original-commit: flang-compiler/f18@9e0d79f173
Reviewed-on: https://github.com/flang-compiler/f18/pull/841
Tree-same-pre-rewrite: false
2019-11-26 11:18:59 -08:00
Tim Keith 67c548376d [flang] Move distinguishability check to check-declarations.cc
The check that specific procedures of a generic are distinguishable
doesn't need to be done in `resolve-names.cc`. It can be deferred until
`check-declarations.cc` because it only depends on the symbol table.
Make use of `AttachDeclaration` when reporting errors

Refactor checks for different symbol details into separate functions
as they are getting more numerous.

Original-commit: flang-compiler/f18@cd0d6930bb
Reviewed-on: https://github.com/flang-compiler/f18/pull/841
Tree-same-pre-rewrite: false
2019-11-26 11:18:53 -08:00
Tim Keith abc99c63ff [flang] Change AttachDeclaration to take reference instead of pointer
AttachDeclaration (and so also SayWithDeclaration) don't do anything
when passed a null pointer for the symbol and in all but one place they
are called the symbol can't be null. So change both function to take
`const Symbol &` rather than `const Symbol *`. Change it to handle
procedure bindings as well.

Add `SayWithDeclaration` to `CheckHelper` to simplify calling the one in
`evaluate` and prevent attaching the declaration when it would point at
the same line.

Original-commit: flang-compiler/f18@5f1c2ff663
Reviewed-on: https://github.com/flang-compiler/f18/pull/841
Tree-same-pre-rewrite: false
2019-11-26 11:18:53 -08:00
Tim Keith e2b939e5f3 [flang] Combine GenericDetails and GenericBindingDetails
`GenericDetails` and `GenericBindingDetails` were almost identical:
the former has optional data members to handle the case when a specific
procedure or derived type has the same name as the generic symbol.

Most places they are handled the same way so it simplifies things to
have only one type. In the case where we want to know if it is a generic
binding (e.g. in `mod-file.cc`) we can check the kind of scope that owns
the symbol.

Save name from the generic binding for better location of error messages.

Original-commit: flang-compiler/f18@f65a9edca2
Reviewed-on: https://github.com/flang-compiler/f18/pull/841
Tree-same-pre-rewrite: false
2019-11-26 11:18:53 -08:00
Tim Keith 701a9bd0e5 [flang] Refactor GenericKind
Change GenericKind from an enum class to a variant that includes the
`NumericOperator`, `LogicalOperator`, and `RelationalOperator` from `common`.
This allows for better tests like `IsIntrinsicOperator` (which used to
check for being in a range of the `GenericKind` enumeration) and
simplifies mapping the kind to a string representation.

Original-commit: flang-compiler/f18@c74327c393
Reviewed-on: https://github.com/flang-compiler/f18/pull/841
Tree-same-pre-rewrite: false
2019-11-26 11:18:47 -08:00
peter klausler e46cd9ee18 [flang] Fold MERGE, use it in ISO_FORTRAN_ENV
Reduce use of intrinsic type KIND codes in ISO_FORTRAN_ENV

Use COUNT([x]) rather than MERGE(1,0,x)

Fix problems in array constructor expression analysis

Original-commit: flang-compiler/f18@79018f7126
Reviewed-on: https://github.com/flang-compiler/f18/pull/836
2019-11-22 14:16:48 -08:00
Isuru Fernando fe7e36d46c [flang] Need algorithm for std::min (flang-compiler/f18#837)
Original-commit: flang-compiler/f18@d20a79cdd9
Reviewed-on: https://github.com/flang-compiler/f18/pull/837
2019-11-22 14:54:36 -07:00
peter klausler 223499ec99 [flang] Address review comments
Original-commit: flang-compiler/f18@0ce592c7c5
Reviewed-on: https://github.com/flang-compiler/f18/pull/835
2019-11-21 13:55:17 -08:00
peter klausler 4d372b6dc1 [flang] Reformat all C++ in lib/*
Original-commit: flang-compiler/f18@232bcedb66
Reviewed-on: https://github.com/flang-compiler/f18/pull/835
Tree-same-pre-rewrite: false
2019-11-21 13:35:20 -08:00
peter klausler 11ce9b0823 [flang] Revert Symbol::operator=() changes
Rearrange "if" nest for clarity

Pass call12.f90 test.

Original-commit: flang-compiler/f18@69a1a2b796
Reviewed-on: https://github.com/flang-compiler/f18/pull/835
Tree-same-pre-rewrite: false
2019-11-21 11:41:27 -08:00
Pete Steinfeld fd76cc47c5 [flang] Changes to check for constraint C1140
This constraint prohibits deallocation of polymorphic entities in a DO
CONCURRENT.

Section 9.7.3.2 specifies the situations that might cause deallocation
of a polymorphic entity. The ones that are applicable to a DO CONCURRENT
are exiting from a block that declares such variables, intrinsic
assignment, and an actual DEALLOCATE statement. This section also
specifies (paragraph 8) that deallocation of a derived type causes
deallocation of all of its allocatable subobjects.

Section 10.2.1.3 specifies what happens during intrinsic assignment.
Paragraph 3 states If the variable is an allocated allocatable variable,
it is deallocated if expr is an array of different shape, any
corresponding length type parameter values of the variable and expr
differ, or the variable is polymorphic and the dynamic type or any
corresponding kind type parameter values of the variable and expr
differ." Thus, an allocatable polymorphic variable on the left hand side
of an assignment statement gets deallocated. Paragraph 13 states that
  "For a noncoarray allocatable component the following sequence of
   operations is applied.
      (1) If the component of the variable is allocated, it is deallocated."

Thus, a variable on the left-hand side of an assignment statement might have noncorray allocatable components. Such components will be deallocated.
Deallocation can be caused by exiting from a block where the entity is
declared, from an assignment, and from direct deallocation.

Original-commit: flang-compiler/f18@7d1932d344
Reviewed-on: https://github.com/flang-compiler/f18/pull/814
2019-11-21 11:14:51 -08:00
peter klausler ff765f8500 [flang] For call11.f90: more checks on PURE subprograms and TBP bindings
Original-commit: flang-compiler/f18@7aa47f0b9e
Reviewed-on: https://github.com/flang-compiler/f18/pull/833
2019-11-19 14:52:03 -08:00
peter klausler fc94aa6d32 [flang] Define runtime I/O library interface to be used by generated code.
Original-commit: flang-compiler/f18@82cb9b0c87
Reviewed-on: https://github.com/flang-compiler/f18/pull/802
2019-11-19 10:11:23 -08:00
David Truby f3cab5281d [flang] Another atempt to lower core count
Original-commit: flang-compiler/f18@60eeb446b1
Reviewed-on: https://github.com/flang-compiler/f18/pull/832
2019-11-18 14:27:34 +00:00
David Truby e5b754e810 [flang] Change images used for CI to solve build issues
Original-commit: flang-compiler/f18@325b26b3a4
Reviewed-on: https://github.com/flang-compiler/f18/pull/832
Tree-same-pre-rewrite: false
2019-11-18 10:19:02 +00:00
Steve Scalpone 33dad73187 [flang] Rename flang-features to Fortran-features; update the guard macro.
Original-commit: flang-compiler/f18@1a7f5596ec
Reviewed-on: https://github.com/flang-compiler/f18/pull/826
2019-11-14 20:34:50 -08:00
Steve Scalpone ccee728e5a [flang] Rename features.h because many linux systems have an include file called features.h which can complicate makefiles that use a search path.
Original-commit: flang-compiler/f18@fc34d0ddf3
Reviewed-on: https://github.com/flang-compiler/f18/pull/826
Tree-same-pre-rewrite: false
2019-11-14 15:16:38 -08:00
peter klausler ed1ed24ec2 [flang] Semantic checks for PURE subprograms (test call10.f90)
Fix bug found in testing

Original-commit: flang-compiler/f18@ccdd7326ba
Reviewed-on: https://github.com/flang-compiler/f18/pull/825
2019-11-15 10:30:14 -08:00
David Truby 608ea6414d [flang] Disable arm64 gcc builds in CI until they can be fixed
Currently the arm64 gcc builds in CI are getting stuck,
so disable these to get CI working again until they're fixed.

Original-commit: flang-compiler/f18@49803e62ee
Reviewed-on: https://github.com/flang-compiler/f18/pull/829
2019-11-15 16:30:28 +00:00
Tim Keith 158f9e09fc [flang] Fix bad deference in ProgramTree
We weren't handling MainProgram with no ProgramStmt correctly in
ProgramTree. When building it we were dereferencing an empty optional.
And in ResolveSpecificationParts we were dereferencing a null pointer.

Original-commit: flang-compiler/f18@1bda90d005
Reviewed-on: https://github.com/flang-compiler/f18/pull/827
2019-11-14 19:22:24 -08:00
David Truby 056f5f73b7 [flang] Reduce number of threads used for building.
This is to avoid running out of memory on some builds.

Original-commit: flang-compiler/f18@f8abe443cf
Reviewed-on: https://github.com/flang-compiler/f18/pull/823
2019-11-14 15:16:15 +00:00
David Truby 877b26598d [flang] Add CI file for cloud.drone.io
Original-commit: flang-compiler/f18@32252639ab
Reviewed-on: https://github.com/flang-compiler/f18/pull/823
Tree-same-pre-rewrite: false
2019-11-13 11:31:44 +00:00
kiranktp 17332e283e [flang] Fix for flang-compiler/f18#694 - Unexpected error when compiling submodule
Incorporated all review comments and updated the test case.

Change-Id: I03939bfc705cc5319a0b7da3305026b8403b8edc

Original-commit: flang-compiler/f18@5c602bfbc7
Reviewed-on: https://github.com/flang-compiler/f18/pull/817
2019-11-14 17:14:57 +05:30
kiranktp e572117f8b [flang] Fix for flang-compiler/f18#694 - Unexpected error when compiling submodule
Incorporated all review comments and updated the test case.

Change-Id: I03939bfc705cc5319a0b7da3305026b8403b8edc

Original-commit: flang-compiler/f18@a52b0367ea
Reviewed-on: https://github.com/flang-compiler/f18/pull/817
Tree-same-pre-rewrite: false
2019-11-14 11:12:39 +05:30
kiranktp deffc7a55c [flang] Fix for flang-compiler/f18#694 - Unexpected error when compiling submodule
Incorporated all review comments and updated the test case.

Change-Id: I03939bfc705cc5319a0b7da3305026b8403b8edc

Original-commit: flang-compiler/f18@010da4228e
Reviewed-on: https://github.com/flang-compiler/f18/pull/817
Tree-same-pre-rewrite: false
2019-11-14 10:54:52 +05:30
kiranktp c1ca1b2b7f [flang] Fix for flang-compiler/f18#694 - Unexpected error when compiling submodule
Change-Id: I03939bfc705cc5319a0b7da3305026b8403b8edc

Original-commit: flang-compiler/f18@e1237939aa
Reviewed-on: https://github.com/flang-compiler/f18/pull/817
Tree-same-pre-rewrite: false
2019-11-07 15:17:57 +05:30
Tim Keith b5c7193769 [flang] Fix crashes in ResolveOmpObject and RewriteOpenMPLoopConstruct
Using debug build of f18, `omp-resolve01.f90` sometimes crashed in
`OmpVisitor::ResolveOmpObject`. This was because when the designator was
analyzed it could be rewritten from an `ArrayElement` to a `Substring`.
That made the reference to the `Name` inside the designator no longer
valid so the crash happened when it was referenced later. The fix is to
return when the substring is detected so the name is not referenced.

Also, the name returned from `ResolveDesignator` can but null so it must
be checked.

The crash in `RewriteOpenMPLoopConstruct` happened intermittently on
`omp-loop-association.f90`. It happened when the DO construct was the
last element of the block. In that case `block.erase()` returns an
iterator pointing to `block.end()` which must not be dereferenced.

Original-commit: flang-compiler/f18@3299972d04
Reviewed-on: https://github.com/flang-compiler/f18/pull/824
2019-11-14 15:01:20 -08:00
peter klausler 18f5ce5964 [flang] Remove most comparisons to nullptr
Remove needless usage of has_value()

Original-commit: flang-compiler/f18@1da7fcf7a5
Reviewed-on: https://github.com/flang-compiler/f18/pull/822
2019-11-11 14:40:59 -08:00
peter klausler 6c9b8845e9 [flang] checkpoint, all tests pass
Fix name resolution for undeclared intrinsic actual arguments

Original-commit: flang-compiler/f18@12470f06bc
Reviewed-on: https://github.com/flang-compiler/f18/pull/818
2019-11-09 08:37:39 -08:00
sameeranjoshi17 8d216b40c8 [flang] Added passing test case
Original-commit: flang-compiler/f18@752142055b
Reviewed-on: https://github.com/flang-compiler/f18/pull/808
2019-11-06 17:13:22 +05:30
sameeranjoshi17 4aac676c54 [flang] Added test case for semantic check of OpenMP Master construct
Original-commit: flang-compiler/f18@22f3088c76
Reviewed-on: https://github.com/flang-compiler/f18/pull/808
Tree-same-pre-rewrite: false
2019-11-06 14:18:12 +05:30
sameeranjoshi17 e2166e1ca0 [flang] semantic checks for Master construct
Original-commit: flang-compiler/f18@b052a71062
Reviewed-on: https://github.com/flang-compiler/f18/pull/808
Tree-same-pre-rewrite: false
2019-11-03 23:08:26 +05:30
Tim Keith 9b31cbe7db [flang] Add support for logical abbreviations and .XOR.
Update the grammar to handle logical abbreviations (e.g. `.A.` for `.AND.`)
when the feature is enabled. Only support `.X.` when both XOR and
logical abbreviations are enabled.

Fix the driver to enable logical abbreviations with the
`-flogical-abbreviations` option. This was already documented in
`documentation/Extensions.md`.

Remove `parser::Expr::XOR` from the parse tree and immediately map
`.XOR.` to `.NEQV.` if that feature is enabled. This was already being
done during expression analysis anyway.

Add `LanguageFeatureControl::GetNames` to return all of the names of
a logical or relational operator, depending on which features are
enabled. Use these in both name resolution and expression analysis.
Add `Not` to `LogicalOperator` to help in those cases.

Fix handling of BOZ literals: A numeric operation with one real or
integer operand and the other a BOZ literal is intrinsic.
Also, unary plus with a BOZ literal operand is also intrinsic.

Original-commit: flang-compiler/f18@956bd50bc7
Reviewed-on: https://github.com/flang-compiler/f18/pull/815
2019-11-07 14:45:58 -08:00
Tim Keith cae50f01ff [flang] Move features.h from parser to common
Which features are enabled and disabled applies to more than just the
parser, so move that functionality to `common`.

Original-commit: flang-compiler/f18@98b3240efc
Reviewed-on: https://github.com/flang-compiler/f18/pull/815
Tree-same-pre-rewrite: false
2019-11-06 11:15:03 -08:00
peter klausler a717d170cc [flang] Change more pointers into references
Remove unused interface

Respond to review comments

Original-commit: flang-compiler/f18@7fdfe7b4ac
Reviewed-on: https://github.com/flang-compiler/f18/pull/809
2019-11-05 10:28:17 -08:00
vdonaldson 65791b2d0b [flang] Relax the implementation of constraint C1302. (flang-compiler/f18#805)
* Relax the implementation of constraint C1302.

When a list of format items can be unambiguously partitioned into individual items even though one or more otherwise required comma separators are omitted, generate a warning rather than an error.

Fixes flang-compiler/f18#703

Original-commit: flang-compiler/f18@79c0731137
Reviewed-on: https://github.com/flang-compiler/f18/pull/805
2019-11-05 10:11:36 -08:00
Jean Perier 572de7c7b0 [flang] Implement MIN and MAX folding
* Use Extremum<T> FoldOperation to fold MIN and MAX
* Fix Extremum<T> FolOperation
    * For character, the length is the one of the longest argument.
      Define and use `CharacterUtils<Kind>::Resize` helper to do this.
    * For array of all types, Extremum<T> with Ordering::Less was
      behaving like Ordering::Greater. This is because the default
      `ApplyElementwise` for `Operation` was selected and it then
       called the Extremum<T> constructor without the ordering
       argument (which was an optional defaulted to Greater).
      Define a specific handler for Extremum<T> and make the ordering
      argument mandatory to prevent this kind of bug to pass
      f18 compilation in the futur.
* Fix intrinsic.cc for MIN and MAX
    * When provided with two arguments, `Match` was adding an empty
      3rd optional actual argument. Later code working on min and
      max was not expecting this and failing. The fix prevent this
      empty argument to be created by changing the initial size of
      `actualForDummy` to actually be the number of dummies that do
      not have `Optionality::Repeats`

This commit fixes issue flang-compiler/f18#677.

Original-commit: flang-compiler/f18@acb62f240b
Reviewed-on: https://github.com/flang-compiler/f18/pull/803
2019-11-05 02:54:12 -08:00
peter klausler 2c89c31a59 [flang] Enable and pass call08.f90
Refine a check

Original-commit: flang-compiler/f18@bb96c195d4
Reviewed-on: https://github.com/flang-compiler/f18/pull/812
2019-11-04 14:35:36 -08:00
Tim Keith cf9059ae98 [flang] Fix build error using clang
Change `AllFortranNames()` to return a `std::vector` rather than a
`std::initialization_list`. The latter doesn't own its underlying
storage and so can't be returned as a value. clang detects this and
issues a warning.

Two tests in `resolve63.f90` behave differently with clang and require
further investigation.

Original-commit: flang-compiler/f18@1ed3a3cfee
Reviewed-on: https://github.com/flang-compiler/f18/pull/810
2019-11-04 12:05:51 -08:00
Tim Keith dce7f0aca0 [flang] Resolve extended intrinsic operators
Enhance `ArgumentAnalyzer` to do most of the work for this.
For each kind of operator that might have a user-defined form we follow
this process:
- analyze the arguments
- if the types and shapes match the intrinsic operator do the usual
  processing
- otherwise attempt to interpret it as a user-defined operator with
  `TryDefinedOp`

When we fail to resolve an operator, produce different errors depending
on whether there is a user-defined operator available or not.
If there is, report that neither user-defined nor intrinsic operator
worked. If there is not, describe the rules for the intrinsic operator.
In either case, include the type(s) of the operand(s).

Most of the uses of `ArgumentAnalyzer` are in helper functions that
apply to classes of operators.
For consistency, rename `BinaryOperationHelper` to `NumericBinaryOperator`
and `LogicalHelper` to `LogicalBinaryHelper` and introduce `NumericUnaryHelper`
for unary `+` and `-`.  `.NOT.` and `//` are not implemented in helpers.

Replace `success_` with `fatalErrors_` in `ArgumentAnalyzer` for
consistency with `ExpressionAnalyzer`.

Add `NumericOperator` and `LogicalOperator` enums to `Fortran.h` to go
with `RelationalOperator`. Add `AddFortran` functions to each to convert
to a Fortran source string. `RelationalOperator` also has `AllFortranNames`
because there are multiple names for each operator. This replaces
`LogicalOperator` in `expression.h` and the string representation of
the operators in `formatting.cc`.

Original-commit: flang-compiler/f18@3bb9d664e8
Reviewed-on: https://github.com/flang-compiler/f18/pull/807
2019-11-04 10:47:43 -08:00