Commit Graph

5697 Commits

Author SHA1 Message Date
Peter Klausler
815fddfa17 [flang] Impose DATA initialization size limit to avoid crashing
Impose a large but finite limit on the size of a variable being
initialized in a DATA statement to provide a readable error message
for artificial test cases that's better than a memory allocation
failure crash.

Differential Revision: https://reviews.llvm.org/D140146
2022-12-17 07:27:31 -08:00
Ramkumar Ramachandra
22426110c5 mlir/tblgen: use std::optional in generation
This is part of an effort to migrate from llvm::Optional to
std::optional. This patch changes the way mlir-tblgen generates .inc
files, and modifies tests and documentation appropriately. It is a "no
compromises" patch, and doesn't leave the user with an unpleasant mix of
llvm::Optional and std::optional.

A non-trivial change has been made to ControlFlowInterfaces to split one
constructor into two, relating to a build failure on Windows.

See also: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Signed-off-by: Ramkumar Ramachandra <r@artagnon.com>

Differential Revision: https://reviews.llvm.org/D138934
2022-12-17 11:13:26 +01:00
Fangrui Song
2098ad7f00 [flang] std::optional::value => operator*/operator-> 2022-12-17 04:11:55 +00:00
Peter Klausler
12ec5b20c2 [flang] Catch attempts to initialize allocatable components with DATA statement
Nice try, but no, you can't initialize an instance of a derived type using a
structure constructor that has a component corresponding to an allocatable
component.

Differential Revision: https://reviews.llvm.org/D140144
2022-12-16 18:16:30 -08:00
Peter Klausler
290cc4fe17 [flang] Prevent crash in error case: elemental with alternate return
When an ELEMENTAL subroutine is erroneously declared with alternate return
arguments, don't crash when checking the ranks of the actual arguments.

Differential Revision: https://reviews.llvm.org/D140143
2022-12-16 16:45:51 -08:00
Peter Klausler
82cb792066 [flang][runtime] Allow CLASS(*) components when creating descriptors
Extend the descriptor creation function for components to allow
unlimited polymorphic components (CLASS(*)) and to also properly set
the attributes of the established descriptors.

Differential Revision: https://reviews.llvm.org/D140141
2022-12-16 15:09:37 -08:00
Peter Klausler
875c7b7d39 [flang] Correct folding of EXTENDS_TYPE_OF()
There was a falsely known case with a polymorphic type.

Differential Revision: https://reviews.llvm.org/D140140
2022-12-16 13:45:51 -08:00
Valentin Clement
5d7c5e6199
[flang] Fix fir.dispatch_table generation with derived-type parameter with kind type parameter
When generating the `fir.dispatch_table` operation, the name of the parent
derived-type needs to be mangled. For this the type instantiation
DerivedTypeSpec needs to be retrieved to have the correct kind type parameters.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D140209
2022-12-16 21:21:54 +01:00
Valentin Clement
b2b680a5ab
[flang] Unlimited polymoprhic allocation with intrinsic type spec
An unlimited polymoprhic entity can be allocated with a derived type
spec or an intrinsic type spec. This patch add the generation of the
runtime function call when the allocation is done with an intrinsic
type spec.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D140207
2022-12-16 21:20:28 +01:00
Peter Klausler
cf63261b77 [flang] Don't crash attempting to fold absurdly large TRANSFER()
Apply some sanity checking to the type size and SIZE= values and
avoid crashing on stress tests that attempt to create excessively
large results.

Differential Revision: https://reviews.llvm.org/D140138
2022-12-16 11:43:14 -08:00
Peter Klausler
635656f4ff [flang] Expunge needless semantics::ProcInterface
The ProcInterface structure is used only by ProcEntityDetails; it represents
what a program might have put in parentheses in a procedure-declaration-stmt,
either the name of a procedure interface or a declaration-type-spec.

If a procedure entity has an implicit interface, the function result
type (if any) can be kept in EntityDetails::type_, which already exists
and is currently redundant for ProcEntityDetails symbols.

All that is really needed is a nullable Symbol pointer in ProcEntityDetails
to point to the procedure's explicit interface, when it has one.

Also, catch the case where a procedure has an explicit interface
and a program attempts to also give it a type.

Differential Revision: https://reviews.llvm.org/D140134
2022-12-16 10:44:29 -08:00
Peter Klausler
7bd2eace7d [flang] Check for elemental finalizer when defined object has vector subscript
When a defined object is an array with a vector subscript, and it has a
finalizable type, it may have a final subroutine with a matching or
assumed rank dummy argument that cannot be called.  Unless there is
also a suitable elemental final subroutine, diagnose such a case
with an error message.

Differential Revision: https://reviews.llvm.org/D140131
2022-12-16 09:52:45 -08:00
Peter Klausler
6f6af76b84 [flang] Catch bad usage of POINTER attribute
Most attributes apply to only object or only procedure entities,
and attempts to apply them to other kinds of symbol table entries
are caught in name resolution when ConvertToObjectEntity() or
ConvertToProcEntity() fails.  However, the POINTER attribute can
be applied to both, and name resolution can't perform that conversion
yet, and as a result we don't catch many kinds of silly errors.
Fix by ensuring that the symbol is of a type that could eventually
become an object or procedure entity if it is not one already.

Differential Revision: https://reviews.llvm.org/D140137
2022-12-16 09:04:54 -08:00
Jean Perier
4203b062fb [flang] Lower procedure ref to user defined elemental procedures (part 1)
Lower procedure ref to user defined elemental procedure when:
- there are no arguments that may be dynamically optional
- for functions, the result has no length parameters
- the reference can be unordered
- there are not character by value arguments

This uses the recently added hlfir.elemental operation and tools.
The "core" of the argument preparation is shared between elemental
and non elemental calls (genUserCalls is code moved without any
functional changes)

Differential Revision: https://reviews.llvm.org/D140118
2022-12-16 13:04:04 +01:00
Jean Perier
61a124db56 [flang] hlfir.apply codegen
Lower hlfir.apply to hlfir.designate in bufferization.

Differential Revision: https://reviews.llvm.org/D140101
2022-12-16 09:27:58 +01:00
Jean Perier
af2e597522 [flang] enable as_expr codegen from array without FortranVariabeInterface
The defining op of HLFIR variables is expected to be visible
in most cases, but HLFIR codegen won't rely on it from a correctness
point of view.

This patch allows building a fir.shape from an hlfir::Entity does not
have a visible FortranVariabeInterface defining op.

Differential Revision: https://reviews.llvm.org/D140099
2022-12-16 09:22:24 +01:00
Jean Perier
c2e3cb3e43 [flang] hlfir.elemental codegen
Without any optimization or when it cannot be optimized before
bufferization, an hlfir.elemental lowers to an array temporary.
Its codegen consists in:
- allocating a temp given the type, shape, and length parameter arguments.
- generating a loop nest given the elemental shape
- inlining the body of the elemental inside the loops, and replacing the
  yield_element by an assignment to an element of the temp.

Differential Revision: https://reviews.llvm.org/D140093
2022-12-16 09:19:49 +01:00
Peter Klausler
bcd0bf9284 [flang] Enforce 15.4.2.2(4)(c) - explicit interface required
When a function has an implicit interface its result type may
not have a deferred type parameter.

Differential Revision: https://reviews.llvm.org/D140132
2022-12-15 18:26:16 -08:00
Peter Klausler
24db885949 [flang] Check for polymorphism in DEALLOCATE statements in pure procedures
Semantic checking for DEALLOCATE statements omitted checks for
polymorphic objects and ultimate allocatable components in a pure
procedure, which if not caught would allow execution of an impure
FINAL subroutine defined on a type extension.

Differential Revision: https://reviews.llvm.org/D140129
2022-12-15 16:39:48 -08:00
Peter Klausler
e9088e3789 [flang] When resolving a binding, allow for overriding
In type-bound generic resolution, when the actual argument
is monomorphic, resolve the call to the target of the
most recent (i.e., least deeply inherited) override of
the binding, if any.

Differential Revision: https://reviews.llvm.org/D140127
2022-12-15 15:08:48 -08:00
Peter Klausler
f9ebf77ffd [flang] Correct folding of SAME_TYPE_AS()
The result can't be known to be true at compilation time when
either operand is polymorphic.

Differential Revision: https://reviews.llvm.org/D140126
2022-12-15 13:51:50 -08:00
Kelvin Li
7fdd0c00e0 [flang] Semantic-check for procedure pointers with assumed character length
Fixes: https://github.com/llvm/llvm-project/issues/59496

Committed on behalf of tislam

Differential Revision: https://reviews.llvm.org/D139333
2022-12-15 13:36:41 -05:00
Jean Perier
3191e8e19f [flang] Lower binary and unary elemental array operations
Lower binary and unary elemental operations with an array argument
using hlfir.elemental, hlfir.yield_element, and hlfir.apply.

Concat implementation, which is a binary operation, is moved to a
BinaryOp struct so that it can leverage this new code.

This patch implements the "not yet implemented: character array
expression temp with dynamic length" TODO of the current lowering
by splitting the result length computation from the result value
computation. That way, the result length computation can be done
before lowering the operation to an hlfir.elemental, and the length
of the hlfir.elemental is known and storage for it can later be
allocated.

