Commit Graph

4626 Commits

Author SHA1 Message Date
Peter Klausler e0e2a11751 [flang][runtime] Make ASSOCIATED() conform with standard
ASSOCIATED() must be false for zero-sized arrays, and the
strides on a dimension are irrelevant when the extent is unitary.

Differential Revision: https://reviews.llvm.org/D127793
2022-06-16 11:39:44 -07:00
Peter Klausler 2665fbe71e [flang] NINT(-.4999) is 0, not overflow
Overflow detection in the folding of int/nint/ceiling is
incorrectly signalling overflow when a negative argument yields
a zero result.

Differential Revision: https://reviews.llvm.org/D127785
2022-06-16 10:47:52 -07:00
Peter Klausler b67984d356 [flang] Handle module subprogram with interface in same (sub)module when writing module file
There's a few (3) cases where Fortran allows two distinct symbols to have
the same name in the same scope.  Module file output copes with only two of
them.  The third involves a separate module procedure that isn't separate:
both the procedure and its declared interface appear in the same (sub)module.
Fix to ensure that the interface is included in the module file output, so
that the module file reader doesn't suffer a bogus error about a "separate
module procedure without an interface".

Differential Revision: https://reviews.llvm.org/D127784
2022-06-16 10:08:41 -07:00
Peter Klausler 17853928a6 [flang] Correct implementation of WAIT with no ID
Previous one was returning a bogus error status about a bad WAIT
statement ID number.

Differential Revision: https://reviews.llvm.org/D127979
2022-06-16 10:00:40 -07:00
Peter Klausler cfbde7149d [flang][runtime] Catch more (all?) negative unit number errors
Fortran does have negative unit numbers -- they show up in child I/O
subroutines for defined I/O and for OPEN(NEWUNIT=) -- but the runtime
needs to catch the cases where a negative unit number that wasn't
generated by the runtime is passed in for OPEN or for an I/O statement
that would ordinarily create an anonymous "fort.NNN" file for a
hitherto unseen unit.

Differential Revision: https://reviews.llvm.org/D127788
2022-06-15 17:29:50 -07:00
Peter Klausler 2815bacc91 [flang] Fix error message
A message has a %s string substitution in it but somebody (probably me)
forgot to pass the argument that defines it.

Differential Revision: https://reviews.llvm.org/D127794
2022-06-15 15:30:14 -07:00
Peter Klausler cfc7675a4d [flang][docs] Document non-supported VMS extensions
The prescanner does not support VMS Fortran listing control directives
(%LIST, %NOLIST, %EJECT) or continuation lines on INCLUDE lines.

Differential Revision: https://reviews.llvm.org/D127791
2022-06-15 14:55:47 -07:00
Peter Klausler 690de85ed8 [flang][runtime] Better error message for mis-ASSIGN'ed FORMAT
When an I/O data transfer statement uses an ASSIGN'ed FORMAT that
has not been ASSIGN'ed to a FORMAT statement, the runtime receives
a zero-length format string.  Distinguish this case from the general
error message about missing parentheses.

