Commit Graph

5697 Commits

Author SHA1 Message Date
Peter Klausler
fac00d1b5d [flang] Fix ENUMERATOR declarations in nested scopes
ENUMERATOR declarations are checking for conflicts between new
enumerator names and names in both the local scope and scopes
that contain it.  ENUMERATOR declarations belong to the local
scope and so only a conflict with a name therein is an error.
(In short, use FindInScope rather than FindSymbol.)

Differential Revision: https://reviews.llvm.org/D142773
2023-01-29 15:55:26 -08:00
Peter Klausler
88f7b4d5b6 [flang][MSVC] Change XFAIL to UNSUPPORTED for disabled test
Test flang/test/Semantics/select-rank02.f90 has an unresolved
failure when built with MSVC on an x86 Windows buildbot, but it passes
on an Arm Windows buildbot.  Change XFAIL to UNSUPPORTED to dodge
an XPASS buildbot complaint on the Arm Windows buildbot.
2023-01-29 14:53:40 -08:00
Peter Klausler
2725499221 [flang] Check that DO index variables are definable
We're letting immutable objects appear as DO index variables;
catch and diagnose this error.

Differential Revision: https://reviews.llvm.org/D142767
2023-01-29 14:27:26 -08:00
Sylvestre Ledru
4430e69fbd flang: remove the hardcoded 15 from the release notes
Differential Revision: https://reviews.llvm.org/D142835
2023-01-29 22:14:58 +01:00
Peter Klausler
23f258cebb [flang] Don't fold REPEAT() when the result would be too large
A test program shouldn't be able to crash the compiler by getting it to
fold REPEAT() with an absurdly large repetition count.

Differential Revision: https://reviews.llvm.org/D142770
2023-01-29 12:14:41 -08:00
Peter Klausler
042c964d60 [flang] Fix defined I/O semantics crash & missing errors that exposed it
Semantics crashes when emitting runtime derived type information tables
for a type that has user-defined I/O procedures declared outside the
type with explicit INTERFACE blocks (as opposed to a GENERIC binding
within the type).  This is due to the runtime table constructor
adding a table entry for each specific procedure of any explicit interface
 of the right kind (e.g., READ(UNFORMATTED)) that it found, rather than
just the ones that pertain to the derived type in question.  But
semantics also wasn't checking such interfaces for distinguishable
specific procedures, either.

Clean these up, improve the spelling of defined I/O procedure kinds
in error messages ("read(formatted)" rather than "READFORMATTED"),
and make error messages stemming from macro expansions only have
one "error:" prefix on the original message so that a new test
would work.

Differential Revision: https://reviews.llvm.org/D142769
2023-01-29 10:15:27 -08:00
Peter Klausler
eb1bd7086a [flang] If it's got an argument keyword, it can't become an array reference
Array references like A(1) are commonly misparsed as function references,
since the parser has almost no semantic context, and the parse tree is
fixed up later by semantics once it can be disambiguated.  In a case
like A(I=1), however, the presence of an argument keyword must prevent
conversion into an array reference.  (It might still also be a structure
constructor.)

Differential Revision: https://reviews.llvm.org/D142765
2023-01-29 08:40:46 -08:00
Peter Klausler
5aa060e3e1 [flang][MSVC] Disable test on Windows
A test is crashing the compiler unexpectedly when built with MSVC;
disable it with an XFAIL until it can be analyzed further.
2023-01-28 17:25:50 -08:00
Peter Klausler
034bab4cc8 [flang] Diagnose invalid initializations
f18 current ignores attempts to initialize (with =expr) things
that are not objects, or allows meaningless initializations of
things that have mistakenly been promoted to be objects.
Fix by refusing to promote to objects names that have any
attributes that cannot be applied to objects, and then catch
data initializations of symbols that are not objects.

