platform/upstream/llvm.git
4 years ago[flang] Change CheckDefinabilityInPureScope to return bool
Tim Keith [Thu, 5 Mar 2020 21:05:45 +0000 (13:05 -0800)]
[flang] Change CheckDefinabilityInPureScope to return bool

Have CheckDefinabilityInPureScope and CheckCopyabilityInPureScope return
false when their checks fail and report errors so that we will be able
to avoid reporting extra errors in those cases.

Original-commit: flang-compiler/f18@305a3470e572161483b0f430514b77ba19f932ea
Reviewed-on: https://github.com/flang-compiler/f18/pull/1050
Tree-same-pre-rewrite: false

4 years ago[flang] Change WhyNotModifiable to return optional
Tim Keith [Thu, 5 Mar 2020 20:56:30 +0000 (12:56 -0800)]
[flang] Change WhyNotModifiable to return optional

One overload of WhyNotModifiable returned an optional message while the
other returns a unique_ptr. Change the latter to be consistent with the
former and other message-returning functions in this file.

Also, reorder the if clauses to reduce the level of indentation.

Original-commit: flang-compiler/f18@864e9cfc7ee98e3646052fdc757943011d641691
Reviewed-on: https://github.com/flang-compiler/f18/pull/1050
Tree-same-pre-rewrite: false

4 years ago[flang] Fix handling of DataRef when analyzing CoindexedNamedObject
Tim Keith [Sat, 7 Mar 2020 01:05:04 +0000 (17:05 -0800)]
[flang] Fix handling of DataRef when analyzing CoindexedNamedObject

As we loop through the Components, maintain a pointer to the current
DataRef rather than moving it. This is more efficient and the previous
behavior caused illegal memory accesses.

Original-commit: flang-compiler/f18@cede2971ff863b8dd6a2c8727f6566a444ac7a52
Reviewed-on: https://github.com/flang-compiler/f18/pull/1050
Tree-same-pre-rewrite: false

