1483 Commits

Author SHA1 Message Date
Sergio Afonso
f13aea1d87
[Flang][OpenMP] Update semantics checks for 'teams' nesting (#126922)
This patch introduces a directive set for combined constructs where
`teams` is the last leaf. This is used in a couple places to simplify
checks, which is NFC, but it also replaces two incorrect uses of
`topTeamsSet`.

Before, these checks would incorrectly skip combined constructs where
`teams` was the last leaf construct when checking for allowed nested
constructs inside of a `teams` region. Similarly, it would also
incorrectly perform these checks whenever a compound `teams` construct
where `teams` was the first leaf construct was found.
2025-02-12 15:24:31 +00:00
Valentin Clement (バレンタイン クレメン)
b00b193728
[flang][cuda] Allow POINTER component to have device attribute (#126116) 2025-02-06 19:43:04 -08:00
Tom Eccles
39be2d0266
[flang][OpenMP][Semantics] Don't allow reduction of derived type components (#125480)
Before this patch, reduction of derived type components crashed the
compiler when trying to create the omp.declare_reduction.

In OpenMP 3.1 the standard says "a list item that appears in a reduction
clause must be a named variable of intrinsic type" (page 106). As I
understand it, a derived type component is not a variable.

OpenMP 4.0 added declare reduction, partly so that users could define
their own reductions on derived types. The above wording was removed
from the standard but derived type components were never explicitly
allowed.

OpenMP 5.0 added "A variable that is part of another variable, with the
exception of array elements, cannot appear in17 a reduction clause".

All standard versions also require the reduction argument to be
"definable", which roughly means that it is a variable. A
derived type component is more like an expression.

Fixes #125445
2025-02-06 10:44:16 +00:00
Valentin Clement (バレンタイン クレメン)
d3e2459da8
[flang][cuda][NFC] Add tests for device functions in cuf kernels (#125882) 2025-02-05 09:52:59 -08:00
Eugene Epshteyn
642288247d
[flang] Add support for -fimplicit-none-ext option (#125248)
When -fimplicit-none-ext is passed, flang behaves as if "implicit
none(external)" was specified for all relevant constructs in Fortran
source file.

Note: implicit17.f90 was based on implicit07.f90 with `implicit
none(external)` removed and `-fimplicit-none-ext` added.
2025-02-04 20:50:01 -05:00
Valentin Clement (バレンタイン クレメン)
bbc90f899a
[flang][cuda] Relax semanctic check in cuf kernel and openacc compute constructs (#125750)
Previous patch was too restrictive and didn't take into account cuf
kernels and openacc compute constructs as being device context.
2025-02-04 13:10:47 -08:00
Valentin Clement (バレンタイン クレメン)
7e1437ba4a
[flang][cuda] Detect illegal data transfer in semantic (#125591)
When the LHS is a device variable and the RHS has implicit transfer,
this is considered as an illegal transfer according to
https://docs.nvidia.com/hpc-sdk/compilers/cuda-fortran-prog-guide/index.html#implicit-data-transfer-in-expressions.

Detect this is semantic .
2025-02-03 15:00:43 -08:00
Krzysztof Parzyszek
fe8b323f59
[flang][OpenMP] Semantic checks for context selectors (#123243)
This implements checks of the validity of context set selectors and
trait selectors, plus the types of trait properties. Clause properties
are also validated, but not name or extension properties.

---------

Co-authored-by: Tom Eccles <tom.eccles@arm.com>
2025-02-03 09:48:04 -06:00
Peter Klausler
2bfb3bae69
[flang] Make REAL/COMPLEX(10) a hard error for non-x86 targets (#124655)
Currently the use of REAL/COMPLEX(KIND=10) as a type or literal constant
suffix elicits an optional warning message only. This leads to compiler
internal errors during lowering when these types appear in code being
compiled to non-x86_64 targets. For better error messaging, make the use
of these types a hard error in semantics instead when they are not
supported by the target architecture.
2025-01-31 11:43:29 -08:00
Peter Klausler
f8300f1c2a
[flang] Refine "same type" testing for intrinsic arguments (#125133)
Some errors aren't being caught, such as the case in the linked bug
where the PAD= argument to RESHAPE() didn't have the same declared type
as the ARRAY=; this led to a crash in lowering. Refine the "same type"
testing logic for intrinsic procedures, and add a better test.

Fixes https://github.com/llvm/llvm-project/issues/124976.
2025-01-31 10:55:08 -08:00
Peter Klausler
56c468474d
[flang] Suppress USEs of non-USE'able names in module files (#124980)
When harvesting and formatting symbols USE'd from other modules, don't
emit USE statements to module files for names unless they come from the
topmost scope of the module. There was a check to prevent names from
derived type scopes from escaping in this way, but it must be made more
general to prevent other cases like dummy arguments in interfaces.

Fixes https://github.com/llvm/llvm-project/issues/124716.
2025-01-31 10:54:48 -08:00
Peter Klausler
c82db773f4
[flang] Handle indirect USE of ancestor module into submodule (#124969)
A USE statement within a submodule (possibly in a nested scope) is not
allowed to USE the submodule's ancestor module directly, but it is
permissible to USE that ancestor module indirectly via another unrelated
module. Don't emit "already present in scope" errors for this case.

Fixes https://github.com/llvm/llvm-project/issues/124731.
2025-01-31 10:54:25 -08:00
Peter Klausler
cadc70c1f0
[flang] Prefer non-elemental to elemental defined operator resolution (#124941)
A non-elemental specific procedure must take precedence over an
elemental specific procedure in defined operator generic resolution.

Fixes https://github.com/llvm/llvm-project/issues/124777.
2025-01-31 10:54:00 -08:00
Peter Klausler
4927a5ed4a
[flang] Allow defined assignment to CLASS(*) (#124817)
An unlimited polymorphic left-hand side variable is acceptable in the
definition of a defined assignment subroutine.

Fixes https://github.com/llvm/llvm-project/issues/124621.
2025-01-31 10:53:40 -08:00
Peter Klausler
36caa8f9e2
[flang] Fix crash on SMP with dummy procedure (#124663)
When a separate module procedure is defined with MODULE PROCEDURE, the
compiler crashes if there is a dummy procedure in the interface defined
with only a result type. This is due to the type already having been
defined on the ProcEntityDetails symbol as part of earlier wholesale
symbol duplication. Adjust the code to not define the result type of the
ProcEntityDetails if it is already present, but to verify that it is the
same type instead.

Fixes https://github.com/llvm/llvm-project/issues/124487.
2025-01-31 10:52:34 -08:00
Peter Klausler
b4d52a9abd
[flang] Repair recent Power build bot breakage (#124950)
Add AIX_WARNING expected warnings to a test that is now producing new
warnings.

Should fix https://lab.llvm.org/buildbot/#/builders/201/builds/2291.
2025-01-30 11:41:20 -08:00
Jean-Didier PAILLEUX
e811cb00e5
[flang] Implement !DIR$ UNROLL [N] (#123331)
This patch implements support for the UNROLL directive to control how
many times a loop should be unrolled.
It must be placed immediately before a `DO LOOP` and applies only to the
loop that follows. N is an integer that specifying the unrolling factor.
This is done by adding an attribute to the branch into the loop in LLVM
to indicate that the loop should unrolled.
The code pushed to support the directive `VECTOR ALWAYS` has been
modified to take account of the fact that several directives can be used
before a `DO LOOP`.
2025-01-29 09:44:09 +01:00
Thirumalai Shaktivel
ba789c6f82
[Flang] Add semantics checks for CrayPointer usage in DSA list (#123171)
Follow-up PR to fix the failure caused here:
https://github.com/llvm/llvm-project/pull/121028

Failure:
https://lab.llvm.org/buildbot/#/builders/89/builds/14474

Problems:
- Cray pointee cannot be used in the DSA list (If used results in segmentation fault)
- Cray pointer has to be in the DSA list when Cray pointee is used in the default (none) region

Fix: Added required semantic checks along the tests
Reference from the documentation (OpenMP 5.0: 2.19.1):
- Cray pointees have the same data-sharing attribute as the storage with
which their Cray pointers are associated.
2025-01-28 08:27:42 +05:30
Peter Klausler
d732c86c92
[flang] Don't take corank from actual intrinsic argument (#124029)
When constructing the characteristics of a particular reference to an
intrinsic procedure that was passed a non-coindexed reference to local
coarray data as an actual argument, don't add the corank of the actual
argument to those characteristics.

Also clean up the TypeAndShape characteristics class a little; the
Attr::Coarray is redundant since the corank() accessor can be used to
the same effect.
2025-01-27 11:57:01 -08:00
Peter Klausler
1e9b60cfa4
[flang] Recognize and check EVENT_QUERY (#123429)
Recognize the intrinsic subroutine EVENT_QUERY and enforce semantic
requirements on calls to it.
2025-01-27 11:56:41 -08:00
Peter Klausler
08c364280a
[flang] Improve error message on bad complex literal. (#124331)
A complex literal constant can have one BOZ component, since the type
and value of the literal can be determined by converting the BOZ value
to the type of the other component. But a complex literal constant with
two BOZ components doesn't have a well-defined type. The error message
was confusing in the case; emit a better one.

Fixes https://github.com/llvm/llvm-project/issues/124201.
2025-01-27 09:00:10 -08:00
Peter Klausler
b0fab14e9c
[flang] Fix spurious error in character sequence association (#124204)
When an allocatable or pointer was being associated as a storage
sequence with a dummy argument, the checks were using the actual storage
size of the allocatable or pointer's descriptor, not the size of the
storage that it references.

Fixes https://github.com/llvm/llvm-project/issues/123807.
2025-01-27 08:58:20 -08:00
Peter Klausler
c596aae47a
[flang] Catch assumed-length interoperability error (#124179)
An assumed-length character dummy argument is interoperable only if it
is neither a pointer nor allocatable.
2025-01-27 08:57:48 -08:00
Peter Klausler
d1d952c206
[flang] Interpret 'Q' exponent letter as kind=16 even on x86 (#124158)
The compiler was interpreting 'Q' as an exponent letter in a literal
real constant as meaning real(kind=10) on x86-64, which is the legacy
80387 80-bit extended precision floating-point type. It turns out that
'Q' means kind=16 with all other compilers, even for x86-64 targets.
Change to conform.
2025-01-27 08:57:27 -08:00
Peter Klausler
f5ddb1012d
[flang] Fix crash in module file generation (#123859)
An assertion in module file generation didn't allow for a case that has
arisen in a test; remove it, extend commentary, and add a regression
test.

Fixes https://github.com/llvm/llvm-project/issues/123534.
2025-01-27 08:56:25 -08:00
Peter Klausler
3ac00784ac
[flang] Fix crash on erroneous program (#123843)
Catch and report multiple initializations of the same procedure pointer
rather than assuming that control wouldn't reach a given point in name
resolution in that case.

Fixes https://github.com/llvm/llvm-project/issues/123538.
2025-01-27 08:55:56 -08:00
Peter Klausler
b16c989697
[flang] Fix check for coarray actual passed to implicit interface (#123836)
The check for a coarray actual argument being passed to a procedure with
an implicit interface was incorrect, yielding false positives for
coindexed objects. Fix.
2025-01-27 08:55:20 -08:00
Peter Klausler
210e675cfd
[flang] Accept CHANGE TEAM/END TEAM as branch target (#123822)
It is valid to jump to a CHANGE TEAM statement from anywhere in the
containing executable part, and valid to jump to an END TEAM statement
from within the construct.
2025-01-27 08:54:56 -08:00
Peter Klausler
2625510ef8
[flang] Refine EVENT_TYPE/LOCK_TYPE usage checks (#123244)
The event variable in an EVENT POST/WAIT statement can be a coarray
reference, and need not be an entire coarray.

Variables and potential subobject components with EVENT_TYPE/LOCK_TYPE
must be coarrays, unless they are potential subobjects nested within
coarrays or pointers.
2025-01-27 08:45:11 -08:00
Peter Klausler
512b44d5e1
[flang] Define ATOMIC_ADD as an intrinsic procedure (#122993)
This one appears to have been omitted when other ATOMIC_xxx intrinsic
procedures were defined. There's already tests for it, but they
apparently work even when ATOMIC_ADD must be interpreted as an external
procedure with an implicit interface. Extend the tests with INTRINSIC
NONE(EXTERNAL, TYPE) statements to ensure that they require the
intrinsic interpretation.
2025-01-27 08:44:39 -08:00
Peter Klausler
038b42ba5b
[flang] Safer hermetic module file reading (#121002)
When a hermetic module file is read, use a new scope to hold its
dependent modules so that they don't conflict with any modules in the
global scope.
2025-01-27 08:43:41 -08:00
Mats Petersson
8035d38daa
[Flang][OpenMP]Add parsing support for DISPATCH construct (#121982)
This allows the Flang parser to accept the !$OMP DISPATCH and related
clauses.

Lowering is currently not implemented. Tests for unparse and parse-tree
dump is provided, and one for checking that the lowering ends in a "not
yet implemented"

---------

Co-authored-by: Kiran Chandramohan <kiran.chandramohan@arm.com>
2025-01-26 09:44:04 +00:00
Valentin Clement (バレンタイン クレメン)
3d59e30cbc
[flang][cuda] Allow DO CONCURRENT in cuf kernel (#124190) 2025-01-23 15:09:39 -08:00
Valentin Clement (バレンタイン クレメン)
4065d985ab
[flang][cuda] Allow complex type in cuf kernel reduce (#124185) 2025-01-23 15:09:24 -08:00
Renaud Kauffmann
652ff20140
[flang][cuda] Adding atomicadd as a cudadevice intrinsic and converting it LLVM dialect (#123840)
With these changes, CUF atomic operations are handled as cudadevice
intrinsics and are converted straight to the LLVM dialect with the
`llvm.atomicrw` operation.

I am only submitting changes for `atomicadd` to gather feedback. If we
are to proceed with these changes I will add support for all other
applicable atomic operations following this pattern.
2025-01-22 19:06:28 -08:00
agozillon
8f5df88918
[Flang][Semantics] Allow declare target to be used on functions external to the declare targets scope (#122546)
Whilst a little contrived, OpenMP allows you to utilise declare target
in the scope of one function to mark another function declare target,
currently this leads to a semantic error.

This appears to be because when we process the declare target directive
in the scope of another function (referring to another function), we do
not search externally from that functions scope to find possible prior
definitions, we only search in the current scope, this leads to us
implicitly defining a new variable and using that when implicit none is
not specified and then error'ng out or error'ng out earlier when implict
none is defined. This patch tries to address this behaviour by looking
externally for a function first and using that, before defaulting back
to the prior behaviour.
2025-01-21 16:05:12 +01:00
Thirumalai Shaktivel
c2aa11d148
[Flang] Add LLVM lowering support for UNTIED clause in Task (#121052)
Implementation details:
The UNTIED clause is recognized by setting the flag=0 for the default
case or performing logical OR to flag if other clauses are specified,
and this flag is passed as an argument to the `__kmpc_omp_task_alloc`
runtime call.


Resubmitting the PR with fix for the failure, as it was reverted here:
927a70daf31b1610627f346b0dc140eda72144b9
and previously merged here: https://github.com/llvm/llvm-project/pull/115283
2025-01-21 09:10:25 +05:30
Leandro Lupori
9c464e60d2
[flang][OpenMP] Don't try to privatize FORALL/DO CONCURRENT indices (#123341)
FORALL/DO CONCURRENT indices have predetermined private DSA (OpenMP 5.2
5.1.1).

As FORALL/DO CONCURRENT indices are defined in the construct itself, and
OpenMP
directives may not appear in it, they are already private and don't need
to be modified.

Fixes https://github.com/llvm/llvm-project/issues/100919
Fixes https://github.com/llvm/llvm-project/issues/120023
Fixes https://github.com/llvm/llvm-project/issues/123537
2025-01-20 15:46:11 -03:00
Kiran Chandramohan
ebc7efbab5
Revert "[Flang OpenMP] Add semantics checks for cray pointer usage in DSA list" (#123220)
Reverts llvm/llvm-project#121028

Reverting due to CI failure
(https://lab.llvm.org/buildbot/#/builders/89/builds/14474)
2025-01-16 16:53:46 +00:00
Thirumalai Shaktivel
990774ab8e
[Flang] Add semantic checks for cray pointer usage in DSA list (#121028)
Problems:
- Cray pointee cannot be used in the DSA list (If used results in
segmentation fault)
- Cray pointer has to be in the DSA list when Cray pointee is used in
the default (none) region

Fix: Added required semantic checks along the tests

Reference from the documentation (OpenMP 5.0: 2.19.1):
- Cray pointees have the same data-sharing attribute as the storage with
   which their Cray pointers are associated.
2025-01-16 12:46:27 +05:30
Peter Klausler
ecf264d3b4
[flang] Fix spurious error message due to inaccessible generic binding (#122810)
Generic operator/assignment checks for distinguishable specific
procedures must ignore inaccessible generic bindings.

Fixes https://github.com/llvm/llvm-project/issues/122764.
2025-01-14 13:02:21 -08:00
Peter Klausler
9629f2c4ca
[flang] Improve module file error message wording (#122787)
Instead of "Cannot read ...", distinguish true errors in finding and
parsing module files from problems with unexpected hash codes by using
"Cannot parse" or "Cannot use" wording as appropriate.
2025-01-14 13:01:56 -08:00
Peter Klausler
9f0f54a629
[flang] Improve error messages for module self-USE (#122747)
A module can't USE itself, either directly within the top-level module
or from one of its submodules. Add a test for this case (which we
already caught), and improve the diagnostic for the more confusing case
involving a submodule.
2025-01-14 13:00:03 -08:00
Peter Klausler
9696355484
[flang] Better messages and error recovery for a bad RESHAPE (#122604)
Add tests for negative array extents where necessary, motivated by a
compiler crash exposed by yet another fuzzer test, and improve overall
error message quality for RESHAPE().

Fixes https://github.com/llvm/llvm-project/issues/122060.
2025-01-14 12:57:49 -08:00
Peter Klausler
89bbaf3cf2
[flang] Fix another crash from another fuzzer test. (#122562)
Fixes https://github.com/llvm/llvm-project/issues/122045.
2025-01-14 12:57:10 -08:00
Peter Klausler
b720b6cbe9
[flang] Fix crash from fuzzy test. (#122364)
Fixes https://github.com/llvm/llvm-project/issues/122002.
2025-01-14 12:56:03 -08:00
Peter Klausler
9405a81ee7
[flang] Fix crash exposed by fuzzing (#122187)
An integer overflowed in an erroneous test. Fix, and improve the error
messages a bit.

Fixes https://github.com/llvm/llvm-project/issues/121979.
2025-01-14 10:42:29 -08:00
Peter Klausler
6f55c8068f
[flang] Fix crash in fuzzer-generated error test. (#122199)
Fixes https://github.com/llvm/llvm-project/issues/121973.
2025-01-14 10:41:42 -08:00
Peter Klausler
c8202db43a
[flang] Fix crash in fuzzing test (#122189)
Fixes https://github.com/llvm/llvm-project/issues/121972.
2025-01-14 10:40:39 -08:00
Peter Klausler
bf23ae6d38
[flang] Fix crash in fuzzed input program (#122193)
Fixes https://github.com/llvm/llvm-project/issues/121971.
2025-01-14 10:39:51 -08:00