Differential Revision: https://reviews.llvm.org/D142766
2023-01-28 17:00:28 -08:00
Peter Klausler
10b990a03b [flang] Diagnose known out-of-range subscripts in more circumstances
Semantics can catch out-of-range subscript values already when they
appear in DATA statement objects and constant folding of name constant
array indexing; this patch fills the gap by checking known constant
subscript values in other contexts.

Differential Revision: https://reviews.llvm.org/D142764
2023-01-28 15:27:17 -08:00
Akash Banerjee
a536d3e40e [MLIR][OpenMP] Add conversion support from FIR to LLVM Dialect for OMP Target Data directives
This enables conversion of OpenMP Target Data, Enter Data and Exit Data from FIR Dialect to LLVM IR Dialect.

Differential Revision: https://reviews.llvm.org/D142629
2023-01-28 20:24:41 +00:00
Peter Klausler
82d7a6b2bb [flang] Diagnose fixed form statement that begins with continuation line
A fixed form continuation line should not be the first line of a statement;
emit a warning if it looks like one is so that the programmer can look
for a missing card.

Differential Revision: https://reviews.llvm.org/D142763
2023-01-28 10:16:43 -08:00
Peter Klausler
2d528fd7d7 [flang] Warn about defined operator with too few/many dummy arguments
A function in a defined operator generic interface will syntactically
have one or two arguments.  If a defined operator includes a specific
function with 0 or more than 2 dummy arguments, there's no way that it
could be invoked by way of the interface.  Emit a warning.

Differential Revision: https://reviews.llvm.org/D142762
2023-01-28 10:15:35 -08:00
Peter Klausler
ebd85ae285 [flang] Enforce ENTRY dummy argument usage restriction
A dummy argument that appears only in ENTRY statements may
not be used in the executable part prior to its first ENTRY
statement.

Differential Revision: https://reviews.llvm.org/D142758
2023-01-28 09:27:00 -08:00
Peter Klausler
73eb5dbd5f [flang] Catch out-of-range constant arguments to CHAR/ACHAR
When folding the intrinsic functions CHAR and ACHAR, emit an
error message if the argument is out of the valid range for the
kind of the result.

Differential Revision: https://reviews.llvm.org/D142754
2023-01-27 17:25:33 -08:00
Peter Klausler
aad5984b56 [flang] Portability warnings for an ambiguous ASSOCIATED() case
The standard's specification for the ASSOCIATED() intrinsic function
describes its optional second argument (TARGET=) as being required
to be a valid target for a pointer assignment statement in which the
first argument (POINTER=) was the left-hand side.  Some Fortran compilers
apparently interpret this text as a requirement that the POINTER= argument
actually be a valid left-hand side to a pointer assignment statement,
and emit an error if it is not so.  This particularly affects the
use of an explicit NULL pointer as the first argument.

Such usage is well-defined, benign, useful, and supported by at least
two other compilers, so we should continue to accept it.  This patch
adds a portability warning and some documentation.

In order to implement the portability warning in the best way, the
special checks on calls to the ASSOCIATED() intrinsic function have
been moved from intrinsic processing to Semantics/check-calls.cpp,
whence they have access to semantics' toolchest.  Special checks for
other intrinsic functions might also migrate in the future in order
to keep them all in one place.

Differential Revision: https://reviews.llvm.org/D142768
2023-01-27 16:51:03 -08:00
Peter Klausler
f0c5a4d854 [flang] Fix shared library build
A recent patch introduced a dependency upon Semantics from
Evaluate; fixing immediately.
2023-01-27 15:52:33 -08:00
Peter Klausler
c7f8bc0ee8 [flang][parser] Diagnose an invalid space
In free form, don't silently skip over an invalid space between
an underscore and a kind parameter.

Differential Revision: https://reviews.llvm.org/D142760
2023-01-27 14:54:53 -08:00
Peter Klausler
036701a177 [flang] Correct procedure pointer (or dummy) compatibility check
Fix a subtle bug in procedure compatibility checking with base
derived types vs. their extensions to ensure that a procedure
expecting an extended type cannot be associated with a pointer
(or dummy procedure) to a procedure expecting a base type.

  subroutine s1(base); ... subroutine s2(extended)
  procedure(s1), pointer :: p
  p => s2 ! <- must be caught as an error