4 years ago[flang] Fix for 'wrong constant folding of assumed-rank array' (flang-compiler/f18...
Steve Scalpone [Thu, 5 Mar 2020 16:06:58 +0000 (08:06 -0800)]
[flang] Fix for 'wrong constant folding of assumed-rank array' (flang-compiler/f18#1010)

https://github.com/flang-compiler/f18/issues/990

Original-commit: flang-compiler/f18@d971333025bb316529d233528a725fcc726f6615
Reviewed-on: https://github.com/flang-compiler/f18/pull/1010

4 years ago[flang] Change README to refer to LLVM_BUILD_DIR. (flang-compiler/f18#1033)
Steve Scalpone [Thu, 5 Mar 2020 15:12:06 +0000 (07:12 -0800)]
[flang] Change README to refer to LLVM_BUILD_DIR. (flang-compiler/f18#1033)

* Change README to refer to LLVM_BUILD_DIR.

LLVM_INSTALL_TOOLS doesn't to install llvm-lit. However pointing to the cmake file in the build directory works fine, and lit and FileCheck will be picked up correctly this way.

Original-commit: flang-compiler/f18@3cbe344f82a0898c9e20b6718d5f80d52670838b
Reviewed-on: https://github.com/flang-compiler/f18/pull/1033

4 years ago[flang] Use a file descriptor in Temp struct (flang-compiler/f18#1036)
Steve Scalpone [Thu, 5 Mar 2020 15:09:29 +0000 (07:09 -0800)]
[flang] Use a file descriptor in Temp struct (flang-compiler/f18#1036)

The struct Temp is used in the function call createUniqueFile
which only takes in a file descriptor instead of a file handler.
In Unix these are the same thing, but in Windows they are different.
Therefore, the type of the member of struct Temp is changed
from file handler to file descriptor and when closing the file
the file descriptor is converted to a file handler.

Original-commit: flang-compiler/f18@a8edb328f717305143ac827132c6d6f45e6e11b9
Reviewed-on: https://github.com/flang-compiler/f18/pull/1036

4 years ago[flang] Use std::mutex instead of pthreads (flang-compiler/f18#1006)
Steve Scalpone [Thu, 5 Mar 2020 14:52:35 +0000 (06:52 -0800)]
[flang] Use std::mutex instead of pthreads (flang-compiler/f18#1006)

* Use std::mutex for portability.

Original-commit: flang-compiler/f18@a9a725eb9d2c39a203f4b4f55f1e03c5e17f6cf7
Reviewed-on: https://github.com/flang-compiler/f18/pull/1006

4 years ago[flang] Add missing include <algorithm> for std::max (flang-compiler/f18#1028)
Steve Scalpone [Thu, 5 Mar 2020 14:31:24 +0000 (06:31 -0800)]
[flang] Add missing include <algorithm> for std::max (flang-compiler/f18#1028)

Original-commit: flang-compiler/f18@0e32eebf7fec8cd07ab3280565799cfbf2ca55e2
Reviewed-on: https://github.com/flang-compiler/f18/pull/1028

4 years ago[flang] Don't link to libm (flang-compiler/f18#1038)
Steve Scalpone [Thu, 5 Mar 2020 13:40:44 +0000 (05:40 -0800)]
[flang] Don't link to libm (flang-compiler/f18#1038)

* Don't link to libm on windows

* Don't link to libm in Unix as well

Original-commit: flang-compiler/f18@a807862ab85f2d2206f8fa77d927b0e110513620
Reviewed-on: https://github.com/flang-compiler/f18/pull/1038

4 years ago[flang] Merge pull request flang-compiler/f18#1043 from DavidTruby/zlib
Eric Schweitz [Wed, 4 Mar 2020 23:57:09 +0000 (15:57 -0800)]
[flang] Merge pull request flang-compiler/f18#1043 from DavidTruby/zlib

Link against zlib when LLVM does.

Original-commit: flang-compiler/f18@8b0a473069cb3691d604f72d7f9a5200aa7f1c01
Reviewed-on: https://github.com/flang-compiler/f18/pull/1043

4 years ago[flang] Link against zlib when LLVM does.
David Truby [Mon, 2 Mar 2020 13:35:24 +0000 (13:35 +0000)]
[flang] Link against zlib when LLVM does.

Original-commit: flang-compiler/f18@2260abe4c27a76e374b286df072e303aa9ea1418
Reviewed-on: https://github.com/flang-compiler/f18/pull/1043

4 years ago[flang] Merge pull request flang-compiler/f18#1046 from flang-compiler/tsk-comps
Tim Keith [Tue, 3 Mar 2020 21:28:04 +0000 (13:28 -0800)]
[flang] Merge pull request flang-compiler/f18#1046 from flang-compiler/tsk-comps

Improve checking of structure constructor keywords

Original-commit: flang-compiler/f18@c80c72d6f96e75c9b6d12c12b813a0922c6d39ef
Reviewed-on: https://github.com/flang-compiler/f18/pull/1046

4 years ago[flang] Improve checking of structure constructor arguments
Tim Keith [Tue, 3 Mar 2020 00:43:01 +0000 (16:43 -0800)]
[flang] Improve checking of structure constructor arguments

When a misparsed FunctionReference was converted to a StructureConstructor,
the components accessed were not checked for accessibility.

The conversion happens in expression analysis so that where the accessibity
must be checked. So move `CheckAccessibleComponent` to `tools.h` so that it
can be shared by `resolve-names.cpp` and `expression.cpp`.

Add FindModuleContaining to help implement this and use it other places.

Check that an access-spec can only appear in a module.

Remove some unnecessary "semantics::" qualifiers.

Original-commit: flang-compiler/f18@99ce156e49ec0847ce42a6d10f0a62664714092b
Reviewed-on: https://github.com/flang-compiler/f18/pull/1046

4 years ago[flang] Merge pull request flang-compiler/f18#1039 from flang-compiler/tsk-arrays
Tim Keith [Tue, 3 Mar 2020 00:53:22 +0000 (16:53 -0800)]
[flang] Merge pull request flang-compiler/f18#1039 from flang-compiler/tsk-arrays

Improve array element errors

Original-commit: flang-compiler/f18@899ef78d6aac3a1c5e8264100165dcc2521684c6
Reviewed-on: https://github.com/flang-compiler/f18/pull/1039

4 years ago[flang] Improve array element errors
Tim Keith [Fri, 28 Feb 2020 02:00:45 +0000 (18:00 -0800)]
[flang] Improve array element errors

When something is parsed as an array element it was sometimes intended
to be a function call or structure constructor. So if the base name is
not found the errors can be confusing. This is an attempt to improve
them.

When the subscript list is empty, it was probably meant to be a function
call, so report that the name is not a function.

If the base is a scalar but there are subscripts, report that it is not
an array.

Original-commit: flang-compiler/f18@e2fd5333ff1bb1e8e88cbf35028654bcf70fe9e9
Reviewed-on: https://github.com/flang-compiler/f18/pull/1039

4 years ago[flang] Merge pull request flang-compiler/f18#1044 from flang-compiler/tsk-data
Tim Keith [Mon, 2 Mar 2020 21:37:33 +0000 (13:37 -0800)]
[flang] Merge pull request flang-compiler/f18#1044 from flang-compiler/tsk-data

Expression analysis on DataStmtConstant

Original-commit: flang-compiler/f18@1611fd8e9e237dc86266b146309931428d228ace
Reviewed-on: https://github.com/flang-compiler/f18/pull/1044

4 years ago[flang] Expression analysis on DataStmtConstant
Tim Keith [Mon, 2 Mar 2020 15:59:29 +0000 (07:59 -0800)]
[flang] Expression analysis on DataStmtConstant

Data statements contains expressions but they are not wrapped in one of
the kinds of parse tree nodes that are analyzed, like `parser::Expr`.
So potential errors were not discovered.

Change `ExprChecker` to handle `DataStmtConstant` and analyze any
expressions that are contained in it. Note that the analyzed form of
the expression is not yet saved in the parse tree.

Original-commit: flang-compiler/f18@8bdaf0a521f6630ec2c369b2c41484eff4803d6e
Reviewed-on: https://github.com/flang-compiler/f18/pull/1044

4 years ago[flang] Merge pull request flang-compiler/f18#1037 from vjayathirtha-nv/master
vjayathirtha-nv [Fri, 28 Feb 2020 00:05:22 +0000 (16:05 -0800)]
[flang] Merge pull request flang-compiler/f18#1037 from vjayathirtha-nv/master

Add semantic checks C8104, C8105. Add tests for C8103, C8104, C8105

Original-commit: flang-compiler/f18@f2a4e5c685bc421306611c64295caa50986d9578
Reviewed-on: https://github.com/flang-compiler/f18/pull/1037

4 years ago[flang] Add semantic checks C8104, C8105. Add tests for C8103, C8104, C8105
Varun Jayathirtha [Wed, 26 Feb 2020 02:01:23 +0000 (18:01 -0800)]
[flang] Add semantic checks C8104, C8105. Add tests for C8103, C8104, C8105

Original-commit: flang-compiler/f18@8134fc477e843d9bf525eeb552ba1d234140e7a7
Reviewed-on: https://github.com/flang-compiler/f18/pull/1037

4 years ago[flang] Merge pull request flang-compiler/f18#1031 from flang-compiler/ps-types
psteinfeld [Thu, 27 Feb 2020 21:57:27 +0000 (13:57 -0800)]
[flang] Merge pull request flang-compiler/f18#1031 from flang-compiler/ps-types

Semantic checks for C712 through C727

Original-commit: flang-compiler/f18@d6898ab882009197beb898152f0d05fe708cc658
Reviewed-on: https://github.com/flang-compiler/f18/pull/1031

4 years ago[flang] Responses to pull request comments
Pete Steinfeld [Thu, 27 Feb 2020 16:49:40 +0000 (08:49 -0800)]
[flang] Responses to pull request comments

I cleaned up some code and reverted a change to semantic checking for
the exponent letter in REAL literals.

Original-commit: flang-compiler/f18@e81f57fcf54ee0493044d53a6d1bf05f661e2660
Reviewed-on: https://github.com/flang-compiler/f18/pull/1031

4 years ago[flang] Semantic checks for C712 through C727
Pete Steinfeld [Thu, 27 Feb 2020 04:19:48 +0000 (20:19 -0800)]
[flang] Semantic checks for C712 through C727

I've updated the compiler and test source with references to the contraints at
the points where they were enforced and tested.  Many of these were already
implemented and required no code change.  A few constraint checks were both
implemented and tested, and I only added references to the constraint
numbers in the compiler source and tests.  Here are the things I had to
implement:

Constraint C716 states that, in a REAL constant, if both a kind-param and an
exponent letter appear, the exponent letter must be 'E'.

Constraints C715 and C719 require that a KIND value be actually implemented.

Constraint C722 requires that functions that return assumed-length character
types are external.

Constraint C726 disallows assumed lenght charater types for dummy arguments and
return types.

Original-commit: flang-compiler/f18@45998741e5f04bba7db6eed6a4d27c1d25209b41
Reviewed-on: https://github.com/flang-compiler/f18/pull/1031
Tree-same-pre-rewrite: false

4 years ago[flang] Merge pull request flang-compiler/f18#1024 from flang-compiler/tsk-rewrite
Tim Keith [Thu, 27 Feb 2020 03:20:57 +0000 (19:20 -0800)]
[flang] Merge pull request flang-compiler/f18#1024 from flang-compiler/tsk-rewrite

Fix misparsed structure constructor in data stmt

Original-commit: flang-compiler/f18@7649e5d705b2c87d710525d522a42288030c3bfa
Reviewed-on: https://github.com/flang-compiler/f18/pull/1024

4 years ago[flang] Fix misparsed structure constructor in data stmt
Tim Keith [Wed, 26 Feb 2020 01:13:56 +0000 (17:13 -0800)]
[flang] Fix misparsed structure constructor in data stmt

In a data statement like `data x / a(1) /`, `a(1)` may be an array
element or a structure constructor. It is parsed as an array element
so if it turns out `a` is a derived type it must be rewritten as a
strucutre constructor.

Original-commit: flang-compiler/f18@a2b2a330e7dbb8d719fdab9bb28921cf84f503ca
Reviewed-on: https://github.com/flang-compiler/f18/pull/1024

4 years ago[flang] Merge pull request flang-compiler/f18#1014 from flang-compiler/tsk-where
Tim Keith [Thu, 27 Feb 2020 00:10:49 +0000 (16:10 -0800)]
[flang] Merge pull request flang-compiler/f18#1014 from flang-compiler/tsk-where

Remove use of std::set::merge

Original-commit: flang-compiler/f18@59c14bad32093f5ccfcd0a05e337295c2c1c85ea
Reviewed-on: https://github.com/flang-compiler/f18/pull/1014

4 years ago[flang] Remove use of std::set::merge
Tim Keith [Sat, 22 Feb 2020 19:47:04 +0000 (11:47 -0800)]
[flang] Remove use of std::set::merge

Some versions of clang that we are building with don't have
std::set::merge, even though it is part of C++17. Work around
that by using std::set::insert until we can count on merge being
available everywhere.

Original-commit: flang-compiler/f18@886ccc37fbff5df00717ac728e2aba240d0a314c
Reviewed-on: https://github.com/flang-compiler/f18/pull/1014

4 years ago[flang] Add script to flatten git history for llvm monorepo submission (flang-compile...
Peter Waller [Wed, 26 Feb 2020 19:50:43 +0000 (19:50 +0000)]
[flang] Add script to flatten git history for llvm monorepo submission (flang-compiler/f18#854)

This script, when run on a checkout of the f18 repository, takes the
current origin/master and makes a branch called "new" with a rewritten
history;

The "new" branch has a flat git history (that is, a series of commits
with only one parent). Flattening is done for merge commits by taking
the content of the commit as it is at the merge commit.

Original-commit: flang-compiler/f18@d9871fa9eb2304c4761a4a818187553396bb8924
Reviewed-on: https://github.com/flang-compiler/f18/pull/854

4 years ago[flang] Merge pull request flang-compiler/f18#1021 from flang-compiler/pmk-ieee-128
Peter Klausler [Wed, 26 Feb 2020 16:54:41 +0000 (08:54 -0800)]
[flang] Merge pull request flang-compiler/f18#1021 from flang-compiler/pmk-ieee-128

Fix layout of 128-bit IEEE-754 floating-point values

Original-commit: flang-compiler/f18@91feed7a3841bb4f865353ebd7790c39ea926390
Reviewed-on: https://github.com/flang-compiler/f18/pull/1021

4 years ago[flang] Fix layout of 128-bit IEEE-754 floating-point values
peter klausler [Tue, 25 Feb 2020 01:04:54 +0000 (17:04 -0800)]
[flang] Fix layout of 128-bit IEEE-754 floating-point values

Original-commit: flang-compiler/f18@c95c45704e7c0afeb0d2dbec965afd368e923a3a
Reviewed-on: https://github.com/flang-compiler/f18/pull/1021

4 years ago[flang] Merge pull request flang-compiler/f18#1026 from flang-compiler/jpr-drone-fix
jeanPerier [Wed, 26 Feb 2020 15:15:42 +0000 (07:15 -0800)]
[flang] Merge pull request flang-compiler/f18#1026 from flang-compiler/jpr-drone-fix

Fix drone CI build failure due to lack of FileCheck

Original-commit: flang-compiler/f18@a5644a4e8e81c47de1352829a562193e7cfaff03
Reviewed-on: https://github.com/flang-compiler/f18/pull/1026

4 years ago[flang] Remove clang from LLVM drone builds until needed to fasten builds
Jean Perier [Wed, 26 Feb 2020 14:16:22 +0000 (06:16 -0800)]
[flang] Remove clang from LLVM drone builds until needed to fasten builds

Original-commit: flang-compiler/f18@5eaebc800caa90b592c5ba8cf1fd6fd3987b3636
Reviewed-on: https://github.com/flang-compiler/f18/pull/1026

4 years ago[flang] Fix drone CI build failure due to lack of FileCheck
Jean Perier [Wed, 26 Feb 2020 10:01:02 +0000 (02:01 -0800)]
[flang] Fix drone CI build failure due to lack of FileCheck

Simply use the llvm build directory and save installing LLVM on the way.

Original-commit: flang-compiler/f18@7848ab146ad32062daba9f07b032655568381a1b
Reviewed-on: https://github.com/flang-compiler/f18/pull/1026
Tree-same-pre-rewrite: false

4 years ago[flang] Merge pull request flang-compiler/f18#1023 from flang-compiler/tsk-issue1022
Tim Keith [Tue, 25 Feb 2020 23:32:06 +0000 (15:32 -0800)]
[flang] Merge pull request flang-compiler/f18#1023 from flang-compiler/tsk-issue1022

Allow for access-stmt before namelist-stmt

Original-commit: flang-compiler/f18@618dc08139664c944f57b6763751b264ca2cf579
Reviewed-on: https://github.com/flang-compiler/f18/pull/1023

4 years ago[flang] Allow for access-stmt before namelist-stmt
Tim Keith [Tue, 25 Feb 2020 02:55:53 +0000 (18:55 -0800)]
[flang] Allow for access-stmt before namelist-stmt

You can declare a name in an access statement and then declare it as
a namelist group name. We weren't allowing that because we didn't
convert a symbol with UnknownDetails to one with NamelistDetails.

Fixes flang-compiler/f18#1022.

Original-commit: flang-compiler/f18@a759204db583d337dda886acf748e0fe135c6259
Reviewed-on: https://github.com/flang-compiler/f18/pull/1023

4 years ago[flang] Replace module writer posix file handling with llvm file handling. (flang...
David Truby [Tue, 25 Feb 2020 15:59:50 +0000 (15:59 +0000)]
[flang] Replace module writer posix file handling with llvm file handling. (flang-compiler/f18#993)

NOTE: This commit introduces a dependency on LLVM HEAD

Original-commit: flang-compiler/f18@97efc0194d411a17ec47edf5e27157d1a1afa3bc
Reviewed-on: https://github.com/flang-compiler/f18/pull/993

4 years ago[flang] [LLVMify F18] Compiler module folders should have capitalised names (flang...
CarolineConcatto [Tue, 25 Feb 2020 15:11:52 +0000 (15:11 +0000)]
[flang] [LLVMify F18] Compiler module folders should have capitalised names (flang-compiler/f18#980)

This patch renames the modules in f18 to use a capital letter in the
module name

Signed-off-by: Caroline Concatto <caroline.concatto@arm.com>
Original-commit: flang-compiler/f18@d2eb7a1c443d1539ef12b6f027074a0eb15b1ea0
Reviewed-on: https://github.com/flang-compiler/f18/pull/980

4 years ago[flang] Merge pull request flang-compiler/f18#1013 from flang-compiler/tsk-rewrite
Tim Keith [Sat, 22 Feb 2020 00:25:54 +0000 (16:25 -0800)]
[flang] Merge pull request flang-compiler/f18#1013 from flang-compiler/tsk-rewrite

Temporarily disable part of data01 test

Original-commit: flang-compiler/f18@cf48fe874617647e5f9250bedd35248711b8371c
Reviewed-on: https://github.com/flang-compiler/f18/pull/1013

4 years ago[flang] Temporarily disable part of data01 test
Tim Keith [Sat, 22 Feb 2020 00:25:10 +0000 (16:25 -0800)]
[flang] Temporarily disable part of data01 test

`data x /a(1)/` is ambiguous. The data value may be an array element
or a structure constructor. We need to parse it as one of these and
then fix up the parse tree when it should have been the other one.

My PR 1012 changed the parser to identify this as an array element.
That makes this test invalid until we have the right parse tree fixup,
so I am disabling it for now.

Original-commit: flang-compiler/f18@72aa278f0341f345a12fcd76a6ad1f2045ecc233
Reviewed-on: https://github.com/flang-compiler/f18/pull/1013

4 years ago[flang] Merge pull request flang-compiler/f18#1009 from flang-compiler/tsk-where
Tim Keith [Fri, 21 Feb 2020 23:48:52 +0000 (15:48 -0800)]
[flang] Merge pull request flang-compiler/f18#1009 from flang-compiler/tsk-where

Add more checks on WHERE and FORALL

Original-commit: flang-compiler/f18@c9638d10c6515703e8c095127bd46ae1dae1637e
Reviewed-on: https://github.com/flang-compiler/f18/pull/1009

4 years ago[flang] Add more checks on WHERE and FORALL
Tim Keith [Thu, 20 Feb 2020 22:54:46 +0000 (14:54 -0800)]
[flang] Add more checks on WHERE and FORALL

Check that masks and LHS of assignments in WHERE statements and
constructs have consistent shapes. They must all have the same rank and
any extents that are compile-time constants must match.

Emit a warning for assignments in FORALL statements and constructs where
the LHS does not reference each of the index variables.

Original-commit: flang-compiler/f18@8b04dbebcf5621cfd571a8c45878cebcd1a1bfb0
Reviewed-on: https://github.com/flang-compiler/f18/pull/1009

4 years ago[flang] Merge pull request flang-compiler/f18#1012 from flang-compiler/tsk-rewrite
Tim Keith [Fri, 21 Feb 2020 23:46:24 +0000 (15:46 -0800)]
[flang] Merge pull request flang-compiler/f18#1012 from flang-compiler/tsk-rewrite

Fix parsing bug on DATA statement

Original-commit: flang-compiler/f18@b9f2617f55bd3be8414f8d8f078f53f0bf881667
Reviewed-on: https://github.com/flang-compiler/f18/pull/1012

4 years ago[flang] Fix parsing bug on DATA statement
Tim Keith [Fri, 21 Feb 2020 23:31:12 +0000 (15:31 -0800)]
[flang] Fix parsing bug on DATA statement

This DATA statement was getting a parsing error:
`data x /a(i)%b/`

The parser was expecting the ending '/' where the '%' was. The problem
was parsing `a(i)` as a structure constructor. Instead, move the
constant subobject case before structure constructor, but match it only
if not followed by '('. That is because in `data x /a(1)(2)/`, `a(1)` is
a valid structure constructor.

Also, remove the NamedConstant alternative from DataStmtRepeat. A named
constant is always parsed as a ConstantSubobject so it can never occur.

Original-commit: flang-compiler/f18@04a76b272675d47ec7752420b15976c69a907dab
Reviewed-on: https://github.com/flang-compiler/f18/pull/1012

4 years ago[flang] Issue flang-compiler/f18#992 : Implementing Semantic checks for DATA Stateme...
Anchu Rajendran S [Fri, 21 Feb 2020 06:19:14 +0000 (11:49 +0530)]
[flang] Issue flang-compiler/f18#992 :  Implementing Semantic checks for DATA Statement (C874-C887) (flang-compiler/f18#992)

This commit covers Semantic Constraints C882 - C887

C882 : It was partially Implemented. Finished the implementation
and added test case
C884 : Implemented and added test case
C883 : Implementation was there already. Added test case
C885, C886, C887 : Implementation was there already. Added test case for
data-repeat.

Original-commit: flang-compiler/f18@822129736b6b7a96b6ff3ffe810d842ce42e3672
Reviewed-on: https://github.com/flang-compiler/f18/pull/992

4 years ago[flang] Add missing array include (flang-compiler/f18#1004)
Isuru Fernando [Thu, 20 Feb 2020 21:12:49 +0000 (15:12 -0600)]
[flang] Add missing array include (flang-compiler/f18#1004)

Original-commit: flang-compiler/f18@de801a0db7614c93abc8239d02a453d60c9ea8a1
Reviewed-on: https://github.com/flang-compiler/f18/pull/1004

4 years ago[flang] Disable 80-bit extended precision if on MSVC (flang-compiler/f18#1003)
Isuru Fernando [Thu, 20 Feb 2020 19:33:43 +0000 (13:33 -0600)]
[flang] Disable 80-bit extended precision if on MSVC (flang-compiler/f18#1003)

Original-commit: flang-compiler/f18@2c1fc63758eac43eb4d2fd4fdf1e7b0e63d52f70
Reviewed-on: https://github.com/flang-compiler/f18/pull/1003

4 years ago[flang] Merge pull request flang-compiler/f18#989 from flang-compiler/tsk-forall
Tim Keith [Wed, 19 Feb 2020 21:42:30 +0000 (13:42 -0800)]
[flang] Merge pull request flang-compiler/f18#989 from flang-compiler/tsk-forall

Add FORALL checking to DoChecker

Original-commit: flang-compiler/f18@35fd0cda58776389d2ed68eaefbc1e1d59423ec8
Reviewed-on: https://github.com/flang-compiler/f18/pull/989

4 years ago[flang] Rename DoChecker to DoForallChecker
Tim Keith [Wed, 19 Feb 2020 21:28:19 +0000 (13:28 -0800)]
[flang] Rename DoChecker to DoForallChecker

This reflects the fact that it now performs checks on both DO
and FORALL constructs. Rename the source files as well.

Original-commit: flang-compiler/f18@8ecb6a279f53ff4cc9493506370664fb1923470a
Reviewed-on: https://github.com/flang-compiler/f18/pull/989

4 years ago[flang] Add FORALL checking to DoChecker
Tim Keith [Wed, 19 Feb 2020 01:14:24 +0000 (17:14 -0800)]
[flang] Add FORALL checking to DoChecker

FORALL statements and constructs require a lot of the same checking
as DO CONCURRENT, so do the checks in DoChecker so that code can be
shared where possible. This requires some reorganization there.
Remove code from AssignmentChecker that did some of these checks.

Change names that contain `DoVar` or `DoVariable` to `IndexVar` to
reflect the fact that they may be DO or FORALL index variables.
Distinguish between the two when necessary with enum `IndexVarKind`.

Change some messages that referred to "concurrent-header" or
"concurrent-control" to specifically say "DO CONCURRENT" or "FORALL".

Original-commit: flang-compiler/f18@84752c492e910573e2f0ede1ed3c0417aac363b9
Reviewed-on: https://github.com/flang-compiler/f18/pull/989
Tree-same-pre-rewrite: false

4 years ago[flang] Reorganize evaluate::Assignment
Tim Keith [Tue, 18 Feb 2020 23:20:28 +0000 (15:20 -0800)]
[flang] Reorganize evaluate::Assignment

Every analyzed assignment represented by `evaluate::Assignment` has
a LHS and RHS expression. These need to be checked uniformly in various
places. So change Assignment always to have those data members, with
the variant determining which kinds of assignment it is: intrinsic,
user-defined, or pointer.

Original-commit: flang-compiler/f18@fb87d16a868112e26ade0ad696b2232d8cf3a524
Reviewed-on: https://github.com/flang-compiler/f18/pull/989
Tree-same-pre-rewrite: false

4 years ago[flang] Merge pull request flang-compiler/f18#985 from flang-compiler/ps-types
psteinfeld [Wed, 19 Feb 2020 20:24:46 +0000 (12:24 -0800)]
[flang] Merge pull request flang-compiler/f18#985 from flang-compiler/ps-types

Semantic checks for C709, C710, and C711

Original-commit: flang-compiler/f18@fa6d4753b74d1fb5fa4b453d7c35de14910fd5be
Reviewed-on: https://github.com/flang-compiler/f18/pull/985

4 years ago[flang] Semantic checks for C709, C710, and C711
Pete Steinfeld [Fri, 14 Feb 2020 23:53:11 +0000 (15:53 -0800)]
[flang] Semantic checks for C709, C710, and C711

C709 An assumed-type entity shall be a dummy data object that does not
have the ALLOCATABLE, CODIMENSION, INTENT (OUT), POINTER, or VALUE
attribute and is not an explicit-shape array.

C710 An assumed-type variable name shall not appear in a designator or
expression except as an actual argument corresponding to a dummy
argument that is assumed-type, or as the first argument to the intrinsic
function IS_CONTIGUOUS, LBOUND, PRESENT, RANK, SHAPE, SIZE, or UBOUND,
or the function C_LOC from the intrinsic module ISO_C_BINDING.

C711 An assumed-type actual argument that corresponds to an assumed-rank
dummy argument shall be assumed-shape or assumed-rank.

For C709 I added code to check-declarations.cpp.  For this, I had to
distinguish between polymorphic types and assumed-type types to
eliminate multiple messages on the same line.

C710 was already checked, but I added a notation in the source.

For C711 I added code to check-call.cpp and the test call15.f90.

Original-commit: flang-compiler/f18@4a703f2b5a6484208a059dc0b456363c138a661d
Reviewed-on: https://github.com/flang-compiler/f18/pull/985

4 years ago[flang] Merge pull request flang-compiler/f18#994 from flang-compiler/jpr-fix-shared...
jeanPerier [Wed, 19 Feb 2020 18:44:59 +0000 (10:44 -0800)]
[flang] Merge pull request flang-compiler/f18#994 from flang-compiler/jpr-fix-shared-builds

Fix issues with -DBUILD_SHARED_LIBS=On

Original-commit: flang-compiler/f18@a20a80e71e05f5ceea84e804e8f4d7bd4b7b52e9
Reviewed-on: https://github.com/flang-compiler/f18/pull/994

4 years ago[flang] Fix issues with -DBUILD_SHARED_LIBS=On
Jean Perier [Wed, 19 Feb 2020 13:19:08 +0000 (05:19 -0800)]
[flang] Fix issues with -DBUILD_SHARED_LIBS=On

This re-ordering allows building f18 with shared library using and LLVM build
with static libraries.

This reordering (that also made sens form an alphabetical point of view)
works here to do such "shared+archive" compiling because the current
dependency on LLVM is simple (only one f18 lib + an executable depends on LLVM).
As soon as two f18 libraries will depend on LLVM, one will have to use an LLVM
version built with -DBUILD_SHARED_LIBS=On if one wants to use this option
to compile f18.

Original-commit: flang-compiler/f18@bbbbe9c1aa2fd38dc2164a6440290dbbea1518e2
Reviewed-on: https://github.com/flang-compiler/f18/pull/994

4 years ago[flang] [OpenMP] Predetermined rule for sequential loop index (flang-compiler/f18...
Jinxin (Brian) Yang [Wed, 19 Feb 2020 00:27:43 +0000 (16:27 -0800)]
[flang] [OpenMP] Predetermined rule for sequential loop index (flang-compiler/f18#976)

This commit implements rule:
A loop iteration variable for a sequential loop in a parallel or
task generating construct is private in the innermost such construct
that encloses the loop.

A Simple example:
```
  i = -1                    <== Scope 0
  j = -1
  !$omp parallel            <== Scope 1
  print *,i,j      <-- both are shared (Scope 0)
  !$omp parallel            <== Scope 2
  print *,i,j      <-- a) i is shared (Scope 0), j is private (Scope 2)
  !$omp do                  <== Scope 3
  do i=1, 10       <-- i is private (Scope 3)
     do j=1, 10    <-- b) j is private (Scope 2, not 3!)
     enddo
  enddo
  print *,i,j      <-- c) i is shared (Scope 0), j is private (Scope 2)
  !$omp end parallel
  print *,i,j      <-- both are shared (Scope 0)
  !$omp end parallel
  print *,i,j      <-- both are shared (Scope 0)
end
```

Ideally the above rule solves a), b), and c) but a) is left as a TODO
because it is better to handle the data-sharing attribute conflicts
along with the rules for "Predetermined DSA on Clauses".

The basic idea is when visiting the `DoConstruct` node within an OpenMP
construct, if the do-loop is not associated (like `i` loop is associated
with `!$omp do`) AND the do-loop is in the parallel/task generating
construct, resolve the loop index to be private to that innermost construct.

In the above example, `j` loop is not associated (then it is sequential) and
the innermost parallel/task generating construct that encloses the `j` loop
is the `parallel` construct marked with `<== Scope 2`, so `j` is private
to that construct. To do that, I also need to change the prototype of those
`ResolveOmp*` functions to allow specifiying the `scope` because the new
symbol for `j` should be created in Scope 2 and all the `symbol` field of
`Name j` in that `parallel` construct should be fixed, such as c).

Original-commit: flang-compiler/f18@69a845283b058a3644053ec58b00d3361f4d4a59
Reviewed-on: https://github.com/flang-compiler/f18/pull/976

4 years ago[flang] Merge pull request flang-compiler/f18#959 from jeanPerier/jpr-mono-split
jeanPerier [Mon, 17 Feb 2020 17:47:01 +0000 (09:47 -0800)]
[flang] Merge pull request flang-compiler/f18#959 from jeanPerier/jpr-mono-split

RFC: FIR Merge - PR1: Add PFTBuilder structure to help lowering the parse-tree

Original-commit: flang-compiler/f18@f28afa7138a55c0af3aadc8028844012ce8e6191
Reviewed-on: https://github.com/flang-compiler/f18/pull/959

4 years ago[flang] Add Pre-FIR Tree structure to help lowering the parse-tree
Jean Perier [Tue, 28 Jan 2020 12:58:30 +0000 (04:58 -0800)]
[flang] Add Pre-FIR Tree structure to help lowering the parse-tree

The Pre-FIR Tree structure is a transient data structure that
is meant to be built from the parse tree just before lowering to
FIR and that will be deleted just afterwards. It is not meant to perfrom
optimization analysis and transformations. It only provides temporary
information, such as label target information or parse tree parent nodes,
that is meant to be used to lower the parse tree structure into
FIR operations.
A PFTBuilder class builds the Pre-Fir Tree from the parse-tree.
A pretty printer is available to visualize this data structure.

- Lit tests are added to:
  1. that the PFT tree structure is as expected
  2. that the PFT captures all intented nodes

- Cmake changes: Prevent warnings inisde LLVM headers when compiling flang

The issue is that some LLVM headers  define functions where the usage of
the parameters depend on environment ifdef. See for instance Size in:
https://github.com/llvm/llvm-project/blob/5f940220bf9438e95ffa4a627ac1591be1e1ba6e/llvm/include/llvm/Support/Compiler.h#L574

Because flang is build with -Werror and -Wunused-parameter is default in
clang, this may breaks build in some environments (like with clang9 on macos).
A solution would be to add -Wno-unused-parameter to flang CmakLists.txt,
but it is wished to keep this warning on flang sources for quality purposes.
Fixing LLVM headers is not an easy task and `[[maybe_unused]]` is C++17 and
cannot be used yet in LLVM headers.
Hence, this fix simply silence warnings coming from LLVM headers by telling
CMake they are to be considered as if they were system headers.

- drone.io changes: remove llvm 6.0 from clang config in drone.io and link
flang with libstdc++ instead of libc++

llvm-dev resolved to llvm-6.0 in clang builds on drone.io. llvm 6.0 too old.
LLVM packages are linked with libstdc++ standard library whereas libc++ was
used for flang. This caused link time failure when building clang. Change
frone.io to build flang with libc++.

Note:
This commit does not reflect an actual work log, it is a feature based split of the
changes done in the FIR experimental branch. The related work log can be found in the
commits between:
864898cbe509d032abfe1172ec367dbd3dd92bc1
and
137c23da9c64cf90584cf81fd646053a69e91f63

Other changes come from https://github.com/flang-compiler/f18/pull/959 review.

Original-commit: flang-compiler/f18@edb0943bca4b81689f320bda341040bf255d6e2e
Reviewed-on: https://github.com/flang-compiler/f18/pull/959

4 years ago[flang] Add clang-format files for FIR source (LLVM style)
Jean Perier [Tue, 21 Jan 2020 15:41:52 +0000 (07:41 -0800)]
[flang] Add clang-format files for FIR source (LLVM style)

Note:
This commit does not reflect an actual work log, it is a feature based split of the
changes done in the FIR experimental branch. The related work log can be found in the commits between:
https://github.com/schweitzpgi/f18/commit/8c320e3bf2c3e9cdac66c81db3bf4634bf972e1d
and:
https://github.com/schweitzpgi/f18/commit/9b9ea05f9a75608c7bb5372c56bf7b9363569a69

Original-commit: flang-compiler/f18@00d8d5121cdaed09e584a0aea7d59baf322bfaa3
Reviewed-on: https://github.com/flang-compiler/f18/pull/959
Tree-same-pre-rewrite: false

4 years ago[flang] Merge pull request flang-compiler/f18#981 from flang-compiler/ps-c708
psteinfeld [Fri, 14 Feb 2020 17:27:52 +0000 (09:27 -0800)]
[flang] Merge pull request flang-compiler/f18#981 from flang-compiler/ps-c708

Semantic check for C708

Original-commit: flang-compiler/f18@4d4b375d14810223badee7b47a151bc1d7ebab5b
Reviewed-on: https://github.com/flang-compiler/f18/pull/981

4 years ago[flang] Semantic check for C708
Pete Steinfeld [Tue, 11 Feb 2020 20:14:04 +0000 (12:14 -0800)]
[flang] Semantic check for C708

An entity declared with the CLASS keyword shall be a dummy argument or
have the ALLOCATABLE or POINTER attribute.

Implementing this check revealed a problem in the test resolve44.cpp.
It also showed that we were doing semantic checking on the entities
created by the compiler for LOCAL and LOCAL_INIT locality-specs.  So I
changed the creation of symbols associated with LOCAL and LOCAL_INIT
locality-specs to be host associated with the outer symbol rather than
new object entities.  In the process, I also changed things so that the
`parser::Name` associated with the newly created symbols was set to the
symbol rather than being set to nullptr.

Original-commit: flang-compiler/f18@5dd0b0bbe811a908374b2907bb38c75ca76127d2
Reviewed-on: https://github.com/flang-compiler/f18/pull/981

4 years ago[flang] Add zlib to drone files so that linking LLVM works. (flang-compiler/f18#983)
David Truby [Fri, 14 Feb 2020 04:46:29 +0000 (04:46 +0000)]
[flang] Add zlib to drone files so that linking LLVM works. (flang-compiler/f18#983)

Original-commit: flang-compiler/f18@403faf847d0beacac26421bc82318aaef0e973c9
Reviewed-on: https://github.com/flang-compiler/f18/pull/983

4 years ago[flang] Merge pull request flang-compiler/f18#982 from flang-compiler/pmk-more-io
Peter Klausler [Thu, 13 Feb 2020 19:08:26 +0000 (11:08 -0800)]
[flang] Merge pull request flang-compiler/f18#982 from flang-compiler/pmk-more-io

Progress on Fortran I/O runtime

Original-commit: flang-compiler/f18@47ed180b67cae9d61251574e94c97675d5c998b1
Reviewed-on: https://github.com/flang-compiler/f18/pull/982

4 years ago[flang] Progress on Fortran I/O runtime
peter klausler [Wed, 5 Feb 2020 00:55:45 +0000 (16:55 -0800)]
[flang] Progress on Fortran I/O runtime

Use internal units for internal I/O state

Replace use of virtual functions

reference_wrapper

Internal formatted output to array descriptor

Delete dead code

Begin list-directed internal output

Refactorings and renamings for clarity

List-directed external I/O (character)

COMPLEX list-directed output

Control list items

First cut at unformatted I/O

More OPEN statement work; rename class to ExternalFileUnit

Complete OPEN (exc. for POSITION=), add CLOSE()

OPEN(POSITION=)

Flush buffers on crash and for terminal output; clean up

Documentation

Fix backquote in documentation

Fix typo in comment

Begin implementation of input

Refactor binary floating-point properties to a new header, simplify numeric output editing

Dodge spurious GCC 7.2 build warning

Address review comments

Original-commit: flang-compiler/f18@9c4bba11cf2329575ea9ee446f69e9caa797135c
Reviewed-on: https://github.com/flang-compiler/f18/pull/982

4 years ago[flang] Merge pull request flang-compiler/f18#978 from flang-compiler/ps-types
psteinfeld [Tue, 11 Feb 2020 19:32:12 +0000 (11:32 -0800)]
[flang] Merge pull request flang-compiler/f18#978 from flang-compiler/ps-types

Semantic checks for constraints on types

Original-commit: flang-compiler/f18@2efdf12f6a2533980dfcfc6c3bb375e65ac07a67
Reviewed-on: https://github.com/flang-compiler/f18/pull/978

4 years ago[flang] Semantic checks for constraints on types
Pete Steinfeld [Mon, 10 Feb 2020 21:24:32 +0000 (13:24 -0800)]
[flang] Semantic checks for constraints on types
I implemented and added tests for constraints C703, C704, C705, C706,
and C796.  In some cases, the code and/or test already existed, and all
I did was add a notation indicating the associated constraint.

Original-commit: flang-compiler/f18@49a64c4c2374e930f6890b270289a6f49ba63edd
Reviewed-on: https://github.com/flang-compiler/f18/pull/978

4 years ago[flang] Merge pull request flang-compiler/f18#979 from flang-compiler/ps-dev-story
psteinfeld [Tue, 11 Feb 2020 19:04:37 +0000 (11:04 -0800)]
[flang] Merge pull request flang-compiler/f18#979 from flang-compiler/ps-dev-story

Updated the description of `evaluate::Expr` types

Original-commit: flang-compiler/f18@92884fa4f63e5186fc23d185b9d163ac28ff39d5
Reviewed-on: https://github.com/flang-compiler/f18/pull/979

4 years ago[flang] Updated the description of `evaluate::Expr` types
Pete Steinfeld [Mon, 3 Feb 2020 18:31:30 +0000 (10:31 -0800)]
[flang] Updated the description of `evaluate::Expr` types

Original-commit: flang-compiler/f18@75adddd504577a295f0c906aa049bd47ce2b4f2e
Reviewed-on: https://github.com/flang-compiler/f18/pull/979

4 years ago[flang] Merge pull request flang-compiler/f18#977 from flang-compiler/tsk-osx-error
Tim Keith [Mon, 10 Feb 2020 19:05:10 +0000 (15:05 -0400)]
[flang] Merge pull request flang-compiler/f18#977 from flang-compiler/tsk-osx-error

Fix compilation error on macOS

Original-commit: flang-compiler/f18@204c67d7b6721c38d24cb2ffb3d812350f6d146b
Reviewed-on: https://github.com/flang-compiler/f18/pull/977

4 years ago[flang] Fix compilation error on macOS
Tim Keith [Mon, 10 Feb 2020 18:55:24 +0000 (10:55 -0800)]
[flang] Fix compilation error on macOS

The call to `std::min` failed to compile with GCC on macOS due to type
inference because `std::size_t` is `long unsigned int` but `std::int64_t`
is `long long int`.

Original-commit: flang-compiler/f18@c342575a9e0217fa3252b70b8ef3eac0236a58e3
Reviewed-on: https://github.com/flang-compiler/f18/pull/977

4 years ago[flang] Merge pull request flang-compiler/f18#972 from flang-compiler/jpr-clang-10...
jeanPerier [Mon, 10 Feb 2020 15:59:10 +0000 (07:59 -0800)]
[flang] Merge pull request flang-compiler/f18#972 from flang-compiler/jpr-clang-10-warnings

Fix issues comming from clang-10 warnings

Original-commit: flang-compiler/f18@90e6448255d9489eeb3081a9fda9d320caf8b3e3
Reviewed-on: https://github.com/flang-compiler/f18/pull/972

4 years ago[flang] Fix issues comming from clang-10 warnings
Jean Perier [Thu, 6 Feb 2020 11:27:36 +0000 (03:27 -0800)]
[flang] Fix issues comming from clang-10 warnings

- Remove SubprogramDetails copy ctor
- Prevent copies in range based loops over symbols
- Remove unsued var

Original-commit: flang-compiler/f18@16543d22f74e9421ecb4078818f4c1970bac0a5d
Reviewed-on: https://github.com/flang-compiler/f18/pull/972

4 years ago[flang] Merge pull request flang-compiler/f18#973 from flang-compiler/ps-c702
psteinfeld [Fri, 7 Feb 2020 18:28:03 +0000 (10:28 -0800)]
[flang] Merge pull request flang-compiler/f18#973 from flang-compiler/ps-c702

Semantic checks for C702

Original-commit: flang-compiler/f18@351a7d5ea6264cc58a3fd7a20e79442c41f8dd68
Reviewed-on: https://github.com/flang-compiler/f18/pull/973

4 years ago[flang] Semantic checks for C702
Pete Steinfeld [Thu, 6 Feb 2020 20:26:51 +0000 (12:26 -0800)]
[flang] Semantic checks for C702
C702 (R701) A colon shall not be used as a type-param-value except in the
declaration of an entity that has the POINTER or ALLOCATABLE attribute.

I added code to the visitor for a TypeDeclarationStmt to check for the
'LEN' type parameter for strings and to loop over the type parameters
for derived types.

I also ran into a few situations where previous tests had erroneously
used a colon for type parameters without either the POINTER or
ALLOCATABLE attribute and fixed them up.

Original-commit: flang-compiler/f18@a1a95bfcd1811d697f1386fe57af664b8a16ffb5
Reviewed-on: https://github.com/flang-compiler/f18/pull/973

4 years ago[flang] [OpenMP] Predetermined rules for loop index variables (flang-compiler/f18...
Jinxin (Brian) Yang [Wed, 5 Feb 2020 18:13:43 +0000 (10:13 -0800)]
[flang] [OpenMP] Predetermined rules for loop index variables (flang-compiler/f18#962)

This refers to three rules in OpenMP 4.5 Spec 2.15.1.1:
  * The loop iteration variable(s) in the associated do-loop(s) of a do,
    parallel do, taskloop, or distribute construct is (are) private.
  * The loop iteration variable in the associated do-loop of a simd
    construct with just one associated do-loop is linear with a linear-step
    that is the increment of the associated do-loop.
  * The loop iteration variables in the associated do-loops of a simd
    construct with multiple associated do-loops are lastprivate.

A simple example:
```
implicit none
  integer :: N = 1024
  integer i, j, k
  !$omp parallel do collapse(3)
  do i=1, N  <- i is private
     do j=1, N  <- j is private
        do k=1, N  <- k is private
        enddo
     enddo
  enddo
end
```

If `collapse` clause is not present, the associated do-loop for construct
`parallel do` is only `i` loop. With `collapse(n)`, `i`, `j`, and `k` are
all associated do-loops and the loop index variables are private to the
OpenMP construct:

```
implicit none
 !DEF: /MainProgram1/n ObjectEntity INTEGER(4)
 integer :: n = 1024
 !DEF: /MainProgram1/i ObjectEntity INTEGER(4)
 !DEF: /MainProgram1/j ObjectEntity INTEGER(4)
 !DEF: /MainProgram1/k ObjectEntity INTEGER(4)
 integer i, j, k
!$omp parallel do  collapse(3)
 !DEF: /MainProgram1/Block1/i (OmpPrivate) HostAssoc INTEGER(4)
 !REF: /MainProgram1/n
 do i=1,n
  !DEF: /MainProgram1/Block1/j (OmpPrivate) HostAssoc INTEGER(4)
  !REF: /MainProgram1/n
  do j=1,n
   !DEF: /MainProgram1/Block1/k (OmpPrivate) HostAssoc INTEGER(4)
   !REF: /MainProgram1/n
   do k=1,n
   end do
  end do
 end do
end program
```

This implementation assumes that the structural checks for do-loops
are done at this point, for example the `n` in `collapse(n)` should
be no more than the number of actual perfectly nested do-loops, etc..

Original-commit: flang-compiler/f18@572a57d3d0d785bb3f2aad9e890ef498c1214309
Reviewed-on: https://github.com/flang-compiler/f18/pull/962

4 years ago[flang] Merge pull request flang-compiler/f18#968 from flang-compiler/jpr-fix-clang...
jeanPerier [Wed, 5 Feb 2020 10:46:52 +0000 (02:46 -0800)]
[flang] Merge pull request flang-compiler/f18#968 from flang-compiler/jpr-fix-clang-template-step-limit

Fix template step limit issue with clang

Original-commit: flang-compiler/f18@d4cd378290feb05ace2d549fb74db3e48b962f10
Reviewed-on: https://github.com/flang-compiler/f18/pull/968

4 years ago[flang] Fix template step limit issue with clang
Jean Perier [Tue, 4 Feb 2020 18:30:16 +0000 (10:30 -0800)]
[flang] Fix template step limit issue with clang

While working on PR 959, I instanciated a `common::TupleToVariant`
with ~50+ types inside the tuple. Clang would then crash after
1hr compilation with message:
"constexpr evaluation hit maximum step limit; possible infinite loop"
After investigating, it turned out clang handles very badly the way
`common::AreTypesDistinctHelper` was implemented.
Its "number of steps" was exponential with the number of types.
This fix makes this number quadratic which solves the issue.

Original-commit: flang-compiler/f18@4542cb57082eaf578799c76482d4b706ae5da077
Reviewed-on: https://github.com/flang-compiler/f18/pull/968

4 years ago[flang] Merge pull request flang-compiler/f18#950 from flang-compiler/pmk-frame
Peter Klausler [Tue, 4 Feb 2020 22:47:02 +0000 (14:47 -0800)]
[flang] Merge pull request flang-compiler/f18#950 from flang-compiler/pmk-frame

Formatted output editing & initial buffer framing code

Original-commit: flang-compiler/f18@003b664229a91b1692b52014ef6f9c9b65119b0d
Reviewed-on: https://github.com/flang-compiler/f18/pull/950

4 years ago[flang] Initial buffer framing code
peter klausler [Fri, 24 Jan 2020 00:59:27 +0000 (16:59 -0800)]
[flang] Initial buffer framing code

Address review comments

Integer output data editing (I,B,O,Z)

Full integer output formatting

Stub out some work in progress

Progress on E output data editing

E, D, EN, and ES output editing done

Fw.d output editing

Real G output editing

G output editing for reals

Make environment a distinct module

CHARACTER and LOGICAL output editing

Minimal decimal representations for E0, F0, G0 editing

Move real output editing code into its own file

Fix/dodge some GCC build problems

Prep work for external I/O statement state

External HELLO, WORLD

Fix build problem with GCC

Add virtual destructors where needed

Add new test

Original-commit: flang-compiler/f18@c3f1774f8eee903928b7e46636edfb03425eabc0
Reviewed-on: https://github.com/flang-compiler/f18/pull/950

4 years ago[flang] Merge pull request flang-compiler/f18#939 from flang-compiler/ps-dev-story
psteinfeld [Mon, 3 Feb 2020 17:28:49 +0000 (09:28 -0800)]
[flang] Merge pull request flang-compiler/f18#939 from flang-compiler/ps-dev-story

Explanation of how to implement a semantic check

Original-commit: flang-compiler/f18@bedca1462b46c52cf41b5f40cd7ed9bb6cc78f29
Reviewed-on: https://github.com/flang-compiler/f18/pull/939

4 years ago[flang] Explanation of how to implement a semantic check
Pete Steinfeld [Thu, 16 Jan 2020 00:25:26 +0000 (16:25 -0800)]
[flang] Explanation of how to implement a semantic check

This is the story of implementing semantic checks for passing DO
variables to functions with dummy arguments with INTENT(OUT) or
INTENT(INOUT).

Original-commit: flang-compiler/f18@889f90913f280f285eb9960a0e0baadfd43a555f
Reviewed-on: https://github.com/flang-compiler/f18/pull/939

4 years ago[flang] Merge pull request flang-compiler/f18#961 from flang-compiler/tsk-contig2
Tim Keith [Thu, 30 Jan 2020 00:17:41 +0000 (16:17 -0800)]
[flang] Merge pull request flang-compiler/f18#961 from flang-compiler/tsk-contig2

Fix another bug checking simple contiguity

Original-commit: flang-compiler/f18@cd371e9a2ab66c31c6df77c0fa3052a80f00908c
Reviewed-on: https://github.com/flang-compiler/f18/pull/961

4 years ago[flang] Fix another bug checking simple contiguity
Tim Keith [Tue, 28 Jan 2020 23:06:03 +0000 (15:06 -0800)]
[flang] Fix another bug checking simple contiguity

The test still wasn't correct for structure components. If the last
part-ref is a non-array or a single array element, but the whole
ArrayRef has non-zero rank, it is not contiguous. Otherwise, if there
are subscripts on the last part-ref they can be checked normally.

Add some tests for cases that were previously failing, and also for
cases with vector subscripts.

Original-commit: flang-compiler/f18@aa0a0887325bd1fc6c3a1ad40fc6711d2e458a1c
Reviewed-on: https://github.com/flang-compiler/f18/pull/961

4 years ago[flang] Merge pull request flang-compiler/f18#954 from flang-compiler/ps-impure-final
psteinfeld [Wed, 29 Jan 2020 21:19:22 +0000 (13:19 -0800)]
[flang] Merge pull request flang-compiler/f18#954 from flang-compiler/ps-impure-final

Semantic checks for deallocating entities with IMPURE FINAL procedures

Original-commit: flang-compiler/f18@61da1f9e5c59cedb02026954a73ab30d8319a66c
Reviewed-on: https://github.com/flang-compiler/f18/pull/954

4 years ago[flang] Semantic checks for deallocating entities with IMPURE FINAL procedures
Pete Steinfeld [Mon, 27 Jan 2020 22:12:35 +0000 (14:12 -0800)]
[flang] Semantic checks for deallocating entities with IMPURE FINAL procedures

You cannot call an IMPURE procedure in a DO CONCURRENT construct.  One
way that can happen is if an entity with an IMPURE FINAL procedure gets
deallocated.  Similar to the checks for deallocating coarrays, there are
three ways that an entity can get deallocated that are applicable to DO
CONCURRENT constructs -- an actual DEALLOCATE statement, block exit, and
assignment.

This change depends on the utility function `HasImpureFinal()` in tools.h to
determine if an entity has a derived type with an IMPURE FINAL
procedure.  In the course of testing this change, I realized that this
check is incorrect, but the code specific to DO CONCURRENT is
independent of the check, so I might as well implement it.

Original-commit: flang-compiler/f18@d2294ff511aebd64889df57d02325bd6fcdf914a
Reviewed-on: https://github.com/flang-compiler/f18/pull/954

4 years ago[flang] Merge pull request flang-compiler/f18#960 from flang-compiler/by-remove-default
Jinxin (Brian) Yang [Tue, 28 Jan 2020 22:12:14 +0000 (14:12 -0800)]
[flang] Merge pull request flang-compiler/f18#960 from flang-compiler/by-remove-default

Remove `default` case for OmpSectionsDirective (only two enum values)

Original-commit: flang-compiler/f18@d98bf8494e2e017ed9a7e1d3c93688c379c01bf3
Reviewed-on: https://github.com/flang-compiler/f18/pull/960

4 years ago[flang] Remove `default` case for OmpSectionsDirective (only two enum values)
Jinxin Yang [Tue, 28 Jan 2020 21:58:14 +0000 (13:58 -0800)]
[flang] Remove `default` case for OmpSectionsDirective (only two enum values)

Original-commit: flang-compiler/f18@3f37e0dbaf32f1127553be2149915cab1b93cdcf
Reviewed-on: https://github.com/flang-compiler/f18/pull/960

4 years ago[flang] [OpenMP] Name Resolution for OpenMP constructs (flang-compiler/f18#940)
Jinxin (Brian) Yang [Tue, 28 Jan 2020 20:51:35 +0000 (12:51 -0800)]
[flang] [OpenMP] Name Resolution for OpenMP constructs (flang-compiler/f18#940)

This is an extended framework based on the previous work that addresses
the NR on OpenMP directives/clauses (b2ea520). In this change:
  * New `OmpVisitor` is created (ResolveNamesVisitor derives from it) to
    create necessary scopes for certain OpenMP constructs. This is along
    with the regular Fortran NR process.
  * Old `OmpVisitor` is adjusted and converted to a standalone visitor--
    `OmpAttributeVisitor`. This is used to walk through the OpenMP constructs
    and do the NR for variables on the OpenMP directives or data references
    within the OpenMP constructs. "Do the NR" here means that based on the NR
    results of the regular Fortran NR, fix the symbols of `Names` related
    to the OpenMP constructs. Note that there is an `OmpContext` in this
    visitor (similar to the one in `OmpStructureChecker`), this is necessary
    when dealing with the nested OpenMP constructs in the future.

Given an OpenMP code:
```
real*8 a, b
  a = 1.
  b = 2.
  !$omp parallel private(a)
  a = 3.
  b = 4.
  !$omp end parallel
  print *, a, b
end
```

w/o -fopenmp:
```
real*8 a, b
 !REF: /MainProgram1/a
 a = 1.
 !REF: /MainProgram1/b
 b = 2.
 !!!! OMP parallel
 !REF: /MainProgram1/a
 a = 3.
 !REF: /MainProgram1/b
 b = 4.
 !!!! OMP end parallel
 !REF: /MainProgram1/a
 !REF: /MainProgram1/b
 print *, a, b
end
```

w/ -fopenmp:
```
real*8 a, b
 !REF: /MainProgram1/a
 a = 1.
 !REF: /MainProgram1/b
 b = 2.
!$omp parallel  private(a)   <-- new Symbol for 'a' created
 !DEF: /MainProgram1/Block1/a (OmpPrivate) HostAssoc REAL(8)
 a = 3.   <-- fix the old symbol with new Symbol in parallel scope
 !REF: /MainProgram1/b
 b = 4.   <-- do nothing because by default it is shared in this scope
!$omp end parallel
 !REF: /MainProgram1/a
 !REF: /MainProgram1/b
 print *, a, b
end
```

Please note that this is a framework update, there are still many
things on the TODO list for finishing the NR for OpenMP (based on
the `OpenMP-semantics.md` design doc), which will be on top of this
framework.

Some TODO items:
- Create a generic function to go through all the rules for deciding
  `predetermined`, `explicitly determined`, and `implicitly determined`
  data-sharing attributes. (This is the next biggest part)
- Handle `Array Sections` and `Array or Structure Element`.
- Take association into consideration for example Pointer association,
  `ASSOCIATE` construct, and etc.
- Handle all the name resolution for directives/clauses that have
  `parser::Name`.

* N.B. Extend `AddSourceRange` to apply to current and parent scopes
  - motivated by a few cases that need to call `AddSourceRange`
    for current & parent scopes; the extension should be safe
  - global scope is not included

Original-commit: flang-compiler/f18@0c3c39d30e3f166a6a1303337c5fd7eead720fd0
Reviewed-on: https://github.com/flang-compiler/f18/pull/940

4 years ago[flang] Merge pull request flang-compiler/f18#956 from flang-compiler/ps-checklist
psteinfeld [Tue, 28 Jan 2020 04:18:52 +0000 (20:18 -0800)]
[flang] Merge pull request flang-compiler/f18#956 from flang-compiler/ps-checklist

More checklist items

Original-commit: flang-compiler/f18@32eb0d79c3a334d15ed1dc351619be9fda6b2a9f
Reviewed-on: https://github.com/flang-compiler/f18/pull/956

4 years ago[flang] More checklist items
Pete Steinfeld [Fri, 24 Jan 2020 20:08:24 +0000 (12:08 -0800)]
[flang] More checklist items

I added more items when reviewing some actual pull request comments.

Original-commit: flang-compiler/f18@195d807ff221e4247ec5609e8e816e81dab5df94
Reviewed-on: https://github.com/flang-compiler/f18/pull/956

4 years ago[flang] Changed *.cc file extension to *.cpp (updated scripts) (flang-compiler/f18...
Alexis Perry [Tue, 28 Jan 2020 02:18:45 +0000 (19:18 -0700)]
[flang] Changed *.cc file extension to *.cpp (updated scripts) (flang-compiler/f18#958)

Updated CMake files accordingly, using better regex
Updated license headers to match new extension and fit within 80 columns
Updated other comments within files that referred to the old extension

Original-commit: flang-compiler/f18@ae7721e611918631d1e3821dbb60f5ffcd9a69b1
Reviewed-on: https://github.com/flang-compiler/f18/pull/958

4 years ago[flang] Moved public headers to include/flang (flang-compiler/f18#943)
David Truby [Mon, 27 Jan 2020 20:57:59 +0000 (20:57 +0000)]
[flang] Moved public headers to include/flang (flang-compiler/f18#943)

Original-commit: flang-compiler/f18@21adbc7e05b2454ba3fc725b4697748f98599471
Reviewed-on: https://github.com/flang-compiler/f18/pull/943

4 years ago[flang] Merge pull request flang-compiler/f18#951 from flang-compiler/tsk-impure
Tim Keith [Mon, 27 Jan 2020 19:53:53 +0000 (11:53 -0800)]
[flang] Merge pull request flang-compiler/f18#951 from flang-compiler/tsk-impure

Fix bugs detecting impure calls

Original-commit: flang-compiler/f18@db5ebec5156f3f93fb99358192307298c99fc3c4
Reviewed-on: https://github.com/flang-compiler/f18/pull/951

4 years ago[flang] Fix bugs detecting impure calls
Tim Keith [Sat, 25 Jan 2020 16:15:17 +0000 (08:15 -0800)]
[flang] Fix bugs detecting impure calls

Change Traverse to visit the actual arguments of structure constructors.

Change FindImpureCallHelper to visit the actual arguments of a call to a
pure procedure in case one of them makes a call to an impure function.

Original-commit: flang-compiler/f18@81a5488ee62b4324d002c348464712c930095a32
Reviewed-on: https://github.com/flang-compiler/f18/pull/951

4 years ago[flang] Merge pull request flang-compiler/f18#952 from flang-compiler/tsk-contig
Tim Keith [Mon, 27 Jan 2020 19:53:31 +0000 (11:53 -0800)]
[flang] Merge pull request flang-compiler/f18#952 from flang-compiler/tsk-contig

Fix bug detecting simply contiguous component

Original-commit: flang-compiler/f18@a8a7a8c914aecbfdaff95419eb0408aa979abe53
Reviewed-on: https://github.com/flang-compiler/f18/pull/952

4 years ago[flang] Fix bug detecting simply contiguous component
Tim Keith [Sun, 26 Jan 2020 18:42:34 +0000 (10:42 -0800)]
[flang] Fix bug detecting simply contiguous component

We were always return false when testing a component for simple
contiguity. Change to check that the component is an array that is
simply continguous. Also treat a scalar component of scalar as simply
contiguous.

A pointer with bounds remapping to a complex part is a similar case
so add a test for that too.

Original-commit: flang-compiler/f18@27d76da2a44614b2c4cf4d576410372cabf66577
Reviewed-on: https://github.com/flang-compiler/f18/pull/952

4 years ago[flang] Merge pull request flang-compiler/f18#949 from flang-compiler/pmk-file
Peter Klausler [Mon, 27 Jan 2020 18:01:32 +0000 (10:01 -0800)]
[flang] Merge pull request flang-compiler/f18#949 from flang-compiler/pmk-file

OpenFile class: API and implementation wrappers for open external files

Original-commit: flang-compiler/f18@edd60ae8281ab21588355c4f93680b6152219cd0
Reviewed-on: https://github.com/flang-compiler/f18/pull/949

4 years ago[flang] Basic file operation wrapper
peter klausler [Fri, 24 Jan 2020 00:10:00 +0000 (16:10 -0800)]
[flang] Basic file operation wrapper

Asynchronous interfaces and locking

Original-commit: flang-compiler/f18@3ba77a0c2035644485737a025cc8912485b56225
Reviewed-on: https://github.com/flang-compiler/f18/pull/949

4 years ago[flang] Merge pull request flang-compiler/f18#946 from flang-compiler/pmk-hello
Peter Klausler [Fri, 24 Jan 2020 20:35:43 +0000 (12:35 -0800)]
[flang] Merge pull request flang-compiler/f18#946 from flang-compiler/pmk-hello

12HHELLO, WORLD

Original-commit: flang-compiler/f18@3087aa82840b817cb7433c48cc2310accf9dc9b6
Reviewed-on: https://github.com/flang-compiler/f18/pull/946

4 years ago[flang] Drill down to a working implementation of the APIs for an
peter klausler [Thu, 16 Jan 2020 21:51:25 +0000 (13:51 -0800)]
[flang] Drill down to a working implementation of the APIs for an
internal formatted WRITE with no data list items.

Improve argument names in io-api.h

Bump up error number to not conflict with errno values

Use Fortran::runtime::io namespace

Add wrapper around malloc/free, allow use of unique_ptr with wrapper

IoErrorHandler

Revamp FormatContext, use virtual member functions

Update comment syntax, allow for old C

12HHELLO, WORLD

Remove files not yet ready for review

Use std::forward

Fix gcc build warnings

Fix redundant filename in license boilerplate

Reduce runtime dependence on compiler binary libraries, fixing shared lib builds

Original-commit: flang-compiler/f18@839a91f1d699cd839767407bcdb1e384f2d2b730
Reviewed-on: https://github.com/flang-compiler/f18/pull/946

4 years ago[flang] Merge pull request flang-compiler/f18#944 from flang-compiler/tsk-pointer
Tim Keith [Wed, 22 Jan 2020 21:50:42 +0000 (13:50 -0800)]
[flang] Merge pull request flang-compiler/f18#944 from flang-compiler/tsk-pointer

Check bounds on pointer assignment

Original-commit: flang-compiler/f18@5e331c1a5cdbfa80c4ef736e95dc0a88b34c6d01
Reviewed-on: https://github.com/flang-compiler/f18/pull/944

4 years ago[flang] Check bounds on pointer assignment
Tim Keith [Wed, 22 Jan 2020 01:15:21 +0000 (17:15 -0800)]
[flang] Check bounds on pointer assignment

Perform checks on bounds-spec and bounds-remapping in a pointer
assignment statement:
- check that the rank of the bounds specified matches the rank of the
  pointer
- for bounds-spec, check that the pointer rank matches the target rank
- for bounds-remapping:
  - check that the target is rank 1 or simply contiguous
  - check that there are sufficient elements on the RHS for the bounds
    specified, when it can be determined at compile time

Move more of the pointer-specific checking from `assignment.cc`
to `pointer-assignment.cc`.

Original-commit: flang-compiler/f18@7489b3539224f8ad7a55873916e5854510236218
Reviewed-on: https://github.com/flang-compiler/f18/pull/944