Commit Graph

2918 Commits

Author SHA1 Message Date
River Riddle 82fd139201 [flang] Update FirOpsDialect constructor to pass its TypeID 2020-08-07 13:43:25 -07:00
River Riddle 1d6a8deb41 [mlir] Remove the need to define `kindof` on attribute and type classes.
This revision refactors the default definition of the attribute and type `classof` methods to use the TypeID of the concrete class instead of invoking the `kindof` method. The TypeID is already used as part of uniquing, and this allows for removing the need for users to define any of the type casting utilities themselves.

Differential Revision: https://reviews.llvm.org/D85356
2020-08-07 13:43:25 -07:00
peter klausler 43b304b09f [flang] Support DATA statement initialization of numeric with Hollerith/CHARACTER
This is a common Fortran language extension.

Differential Revision: https://reviews.llvm.org/D85492
2020-08-07 13:17:36 -07:00
peter klausler cc01194c2f [flang] Descriptor-based I/O data item transfers
Add support for OutputDescriptor() and InputDescriptor()
in the I/O runtime.  Change existing scalar formatted I/O
functions to drive descriptor-based I/O routines internally.

Differential Revision: https://reviews.llvm.org/D85491
2020-08-07 13:09:09 -07:00
peter klausler 0e9e06a6d4 [flang][NFC] Reformat files with current clang-format
Differential Revision: https://reviews.llvm.org/D85489
2020-08-07 12:10:26 -07:00
Tim Keith cf03bcf929 [flang] Remove extra CMAKE_CXX_FLAGS in Lower and Optimizer
`-Wno-error` and `-Wno-unused-parameter` appear to no longer be needed
for Lower and Optimizer.

Differential Revision: https://reviews.llvm.org/D85465
2020-08-07 10:21:54 -07:00
Tim Keith d8713523a2 [flang] Improve message for assignment to subprogram
In the example below we were producing the error message
"Assignment to constant 'f' is not allowed":
```
function f() result(r)
  f = 1.0
end
```

This changes it to a more helpful message when the LHS is a subprogram
name and also mentions the function result name when it's a function.

Differential Revision: https://reviews.llvm.org/D85483
2020-08-06 20:34:00 -07:00
Michael Kruse f81bae9ff4 [flang][msvc] Do not use gcc/clang command line options for msvc.
The command line options `-Wno-error` and `-Wno-unused-parameter` are specific to gcc/clang, do not use them when compiling with other compilers.