Differential Revision: https://reviews.llvm.org/D142753
2023-01-27 14:53:09 -08:00
Peter Klausler
f7be1aadf2 [flang] Prohibit multiple separate module procedure definitions
Ensure that non-BIND(C) separate module procedures are not
defined more than once.

Differential Revision: https://reviews.llvm.org/D142750
2023-01-27 14:34:03 -08:00
Peter Klausler
6179623628 [flang] Don't apply intrinsic assignment check for PURE subprograms to defined assignment
A semantic constraint on assignments in PURE subprograms (C1594) applies
only to an intrinsic assignment and should not be checked in the case of
a defined assignment.

Differential Revision: https://reviews.llvm.org/D142748
2023-01-27 14:32:07 -08:00
Peter Klausler
54912dd2fb [flang] Catch obscure error in defined assignment
A subroutine that implements a defined assignment cannot have
a dummy argument for its second operand (the RHS of the assignment)
with the POINTER or ALLOCATABLE attributes, since the RHS of
an assignment is always an expression.  This problem is flagged
as a fatal error in other compilers, so let's make it fatal here
as well.

Differential Revision: https://reviews.llvm.org/D142752
2023-01-27 13:41:39 -08:00
Peter Klausler
057a2c239e [flang] Don't fold STORAGE_SIZE() on polymorphic argument
More generally, don't return a successful result from
Fortran::evaluate::DynamicType::MeasureSizeInBytes() when the
type is polymorphic.

Differential Revision: https://reviews.llvm.org/D142772
2023-01-27 11:58:41 -08:00
Sacha Ballantyne
7d2e198729 [flang] Add Count to simplified intrinsics
This patch adds a simplfiied version of count for the simplify intrinsics pass, allowing the function to be inlined.

This was done specifically to help improve performance for exchange2, and provides a ~12% performance increase.

Reviewed By: vzakhari, Leporacanthicus

Differential Revision: https://reviews.llvm.org/D142209
2023-01-27 16:30:11 +00:00
Jean Perier
36e1890f6b [flang][hlfir] Handle box and non constant must_free in end_associate.
Differential Revision: https://reviews.llvm.org/D142700
2023-01-27 12:52:20 +01:00
Jean Perier
86e6a8c33a [flang][hlfir] Handle scalar to array in hlfir.assign codegen.
The scalar must be placed in memory before creating descriptors and
calling the runtime assignment API.

Differential Revision: https://reviews.llvm.org/D142698
2023-01-27 12:50:30 +01:00
Slava Zakharin
02445263e2 [flang] Fixed restrictions checking for OpenACC loop-associated constructs.
CheckDoConcurrentClauseRestriction and CheckTileClauseRestriction expect
that the construct has associated DoConstruct, while it is not set
when the do-loop has no loop control. The change is to skip the clauses
checks, when the do-loop does not have the loop control.

An alternative fix would be to associate the DoConstruct even when
the do-loop has no loop control and let Check*ClauseRestriction run their
checks, but I am not sure if associating invalid DoConstruct is a good idea.

This fixes failure in Semantics/OpenACC/acc-canonicalization-validity.f90
reported in D142279.

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D142652
2023-01-26 14:20:57 -08:00
Slava Zakharin
e054e0da9f [flang] Fixed uninitialized std::unique_ptr dereference.
This fixes unittest failures reported in D142279:
  flang-Unit :: Frontend/./FlangFrontendTests/5/7
  flang-Unit :: Frontend/./FlangFrontendTests/6/7
2023-01-26 14:20:57 -08:00
Jay Foad
6772966dcd [flang] Fix dereference of std::optional with no value
Differential Revision: https://reviews.llvm.org/D142648
2023-01-26 17:36:44 +00:00
Akash Banerjee
0488ecb569 [MLIR][OpenMP] Add Lowering support for OpenMP Target Data, Exit Data and Enter Data directives
This patch adds Fortran Lowering support for the OpenMP Target Data, Target Exit Data and Target Enter Data constructs.
operation.

