1244 Commits

Author SHA1 Message Date
Peter Klausler
68a27989d0
[flang] Accept and ignore compiler directives between internal subpro… (#89810)
…grams

The parser only recognizes compiler directives that appear within
internal / module subprograms, not those that might appear between them.
Extend to allow them between subprograms as well.
2024-04-24 15:25:19 -07:00
Peter Klausler
0e1bb1d835
[flang] Don't convert actual arguments when interface is implicit (#89795)
When the interface of a procedure is implicit at the point of call,
don't perform actual argument type conversion to the types of the dummy
arguments. This was inadvertently taking place in a case where the
procedure has an implicit interface but was also defined in the same
source file, so that its characteristics were known.
2024-04-24 15:08:22 -07:00
Peter Klausler
c3def59d0f
[flang] Fix bogus error about duplicate binding names (#89786)
Don't call SetBindNameOn() from DeclareUnknownEntity() unless there is
an explicit BIND(C) attribute.

Fixes https://github.com/llvm/llvm-project/issues/89439 and
https://github.com/llvm/llvm-project/issues/89558.
2024-04-24 14:57:00 -07:00
Valentin Clement (バレンタイン クレメン)
49cb6dbcb8
[flang][cuda] Remove restriction on device subprogram (#89677)
Newer version allow `pure`, `elemental` and `recursive` on device
subprogram.
2024-04-23 10:01:26 -07:00
Kiran Chandramohan
0661af893f
[Flang][OpenMP] Add restriction about subobjects to firstprivate and … (#89608)
…lastprivate

OpenMP 5.2 standard (Section 5.3) defines privatization for list items.
Section 3.2.1 in the standard defines list items to exclude variables
that are part of other variables.

This patch adds the restriction to firstprivate and lastprivates, it was
previously added for privates.

Fixes https://github.com/llvm/llvm-project/issues/67227

Note: The specific checks that are added here are explicitly called out
in OpenMP 4.0
(https://www.openmp.org/wp-content/uploads/OpenMP4.0.0.pdf) Sections
2.14.3.4 and 2.14.3.5 but in later standards have become implicit
through other definitions.
2024-04-23 12:56:52 +01:00
Peter Klausler
cb26391968
[flang] Make proc characterization error conditional for generics (#89429)
When the characteristics of a procedure depend on a procedure that
hasn't yet been defined, the compiler currently emits an unconditional
error message. This includes the case of a procedure whose
characteristics depend, perhaps indirectly, on itself. However, in the
case where the characteristics of a procedure are needed to resolve a
generic, we should not emit an error for a hitherto undefined procedure
-- either the call will resolve to another specific procedure, in which
case the error is spurious, or it won't, and then an error will issue
anyway.

Fixes https://github.com/llvm/llvm-project/issues/88677.
2024-04-22 15:21:45 -07:00
Peter Klausler
59bf49a632
[flang] Fix bogus error on statement function (#89402)
When a statement function in a nested scope has a name that clashes with
a name that exists in the host scope, the compiler can handle it
correctly (with a portability warning)... unless the host scope acquired
the name via USE association. Fix.

Fixes https://github.com/llvm/llvm-project/issues/88678.
2024-04-22 15:12:32 -07:00
Peter Klausler
cb1b846eda
[flang] Improve error reporting for procedures determined by usage (#88184)
When a symbol is known to be a procedure due to its being referenced as
a function or subroutine, improve the error messages that appear if the
symbol is also used as an object by attaching the source location of its
procedural use. Also, for errors spotted in name resolution due to how a
given symbol has been used, don't unconditionally set the symbol's error
flag (which is otherwise generally a good idea, to prevent cascades of
errors), so that more unrelated errors related to usage will appear.
2024-04-22 14:27:39 -07:00
Peter Klausler
e8572d0fc9
[flang] Don't emit conversion error for max(a,b, optionalCharacter) (#88156)
A recent patch added an error message for whole optional dummy argument
usage as optional arguments (third or later) to MAX and MIN when those
names required type conversion, since that conversion only works when
the optional arguments are present. This check shouldn't care about
character lengths. Make it so.
2024-04-22 14:13:00 -07:00
Leandro Lupori
5198923c70
[flang][OpenMP] Allow common blocks in nested directives (#88430)
COMMON block names must be declared in the same scoping unit in
which the OpenMP directive or clause appears, but OpenMP
constructs must not be considered as scoping units. Instead,
consider only program units and block constructs as such.
2024-04-22 10:19:42 -03:00
Valentin Clement (バレンタイン クレメン)
c69efcd548
[flang][cuda] Relax assumed size check on object with device attribute (#89466)
Assumed size arrays are apparently allowed with attribute device.
2024-04-19 15:55:24 -07:00
Valentin Clement (バレンタイン クレメン)
4523a26782
[flang][cuda] Enforce DEVICE attribute when ALLOCATE with STREAM option (#89459)
When the STREAM option is specified on an ALLOCATE statement, the object
must have the DEVICE attribute.
2024-04-19 15:19:37 -07:00
Valentin Clement (バレンタイン クレメン)
16e3464852
[flang][cuda] Enforce PINNED attribute when ALLOCATE with PINNED option (#89455)
When the PINNED option is specified on an ALLOCATE statement, the object
must have the PINNED attribute.
2024-04-19 14:58:22 -07:00
Valentin Clement (バレンタイン クレメン)
aa7c104124
[flang][cuda] Allow fixed size array with the managed attribute (#89436)
Fixed size array and scalar should be allowed with the `managed`
attribute.
2024-04-19 12:47:40 -07:00
Valentin Clement (バレンタイン クレメン)
a309c07ad3
[flang][cuda] Allow if stmt in device subroutine (#89347) 2024-04-19 07:30:26 -07:00
Kiran Chandramohan
b3c72bcbf2
[Flang][OpenMP] Issue error if reduction clause has proc-pointer (#88999)
OpenMP 5.2: Section 5.5.5: A procedure pointer must not appear in a
reduction clause.

Fixes #87915
2024-04-19 12:47:31 +01:00
Valentin Clement (バレンタイン クレメン)
3090efc6b6
[flang][cuda] Relax semantic for device variable in block construct (#89330) 2024-04-18 18:12:41 -07:00
Valentin Clement (バレンタイン クレメン)
26101e8c50
[flang][cuda] Avoid crash by exiting the check if assignment is not usable (#89149)
In the presence of other semantic error, `GetAssignment` would return a
nullptr and therefore would make the rest of the check crash when trying
to collect symbols.

Exiting early when we have a nullptr so the compiler doesn't crash and
user can get the meaningful semantic error.
2024-04-17 15:42:09 -07:00
harishch4
fa61f062a5
Fix threadprivate variable scope inside BLOCK construct. (#88921)
When a local variable inside a BLOCK construct is used as threadprivate
variable, llvm-flang throws below error:

> error: The THREADPRIVATE directive and the common block or variable in
it must appear in the same declaration section of a scoping unit
2024-04-17 15:21:45 +05:30
Kiran Chandramohan
17cb8a537b
[Flang][OpenMP] Accept the reduction modifier (#86492)
Accept the reduction modifier in the Flang parser. Issue a TODO message
during lowering.

OpenMP 5.0 introduced the reduction modifier. Details can be seen in
2.19.5.4 reductionClause.
OpenMP 5.2 relevant section is 5.5.8reductionClause.

This will help remove some of the parser errors highlighted in the
following post and also bring it to a well defined behaviour (produce
TODO errors for unsupported features, do not crash).
https://discourse.llvm.org/t/proposal-rename-flang-new-to-flang/69462/60
2024-04-15 14:24:42 +01:00
Valentin Clement (バレンタイン クレメン)
7b6b023121
[flang][cuda] Fix crash in semantic (#88577)
Fix for #88451

Do not perform semantic check about data transfer on assignment
statement in device context.
2024-04-12 14:28:05 -07:00
Krzysztof Parzyszek
4078afc6d2
[LLVM][OpenMP] Add "nowait" clause as valid for "workshare" (#88426)
Add the "nowait" clause to the list of allowed clauses for the "workshare"
directive. This will make it consistent with other directives (which are
shared between C/C++ and Fortran).

The parser will still reject "nowait" on "!$omp workshare", so this has no
effect on accepting/rejecting Fortran source code.
2024-04-12 14:52:24 -05:00
NimishMishra
506ff54792
[flang][Semantics] Fix updating flags of threadprivate symbols in presence of default clause (#78283)
Current semantic checks of default clause incorrectly update symbol
flags related to threadprivate symbols. This patch adds an additional
check to skip such updation should a symbol be already declared
threadprivate.

Fixes https://github.com/llvm/llvm-project/issues/78282
2024-04-11 22:12:14 -07:00
Valentin Clement (バレンタイン クレメン)
e953c862e9
[flang][cuda] Add UNIFIED data attribute (#88171)
Latest version of the specification introduced the `UNIFIED` attribute
for data.


https://docs.nvidia.com/hpc-sdk/compilers/cuda-fortran-prog-guide/#cfref-var-attr-unified-data

This patch adds the attribute to parsing, semantic and lowering. 

The matching rules for dummy/actual arguments is not part of this patch.
2024-04-09 13:32:21 -07:00
Peter Klausler
e1ad2735c3
[flang] Clean up ISO_FORTRAN_ENV, fix NUMERIC_STORAGE_SIZE (#87566)
Address TODOs in the intrinsic module ISO_FORTRAN_ENV, and extend the
implementation of NUMERIC_STORAGE_SIZE so that the calculation of its
value is deferred until it is needed so that the effects of
-fdefault-integer-8 or -fdefault-real-8 are reflected. Emit a warning
when NUMERIC_STORAGE_SIZE is used from the module file and the default
integer and real sizes do not match.

Fixes https://github.com/llvm/llvm-project/issues/87476.
2024-04-08 11:57:01 -07:00
Peter Klausler
97e3f605d5
[flang] Don't allow non-standard data conversions of potentially abse… (#87391)
…nt arguments

Arguments to the intrinsic functions MAX and MIN after the first two are
optional. When these actual arguments might not be present at run time,
emit a compilation time error if they require data conversion (a
non-standard but nearly universal language extension); such a conversion
would crash if the argument was absent.

Other compilers either disallow data conversions entirely on MAX/MIN or
crash at run time if a converted argument is absent.

Fixes https://github.com/llvm/llvm-project/issues/87046.
2024-04-08 11:56:36 -07:00
Peter Klausler
aace1e1719
[flang] Improve error message with declaration (#87294)
When a program attempts to use a non-object entity as the base of a
component reference or type parameter inquiry, the message is somewhat
uninformative and the position of the entity's declaration will not
reflect any updates made to the symbol during name resolution.

Includes some NFC C++17 style clean-up on some code noticed while
debugging (missing mandatory braces).
2024-04-08 11:55:03 -07:00
Peter Klausler
af61d08280
[flang] Handle forward reference to shadowing derived type from IMPLICIT (#87280)
A derived type name in an IMPLICIT statement might be a host association
or it might be a forward reference to a local derived type, which may be
shadowing a host-associated name. Add a scan over the specification part
in search of derived type definitions to determine the right
interpretation.

Fixes https://github.com/llvm/llvm-project/issues/87215.
2024-04-08 11:54:37 -07:00
Peter Klausler
92ecc22b8d
[flang] Fix crash in semantics on bad program (#87199)
Don't accept a putative statement function definition for a symbol that
is a subprogram but can't possibly be a statement function.

Fixes https://github.com/llvm/llvm-project/issues/86936.
2024-04-08 11:53:49 -07:00
Valentin Clement (バレンタイン クレメン)
896b5e5571
[flang][cuda] Allow list-directed PRINT and WRITE stmt in device code (#87415)
The specification allow list-directed PRINT and WRITE statements to
appear in device code. This patch relax the semantic check to allow
them.

3.6.11.
List-directed PRINT and WRITE statements to the default unit may be used
when compiling for compute capability 2.0 and higher; all other uses of
PRINT and WRITE are disallowed.
2024-04-08 09:59:12 -07:00
Valentin Clement (バレンタイン クレメン)
0aa982fb32
[flang][cuda] Add restriction on implicit data transfer (#87720)
In section 3.4.2, some example of illegal data transfer using expression
are given. One of it is when multiple device objects are part of an
expression in the rhs. Current implementation allow a single device
object in such case. This patch adds a similar restriction.
2024-04-05 13:40:38 -07:00
Valentin Clement (バレンタイン クレメン)
f2a0dd3305
[flang][cuda] Add restriction on assumed size device variable (#87664)
According to
https://docs.nvidia.com/hpc-sdk/compilers/cuda-fortran-prog-guide/#cfpg-var-qual-attr-device

> A device array may be an explicit-shape array, an allocatable array,
or an assumed-shape dummy array.

Assumed size array are not supported. This patch adds an error for that
case.
2024-04-04 12:48:08 -07:00
harishch4
f546b6ef3c
[Flang] Relaxing an error when contiguous pointer is assigned to a non-contig… (#86781)
…uous function.

Fix from [thtsikas](https://github.com/thtsikas) based on a discussion
in
[slack](https://flang-compiler.slack.com/archives/C5C58TT32/p1711124374836079).

Example:
```
Program test
  Integer, Pointer, Contiguous :: cont(:)
  Interface
     Function f()
       Integer, Pointer :: f(:)
     End Function
  End Interface
  cont => f()
  Print *, cont(3)
End Program

Function f()
  Integer, Pointer :: f(:)
  Allocate (f(4),Source=[1,1,42,1])
  ! f => f(4:1:-1)        !! not contiguous, runtime error
End Function f
```

Understanding is that the standard intended to allow this pattern. The
restriction 10.2.2.3 p6 Data pointer assignment "If the pointer object
has the CONTIGUOUS attribute, the pointer target shall be contiguous."
is not associated with a numbered constraint. If there is a mechanism
for injecting runtime checks, this would be a place to do it. Absent
that, a warning is the best we can do.

No other compiler treats contigPtr => func() as an error when func() is
not CONTIGUOUS, so a warning would probably be better for consistency.
https://godbolt.org/z/5cM6roeEE
2024-04-01 17:13:22 +05:30
Peter Klausler
f4fc959c35
[flang] Catch impossible but necessary TBP override (#86558)
An apparent attempt to override a type-bound procedure is not allowed to
be interpreted as on override when the procedure is PRIVATE and the
override attempt appears in another module. However, if the TBP that
would have been overridden is a DEFERRED procedure in an abstract base
type, the override must take place. PRIVATE DEFERRED procedures must
therefore have all of their overrides appear in the same module as the
abstract base type.
2024-03-26 10:11:19 -07:00
Peter Klausler
f92f775212
[flang][NFC] Address reported "possible missing return" (#86523)
A function uses "if constexpr" to consider all possible types in a
variant, but looks as if it can fall out without returning an
expression. Add a final "else" with a crash to make things more clear
and to protect against unlikely future extensions of the type.

Fixes https://github.com/llvm/llvm-project/issues/86391.
2024-03-26 10:02:22 -07:00
Peter Klausler
8f01ecaeb8
[flang] Special-case handling of INTRINSIC in type-decl-stmt (#86518)
Fortran allows the INTRINSIC attribute to be specified with a distinct
attribute statement, and also as part of the attribute list of a
type-declaration-stmt. This is an odd case (especially as the declared
type is mandated to be ignored if it doesn't match the type of the
intrinsic function) that can lead to odd error messages and crashes,
since the rest of name resolution expects that intrinsics with explicit
declarations will have been declared with INTRINSIC attribute
statements. Resolve by handling an "inline" INTRINSIC attribute as a
special case while processing a type-declaration-stmt, so that

  real, intrinsic :: acos, asin, atan

is processed exactly as if it had been

  intrinsic acos, asin, atan; real acos, asin, atan

Fixes https://github.com/llvm/llvm-project/issues/86382.
2024-03-26 09:50:37 -07:00
Peter Klausler
3ada883f7c
[flang][runtime] Runtime support for REDUCE() (#86214)
Supports the REDUCE() transformational intrinsic function of Fortran
(see F'2023 16.9.173) in a manner similar to the existing support for
SUM(), PRODUCT(), &c. There are APIs for total reductions to scalar
results, and APIs for partial reductions that reduce the rank of the
argument by one.

This implementation requires more functions than other reductions
because the various possible types of the user-supplied OPERATION=
function need to be elaborated.

Once the basic API in reduce.h has been approved, later patches will
implement lowering.

REDUCE() is primarily for completeness, not portability; only one other
Fortran compiler implements this F'2018 feature today, and only some
types work correctly with it.
2024-03-26 09:21:16 -07:00
Peter Klausler
f50f0caf87
[flang] Fix crash in name resolution (#85835)
ConvertToObjectEntity() returns true for use- and host-associated object
symbols, too. Ensure in this case that the symbol really is a
non-associated object.

Fixes https://github.com/llvm/llvm-project/issues/85776.
2024-03-26 08:59:22 -07:00
Leandro Lupori
edcf65d40c
[flang][OpenMP] Allow loop iteration variables in DSA clauses (#86194)
Iteration variables of non-associated loops may be listed in DSA
clauses.

Fixes https://github.com/llvm/llvm-project/issues/78938
2024-03-25 08:48:11 -03:00
jeanPerier
de7a50fb88
[flang] Fix lowering of host associated cray pointee symbols (#86121)
Cray pointee symbols can be host associated from a module or host
procedure while the related cray pointer is not explicitly associated.
This caused the "not yet implemented: lowering symbol to HLFIR" to fire
when lowering a reference to the cray pointee and fetching the cray
pointer.

This patch:
- Ensures cray pointers are always instantiated when instantiating a
cray pointee.
- Fix internal procedure lowering to deal with cray pointee host
association like it does for pointers (the lowering strategy for cray
pointee is to create a pointer that is updated with the cray pointer
value before being fetched).

This should fix the bug reported in
https://github.com/llvm/llvm-project/issues/85420.
2024-03-22 11:13:04 +01:00
harishch4
a7eaae4ec6
[Flang] Fix to the module procedure interface block ignoring implicit… (#85735)
… of host scoping unit.

Fix as proposed by @thtsikas [here
](11d07d9ef6 (commitcomment-139798026)).
2024-03-19 22:46:57 +05:30
Kelvin Li
a5f576e596
[flang] Diagnose calling impure final procedure due to finalization in FORALL (#85685)
This patch checks the LHS of an assignment in a FORALL loop and
diagnoses if any impure final procedure is called.
2024-03-18 21:35:56 -04:00
Peter Klausler
d0d9839b14
[flang] Fix crash on erroneous program (#85615) (#85659)
Replace a pointer that should never be null with a reference argument so
that it's always defined.

Fixes https://github.com/llvm/llvm-project/issues/85615.
2024-03-18 14:14:41 -07:00
Peter Klausler
53e8d501e2
[flang] Catch inappropriate attributes for PARAMETERs (#85588)
There's several symbol attributes that cannot be applied to named
constants, but that weren't being checked.
2024-03-18 14:13:50 -07:00
Kelvin Li
0c21377aea
[flang] Diagnose the impure procedure reference in finalization according to the rank of the entity (#85475)
Use the rank of the array section to determine which final procedure
would be called in diagnosing whether that procedure is impure or not.
2024-03-18 10:59:47 -04:00
Tom Eccles
53d8c6b1b1
[flang][Semantics][OpenMP] set intrinsic attr for reductions (#85114)
Reductions such as min are intrinsic procedures. This distinguishes them
from user defined reductions. Previously, the intrinsic attribute was
not set when visiting reduction clauses causing them to be missed.

wsloop-reduction-min.f90 (the other min reduction test) worked because
it contained "min" used as an intrinsic inside of the body of the
reduction. This allowed ResolveNamesVisitor::HandleProcedureName to set
the correct attribute on that Symbol.
2024-03-15 11:12:09 +00:00
Peter Klausler
dc55c4435d
[flang] Clip circular dependence between implementation modules (#85309)
flang/module/__fortran_type_info.mod uses __fortran_builtins.mod, but it
is also implicitly used when compiling __fortran_builtins.f90 (or
anything else). If __fortran_type_info.mod finds an old
__fortran_builtins.mod file, compilation can fail while building the new
one.

Break the dependence by *not* generating runtime derived type
information for __fortran_builtins.f90.
2024-03-14 15:29:06 -07:00
Peter Klausler
702a86a8f1
[flang] Correct accessibility of name that is both generic and derive… (#85098)
…d type

When the same name is used for a derived type and generic interface in a
module, and no explicit PUBLIC or PRIVATE statement appears for the name
but the derived type definition does have an explicit accessibility,
that accessibility must also apply to the generic interface.
2024-03-13 15:13:56 -07:00
Peter Klausler
5661188c57
[flang] Support multiple distinct module files with same name in one … (#84838)
…compilation

Allow multiple module files with the same module name to exist in one
compilation; distinct modules are distinguished by their hashes.
2024-03-13 14:42:40 -07:00
Peter Klausler
ccfb9e6eb7
[flang] Omit parent components for references to bindings (#84836)
https://github.com/llvm/llvm-project/pull/78593 changed expression
semantics to always include the names of parent components that were
necessary to access an inherited component. This turns out to have
broken calls to inherited NOPASS procedure bindings. Update the patch to
omit explicit parent components when accessing bindings, while retaining
them for component accesses (including procedure components).
2024-03-13 14:30:04 -07:00