It adds a DesignatorOp builder to make "dumb" indexing (without triplets,
component, substrings or derived type component ref) easier since indexing
needs to be generated for array variables in elemental expression (in
the added hlfir::genElementAt helper).

Differential Revision: https://reviews.llvm.org/D140040
2022-12-15 13:15:12 +01:00
Valentin Clement
9379ca0a25
[flang] Fix associating entity when selector is an array, pointer or allocatable
In SELECT TYPE, within the block following TYPE IS, the associating entity is not polymorphic.
It has the type named in the type guard and other properties taken from the
selector. Within the block following a CLASS IS type guard statement, the
associating entity is polymorphic and has the declared type named in the type
guard statement.
This patch makes sure the associating entity matches the selector if it is
an array, a pointer or an allocatable.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D140017
2022-12-15 12:02:38 +01:00
Jean Perier
b22fa8659a [flang][NFC] add builder to simplify fir.shape creation
Differential Revision: https://reviews.llvm.org/D140031
2022-12-15 11:14:14 +01:00
Jean Perier
7d0429bf54 [flang] Add hlfir.apply definition
hlfir.apply allows retrieving element values from an array expression
value. See https://github.com/llvm/llvm-project/blob/main/flang/docs/HighLevelFIR.md
for more detail.

Differential Revision: https://reviews.llvm.org/D140023
2022-12-15 11:12:52 +01:00
Jean Perier
686881976c [flang] Add hlfir.elemental and hlfir.yield_element definition
hlfir.elemental is the operation that will allow representing all
Fortran elemental expressions and more as functions of the indices.
See https://github.com/llvm/llvm-project/blob/main/flang/docs/HighLevelFIR.md for
more details about it.

Also add hlfir.yield_elemement which is the hlfir.elemental region terminator.

Differential Revision: https://reviews.llvm.org/D140015
2022-12-15 11:10:33 +01:00
Kazu Hirata
7e937d08e1 Don't include StringSwitch (NFC)
These files do not use llvm::StringSwitch.
2022-12-14 21:50:34 -08:00
Slava Zakharin
9e8f677299 [flang] Lower exponentiation without using pgmath.
Exponentiation is lowered to either math::FPowI or Fortran runtime
call (in case of --math-runtime=precise).

MathToFuncs convertor will convert math::FPowI operations with
exponent width >32 to calls of outlined implementations and otherwise
will leave the operation to MathToLLVM convertor.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D139806
2022-12-14 15:32:51 -08:00
Paul Robinson
e84d1879e5 [Flang] Convert a test to check 'target=...'
Part of the project to eliminate special handling for triples in lit
expressions.

Differential Revision: https://reviews.llvm.org/D139967
2022-12-14 08:34:11 -08:00
Paul Robinson
83f045f08c [Flang] Remove some incorrect UNSUPPORTED clauses
Differential Revision: https://reviews.llvm.org/D139968
2022-12-14 04:33:04 -08:00
Kazu Hirata
bfe4c5cc0b [flang] Fix a warning
This patch fixes:

  flang/lib/Lower/PFTBuilder.cpp:1042:6: error: function 'dumpScope'
  is not needed and will not be emitted
  [-Werror,-Wunneeded-internal-declaration]
2022-12-13 17:36:56 -08:00
V Donaldson
9b35843e93 [flang] Fix build failure 2022-12-13 15:10:59 -08:00
V Donaldson
518e6f12f3 [flang] Submodules
A submodule is a program unit that may contain the implementions of procedures
declared in an ancestor module or submodule.

Processing for the equivalence groups and variables declared in a submodule
scope is similar to existing processing for the equivalence groups and
variables in module and procedure scopes. However, module and procedure scopes
are tied directly to code in the Pre-FIR Tree (PFT), whereas processing for a
submodule must have access to an ancestor module scope that is guaranteed
to be present in a .mod file, but is not guaranteed to be in the PFT. This
difference is accommodated by tying processing directly to a front end scope.
Function scopes that can be processed on the fly are done that way; the
resulting variable information is never stored. Module and submodule scopes
whose symbol information may be needed during lowering of any number of module
procedures are instead cached on first use, and reused as needed.

These changes are a direct extension of current code. All module and submodule
variables in scope are processed, whether referenced or not. A possible
alternative would be to instead process symbols only when first used. While
this could ultimately be beneficial, such an approach must account for the
presence of equivalence groups. That information is not currently available
for on-the-fly variable processing.

Some additional changes are needed to include submodules in places where
modules must be considered, and to include separate module procedures in
places where other subprogram variants are considered. There is also a fix
for a bug involving the use of variables in an equivalence group in a
namelist group, which also involves scope processing code.
2022-12-13 13:06:07 -08:00
Cabrera, Anthony
9c87746de7 [flang] emit warning when encountering a non-variable actual argument when its corresponding dummy argument expects a VOLATILE variable
This patch implements @klausler's suggestion in `llvm-project` [issue #58973](https://github.com/llvm/llvm-project/issues/58973); encountering the `VOLATILE` attribute should produce a __warning__, not a __fatal error__.

When tested on the following Fortran program `snem0601_012_.f90`:
```fortran
  module mod
    contains
    subroutine sub(m6,error)
    integer,intent(inout) :: error

    integer,volatile :: m6

    if (any ((/m6/).ne.(/6/))) &
   & then
       error = 1
    end if
    end subroutine
  end module

  program fe1nvol12

    use mod
    integer :: error = 0

    call sub(6,error)

    if (error .ne. 0) then
      print *,'NG: snem0601_012'
    end if

    print *,'pass: snem0601_012'

  end program fe1nvol12
```

the following output is produced:

```bash
$ flang-new -fc1 snem0601_012_.f90
/noback/93u/Sandbox/issue_58973_volatile_dummy_arg/snem0601_012_.f90:21:12: warning: actual argument associated with VOLATILE dummy argument 'm6=' is not a variable
    call sub(6,error)
             ^
```

Reviewed By: clementval, klausler

Differential Revision: https://reviews.llvm.org/D139134
2022-12-13 15:28:15 -05:00
Slava Zakharin
22702cc76c [mlir][math] Added math::FPowI conversion to calls of outlined implementations.
Power functions are implemented as linkonce_odr scalar functions
for FPowI operations met in a module.
Vector form of FPowI is linearized into a sequence of calls
of the scalar functions.

Option {min-width-of-fpowi-exponent} controls which FPowI operations
are converted by MathToFuncs: if the width of the exponent's integer
type is less than the specified value, then the operation is not converted.

Flang will specify {min-width-of-fpowi-exponent=33} to make sure that
math::FPowI operations with exponent wider than 32 bits will be converted
by MathToFuncs, and operations with more narrow exponent will be left
for MathToLLVM to convert them to LLVM::PowIOp.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D139804
2022-12-13 12:15:35 -08:00
Valentin Clement
7602e09b1c
[flang] Handle type generation for unlimited polymorphic function result
An unlimited polymorphic entity is considered to have a derived category
in its dynamic type but no type descriptor. Avoid a nullptr dereference when
an unlimited polymorphic type needs to be generated.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D139923
2022-12-13 15:00:08 +01:00
Valentin Clement
a6924c6d74
[flang] Use input type when emboxing/reboxing polymorphic entities
When emboxing an entity to a polymorphic box, use the input type to
compute the type code and element size as the box type is too generic.
When reboxing a polymorphic box, get this information from the input
box.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D139916
2022-12-13 09:44:25 +01:00
Jonathon Penix
1ee9080d6b [flang] Preserve bound info for pointer assignments through derived types
Doing a pointer assignment to another pointer which is a derived type component
could result in the bound information being lost, potentially leading to
incorrect array accesses. Fix this by trying to retain the bound info during
the assignment.

Fixes #57441

Differential Revision: https://reviews.llvm.org/D139800
2022-12-12 14:22:22 -08:00
Tom Eccles
9d86f2dc4f [flang] skip fast_math linker test on powerpc #3
Another attempt to skip the fast-math linker test on powerpc. The test
has to be skipped because there is no crtfastmath.o on powerpc.

Change recommended by Amy Kwan <amyk>.

See https://reviews.llvm.org/D138675
2022-12-12 21:46:35 +00:00
Tom Eccles
6442b4da4e [flang] disable fast_math test on powerpc
There seems not be any crtfastmath.o on powerpc.

See https://reviews.llvm.org/D138675
2022-12-12 20:02:37 +00:00
Tom Eccles
1a4f1449ac [flang] Match alternative names for crtend in fastmath test
The fastmath test checks that crtfastmath.o is added between crtbeginS.o
and crtendS.o. On some systems, crtend is called crtend.o - match these
too.

Related to https://reviews.llvm.org/D138675
2022-12-12 13:32:38 +00:00
Valentin Clement
40cb4fd0b9
[flang] Perform polymorphic pointer association with runtime call
pointer association to a polymorphic pointer needs to potentially
update the element size in the descriptor. Update the pointer association
to polymoprhic pointer with a runtime call to PointerAssociate.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D139825
2022-12-12 14:05:14 +01:00
Tom Eccles
bea45027b4 [flang] match alternate names for crtbegin in fastmath test
The fastmath test checks that crtfastmath.o is added between crtbeginS.o
and crtend.o. On some systems the first file is instead called
crtbegin.o - match these too.

Related to https://reviews.llvm.org/D138675
2022-12-12 11:28:21 +00:00
Mark de Wever
d40dc41738 [CMake] Warn when the version is older than 3.20.0.
This is a preparation to require CMake 3.20.0 after LLVM 16 has been
released.