Differential Revision: https://reviews.llvm.org/D142357
2023-01-26 10:59:55 +00:00
Sylvestre Ledru
7c7e215f0e flang: fix a copy and paste mistake
Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D142488
2023-01-26 09:18:49 +01:00
rkayaith
94a309284d [mlir][Pass] Make PassManager default to op-agnostic
Currently `PassManager` defaults to being anchored on `builtin.module`.
Switching the default makes `PassManager` consistent with
`OpPassManager` and avoids the implicit dependency on `builtin.module`.

Specifying the anchor op type isn't strictly necessary when using
explicit nesting (existing pipelines will continue to work), but I've
updated most call sites to specify the anchor since it allows for better
error-checking during pipeline construction.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D137731
2023-01-25 15:38:19 -05:00
Valentin Clement
b1a34b242f
[flang] Fix element indexing in derived type default initialization
Derived type default initialization was not taking the step into
consideration.

```
module dt_init
  type p1
    integer :: a
  end type
  type, extends(p1) :: p2
    integer :: b = 10
  end type
contains
  subroutine init_dt(z)
    class(p1), intent(out) :: z(:)
    select type(z)
    type is (p2)
      print*,z
    end select
  end subroutine
end module
program test
  use dt_init
  type(p2) :: t(6) = [ p2(1,2),p2(3,4),p2(5,6),p2(7,8),p2(9,10),p2(11,12) ]
  print*,t
  call init_dt(t(::2))
  print*,t
end program
```

Without the fix, the three first elements are initialized

```
 1 2 3 4 5 6 7 8 9 10 11 12
 1 10 5 10 9 10
 1 10 3 10 5 10 7 8 9 10 11 12
```

Where it should be element number 1,3,5

```
 1 2 3 4 5 6 7 8 9 10 11 12
 1 10 5 10 9 10
 1 10 3 4 5 10 7 8 9 10 11 12
```

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D142527
2023-01-25 18:39:03 +01:00
Kiran Chandramohan
3af9dfe464 [Flang][Debug] Use pathnames from location of functions
This ensures that functions in included files have the correct path
in their file metadata.

Note: This patch also sets all locations to have the full path names.

Reviewed By: vzakhari, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D142263
2023-01-25 13:49:21 +00:00
Jean Perier
35fc35cc02 [flang][hlfir] Add hlfir.copy_in and hlfir.copy_out codegen to FIR.
Use runtime Assign to deal with the copy (and the temporary creation, so
that this code can deal with polymorphic temps without any change).

Using Assign for the copy is desired here since the copy happens when
the data is not contiguous, and it happens inside an if/then which
makes it hard to optimize.
See 2b60ed405b
for more details (note that, contrary to this last commit, the code at
hand is only dealing with copy-in/copy-out, it is not intended to deal
with preparing VALUE arguments).

Differential Revision: https://reviews.llvm.org/D142475
2023-01-25 10:46:06 +01:00
Jean Perier
69ee5a53e5 [flang][hlfir] Add hlfir.copy_in and hlfir.copy_out operations
These operations implement the optional copy of a non contiguous
variable into a temporary before a call, and the copy back from the
temporary after the call.