This patch is part of the series to [[ http://lists.llvm.org/pipermail/flang-dev/2020-July/000448.html | make flang compilable with MS Visual Studio ]].

Reviewed By: isuruf

Differential Revision: https://reviews.llvm.org/D85355
2020-08-06 15:46:52 -05:00
Tim Keith 08c7d570d3 [flang] Add options to control IMPLICIT NONE
Add `-fimplicit-none-type-always` to treat each specification-part
like it has `IMPLICIT NONE`. This is helpful for enforcing good Fortran
programming practices. We might consider something similar for
`IMPLICIT NONE(EXTERNAL)` as well.

Add `-fimplicit-none-type-never` to ignore occurrences of `IMPLICIT NONE`
and `IMPLICIT NONE(TYPE)`. This is to handle cases like the one below,
which violates the standard but it accepted by some compilers:
```
subroutine s(a, n)
  implicit none
  real :: a(n)
  integer :: n
end
```

Differential Revision: https://reviews.llvm.org/D85363
2020-08-06 06:48:01 -07:00
Irina Dobrescu e355f85bdf [flang] Add parser support for OpenMP allocate clause
Differential Revision: https://reviews.llvm.org/D85212
2020-08-06 10:45:34 +01:00
Tim Keith 6d2d73059f [flang] Fix compilation warning in check-directive-structure.h
Clang 9 gets the following warning after revision `D85104`.
```
../../flang/lib/Semantics/check-directive-structure.h:36:7: error: 'Fortran::semantics::DirectiveStructureChecker<llvm::omp::Directive, llvm::omp::Clause, Fortran::parser::OmpClause, 77>' has virtual functions but non-virtual destructor [-Werror,-Wnon-virtual-dtor]
```

The fix is the make the destructor virtual. Neither it nor the
constructor need to be public, so make them protected.

Differential Revision: https://reviews.llvm.org/D85383
2020-08-05 18:03:41 -07:00
Valentin Clement 40626184cf [flang][NFC] Unify OpenMP and OpenACC structure checker
This patch remove duplicated code between the check-omp-structure and the check-acc-structure
and unify it into a check-directive-structure templated class.

Reviewed By: kiranchandramohan, sscalpone, ichoyjx

Differential Revision: https://reviews.llvm.org/D85104
2020-08-05 14:25:49 -04:00
Andrzej Warzynski 621681e3e5 [Flang] Fix multi-config generator builds
Based on https://reviews.llvm.org/D84022 with additional changes to
maintain out-of-tree builds.

Original commit message:
Currently the binaries are output directly into the bin subdirectory of
the build directory. This doesn't work correctly with multi-config
generators which should output the binaries into <CONFIG_NAME>/bin
instead.

The original patch was implemented by David Truby and the additional
changes added here were also proposed by David Truby.

Differential Revision: https://reviews.llvm.org/D85078/

Co-authored-by: David Truby <david.truby@arm.com>
2020-08-05 08:59:11 +01:00
Rahul Joshi 1d6a724aa1 [MLIR] Change FunctionType::get() and TupleType::get() to use TypeRange
- Moved TypeRange into its own header/cpp file, and add hashing support.
- Change FunctionType::get() and TupleType::get() to use TypeRange

Differential Revision: https://reviews.llvm.org/D85075
2020-08-04 12:43:40 -07:00
peter klausler 675ad1bc6a [flang] Implement runtime support for INQUIRE statements
Differential Revision: https://reviews.llvm.org/D85166
2020-08-03 17:15:08 -07:00
peter klausler d879ac8a6e [flang] Defer "next input record" processing until handlers established
External input was detecting "end of file" conditions in
BeginExternal...Input() and BeginUnformattedInput() routines
before EnableHandlers() could have been called.  Defer the
"start next record" processing to the input data item
handlers (and EndIoStatement() for when there are no data
items).

Differential Revision: https://reviews.llvm.org/D85161
2020-08-03 16:44:37 -07:00
peter klausler d8334c4360 [flang] Acquire file accessibility, size, positioning
Extend the raw file wrapper to get accessibility, positioning,
and size information.  This is needed for INQUIRE (to follow).

Differential Revision: https://reviews.llvm.org/D85160
2020-08-03 16:42:48 -07:00
peter klausler 49bbb8b60e Remove unneeded RoundDefault enumerator, and fix spelling in comments 2020-08-03 16:14:24 -07:00
peter klausler 7c5630fe99 [flang] Handle spaces (more) correctly in REAL input
Fixes problems in FCVS test fm110.f.
Add more comments, too.

Differential Revision: https://reviews.llvm.org/D85163
2020-08-03 16:12:30 -07:00
peter klausler 089adc339e [flang] Make preprocessing behavior tests runnable as regression tests
And fix a minor bug exposed by doing so.

Differential Revision: https://reviews.llvm.org/D85164
2020-08-03 15:07:38 -07:00
Tim Keith 0d454e8e08 [flang] Fix bug detecting intrinsic function
Don't set the INTRINSIC attribute on a dummy procedure.

Differential Revision: https://reviews.llvm.org/D85136
2020-08-03 12:21:59 -07:00
compinder 594dec2884 [FLANG] Fix issues in SELECT TYPE construct when intrinsic type specification is specified in TYPE GUARD statement.
Fix of PR46789 and PR46830.

Differential Revision: https://reviews.llvm.org/D84290
2020-08-03 09:24:42 +05:30
River Riddle 2a6c8b2e95 [mlir][PassIncGen] Refactor how pass registration is generated
The current output is a bit clunky and requires including files+macros everywhere, or manually wrapping the file inclusion in a registration function. This revision refactors the pass backend to automatically generate `registerFooPass`/`registerFooPasses` functions that wrap the pass registration. `gen-pass-decls` now takes a `-name` input that specifies a tag name for the group of passes that are being generated. For each pass, the generator now produces a `registerFooPass` where `Foo` is the name of the definition specified in tablegen. It also generates a `registerGroupPasses`, where `Group` is the tag provided via the `-name` input parameter, that registers all of the passes present.

Differential Revision: https://reviews.llvm.org/D84983
2020-07-31 13:20:37 -07:00
Sourabh Singh Tomar bf812c145c [flang][OpenMP] Added initial support for lowering OpenMP parallel construct
This patch lower `!OMP PARALLEL` construct from PFT to OpenMPDialect operations.
This is first patch in this direction(lowering parallel construct).

OpenMP parallel construct can have multiple clauses and parameters. This patch
only implements lowering of an empty(contains no code in body) parallel construct
without any clauses or parameters.

Patch is carved out of following approved PR:
https://github.com/flang-compiler/f18-llvm-project/pull/322

Reviewed By: kiranchandramohan, DavidTruby

Differential Revision: https://reviews.llvm.org/D84965
2020-07-31 23:59:46 +05:30
sameeran joshi b752a8ca49 [flang][NFC] Verify C781 from - Clause 7 constraint checks for f18.
Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D84503
2020-07-31 23:58:18 +05:30
sameeran joshi 8830f1170d [flang]Verify C7107, C7108, C7109 from - Clause 7 constraint checks for f18.
1.  Annotate the sources with constraint numbers.
   2.  Add tests for

    *C7107 (R765) digit shall have one of the values 0 or 1.
    *C7108 (R766) digit shall have one of the values 0 through 7.
    *C7109 (R764) A boz-literal-constant shall appear only as a data-stmt-constant in a DATA statement, or where explicitly allowed in 16.9 as an actual argument of an intrinsic procedure.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D84504
2020-07-31 23:45:20 +05:30
Tim Keith 765b81f6b9 Revert "[flang] Fix multi-config generator builds."
This reverts commit 332170356e.

The change breaks out-of-tree builds.
Discussion in https://reviews.llvm.org/D84022
2020-07-31 11:10:44 -07:00
sameeran joshi 49660234db [Flang] Checks for constraint C7110-C7115.
Added more tests.
	 Annotate sources and tests.
	 Improve error message.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D85014
2020-07-31 23:27:57 +05:30
Richard Barton 30e45f339e [flang] Add -h as a synonym for help
As expected by user in http://lists.llvm.org/pipermail/flang-dev/2020-June/000404.html

Depends on D84856

Differential Revision: https://reviews.llvm.org/D84857
2020-07-31 15:56:37 +01:00
Richard Barton b068d19a15 [flang] Add details to --help screen on default behaviour
Add a usage string and a defaults section that clarifies:
 * If no input files are given, f18 reads from stdin
 * If no input files are given, f18 dumps the parse tree.
 * The default behaviour is to exec F18_FC.
 * The fefault F18_FC setting is 'gfortran'

Adds a simple regression test which tests the top and tail of the help
screen and the exit status.

Depends on D84855

Differential Revision: https://reviews.llvm.org/D84856
2020-07-31 15:56:37 +01:00
Richard Barton dd5ea5674b [flang] Make interactive behaviour more obvious
When flang is invoked with no files it waits for input on stdin. Make it
print a message saying this to prevent the user being surprised.

Differential Revision: https://reviews.llvm.org/D84855
2020-07-31 15:56:37 +01:00
Jean Perier a50cec71ec [flang] Fix CMPLX folding with complex arguments
CMPLX folding was expecting only one arguments in case X argument
is complex. This is wrong since there is also the optional KIND
argument.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D84936
2020-07-31 10:26:08 +02:00
Peter Steinfeld 2cf52504bb [flang] Fixes for RESHAPE()
I fixed an assert caused by passing an empty array as the source= argument to
RESHAPE().  In the process, I noticed that there were no tests for RESHAPE(),
so I wrote a test that covers all the description in 16.9.163.  In the process,
I made the error messages more consistent and descriptive.  I also changed the
test to see if a reference to an intrinsic function was a constant to say that
it is a constant if it's a refererence to an invalid intrinsic.  This avoids
emitting multiple messages for the same erroneous source.

Differential Revision: https://reviews.llvm.org/D84904
2020-07-30 19:05:06 -07:00
Peter Steinfeld fac84536bc [flang] Fix an assert on duplicate initializations
When declaring the same variable twice with an initialization, we were failing
an internal check.  I fixed this by checking to see if the associated symbol
already had an error.

I added tests for pointer and non-pointer initialization of duplicate names.

Differential Revision: https://reviews.llvm.org/D84969
2020-07-30 12:58:28 -07:00
Tim Keith 38272f45fe [flang] Create HostAssoc symbols for uplevel references
To make it easier for lowering to identify which symbols from the host
are captured by internal subprograms, create HostAssocDetails for them.

In particular, if a symbol is referenced and it is contained in a
subprogram or main program that is not the same as the containing
program unit of the reference, a HostAssocDetails symbol is created
in the current scope.

Differential Revision: https://reviews.llvm.org/D84889
2020-07-30 07:12:26 -07:00
Jean Perier 67e41df4e0 [flang] Expose specific to generic intrinsic name mapping
The intrinsic lowering facility is based on the generic intrinsic names to avoid
duplicating implementations. Specific intrinsics call are re-written to call to
the generic versions by the front-end but this cannot be done when specific intrinsics
are passed as arguments (the rewrite would give illegal/ambiguous unparsed Fortran).
Solve the issue by making the specific to generic name mapping accessible to lowering
and can be later used to generate the unrestricted intrinsic functions.

Reviewed By: schweitz

Differential Revision: https://reviews.llvm.org/D84842
2020-07-30 14:30:12 +02:00
David Truby 332170356e [flang] Fix multi-config generator builds.
Summary:
Currently the binaries are output directly into the bin subdirectory of the
build directory. This doesn't work correctly with multi-config generators which
should output the binaries into <CONFIG_NAME>/bin instead.

Reviewers: sscalpone, richard.barton.arm

Subscribers: mgorny, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D84022
2020-07-30 09:56:52 +01:00
Tim Keith 2c662f3d3d [flang] Fix bug with intrinsic in type declaration stmt
When an instrinsic function is declared in a type declaration statement
we need to set the INTRINSIC attribute and (per 8.2(3)) ignore the
specified type.

To simplify the check, add IsIntrinsic utility to BaseVisitor.

Also, intrinsics and external procedures were getting assigned a size
and offset and they shouldn't be.

Differential Revision: https://reviews.llvm.org/D84702
2020-07-29 07:23:31 -07:00
Tim Keith 9500d48de3 [flang][NFC] Extract name resolution for OpenACC & OpenMP into new file
Move `ResolveAccParts` and `ResolveOmpParts` from resolve-names.cpp to
resolve-directives.{h,cpp}. Move the implementation in the classes
`DirectiveAttributeVisitor`, `AccAttributeVisitor`, and
`OmpAttributeVisitor` to resolve-directives.cpp as well.

To allow this to happen, move `EvaluateIntExpr` and introduce
`EvaluateInt64` to resolve-names-utils.h. The latter is also useful
elsewhere in resolve-names.cpp for converting an Expr to std::int64_t.

The other problem was that `ResolveDesignator` was called from the code
that was moved. At the moment it doesn't seem to be doing anything so I
removed the calls (and no tests failed). If it proves to be needed, we
can either resolve those designators in resolve-names.cpp or pass the
`ResolveDesignator` function in to the code that needs to call it.

Differential Revision: https://reviews.llvm.org/D84768
2020-07-28 16:38:36 -07:00
Camille Coti ca0bf440db Order of libraries and source files in the f18 frontend
When the f18 frontend calls the link editor, put the libraries and object files in the correct order.

Fixes the issues reported here https://github.com/flang-compiler/flang/issues/897

Reviewed By: sscalpone, AlexisPerry

Differential Revision: https://reviews.llvm.org/D84340
2020-07-28 09:03:04 -06:00
peter klausler e57464151d [flang] Allow omission of comma in FORMAT(1PE5.2) in runtime
A comma is not required between a scale factor and a following
data edit descriptor (C1302).

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D84369
2020-07-27 15:02:54 -07:00
AlexisPerry 4a4cafabc9 [flang] Temp Driver - pass the flag to change the default integer kind through to F18_FC
fixes BUG 46307

Differential Revision: https://reviews.llvm.org/D84266
2020-07-27 09:57:34 -07:00
Valentin Clement ff25b2da2a [flang][openacc] Basic name resolution infrastructure for OpenACC construct
Reviewed By: tskeith, klausler, ichoyjx

Differential Revision: https://reviews.llvm.org/D83998
2020-07-26 20:01:35 -04:00
Tim Keith 7454acdf3b [flang] Fix implicit declarations in statement functions
If a symbol (that is not a dummy argument) is implicitly declared inside
a statement function, don't create it in the statement function's scope.
Instead, treat statement functions like blocks when finding the inclusive
scope and create the symbol there.

Add a new flag, StmtFunction, to symbols that represent statement functions.

Differential Revision: https://reviews.llvm.org/D84588
2020-07-26 12:13:39 -07:00
David Truby 4ef2e594d5 [flang] Run non-gtest unit tests with lit.
Summary:
As a corrollary, these tests are now run as part of the check-flang
target.

Reviewers: sscalpone

Subscribers: mgorny, delcypher, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83946
2020-07-24 14:49:39 +01:00
Tim Keith 412056e2d0 [flang] Implicitly convert result of statement function
The result of a statement function may require an implicit conversion
to match its result type. Add that to the expression that represents
the statement function body in SubprogramDetails.

Extract the analysis of that expression into a separate function.

Dump the statement function expression as part of the dump of
SubprogramDetails.

Differential Revision: https://reviews.llvm.org/D84452
2020-07-23 17:15:35 -07:00
clementval aca58ef784 [flang][openacc] Add missing comment in header 2020-07-23 14:10:35 -04:00
Pete Steinfeld 83dca19c11 [flang] Fix a crash when a BOZ literal is used as a relational operator
Summary:
Expressions like `iVar==z'fe'` were causing an assertion error  because
the `Relate()` function in `Evaluate/tools.cpp` that processes
relational operators didn't deal with BOZ literals, which are typeless.
I fixed this by checking to see if the operands are BOZ literals.  If
so, if the other operand is REAL, I convert them to REAL.  Otherwise, I convert
them to integers with default kind.

I also added a test to resolve63.f90 that triggers the problem.

Reviewers: tskeith, DavidTruby

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83917
2020-07-23 09:14:10 -07:00
Sourabh Singh Tomar 9e4ab439c2 [flang][OpenMP] Added support for lowering OpenMP taskyield construct
Summary:
This patch lower `!OMP TASKYIELD` construct from PFT to
OpenMPDialect operations.
Construct is lowered with conformance to OpenMP 5.0 spec.

Patch is carved out of following merged PR:
https://github.com/flang-compiler/f18-llvm-project/pull/297

Reviewed: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D84350
2020-07-23 07:16:34 +05:30
Valentin Clement b27ab9ce74 [flang][openacc] Skeleton for OpenACC construct lowering
Summary:
This patch introduce the basic infrastructure to be able to lower
OpenACC constructs to the future OpenACC dialect.

Reviewers: schweitz, kiranchandramohan, DavidTruby, sscalpone, jdoerfert, ichoyjx

Reviewed By: ichoyjx

Subscribers: ichoyjx, SouraVX, mgorny, jfb, sstefan1, llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D84195
2020-07-22 21:34:22 -04:00
Valentin Clement 3b8ffdec07 [flang][openmp] Required clauses are allowed
Summary:
This patch fix a problem where clause needed to be in the allowed set even
they were in the required set. A required clause is allowed obvisouly. This allow
to remove the duplicate in OMP.td

Reviewers: kiranchandramohan, DavidTruby, richard.barton.arm, jdoerfert, sscalpone, kiranktp, ichoyjx

Reviewed By: kiranchandramohan

Subscribers: yaxunl, guansong, sstefan1, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D84353
2020-07-22 21:31:35 -04:00
peter klausler 3bc2ae951a [flang] Add runtime I/O APIs for COMPLEX formatted input
It turns out that COMPLEX formatted input needs its own runtime APIs
so that null values in list-directed input skip the entire COMPLEX
datum rather than just a real or imaginary part thereof.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D84370
2020-07-22 17:52:19 -07:00
Logan Smith 77e0e9e17d Reapply "Try enabling -Wsuggest-override again, using add_compile_options instead of add_compile_definitions for disabling it in unittests/ directories."
add_compile_options is more sensitive to its location in the file than add_definitions--it only takes effect for sources that are added after it. This updated patch ensures that the add_compile_options is done before adding any source files that depend on it.

Using add_definitions caused the flag to be passed to rc.exe on Windows and thus broke Windows builds.
2020-07-22 17:50:19 -07:00
Logan Smith 97a0f80c46 Revert "Try enabling -Wsuggest-override again, using add_compile_options instead of add_compile_definitions for disabling it in unittests/ directories."
This reverts commit 388c9fb1af.
2020-07-22 15:07:01 -07:00
Logan Smith 388c9fb1af Try enabling -Wsuggest-override again, using add_compile_options instead of add_compile_definitions for disabling it in unittests/ directories.
Using add_compile_definitions caused the flag to be passed to rc.exe on Windows and thus broke Windows builds.
2020-07-22 14:19:34 -07:00
Pete Steinfeld f72106e2a3 [flang] Fix an assert when RESHAPE() is called on empty strings
Summary:
When a constant array of empty strings goes through contant folding, the result
is something that contains no bytes.  If this array is passed to the intrinsic
function `RESHAPE()`, we were not handling things correctly.  I fixed this by
checking for an empty destination when calling the function `CopyFrom()` on an
array of strings.

I also added a test with a couple of different examples that trigger the
problem.

Reviewers: klausler, tskeith, DavidTruby

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D84352
2020-07-22 12:21:58 -07:00
Louis Dionne afa1afd410 [CMake] Bump CMake minimum version to 3.13.4
This upgrade should be friction-less because we've already been ensuring
that CMake >= 3.13.4 is used.

This is part of the effort discussed on llvm-dev here:

  http://lists.llvm.org/pipermail/llvm-dev/2020-April/140578.html

Differential Revision: https://reviews.llvm.org/D78648
2020-07-22 14:25:07 -04:00
Hans Wennborg 3eec657825 Revert "Enable -Wsuggest-override in the LLVM build" and the follow-ups.
After lots of follow-up fixes, there are still problems, such as
-Wno-suggest-override getting passed to the Windows Resource Compiler
because it was added with add_definitions in the CMake file.

Rather than piling on another fix, let's revert so this can be re-landed
when there's a proper fix.

This reverts commit 21c0b4c1e8.
This reverts commit 81d68ad27b.
This reverts commit a361aa5249.
This reverts commit fa42b7cf29.
This reverts commit 955f87f947.
This reverts commit 8b16e45f66.
This reverts commit 308a127a38.
This reverts commit 274b6b0c7a.
This reverts commit 1c7037a2a5.
2020-07-22 20:23:58 +02:00
peter klausler c6cb726a8c [flang] Replay a FORMAT at the right position
When FORMAT control reaches the final parenthesis and data items
remain, we advance a record and revert to the beginning of the
FORMAT for further items.  But when the FORMAT contains any
nested parenthesized group of editing descriptors, possibly
repeated, reversion must be to the beginning of the last such
top-level parenthesized group, including its repetition count.

Reviewed By: sscalpone, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D84281
2020-07-21 18:59:49 -07:00
peter klausler 320389e849 [flang] Fix source line continuation in potential macro calls (bugzilla 46768)
The prescanner looks for implicit continuation lines when
there are unclosed parentheses at the end of a line, so that
source preprocessing macro references with arguments that span
lines are recognized.  The condition that determines this
implicit continuation has been put into a predicate member
function and corrected to apply only when the following line
is source (not a preprocessing directive, comment, &c.).

Fixes bugzilla #46768.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D84280
2020-07-21 18:21:35 -07:00
peter klausler 8f2c5c4314 [flang] Implement byte-swapped external unformatted I/O in runtime
Add SetConvert() to the OPEN statement's runtime API.
Add ByteswapOption() to the main program's runtime API.
Check a $FORT_CONVERT environment variable, too, for
a swapping specifier.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D84284
2020-07-21 18:14:46 -07:00
peter klausler 9bb091a8fc [flang] Handle leading zeroes after decimal in REAL formatted input
Leading zero digits after the decimal mark were being dropped.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D84282
2020-07-21 18:03:24 -07:00
peter klausler 26330a0c7c [flang] Check for misplaced labels
In fixed form source, complain when a label digit appears
outside the label field & when a non-digit appears in the label
field.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D84283
2020-07-21 18:00:16 -07:00
Logan Smith 21c0b4c1e8 Disable -Wsuggest-override for all remaining unittests/ directories 2020-07-21 17:48:36 -07:00
peter klausler cbff0c75b9 [flang] Improve output from a STOP statement
Add a missing newline to IEEE FP flag formatting, and
don't neglect to emit STOP when there's no code number.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D84060
2020-07-18 11:33:46 -07:00
peter klausler e79a86e45b [flang] Insert leading blanks in LOGICAL formatted output fields
Summary: For Lw output editing, emit (w-1) blanks before the T or the F.

Reviewed By: sscalpone, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D84059
2020-07-18 10:44:16 -07:00
peter klausler b0a971d25c [flang] Prevent bogus runtime I/O error message
The runtime was requiring that STATUS='OLD' be explicitly specified
on an OPEN statement for a connected unit.  There error should issue
only if a STATUS= other than 'OLD' is specified; an OPEN with no
STATUS= specifier is okay.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D84079
2020-07-17 17:21:54 -07:00
peter klausler 8305a92a47 [flang] Treat tabs like spaces in formatted input.
Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D84078
2020-07-17 17:19:20 -07:00
peter klausler 8e2b4e50f2 [flang] Support <name>=<integer> syntax in compiler directives
Accept name=value as part of a !DIR$ compiler directive.  These
are currently ignored in semantics, but we should recognize
more directive forms to facilitate testing.  In due course,
these placeholding directive parsers will be replaced.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D84077
2020-07-17 17:05:38 -07:00
peter klausler cf2274b779 [flang] Allow ! and // comments after some preprocessing directives
Old-style C /*comments*/ are omitted from preprocessor directive
token sequences by the prescanner, but line-ending C++ and Fortran
free-form comments are not since their handling might depend on
the directive.  Add code to skip these line-ending comments as
appropriate in place of existing code that just skipped blanks.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D84061
2020-07-17 15:28:22 -07:00
peter klausler ea4758a125 [flang] Rework read/write permission management for runtime file opening
Anonymous Fortran unit files (e.g., "./fort.7") need to be created
O_RDWR so that they can be written, rewound, and read.  Other
files opened with no ACTION= specifier need to set read/write
permissions based on the file, if it exists.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D84063
2020-07-17 14:44:58 -07:00
peter klausler b30fa1c3da [flang] Add entry points for internal scalar list-directed I/O
BeginInternalListInput and BeginInternalListOutput were missing
from the I/O API implementation; add them.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D84066
2020-07-17 12:49:06 -07:00
Sourabh Singh Tomar 079b49b3fb [flang][OpenMP] Added support for lowering OpenMP taskwait construct
Summary:
This patch lower `!OMP TASKWAIT` construct from PFT to
OpenMPDialect operations.
Construct is lowered with conformance to OpenMP 4.5 spec.

Patch is carved out of following approved PR:
https://github.com/flang-compiler/f18-llvm-project/pull/280

Reviewed By: kiranchandramohan, clementval

Differential Revision: https://reviews.llvm.org/D83983
2020-07-17 20:01:54 +05:30
Rahul Joshi 2e046be90e [flang] Adopt NoRegionArguments (WhereOp) and ParentOneOf (ResultOp) traits
Differential Revision: https://reviews.llvm.org/D83522
2020-07-16 08:35:22 -07:00
David Truby 920e127e02 [flang] Add missing link dependencies to FrontendOpenACC.
Summary:
These link dependencies are required for shared library builds to
work correctly.

Reviewers: clementval

Reviewed By: clementval

Subscribers: mgorny, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83938
2020-07-16 14:22:18 +01:00
David Truby 1c93671e59 [flang] Fix shared library builds for lib/Lower.
Summary:
This adds missing definitions for functions in the Lower directory
that were causing failures in shared library builds.
The definitions for these are taken from the fir-dev branch on github.

Reviewers: sscalpone, schweitz, jeanPerier, klausler

Reviewed By: schweitz

Subscribers: mgorny, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83771
2020-07-16 10:18:14 +01:00
Kiran Kumar T P d4b1a14f0a [flang][OpenMP] Enhance parser support for taskwait construct to OpenMP 5.0
Summary:
This patch enhances parser support for taskwait construct to OpenMP 5.0.

2.17.5 taskwait Construct
        !$omp taskwait [clause[ [,] clause] ... ]
                where clause is one of the following:
                depend([depend-modifier,]dependence-type : locator-list)

The patch includes code changes and testcase modifications.

Reviewed By: Valentin Clement, Kiran Chandramohan

Differential Revision: https://reviews.llvm.org/D82255
2020-07-16 10:10:59 +05:30
Tim Keith fa5e4482e0 [flang] Don't use-associate intrinsics
When an intrinsic is referenced in a module scope, a symbol for it is
added. When that module is USEd, the intrinsic should not be included.
Otherwise we can get ambiguous reference errors with the same intrinsic
coming from two difference modules.

Differential Revision: https://reviews.llvm.org/D83905
2020-07-15 15:08:08 -07:00
Tim Keith b297563a75 [flang] Fix erroneous application of SAVE statement
A SAVE statement with no entity list applies the SAVE attribute only to
the entities that it is allowed on. We were applying it to automatic
data objects and reporting an error that they can't have SAVE.

The fix is to change `DeclarationVisitor::CheckSaveAttr` to check for
automatic objects. That controls both checking and setting the
attribute. This allows us to remove the check from `CheckSpecExpr`
(along with `symbolBeingChecked_`). Also, it was only called on constant
objects so the non-const overload can be eliminated.

The check in `CheckSpecExpr` is replaced by an explicit check for
automatic objects in modules. This caught an error in modfile03.f90 so
that part of the test was eliminated.

Differential Revision: https://reviews.llvm.org/D83899
2020-07-15 13:02:33 -07:00
Valentin Clement 9aa3dca80f [flang][openacc] Semantic checks for OpenACC 3.0 clauses validity
Summary: This patch adds semantic checking for the OpenACC 3.0 clauses validity.

Reviewers: sscalpone, tskeith, klausler, ichoyjx, DavidTruby, jdoerfert

Reviewed By: tskeith, klausler

Subscribers: mgorny, llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D83807
2020-07-14 20:44:35 -04:00
peter klausler 8dbc86adf3 [flang] Fix list-directed input (repeated nulls and LOGICAL)
Allow repeated nulls in list-directed input (e.g., "4*,") and
ignore excess characters in list-directed LOGICAL input after the
T or F.

Fixes FCVS test fm923.f.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D83810
2020-07-14 16:59:50 -07:00
peter klausler bd43fa29e3 [flang] Implement anonymous units in the runtime
I/O from/to an unopened unit number needs to open &/or create
a "fort.$UNIT" file.

Fixes FCVS test fm401.f.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D83809
2020-07-14 16:12:06 -07:00
Pete Steinfeld 0c64cb6d08 [flang] Fix a crash when an array constructor contains an unlimited polymorphic value
Summary:
C7113 States that "An ac-value shall not be unlimited polymorphic."  We failed
to detect this situation which resulted in a crash when trying to get the
underlying derived type specification of the unlimited polymorphic value.

I added code to avoid the crash, code to emit an error message, and a test.

Reviewers: klausler, tskeith, DavidTruby

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83793
2020-07-14 15:22:33 -07:00
peter klausler af6b8d5139 [flang] Refine CR handling
We need to retain carriage return characters in source files
that are not parts of multi-byte line endings; they are
significant in CHARACTER literal constants.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D83808
2020-07-14 14:14:35 -07:00
peter klausler ce6f0303df [flang] Tuning up binary->decimal conversion
Use short division of big-radix values by powers of two when
converting values with negative unbiased exponents rather than
multiplication by smaller powers of five; this reduces the overall
outer iteration count. This change is a win across the entire range
of inputs.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D83806
2020-07-14 13:22:26 -07:00
AlexisPerry 02c3f70b47 [flang] Change the default F18_FC to gfortran
Summary: Changed default F18_FC from pgf90 to gfortran. Removed unnecessary references to pgf90 in favor of more generic naming.

Reviewers: sscalpone, richard.barton.arm, DavidTruby, jdoerfert, clementval

Reviewed By: sscalpone, richard.barton.arm, clementval

Subscribers: sstefan1, tskeith, klausler, clementval, flang-commits, llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D83488
2020-07-14 13:11:38 -06:00
Valentin Clement 0a90ffa772 [flang][openacc] OpenACC 3.0 parser
Summary:
This patch introduce the parser for OpenACC 3.0 in Flang. It uses the same TableGen mechanism
than OpenMP.

Reviewers: nvdatian, sscalpone, tskeith, klausler, ichoyjx, jdoerfert, DavidTruby

Reviewed By: klausler

Subscribers: MaskRay, SouraVX, mgorny, hiraditya, jfb, sstefan1, llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D83649
2020-07-14 14:29:40 -04:00
Isuru Fernando 9017b9ce1a [flang] Turn off FLANG_ENABLE_WERROR by default
Summary: This is a follow up to https://reviews.llvm.org/D78306

Reviewers: DavidTruby, sscalpone, jdoerfert

Reviewed By: DavidTruby

Subscribers: tskeith, Meinersbur, ChinouneMehdi, richard.barton.arm, mehdi_amini, mgorny, llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D81695
2020-07-14 12:17:51 -05:00
Sourabh Singh Tomar 3d0b76022d [flang][OpenMP] upstream OpenMP lowering
Summary:
This patch implements lowering of OpenMP barrier construct from
pft to OpenMPDialect.

Patch is carved out of following merged PR's from fir-dev branch
of https://github.com/flang-compiler/f18-llvm-project/

PR's:
https://github.com/flang-compiler/f18-llvm-project/pull/248
https://github.com/flang-compiler/f18-llvm-project/pull/251

Unfortunately primary tool `bbc` for functional validation is not
yet upstreamed. So this patch includes a unittest for lowering
`!OMP barrier` construct.

Some part of the these PR's still remains downstream(functional test
and dialect registration to legalizer) for obvious reasons.
Will upstream them when the dependencies are upstreamed.

Reviewed By: schweitz, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D83659
2020-07-14 18:01:15 +05:30
Valentin Clement f06ad91347 Revert "[flang][openacc] OpenACC 3.0 parser"
This reverts commit 65049d1610.

Buildbot failure clang-ppc64le-rhel
2020-07-13 22:35:19 -04:00
Valentin Clement 65049d1610 [flang][openacc] OpenACC 3.0 parser
Summary:
This patch introduce the parser for OpenACC 3.0 in Flang. It uses the same TableGen mechanism
than OpenMP.

Reviewers: nvdatian, sscalpone, tskeith, klausler, ichoyjx, jdoerfert, DavidTruby

Reviewed By: klausler

Subscribers: SouraVX, mgorny, hiraditya, jfb, sstefan1, llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D83649
2020-07-13 20:15:06 -04:00
AlexisPerry f630b8590f [flang] Extended the flang driver options to include gfortran equivalents to pgf90 specific options.
Summary: Added gfortran equivalents of pgf90's -Mfixed, -Mfree, -Mextend, -Mstandard, -Munlimited and also added -fdefault-double-8

Reviewers: sscalpone, richard.barton.arm, DavidTruby, clementval, jdoerfert

Reviewed By: sscalpone, richard.barton.arm

Subscribers: sstefan1, llvm-commits, flang-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D83687
2020-07-13 14:26:28 -06:00
Tim Keith 3780d3eb10 [flang] Use octal escapes for character literals in modfiles
Character literals can be formatted using octal or hex escapes for
non-ascii characters. This is so that the program can be unparsed for
either pgf90 or gfortran to compile. But modfiles should not be affected
by that -- they should be consistent.

This changes causes modfiles to always have character literals formatted
with octal escapes.

Differential Revision: https://reviews.llvm.org/D83703
2020-07-13 12:19:18 -07:00
David Truby 4121172239 [flang][openmp] libc++ unordered_map build fix in flang openmp static analysis
Simply move the include of unordered_map from the .cpp file to the .h file
2020-07-13 16:08:24 +01:00
Valentin Clement 6e42a417ba [flang][openmp] Check clauses allowed semantic with tablegen generated map
Summary:
This patch is enabling the generation of clauses enum sets for semantics check in Flang through
tablegen. Enum sets and directive - sets map is generated by the new tablegen infrsatructure for OpenMP
and other directive languages.
The semantic checks for OpenMP are modified to use this newly generated map.

Reviewers: DavidTruby, sscalpone, kiranchandramohan, ichoyjx, jdoerfert

Reviewed By: DavidTruby, ichoyjx

Subscribers: mgorny, yaxunl, hiraditya, guansong, sstefan1, aaron.ballman, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83326
2020-07-11 12:45:12 -04:00
Eric Schweitz 9263e08251 [flang] ifdef to avoid warning about supposedly dead function 2020-07-09 16:10:08 -07:00
peter klausler 8a8bb078a3 [flang] Fix frontend build with -DBUILD_SHARED_LIBS=On
Fix fronted shared library builds by eliminating dependences of
the parser on other component libraries, moving some code around that
wasn't in the right library, and making some dependences
explicit in the CMakeLists.txt files.  The lowering library
does not yet build as a shared library due to some undefined
names.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D83515
2020-07-09 15:54:19 -07:00
Pete Steinfeld 85d9745c83 [flang] Fix a crash when creating generics from a copy
Summary:
When a program unit creates a generic based on one defined in a module, the
function `CopyFrom()` is called to create the `GenericDetails`.  This function
copied the `specificProcs_` but failed to copy the `bindingNames_`.  If the
function `CheckGeneric()` then gets called, it tries to index into the empty
binding names and causes the crash.

I fixed this by adding code to `CopyFrom()` to copy the binding names.

I also added a test that causes the crash.

Reviewers: klausler, tskeith, DavidTruby

Subscribers: llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D83491
2020-07-09 15:49:45 -07:00
Eric Schweitz 7cd1b0ff34 [flang] partially revert upstreamed code to support complex values in runtime support to avoid warnings. 2020-07-09 07:39:44 -07:00
peter klausler cffc603617 [flang] Fix negative unit number hashing
Ensure that external unit number hashing produces a valid
index for a negative unit number, viz. a NEWUNIT=.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D83428
2020-07-08 17:59:00 -07:00
Pete Steinfeld 9520b6c8ab [flang] Fix a crash when cosubscript list is empty
Summary:
When there are errors in the evaluation of every cosubscript expression in a
coindexed object, the compiler would crash.  I fixed this by just checking to
see if there were errors in the evaluation of the cosubscripts before
constructing the `DataRef` for the coindexed object.

Reviewers: klausler, tskeith, DavidTruby

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83410
2020-07-08 10:11:34 -07:00
Eric Schweitz c54a013e5a partial revert on RTBuilder.h to avoid warnings. 2020-07-08 08:47:13 -07:00
Eric Schweitz 24b62f28c5 [flang] Upstreaming intrinsic call lowering.
This module implements the lowering of Fortran intrinsics to the
corresponding calls in support libraries (the Fortran runtime, math
libraries, etc.)

This revision is a tad larger because there are a large number of Fortran
intrinsics and this adds lowering for a fair number of them.

Differential revision: https://reviews.llvm.org/D83355
2020-07-08 07:34:21 -07:00
Pete Steinfeld 15fa287b64 [flang] Support for image selectors
Summary:
This change implements support for image selectors and image selector
specifications as described in section 9.6.

In check-coarray[.h,cpp] I changed the `Leave()` function for
`parser::ImageSelectorSpec` to take a `parser::ImageSelector`, which
contains a list of image selector specifications.  This allows us to
detect when the same specification is used more than once.  I also added
code to analyze the expressions for the image selector specifications to
expression.cpp and a test for all of the conditions to check at
compile-time.

Note that we do not check at compile-time to see if the value of the
cosubscripts are within the specified cobounds.  We also do not check anything
related to selecting a valid team.  We also do not check that the denotation of
the `stat-variable` is not dependent on the evaluation of an entity in the
same statement.

Reviewers: klausler, tskeith, DavidTruby

Subscribers: llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D83336
2020-07-08 07:31:54 -07:00
Isuru Fernando 2ebf4b6e4c [flang] Fix setting mxcsr on MSVC
Reviewers: sscalpone, jdoerfert, #flang, DavidTruby, jeanPerier

Reviewed By: jeanPerier

Subscribers: richard.barton.arm, jeanPerier, ro, llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D77815
2020-07-08 07:25:25 -05:00
peter klausler 8f0f9eaddf [flang] Fix CHARACTER length folding problem
Do not rewrite LEN(x) or x%len to the expression that specifies
the length of x when that length is not a constant expression.
Its value may have changed since the value of the expression was
first captured in the definition of the object.

Reviewed By: tskeith, sscalpone

Differential Revision: https://reviews.llvm.org/D83352
2020-07-07 16:38:36 -07:00
Zachary Selk 4b9b64d561 [flang] Added missing runtime I/O definitions
Added runtime function definitions for 32-bit real I/O and 32-bit complex output

Differential Revision: https://reviews.llvm.org/D83112
2020-07-07 12:33:51 -07:00
Katherine Rasmussen c6a23df691 [flang] Make 'num_images()' intrinsic
I added 'num_images()' to the list of functions that are evaluated as intrinsic. I also added a test file in flang/test/Semantics to test calls to 'num_images()'. There was a call to 'num_images()' in flang/test/Semantics/call10.f90 that expected an error, now it no longer produces an error. So I edited that file accordingly. I also edited the intrinsics unit test to add further testing of 'num_images()'.

Differential Revision: https://reviews.llvm.org/D83142
2020-07-07 12:31:10 -07:00
Eric Schweitz 216a54a04b [flang] Add lowering of I/O statements.
The IO module is where I/O related statements are lowered to calls to the runtime library.

Differential revision: https://reviews.llvm.org/D83267
2020-07-07 07:31:50 -07:00
Kiran Kumar T P cd503166fb [flang][OpenMP] Enhance parser support for flush construct to OpenMP 5.0
Summary:
This patch enhances parser support for flush construct to OpenMP 5.0 by including memory-order-clause.

2.18.8 flush Construct
        !$omp flush [memory-order-clause] [(list)]
                where memory-order-clause is
                acq_rel
                release
                acquire

The patch includes code changes and testcase modifications.

Reviewed By: klausler, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D82177
2020-07-07 14:27:13 +05:30
Tim Keith 1b18391818 [flang] Add missing include for std::min
This was causing the build to fail on macos.

Differential Revision: https://reviews.llvm.org/D83237
2020-07-06 13:03:02 -07:00
Pete Steinfeld f9e24a563c [flang] Bug fix for ambiguous references to data and functions
Summary:
A program may erroneously reference the same name as both a data object
and as a function.  Some of these references were causing an internal
error in expression analysis.

It was already the case that a symbol referenced in a parse tree for a
call was changed from an `Entity` to a `ProcEntity`.  I added code to
detect when a symbol was referenced in a parse tree as an array element
gets changed from an `Entity` to an `ObjectEntity`.  Then, if an
`ObjectEntity` gets called as a function or a `ProcEntity` gets
referenced as a data object, errors get emitted.

This analysis was previously confined to the name resolution of the
specification part of a `ProgramTree`.  I added a pass to the execution
part of a `ProgramTree` to catch names declared in blocks.

Reviewers: tskeith, klausler, DavidTruby

Subscribers: llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D82903
2020-07-06 11:27:14 -07:00
peter klausler a39e9cf6be [flang] Basic tests of external I/O runtime (part 9/9)
Add new unit tests for external Fortran I/O that drive the
Fortran I/O runtime API from C++ and exercise basic writing
and read-back in the various combinations of access modes,
record length variability, and formatting.  Sequential modes
are tested with positioning.  More thorough tests written in
Fortran will follow when they can be compiled and run.

The Fortran runtime's error termination callback registration
was extended with source file and line number positions for
better failure messages in unit testing.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D83164
2020-07-06 10:37:13 -07:00
peter klausler 5d5b968252 [flang] Add fixes and missing stmts to I/O runtime API handlers (ext. I/O part 8)
Complete the rework of the initial implementation of external I/O
to fix problems found in testing (tests to follow); add handlers
for hitherto unimplemented PAUSE, FLUSH, ENDFILE, BACKSPACE, and
REWIND statements.

Reviewed By: tskeith, sscalpone

Differential Revision: https://reviews.llvm.org/D83162
2020-07-04 12:53:31 -07:00
peter klausler 45b5c79a31 [flang] Extend & fix per-I/O-statement state (ext. I/O work part 7)
The per-I/O-statement state structures need to support missing
external I/O statements, and some bugs found in testing with
formatted input and record advancement are fixed.  The effects
of these changes will not be visible until further patches to
the I/O API handlers are pushed.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D83151
2020-07-04 10:49:00 -07:00
peter klausler 0006354c3b [flang] Further implementation of external I/O unit operations (part 6)
Rework initial implementation of external I/O unit operations to
fix problems exposed in unit tests (in a later patch).  Add flushing.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D83147
2020-07-03 17:31:01 -07:00
peter klausler 7926969afc [flang] Track known file size, add IsATerminal (ext. I/O work part 5)
Add a data member knownSize_ and an accessor to allow the size of
an external file to be tracked when known.  Also add a wrapper for
::isatty() here in the filesystem encapsulation module.  These
features are needed for the external I/O rework changes still
to come.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D83141
2020-07-03 13:04:18 -07:00
peter klausler c7cabf9d60 [flang] Define new runtime error IOSTAT values (I/O runtime work part 4)
Add more IOSTAT= values for errors that can arise in external I/O.

Reviewed By: sscalpone

Differential Revision: https://reviews.llvm.org/D83140
2020-07-03 12:41:33 -07:00
Eric Schweitz 35808ab8e1 [flang] Add FIRBuilder.cpp
The FIR builder is a helper class that manages the creation of MLIR
operations from the bridge. The focus of the builder is the creation of
Operations, Types, etc.

Differential revision: htps://reviews.llvm.org/D83107
2020-07-03 11:52:00 -07:00
peter klausler 98d576c78f [flang] Improve API for runtime allocator (I/O runtime work part 3)
New<A> used to return an A&; now it returns an OwningPtr<A>
to force better ownership tracking of allocations.  Its API
has also been split into New<A> and SizedNew<A> to allow
allocations with a size override.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D83108
2020-07-03 08:37:40 -07:00
Jean Perier eb305631be [flang][NFC] Move and rework pgmath description used in folding
This change prepares usage of lipgmath description in lowering.
- Removes the static variable templates that were used to abstract
  libpgmath description
- Move the description to pgmath.h.inc header and rework the macros
  so that they can both be used to declare pgmath functions and use
  them.
  The way they are to be used is left to pgmath.h.inc user that
  must define PGMATH_USE_XX macros that will be called for all pgmath
  functions in pgmath.h.inc.
- In intrinsic-library.cpp define PGMATH_USE_XX macro callbacks in
  order to capture function pointers to pgmath functions as well as
  a description of their type. This will be used for constant folding
  using pgmath.
- Change atan/atan2 handling to use atan2 instead of atan when there are two
arguments  because it is easier to handle in the runtime description.

Also fixes lipgmath linking regression after D78215 cmake changes.

This change is motivated by the need to use a similar pgmath
description in lowering. The difference is that no function pointers will
be taken there, and instead only the function name and type are needed.

Reviewed By: schweitz, sscalpone

Differential Revision: https://reviews.llvm.org/D83051
2020-07-03 10:19:33 +02:00
peter klausler 4e958c1748 [flang] External I/O runtime work, repackaged (part 2)
Clean up the input editing path so external input works better
when combined with further changes.  List-directed input needed
to allow for advancement to following records.

Reviewed By: tskeith, sscalpone

Differential Revision: https://reviews.llvm.org/D83104
2020-07-02 17:44:51 -07:00
peter klausler 37f98f6f4c [flang] External I/O runtime work, repackaged (part 1)
Add a isFixedRecordLength flag member to Connection to
disambiguate the state of "record has known variable length"
from "record has fixed length".  Code that sets and tests this
flag will appear in later patches.  Rearrange data members to
reduce storage requirements, since Connection might indirectly
end up on a program stack frame.  Add a utility member function
BeginRecord(); use it in internal I/O processing.

Reviewed By: tskeith, sscalpone

Differential Revision: https://reviews.llvm.org/D83098
2020-07-02 15:17:26 -07:00
peter klausler 7cccd49a55 [flang] Clean up binary dependences of runtime libraries
There were dependences upon LLVM libraries in the Fortran
runtime support library binaries due to some indirect #includes
of llvm/Support/raw_ostream.h, which caused some kind of internal
ABI version consistency checking to get pulled in.  Fixed by
cleaning up some includes.

Reviewed By: tskeith, PeteSteinfeld, sscalpone

Differential Revision: https://reviews.llvm.org/D83060
2020-07-02 12:27:01 -07:00
Tim Keith 70f2bcc197 [flang] Fix bug determining alternate return
The arguments have been moved out of the analyzer so we can't get the
expected number there. Instead use the argument count from the newly
built callee.

Differential Revision: https://reviews.llvm.org/D83063
2020-07-02 12:24:35 -07:00
Eric Schweitz 5c02a2421b [flang] Add inliner pass.
This adds a minimalist inliner implementation. Along with the inliner, a
minimum number of support files are also included. These will pave the
way for future diffs to add more transformation passes to flang. A
future diff will add the inline test, which cannot be run successfully
quite yet as some components have not yet been upstreamed.

Differential revision:
2020-07-02 06:10:54 -07:00
Eric Schweitz ffa1f8198e [flang] Add changes to codegen to convert it to tablegen passes.
This upstreams changes to codegen to convert the passes to the new
tablegen pass support from MLIR.

Differential revision: https://reviews.llvm.org/D83018
2020-07-02 06:07:40 -07:00
Valentin Clement 2ddba3082c [flang][openmp] Use common Directive and Clause enum from llvm/Frontend
Summary:
This patch is removing the custom enumeration for OpenMP Directives and Clauses and replace them
with the newly tablegen generated one from llvm/Frontend. This is a first patch and some will follow to share the same
infrastructure where possible. The next patch should use the clauses allowance defined in the tablegen file.

Reviewers: jdoerfert, DavidTruby, sscalpone, kiranchandramohan, ichoyjx

Reviewed By: DavidTruby, ichoyjx

Subscribers: jholewinski, cfe-commits, dblaikie, MaskRay, ymandel, ichoyjx, mgorny, yaxunl, guansong, jfb, sstefan1, aaron.ballman, llvm-commits

Tags: #llvm, #flang, #clang

Differential Revision: https://reviews.llvm.org/D82906
2020-07-01 20:58:11 -04:00
Tim Keith 05756e6937 [flang] Add more support for alternate returns
Add `hasAlternateReturns` to `evaluate::ProcedureRef`.

Add `HasAlternateReturns` to test subprogram symbols.

Fix `label01.F90` test: It was checking that "error: " didn't appear in
the output. But that was erroneously matching a warning that ends
"would be in error:". So change it to check for ": error: " instead.

Differential Revision: https://reviews.llvm.org/D83007
2020-07-01 17:28:01 -07:00
Tim Keith dd90408262 [flang][NFC] Get formatting in sync with latest clang-format
flang/module only contains Fortran files and one is a .h so disable
formatting on that directory.

Differential Revision: https://reviews.llvm.org/D82989
2020-07-01 16:51:46 -07:00
clementval 5c37b2a5ee Revert "[flang][openmp] Use common Directive and Clause enum from llvm/Frontend"
This reverts commit 7f1e776795.
2020-07-01 18:49:07 -04:00
peter klausler 31e6cd28a5 [flang] Implement cross-set EQUIVALENCE impossibility checking
Implement cross-set EQUIVALENCE impossibility checking; fixes
an infinite loop on an erroneous test.  Also fix substring
reference offset calculations in EQUIVALENCE discovered to
be incorrect during testing.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D82993
2020-07-01 14:09:07 -07:00
Eric Schweitz 5a580bbb81 [flang] Add the Runtime.h to prepare for more code being upstreamed.
This is the header file for lowering Fortran statements that depend on
the Fortran runtime support library. The implementation of the lowering
of these constructs will follow in a subsequent diff.

Differential revision: https://reviews.llvm.org/D82991
2020-07-01 13:26:36 -07:00
Valentin Clement 7f1e776795 [flang][openmp] Use common Directive and Clause enum from llvm/Frontend
Summary:
This patch is removing the custom enumeration for OpenMP Directives and Clauses and replace them
with the newly tablegen generated one from llvm/Frontend. This is a first patch and some will follow to share the same
infrastructure where possible. The next patch should use the clauses allowance defined in the tablegen file.

Reviewers: jdoerfert, DavidTruby, sscalpone, kiranchandramohan, ichoyjx

Reviewed By: DavidTruby, ichoyjx

Subscribers: ichoyjx, mgorny, yaxunl, guansong, jfb, sstefan1, aaron.ballman, llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D82906
2020-07-01 15:58:45 -04:00
River Riddle f625f5231a [mlir] Remove the default template parameters from AttrBase and TypeBase.
MSVC 2017 doesn't support the case where a trailing variadic template list comes after template types with default parameters. Until we upgrade to VS 2019, we can't use the simplified definitions.
2020-06-30 21:55:32 -07:00
Tim Keith 98202edacb [flang] Silence some warnings from clang-tidy
Disable some of the warnings from clang-tidy, in particular,
`readability-identifier-naming`. They add clutter to reviews.

Differential Revision: https://reviews.llvm.org/D82795
2020-06-30 10:15:12 -07:00
Eric Schweitz bd2c3014e1 [flang] Add coarray lowering hooks.
Differential review: https://reviews.llvm.org/D82790
2020-06-29 14:24:13 -07:00
peter klausler f45b41348b [flang] Defer stmt function body analysis until specification part complete
Expression analysis was being invoked on the bodies of statement functions
as they were being encountered during name resolution.  This led to failures
on some FCVS tests in cases where those expressions contained implicitly
typed objects.  Defer the analysis of statemet function bodies to the end
of the specification part, at which time the symbols of the enclosing scope
will have been typed.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D82796
2020-06-29 12:32:19 -07:00
peter klausler 5fb5f7b5ab [flang] Fix line continuation after bare labels (fm200.f)
Fixed-form line continuation was not working when the
preceding line was a bare label.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D82687
2020-06-26 17:07:38 -07:00
Richard Barton b537c81b5f [flang] Port remaining test_any.sh tests to FileCheck
Port the remaining tests which only require mechanical changes and delete
test_any.sh.

    * Delete old RUN lines
    * Replace:
        EXEC: ${F18} ... | ${FileCheck} ...
      with
        RUN: %f18 .. | FileCheck ...
    * Prepend RUN line with not when it is expected to fail

Also reinstate a de-activated EXEC line and port it in the same way.

Differential Revision: https://reviews.llvm.org/D82168
2020-06-26 19:35:14 +01:00
Eric Schweitz c3477c51e5 [flang] Add CHARACTER type lowering helpers and runtime.
In order for these files to build properly, this patch rolls up a number of changes that have been made to various files that have been upstreamed.

Implementations for the interfaces included in Bridge.h and IntrinsicCall.h will be included in a future diff.

Differential revision: https://reviews.llvm.org/D82608
2020-06-26 11:01:52 -07:00
Richard Barton ae74252341 [flang] Port test_any.sh tests to FileCheck: Hand port canondo{08-18} tests
These tests checked for stdout and stderr in the same pipe, which does not
come out in a guaranteed order. test_any.sh's FileCheck accepts CHECK lines in
any order while FileCheck checks must match in order.

Hand port these to pipe stdout to a temp file which is checked with a separate
FileCheck RUN line to test it.

Differential Revision: https://reviews.llvm.org/D82167
2020-06-26 18:50:46 +01:00
Richard Barton bf57fc1c8e [flang] Port test_any.sh tests to FileCheck: Hand port getsymbols tests
test_any.sh's FileCheck accepts the CHECK line matches in any order while
FileCheck checks in strict order. Re-order the CHECK lines to source code
order - they come from an ordered datastructure.

Some CHECK lines are sensitive to line number which are fixed up manually.

getsymbols02 had multiple test inputs which had their own EXEC lines.
Consolidate these together in one file.

Differential Revision: https://reviews.llvm.org/D82166
2020-06-26 18:49:21 +01:00
Richard Barton 66c26d93b7 [flang] Port test_any.sh tests to FileCheck: Hand port getdefinition* tests
These tests are sensitive to line numbers in the input and check output.
They also successively write to a temporary file then check that.

Fix the line number issues and replace the temporary file use with successive
calls to FileCheck with different check-prefixes.

Differential Revision: https://reviews.llvm.org/D82165
2020-06-26 18:47:13 +01:00
Richard Barton 9c98ed9cd4 [flang] Port test_any.sh tests to FileCheck: Hand port tests which use regexes
The regex syntax used by test_any.sh's FileCheck is sometimes incompatible with
real FileCheck.

Hand port these tests to use FileCheck and it's regex format.

Also remove FIXME from label01 that no longer applies.
Also add second run-line that enables all tests.
Add some new FIXMEs for issues in original tests

Differential Revision: https://reviews.llvm.org/D82164
2020-06-26 18:41:31 +01:00
Mehdi Chinoune 4198874630 [flang] Replace ATTRIBUTE_UNUSED with LLVM_ATTRIBUTE_UNUSED
ATTRIBUTE_UNUSED wasn't defined with MSVC.

Patch by: Mehdi Chinoune <chinoune.mehdi@hotmail.com>

Differential Revision: https://reviews.llvm.org/D78356
2020-06-25 19:53:19 +01:00
Eric Schweitz 84f3805805 [flang] add RTBuilder.h
This is a set of type building models that is specific to the lowering
process. It provides the mechanism of mapping C(++) header file interfaces
to the MLIR+FIR type system.

It also provides some macros to build a constexpr evaluated table to
runtime functions. This code is used to build the interface tables to
various runtime support libraries.

Differential revision: https://reviews.llvm.org/D82387
2020-06-23 14:54:45 -07:00
Eric Schweitz a9c478acd0 add copy of MLIR .clang-tidy to squelch noise in phabricator reviews 2020-06-22 15:26:28 -07:00
Tim Keith 663860f63e [flang] Fix bug checking SAVE attribute
Treat function result like dummy argument: a SAVE statement without an
entity-list does not make it saved.

Differential Revision: https://reviews.llvm.org/D82309
2020-06-22 11:33:04 -07:00
peter klausler 16d24e4543 [flang] Shape analysis for result of MATMUL
Implement shape analysis for the result of the MATMUL
generic transformational intrinsic function, based on
the shapes of its arguments.  Correct the names of the
arguments to match the standard, too.

Reviewed By: PeteSteinfeld
Differential Revision: https://reviews.llvm.org/D82250
2020-06-22 09:45:30 -07:00
Eric Schweitz 3a84d84adc [flang] Finish adding AbstractConverter.h
This adds the abstract converter interface. The abstract converter is an
interface that supports the conversion of front-end data structures to
MLIR. This interface will be instantiated by the bridge in a future
commit.

Differential revision: https://reviews.llvm.org/D82268
2020-06-22 08:18:15 -07:00
sameeran joshi fa5d416efd [flang]Fix individual tests with lit when building out of tree
Summary:

Fix individual check tests with lit when building out-of-tree
`ninja check-flang-<folder>` was not working.
The CMakeLists.txt was looking for the lit tests in the source directory
instead of the build directory.

This commit extends @CarolineConcatto previous patch[D81002]

Reviewers: DavidTruby, sscalpone, tskeith, CarolineConcatto, jdoerfert

Reviewed By: DavidTruby

Subscribers: flang-commits, llvm-commits, CarolineConcatto

Tags: #flang, #llvm

Differential Revision: https://reviews.llvm.org/D82120
2020-06-22 10:30:33 +05:30
Eric Schweitz b938eaec55 [flang] Add BoxValue.h
The bridge uses internal boxes of related ssa-values to track all the
information associated with a Fortran variable. Variables may have a
location and a value, but may also carry other properties such as rank,
shape, LEN parameters, etc. in Fortran.

Differential revision: https://reviews.llvm.org/D82228
2020-06-20 14:13:14 -07:00
Eric Christopher 64b04e4754 Temporarily Revert "[flang][OpenMP] Enhance parser support for flush construct to OpenMP 5.0"
as it's failing Semantics/omp-clause-validity01.f90.

This reverts commit b32401464f.
2020-06-20 01:18:53 -07:00
Kiran Kumar T P b32401464f [flang][OpenMP] Enhance parser support for flush construct to OpenMP 5.0
Summary:
This patch enhances parser support for flush construct to OpenMP 5.0 by including memory-order-clause.

2.18.8 flush Construct
	!$omp flush [memory-order-clause] [(list)]
		where memory-order-clause is
		acq_rel
		release
		acquire

The patch includes code changes and testcase modifications.

Reviewed By: klausler, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D82177
2020-06-20 13:33:29 +05:30
peter klausler 0df6f8fe8e [flang] Fix F5.3 formatting of 0.025
Fix F output editing in the Fortran runtime so that it
respects the 'd' count of digits after the decimal mark.

Reviewed By: tskeith

Differential Revision: https://reviews.llvm.org/D82242
2020-06-19 18:09:10 -07:00
peter klausler a20d48d7d3 [flang] DATA stmt processing (part 4/4): Check & convert DATA
Implement rest of DATA statement semantics and conversion of
DATA statement initializations into static initializers of
objects in their symbol table entries.

Reviewed By: tskeith, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D82207
2020-06-19 13:26:20 -07:00
Eric Schweitz b5d51c2448 [flang] Add SymbolMap
The symbol map is a data structure for tracking variables in a subprogram during the lowering of that subprogram to FIR/MLIR. These data structures will be used by the bridge, which has not been upstreamed yet.

Differential revision: https://reviews.llvm.org/D82140
2020-06-19 11:47:58 -07:00
peter klausler 4171f80d54 [flang] DATA stmt processing (part 3/4): Remaining prep work
Rolls up small changes across the frontend to prepare for the large
forthcoming patch (part 4/4) that completes DATA statement processing
via conversion to initializers.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D82137
2020-06-19 09:09:05 -07:00
peter klausler 286d7a2159 [flang] DATA statement processing (part 2/4): Initial images
Summary:
Defines a representation for the initialized memory image of
a variable.  This image is populated by DATA statement
processing as designator elements are put into correspondence
with values, then converted into an initializer in the symbol
table so that lowering can pass the initial image to the
code generator.

Reviewers: tskeith, PeteSteinfeld, sscalpone, jdoerfert, DavidTruby

Reviewed By: tskeith

Subscribers: mgorny, llvm-commits, flang-commits

Tags: #flang, #llvm

Differential Revision: https://reviews.llvm.org/D82131
2020-06-18 17:13:59 -07:00
peter klausler d1862eb845 [flang] DATA stmt processing (part 1/4): designator folding
Summary:
Add code to resolve constant Designators at compilation time
into a base Symbol, byte offset, and field size.  This is used in
later DATA statement processing to identify the static storage being
initialized by each object in a DATA statement.  Also implement
the reverse mapping so that Designators can be reconstructed for
use in error messages about (e.g.) duplicate initializers.

Reviewers: tskeith, PeteSteinfeld, sscalpone, jdoerfert, DavidTruby

Reviewed By: PeteSteinfeld

Subscribers: mgorny, llvm-commits, flang-commits

Tags: #flang, #llvm

Differential Revision: https://reviews.llvm.org/D82125
2020-06-18 15:25:21 -07:00
peter klausler 2750556551 [flang] Roll up small fixes to runtime bugs found in testing
Summary:
Fix several bugs in the Fortran runtime found in initial
testing.

Reviewers: tskeith, PeteSteinfeld, sscalpone, jdoerfert, DavidTruby

Reviewed By: tskeith, PeteSteinfeld

Subscribers: llvm-commits, flang-commits

Tags: #flang, #llvm

Differential Revision: https://reviews.llvm.org/D82116
2020-06-18 14:25:04 -07:00
peter klausler 3aee64a9e0 [flang] Fix build problems on osx
Summary:
Fix build problems encountered on osx in two files.
The one in character.cpp fixes a legitimate bug that
elicited a valid warning.

Reviewers: tskeith, PeteSteinfeld, sscalpone, jdoerfert, DavidTruby

Reviewed By: tskeith, PeteSteinfeld

Subscribers: llvm-commits, flang-commits

Tags: #flang, #llvm

Differential Revision: https://reviews.llvm.org/D82107
2020-06-18 11:14:25 -07:00
Pete Steinfeld 3ed2909feb [flang] Fix crash with alternate returns in modules
Summary:
We weren't handling the case of subroutines with alternate returns that
are contained in modules.  I changed the code to add an `*` as the name
of the parameter when creating the `.mod` file.

Reviewers: tskeith, klausler, DavidTruby

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D82096
2020-06-18 08:56:12 -07:00
Jean Perier f1fa3b7f6e [flang] AMAX0, MIN1... rewrite to MAX/MIN: make result conversion explicit
Summary:
This patch changes speficic extremum functions rewrite to generic MIN/MAX.
It applies to AMAX0, AMIN0, AMAX1, AMIN1, MAX0, MIN0, MAX1, MIN1, DMAX1,
and DMIN1.

- Do not re-write specific extremums to MAX/MIN in intrinsic Probe and let
folding rewrite it and introduc the conversion on the MIN/MAX result.
- Also make operand promotion explicit in MIN/MAX folding.

For instance, after this patch:
AMAX0(int8, int4) is rewritten to REAL(MAX(int8, INT(int4, 8)))

All this care is to avoid rewritting it to MAX(REAL(int8), REAL(int4))
that may not always be numerically equivalent to the first rewrite.

Reviewers: klausler, schweitz, sscalpone, jdoerfert, DavidTruby

Reviewed By: klausler, schweitz

Subscribers: llvm-commits, flang-commits

Tags: #flang, #llvm

Differential Revision: https://reviews.llvm.org/D81940
2020-06-18 08:14:58 +02:00
peter klausler 3d627d6ff9 [flang] More Fortran runtime support for CHARACTER operations
Summary:
- Remove C++ library dependence from lock.h
- Implement LEN_TRIM, REPEAT, ADJUSTL, ADJUSTR, MAX/MIN
  intrinsic functions for CHARACTER

Reviewers: tskeith, PeteSteinfeld, sscalpone, schweitz, DavidTruby

Reviewed By: PeteSteinfeld

Subscribers: llvm-commits, flang-commits

Tags: #flang, #llvm

Differential Revision: https://reviews.llvm.org/D82054
2020-06-17 15:51:48 -07:00
Eric Schweitz b46e2548b6 [flang] Fix fallout from varous changes to the cmake files.
Differential revision: https://reviews.llvm.org/D82050
2020-06-17 14:40:05 -07:00
Tim Keith f392b75fd8 [flang] Fix out-of-tree builds
Replace two MLIR dependencies with MLIRLinalgOps.

Differential Revision: https://reviews.llvm.org/D82038
2020-06-17 12:02:00 -07:00
Eric Schweitz 30db177693 [flang] Upstream the Mangler module from lowering.
This upstreams the internal name mangling used in the bridge to generate
unique names from symbols.

Replace InternalNamesTest with the actual, functional unittest.

Differential revision: https://reviews.llvm.org/D81764
2020-06-16 15:24:13 -07:00
sameeran joshi 93f602b339 [flang] unit test support for out-of-tree and in-tree using google tests framework
Review comments addressed.
2020-06-15 22:09:56 +05:30
David Truby 9362698450 [flang] Change DIE("unreachable") cases to use llvm_unreachable
Reviewers: sscalpone

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79507
2020-06-15 17:21:35 +01:00
Eric Schweitz 4741835e03 [flang] Add the helper class for building fir.do_loop operations. A fir.do_loop models the semantics of a Fortran DO loop construct. One can use this operation to explicitly capture a DO loop for passing into the high-level optimizer.
Differential revision: https://reviews.llvm.org/D81692
2020-06-12 17:28:00 -07:00
Pete Steinfeld bb2f6f66c7 [flang] Added test for specification expressions
I added a test the exercises all of the cases instances of specification expressions as defined in section 10.1.11.

Summary: [flang] Added test for specification expressions

Reviewers: tskeith, klausler, DavidTruby

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D81759
2020-06-12 15:13:24 -07:00
peter klausler a0226f9bff [flang] Dodge bogus uninitialized data warning from gcc 10.1 via code cleanup
G++ 10.1 emits inappropriate "use of uninitialized data" warnings when
compiling f18.  The warnings stem from two sites in templatized code
whose multiple instantiations magnified the number of warnings.

These changes dodge those warnings by making some innocuous changes to
the code.  In the parser, the idiom defaulted(cut >> x), which yields a
parser that always succeeds, has been replaced with a new equivalent
pass<T>() parser that returns a default-constructed value T{} in an
arguably more readable fashion.  This idiom was the only attestation of
the basic parser cut, so it has been removed and the remaining code
simplified.  In Evaluate/traverse.h, a return {}; was replaced with a
return of a default-constructed member.

Differential Revision: https://reviews.llvm.org/D81747
2020-06-12 10:05:05 -07:00
sameeran joshi 70ad73b6b7 [flang] Semantics for SELECT TYPE
Summary:
    Added support for all semantic checks except C1157
    was previously implemented.

    Address review comments.

    Reviewers: PeteSteinfeld, tskeith, klausler, DavidTruby, kiranktp, anchu-rajendran, sscalpone

    Subscribers: kiranchandramohan, llvm-commits, flang-commits

    Tags: #llvm, #flang

    Differential Revision: https://reviews.llvm.org/D79851
2020-06-12 00:12:24 +05:30
Eric Schweitz 8bba0bca72 [flang] Add the complex expression helper class.
The complex expression helper class can be used to generate small,
short-lived instances of a "helper" that can be used to aid the
construction of complex expressions in FIR. The helper class bundles
together these functionally related operations.

Included in this diff is the header for the FIR builder. The
implementation has other dependences and will follow.

Differential Revision: https://reviews.llvm.org/D81287
2020-06-10 09:05:20 -07:00
Tim Keith a27d385209 [flang] Fix bug resolving type in type definition
When we encountered a type name in a derived type definition, we were
sometimes finding a component of that name rather than the type from
the enclosing scope. Fix this by introducing `NonDerivedTypeScope()` to
start the search in the right scope.

Differential Revision: https://reviews.llvm.org/D81493
2020-06-09 14:14:03 -07:00
Valentin Clement 38674030c0 Apply fix from D81179 only from GCC < 8
Summary: Apply workaround done in D81179 only for GCC < 8. As @klausler mentioned in D81179 we want to avoid additional checks for other compilers that do not need them.

Reviewers: DavidTruby, klausler, jdoerfert, sscalpone

Reviewed By: klausler, sscalpone

Subscribers: llvm-commits, tskeith, isuruf, klausler

Tags: #flang, #llvm

Differential Revision: https://reviews.llvm.org/D81208
2020-06-08 15:51:57 -04:00
Isuru Fernando bb73d1b278 [flang] Fix issue of flang/runtime/config.h not being found in out of tree builds
Summary: Fixes https://bugs.llvm.org/show_bug.cgi?id=46078

Reviewers: DavidTruby, jdoerfert, PeteSteinfeld, sscalpone, tskeith

Reviewed By: PeteSteinfeld, sscalpone, tskeith

Subscribers: mgorny, llvm-commits, tskeith

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D81266
2020-06-08 14:16:08 -05:00
Isuru Fernando 3862cbbc65 [flang] Use LLVM's flags
Summary:
The only difference is that LLVM_ENABLE_WERROR is set to OFF
by default, but we enable this in a standalone flang build

This commit fixes some windows issues with the flags

Reviewers: DavidTruby, jdoerfert, sscalpone

Reviewed By: DavidTruby, sscalpone

Subscribers: ormris, richard.barton.arm, mehdi_amini, Meinersbur, ChinouneMehdi, tskeith, mgorny, llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D78306
2020-06-08 15:29:52 +01:00
Pete Steinfeld 4d8c00c059 [flang] Fix crash on erroneous expressions
Summary:
If you create an expression with parse errors, the `parser::Expr.typedExpr`
will be empty, which causes a compiler crash.  The crash is caused by the
check in check-do-forall.cpp that scans all expresssions to see if `DO`
variables are being modified.

It turned out that the problem was that I was fetching subexpressions of type
`parser::Expr`, which are not guaranteed to have a non-null `typedExpr`.  I
fixed this by only grabbing the top-level expression from which to gather
arguments as part of the DO loop analysis.  This, in turn, exposed a problem
where I wasn't collecting all of the actual arguments in an expression.  This
was caused by the fact that I wasn't recursing through the rest of the
expression after finding an argument.  I fixed this by recursing through the
argument in the member function in `CollectActualArgumentsHelper`.

Reviewers: klausler, tskeith, DavidTruby

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D81101
2020-06-05 08:46:43 -07:00
Pete Steinfeld 1746c8ed26 [flang] Fixed crash on forward referenced `len` parameter
Summary:
Using a forward reference to define a `len` parameter causes a crash.
The underlying cause was that a previously declared type had an
erroneous expression for its `LEN` param value.  When this expression
was referenced to evaluate a subsequent expression, bad things happened.
I fixed this by putting in code to detect this case.

Reviewers: tskeith, klausler, DavidTruby

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D80593
2020-06-04 13:12:11 -07:00
Eric Schweitz baa12ddb6f [flang] Add the conversions for types.
Part of lowering is to convert the front-end types to their FIR dialect representations.  These conversions are done by here in the ConvertType module.

proactively update the code to conform better with LLVM coding conventions

Differential Revision: https://reviews.llvm.org/D81034
2020-06-04 12:54:50 -07:00
Valentin Clement 3d9bb031d1 [flang] avoid GCC < 8 compiler failure after D80794
Summary:
Patch D80794 remove the custom flags for release build for flang.
This leads to build failure with GCC < 8. This patch add upperbound check
in order to avoid the -Werror=array-bounds to trigger a build failure.

```
/home/4vn/versioning/llvm-project/flang/lib/Decimal/big-radix-floating-point.h:183:29: error: array subscript is above array bounds [-Werror=array-bounds]
           digit_[j] = digit_[j + remove];
                       ~~~~~~^
/home/4vn/versioning/llvm-project/flang/lib/Decimal/big-radix-floating-point.h:183:29: error: array subscript is above array bounds [-Werror=array-bounds]
           digit_[j] = digit_[j + remove];
                       ~~~~~~^
/home/4vn/versioning/llvm-project/flang/lib/Decimal/big-radix-floating-point.h:183:29: error: array subscript is above array bounds [-Werror=array-bounds]
           digit_[j] = digit_[j + remove];
                       ~~~~~~^
/home/4vn/versioning/llvm-project/flang/lib/Decimal/big-radix-floating-point.h:183:29: error: array subscript is above array bounds [-Werror=array-bounds]
           digit_[j] = digit_[j + remove];
                       ~~~~~~^
/home/4vn/versioning/llvm-project/flang/lib/Decimal/big-radix-floating-point.h:183:29: error: array subscript is above array bounds [-Werror=array-bounds]
           digit_[j] = digit_[j + remove];
```

```
/home/4vn/versioning/llvm-project/flang/include/flang/Evaluate/integer.h:809:28: error: array subscript is above array bounds [-Werror=array-bounds]
               xy += product[to];
                     ~~~~~~~^
/home/4vn/versioning/llvm-project/flang/include/flang/Evaluate/integer.h:810:22: error: array subscript is above array bounds [-Werror=array-bounds]
               product[to] = xy & partMask;
               ~~~~~~~^
/home/4vn/versioning/llvm-project/flang/include/flang/Evaluate/integer.h:809:28: error: array subscript is above array bounds [-Werror=array-bounds]
               xy += product[to];
                     ~~~~~~~^
```

Reviewers: DavidTruby, sscalpone, jdoerfert

Reviewed By: DavidTruby

Subscribers: llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D81179
2020-06-04 14:48:39 -04:00
Jean Perier 62b127eef6 [flang] Fix IsConstantExpr for division expressions
Summary:
Fortran::evaluate::IsConstantExpr did not check that the numerator
was a constant expression. This patch fixes the issue.

Reviewers: DavidTruby, klausler, schweitz, PeteSteinfeld, jdoerfert, sscalpone

Reviewed By: klausler, PeteSteinfeld, sscalpone

Subscribers: llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D81096
2020-06-04 09:44:44 +02:00
Anchu Rajendran 70f1b4b412 [flang] Implemented 2 Semantic checks for DATA statement and fixed a few bugs
Summary
  - Implemented C876, C877
  - Fixed IsConstantExpr to check C879
  - Fixed bugs in few test cases - data01.f90, block-data01.f90,
  pre-fir-tree02.f90
  - Modified implementation of C8106 to identify all automatic objects
  and modified equivalence01.f90 to reflect the changes

Differential Revision: https://reviews.llvm.org/D78424
2020-06-03 10:33:26 +05:30
David Truby 81bf1e29aa [flang] Fix release build flags.
Summary:
This patch removes the custom CMAKE_RELEASE_CXX_FLAGS variable.
This variable being set was having the effect of removing other important
Release flags, notably `-DNDEBUG`.

This patch may need to be accompanied by fixes for the macOS issues that
the removed comment mentions; I don't have a mac to test this on though so
hopefully a reviewer can help with that.

Reviewers: Andrzej, tskeith, sscalpone

Subscribers: mgorny, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D80794
2020-06-02 16:29:12 +01:00
Eric Schweitz ae6e499d25 [flang] This adds the lowering stubs for Open MP.
The lowering bridge will call these lowering hooks to process the Open
MP directives that it iterates over in the PFT.  This is a mock
interface without an implementation in this patch.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D80815
2020-06-01 09:11:53 -07:00
Tim Keith 14f49599cc [flang][NFC] Remove link-time dependency of Evaluate on Semantics
Summary:
Some Symbol-related functions used in Evaluate were moved to
Evaluate/tools.h. This includes changing some member functions that were
replaced by non-member functions `IsDummy`, `GetUsedModule`, and
`CountLenParameters`.

Some member functions were made inline in `Scope`, `Symbol`,
`ArraySpec`, and `DeclTypeSpec`. The definitions were preceded by a
comment explaining why they are inline.

`IsConstantShape` was expanded inline in `IsDescriptor` because it isn't
used anywhere else

After this change, at least when compiling with clang on macos,
`libFortranEvaluate.a` has no undefined symbols that are satisfied by
`libFortranSemantics.a`.

Reviewers: klausler, PeteSteinfeld, sscalpone, jdoerfert, DavidTruby

Reviewed By: PeteSteinfeld

Subscribers: llvm-commits

Tags: #flang, #llvm

Differential Revision: https://reviews.llvm.org/D80762
2020-05-29 16:39:14 -07:00
Eric Schweitz fbac9ce226 [flang] Batch together the changes to the PFT intermediate data
structure for upstreaming to llvm-project.

These files have had many changes since they were originally upstreamed.
Some of the changes are cosmetic.  Most of the functional changes were
done to support the lowering of control-flow syntax from the front-end
parse trees to the FIR dialect.

This patch is meant to be a reviewable size. The functionality it
provides will be used by code yet to be upstreamed in lowering.

review comments:

[review D80449][NFC] make PFT ParentVariant a ReferenceVariant

ReferenceVariant had to be slightly updated to also support
non constant references (which is required for ParentType).

[review D80449] extend Variable implementation beyond a comment
2020-05-29 15:24:20 -07:00
Pete Steinfeld c4dbe59ae8 [flang] Fixes for problems with declaring procedure entities
Summary:
We were not detecting declaring multiple interfaces to the same procedure.
Also, we were not handling the initialization of entitiies where the associated
Symbol had previously had errors.

I added the function `IsInterfaceSet()` to ProcEntityDetails to see if
the value of `interface_` had been previously set.  I then checked  this
function before calling set_interface() and emitted an error message if
the interface was already set.

Also, in situations where we were emitting error messages for symbols, I
set the Error flag on the Symbol.  Then when performing initialization
on the Symbol, I first check to see if the Symbol had an error.

Reviewers: tskeith, klausler, DavidTruby

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D80453
2020-05-26 12:17:20 -07:00
Pete Steinfeld 38095549c6 [flang] Constraint checks C751 to C760
Summary:
Many of these were already implemented, and I just annotated the tests and/or
the code.

C752 was a simple check to verify that CONTIGUOUS components are arrays with

C754 proved to be virtually identical to C750 that I implemented previously.
This caused me to remove the distinction between specification expressions for
type parameters and bounds expressions that I'd previously created.
the POINTER attribute.

I also changed the error messages to specify that errors in specification
expressions could arise from either bad derived type components or type
parameters.

In cases where we detect a type param that was not declared, I created a symbol
marked as erroneous.  That avoids subsequent semantic process for expressions
containing the symbol.  This change caused me to adjust tests resolve33.f90 and
resolve34.f90.  Also, I avoided putting out error messages for erroneous type
param symbols in `OkToAddComponent()` in resolve-names.cpp and in
`EvaluateParameters()`, type.cpp.

C756 checks that procedure components have the POINTER attribute.

Reviewers: tskeith, klausler, DavidTruby

Subscribers: llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D79798
2020-05-15 18:50:14 -07:00
Eric Christopher b1ae13b4e9 Fix flang build after mlir SideEffects.h -> SideEffectInterfaces.h change. 2020-05-15 15:51:32 -07:00
Alex Zinenko 4ead2cf76c [mlir] Rename conversions involving ex-Loop dialect to mention SCF
The following Conversions are affected: LoopToStandard -> SCFToStandard,
LoopsToGPU -> SCFToGPU, VectorToLoops -> VectorToSCF. Full file paths are
affected. Additionally, drop the 'Convert' prefix from filenames living under
lib/Conversion where applicable.

API names and CLI options for pass testing are also renamed when applicable. In
particular, LoopsToGPU contains several passes that apply to different kinds of
loops (`for` or `parallel`), for which the original names are preserved.

Differential Revision: https://reviews.llvm.org/D79940
2020-05-15 10:45:11 +02:00
Valentin Clement 85725a67c7 [Flang][OpenMP] Avoid abort when collapse clause value is negative
Summary:
If the value in the collapse close is negative f18 abort without the correct error message. This PR change the size_t in name resolution to a int64_t and check appropriately for negative or zero before the privatization of induction variable.
The correct error is then catch by the OpenMP structure check.

This diff is migrated from the GitHub pull request https://github.com/flang-compiler/f18/pull/1098

Reviewers: ichoyjx, jdoerfert, sscalpone, DavidTruby

Reviewed By: ichoyjx, sscalpone, DavidTruby

Subscribers: sscalpone, klausler, yaxunl, guansong, llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D77821
2020-05-14 21:37:25 -04:00
Stephen Neuendorffer 661b234cbc [MLIR] Rename SideEffects.td -> SideEffectInterfaces.td
This normalize the name of the tablegen file with the name of the generated
files (SideEffectInterfaces.h.inc) and the other Interface tablegen files,
which all end in Interface(s).td

Differential Revision: https://reviews.llvm.org/D79517
2020-05-12 12:21:42 -07:00
Tim Keith 6f300105d2 [flang] Fix bug with IMPORT of USE of USE
When a module contained an import of a use-association of a
use-association, we weren't recognizing that the symbols was needed.
The fix is the follow all of the use-associations using `GetUltimate()`.

Differential Revision: https://reviews.llvm.org/D79737
2020-05-11 13:28:07 -07:00
Tim Keith 99aa87a5b5 [flang][NFC] Simplify semantics test scripts
There were several different ways of handling the option to f18 to
find predefined modules:
- test_errors.sh was created by cmake substituting
  FLANG_INTRINSIC_MODULES_DIR into test_errors.sh.in
- some tests used the flang script which has the option built it
- some tests used %f18_with_includes which was replaced by the path
  to f18 plus the -I option
- some included -I../../include/flang in their run command

To make this more consistent, change %f18 to include the
-intrinsic-module-directory option and use it everywhere, including
to replace %flang and %f18_with_includes. This requires changing all
of the invocations of the test scripts to put %f18 at the end so that
it can expand to more than one argument.

This eliminates the need to generate test_errors.sh which means we
don't need flang/test/Semantics/CMakeLists.txt or the %B substitution.
That makes the test_errors.sh command like the others, replacing
%B/test/Semantics/test_errors.sh with %S/test_errors.sh.

Also remove the OPTIONS: functionality as custom options can be included
in the RUN: command. And remove -I/../../include/flang as that is now
always included.

Differential Revision: https://reviews.llvm.org/D79634
2020-05-11 11:49:25 -07:00
Valentin Clement 63a4fdda8c [flang] Fix compilation after rename of Loop dialect to scf
Summary: Flang was not compiling correctly after the renaming of Loop dialect to SCF. This patch fixes the problem.

Reviewers: ftynse, DavidTruby

Reviewed By: ftynse

Subscribers: aartbik, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79723
2020-05-11 13:15:33 -04:00
Tim Keith b05c8c5756 [flang] Make implicit conversion explicit in assignment
When intrinsic types are assigned there are some implicit conversions
that take place. This change make them explicit in the types
representation of assignments.

Differential Revision: https://reviews.llvm.org/D79637
2020-05-09 09:11:00 -07:00
sameeran joshi 332e6aea37 [flang]Semantics for SELECT RANK.
Summary:
    Initially on github I worked on semantic checks.Then I tried some compile-time
    test of the rank value, they were failing as there were no symbols
    generated for them inside SELECT RANK's scope.So I went further to
    add new symbol in each scope, also added the respective 'rank: '
    field for a symbol when we dump the symboltable. I added a field to
    keep track of the rank in AssocEntityDetails class.This caused shape
    analysis framework to become inconsistent. So shape analysis framework
    was updated to handle this new representation.

	 *   I added more tests for above changes.

	 *   On phabricator I addressed some minor changes.

	 *   Lastly I worked on review comments.

    Reviewers: klausler,sscalpone,DavidTruby,kiranchandramohan,tskeith,anchu-rajendran,kiranktp

    Reviewed By:klausler, DavidTruby, tskeith

    Subscribers:#flang-commits, #llvm-commits

    Tags: #flang, #llvm

    Differential Revision: https://reviews.llvm.org/D78623
2020-05-08 08:52:31 +05:30
Jacques Pienaar 5eae715a31 [mlir] Add NamedAttrList
This is a wrapper around vector of NamedAttributes that keeps track of whether sorted and does some minimal effort to remain sorted (doing more, e.g., appending attributes in sorted order, could be done in follow up). It contains whether sorted and if a DictionaryAttr is queried, it caches the returned DictionaryAttr along with whether sorted.

Change MutableDictionaryAttr to always return a non-null Attribute even when empty (reserve null cases for errors). To this end change the getter to take a context as input so that the empty DictionaryAttr could be queried. Also create one instance of the empty dictionary attribute that could be reused without needing to lock context etc.

Update infer type op interface to use DictionaryAttr and use NamedAttrList to avoid incurring multiple conversion costs.

Fix bug in sorting helper function.

Differential Revision: https://reviews.llvm.org/D79463
2020-05-07 12:33:36 -07:00
sameeran joshi cc4768f2ec [flang]Add examples in documentation/BijectiveInternalNameUniquing.md
Summary:
    I thought it would be simpler to understand on how the unique names would
    look like when an example is present. So I added some examples.

    I found 2 such places to add examples
    -Common blocks
    -Module scope global data

    Reviewers: schweitz, kiranchandramohan, sscalpone, jeanPerier, jdoerfert, DavidTruby

    Reviewed By: schweitz, jeanPerier

    Subscribers: llvm-commits, flang-commits

    Tags: #flang, #llvm

    Differential Revision: https://reviews.llvm.org/D79442
2020-05-08 00:01:35 +05:30
Tim Keith 7ccc7e5672 [flang] Fix to IsDescriptor
IsDescriptor was returning false for a component whose shape depended
on a length parameter. Change it to return true for any array with
non-constant bounds.

Differential Revision: https://reviews.llvm.org/D79349
2020-05-07 07:51:45 -07:00
Tim Keith 54b35c0664 [flang][NFC] Replace "align" with "alignment"
In the places it is used as a noun, replace "align" with "alignment".

Differential Revision: https://reviews.llvm.org/D79520
2020-05-06 15:03:30 -07:00
Pete Steinfeld 07b69dcf66 [flang] Response to Steve Scalpone's suggestion to improve a message
Summary: I updated the code that produces the message and the associated test.

Reviewers: sscalpone, DavidTruby, kiranchandramohan

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79514
2020-05-06 15:00:53 -07:00
Pete Steinfeld cfce9b6760 [flang] Response to Steve Scalpone's suggestion to improve a message
Summary: I updated the code that produces the message and the associated test.

Reviewers: sscalpone, DavidTruby

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79514
2020-05-06 12:28:21 -07:00
Tim Keith d5c05ced82 [flang][NFC] Add accessors to equivalence and common blocks
Add a way to get mutable equivalence sets to Scope so that they can
have sizes and offsets assigned to them.

Change CommonBlockDetails to have mutable symbols so that they can have
sizes and offets assigned to them. This also allows the removal of some
`const_cast`s.

Add MutableSymbolRef and MutableSymbolVector as mutable analogs to
SymbolRef and SymbolVector. Replace uses of equivalent types with those
names.

Differential Revision: https://reviews.llvm.org/D79346
2020-05-06 12:22:28 -07:00
Tim Keith 237d0e3c04 [flang] Handle EQUIVALENCE and COMMON in size and offset computations
Objects in common blocks have offsets relative to the start of the
common block, independent of the enclosing scope, so they are processed
first. Add alignment to CommonBlockDetails to record the required
alignment of the common block.

For equivalence sets, each object depends on the one that is forced to
occur first in memory. The rest are recorded in the dependents_ map and
have offsets assigned after the other symbols are done.

Differential Revision: https://reviews.llvm.org/D79347
2020-05-06 11:45:28 -07:00
Tim Keith 0195b3a909 [flang] Fix bug in tests for standalone build
When doing a standalone build of flang against an LLVM that contains a
built flang, the tests were run on the flang from LLVM rather than on
the one that was just built.

The problem was in the lit configuration for finding %flang etc.
Fix it to look only in the directory where it was built.

Differential Revision: https://reviews.llvm.org/D79327
2020-05-05 11:08:23 -07:00
Pete Steinfeld 8d0c3c05f2 [flang] New implementation for checks for constraints C741 through C750
Summary:
Most of these checks were already implemented, and I just added references to
them to the code and tests. Also, much of this code was already
reviewed in the old flang/f18 GitHub repository, but I didn't get to
merge it before we switched repositories.

I implemented the check for C747 to not allow coarray components in derived
types that are of type C_PTR, C_FUNPTR, or type TEAM_TYPE.

I implemented the check for C748 that requires a data component whose type has
a coarray ultimate component to be a nonpointer, nonallocatable scalar and not
be a coarray.

I implemented the check for C750 that adds additional restrictions to the
bounds expressions of a derived type component that's an array.
These bounds expressions are sepcification expressions as defined in
10.1.11.  There was already code in lib/Evaluate/check-expression.cpp to
check semantics for specification expressions, but it did not check for
the extra requirements of C750.

C750 prohibits specification functions, the intrinsic functions
ALLOCATED, ASSOCIATED, EXTENDS_TYPE_OF, PRESENT, and SAME_TYPE_AS. It
also requires every specification inquiry reference to be a constant
expression, and requires that the value of the bound not depend on the
value of a variable.

To implement these additional checks, I added code to the intrinsic proc
table to get the intrinsic class of a procedure.  I also added an
enumeration to distinguish between specification expressions for
derived type component bounds versus for type parameters.  I then
changed the code to pass an enumeration value to
"CheckSpecificationExpr()" to indicate that the expression was a bounds
expression and used this value to determine whether to emit an error
message when violations of C750 are found.

I changed the implementation of IsPureProcedure() to handle statement
functions and changed some references in the code that tested for the
PURE attribute to call IsPureProcedure().

I also fixed some unrelated tests that got new errors when I implemented these
new checks.

Reviewers: tskeith, DavidTruby, sscalpone

Subscribers: jfb, llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D79263
2020-05-05 09:37:39 -07:00
Stephen Neuendorffer f432154d1b [flang] update tools/f18 to use LLVM_LINK_COMPONENTS.
This will prevent conflicts with libLLVM.so when using LLVM_LINK_LLVM_DYLIB=on.

Differential Revision: https://reviews.llvm.org/D79370
2020-05-05 08:55:17 -07:00
peter klausler 6fec2c4402 [flang] Fix x87 binary->decimal
Summary:
Fix decimal formatting of 80-bit x87 values; the calculation ofnearest neighbor values failed to account for the explicitmost significant bit in that format.

Replace MultiplyByRounded with MultiplyBy in binary->decimal conversions,
since rounding won't happen and the name was misleading; then remove
dead code, and migrate LoseLeastSignificantDigit() from one source file
to another where it's still needed.

Reviewers: tskeith, sscalpone, jdoerfert, DavidTruby

Reviewed By: tskeith

Subscribers: llvm-commits, flang-commits

Tags: #flang, #llvm

Differential Revision: https://reviews.llvm.org/D79345
2020-05-04 12:04:08 -07:00
Pete Steinfeld b6f1bad630 [flang] Fixed a crash
Summary:
I found a small test case that caused a crash when derived type
definitions have parameters without definitions.

Reviewers: tskeith, klausler, DavidTruby

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D79282
2020-05-04 07:54:23 -07:00
River Riddle 1165a35a73 [IndexedAccessorRange] Only offset the base if the index is non-zero.
This is more efficient and removes the need for derived ranges to handle the degenerate empty case.
2020-05-01 11:56:39 -07:00
Eric Schweitz d93ae65253 [flang] Add the header file for the conversion of FIR(MLIR) to LLVM-IR dialect
Summary:
This is the interface to the conversion pass that converts the FIR dialect (and standard dialects) of MLIR to the LLVM-IR dialect. The implementation of this bridge will be forthcoming in subsequent diffs.

The purpose of the code gen bridge is to take the IR, which will be expressed as a mix of higher-level Fortran constructs as expressed in the FIR dialect and the MLIR standard dialect, and convert the representation into the LLVM-IR dialect. At that point, the LLVM-IR dialect can be converted into LLVM IR (proper) by a standard MLIR pass.

Reviewers: jeanPerier, vjayathirtha-nv, sscalpone, jdoerfert, DavidTruby, kiranchandramohan

Reviewed By: sscalpone, kiranchandramohan

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D79177
2020-04-30 11:45:39 -07:00
Eric Schweitz 7875362986 [flang] Add the proposal document and rationale for the internal naming module that was previously added.
Summary:
This document describes how uniquing of internal names is done. This
name uniquing is done to support the constraints and invariants of the FIR
dialect of MLIR.

Reviewers: jeanPerier, mehdi_amini, DavidTruby, jdoerfert, sscalpone, kiranchandramohan

Reviewed By: jeanPerier, sscalpone, kiranchandramohan

Subscribers: tskeith, kiranchandramohan, rriddle, llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D79089
2020-04-30 11:32:01 -07:00
River Riddle 0752d98ccf [mlir] Simplify BranchOpInterface by using MutableOperandRange
This range allows for performing many different operations on successor operands, including erasing/adding/setting. This removes the need for the explicit canEraseSuccessorOperand and eraseSuccessorOperand methods.

Differential Revision: https://reviews.llvm.org/D79077
2020-04-29 16:48:15 -07:00
Rainer Orth 3119bdb5d6 [Flang][CMake] Add explicit libFortranCommon dependency for f18 etc.
When I tried Solaris builds with `-DBUILD_SHARED_LIBS=ON`, some commands failed
to link:

  [ 94%] Linking CXX executable ../../../../bin/f18
  Undefined                       first referenced
   symbol                             in file
  Fortran::common::IntrinsicTypeDefaultKinds::set_sizeIntegerKind(int) CMakeFiles/f18.dir/f18.cpp.o  (symbol belongs to implicit dependency /var/llvm/local-amd64-release-shared-gcc8-make/lib/libFortranCommon.so.11git)
  Fortran::common::IntrinsicTypeDefaultKinds::set_subscriptIntegerKind(int) CMakeFiles/f18.dir/f18.cpp.o  (symbol belongs to implicit dependency /var/llvm/local-amd64-release-shared-gcc8-make/lib/libFortranCommon.so.11git)
  Fortran::common::EnumIndexToString[abi:cxx11](int, char const*) CMakeFiles/f18.dir/f18.cpp.o  (symbol belongs to implicit dependency /var/llvm/local-amd64-release-shared-gcc8-make/lib/libFortranCommon.so.11git)
  Fortran::common::IntrinsicTypeDefaultKinds::set_defaultIntegerKind(int) CMakeFiles/f18.dir/f18.cpp.o  (symbol belongs to implicit dependency /var/llvm/local-amd64-release-shared-gcc8-make/lib/libFortranCommon.so.11git)
  Fortran::common::IntrinsicTypeDefaultKinds::IntrinsicTypeDefaultKinds() CMakeFiles/f18.dir/f18.cpp.o  (symbol belongs to implicit dependency /var/llvm/local-amd64-release-shared-gcc8-make/lib/libFortranCommon.so.11git)
  Fortran::common::IntrinsicTypeDefaultKinds::set_defaultRealKind(int) CMakeFiles/f18.dir/f18.cpp.o  (symbol belongs to implicit dependency /var/llvm/local-amd64-release-shared-gcc8-make/lib/libFortranCommon.so.11git)
  ld: fatal: symbol referencing errors

This patch fixes this by adding explicit dependencies on `libFortranCommon`
to the affected commands.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86-64-pc-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D78761
2020-04-28 13:28:41 +02:00
Alex Zinenko bb1d976feb [mlir][flang] use OpBuilder& instead of Builder* in <Op>::build methods
As we start defining more complex Ops, we increasingly see the need for
Ops-with-regions to be able to construct Ops within their regions in
their ::build methods. However, these methods only have access to
Builder, and not OpBuilder. Creating a local instance of OpBuilder
inside ::build and using it fails to trigger the operation creation
hooks in derived builders (e.g., ConversionPatternRewriter). In this
case, we risk breaking the logic of the derived builder. At the same
time, OpBuilder::create, which is by far the largest user of ::build
already passes "this" as the first argument, so an OpBuilder instance is
already available.

Update all ::build methods in all Ops in MLIR and Flang to take
"OpBuilder &" instead of "Builder *". Note the change from pointer and
to reference to comply with the common style in MLIR, this also ensures
all other users must change their ::build methods.

Differential Revision: https://reviews.llvm.org/D78713
2020-04-28 10:42:08 +02:00
Eric Schweitz bc0342383d [flang] Upstream recent work on FIR to llvm-project.
Summary:

Reviewers: DavidTruby, sscalpone, jeanPerier

Subscribers: mgorny, aartbik, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78835
2020-04-27 17:48:57 -07:00
River Riddle 7c221a7d4f [mlir][Symbol] Change Symbol from a Trait into an OpInterface.
This provides a much cleaner interface into Symbols, and allows for users to start injecting op-specific information. For example, derived op can now inject when a symbol can be discarded if use_empty. This would let us drop unused external functions, which generally have public visibility.

This revision also adds a new `extraTraitClassDeclaration` field to ODS OpInterface to allow for injecting declarations into the trait class that gets attached to the operations.

Differential Revision: https://reviews.llvm.org/D78522
2020-04-27 13:04:49 -07:00
Alexander Belyaev ed5363a674 [MLIR] Add getBody() method to SingleImplicitBlockTerminator op trait.
Many ops with this trait have `getBody()` and `getBodyBuilder()` methods defined in `extraClassDeclaration` in tablegen. `getBody()` implementation is the same accross all these ops, but `getBodyBuilder()` can return builders with varying insertion points set. In this PR, `getBody()` is moved into `SingleImplicitBlockTerminator` struct and `getBodyBuilder()` is replaced with `OpBuilder::atBlock(End|Terminator)(op.getBody);`.

Differential Revision: https://reviews.llvm.org/D78864
2020-04-27 21:48:52 +02:00
David Truby 52492e6c43 [flang][NFC] Fix gcc 9 warning in omp combined construct checks. 2020-04-27 17:59:06 +01:00
David Truby 75c31057a7 [flang] Semantic checks for OpenMP combined constructs.
Summary:
This includes a refactor of the existing combined construct checks
that were present, as well as adding the remaining combined constructs
that had not been implemented yet.

Reviewers: jdoerfert

Subscribers: yaxunl, guansong, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77812
2020-04-27 12:40:49 +01:00
David Truby b547e1a4d1 [flang] Fix handling of files without terminating newlines.
Reviewers: sscalpone

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78578
2020-04-27 12:40:22 +01:00
sameeran joshi 807fe05d35 [flang][docs] Doxygen support in flang.
Summary:
    Added support for doxygen-style documentation generation from source code.
    Added -DLLVM_ENABLE_DOXYGEN=ON -DFLANG_INCLUDE_DOCS=ON flags to cmake.
    Added the target doxygen-flang for building doxygen
    Updated README.txt

    Reviewers: DavidTruby, richard.barton.arm, sscalpone,  mehdi_amini, jdoerfert

    Reviewed By: DavidTruby, richard.barton.arm, sscalpone

    Previous review: https://github.com/flang-compiler/f18/pull/1065

    Differential Revision: https://reviews.llvm.org/D78136
2020-04-27 15:02:29 +05:30
peter klausler 3a1afd8c3d Rework DATA statement semantics to use typed expressions
Summary:
Updates recent work on DATA statement semantic checking in
flang/lib/Semantics/check-data.{h,cpp} to use the compiler's
internal representation for typed expressions rather than working
on the raw parse tree.  Saves the analyzed expressions for DATA
statement values as parse tree decorations because they'll soon be
needed in lowering.  Corrects wording of some error messages.

Fixes a bug in constant expression checking: structure constructors
are not constant expressions if they set an allocatable component
to anything other than NULL.

Includes infrastructure changes to make this work, some renaming
to reflect the fact that the implied DO loop indices tracked by
expression analysis are not (just) from array constructors, remove
some dead code, and improve some comments.

Reviewers: tskeith, sscalpone, jdoerfert, DavidTruby, anchu-rajendran, schweitz

Reviewed By: tskeith, anchu-rajendran, schweitz

Subscribers: llvm-commits, flang-commits

Tags: #flang, #llvm

Differential Revision: https://reviews.llvm.org/D78834
2020-04-25 10:29:34 -07:00
Eric Schweitz 5339029ff7 [flang] Support for making unique internal names.
Differential Revision: https://reviews.llvm.org/D78838
2020-04-24 17:27:31 -07:00
peter klausler fc0262419a [flang] More CHARACTER runtime support + unit test
Summary:
This is a continuation of development of the runtime support library's functions for
CHARACTER data; specifically, it implements CHARACTER comparisons.
It includes a new unit test, and moves an #include directive to the
runtime's unit testing main header.

Reviewers: tskeith, sscalpone, DavidTruby, jdoerfert

Reviewed By: tskeith

Subscribers: flang-commits, mgorny, llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D78826
2020-04-24 14:34:51 -07:00
Tim Keith c353ebbfa4 [flang] Compute sizes and offsets for symbols
Summary:
Add size and offset properties to symbols, representing their byte size
and offset within their enclosing scope.

Add size and align properties to scopes so that they are available for
scopes representing derived types.

Add ComputeOffsets pass over the symbol table to fill in those fields.

Compute descriptor size based on rank and length parameters. Extract
DerivedTypeSpec::NumLengthParameters from DynamicType::RequiresDescriptor
to share the code.

Add Scope::GetSymbols to get symbols in canonical order.
compute-offsets.cpp and mod-file.cpp both need to process symbols in the
order in which they are declared. Move the collecting of those symbols
into Scope so that it can be shared.

Add symbol size and offset to output of `-fdebug-dump-symbols` and use
that in some tests.

Still to do:
- make size and alignment rules configurable based on target
- use offsets to check EQUIVALENCE statements

Differential Revision: https://reviews.llvm.org/D78680
2020-04-23 14:54:34 -07:00
Tim Keith 4ced7a48e6 [flang] Remove unused variable
Reviewers: sscalpone, jdoerfert, DavidTruby

Reviewed By: sscalpone

Subscribers: llvm-commits

Tags: #flang, #llvm

Differential Revision: https://reviews.llvm.org/D78725
2020-04-23 09:22:14 -07:00
Tim Keith 9623003e93 [flang][NFC] Refactor derived type instantiation
Summary:
Move InstantiateComponent and InstantiateIntrinsicType from symbol.cpp
to type.cpp as that is where they are called.

Put both in InstantiateHelper class to better isolate them.
Add CreateDerivedTypeSpec in InstantiateHelper.

Add non-const forms for AsIntrinsic and AsDerived to avoid const_cast.

No functional changes.

Reviewers: DavidTruby, klausler, PeteSteinfeld, jdoerfert

Reviewed By: klausler

Subscribers: llvm-commits

Tags: #flang, #llvm

Differential Revision: https://reviews.llvm.org/D78678
2020-04-23 08:29:47 -07:00
Tim Keith 026d8807f4 [flang] Add missing check for unresolved name
Summary:
The name in an InputItem isn't necessarily resolved if an error occurred,
so it needs to be checked.

Fixes https://bugs.llvm.org/show_bug.cgi?id=45477

Reviewers: klausler, PeteSteinfeld, DavidTruby, jdoerfert, sscalpone

Reviewed By: klausler, sscalpone

Subscribers: llvm-commits

Tags: #llvm, #flang

Differential Revision: https://reviews.llvm.org/D78685
2020-04-23 07:00:38 -07:00
Valentin Clement a6c1692cb3 [Flang] fix dependency issues after D78215
Patch D78215 changes various dependencies in the CMakeLists.txt. This
results in error while compiling. This patch fixes the issue.

Reviewers: DavidTruby

Differential Revision: https://reviews.llvm.org/D78340
2020-04-21 20:32:11 +01:00
Rainer Orth 0535fab237 [Flang][test] Don't set PATH in flang/test/Semantics/common.sh
Currently, many `Flang :: Semantics` tests FAIL on Solaris.  The failure
mode is always the same:

  actual at 67: Name in ALLOCATE statement must be a variable name
  expect at 67: ERROR: Name in ALLOCATE statement must be a variable name

It turns out the issue is twofold here:

- The awk script embedded in `flang/test/Semantics/common.sh` uses a string
  value for `FS`, which isn't supported by traditional awk as documented in
  the GNU autoconf manual.

- Even though /usr/gnu/bin (with gawk installed as awk) is in my build
  environment's `PATH`, still /bin/awk is used

Although the proper fix would probably be to avoid the unportability, it's
easy to work around it for now.  `common.sh` above is the only script in
the whole tree that for unknown reasons overrides `PATH` to
`/usr/bin:/bin`, unnecessarily creating this mess in the first place.  Just
removing that setting easily avoids the issue.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D78550
2020-04-21 14:32:57 +02:00
Anchu Rajendran c1c01212c4 [flang]Implemented Semantic Checkes for 5 data constraints
Summary:
 C874, C875, C878, C880 and C881 checks are implemented.

Differential Revision: https://reviews.llvm.org/D78008
2020-04-18 12:21:30 +05:30
Mehdi Chinoune 2d6b9dbfef [flang] Use the Flang cmake-functions to add targets.
Summary: It also removes the cycle-dependency between FortranSemantics and FortranEvaluate.

Reviewers: #flang, jdoerfert, sscalpone

Reviewed By: #flang, sscalpone

Subscribers: DavidTruby, schweitz, tskeith, mgorny, aartbik, llvm-commits

Tags: #flang, #llvm

Differential Revision: https://reviews.llvm.org/D78215
2020-04-16 15:51:30 +01:00
David Truby 29e71ceaee [flang] Add return statement to Logical opeator=.
This removes the current undefined behavior where the function has a return type
but no return statement.

Fixes: https://bugs.llvm.org/show_bug.cgi?id=45530
2020-04-15 13:18:42 +01:00
River Riddle ebf190fcda [llvm][ADT] Move TypeSwitch class from MLIR to LLVM
This class implements a switch-like dispatch statement for a value of 'T' using dyn_cast functionality. Each `Case<T>` takes a callable to be invoked if the root value isa<T>, the callable is invoked with the result of dyn_cast<T>() as a parameter.

Differential Revision: https://reviews.llvm.org/D78070
2020-04-14 15:14:41 -07:00
River Riddle 2f21a57966 [llvm][STLExtras] Move the algorithm `interleave*` methods from MLIR to LLVM
These have proved incredibly useful for interleaving values between a range w.r.t to streams. After this revision, the mlir/Support/STLExtras.h is empty. A followup revision will remove it from the tree.

Differential Revision: https://reviews.llvm.org/D78067
2020-04-14 15:14:40 -07:00
Eric Schweitz d58a405de6 [flang] Upstream patch to enable the fir-ops test. bug 45487
Differential revision: https://reviews.llvm.org/D77834
2020-04-14 10:02:04 -07:00
Mehdi Amini ed6c452edc Add missing dependencies on the flang test target
Without this, the LLVM utilities (FileCheck) aren't built when running
`ninja check-flang` and it fails with:

llvm-project/llvm/utils/lit/lit/llvm/subst.py:134: fatal: Did not find FileCheck in...

Also the modules aren't built without depending on `module_files`, which
makes multiple tests failing.

Differential Revision: https://reviews.llvm.org/D78036
2020-04-13 18:23:01 +00:00
David Truby 413467f9ec [flang] [NFC] Adjust README.md for upstreaming.
This changes the references and build instructions for Flang so that
they are correct now that F18 has been rechristened Flang and merged
with LLVM.

Reviewed at: https://github.com/flang-compiler/f18/pull/909
2020-04-09 21:15:48 +01:00
David Truby 89c7d9633b [flang] Temporarily XFAIL failing test Fir/fir-ops.fir 2020-04-09 18:36:17 +01:00
David Truby a1726e65bc [flang] Add dependency on libSemantics to libEvaluate.
When building flang with LLVM HEAD, the unittests fail to link with ld.bfd or
ld.gold due to a linker ordering issue. Adding libSemantics as a dependency to
libEvaluate seems to fix that issue.

Reviewed at: https://github.com/flang-compiler/f18/pull/1104
2020-04-09 16:41:36 +01:00
David Truby 55d5e6cbe2 [flang] Remove flatten and merge upstreaming script.
Original-commit: flang-compiler/f18@21f3c455e8
2020-04-09 15:54:31 +01:00
David Truby 2d65baf845 [flang] Adjust README.md for upstreaming to LLVM.
Original-commit: flang-compiler/f18@24d23963b8
2020-04-09 15:54:26 +01:00
Tim Keith 0bd73f2c38 [flang] Convert std::uint64_t to std::uintmax_t as well
Original-commit: flang-compiler/f18@92a1ef6810
Reviewed-on: https://github.com/flang-compiler/f18/pull/1101
2020-04-06 10:06:34 -07:00
Tim Keith 76d71354db [flang] Add message formatting for std::int64_t
There is no printf formatting string for std::int64_t. Instead we have
to cast to std::intmax_t and use `%jd`. This change simplifies that by
automatically converting std::int64_t to std::intmax_t when formatting
messages.

Original-commit: flang-compiler/f18@8a2343dfff
Reviewed-on: https://github.com/flang-compiler/f18/pull/1101
Tree-same-pre-rewrite: false
2020-04-03 17:28:23 -07:00
Caroline Concatto 5c7ecef1e4 [flang] Adjust supported compilers statement in F18 readme
This patch is an update of the readme according to compilations done and
also information given in flang dev mailing list.
[F18] Which compilers configurations f18 have being tested/built?

Signed-off-by: Caroline Concatto <caroline.concatto@arm.com>

Original-commit: flang-compiler/f18@3749b463dc
Reviewed-on: https://github.com/flang-compiler/f18/pull/1087
2020-04-06 16:33:12 +01:00
peter klausler 455ed8de4f [flang] Process names in ASSIGN and assigned GOTO
Allow ASSIGNed integer variables as formats

Address review comment

Original-commit: flang-compiler/f18@361a151508
Reviewed-on: https://github.com/flang-compiler/f18/pull/1099
2020-04-03 14:58:07 -07:00
peter klausler 4d54bb7af8 [flang] Define CHARACTER runtime API, establish placeholder implementations
formatting

Original-commit: flang-compiler/f18@1d287d9d59
Reviewed-on: https://github.com/flang-compiler/f18/pull/1096
2020-04-02 09:38:25 -07:00
Pete Steinfeld 2b790490b6 [flang] Checks for constraints C731 through C740
In most cases, I just added the contraint names to the code and tests.

I implemented the following checks:
  - C736 A child type with a coarray ultimate component must have a parent with
    a coarray ultimate component.
  - C737 A child type with and EVENT_TYPE or LOCK_TYPE component must have a
    parent either which is EVENT_TYPE or LOCK_TYPE or a type with an EVENT_TYPE
    or LOCK_TYPE component.
  - C740 Sequence types must contain at least on component
  - C740 Data components of sequence types must either be of an intrinsic type
    or a sequenced derived type.

After implementing these checks, some tests had new errors unrelated to their
original purpose, so I fixed them.

Original-commit: flang-compiler/f18@098f01bc47
Reviewed-on: https://github.com/flang-compiler/f18/pull/1097
2020-04-02 06:41:33 -07:00
Tim Keith 1f8790050b [flang] Reformat with latest clang-format and .clang-format
Original-commit: flang-compiler/f18@9fe84f45d7
Reviewed-on: https://github.com/flang-compiler/f18/pull/1094
2020-03-28 21:00:16 -07:00
Isuru Fernando ea5efd1ea8 [flang] Support platforms without strerror_r
Original-commit: flang-compiler/f18@0575b54cc7
Reviewed-on: https://github.com/flang-compiler/f18/pull/1068
2020-03-28 16:46:43 -05:00
Isuru Fernando ddb68d248c [flang] Support windows where mkstemp and ftruncate doesn't exist
Original-commit: flang-compiler/f18@7b7e30845d
Reviewed-on: https://github.com/flang-compiler/f18/pull/1069
2020-03-28 15:07:03 -05:00
peter klausler 84a099df05 [flang] Fix missing substring bounds (bug flang-compiler/f18#1091)
Original-commit: flang-compiler/f18@3b0c150b2e
Reviewed-on: https://github.com/flang-compiler/f18/pull/1093
2020-03-27 14:17:25 -07:00
peter klausler 7a77c20dbd [flang] Semantics for SELECT CASE
Prep for review

Respond to review comments

Fix first line in new test

Original-commit: flang-compiler/f18@12f6f30600
Reviewed-on: https://github.com/flang-compiler/f18/pull/1089
2020-03-27 12:02:11 -07:00
Steve Scalpone 282358fac9 [flang] [mlir rebase] Add MLIR config and react to MLIR name changes (flang-compiler/f18#1090)
[mlir rebase] Add MLIR config and react to MLIR name changes

Similar to flang-compiler/f18#1085.  Now use the MLIR package to set up paths for include files and libraries.  Three MLIR names changed:
 * VectorOpsDialect to VectorDialect
 * AffineOpsDialect to AffineDialect
 * createVectorizePass to createSuperVectorizePass

Update README.md to explain how to link with MLIR. Update the example gcc to version 8.3.

Update drone.io config to define -DMLIR_DIR

Co-authored-by: Jean Perier <jperier@nvidia.com>

Original-commit: flang-compiler/f18@116f64315f
Reviewed-on: https://github.com/flang-compiler/f18/pull/1090
2020-03-27 09:23:32 -07:00
Patrick McCormick 6c16aa4f67 [flang] A rework of the cmake build components for in and out of tree builds.
In general all the basic functionality seems to work and removes some redundancy
and more complicated features in favor of borrowing infrastructure from LLVM
build configurations. Here's a quick summary of details and remaining issues:

  * Testing has spanned Ubuntu 18.04 & 19.10, CentOS 7, RHEL 8, and
    MacOS/darwin.  Architectures include x86_64 and Arm.  Without
    access to Window nothing has been tested there yet.

  * As we change file and directory naming schemes (i.e.,
    capitalization) some odd things can occur on MacOS systems with
    case preserving but not case senstive file system configurations.
    Can be painful and certainly something to watch out for as any
    any such changes continue.

  * Testing infrastructure still needs to be tuned up and worked on.
    Note that there do appear to be cases of some tests hanging (on
    MacOS in particular).  They appear unrelated to the build
    process.

  * Shared library configurations need testing (and probably fixing).

  * Tested both standalone and 'in-mono repo' builds.  Changes for
    supporting the mono repo builds will require LLVM-level changes that
    are straightforward when the time comes.

  * The configuration contains a work-around for LLVM's C++ standard mode
    passing down into Flang/F18 builds (i.e., LLVM CMake configuration would
    force a -std=c++11 flag to show up in command line arguments.  The
    current configuration removes that automatically and is more strict in
    following new CMake guidelines for enforcing C++17 mode across all the
    CMake files.

  * Cleaned up a lot of repetition in the command line arguments.  It
    is likely that more work is still needed to both allow for
    customization and working around CMake defailts (or those
    inherited from LLVM's configuration files). On some platforms agressive
    optimization flags (e.g. -O3) can actually break builds due to the inlining
    of templates in .cpp source files that then no longer are available for use
    cases outside those source files (shows up as link errors).   Sticking at -O2
    appears to fix this.  Currently this CMake configuration forces this in
    release mode but at the cost of stomping on any CMake, or user customized,
    settings for the release flags.

  * Made the lit tests non-source directory dependent where appropriate. This is
    done by configuring certain test shell files to refer to the correct paths
    whether an in or out of tree build is being performed. These configured
    files are output in the build directory. A %B substitution is introduced in
    lit to refer to the build directory, mirroring the %S substitution for the
    source directory, so that the tests can refer to the configured shell scripts.

Co-authored-by: David Truby <david.truby@arm.com>

Original-commit: flang-compiler/f18@d1c7184159
Reviewed-on: https://github.com/flang-compiler/f18/pull/1045
2020-03-26 18:17:04 +00:00
David Truby cc77f818f2 [flang] Add explicit nullptr check in initialisation of inDoConstruct.
This explicit check is needed as we are using braced initialisation here so
implicit narrowing conversions (such as pointer to bool) are not allowed.

Original-commit: flang-compiler/f18@ff8dad10bf
Reviewed-on: https://github.com/flang-compiler/f18/pull/1083
2020-03-25 18:37:31 +00:00
peter klausler c42f6314eb [flang] Semantics for ENTRY
initial test passes

Move some checks to check-declarations

Fix bugs found in testing

Get tests all passing

Allow declaration statements for function result to follow ENTRY

Fix another bug

Original-commit: flang-compiler/f18@e82cfee432
Reviewed-on: https://github.com/flang-compiler/f18/pull/1086
2020-03-24 14:30:34 -07:00
Pete Steinfeld e17e71735e [flang] Changes to enforce constraints C727 to C730 and most constraints related to attributes
The full list of constraints is C727, C728, C729, C730, C743, C755, C759, C778,
and C1543.

I added a function to tools.cpp to check to see if a symbol name is the name
of an intrinsic type.

The biggest change was to resolve-names.cpp to check to see if attributes were
either duplicated or in conflict with each other.  I changed all locations
where attributes were set to check for duplicates or conflicts.

I also added tests for all checks and annotated the tests and code with the
numbers of the constraints being tested/checked.

Original-commit: flang-compiler/f18@3f30e8a61e
Reviewed-on: https://github.com/flang-compiler/f18/pull/1084
2020-03-24 09:24:49 -07:00
David Truby 3214c18774 [flang] Remove non-alignment based divergences from LLVM formatting.
This only changs the clang-format file and adds documentation
referring to the new process for formatting code. A future commit
will perform a reformatting according to these new formatting
settings.

Original-commit: flang-compiler/f18@02531d788e
Reviewed-on: https://github.com/flang-compiler/f18/pull/945
2020-03-23 17:52:22 +00:00
David Truby 13ea73e42d [flang] Replace manual mmap with llvm::MemoryBuffer
The previous code had handling for cases when too many file descriptors may be
opened; this is not necessary with MemoryBuffer as the file descriptors are
closed after the mapping occurs. MemoryBuffer also internally handles the case
where a file is small and therefore an mmap is bad for performance; such files
are simply copied to memory after being opened.

Many places elsewhere in the code assume that the buffer is not empty, and the
old file opening code handles this by replacing an empty file with a buffer
containing a single newline. That behavior is now kept in the new MemoryBuffer
based code.

Original-commit: flang-compiler/f18@d34df84351
Reviewed-on: https://github.com/flang-compiler/f18/pull/1032
2020-03-24 13:35:01 +00:00
Caroline Concatto 8670e49901 [flang] [LLVMify F18] Replace the use std::ostream with LLVM streams llvm::ostream
This patch replaces the occurrence of std::ostream by llvm::raw_ostream.
In  LLVM Coding Standards[1] "All new code should use raw_ostream
instead of ostream".[1]

As a consequence, this patch also replaces the use of:
   std::stringstream by llvm::raw_string_ostream or llvm::raw_ostream*
   std::ofstream by llvm::raw_fd_ostream
   std::endl by '\n' and flush()[2]
   std::cout by llvm::outs()   and
   std::cerr by llvm::errs()

It also replaces  std::strerro by llvm::sys::StrError** , but NOT in  Fortran
runtime libraries

*std::stringstream were replaced by llvm::raw_ostream in all methods that
used std::stringstream as a parameter. Moreover, it removes the pointers to
these streams.

[1]https://llvm.org/docs/CodingStandards.html
[2]https://releases.llvm.org/2.5/docs/CodingStandards.html#ll_avoidendl

Signed-off-by: Caroline Concatto <caroline.concatto@arm.com>

Running clang-format-7

Signed-off-by: Caroline Concatto <caroline.concatto@arm.com>

Removing residue of ostream library

Signed-off-by: Caroline Concatto <caroline.concatto@arm.com>

Original-commit: flang-compiler/f18@a3507d44b8
Reviewed-on: https://github.com/flang-compiler/f18/pull/1047
2020-03-19 07:54:36 +00:00
peter klausler 9977b24a6d [flang] Improve error message for procedure passed as invalid argument to an intrinsic
Support forward references to sibling module procedures

Add tests, handle corner cases

Rename new test

Original-commit: flang-compiler/f18@234bb519cd
Reviewed-on: https://github.com/flang-compiler/f18/pull/1076
2020-03-18 14:04:08 -07:00
Tim Keith 61b1390e2a [flang] Check module subprogram against separate module procedure
When a module subprogram has the MODULE prefix the following must match
with the corresponding separate module procedure interface body:
- C1549: characteristics and dummy argument names
- C1550: binding label
- C1551: NON_RECURSIVE prefix

SubprogramMatchHelper performs all of these checks.

Rename separate-module-procs.f90 to separate-mp01.f90 so we can have
separate-mp02.f90 (etc).

Make ShapesAreCompatible public in characteristics.h.

Add Scope::IsSubmodule.

Original-commit: flang-compiler/f18@d121578af1
Reviewed-on: https://github.com/flang-compiler/f18/pull/1080
2020-03-17 16:01:59 -07:00
Tim Keith 824d198e31 [flang] Create symbols for args of separate-module-subprogram
A separate-module-subprogram is declared as `module procedure ...`
and gets its characteristics from the declaration of that name as
a separate module procedure. When we encounter one, we need to create
symbols in the new subprogram scope for the dummy arguments and
function return (if any).

The failure to create these symbols led to the bug in issue flang-compiler/f18#1054:
when a dummy argument was referenced, the compiler interpreted it as
an implicit declaration because there was no symbol for the argument.

Fixes flang-compiler/f18#1054.

Original-commit: flang-compiler/f18@4d3c4bac84
Reviewed-on: https://github.com/flang-compiler/f18/pull/1080
Tree-same-pre-rewrite: false
2020-03-17 16:01:59 -07:00
Tim Keith d1ce4d275f [flang] Fix location of name of Symbol for ProcEntity
When we encounter a ProcDecl and a symbol for it has already been
created, replace the CharBlock for the name with the one in the ProcDecl
as it is the "main" declaration of that name. This matches what is done
for an EntityDecl.

This moves the location of some error messages to a better source
location so update the affected tests.

Original-commit: flang-compiler/f18@514c0f2c94
Reviewed-on: https://github.com/flang-compiler/f18/pull/1080
Tree-same-pre-rewrite: false
2020-03-17 16:01:59 -07:00
peter klausler f4faeefe3d [flang] Do not emit a prefix for a default-kind character constant in AsFortran
Original-commit: flang-compiler/f18@4a3db55727
Reviewed-on: https://github.com/flang-compiler/f18/pull/1078
2020-03-17 12:35:31 -07:00
Tim Keith 6905526a10 [flang] Test cleanup
Fix omp-nested01.f90 so that it is not an expected failure. The test was
never enabled but I'm guessing this is what it's supposed to do.

Fix the instructions to include "make test" as part of running tests.

Original-commit: flang-compiler/f18@c351181cab
Reviewed-on: https://github.com/flang-compiler/f18/pull/1075
2020-03-16 10:46:17 -07:00
peter klausler 2bd473de82 [flang] more edits
Remove AllocateDefaultCharacter

Refinements in code review

Original-commit: flang-compiler/f18@688512ddc6
Reviewed-on: https://github.com/flang-compiler/f18/pull/1070
2020-03-16 09:57:12 -07:00
peter klausler 38ebace5b7 [flang] Complete formatting of pointer assignments, move to formatting.cpp with rest of AsFortran
Original-commit: flang-compiler/f18@9625317ee8
Reviewed-on: https://github.com/flang-compiler/f18/pull/1073
2020-03-13 09:52:15 -07:00
Luke Ireland da9d002b18 [flang] Added CMakeLists changes, moved config and made test scripts compatible.
All Fortran tests are now run in lit, except Preprocessing tests flang-compiler/f18#1052
Preprocessing tests are a separate kind of test, so will be sorted out
later.

Original-commit: flang-compiler/f18@3f99d35f3d
Reviewed-on: https://github.com/flang-compiler/f18/pull/1027
2020-03-13 13:54:24 +00:00
Luke Ireland f1a8eae3b6 [flang] Port all remaining regression tests to lit
We have re-classified a subset of the regression tests as unit tests and
now we are porting the remaining ones.

Test discovery and running is now performed by lit rather than ctest.
The tests continue to use their original scripts with minor
modifications. Most of the changes were mechanical and so scripted.
A few changes were made by hand. Details

Manual:
  * modfile09-*.f90 tests depend on being run together as some tests have
    dependencies on modules created by other tests. This will need
     separating out when porting away from test_modfile.sh, but for now,
     added modfile09-*.f90 to the Inputs directory and added a single
     tests modfile09.f90 to hold the run line.
  * getdefinition03-a.f90 includes a non-test file getdefinition03-b.f90.
    Manually edited the former to find the latter in Inputs so as to add
    only one test.
  * Same pattern for getsymbols03-{a,b}.f90

Auto:
  * Remaining tests have a lit RUN line added to them based on the type
    of test they are.
  * Failing tests also have an XFAIL line added to them.
  * Generic tests have their pre-existing RUN lines replaced with the
    word "EXEC" to avoid conflict with the added lit RUN line.

Original-commit: flang-compiler/f18@63ec0af9f4
Reviewed-on: https://github.com/flang-compiler/f18/pull/1027
Tree-same-pre-rewrite: false
2020-03-13 11:58:11 +00:00
Luke Ireland ee5fa1f233 [flang] Create a separate directory for unittests
Some of the regression tests are C programs that act as test harnesses
for the compiler internals as opposed to being Fortran inputs to test
the compiler in action. The former style of tests are analog to LLVM's
unittests and will not use the lit framework.

Change-Id: I0ff10e23f66ff843e8fff4c35cfb6559b9dab762

Original-commit: flang-compiler/f18@2bfddbe8f8
Reviewed-on: https://github.com/flang-compiler/f18/pull/1027
Tree-same-pre-rewrite: false
2020-03-13 11:58:11 +00:00
Luke Ireland a9d9261cf3 [flang] Re-enable semantics/altreturn{02,03} tests
These tests were disabled due to https://github.com/flang-compiler/f18/issues/407.
Previously these tests caused F18 to crash as the feature was not fully
implemented.

The altreturn feature is now implemented, so these tests can be
re-enabled. altreturn03 tested some negative cases which F18 correctly
diagnoses. Modified that test to expect these new error messages. Also
make the later cases in the test reachable.

These tests can now be ported by the script to lit-style tests.

Change-Id: Ib336c10d55068d9a26fc2deb43ad052e74e73456

Original-commit: flang-compiler/f18@4de19d7ba2
Reviewed-on: https://github.com/flang-compiler/f18/pull/1027
Tree-same-pre-rewrite: false
2020-03-13 11:58:11 +00:00
Jean Perier f856a5526a [flang] Support latest LLVM head with FIR - MLIR SideEffects interface change
Include new .td after LLVM changes:
0ddba0bd59

Tested to work with LLVM head ecd3e678bb
from 2020-03-13 01:45 am PCT

Backwards compatible with previous known compatible heads at least back to
fde9d33f71 from 2020-03-10, so need to
update LLVM builds if they previously work with FIR.

Original-commit: flang-compiler/f18@45454587c9
Reviewed-on: https://github.com/flang-compiler/f18/pull/1071
2020-03-13 04:06:31 -07:00
Isuru Fernando 231fae9087 [flang] Need <algorithm> for std::min and std::max (flang-compiler/f18#1063)
Original-commit: flang-compiler/f18@d0f9ef7742
Reviewed-on: https://github.com/flang-compiler/f18/pull/1063
2020-03-12 10:52:29 -07:00
Eric Schweitz 324bab9bf4 [flang] fix typo (flang-compiler/f18#1067)
Original-commit: flang-compiler/f18@4cdc9f75e2
Reviewed-on: https://github.com/flang-compiler/f18/pull/1067
2020-03-12 10:25:22 -07:00
David Truby 232711df35 [flang] Added documentation explaining the use of std::list (flang-compiler/f18#988)
Original-commit: flang-compiler/f18@094f558907
Reviewed-on: https://github.com/flang-compiler/f18/pull/988
2020-03-12 09:38:59 -07:00
RichBarton-Arm 3064bdcce9 [flang] Add initial CODE_OWNERS file (flang-compiler/f18#1066)
Original-commit: flang-compiler/f18@e5f369d086
Reviewed-on: https://github.com/flang-compiler/f18/pull/1066
2020-03-12 08:15:20 -07:00
jeanPerier 57f536a448 [flang] Add Fortran IR (FIR) MLIR dialect implementation (flang-compiler/f18#1035)
Adds FIR library that implements an MLIR dialect to which Fortran
parse-tree will be lowered to.

FIR is defined and documented inside FIROps.td added in this commit.
It is possible to generate a more readable description FIRLangRef.md
from FIROps.td following the related instructions added to the README.md
by this commit.

This patch adds FIR definition and implementation that allow parsing,
printing, and verifying FIR. FIR transformations and lowering to Standard
and LLVM dialects are not part of this patch. The FIR verifiers are verifying
the basic properties of FIR operations in order to provide a sufficient
frame for lowering. Verifiers for more advanced FIR properties can be added
as needed.

Coarrays are not covered by FIR defined in this patch.

This patch also adds tco tool that is meant to process FIR input files and
drives transformations on it. The tco tool is used for testing.
In this patch, it is only used to demonstrate parsing/verifying/
and dumping FIR with round-trip tests.

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:

742edde572
and
2ff5524212

Changes on top of these original commits were made during this patch review.

Original-commit: flang-compiler/f18@30b428a51e
Reviewed-on: https://github.com/flang-compiler/f18/pull/1035
2020-03-11 21:47:22 -07:00
peter klausler 3b63571425 [flang] Use hash table for UnitMap, avoid C++ STL binary dependence
Scan FORMAT strings locally to avoid C++ binary runtime dependence when computing deepest parenthesis nesting

Remove a dependency on ostream from runtime

Remove remaining direct external references from runtime to C++ library binaries

Remove runtime dependences on lib/common

SetPos() and SetRec()

Instantiate templates for input

Begin input; rearrange locking, deal with CLOSE races

View()

Update error message in test to agree with compiler change

First cut at real input

More robust I/O runtime error handling

Debugging of REAL input

Add iostat.{h,cpp}

Rename runtime/numeric-* to runtime/edit-*

Move templates around, templatize integer output editing

Move LOGICAL and CHARACTER output from io-api.cpp to edit-output.cpp

Change pointer argument to reference

More list-directed input

Complex list-directed input

Use enum class Direction rather than bool for templates

Catch up with changes to master

Undo reformatting of Lower code

Use record number instead of subscripts for internal unit

Unformatted sequential backspace

Testing and debugging

Dodge bogus GCC warning

Add <cstddef> for std::size_t to fix CI build

Address review comments

Original-commit: flang-compiler/f18@50406b3496
Reviewed-on: https://github.com/flang-compiler/f18/pull/1053
2020-03-11 13:23:39 -07:00
Isuru Fernando 0a8a6cd921 [flang] Fix an ambiguous overload error
Original-commit: flang-compiler/f18@70fa71ff7b
Reviewed-on: https://github.com/flang-compiler/f18/pull/1029
2020-03-05 09:19:11 -06:00
peter klausler f7432ca7a6 [flang] Resolve known problems in shape analysis
Original-commit: flang-compiler/f18@ed2e4842d3
Reviewed-on: https://github.com/flang-compiler/f18/pull/1061
2020-03-11 13:17:03 -07:00
peter klausler 771c21c19f [flang] Repair C_LOC
Original-commit: flang-compiler/f18@dc1c95277d
Reviewed-on: https://github.com/flang-compiler/f18/pull/1061
Tree-same-pre-rewrite: false
2020-03-11 11:00:36 -07:00
peter klausler 886fb42ece [flang] Extend shape analysis to cope with ASSOCIATE construct entities better
Fix incomplete copy&paste

Another review comment addressed

Original-commit: flang-compiler/f18@a2e2593fa5
Reviewed-on: https://github.com/flang-compiler/f18/pull/1061
Tree-same-pre-rewrite: false
2020-03-10 16:46:25 -07:00
Isuru Fernando 59baf8b822 [flang] Rename EXTERN_C_END to FORTRAN_EXTERN_C_END
Since EXTERN_C_END is a macro defined in Windows system headers

Original-commit: flang-compiler/f18@4c6e5608ad
Reviewed-on: https://github.com/flang-compiler/f18/pull/1051
2020-03-06 00:51:41 -06:00
Tim Keith a40dbe7c41 [flang] Allow for vector subscript on LHS of assignment
Original-commit: flang-compiler/f18@38aefd41f0
Reviewed-on: https://github.com/flang-compiler/f18/pull/1062
2020-03-10 16:32:58 -07:00
Tim Keith 6ab50745c0 [flang] Fix scope accessibility check
The check for whether a private component is accessible was depending on
determining whether the source range of the current scope was within the
source range of the module that the component was declared in. This
could fail if the current scope was of kind `ImpliedDos` and had no
source range.

The fix is to add `Scope::Contains` to check the relationship by
traversing the parent links. These are created when the Scope is so are
always reliable. The source range of a scope is built up over time.

Original-commit: flang-compiler/f18@d787108637
Reviewed-on: https://github.com/flang-compiler/f18/pull/1060
2020-03-10 15:31:02 -07:00
peter klausler e03b20e66e [flang] Changes to get a clean build of f18 with latest clang
Prep for review

Original-commit: flang-compiler/f18@111f49061e
Reviewed-on: https://github.com/flang-compiler/f18/pull/1059
2020-03-10 13:12:52 -07:00
Tim Keith a0a1f519c0 [flang] Perform definability checks on LHS of assignment
If the pure context check succeeds, call `WhyNotModifiable` to verify
the LHS can be modified.

Detect assignment to whole assumed-size array.

Change `IsVariable` to return false for a parameter or a component or
array reference whose base it a parameter.

When analyzing an assignment statement, report an error if the LHS is
a constant expression. Otherwise it might get folded and when we detect
the problem later the error will be confusing.

Handle Substring on LHS of assignment. Change ExtractDataRef and IsVariable
to work on a Substring.

Fix IsImpliedShape and IsAssumedSize predicates in ArraySpec.

Fix C709 check in check-declarations.cpp.

Original-commit: flang-compiler/f18@f2d2657aab
Reviewed-on: https://github.com/flang-compiler/f18/pull/1050
2020-03-09 17:25:12 -07:00
Tim Keith c97e1c0a45 [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@305a3470e5
Reviewed-on: https://github.com/flang-compiler/f18/pull/1050
Tree-same-pre-rewrite: false
2020-03-09 17:25:12 -07:00
Tim Keith 2cc21cecf2 [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@864e9cfc7e
Reviewed-on: https://github.com/flang-compiler/f18/pull/1050
Tree-same-pre-rewrite: false
2020-03-09 17:25:12 -07:00
Tim Keith 0b130278a0 [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@cede2971ff
Reviewed-on: https://github.com/flang-compiler/f18/pull/1050
Tree-same-pre-rewrite: false
2020-03-09 17:25:12 -07:00
Steve Scalpone e0ca7b447b [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@d971333025
Reviewed-on: https://github.com/flang-compiler/f18/pull/1010
2020-03-05 08:06:58 -08:00
Steve Scalpone a705a4a314 [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@3cbe344f82
Reviewed-on: https://github.com/flang-compiler/f18/pull/1033
2020-03-05 07:12:06 -08:00
Steve Scalpone 61106305b6 [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@a8edb328f7
Reviewed-on: https://github.com/flang-compiler/f18/pull/1036
2020-03-05 07:09:29 -08:00
Steve Scalpone e8f09da68d [flang] Use std::mutex instead of pthreads (flang-compiler/f18#1006)
* Use std::mutex for portability.

Original-commit: flang-compiler/f18@a9a725eb9d
Reviewed-on: https://github.com/flang-compiler/f18/pull/1006
2020-03-05 06:52:35 -08:00
Steve Scalpone 5dfd2b06d4 [flang] Add missing include <algorithm> for std::max (flang-compiler/f18#1028)
Original-commit: flang-compiler/f18@0e32eebf7f
Reviewed-on: https://github.com/flang-compiler/f18/pull/1028
2020-03-05 06:31:24 -08:00
Steve Scalpone e94ee41ec2 [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@a807862ab8
Reviewed-on: https://github.com/flang-compiler/f18/pull/1038
2020-03-05 05:40:44 -08:00
David Truby d545a132bc [flang] Link against zlib when LLVM does.
Original-commit: flang-compiler/f18@2260abe4c2
Reviewed-on: https://github.com/flang-compiler/f18/pull/1043
2020-03-02 14:19:10 +00:00
Tim Keith 47452b9691 [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@99ce156e49
Reviewed-on: https://github.com/flang-compiler/f18/pull/1046
2020-03-03 13:24:09 -08:00
Tim Keith 3495c78214 [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@e2fd5333ff
Reviewed-on: https://github.com/flang-compiler/f18/pull/1039
2020-03-02 16:45:02 -08:00
Tim Keith 2a00c617d6 [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@8bdaf0a521
Reviewed-on: https://github.com/flang-compiler/f18/pull/1044
2020-03-02 07:59:29 -08:00
Varun Jayathirtha 92c1f6bb98 [flang] Add semantic checks C8104, C8105. Add tests for C8103, C8104, C8105
Original-commit: flang-compiler/f18@8134fc477e
Reviewed-on: https://github.com/flang-compiler/f18/pull/1037
2020-02-27 15:55:46 -08:00
Pete Steinfeld 84b2909ded [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@e81f57fcf5
Reviewed-on: https://github.com/flang-compiler/f18/pull/1031
2020-02-27 08:49:40 -08:00
Pete Steinfeld 657aaf8b8d [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@45998741e5
Reviewed-on: https://github.com/flang-compiler/f18/pull/1031
Tree-same-pre-rewrite: false
2020-02-26 20:19:48 -08:00
Tim Keith 914a91c1c3 [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@a2b2a330e7
Reviewed-on: https://github.com/flang-compiler/f18/pull/1024
2020-02-25 17:13:56 -08:00
Tim Keith c875618506 [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@886ccc37fb
Reviewed-on: https://github.com/flang-compiler/f18/pull/1014
2020-02-26 16:10:11 -08:00
Peter Waller 42cc44fbc8 [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@d9871fa9eb
Reviewed-on: https://github.com/flang-compiler/f18/pull/854
2020-02-26 11:50:43 -08:00
peter klausler b7a5b5c7b6 [flang] Fix layout of 128-bit IEEE-754 floating-point values
Original-commit: flang-compiler/f18@c95c45704e
Reviewed-on: https://github.com/flang-compiler/f18/pull/1021
2020-02-26 08:23:44 -08:00
Jean Perier 13c7778df9 [flang] Remove clang from LLVM drone builds until needed to fasten builds
Original-commit: flang-compiler/f18@5eaebc800c
Reviewed-on: https://github.com/flang-compiler/f18/pull/1026
2020-02-26 06:16:22 -08:00
Jean Perier c3ce28b8b4 [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@7848ab146a
Reviewed-on: https://github.com/flang-compiler/f18/pull/1026
Tree-same-pre-rewrite: false
2020-02-26 03:49:42 -08:00
Tim Keith de066a2756 [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@a759204db5
Reviewed-on: https://github.com/flang-compiler/f18/pull/1023
2020-02-25 15:22:13 -08:00
David Truby 0855c45400 [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@97efc0194d
Reviewed-on: https://github.com/flang-compiler/f18/pull/993
2020-02-25 07:59:50 -08:00
CarolineConcatto 64ab3302d5 [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@d2eb7a1c44
Reviewed-on: https://github.com/flang-compiler/f18/pull/980
2020-02-25 07:11:52 -08:00
Tim Keith 6374eea9cf [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@72aa278f03
Reviewed-on: https://github.com/flang-compiler/f18/pull/1013
2020-02-21 16:25:10 -08:00
Tim Keith e0ba2b8783 [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@8b04dbebcf
Reviewed-on: https://github.com/flang-compiler/f18/pull/1009
2020-02-21 15:47:01 -08:00
Tim Keith 28d8a67d43 [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@04a76b2726
Reviewed-on: https://github.com/flang-compiler/f18/pull/1012
2020-02-21 15:31:12 -08:00
Anchu Rajendran S df1b4b144e [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@822129736b
Reviewed-on: https://github.com/flang-compiler/f18/pull/992
2020-02-20 22:19:14 -08:00
Isuru Fernando ca861fd494 [flang] Add missing array include (flang-compiler/f18#1004)
Original-commit: flang-compiler/f18@de801a0db7
Reviewed-on: https://github.com/flang-compiler/f18/pull/1004
2020-02-20 13:12:48 -08:00
Isuru Fernando 256b53688e [flang] Disable 80-bit extended precision if on MSVC (flang-compiler/f18#1003)
Original-commit: flang-compiler/f18@2c1fc63758
Reviewed-on: https://github.com/flang-compiler/f18/pull/1003
2020-02-20 11:33:43 -08:00
Tim Keith aafc1578ae [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@8ecb6a279f
Reviewed-on: https://github.com/flang-compiler/f18/pull/989
2020-02-19 13:28:19 -08:00
Tim Keith ee7cc4764f [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@84752c492e
Reviewed-on: https://github.com/flang-compiler/f18/pull/989
Tree-same-pre-rewrite: false
2020-02-18 17:14:24 -08:00
Tim Keith 88aa96ffe9 [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@fb87d16a86
Reviewed-on: https://github.com/flang-compiler/f18/pull/989
Tree-same-pre-rewrite: false
2020-02-18 15:20:28 -08:00
Pete Steinfeld 4d0c8522e3 [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@4a703f2b5a
Reviewed-on: https://github.com/flang-compiler/f18/pull/985
2020-02-19 11:58:29 -08:00
Jean Perier 24b9ef8727 [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@bbbbe9c1aa
Reviewed-on: https://github.com/flang-compiler/f18/pull/994
2020-02-19 05:25:35 -08:00
Jinxin (Brian) Yang aa9fc5bddc [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@69a845283b
Reviewed-on: https://github.com/flang-compiler/f18/pull/976
2020-02-18 16:27:43 -08:00
Jean Perier 3364086795 [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:
5f940220bf/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@edb0943bca
Reviewed-on: https://github.com/flang-compiler/f18/pull/959
2020-02-17 02:38:49 -08:00
Jean Perier c52cd6355c [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:
8c320e3bf2
and:
9b9ea05f9a

Original-commit: flang-compiler/f18@00d8d5121c
Reviewed-on: https://github.com/flang-compiler/f18/pull/959
Tree-same-pre-rewrite: false
2020-02-17 02:37:49 -08:00
Pete Steinfeld 79f38ab4bb [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@5dd0b0bbe8
Reviewed-on: https://github.com/flang-compiler/f18/pull/981
2020-02-14 08:33:07 -08:00
David Truby d7cee59762 [flang] Add zlib to drone files so that linking LLVM works. (flang-compiler/f18#983)
Original-commit: flang-compiler/f18@403faf847d
Reviewed-on: https://github.com/flang-compiler/f18/pull/983
2020-02-13 20:46:29 -08:00
peter klausler 95696d563b [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@9c4bba11cf
Reviewed-on: https://github.com/flang-compiler/f18/pull/982
2020-02-13 10:31:26 -08:00
Pete Steinfeld 702d3075ac [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@49a64c4c23
Reviewed-on: https://github.com/flang-compiler/f18/pull/978
2020-02-11 11:30:51 -08:00
Pete Steinfeld b9e9b6f84d [flang] Updated the description of `evaluate::Expr` types
Original-commit: flang-compiler/f18@75adddd504
Reviewed-on: https://github.com/flang-compiler/f18/pull/979
2020-02-11 11:03:06 -08:00
Tim Keith 6256fbe200 [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@c342575a9e
Reviewed-on: https://github.com/flang-compiler/f18/pull/977
2020-02-10 10:55:24 -08:00
Jean Perier 231ff4e6ad [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@16543d22f7
Reviewed-on: https://github.com/flang-compiler/f18/pull/972
2020-02-10 02:33:06 -08:00
Pete Steinfeld 05f44aff45 [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@a1a95bfcd1
Reviewed-on: https://github.com/flang-compiler/f18/pull/973
2020-02-07 10:26:23 -08:00
Jinxin (Brian) Yang f90404e59c [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@572a57d3d0
Reviewed-on: https://github.com/flang-compiler/f18/pull/962
2020-02-05 10:13:43 -08:00
Jean Perier a8ef13ea25 [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@4542cb5708
Reviewed-on: https://github.com/flang-compiler/f18/pull/968
2020-02-04 10:30:16 -08:00
peter klausler f7be251804 [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@c3f1774f8e
Reviewed-on: https://github.com/flang-compiler/f18/pull/950
2020-02-04 14:40:05 -08:00
Pete Steinfeld 60cd064058 [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@889f90913f
Reviewed-on: https://github.com/flang-compiler/f18/pull/939
2020-02-03 09:27:14 -08:00
Tim Keith f1b61dbd5e [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@aa0a088732
Reviewed-on: https://github.com/flang-compiler/f18/pull/961
2020-01-29 16:08:39 -08:00
Pete Steinfeld eaf2288857 [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@d2294ff511
Reviewed-on: https://github.com/flang-compiler/f18/pull/954
2020-01-29 12:42:52 -08:00
Jinxin Yang d8f4d7fcd2 [flang] Remove `default` case for OmpSectionsDirective (only two enum values)
Original-commit: flang-compiler/f18@3f37e0dbaf
Reviewed-on: https://github.com/flang-compiler/f18/pull/960
2020-01-28 13:58:14 -08:00
Jinxin (Brian) Yang 64b7325a2e [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@0c3c39d30e
Reviewed-on: https://github.com/flang-compiler/f18/pull/940
2020-01-28 12:51:35 -08:00
Pete Steinfeld 78807b9880 [flang] More checklist items
I added more items when reviewing some actual pull request comments.

Original-commit: flang-compiler/f18@195d807ff2
Reviewed-on: https://github.com/flang-compiler/f18/pull/956
2020-01-24 12:08:24 -08:00
Alexis Perry 352d347aa5 [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@ae7721e611
Reviewed-on: https://github.com/flang-compiler/f18/pull/958
2020-01-27 18:18:45 -08:00
David Truby 65b62f9bde [flang] Moved public headers to include/flang (flang-compiler/f18#943)
Original-commit: flang-compiler/f18@21adbc7e05
Reviewed-on: https://github.com/flang-compiler/f18/pull/943
2020-01-27 12:57:59 -08:00
Tim Keith ea5b1efd8f [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@81a5488ee6
Reviewed-on: https://github.com/flang-compiler/f18/pull/951
2020-01-25 08:15:17 -08:00
Tim Keith 56634417e7 [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@27d76da2a4
Reviewed-on: https://github.com/flang-compiler/f18/pull/952
2020-01-27 11:51:32 -08:00
peter klausler fae12a08bd [flang] Basic file operation wrapper
Asynchronous interfaces and locking

Original-commit: flang-compiler/f18@3ba77a0c20
Reviewed-on: https://github.com/flang-compiler/f18/pull/949
2020-01-27 09:50:25 -08:00
peter klausler 491122d1cd [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@839a91f1d6
Reviewed-on: https://github.com/flang-compiler/f18/pull/946
2020-01-24 12:33:47 -08:00
Tim Keith d1337ba3ee [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@7489b35392
Reviewed-on: https://github.com/flang-compiler/f18/pull/944
2020-01-22 13:50:02 -08:00
Tim Keith d4a1bd7c9a [flang] Refactor Analyze(PointerAssignmentStmt)
Use early returns to reduce the indentation.
Check LHS is a pointer as early as possible.
A PointerAssignmentStmt can only have a typedAssignment that
represents a PointerAssignment. So assert that is the case and
don't worry about the other cases.

Original-commit: flang-compiler/f18@bdf3d3a292
Reviewed-on: https://github.com/flang-compiler/f18/pull/944
Tree-same-pre-rewrite: false
2020-01-22 13:50:02 -08:00
Tim Keith 0ac2761f2c [flang] Make GenericAssignmentWrapper more like GenericExprWrapper
Have it wrap an optional Assignment so that we can distinguish between
unanalyzed and analyzed with error.

Change analysis of PointerAssignmentStmt to proceed with bounds even
if the DataRef or Expr has an error. Otherwise any bounds expressions
won't be analyzed in that case.

In GetExpr() and GetAssignment() if we get an internal error due to an
unanalyzed expression, dump the parse tree for the expression so we have
some context for the error. They should only be called after the
expression analysis phase. At that point, every expression and assignment
should be analyzed, though some may have resulted in errors(indicated by
returning `nullptr`).

Original-commit: flang-compiler/f18@3b865d7703
Reviewed-on: https://github.com/flang-compiler/f18/pull/944
Tree-same-pre-rewrite: false
2020-01-22 13:50:02 -08:00
Tim Keith 8ad8bfb2a8 [flang] Add `std::string ExpressionBase::AsFortran()`
This is easier to use when including an expression in an error message
and also useful when debugging for dumping expressions.

Fix up several places that no longer need to use a temporary
std::stringstream.

Also change some references to `operator<<` in `formatting.cc` and
`symbol.cc` that became ambiguous with this change.

Original-commit: flang-compiler/f18@25dc49b6e9
Reviewed-on: https://github.com/flang-compiler/f18/pull/944
Tree-same-pre-rewrite: false
2020-01-22 13:50:02 -08:00
Pete Steinfeld fa10045bd7 [flang] Checklist to precede pull requests
I added a checklist to the C++ Style document for things to check before
submitting a pull request or when responding to a request for comments
on a pull request.

Original-commit: flang-compiler/f18@903420268a
Reviewed-on: https://github.com/flang-compiler/f18/pull/936
2020-01-22 09:34:02 -08:00
peter klausler ee60c9a553 [flang] Fix shape analysis of RHS designators of pointer assignments
Original-commit: flang-compiler/f18@bf26a36ef4
Reviewed-on: https://github.com/flang-compiler/f18/pull/938
2020-01-15 15:14:20 -08:00
Tim Keith 628a359071 [flang] Fix checking of pointer target with association
When checking if the target of a pointer assignment is valid, we
weren't following associations. E.g. we complained about the assignment
below if `b` had the TARGET attribute but `c` did not:
```
associate(a => b%c)
  p => a
end associate
```

The fix is to change `GetSymbolVector()` to follow associations in
creating the chain of symbols from a designator.

Add tests for this, and also some other cases where TARGET is on the
derived type variable rather than the component (which worked but didn't
have tests).

Original-commit: flang-compiler/f18@c81c6baedd
Reviewed-on: https://github.com/flang-compiler/f18/pull/937
2020-01-15 13:43:05 -08:00
peter klausler c3df14c30a [flang] begin processing format strings
Move RoundingMode to Fortran.h

Always skip blanks outside character literals & Hollerith

Templatize

optimize repeat counts somewhat

Fix license punctuation, remove patch

Original-commit: flang-compiler/f18@4a0d39b039
Reviewed-on: https://github.com/flang-compiler/f18/pull/927
2020-01-15 11:27:55 -08:00
peter klausler 68f021b8ac [flang] Comments
Original-commit: flang-compiler/f18@0c12188e84
Reviewed-on: https://github.com/flang-compiler/f18/pull/926
2020-01-14 16:16:32 -08:00
peter klausler 210992e526 [flang] Better EQUIVALENCE handling
Original-commit: flang-compiler/f18@7c55097e81
Reviewed-on: https://github.com/flang-compiler/f18/pull/926
Tree-same-pre-rewrite: false
2020-01-14 15:59:29 -08:00
peter klausler a3f4eedea7 [flang] Better fix; clean up redundant utilities
Original-commit: flang-compiler/f18@531db49321
Reviewed-on: https://github.com/flang-compiler/f18/pull/926
Tree-same-pre-rewrite: false
2020-01-14 15:08:37 -08:00
peter klausler 294cae1bcd [flang] Fix unrelated build error found in testing
Original-commit: flang-compiler/f18@5a00d77827
Reviewed-on: https://github.com/flang-compiler/f18/pull/926
Tree-same-pre-rewrite: false
2020-01-14 14:19:42 -08:00
peter klausler 26481ef2bb [flang] Update a test
Original-commit: flang-compiler/f18@5f32183eed
Reviewed-on: https://github.com/flang-compiler/f18/pull/926
Tree-same-pre-rewrite: false
2020-01-14 11:38:09 -08:00
peter klausler c1a710d772 [flang] Address review comments
Original-commit: flang-compiler/f18@d179c796bd
Reviewed-on: https://github.com/flang-compiler/f18/pull/926
Tree-same-pre-rewrite: false
2020-01-14 11:24:49 -08:00
peter klausler b07a4b2474 [flang] Better check for variables in DATA
Original-commit: flang-compiler/f18@92e20baaa8
Reviewed-on: https://github.com/flang-compiler/f18/pull/926
Tree-same-pre-rewrite: false
2020-01-14 11:11:15 -08:00
peter klausler 7010fff8de [flang] Fix bug
Original-commit: flang-compiler/f18@662b8139b5
Reviewed-on: https://github.com/flang-compiler/f18/pull/926
Tree-same-pre-rewrite: false
2020-01-13 15:39:18 -08:00
peter klausler c2bdc144c5 [flang] More comments addressed
Original-commit: flang-compiler/f18@9c863a572b
Reviewed-on: https://github.com/flang-compiler/f18/pull/926
Tree-same-pre-rewrite: false
2020-01-13 15:13:09 -08:00
peter klausler efa2ec7670 [flang] Address review comments
Original-commit: flang-compiler/f18@59e5565cb8
Reviewed-on: https://github.com/flang-compiler/f18/pull/926
Tree-same-pre-rewrite: false
2020-01-13 14:30:31 -08:00
peter klausler 15c89acb18 [flang] BLOCK DATA
add test

Original-commit: flang-compiler/f18@91c084b698
Reviewed-on: https://github.com/flang-compiler/f18/pull/926
Tree-same-pre-rewrite: false
2020-01-13 12:23:14 -08:00
Tim Keith cb37808058 [flang] Pointer assignment semantic checks
Call `CheckPointerAssignment()` when analyzing a pointer assignment
statement. NOTE: the cases with bounds-spec and bounds-remapping are
still to be done.

Perform checks on pointer symbols in `check-declarations.cc`.

Check for pointer to generic intrinsic in `semantics/expression.cc`.

Add the other required pointer assignment checks to `pointer-assignment.cc`.

Original-commit: flang-compiler/f18@3dc5fd6d9e
Reviewed-on: https://github.com/flang-compiler/f18/pull/928
2020-01-14 13:02:56 -08:00
Tim Keith cfedf1dac9 [flang] C1027: procedure pointer may not be coindexed object
Original-commit: flang-compiler/f18@4261daf352
Reviewed-on: https://github.com/flang-compiler/f18/pull/928
Tree-same-pre-rewrite: false
2020-01-14 13:02:56 -08:00
Tim Keith a5db74b614 [flang] Add IntrinsicProcTable::IsSpecificIntrinsicFunction
This replaces IsUnrestrictedSpecificIntrinsicFunction and returns
information that allows the caller to distinguish between restricted
and unrestricted intrinsics.

The new case in `resolve46.f90` used to get an internal error.

Original-commit: flang-compiler/f18@4cb1ee10b9
Reviewed-on: https://github.com/flang-compiler/f18/pull/928
Tree-same-pre-rewrite: false
2020-01-14 13:02:56 -08:00
Tim Keith 355ab9bb82 [flang] Make Fortran form of intrinsic types uppercase
`DynamicType::AsFortran` was using mixed case for intrinic type names.
Make it upper case for consistency with TYPE(...) and CHARACTER when a
length is present and other error messages.

Original-commit: flang-compiler/f18@e16909d67f
Reviewed-on: https://github.com/flang-compiler/f18/pull/928
Tree-same-pre-rewrite: false
2020-01-14 13:02:56 -08:00
Tim Keith c42a22091f [flang] Move pointer assignment checking to its own file
Create `pointer-assignment.{h,cc}` for pointer assignment checking.
It doesn't share with assignment checking so it should be its own file.
Move the code into semantics namespace.

Original-commit: flang-compiler/f18@1658aba81f
Reviewed-on: https://github.com/flang-compiler/f18/pull/928
Tree-same-pre-rewrite: false
2020-01-14 13:02:56 -08:00
Tim Keith ce3d838bc6 [flang] Clean up AssignmentContext
Eliminate `at_` and use location from `SemanticsContext` instead.

Add and use Analyze functions for `std::optional` and `std::list`.

Original-commit: flang-compiler/f18@e171029ccd
Reviewed-on: https://github.com/flang-compiler/f18/pull/928
Tree-same-pre-rewrite: false
2020-01-14 13:02:55 -08:00
Tim Keith 889c81eae7 [flang] Move checks for valid array-spec to check-declarations.cc
At the time we finish processing an array-spec in `resolve-names.cc`,
we don't know if the entity is going to be declared ALLOCATABLE later
so we can't check for validity there. In the new test in `resolve58.f90`
(based on issue flang-compiler/f18#930) we were reporting an error on `b` and not on `a`
when it should be the reverse.

The fix is to move array-spec checking to `check-declarations.cc`,
after name resolution is complete.

Fixes flang-compiler/f18#930.

Original-commit: flang-compiler/f18@c596d2fef7
Reviewed-on: https://github.com/flang-compiler/f18/pull/933
2020-01-14 12:06:52 -08:00
peter klausler 1fe6297cab [flang] Fix bug flang-compiler/f18#931: spurious error reported on CSHIFT
Original-commit: flang-compiler/f18@bd9bd78865
Reviewed-on: https://github.com/flang-compiler/f18/pull/932
2020-01-14 10:53:36 -08:00
CarolineConcatto 0d9dd49ed4 [flang] Regression tests configuration for f18 repository (flang-compiler/f18#861)
The configuration for the tests are in lit.* files.
The lit tests rely on the presence of llvm-lit,FileCheck, not and  count.
When building LLVM add:
-DLLVM_INSTALL_UTILS=On at the cmake command.
LLVM_LIT is found by setting LLVM_EXTERNAL_LIT in f18 CMakeLists.txt.

This patch:
  * Uses LLVM_EXTERNAL_LIT
  * Adds regression tests configurations
  * Adds a proof of concept regression test

The regression test needs to have the Utils build in LLVM.
This is done by adding:
  -DLLVM_INSTALL_UTILS=On
to the LLVM build cmake.

Signed-off-by: Caroline Concatto <caroline.concatto@arm.com>

Original-commit: flang-compiler/f18@a58c6067a1
Reviewed-on: https://github.com/flang-compiler/f18/pull/861
2020-01-14 08:20:49 -08:00
David Truby 05bdb54a49 [flang] Outline operator<< for CharBlock. (flang-compiler/f18#916)
This fixes an issue where the Dump function definitions in dump.cc
were relying on the forward declaration of operator<< for CharBlock
which was marked inline and only present in char-block.h.

This is not allowed under section 6.2.10 of the C++17 standard, and
caused a compilation failure when building with clang 9 as this was
inlining every use of the function and therefore not generating an
outlined definition for linking.

Original-commit: flang-compiler/f18@3ad75d123b
Reviewed-on: https://github.com/flang-compiler/f18/pull/916
2020-01-13 22:08:56 -08:00
Pete Steinfeld 5f7a9504ae [flang] Removed an unnecessary check after Tim fixed issue flang-compiler/f18#915.
Original-commit: flang-compiler/f18@348b04bc1c
Reviewed-on: https://github.com/flang-compiler/f18/pull/924
2020-01-12 08:31:54 -08:00
Pete Steinfeld ec45bc26d3 [flang] Checks for DO variables passed to INTENT(OUT) dummies in functions
I added a traveral framework to find actual arguments in expressions.
For arguments that are DO variables being passed to dummy arguments with
INTENT(OUT), I emit an error message.  For INTENT(INOUT), I emit a
warning.

Original-commit: flang-compiler/f18@815dbed75c
Reviewed-on: https://github.com/flang-compiler/f18/pull/918
2020-01-10 15:08:54 -08:00
Tim Keith 1243a0d175 [flang] Detect incorrect use of assumed-type dummy arguments
Assumed-type dummy arguments can only be used as actual arguments. If
they are used in other contexts it is an error. Change argument analysis
to handle these differently depending on the context. `allowAssumedType`
is set when the argument can be assumed-type. These expressions now all
get `typedExpr` set to `nullopt`.

Change `AnalyzeSectionSubscripts` to analyze all of the subscripts
even if one has an error. This ensures they all get analyzed expressions
(or `nullopt` in case of error).

Fix a bug analyzing `BoundsRemapping`: the lower bound was analyzed
twice and the upper bound not at all.

These change mean that `typedExpr` is set in all known cases.
Fixes flang-compiler/f18#915.

Original-commit: flang-compiler/f18@679ef69905
Reviewed-on: https://github.com/flang-compiler/f18/pull/923
2020-01-10 14:51:40 -08:00
Gary Klimowicz cea1040d51 [flang] Minor format change to LLVM license lines
Replace comment lines containing all dashes with the
proper ===-----....----=== markers.

Original-commit: flang-compiler/f18@a8936b0d41
Reviewed-on: https://github.com/flang-compiler/f18/pull/922
2020-01-10 12:12:03 -08:00
peter klausler 9e6d1a7892 [flang] Dodge build problem in some Power environments
Original-commit: flang-compiler/f18@f24abf19c4
Reviewed-on: https://github.com/flang-compiler/f18/pull/919
2020-01-09 14:01:40 -08:00
peter klausler aeb07fbea6 [flang] Runtime starting and stopping
Define ImageTerminator as a mixin-able class

Turn start.cc into main.cc

Original-commit: flang-compiler/f18@cbc6225213
Reviewed-on: https://github.com/flang-compiler/f18/pull/914
2020-01-09 10:01:59 -08:00
peter klausler e6ab4a7869 [flang] Address complaints in bug flang-compiler/f18#912
Original-commit: flang-compiler/f18@829f5647d6
Reviewed-on: https://github.com/flang-compiler/f18/pull/917
2020-01-09 09:39:09 -08:00
peter klausler d267f20a07 [flang] Fold TRIM
Accept IS_CONTIGUOUS and fold it

test folding is_contiguous

Original-commit: flang-compiler/f18@c75a0791b1
Reviewed-on: https://github.com/flang-compiler/f18/pull/911
2020-01-08 08:44:30 -08:00
peter klausler 91a2f0c75c [flang] Implement folding of INDEX, SCAN, & VERIFY
Fold LEN_TRIM

Fold REPEAT

Fix gcc build warning

Fix two tests that had illegal pointers to coarrays

Original-commit: flang-compiler/f18@36769996fa
Reviewed-on: https://github.com/flang-compiler/f18/pull/910
2020-01-07 13:06:08 -08:00
peter klausler 01c3e4c9f0 [flang] enable semantic analysis by default
back out -Mnolargearray default temporarily

Fix C_F_POINTER(SHAPE=) argument check, it can be any kind of integer

Revert default result kind of SIZE() & al. to standard by default

Remove needless usage of -fdebug-semantics

Original-commit: flang-compiler/f18@57058a5b16
Reviewed-on: https://github.com/flang-compiler/f18/pull/907
2020-01-07 10:24:33 -08:00
Kiran Chandramohan 582b932542 [flang] Semantic checks for critical construct
The commit includes the following,
-> The name field in DoConcurrent*Enforce classes are not used anymore.
Removing the field and its collection and retrieval from
DoConcurrentBodyEnforce and its usage in DoConcurrentLabelEnforce.
-> DoConcurrentLabelEnforce is useful for checking that there
are no branches escaping from other constructs also. For enabling
use in other constructs (like critical) moving this to tools.h
and renaming it as LabelEnforce.
-> Checks for the constraints.
-> Tests for the constaints.

Original-commit: flang-compiler/f18@4b7a007ff3
Reviewed-on: https://github.com/flang-compiler/f18/pull/897
2020-01-04 15:13:28 +00:00
peter klausler cc179ba749 [flang] Fold FLOOR, CEILING, NINT, and ANINT
Add GetUltimate() to ResolveAssociations(), fixing a UBOUND test case with use association

Fix folding of array-valued subscripts while I am in here

Original-commit: flang-compiler/f18@f663d4fef4
Reviewed-on: https://github.com/flang-compiler/f18/pull/905
2020-01-03 16:12:06 -08:00
peter klausler 39114d503a [flang] Another attempt to fix bug flang-compiler/f18#877
Original-commit: flang-compiler/f18@2ad2330cda
Reviewed-on: https://github.com/flang-compiler/f18/pull/906
2020-01-03 15:08:37 -08:00
Tim Keith d42aaa81f2 [flang] Add analyzed form of pointer assignment
Add `typedAssignment` to `PointerAssignmentStmt` parse tree node and
extend `evaluate::Assignment` to include pointer assignment, including
analyzed bounds. Analyze pointer assignments and fill those in.
Emit them in unparsed output and parse tree dump when present.

Change assignment checking to use analyzed expressions and assignments
rather than calling AnalyzeExpr. Check bounds in pointer assignments
for impure function calls in FORALL context.

Add `Fold` convenience function to `ExpressionAnalyzer`.

Original-commit: flang-compiler/f18@140c983423
Reviewed-on: https://github.com/flang-compiler/f18/pull/904
2020-01-03 14:10:26 -08:00