This change has been discussed on discourse
https://discourse.llvm.org/t/rfc-upgrading-llvms-minimum-required-cmake-version/66193

Reviewed By: #libc_vendors, MaskRay, ChuanqiXu, to268, thieta, stellaraccident, ldionne, #libc, #libc_abi, phosek

Differential Revision: https://reviews.llvm.org/D137724
2022-12-11 20:19:46 +01:00
Kazu Hirata
c15a925ada [flang] Use std::optional instead of None in comments (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-10 17:00:21 -08:00
Jeff Niu
53406427cd [mlir] FunctionOpInterface: turn required attributes into interface methods (Reland)
Reland D139447, D139471 With flang actually working

- FunctionOpInterface: make get/setFunctionType interface methods

This patch removes the concept of a `function_type`-named type attribute
as a requirement for implementors of FunctionOpInterface. Instead, this
type should be provided through two interface methods, `getFunctionType`
and `setFunctionTypeAttr` (*Attr because functions may use different
concrete function types), which should be automatically implemented by
ODS for ops that define a `$function_type` attribute.

This also allows FunctionOpInterface to materialize function types if
they don't carry them in an attribute, for example.

Importantly, all the function "helper" still accept an attribute name to
use in parsing and printing functions, for example.

- FunctionOpInterface: arg and result attrs dispatch to interface

This patch removes the `arg_attrs` and `res_attrs` named attributes as a
requirement for FunctionOpInterface and replaces them with interface
methods for the getters, setters, and removers of the relevent
attributes. This allows operations to use their own storage for the
argument and result attributes.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D139736
2022-12-10 15:17:09 -08:00
Kazu Hirata
70010893f9 [flang] Use std::nullopt instead of llvm::None (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-09 18:32:33 -08:00
Tom Eccles
20cd3153f3 [flang] Skip fast_math linker test on powerpc
Related to https://reviews.llvm.org/D138675
2022-12-09 21:20:42 +00:00
Tom Eccles
e7b6660243 [flang] Add -ffast-math and -Ofast
clang -cc1 accepts -Ofast. I did not add it to flang -fc1 because this
seems redundant because the compiler driver will always resolve -Ofast
into -O3 -ffast-math (I added a test for this).

-menable-infs is removed from the frontend-forwarding test because if
all of the fast-math component flags are present, these will be resolved
into the fast-math flag. Instead -menable-infs is tested in the
fast-math test.

Specifying -ffast-math to the compiler driver causes linker invocations
to include crtfastmath.o.

RFC: https://discourse.llvm.org/t/rfc-the-meaning-of-ofast/66554

Differential Revision: https://reviews.llvm.org/D138675
2022-12-09 19:55:58 +00:00
Valentin Clement
bf773a61ce
[flang] Handle correctly polymorphic descriptor for IO input
Polymorphic entities are already emboxed. Just update
the code to use `BaseBoxType` instead of `BoxType`.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D139707
2022-12-09 16:06:54 +01:00
David Spickett
f3379feabe Revert "[mlir] FunctionOpInterface: arg and result attrs dispatch to interface"
and "[flang] Fix flang after MLIR update"

This reverts commit dd74e6b6f4 and
1897b67ae8 due to ongoing test failures on flang
bots e.g. https://lab.llvm.org/buildbot/#/builders/179/builds/5050
2022-12-09 15:02:39 +00:00
Valentin Clement
1b41074508
[flang] Embox derived-type when passed to element procedure as passed object
In elemental procedure lowering the passed object is always emboxed. The current code
was not correctly dealing with scalar derived-type used as passed object.

Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D139667
2022-12-09 15:37:56 +01:00
Jean Perier
b013ebe059 [flang] Lower intrinsics to HLFIR part 1
This patch adds support for lowering intrinsics that have no dynamic
optionality aspects to handle and that requires argument to be lowered
to value, addr, or box.

It uses the current intrinsic lowering framework that can be re-used in
HLFIR to start with. HLFIR operations for charater/transformational
intrinsics will be added as needed from an optimization point of view.
The current approach will still create temporary variables for their
value directly in lowering.

Later patch will still need to add:
- support for dynamically optional arguments
- inquires
- "moving" the in memory computation of character and transformational
intrinsics to hlfir.expr. This is not needed from a semantic point of
view, but will help optimizing and will probably be required inside
hlfir.elemental returning characters so that the returned element
type is an hlfir.expr and match the result type of later hlfir.apply.

Differential Revision: https://reviews.llvm.org/D139613
2022-12-09 10:11:37 +01:00
Valentin Clement
ee7a62a306
[flang] Generate iteration shape from passed object
When call an elemental subroutine with a monomorphic or polymorphic
passed object, the iteration shape could not be computed. Use the
passed object to infer the implicit iteration shape so the loop
can be constructed.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D139635
2022-12-09 09:18:37 +01:00
Jeff Niu
1897b67ae8 [flang] Fix flang after MLIR update 2022-12-08 16:22:22 -08:00
Peter Klausler
00a1c6d036 [flang] Restore old unit locking behavior
Rework  the recursive I/O error check on I/O units so that
threads again hold a lock on a unit throughout an I/O statement.
Add an API to the runtime's Lock class implementation for pthreads
to allow detection of solf-deadlock without depending on EDEADLK
or recursive mutexes.

This should fix I/O from OpenMP threads.

Differential Revision: https://reviews.llvm.org/D139477
2022-12-08 08:34:46 -08:00
Valentin Clement
f1307d78c6
[flang] Handle polymorphic passed object in elemental call
The passed object is placed in the passed arguments by semantics.
When the TBP to be called is an elemental subroutine or function it has to be
handled accordingly.

Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D139537
2022-12-08 09:48:17 +01:00
Jean Perier
045365036d [flang] add hlfir.noreassoc codegen
Differential Revision: https://reviews.llvm.org/D139542
2022-12-08 09:33:32 +01:00
Jean Perier
722e960b24 [flang] Add hlfir.as_expr character scalar codegen
Creates a copy of the operand.

Differential Revision: https://reviews.llvm.org/D139533
2022-12-08 09:30:44 +01:00
Kazu Hirata
279166f0a7 [flang] Use std::nullopt instead of llvm::None (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-07 20:10:57 -08:00
Jean Perier
6e3292fba5 [flang] Lower parentheses with hlfir.as_expr and hlfir.no_reassoc
Differential Revision: https://reviews.llvm.org/D139523
2022-12-07 14:45:55 +01:00
Jean Perier
80e5ff775f [flang] add hlfir.no_reassoc definition
Same as fir.no_reassoc but accepts hlfir.expr type. It is needed because
FIR operation can only produce FIR types, and I do not want to change
that for now.

Depends on D139519

Differential Revision: https://reviews.llvm.org/D139520
2022-12-07 14:44:35 +01:00
Jean Perier
cf73faef9b [flang] Add hlfir.as_expr definition
hlfir.as_expr allows taking a value from a character, derived type,
or array expressions. This will allow implementing parentheses.

Combining as_expr + hlfir.associate will allow creating a variable copy
into a new temporary variable.

A later patch will add the ability to "move" a variable into an
expression (to give ownership of the variable storage to the expression,
with the commitment that the variable will not be used anymore).

Differential Revision: https://reviews.llvm.org/D139519
2022-12-07 14:43:45 +01:00
Peixin Qiao
feb9d33a2a [flang] Support codegen for global procedure pointer
This supports the codegen for global procedure pointer in BoxedProcedure
pass. Reset the boxproc type.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138273
2022-12-07 21:24:01 +08:00
Peixin Qiao
7de3c03e80 [flang] Support codegen of procedure pointer component
This supports the codegen for procedure pointer component in
BoxedProcedure pass. Also fix the FIR in ProcedurePointer.md so that
all the cases can be run using `tco` to generate the LLVM IR.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D136842
2022-12-07 21:21:08 +08:00
Valentin Clement
0137123846
[flang] Handle polymorphic passed object in host association
Polymorphic entities are always emboxed. This patch
handles host association of polyrmophic entities as passed object.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D139423
2022-12-07 12:01:18 +01:00
Jean Perier
959de15055 [flang] fir.emboxchar codegen with static length fir.char types
The verifier of fir.emboxchar accepts `fir.char<kind, constant>` types,
but its codegen failed because of a missing cast. It is convenient and
safe to not require making the cast in FIR, so add it in codegen.

Differential Revision: https://reviews.llvm.org/D139514
2022-12-07 11:59:10 +01:00
Jean Perier
82b7a238cf [flang] hlfir.assign default implementation
Add the default unoptimized implementation implementation
of hlfir.assign. It relies on the runtime for array assignment
and always makes a temp of the right hand side for arrays.

Assignment optimization will be done when all HLFIR pieces are in place
and aliasing analysis is available.

Differential Revision: https://reviews.llvm.org/D139426
2022-12-07 09:50:47 +01:00
Jean Perier
1293b5fe5a [flang] turn fatal error into a TODO for FORALL edge-case
See https://github.com/llvm/llvm-project/issues/59337.
This TODO will be implemented as part of HLFIR work
(see https://github.com/llvm/llvm-project/blob/main/flang/docs/HighLevelFIR.md).

Differential Revision: https://reviews.llvm.org/D139410
2022-12-07 09:47:33 +01:00
Valentin Clement
13cde1129e
[flang] Support fir.class in scalar user defined assignment lowering
Support fir.class in genScalarUserDefinedAssignmentCall so
emboxing is done correctly.

Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D139435
2022-12-06 22:02:25 +01:00
Valentin Clement
11760b3a27
[flang] Set correct box type when emboxing temporary in array value copy pass
In some cases, the base type is already a fir.box type. This patch updates
the code to set the result box type to fir.box<T>, where T is the type
of the allocated temp.

This was reported in https://github.com/llvm/llvm-project/issues/59342

Reviewed By: jeanPerier, tblah

Differential Revision: https://reviews.llvm.org/D139401
2022-12-06 15:02:35 +01:00
Jean Perier
788960d628 [flang] Allow conversion from hlfir.expr to fir::ExtendedValue
For now at least, the plan is to keep hlfir.expr usage limited as
sub-expression operand, assignment rhs, and a few other contexts (
e.g. Associate statements). The rest of lowering (statements lowering
in the bridge) will still expect to get and manipulate characters and
arrays in memory. That means that hlfir.expr must be converted to
variable in converter.genExprAddr/converter.genExprBox.

This is done using an hlfir.associate, and generating the related
hlfir.end_associate in the statement context.

hlfir::getFirBase of is updated to avoid bringing in the HLFIR
fir.boxchar/fir.box into FIR when the entity was created with
hlfir::AssociateOp.

Differential Revision: https://reviews.llvm.org/D139328
2022-12-06 13:53:16 +01:00
Jean Perier
9b9a8475d3 [flang] do not generate padding/truncation code when character length are equals
When generating character assignment operations, the generic code
generates some code to handle truncation and padding when the length
differ at runtime. A bypass already exists when the length are compile
time constant and match, but it was not used for the trivial case where
the RHS and LHS length is the same SSA value. In such case, even though,
the length is not know at compile time, it is known to be the same.

This will simplify the code creating character temporaries from a
variable in HLFIR that will use this assignment code.

Note that this probably has little impact on performance (llvm may be clever enough
to later catch that for us). But it makes the generated IR a lot more readable at
little cost.

Differential Revision: https://reviews.llvm.org/D139330
2022-12-06 09:34:13 +01:00
Tarun Prabhu
7fe4abbbc2 [flang] Lower F08 NORM2 intrinsic
The implementation follows the pattern used in comparable intrinsics.
Change the runtime API for Norm2 so it does not expect a mask argument
since the Norm2 intrinsic does not accept a mask in Fortran.

Differential Revision: https://reviews.llvm.org/D138150
2022-12-05 13:53:35 -07:00
Peter Steinfeld
a43319a8ad [Flang] Restore Flang cmake configuration data
Patch D138274 removed some Flang cmake configuration information that we
need for our internal builds.  This change restores them.

Differential Revision: https://reviews.llvm.org/D139355
2022-12-05 12:35:50 -08:00
Peter Klausler
962863d988 [flang] Catch attempts to copy pointers in allocatables in PURE
In a pure context, a pointer acquired from an INTENT(IN) dummy argument
may not be copied.  Catch the case in which the pointer is a component
of an allocatable component at some depth of nesting.

(This patch adds a new component iterator kind that is a variant of
a potential subobject component iterator; it visits all potential
subobject components, plus pointers, into which it does not descend.)

Differential Revision: https://reviews.llvm.org/D139161
2022-12-05 10:18:06 -08:00
Peter Klausler
b90ebbc5bd [flang] Fold the RHS of assignment
In order to emit overflow warnings from assignment statements whose
right-hand sides are constants that undergo conversions, run the
right-hand sides of assignments through constant folding after the
conversions have been made explicit in expression analysis.

Differential Revision: https://reviews.llvm.org/D139151
2022-12-05 09:31:32 -08:00
Valentin Clement
491b6a9ccb
[flang] Fix pointer association with remap on polymorphic entities
Runtime is expecting a 1d array. This patch fixes the generation
of the array holding the bounds to be passed to the runtime function call.

Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D139324
2022-12-05 18:29:06 +01:00
Valentin Clement
87dfec9dc8
[flang] Retrieve rank before updating the pointer
The code is iterating on the rank of the pointer to set the bounds.
If the rank is retrieved after the `pointer = target` it does not
reflect the actual rank of the pointer.

This could happen in code like the following:

```
type t1
  integer :: a
end type

type(t), pointer :: p(:)
class(t), pointer :: q(:,:)
q(0:1,-2:2) => p(10:1:-1)
```

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D139327
2022-12-05 18:27:19 +01:00
Peter Klausler
9e855a6cb8 [flang] Map symbols in expressions when copying interface symbols
Given a MODULE SUBROUTINE or MODULE FUNCTION interface followed
later by a corresponding separate module subprogram definition in a
MODULE PROCEDURE, the copies of the interface's dummy argument and
function result symbols that populate the initial scope of that
MODULE PROCEDURE need to have any symbol references in their types
or bounds adjusted to point to their new counterparts.

Differential Revision: https://reviews.llvm.org/D139200
2022-12-05 07:33:57 -08:00
Samira Bazuzi
6e08ac8dce [flang][NFC] Add a no-arg constructor for Verbatim.
In C++20, types that declare or delete any constructors are no longer aggregates, breaking compilation of many existing uses of aggregate initialization.

Although `Verbatim` declares itself to not have a no-arg default constructor, this is circumvented in `basic-parsers.h` which returns a `RESULT{}` a.k.a. `Verbatim{}`. Adding the no-arg constructor while still deleting the copy/assignment constructors maintains the current state and also supports eventually building this in c++20 mode.

Fix suggested in https://discourse.llvm.org/t/build-failure-when-attempting-to-build-flang-with-c-20/66953.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D139228
2022-12-05 07:30:30 -08:00
Haojian Wu
2ef8fd8a69 An iwyu cleanup in flang/Frontend/TargetOptions.h 2022-12-05 14:19:17 +01:00
Valentin Clement
019bec8c8a
[flang][NFC] Remove implemented TODOs 2022-12-05 10:32:08 +01:00
Valentin Clement
42b21ddaad
[flang] Pointer assignment with remapping involcing polymorphic entities
Lower pointer assignment with remapping involving polymorphic entities
to runtime call to PointerAssociateRemapping.
For the time being all pointer assignment involcing polymorphic entities are
done with the runtime call. When lhs is not unlimited polymorphic
we might be able to do it inlined as well.

Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D139198
2022-12-05 09:36:11 +01:00
Jean Perier
1981116548 [flang] Lower function return to HLFIR
The only special thing that is needed is to update the bridge symbol
lookup to deal with the HLFIR symbol lookup (symbols are mapped to
fir::FortranVariableInterface operations, not Fortran::Lower::SymbolBox).

Differential Revision: https://reviews.llvm.org/D139201
2022-12-05 09:06:32 +01:00
Fangrui Song
a996cc217c Remove unused #include "llvm/ADT/Optional.h" 2022-12-05 06:31:11 +00:00
Qihan Cai
d9df5bb8cf [flang] Diagnostic for shape argument in c_f_pointer
Fix #59177, add check for dimensionality for shape argument against rank of FPTR argument in c_f_pointer

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D138743
2022-12-05 14:09:04 +11:00
Peter Klausler
4b7428e151 [flang] Don't propagate PRIVATE into submodule module files
Module files for submodules should not contain PRIVATE attributes,
since everything in them is local to the parent module and
accessible to all descendant submodules.

Differential Revision: https://reviews.llvm.org/D139160
2022-12-04 17:00:13 -08:00
Peter Klausler
2577cb7a20 [flang] Check restrictions on TRANSFER()
Enforce detectable compilation-time violations of restrictions on the
arguments to the TRANSFER() intrinsic function (16.9.163) with
error messages, and mark other potential problems with warnings.

Differential Revision: https://reviews.llvm.org/D139157
2022-12-04 15:29:12 -08:00
Kazu Hirata
7f773ce6fc [flang] Use std::nullopt instead of None (NFC)
I've verified that every single instance of std::nullopt in this patch
affects generated files and would reduce the number of warnings if
None were deprecated.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-04 14:40:10 -08:00
Kazu Hirata
8d6589cba7 [flang] Use std::nullopt instead of None (NFC)
I've verified that every change in this patch affects generated files
and would reduce the number of warnings if None were deprecated.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-04 13:52:47 -08:00
Fangrui Song
12f6ac39bc [flang] Fix pgoOpt 2022-12-04 21:29:00 +00:00
Peter Klausler
af54b676e4 [flang] Emit errors and warnings about DIM= arguments to intrinsic functions
The semantics of many transformational intrinsic functions, especially
reductions like SUM(), are determined by the static presence or absence
of a DIM= argument.  In the case of an actual DIM= argument that is
syntactically present but could be dynamically absent at execution time
(due to being OPTIONAL, POINTER, or ALLOCATABLE), f18 should emit some
kind of diagnostic message.

Other compilers either ignore this possibility or treat it as a hard
error; neither really seems correct, so let's do something more nuanced.

For cases where the dynamic absence of a value for DIM doesn't pose
as much of a risk because it lowering is going to assume that it's
equal to 1 anyway, emit only a portability warning.

For other cases where the generated code or runtime support library
will need the value of DIM= during execution, emit a warning that
the use of an OPTIONAL/POINTER/ALLOCATABLE variable or component
here is dicey and should be reconsidered.

While here, also catch bad constant DIM= values.

Differential Revision: https://reviews.llvm.org/D139155
2022-12-04 13:04:36 -08:00
Peter Klausler
faa1338ccd [flang] Check constraint C834 on INTENT(OUT) assumed-size dummy arrays
An assumed-size dummy array argument with INTENT(OUT) can't have a type
that might require any runtime (re)initialization, since the size of the
array is not known.

Differential Revision: https://reviews.llvm.org/D139149
2022-12-04 10:38:42 -08:00
Kazu Hirata
63b63c3dcd [flang/unittests] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03 19:08:01 -08:00
Peter Klausler
dc0d56febb [flang] Warn about local names that are the same as their enclosing program unit
Modules, submodules, main programs, and BLOCK DATA subprograms have names
that cannot be used within their scope, so we allow those names to be
used for other entities in the scope.  This might not be entirely
conformant with the language standard, so warn about it.

Differential Revision: https://reviews.llvm.org/D139146
2022-12-03 17:47:35 -08:00
Peter Klausler
e86e2ab973 [flang] More error checking for ASSOCIATED()
The TARGET= argument of the ASSOCIATED() intrinsic function must be a valid
pointer assignment statement target.  Ensure that it does not contain a vector
subscript or any coindexing, either of which would imply a data copy into
temporary storage.

Differential Revision: https://reviews.llvm.org/D139145
2022-12-03 17:42:43 -08:00
Peter Klausler
9c1ad89d0e [flang] Emit portability warning for assigned FORMAT use
Emit a portability warning about usage of a deprecated feature
when an I/O data transfer statement uses a scalar integer
variable as an assigned format.

Differential Revision: https://reviews.llvm.org/D139144
2022-12-03 16:29:17 -08:00
Peter Klausler
066aecff92 [flang] INTENT(IN) pointer may not be forwarded to INTENT(IN OUT) or (OUT) dummy
19.6.8 forbids using an INTENT(IN) pointer dummy argument in a pointer association
context, and associated such a pointer with a dummy argument of INTENT(IN OUT) or
INTENT(OUT) is a circumstance that needs to be caught as an error.

Differential Revision: https://reviews.llvm.org/D139138
2022-12-03 16:28:17 -08:00
Peter Klausler
1623aee41a [flang] Check constraint C1577 for statement functions
Check most of the requiremens of constraint C1577 for statement functions.
The restrictions that prevent recursion are hard errors; the others seem
to be benign legacies and are caught as portability warnings.

Differential Revision: https://reviews.llvm.org/D139136
2022-12-03 15:43:47 -08:00
Peter Klausler
bb7e31bccf [flang] Don't repeat module procedure interface from ancestor in *.mod file
When a submodule defines a module procedure whose interface was declared
in an ancestor (sub)module, don't repeat the definition of that interface
in the submodule's *.mod file output.

Differential Revision: https://reviews.llvm.org/D139132
2022-12-03 13:39:33 -08:00
Peter Klausler
9114ce4d1d [flang] Take character function length into account when testing compatibility
When a character-valued function is passed as an actual argument, and both
the actual function and the dummy argument have explicit result lengths, take them
into account when testing for compatibility.

Differential Revision: https://reviews.llvm.org/D139129
2022-12-03 12:35:23 -08:00
Kazu Hirata
9a41739565 [flang] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03 12:14:21 -08:00
Peter Klausler
32332909f4 [flang] Disable flang/test/Semantics/resolve110.f90 on Windows
This test crashes Semantics (infinite recursion?) only when built with MSVC;
need to investigate further, disabling test for now.
2022-12-03 11:23:17 -08:00
Peter Klausler
fee041f69d [flang] Document and warn about an extension
Standard Fortran allows type-bound procedure bindings to only
be called, and disallows them from being used in other contexts
where a procedure name can be: as the target of a procedure pointer
assignment statement, and as an actual argument that corresponds
to a dummy procedure.  So long as the interfaces match, there's
no good reason for these uses to be errors, and there some obvious
use cases in polymorphic programming.  So emit portability warnings
rather than errors, and document this usage as an extension.

Differential Revision: https://reviews.llvm.org/D139127
2022-12-03 11:09:59 -08:00
Peter Klausler
d7a1351bb8 [flang] Enforce accessibility requirement on type-bound generic operators, &c.
Type-bound generics like operator(+) and assignment(=) need to not be
PRIVATE if they are used outside the module in which they are declared.

Differential Revision: https://reviews.llvm.org/D139123
2022-12-03 10:12:58 -08:00
Peter Klausler
7d147a3263 [flang] Warn on missing colons (C768)
In a derived type definition, a type bound procedure declaration
statement with neither interface nor attributes is required by constraint
C768 to have the optional "::" between the PROCEDURE keyword and the
bindings if any binding has a renaming with "=>".  The colons are
not actually necessary for a correct and unambiguous parse, so
emit a warning when they are missing.

Differential Revision: https://reviews.llvm.org/D139065
2022-12-03 09:27:39 -08:00
Peter Klausler
2f999cce19 [flang] Respect function vs subroutine distinction in generic matching
When checking the specific procedures of a generic interface for a
match against a given set of actual arguments, be sure to not match
a function against a subroutine call or vice versa.  (We generally
catch and warn about attempts to declare mixed interfaces, but they
are usually conforming and can be inadvertently created when generics
are merged due to USE and host association.)

Differential Revision: https://reviews.llvm.org/D139059
2022-12-03 07:53:04 -08:00
Peter Klausler
8a1f12c6fb [flang] Warn about more continuation lines than the standard permits
f18 doesn't have any limit on continuation lines in fixed or free form
source (other than available memory), but the standard does.  Emit
a portability warning when it is exceeded.

Differential Revision: https://reviews.llvm.org/D139055
2022-12-02 17:07:11 -08:00
Peter Klausler
629a29cacc [flang][examples] Fix build of flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp (take 2)
Need to add casts to std::string.
2022-12-02 16:15:20 -08:00
Peter Klausler
5ea0ba2c13 [flang] Enforce more restrictions on I/O data list items
12.6.3p5 requires an I/O data list item to have a defined I/O procedure
if it is polymorphic.  (We could defer this checking to the runtime,
but no other Fortran compiler does so, and we would also have to be
able to catch the case of an allocatable or pointer direct component
in the absence of a defined I/O subroutine.)

Also includes a patch to name resolution that ensures that a
SELECT TYPE construct entity is polymorphic in the domain of a
CLASS IS guard.

Also ensures that non-defined I/O of types with PRIVATE components
is caught.

Differential Revision: https://reviews.llvm.org/D139050
2022-12-02 16:10:52 -08:00
Peter Klausler
bc83d1c655 [flang] Enforce restrictions on intrinsic assignment
When the left-hand side of an intrinsic assignment statement is
polymorphic, the LHS must be a whole allocatable variable or
component and may not be a coarray (10.2.2.1p1(1)).

Differential Revision: https://reviews.llvm.org/D139049
2022-12-02 15:23:38 -08:00
Peter Klausler
8d23614a29 [flang] Disallow NULL() as an expression where it cannot appear
A NULL() pointer is generally not a valid expression (as opposed to
a variable) apart from some initialization contexts and some actual
arguments.

Differential Revision: https://reviews.llvm.org/D139047
2022-12-02 14:36:51 -08:00
Peter Klausler
56b7db9e07 [flang] Change error to portability warning
The standard does *not* require that a real or imaginary part of a complex
literal constant be a scalar if it is a named constant.  Downgrade a
recently installed check to a portability warning, and document it.

Differential Revision: https://reviews.llvm.org/D139046
2022-12-02 13:45:41 -08:00
River Riddle
b74192b7ae [mlir] Remove support for non-prefixed accessors
This finishes off a year long pursuit to LLVMify the generated
operation accessors, prefixing them with get/set. Support for
any other accessor naming is fully removed after this commit.

https://discourse.llvm.org/t/psa-raw-accessors-are-being-removed/65629

Differential Revision: https://reviews.llvm.org/D136727
2022-12-02 13:32:36 -08:00
Peter Klausler
7efec1a40a [flang] Don't emit spurious error for polymorphic actual argument in PURE
Definability checking is unconditionally flagging the use of a polymorphic
variable as an actual argument for a procedure reference in a PURE subprogram
unless the corresponding dummy is INTENT(IN).  This isn't necessary, since
an INTENT(OUT) polymorphic dummy is already caught as an error in the definition
of the callee, which must also be PURE; and an INTENT(IN OUT) or intent-free
dummy is allowed to be passed a polymorphic actual in a PURE context, with
any attempt to deallocate it being caught in the callee.

So add a flag to the definability checker to disable the "polymorphic
definition in PURE context" check when using it to check actual arguments.

Differential Revision: https://reviews.llvm.org/D139044
2022-12-02 13:17:06 -08:00
Peter Klausler
745f6fcd2b [flang][examples] Fix usage of EnumToString()
EnumToString() now returns a string_view; usage in
  examples/FlangOmpReport/FlangOmpReportVisitor.cpp
needs to be updated.  Pushing without review to get
flang build bots back up.
2022-12-02 13:16:40 -08:00
Peter Klausler
78da80e2ef [flang] Restore C702 check for ProcEntity symbols
A recent change moved some checking code from name resolution into
declaration checking, and inadvertently disabled C702 checking for
procedure entities.  Fix.

Differential Revision: https://reviews.llvm.org/D139043
2022-12-02 12:06:49 -08:00
Peter Klausler
0d58834700 [flang] Check discrepancies between local & available global subprograms
When a scope declares the name and perhaps some characteristics of
an external subprogram using any of the many means that Fortran supplies
for doing such a thing, and that external subprogram's definition is
available, check the local declaration against the external definition.
In particular, if the global definition's interface cannot be called
by means of an implicit interface, ensure that references are via an
explicit and compatible interface.

Further, extend call site checking so that when a local declaration
exists for a known global symbol and the arguments are valid for that
local declaration, the arguments are checked against the global's
interface, just are is already done when no local declaration exists.

Differential Revision: https://reviews.llvm.org/D139042
2022-12-02 11:11:31 -08:00
Peter Klausler
01688ee9df [flang] Accommodate unknowable CHARACTER length in evaluate::ArrayConstructor<>
The internal representation for array constructors in expressions during semantic
analysis needs to be able to accommodate circumstances (e.g. TRIM(), substrings)
in which the length of the elements in the array is either unknown or cannot be
represented as a context-free integer expression.

Differential Revision: https://reviews.llvm.org/D139041
2022-12-02 10:37:28 -08:00
Peter Klausler
bcba39a56f [flang] Restore ENUM_CLASS() to be compilation-time code
Rework some recent changes to the ENUM_CLASS() macro so that
all of the construction of enumerator-to-name string mapping
data structures is again performed at compilation time.

Differential Revision: https://reviews.llvm.org/D137859
2022-12-02 09:55:45 -08:00
Usman Nadeem
3951a73490 [Flang][Driver] Handle target CPU and features
This patch:

- Adds target-feature and target-cpu to FC1Options.
- Moves getTargetFeatures() from Clang.cpp to CommonArgs.cpp.
- Processes target cpu and features in the flang driver. Right now
  features are only added for AArch64/x86 because I only did basic
  testing on them but it should generally work for others as well.
  Option handling is similar to clang.
- Adds appropriate structures in TargetOptions and passes them to
  the target machine.

What's missing:

- Adding the CPU info and the features as attributes in the LLVM IR
  module.
- Processing target specific flags, e.g. SVE vector bits for AArch64,
  ABI etc.

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

Change-Id: Ib081a74ea98617674845518a5d2754edba596418
2022-12-02 09:37:53 -08:00
Jean Perier
655d994adc [flang] fix unused-but-set-parameter warning in ConvertExprToHLFIR.cpp
Some named value operands are not used yet (TODOs). Some compilers
complain about it. Remove names of unused parameters.

Differential Revision: https://reviews.llvm.org/D139207
2022-12-02 17:57:12 +01:00
Jean Perier
f24466cf62 [flang] Lower conversions to HLFIR
Differential Revision: https://reviews.llvm.org/D139196
2022-12-02 16:19:38 +01:00
Valentin Clement
f8ea349a6d
[flang] Perform assignment to polymorphic allocatable with runtime call
Lower assignment to polymorphic allocatable to the `Assign` runtime
call.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D139192
2022-12-02 15:51:20 +01:00
Jean Perier
ffdb5f951c [flang] add missing unreachable in D139179
Fix bot failure https://lab.llvm.org/buildbot/#/builders/160/builds/13647
caused by https://reviews.llvm.org/D139179.

Even if the switch is fully covering, adding an unreachable after is
required to cover all path since the switch argument could be a broken
value that does not belong to the enum.
2022-12-02 05:46:22 -08:00
Jean Perier
12c8797fc4 [flang] Lower unary operation to HLFIR
Lower not, negate, and complex component to HLFIR.
Parentheses is the only remaining operation, but needs some
care/thinking to properly deal with character/derived variables.

Differential Revision: https://reviews.llvm.org/D139186
2022-12-02 14:22:41 +01:00
Jean Perier
fed3d272da [flang] Make SetLength TODO explicit in HLFIR
evaluate::SetLength is the last intrinsic binary operation
that needs to be lowered to HLFIR. It will require an hlfir.set_length
op or hlfir.as_expr to convert the result to an expression. Add a TODO
for now.

Differential Revision: https://reviews.llvm.org/D139183
2022-12-02 14:21:27 +01:00
Jean Perier
26ceeee757 [flang] Lower complex constructor to HLFIR
Differential Revision: https://reviews.llvm.org/D139180
2022-12-02 14:20:22 +01:00
Jean Perier
248fcb13be [flang] Lower logical operations to HLFIR
Differential Revision: https://reviews.llvm.org/D139179
2022-12-02 14:19:12 +01:00
Jean Perier
12530711fc [flang] Lower relational to HLFIR
Differential Revision: https://reviews.llvm.org/D139176
2022-12-02 14:18:10 +01:00
Valentin Clement
c44292f15b
[flang] Enable character type guard in select type
SELECT TYPE lower and conversion was not handling
`character` type guard. This add support for it.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D139106
2022-12-02 09:53:48 +01:00
Jean Perier
991a90a00d [flang] Lower evaluate::Extremum
Update BinaryOp<T>::gen so that const T& is threaded and some
operation knowledge that is not encoded by the type T or the arguments
can be used. For Extremum, it is the order (Greater or Lesser) that is
required, but this will also be required for evaluate::Relational.

Differential Revision: https://reviews.llvm.org/D139124
2022-12-02 09:29:39 +01:00
Slava Zakharin
68755f223f Revert "[flang] Use proper attributes for runtime calls with 'i1' arguments/returns."
This reverts commit d5b0de35bd.
2022-12-01 10:32:33 -08:00
Jean Perier
319f0221ee [flang] hlfir.associate and hlfir.end_associate codegen
Add hlfir.associate and hlfir.end_associate codegen.
To properly allow reusing the bufferized expression storage for the
newly created variable, bufferization of hlfir.expr has to be updated
so that hlfir.expr are translated to a variable and a boolean to
indicate if the variable storage needs to be freed after the expression
was used. That way the responsibility to free the bufferized expression
can be passed to the variable user, and applied in the
hlfir.end_associate.

Right now, not of the bufferized expression are heap allocated, so
generating the conditional freemem in hlfir.end_associate is left as
a TODO for when it can be tested.

Differential Revision: https://reviews.llvm.org/D139020
2022-12-01 17:58:28 +01:00
Jean Perier
89af7de9de [flang] Lower power to HLFIR
Differential Revision: https://reviews.llvm.org/D139117
2022-12-01 17:49:36 +01:00
Jean Perier
440e9baa62 [flang] Lower add, mul, div, and sub to HLFIR
Only lower operations when the operands are scalar for now.

Differential Revision: https://reviews.llvm.org/D139108
2022-12-01 17:39:53 +01:00
Valentin Clement
6008520b14
[flang][NFC] Remove debugging line in convert op
This line should not have made it to the final patch.
2022-12-01 15:25:43 +01:00
Valentin Clement
d4d4942911
[flang] Avoid verifier error when emboxing trivial type to unlimited polymorphic entity
Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138989
2022-12-01 14:27:30 +01:00
Jean Perier
e78e4a1761 [flang] lower F77 calls in HLFIR
Use recently added hlfir.associate/hlfir.end_associate to deal
with the cases where the actual argument is an expression.

Differential Revision: https://reviews.llvm.org/D139009
2022-12-01 11:22:38 +01:00
Valentin Clement
ef06327063
[flang] Make sure PointerNullifyDerived is called on pointer array
Record type was not correctly retrived so the runtime call was not
produced correctly.
Fix how the record type is retrived so the correct call is
produced.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D139084
2022-12-01 11:18:28 +01:00
Valentin Clement
131585ab0f
[flang] Use genExprBox for the rhs when calling PointerAssociate for unlimited polymorphic pointer
In D139019 the assumption was made that the rhs was also the MutableBox
but this is not a constraint. Use genExprBox instead. Also the allowed
conversion in D139019 was not correct. Remoed it since it is not needed anymore.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D139081
2022-12-01 11:12:24 +01:00
Slava Zakharin
d5b0de35bd [flang] Use proper attributes for runtime calls with 'i1' arguments/returns.
Clang uses signext/zeroext attributes for integer arguments shorter than
the default 'int' type on a target. So Flang has to match this for functions
from Fortran runtime and also for BIND(C) routines. This patch implements
ABI adjustments only for Fortran runtime calls. BIND(C) part will be done
separately.

This resolves https://github.com/llvm/llvm-project/issues/58579

Differential Revision: https://reviews.llvm.org/D137050
2022-11-30 11:51:34 -08:00
Valentin Clement
abefd87e70
[flang] Delegate pointer association to class(*) pointer to the runtime
Pointer association with an unlimited polymorphic pointer on the lhs
requires more than just updating the base_addr. Delegate the association to
the runtime function `PointerAssociation`.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D139019
2022-11-30 18:57:57 +01:00
Valentin Clement
1bd0ff7a90
[flang] Allow non polymorphic pointer assignment with polymorphic rhs
Remove the TODO and allow pointer assignment with non
polymorphic entity on the lhs. The assignment follow the same scheme
as derived-type pointer assignment to parent component.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138998
2022-11-30 15:53:34 +01:00
Jean Perier
d71c1de0ff [flang][NFC] add genType(FunctionRef<T>) entry points in lowering
This will help lowering to HLFIR to not use the AsGenericExpr/AsExpr
patterns that copies sub-expresssions into evaluate::SomeExpr so that
they can be passed to helpers. Sub-expressions like FunctionRef can
be heavy (hundreds of arguments, constant array expression arguments...).

Differential Revision: https://reviews.llvm.org/D138997
2022-11-30 14:44:27 +01:00
Jean Perier
6eb8ee9835 [flang] Add hlfir.associate and hlfir.end_associate definitions
These operations allow creating an HLFIR variable from a HLFIR value and
destroying it at the end of the variable lifetime.
This will both be used to implement procedure reference arguments association
when the actual is an expression, and to implement the Fortran associate
construct when the associated entity is an expression.

See https://github.com/llvm/llvm-project/blob/main/flang/docs/HighLevelFIR.md
for more details.

Differential Revision: https://reviews.llvm.org/D138996
2022-11-30 13:43:56 +01:00
Muhammad Omair Javaid
c687c2cce5 [FLANG] Fix MSVC + clang-cl build
Flang build on windows with MSVC environment and clang-cl compiler
requires clang_rt.builtin.${target} library. This patch allows us to
locate and include this link library. This is mostly needed for flang
runtime and associated unittests as it requires the uint128 division
builtin function __udivti3.

Reviewed By: DavidTruby

Differential Revision: https://reviews.llvm.org/D138023
2022-11-30 16:29:26 +05:00
Tom Eccles
3a1b409254 [flang] fix unused variables 2022-11-30 10:37:23 +00:00
Valentin Clement
b9e53b96e0
[flang] Handle polymorphic value when creating temporary
Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138921
2022-11-30 09:58:57 +01:00
Valentin Clement
aa47103898
[flang] Use BaseBoxType in component by component assignment
Use BaseBoxType in `genComponentByComponentAssignment`
so the component by component assignment involving polymorphic entities
does not fall back to scalar assignment.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138927
2022-11-29 20:45:05 +01:00
Kelvin Li
b42cb2d601 [flang][doc] Remove DCMPLX intrinsic from the Intrinsic Procedures Lacking Support list
Differential Revision: https://reviews.llvm.org/D138848
2022-11-29 14:15:02 -05:00
Kelvin Li
93196654f5 [flang] Add support for LSHIFT and RSHIFT intrinsics
The functionality of LSHIFT and RSHIFT intrinsics is the same as the
standard SHIFTL and SHIFTA intrinsics respectively. The patch is to
alias the two intrinsics to the standardized ones.

Differential Revision: https://reviews.llvm.org/D138839
2022-11-29 14:03:31 -05:00
Tarun Prabhu
d43a2f09de [flang] Lower F08 FINDLOC intrinsic
The implementation follows the patterns established by the lowering of other
similar intrinsics.

In addition to the code for lowering, the DoTotalReduction template had to be
fixed to correctly break when signaled to do so by the accumulator function.

Differential Revision: https://reviews.llvm.org/D138140
2022-11-29 10:18:38 -07:00
Tom Eccles
6841c43f36 [flang] Remove warnings that fast-math options are unimplemented
These are now fully implemented, see
https://reviews.llvm.org/D137390
https://reviews.llvm.org/D137391
https://reviews.llvm.org/D137456
https://reviews.llvm.org/D137580
https://reviews.llvm.org/D137602
https://reviews.llvm.org/D138048

These flags are still tested in
flang/test/Driver/frontend-forwarding.f90 and
flang/test/Lower/fast-math-arithmetic.f90

Differential revision: https://reviews.llvm.org/D138907
2022-11-29 17:15:05 +00:00
Valentin Clement
391efeb538
[flang][NFC] Retrieve binding table from fir.dispatch_table operations
Change how the binding tables are retrived. Use the newly lowered
fir.dispatch_table operations instead of the fir.global type infos.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138903
2022-11-29 13:22:16 +01:00
Qihan Cai
1147e70e7e [flang] Enable RISC-V for x86CompatibleBehavior in floating point flag
Fixes #59132 by mitigating the behavior of not setting underflow flag on RISC-V platform.

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D138503
2022-11-29 21:15:19 +11:00
Usman Nadeem
54dc764db7 [Flang][Test] Add support to change the default target triple for tests
In this patch I added support to change the default target triple used
by flang tests using the cmake variable: FLANG_TEST_TARGET_TRIPLE.

This functionality is implemented using the LLVM_TARGET_TRIPLE_ENV
variable, so that must be defined as well.

An example use:
`-DLLVM_TARGET_TRIPLE_ENV="LLVM_TARGET_TRIPLE_ENV" -DFLANG_TEST_TARGET_TRIPLE="aarch64-linux-gnu"`

Differential revision: https://reviews.llvm.org/D138530

Change-Id: I38e4a46a65109d415a9b72c8a0bf8a955e937280
2022-11-28 16:02:22 -08:00
Qihan Cai
bac88e898f [flang] Add RISCV-64 support to Optimizer/CodeGen/Target.cpp
As an attempt to fix errors in Flang regression tests on RISCV64 platform, RISCV64 target was added, and subsequent tests were provided.

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D136547
2022-11-29 09:49:26 +11:00
Valentin Clement
545db9c41f
[flang] Handle polymorphic argument when expecting boxed derived-type
Perform a rebox instead of a convert operation when the input type is
polymorphic and the output type is a boxed derived-type.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138831
2022-11-28 20:56:27 +01:00
Valentin Clement
1ea66eefec
[flang] Adapt target rewrite for fir.dispatch operation
Handle rewriting dispatch operation with complex arguments or
return.

sret will be done in a separate patch.

Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138820
2022-11-28 17:36:03 +01:00
Valentin Clement
afb34cf307
[flang] Hanlde disptach op in abstract result pass
Update the call conversion pattern to support fir.dispatch
operation as well. The first operand of fir.dispatch op is always the
polymoprhic object. The pass_arg_pos attribute needs to be shifted when
the result is added as argument.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138799
2022-11-28 16:49:51 +01:00
Thomas Preud'homme
ecfa2d3d99 Add version to all LLVM cmake package
Add a version to non-LLVM cmake package so that users needing an exact
version match can use the version parameter to find_package. Also adjust
the find_package(LLVM) to use an exact version match as well.

Reviewed By: arsenm, stellaraccident, mceier

Differential Revision: https://reviews.llvm.org/D138274
2022-11-25 21:57:58 +00:00
Valentin Clement
e6319cdcb9
[flang] Update fir.dispatch op lowering for tbp with character result
Take into account the result passed as arguments when computing
the pass object index.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138712
2022-11-25 21:25:09 +01:00
Valentin Clement
e1eb81f470
[flang] Allow fir.rebox to unlimited polymorphic box
This patch relaxes the verifier for the fir.rebox operation
to allow reboxing to unlimited polymoprhic box.

Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138695
2022-11-25 14:42:51 +01:00
Valentin Clement
8d692b4b8d
[flang] Avoid crash in lowering for unlimited polymorphic function return
The dynamic type of an unlimited polymorphic entity has the
derived category but does not have derived type spec. This leads
to a crash for a nullptr dereference. This patch avoids this crash
by checking if that the dynamic type is not unlimited polymorphic
before dereferencing the derived type spec.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138691
2022-11-25 13:47:50 +01:00
Thomas Preud'homme
b62c8d396f Revert: Add version to all LLVM cmake package
Summary: This reverts commit ad485b71b5.

Reviewers:

Subscribers:
2022-11-25 10:54:58 +00:00
Jean Perier
36f61d14fb [flang] Add hlfir.concat codegen
hlfir.concat codegen happens in the "bufferization" pass: the pass
that place hlfir.expr in memory and transform all operations producing
or accepting hlfir.expr arguments into operations operating on memory.
Since this pass gets rid of the hlfir.expr type, this is a full
translation pass.

So far hlfir.concat codegen re-uses the current concatenation lowering helper
and only supports concatenation of two strings at a time. This matches
what lowering to HLFIR without any optimization produces. More optimized
versions will be developed later.

Differential Revision: https://reviews.llvm.org/D138673
2022-11-25 09:39:39 +01:00
Jean Perier
94b9fbabe8 [flang] Lower concatenation to hlfir.concat
Differential Revision: https://reviews.llvm.org/D138664
2022-11-25 09:36:58 +01:00
Jean Perier
8dea00f4e7 [flang] Add hlfir.concat operation definition
This operation represents scalar character concatenation. This is
added as part of flang lowering update described in
https://github.com/llvm/llvm-project/blob/main/flang/docs/HighLevelFIR.md

A notable difference with Fortran concatenation is that hlfir.concat can
take two or more operands. This will be used to optimize concatenation
chains.

Differential Revision: https://reviews.llvm.org/D138650
2022-11-25 09:34:15 +01:00
Valentin Clement
fa3587d63e
[flang] Remove debug option
Remove debug option added by mistake in D138587
2022-11-25 09:30:17 +01:00
Evgeniy Brevnov
721f975d35 Use PassGate from LLVMContext if any otherwise global one
Differential Revision: https://reviews.llvm.org/D137149
2022-11-25 15:13:04 +07:00
Valentin Clement
c1b7e9c962
[flang] Adapt descriptor codegen to support unlimited polymorphic entities
Code generation to create and populate the descriptor (element size and
type code) is based on the boxed result type. This does not work well with
unlimited polymorphic entities since the fir type does not represent what is
actually emboxed or reboxed.
In the case of emboxing, the input type will be used to populate
the descriptor element size and type code.
When reboxing an unlimited polymorphic to a unlimited polymorphic entities, the
element size and type code is retrieve from the input box.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138587
2022-11-24 20:47:21 +01:00
Kelvin Li
1094254716 [flang] Lowering LOC intrinsic
This patch is to implement the lowering of the LOC intrinsic.

Differential Revision: https://reviews.llvm.org/D138572
2022-11-24 10:33:27 -05:00
Rainer Orth
dfa7f4ca8b [flang][test] Adjust Driver/pass-plugin-not-found.f90 error message
The `Driver/pass-plugin-not-found.f90` test `FAIL`s on Solaris since part
of the error message differs from what the test expects: Solaris has

  error: unable to load plugin 'X.Y': 'Could not load library 'X.Y':
ld.so.1: flang-new: X.Y: open failed: No such file or directory'

while the test expects

  error: unable to load plugin 'X.Y': 'Could not load library 'X.Y': X.Y:
cannot open shared object file: No such file or directory'

The last part is emitted by the system `dlerror` and is thus unportable.
Hopefully the error text itself is the same everywhere.

The following patch adjusts the expected message accordingly.

Tested on `x86_64-pc-linux-gnu` and `amd64-pc-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D138663
2022-11-24 16:20:33 +01:00
Jean Perier
011b2af0f4 [flang][NFC] move genCallOpAndResult into new ConvertCall.cpp file
Move genCallOpAndResult from ConvertExpr.cpp into a new file so that
it can be shared with lowering to FIR and HLFIR during the transition.
After the transition, call lowering to HLFIR will be implemented in
this new file.

Differential Revision: https://reviews.llvm.org/D138643
2022-11-24 12:38:53 +01:00
Michał Górny
02a2e18e60 [flang] Harmonize standalone gtest support with other projects
Use the CMake rules of unittest libraries via `add_subdirectory()`
when using standalone builds, similarly to how e.g. Clang does that.
Besides making things more consistent, I hope this also unblocks D137035
and effectively we'll be able to simplify things further and have LLVM
semi-automatically include gtest support for us in the future.

Differential Revision: https://reviews.llvm.org/D138573
2022-11-24 03:29:15 +01:00
Michał Górny
58d1988b19 [flang] Fix unittests in standalone build for third-party move
Update external unittest rules for flang standalone builds to account
for the unittest components (gtest, gmock) being moved to `third-party`
directory, in a11cd0d94e.

Differential Revision: https://reviews.llvm.org/D138562
2022-11-23 15:11:09 +01:00
Kelvin Li
0c08418d4b [Flang] Removing Float Bessel functions for AIX
AIX libc only provides bessel functions j0,j1,jn and y0,y1,yn but
does not have their float equivalents j0f,j1f,jnf and y0f,y1f,ynf.

Committed on behalf of madanial

Differential Revision: https://reviews.llvm.org/D136128
2022-11-22 10:43:03 -05:00
Valentin Clement
d38735e601
[flang][NFC] Switch CollectBindings return to SymbolVector
As suggested on D138129, switching rteurn of CollectBindings
function to SymbolVector.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138419
2022-11-22 15:14:03 +01:00
Valentin Clement
9d395e79a6
[flang] Set initial size and type code for unlimited polymorphic descriptor
Initialization of unlimited polymorphic descriptor was raising an error.
This patch sets a default size and type code for unlimited polymoprhic descriptor
that will be updated once allocated/assigned.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138479
2022-11-22 14:48:34 +01:00
Valentin Clement
81bd5e2ef7
Revert "[flang][NFC] Switch CollectBindings return to SymbolVector"
This reverts commit 97e8eeb758.
2022-11-22 10:12:14 +01:00
Valentin Clement
97e8eeb758
[flang][NFC] Switch CollectBindings return to SymbolVector
As suggested on D138129, switching rteurn of CollectBindings
function to SymbolVector.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138419
2022-11-22 09:43:11 +01:00
Valentin Clement
fedf4dcd80
[flang] Do not propagate type desc when box type is not polymorphic
When the rhs is non-polymorphic the type descriptor should not
be propagated. An error in the EmboxOp verifier was raised in that case.
This patch propagate the type descriptor only if the result type of the
EmboxOp operation is polymorphic.

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138442
2022-11-22 09:41:50 +01:00
Valentin Clement
3b257a6373
[flang] Accept BaseBoxType in couple of fir.array_* operations
Couple of operation are expecting BoxType but can totally handle
ClassType as well. This patch updates couple of locations to support
BaseBoxType instead of BoxType only.

Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138422
2022-11-21 16:54:47 +01:00
Aliia Khasanova
399638f98c Merge kDynamicSize and kDynamicSentinel into one constant.
resolve conflicts

Differential Revision: https://reviews.llvm.org/D138282
2022-11-21 13:01:26 +00:00
Jean Perier
ee8c653c21 [flang] Add hlfir.designate codegen for Fortran ArrayRef
Differential Revision: https://reviews.llvm.org/D138198
2022-11-21 10:17:38 +01:00
Valentin Clement
147fe9de29
[flang][NFC] Update TODOs list 2022-11-21 10:05:18 +01:00
Valentin Clement
06b4ce66d8
[flang] Add fir.select_type conversion to if-then-else ladder
Convert fir.select_type operation to an if-then-else ladder.
The type guards are sorted before the conversion so it follows the
execution of SELECT TYPE construct as mentioned in 11.1.11.2 point 4
of the Fortran standard.

Depends on D138279

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138280
2022-11-21 10:01:42 +01:00
Thomas Preud'homme
ad485b71b5 Add version to all LLVM cmake package
Add a version to non-LLVM cmake package so that users needing an exact
version match can use the version parameter to find_package. Also adjust
the find_package(LLVM) to use an exact version match as well.

Reviewed By: arsenm, stellaraccident

Differential Revision: https://reviews.llvm.org/D138274
2022-11-20 21:09:50 +00:00
Peixin Qiao
6ed85a62bd [flang] Support lowering of intrinsic GET_COMMAND
As Fortran 2018 16.9.82, all the arguments of GET_COMMAND are optional.
When they are all absent, do nothing so to be consistent with gfortran
and ifort. The semantic analysis and runtime have been supported.

This intrinsic was introduced from F2003, and this supports the lowering
of it.

Reviewed By: PeteSteinfeld, jeanPerier

Differential Revision: https://reviews.llvm.org/D137887
2022-11-19 19:26:17 +08:00
Slava Zakharin
1dd5ca2452 Revert "[flang] Use proper attributes for runtime calls with 'i1' arguments/returns."
Buildbot might be failing because of this:
https://lab.llvm.org/buildbot/#/builders/65/builds/7283

This reverts commit 396ead93e3.
2022-11-18 20:12:33 -08:00
Peixin Qiao
ae0e5a502b Revert "[flang] Support lowering of intrinsic GET_COMMAND"
This reverts commit 86ea67ed4e.
2022-11-19 11:51:25 +08:00
Peixin Qiao
86ea67ed4e [flang] Support lowering of intrinsic GET_COMMAND
As Fortran 2018 16.9.82, all the arguments of GET_COMMAND are optional.
When they are all absent, do nothing so to be consistent with gfortran
and ifort. The semantic analysis and runtime have been supported.

This intrinsic was introduced from F2003, and this supports the lowering
of it.

Reviewed By: PeteSteinfeld, jeanPerier

Differential Revision: https://reviews.llvm.org/D137887
2022-11-19 11:03:52 +08:00
Jennifer Yu
9d90cf2fca [OPENMP5.1] Initial support for message clause. 2022-11-18 17:59:23 -08:00
Slava Zakharin
396ead93e3 [flang] Use proper attributes for runtime calls with 'i1' arguments/returns.
Clang uses signext/zeroext attributes for integer arguments shorter than
the default 'int' type on a target. So Flang has to match this for functions
from Fortran runtime and also for BIND(C) routines. This patch implements
ABI adjustments only for Fortran runtime calls. BIND(C) part will be done
separately.

This resolves https://github.com/llvm/llvm-project/issues/58579

Differential Revision: https://reviews.llvm.org/D137050
2022-11-18 12:52:57 -08:00
Valentin Clement
8dfd883531
[flang] Add ClassIs runtime function
Add a `ClassIs` function that takes a descriptor and a
type desc to implement the check needed by the CLASS IS type guard
in SELECT TYPE construct.
Since the kind type parameter are directly folded in the type itself
in Flang and the type descriptor is a global, the function just check
if the type descriptor address of the descriptor is equivalent to
the type descriptor address of the global. If not, it check in the
parents of the descriptor's type descriptor.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D138279
2022-11-18 21:17:15 +01:00
Kelvin Li
aaea4e38ab [flang] Add more diagnostic for MAX/MIN intrinsic
Fix https://github.com/llvm/llvm-project/issues/56303

Differential Revision: https://reviews.llvm.org/D137742
2022-11-18 14:37:37 -05:00
Valentin Clement
6f81795fca
[flang][NFC] Remove unused DispatchTableop fct
Remove `appendTableEntry` as it is not used.

Reviewed By: jeanPerier, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D138293
2022-11-18 20:32:43 +01:00