Differential Revision: https://reviews.llvm.org/D142342
2023-01-25 09:50:52 +01:00
Valentin Clement
7aa8a9f1ab
[flang] Fix bounds array creation for pointer remapping calls
`PointerAssociateRemapping` expect a descriptor holding
a newRank x 2 array of int64. The previous lowering was wrong.
Adapt the lowering to fit the expectation of the runtime.
Use the `bounds` to get the rank.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D142487
2023-01-25 09:18:05 +01:00
Slava Zakharin
7ea998e3be [flang] Fixed missing dependency.
It looks like a flaky issue that sometimes breaks the buildbot:
https://lab.llvm.org/buildbot/#/builders/181/builds/13475

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D142081
2023-01-24 13:43:30 -08:00
Valentin Clement
62aa19a5a5
[flang] Keep a fir.box type when doing an array of derived type component
When referencing a single component from a polymorphic array in an expression,
the rebox operation should output a boxed array of that component type and
not a polymorphic boxed array as it was done.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D142462
2023-01-24 19:45:33 +01:00
Valentin Clement
c97d3e5f68
[flang] Use input type to recover the type desc when emboxing
When emboxing to a polymorphic entity without a type source box,
the type desc address must be retrived from the input type and
not from the box type.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D142435
2023-01-24 14:46:31 +01:00
Valentin Clement
f55bfde5f1
[flang] Handle passing NULL() to polymorphic pointer argument
Only updates the assert to check where the box is a BaseBoxType
instead of a BoxType since ClassType are also valid in that case.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D142442
2023-01-24 14:45:37 +01:00
Valentin Clement
f3a94ff057
[flang][NFC] Fix typo 2023-01-24 14:34:16 +01:00
Valentin Clement
4ff863bac4
[flang] Support polymorphic input array for PACK intrinsic
When `ARRAY` is polymorphic, the result needs to carry over
the dynamic type information. This patch updates the lowering
to make the result polymorphic when needed.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D142432
2023-01-24 10:20:05 +01:00
Scott Linder
a1baa7a5c5 [NFC] Add missing llvm:: specifier
This was omitted in 25c0ea2a53
2023-01-23 23:51:06 +00:00
Scott Linder
25c0ea2a53 [NFC] Consolidate llvm::CodeGenOpt::Level handling
Add free functions llvm::CodeGenOpt::{getLevel,getID,parseLevel} to
provide common implementations for functionality that has been
duplicated in many places across the codebase.

Differential Revision: https://reviews.llvm.org/D141968
2023-01-23 22:50:49 +00:00
Slava Zakharin
59b18b5c91 [flang] Avoid unnecessary temporaries in ArrayValueCopy.
Assume no conflict between pointer arrays and arrays without the target
attribute, if the fact of an array not having the target attribute
can be reliably computed.

This change speeds up SPEC CPU2017/527.cam from 2.5k seconds to 880 seconds
on Icelake, and makes further performance investigation easier.

Differential Revision: https://reviews.llvm.org/D142273
2023-01-23 12:33:37 -08:00
Valentin Clement
2e28546ba3
[flang] Keep polymorphic aspect when lowering intrinsic arguments
Make sure the source passed to an intrinsic is still polymorphic when
it is an element of a polymorphic array. This was not handled properly
before.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D142380
2023-01-23 20:25:27 +01:00
Valentin Clement
959caaaa7b
[flang] Add conditional rebox when passing fir.box to optional fir.class
When a `!fir.box<>` is passed as an actual argument to an optional
`!fir.class<>` dummy it needs a `fir.rebox` in order to propagate
the dynamic type information.
The `fir.rebox` needs to happen only on present argument.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D142340
2023-01-23 15:42:04 +01:00
Shivam Gupta
051bf9cd76 [Flang] fix a copy-paste error in scope.cpp
found by PVS-Studio.

Reviewed By: jeanPerier, klausler

Differential Revision: https://reviews.llvm.org/D142306
2023-01-23 14:57:12 +05:30
Valentin Clement
262dad4a81
[flang] Deal with NULL() passed as actual arg to unlimited polymorphic dummy
NULL() passed as actual argument to a procedure with an optional
dummy argument is represented with `fir.box<none>` type. When the dummy
argument is polymoprhic or unlimited polymorphic, the SelectOp will complain
if the types of the two arguments are not identical. Add a conversion from
`fir.box<none>` to `fir.class<none>` in that case.
Other situations with optional will require a fir.rebox and will be done in
a follow up patch.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D142203
2023-01-23 09:49:59 +01:00