Differential Revision: https://reviews.llvm.org/D127797
2022-06-15 14:46:22 -07:00
Peter Klausler eb6cd7fe31 [flang] ERROR STOP is not an image control statement
The predicate that determines image control statements needs
to distinguish STOP (which is) from ERROR STOP (which isn't).

Differential Revision: https://reviews.llvm.org/D127796
2022-06-15 14:39:31 -07:00
Peter Klausler db6c3ecd2c [flang][runtime] Make NCOPIES= argument of REPEAT a signed integer, & check it
NCOPIES= is currently a std::size_t in the API.  If a negative value is
used, the memory allocation will fail.  Change it to be a signed integer,
and crash with a message instead if it be negative.

Differential Revision: https://reviews.llvm.org/D127795
2022-06-15 14:29:17 -07:00
Peter Klausler 1a3ac58667 [flang][runtime] Fix handling of output FORMAT('x' 'y')
I'm emitting "x'y" because the space-separated apostrophes are
misinterpreted as being adjacent repeated quotation marks.
Fix to ensure no space skipping is applied when checking for
repeated quotation marks.

Differential Revision: https://reviews.llvm.org/D127792
2022-06-15 14:23:02 -07:00
Peter Klausler bcad53e131 [flang] Add more qualification when creating names for compiler-generated USEs
When generic resolution finds its specific procedure in a module,
and that specific procedure is not use-associated into the local scope
(perhaps because it was PRIVATE, perhaps because the generic was
use-associated with ONLY:), we create a new use-association with
a renaming.  The name constructed for this renaming needs to be
additionally qualified with the module name of the specific procedure
in order to avoid clashing with another specific of the same name
that may have previously been use-associated in the same way from
a distinct module.

Differential Revision: https://reviews.llvm.org/D127790
2022-06-15 14:18:28 -07:00
Peter Klausler f6253eb9ba [flang][runtime] Fix INQUIRE(POS=n) for non-advancing I/O
Position inquiries need to account for offsets in records to be
accurate in the case of non-advancing I/O.

Differential Revision: https://reviews.llvm.org/D127789
2022-06-15 14:14:06 -07:00
Peter Klausler 8ef1075381 [flang][runtime] Signal END from character input
There's code in EditCharacterInput() that causes that template function
to silently return false if it is invoked at the end of the input file.
This overrides other checks that properly call SignalEnd() later.

Differential Revision: https://reviews.llvm.org/D127786
2022-06-15 14:12:38 -07:00
Peter Klausler 6963fb7dfb [flang][runtime] Fix REWIND after non-advancing data transfer
A REWIND of a unit that's in the middle of a record due to a READ
or WRITE statement with ADVANCE='NO' needs to reset the left tab
limit so that the next transfer takes place at the beginning of
the first record.

Differential Revision: https://reviews.llvm.org/D127783
2022-06-15 13:40:49 -07:00
Peter Klausler 142db43b62 [flang][runtime] Allow recovery from BACKSPACE(badUnit)
When an unconnected unit number is used in a BACKSPACE statement
with ERR=, IOSTAT=, &/or IOMSG= control specifiers, don't crash,
but let the program deal with the error.

Differential Revision: https://reviews.llvm.org/D127782
2022-06-15 13:00:54 -07:00
Valentin Clement 575c9d6d4a
[flang][NFC] Fix some formatting
Fix some mismatch in format used in the file and reduce the diff with fir-dev
to be able to finish the upstreaming on this file.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: PeteSteinfeld, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D127849
2022-06-15 16:49:02 +02:00
PeixinQiao 60e359943b [flang] Fix one regression failure related to BIND(C) statement
For BIND(C) statement, two common block with the same name can have the
same bind name. Fix the regression failure by adding this check. Also add
the regression tests.

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

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D127841
2022-06-15 21:10:36 +08:00
Peixin-Qiao 9441003b52 [flang][OpenMP] Add one semantic check for data-sharing clauses
As OpenMP 5.0, for firstprivate, lastprivate, copyin, and copyprivate
clauses, if the list item is a polymorphic variable with the allocatable
attribute, the behavior is unspecified.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D127601
2022-06-15 16:02:27 +08:00
Peixin-Qiao 3151fb5ef7 [flang] Change C889 from error into warning
This constraint is used in OMP2012 benchmark, and other compilers do not
enforce it. Change it into one warning. This addresses the issue
https://github.com/llvm/llvm-project/issues/56003.

Reviewed By: klausler, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D127740
2022-06-15 15:39:13 +08:00
Katherine Rasmussen 2eeafa2022 [flang] Add failed_images to list of intrinsics and add test
Add failed_images to the list of intrinsic functions. Add a
semantics test for failed_images.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D126805
2022-06-14 14:13:33 -07:00
Katherine Rasmussen 473d780692 [flang] Add team_type to num_images intrinsic call
num_images had previously been added to the list of intrinsics
before the type team_type had been implemented. Now that team_type
is implemented, add the num_images call that has the team argument.
Update the semantics tests for num_images.

Reviewed By: craig.rasmussen

Differential Revision: https://reviews.llvm.org/D126734
2022-06-14 11:28:46 -07:00
Valentin Clement 3260d42398
[flang] Avoid losing type parameter information
This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-06-14 15:57:56 +02:00
Jean Perier ac64c7b987 [flang] Support PDT declaration with initial comp value in internal procedure
Lowering was crashing with "fatal internal error: node has not been analyzed"
if a PDT with initial component value was defined inside an internal
procedure. This is because the related expression cannot be analyzed
without the component values (which happens at the instatiation).
These expression do not need to be visited (the instantiations, if any
will be). Use the form of GetExpr that tolerates the parse tree expression
to not be analyzed into an evaluate::Expr when looking through the
symbols used in an internal procedure.

Note that the PDTs TODO will then fire (it happens after the PFT
analysis) as expected if the derived type is used.

Differential Revision: https://reviews.llvm.org/D127735
2022-06-14 14:46:12 +02:00
Jean Perier 9de831aa2c
Add lowering TODO for bindings returning derived types or arrays
Codegen does not support fir.addressof of functions returning derived
types, arrays are descriptors inside GlobalOp region.

This is because the  abstract-result-opt is required to rewrite such
functions (a hidden argument must be added), but this pass is meant to
run in GlobalOp currently.

Such fir.address_of may be created when lowering procedure pointers
initial value (TODO), or when creating derived type descriptors for
types with bindings.

Add a TODO in lowering until abstract-result-opt is modified to run
on GlobalOp too.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D127722
2022-06-14 10:48:44 +02:00
Peixin-Qiao dafd3cf8b1 [flang] Complement one-to-one association check of bind name and entity name
As Fortran 2018 C802 and C873, if bind name is specified, there can only
be only one entity. The check for common block is missed before. As
Fortran 2018 8.5.5 point 2, the bind name is one identifier, which is
unique. That is, one entity can not have multiple bind names. Also add
this check.

Reviewed By: klausler, Jean Perier

Differential Revision: https://reviews.llvm.org/D126961
2022-06-14 10:34:38 +08:00
Peixin-Qiao c6d8aa27c5 [flang] Add semantic check for multiple part-ref with nonzero rank for TBP
As Fortran 2018 C919, there shall not be more than one part-ref with
nonzero rank. Support this semantic check for type-bound procedure to
address the issue https://github.com/llvm/llvm-project/issues/55811.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D127602
2022-06-14 10:17:44 +08:00
Peter Klausler 6ce0fba0e8 [flang][runtime] Skip remainder of bad input record even with ADVANCE='NO'
After a recoverable error condition in a READ statement with ADVANCE='NO',
skip the remainder of the current record.

Differential Revision: https://reviews.llvm.org/D127433
2022-06-13 16:36:19 -07:00
V Donaldson d4980803b6 [flang] Intrinsic module procedure pure prefixes
Per 7.11.1p1 - All [ieee_arithmetic and ieee_exceptions] functions are
pure and all the subroutines are impure unless otherwise stated.  Most of
these functions are elemental (and not impure), which implies pure.
Several of the remaining non-elemental functions are missing pure prefixes;
add them.
2022-06-13 16:36:07 -07:00
Peter Klausler 850097d6dc [flang][runtime] Don't loop in runtime if blank appears in BOZ input
The code for scanning BOZ input allows for blanks and tabs to appear,
but can hang if they do and the BOZ input value is not followed by
extra valid digits; the repositioning for the second sweep simply
needed to be done in units of character, not valid digits.

Differential Revision: https://reviews.llvm.org/D127431
2022-06-13 16:26:50 -07:00
Peter Klausler f472c099be [flang] Handle USE association in parse tree rewriting
f18 was treating "f() = 1" as a statement function definition
if it could be viewed as being in the specification part and
"f" was a USE-associated function returning a data pointer.
(The non-USE-associated case is fine.)  Fix to allow for "f"
to be USE associated.

Differential Revision: https://reviews.llvm.org/D127430
2022-06-13 16:20:51 -07:00
Peter Klausler 8eebf46964 [flang] Fix crash on USE error
Handle the case of a non-generic procedure that is USE associated
into a scope that has a generic interface of the same name with an
appropriate error rather than crashing.

Differential Revision: https://reviews.llvm.org/D127429
2022-06-13 16:15:47 -07:00
Peter Klausler db52dda8ab [flang][runtime] Detect overflow of fixed-sized exponent output field
When Ew.dEe or Gw.dEe output has an exponent requiring more than 'e'
digits, the whole output field must overflow to asterisks.  The runtime
was detecting short fields and padding them with zeroes, but not
overflow.

Differential Revision: https://reviews.llvm.org/D127428
2022-06-13 16:10:32 -07:00
Peter Klausler 4c42e67bf7 [flang][runtime] Fix overflow detection for REAL input
The test for an overflow during decimal->binary conversion was taking
place too late, causing the data not to be rescanned from the beginning.

Differential Revision: https://reviews.llvm.org/D127427
2022-06-13 16:05:11 -07:00
Peter Klausler 3f3edbe5fc [flang][runtime] Don't emit any leading blanks for G0/E0 output editing
There were cases where E0.d output editing (or G0.d editing that is converted
to E0.d) would emit one or more leading blank characters; fix them.

Differential Revision: https://reviews.llvm.org/D127426
2022-06-13 16:03:24 -07:00
Eric Schweitz f5b970c9ef
[flang] Fix type mismatch in verification error
FIR models Fortran intrinsic types with deliberate KIND values. Like
Fortran, COMPLEX and REAL have related KINDs in FIR. Lowering now
converts REAL types to floating point (MLIR) up front. This patch moves
the code to convert from FIR RealType to MLIR FloatType out of codegen
and into the builder, allowing FIR ComplexTypes to have their element
type returned as an MLIR FloatType.

We should consider whether to replace fir::ComplexType with
mlir::ComplexType at some point. I believe these types are presently
used to convey distinctins in the target ABIs in the Tilikum bridge
however.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: PeteSteinfeld

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-06-13 21:37:39 +02:00
Eric Schweitz 0c1cf585c0
[flang][NFC] Add source location information to report unsupported complex types
This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier, PeteSteinfeld

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-06-13 21:31:17 +02:00
Peter Klausler 89e4b75648 [flang] Document extension: Ew.0 output editing
The restrictions on the relationship between a "kP" scale factor
and a Ew.d/Dw.d/Gw.d significant digit count are not enforced for
output editing when there is no nonzero scale factor in effect.
(An error message about a bad scale factor is confusing if no kP
control edit descriptor has been used.)  Document this usage in
Extensions.md.

Differential Revision: https://reviews.llvm.org/D127435
2022-06-13 11:50:11 -07:00
Peter Klausler ee9c917048 [flang] Fix bogus branch target error on END SELECT
The scope model used for branch target checking treats a label
on an END SELECT statement as if it were in the previous CASE block.
This makes it illegal to GO TO that label from within any earlier
CASE block in that statement.  Fix by treating the CASE blocks as
nested scopes within the scope of the SELECT construct.

Also, add a "warning:" tag to related warning messages.

Differential Revision: https://reviews.llvm.org/D127425
2022-06-13 11:42:55 -07:00
Peter Klausler bd577afe8f [flang][runtime] Fix runtime CSHIFT of rank>1 array case of negative shift count
The calculation of the source index was incorrect when a CSHIFT shift
count value is negative, for the implementation of CSHIFT for arrays
with rank >= 2.  (The vector CSHIFT is fine.)

Differential Revision: https://reviews.llvm.org/D127424
2022-06-13 11:34:25 -07:00
Peter Klausler 2a07db4cf6 [flang][runtime] Don't crash after reporting I/O statement errors
When an I/O statement is known to be in a recoverable error state,
it shouldn't cause a crash later in execution because it's not in
an expected non-erroneous processing state.  Add checking for the
ErroneousIoStatementState variant on paths that might otherwise
lead to runtime crashes.

Differential Revision: https://reviews.llvm.org/D127423
2022-06-13 11:24:59 -07:00
Peter Klausler 1444bc8241 [flang][runtime] Fix list-directed/NAMELIST complex input with "r*" repetition count
The little state machine in GetNextDataEdit() wasn't transitioning
properly from reading the imaginary part of the number back to the
real part for the next iteration of a repeated value.

Differential Revision: https://reviews.llvm.org/D127422
2022-06-13 10:50:25 -07:00
Peter Klausler 166d6ed5c7 [flang][runtime] Better (but still synchronous) support for asynchronous I/O
Track pending "asynchronous" I/O operation IDs so that WAIT statements can
report errors about bad ID numbers.

Lowering will need to extended to call GetAsynchronousId() for a READ or
WRITE statement with ID=n.

Differential Revision: https://reviews.llvm.org/D127421
2022-06-13 10:43:14 -07:00
Peter Klausler 2496938522 [flang][runtime] Fix nonadvancing output edge case
When nonadvancing output uses T/TL control edit descriptors to reposition
the record, don't reset the position to the furthest point written at
the end of the write.

Differential Revision: https://reviews.llvm.org/D127420
2022-06-13 10:27:27 -07:00
Valentin Clement f1c84d0ff0
[flang][NFC] Add TODOs for KIND = 2
Add TODO for KIND=2 so the user is notified correctly.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier, PeteSteinfeld

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

Co-authored-by: Peter Steinfeld <psteinfeld@nvidia.com>
2022-06-13 18:45:32 +02:00
Kiran Chandramohan c030f46703 [Flang][OpenMP] Avoid double privatisation of loop variables
Loop variables of a worksharing loop and sequential loops in parallel
region are privatised by default. These variables are marked with
OmpPreDetermined. Skip explicit privatisation of these variables.

Note: This is part of upstreaming from the fir-dev branch of
https://github.com/flang-compiler/f18-llvm-project.

Reviewed By: Leporacanthicus

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Mats Petersson <mats.petersson@arm.com>
2022-06-13 16:27:34 +00:00
Mogball e16d13322b [mlir] (NFC) Clean up bazel and CMake target names
All dialect targets in bazel have been named *Dialect and all dialect
targets in CMake have been named MLIR*Dialect.
2022-06-13 16:24:15 +00:00
Valentin Clement 4a8305ce85
[flang] Add TODO for half-precision intrinsic reductions
Add TODO for half-precision for reduction.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier, PeteSteinfeld

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2022-06-13 17:40:01 +02:00
jeanPerier a370a4ffce
[flang] Avoid raising a TODO in fir.boxproc rewrite when not needed (#1560)
The pass was raising TODOs when a function both had a fir.boxproc<> argument
and a fir.type<> argument (even if the fir.type<> did not contain a
fir.boxproc itself).

Prevent the TODO from firing when a fir.type<> does not actually contain
a fir.boxproc. Add the location for the remaining TODO (it will be
needed when procedure pointer components are supported in lowering).

FYI, I actually tried to just implement the TODO, but I there is  a funny
issue. When creating the new fir::RecordType, since the name and context
are the same as the type being translated, fir::RecordType:get just
returns the existing type, and there is no way to change it (finalize()
does nothing since it is already finalized). So this will require to add
the ability to mutate the existing type, and I am not sure what are the
MLIR constraints here, so I escaped and left the TODO for that case.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier, PeteSteinfeld

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-06-13 17:36:56 +02:00
Jean Perier c8a9afe7c8
[flang] Handle reversed bounds and negative length in inlined allocation
ALLOCATE statement allows reversed bounds (see Fortran 2018 9.7.1.2
point 1) in which case the extents are zero.

The same applies for the character length provided in the type spec that
can be negative. In which case the new length is zero.

Use genMaxWithZero to deal with these cases.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier, PeteSteinfeld

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2022-06-13 17:35:03 +02:00