202 Commits

Author SHA1 Message Date
Peter Klausler
7e1fff4d50
[flang][runtime] Improve handling of short DATE_AND_TIME(VALUES=) (#180557)
When the actual argument associated with the VALUES= dummy argument of
the intrinsic subroutine DATE_AND_TIME has fewer than eight elements, we
crash with an internal error in the runtime.

With this patch, the compiler now checks the size of the vector at
compilation time, when it is known, and gracefully copes with a short
vector at execution time otherwise, without crashing.
2026-02-10 09:21:31 -08:00
Peter Klausler
c15ae96dc7
[flang][CUDA] Better analysis of actual argument CUDA data attrs (#179569)
When checking an actual argument for any CUDA data attributes, be sure
to check the symbols in a designator like a%b%c in order, taking the
last symbol that has a CUDA attribute. And be sure to interpret a
function result symbol of a device function as a device object, at least
for generic interface resolution for defined assignments and operators.

This patch exposed errors in flang/test/Semantics/bug1214.cuf, which
have been fixed.
2026-02-06 09:30:50 -08:00
Eugene Epshteyn
cab951718b
[flang] Disable various semantic checks for descriptor dummy args with ignore_tkr(c) (#179530)
When descriptor dummy args have ignore_tkr(c), we want to use the
descriptor unchanged. As such, disable various semantic error checks
that are normally performed on descriptor based dummy args without
ignore_tkr(c)
2026-02-04 22:49:25 -05:00
Peter Klausler
55ee00e15f
[flang][CUDA] Allow constant to match device actual in specific procedure (#178658)
When scanning the specific procedures of a generic interface for a match
for a set of actual arguments, accept a constant actual argument as a
match for a dummy argument with the DEVICE attribute.
2026-01-31 14:47:49 -08:00
Valentin Clement (バレンタイン クレメン)
0e9ded5d91
[flang][cuda] Allow device descriptor in show_descriptor (#177424)
Descriptor are always in managed memory so it is safe to call
show_descriptor for them.
2026-01-22 18:28:03 +00:00
Peter Klausler
455de5543c
[flang] Fix non-portable TYPE(*) usage in generic (#176235)
Fortran allows a scalar actual argument of any type to correspond with a
TYPE(*) dummy argument that is an assumed-size array. This usage isn't
portable, and it didn't work with a generic procedure with this
compiler, only specific procedures. It affected at least one API in
OpenMPI.

Fix generic resolution to allow for this case, add a distinguishability
test to detect generic interfaces that have ambiguous specific
procedures due to it, and add an optional portability warning (off by
default).
2026-01-19 11:00:26 -08:00
Peter Klausler
85779e547b
[flang] Silence "used but undefined" warning for LOC(x) (#174807)
When a variable appears as the argument of the extension intrinsic
function LOC(x), assume that it's defined for the purposes of the
warning about variables that are used but never defined, since the
result of the LOC() can be used to define a based Cray pointer.
2026-01-08 08:58:25 -08:00
Valentin Clement (バレンタイン クレメン)
76b00fc75e
[flang][cuda] Skip sizeof intrinsic in check (#174339)
#174025 introduced a new semantic check for host intrinsic with device
variable.`sizeof` intrinsic extension should be skipped for this check.
2026-01-04 18:00:24 +00:00
Valentin Clement (バレンタイン クレメン)
ce69dd3b1f
[flang][cuda] Fix false positive in host intrinsic with device var (#174300)
#174025 was too strict and make couple of downstream testing fail. Relax
the check to skip allowed intrinsics.
2026-01-04 00:28:37 +00:00
Valentin Clement (バレンタイン クレメン)
af79967021
[flang][cuda] Emit error when a device actual argument is used in host intrinsic (#174025)
This can lead to segfault if a device variable is used in a host
intrinsic. Emit an error in semantic.

Reland #172914 with the addition of `__builtin_c_devloc `, `loc` and
`present` as skipped intrinsic
2026-01-02 09:18:27 -08:00
Peter Klausler
2b432dc53f
[flang] Fix two bugs with new warnings (#174153)
The new Severity::ErrorUnlessDeadCode message severity isn't always
considered to be fatal. Consolidate the "is this severity fatal?" logic
into one place.

Some instances in semantics that note variable definitions were
conditional on the symbol being a function result, since only the
"function result was never defined" warning needed to know about them.
Make them note all defined symbols.
2026-01-01 12:46:20 -08:00
Valentin Clement (バレンタイン クレメン)
ecf73cc2c3
Revert "[flang][cuda] Emit error when a device actual argument is used in host intrinsic" (#174019)
Reverts llvm/llvm-project#172914
2025-12-30 13:05:16 -08:00
Valentin Clement (バレンタイン クレメン)
68a0b93b1f
[flang][cuda] Emit error when a device actual argument is used in host intrinsic (#172914)
This can lead to segfault if a device variable is used in a host
intrinsic. Emit an error in semantic.
2025-12-30 08:49:20 -08:00
Peter Klausler
056ae8bab6
[flang] Correctly buffer warnings in Semantics/check-call.cpp (#172738)
There are calls to semantics::SemanticsContext::Warn() in check-call.cpp
that are not properly directing their output to the local message
buffer, so they can appear unconditionally in the output of the
compiler. This is a problem for generic interface resolution, which
checks procedure actual arguments against specific procedures using this
code, buffering the messages that might appear, and discarding the
messages for failed matches. Worse, the bogus warnings that escape the
buffering can be associated with completely unrelated locations.

Fix by passing the local message buffer to these Warn() calls.

(I couldn't come up with a good reduced test case, and am not sure that
the original code can be copied for use as one.)
2025-12-19 14:32:35 -08:00
Eugene Epshteyn
e7bccc7ceb
[flang] Fixed regression in copy-in/copy-out (#161259)
Fixed the polymprphic check for copy-in/copy-out, added regression
tests.

Changed MayNeedCopy() to return std::optional<bool> and renamed it to
ActualArgNeedsCopy(). This function now returns true/false when it's
known that actual arguments needs copy in/out, or std::nullopt to
signify that it's now known, whether copy in/out is needed.

Fixes #159149
2025-11-12 14:37:27 -05:00
Eugene Epshteyn
4f8943dfc1
[flang] Disallow passing array actual arguments to ignore_tkr(r) scalars with VALUE attribute (#166682)
Scalars with VALUE attribute are likely passed in registers, so it's now
clear what lowering should do with the array actual argument in this
case. Fail this case with an error before getting to lowering.
2025-11-12 06:04:09 -05:00
Eugene Epshteyn
edab7212c5
[flang] Implement IGNORE_TKR(P) (#165469)
Implemented IGNORE_TKR(P), which allows ignoring pointer and allocatable
matching (can pass an allocatable array to routine with pointer array
argument and vice versa). Updated documentation.
2025-10-29 08:34:51 -04:00
Peter Klausler
e34d603f18
[flang] More information on generic resolution failures (#164738)
When a generic procedure reference does not match any of its specific
procedures, run through them and emit the errors for each attempted
match, so that the user has more information to resolve the problem by
adjusting the actual arguments.
2025-10-24 14:14:59 -05:00
Peter Klausler
e2ee91ed34
[flang] Clean up some optional<bool> usage (#161925)
Audit the use of std::optional<bool> as a tri-state logical value in
flang, correct a couple cases that need ".value_or()", add some explicit
".has_value()" calls, and document the possible pitfalls.
2025-10-10 10:09:02 -07:00
Peter Klausler
cbe3b72c4c
[flang][CUDA] Downgrade error to warning (#161570)
The compiler currently emit an error about the lack of an explicit
procedure interface when an external procedure that is called via an
implicit interface is known to have an dummy argument with a CUDA data
attribute, even when the corresponding actual argument does have a CUDA
data attribute. This behavior is inconsistent with what happens when
such a call is to an external in another source file and its definition
is not visible -- the compiler silently accepts an actual argument with
a CUDA data attribute across the implicit interface.

Harmonize this situation so that an actual argument with a CUDA data
attribute in a reference to a procedure with an implicit interface
elicits a usage warning encouraging the use of explicit interfaces. Only
when the procedure's definition is visible, and incompatible, will an
error message appear.
2025-10-03 10:48:13 -07:00
Peter Klausler
286f45189b
[flang] Catch attempts to use assumed-rank as elemental argument (#159852)
An assumed-rank array may not be used as an argument to an elemental
procedure.

Fixes https://github.com/llvm/llvm-project/issues/159555.
2025-09-23 15:45:18 -07:00
Andre Kuhlenschmidt
f9cf60b0c1
[flang][NFC] Update comments (#160186)
Just an update to comments that I accidentally did on a testing repo and
didn't get included in the final merge of
https://github.com/llvm/llvm-project/pull/159477.
2025-09-22 13:08:22 -07:00
Andre Kuhlenschmidt
43e4757d85
[flang][semantic] update semantic checks for ansychronous and volatility attributes to use MayNeedCopy (#159477)
Ties the semantic checks for overwriting a asynchronous or volatile
value with a copy-out operation to the function
`evaluate::MayNeedCopy(..., /*forCopyOut=*/false)`. This should make the
checks more accurate and consistent with the lowering. The PR also adds
a default check that looks for the undesired behavior directly, in case
extension later modify what is possible.

A couple portability warnings are added where other compilers are over
restrictive.

Closes https://github.com/llvm/llvm-project/issues/137369
```
$ build/bin/flang -c ~/work/llvm-test-suite/Fortran/gfortran/regression/volatile8.f90 -pedantic
/home/akuhlenschmi/work/llvm-test-suite/Fortran/gfortran/regression/volatile8.f90:21:16: warning: The array section 'a(1_8:5_8:2_8)' should not be associated with dummy argument 'dummy8=' with VOLATILE attribute, unless the dummy is assumed-shape or assumed-rank [-Wvolatile-or-asynchronous-temporary]
      call sub8 (a(1:5:2)) ! { dg-error "Array-section actual argument" }
                 ^^^^^^^^
/home/akuhlenschmi/work/llvm-test-suite/Fortran/gfortran/regression/volatile8.f90:37:16: portability: The actual argument 's9dummy' should not be associated with dummy argument 'dummy9=' with VOLATILE attribute, because a temporary copy is required during the call [-Wportability]
      call sub9 (s9dummy) ! { dg-error "Assumed-shape actual argument" }
                 ^^^^^^^
/home/akuhlenschmi/work/llvm-test-suite/Fortran/gfortran/regression/volatile8.f90:55:17: portability: The actual argument 'a' should not be associated with dummy argument 'dummy10=' with VOLATILE attribute, because a temporary copy is required during the call [-Wportability]
      call sub10 (a) ! { dg-error "Pointer-array actual argument" }
                  ^
```
2025-09-19 19:53:06 -07:00
Eugene Epshteyn
2364736d6b
[flang] Fixed a crash in CheckReduce() (#156382)
Added extra checks to fix the crash.

Fixes #156167
2025-09-02 13:54:02 -04:00
Andre Kuhlenschmidt
a8680be158
[flang][semantics] add portability warning and tests for copy-in/copy-out case (#153263)
This PR adds some tests and a portability warning around
volatility/async, copy-in/copy-out, and definability. It was a NFC until
we decided to add the portability warning.
2025-08-27 10:09:05 -07:00
Andre Kuhlenschmidt
c649d31c59
[flang][warnings] systematically guard warnings (#154234)
This change modifies the messages API to make it impossible to forget to
call ShouldWarn by moving the call inside of the API. The low level API
should be avoided and developers should call Warn on a SemanticContext
or FoldingContext.
2025-08-27 10:08:26 -07:00
Eugene Epshteyn
4b6a4aa522
[flang] Consolidate copy-in/copy-out determination in evaluate framework (#151408)
New implementation of `MayNeedCopy()` is used to consolidate
copy-in/copy-out checks.

`IsAssumedShape()` and `IsAssumedRank()` were simplified and are both
now in `Fortran::semantics` workspace.

`preparePresentUserCallActualArgument()` in lowering was modified to use
`MayNeedCopyInOut()`

Fixes https://github.com/llvm/llvm-project/issues/138471
2025-08-26 18:40:13 -04:00
Valentin Clement (バレンタイン クレメン)
a196281896
[flang][cuda] Remove meaningless warning on CUDA shared arguments (#152404)
The warning in issued during the compatibility check makes little sense.
Just remove it as it is confusing.
2025-08-06 18:50:07 -07:00
Zhen Wang
48122a7977
[flang][cuda] Fix CUDA generic resolution for VALUE arguments in device procedures (#140952)
For actual arguments that have VALUE attribute inside device routines, treat them as if they have device attribute.
2025-06-10 16:15:12 -07:00
Peter Klausler
2ca2e1c9d5
[flang] Tune warning about incompatible implicit interfaces (#136788)
The compiler was emitting a warning about incompatible shapes being used
for two calls to the same procedure with an implicit interface when one
passed a whole array and the other passed a scalar. When the scalar is a
whole element of a contiguous array, however, we must allow for storage
association and not flag it as being a problem.
2025-05-13 07:48:05 -07:00
Peter Klausler
1d8ecbe948
[flang] Require contiguous actual pointer for contiguous dummy pointer (#139298)
When the actual argument associated with an explicitly CONTIGUOUS
pointer dummy argument is itself a pointer, it must also be contiguous.
(A non-pointer actual argument can associate with a CONTIGUOUS pointer
dummy argument if it's INTENT(IN), and in that case it's still just a
warning if we can't prove at compilation time that the actual is
contiguous.)

Fixes https://github.com/llvm/llvm-project/issues/138899.
2025-05-12 12:27:21 -07:00
Peter Klausler
ea87d7c0db
[flang] Add control and a portability warning for an extension (#137995)
This compiler allows an element of an assumed-shape array or POINTER to
be used in sequence association as an actual argument, so long as the
array is declared to have the CONTIGUOUS attribute.

Make sure that this extension is under control of a LanguageFeature
enum, so that a hypothetical compiler driver option could disable it,
and add an optional portability warning for its use.
2025-05-12 12:15:24 -07:00
Zhen Wang
ce69a60bc2
Skip contiguous check when ignore_tkr(c) is used (#138762)
The point of ignore_tkr(c) is to ignore both contiguous warnings and
errors for arguments of all attribute types.
2025-05-07 09:23:43 -07:00
Peter Klausler
544940846d
[flang][CUDA] Add error & warning for device argument first dimension… (#136058)
… discontiguity

For dummy assumed-shape/-rank device arrays, test the associated actual
argument for stride-1 contiguity, and report an error when the actual
argument is known to not be stride-1 contiguous and nonempty, or a
warning when when the actual argument is not known to be empty or
stride-1 contiguous.
2025-04-18 12:51:38 -07:00
Valentin Clement (バレンタイン クレメン)
1d0f8355b1
[flang][cuda] Relax compatibility rules when host,device procedure is involved (#134926)
Relax too restrictive rule for host, device procedure.
2025-04-08 14:55:11 -07:00
Peter Klausler
329bfa91b0
[flang] Fix crash in CO_REDUCE semantics (#131211)
A std::optional<> value was being accessed without first ensuring its
presence.
2025-03-19 12:00:23 -07:00
Peter Klausler
587f997db7
[flang] Catch C15104(4) violations when coindexing is present (#130677)
The value of a structure constructor component can't have a pointer
ultimate component if it is a coindexed designator.
2025-03-19 11:58:59 -07:00
Peter Klausler
fd8de7524d
[flang] Check actual/dummy coranks in more cases (#130167)
The check for equality of actual and dummy argument coranks was taking
place only for ALLOCATABLE coarrays; perform the check for all cases,
and refine the ALLOCATABLE check to apply only to cases that don't fail
the new more general check.
2025-03-10 13:19:58 -07:00
Peter Klausler
f6fc29d331
[flang] Check coranks on MOVE_ALLOC (#129944)
The FROM= and TO= arguments in a reference to the MOVE_ALLOC intrinsic
subroutine must have the same corank.
2025-03-10 13:18:23 -07:00
Peter Klausler
79a25e11fe
[flang] Further work on NULL(MOLD=allocatable) (#129345)
Refine handling of NULL(...) in semantics to properly distinguish
NULL(), NULL(objectPointer), NULL(procPointer), and NULL(allocatable)
from each other in relevant contexts.

Add IsNullAllocatable() and IsNullPointerOrAllocatable() utility
functions. IsNullAllocatable() is true only for NULL(allocatable); it is
false for a bare NULL(), which can be detected independently with
IsBareNullPointer().

IsNullPointer() now returns false for NULL(allocatable).

ALLOCATED(NULL(allocatable)) now works, and folds to .FALSE.

These utilities were modified to accept const pointer arguments rather
than const references; I usually prefer this style when the result
should clearly be false for a null argument (in the C sense), and it
helped me find all of their use sites in the code.
2025-03-03 14:46:35 -08:00
Jean-Didier PAILLEUX
a9b2e31fb0
[flang] Define CO_REDUCE intrinsic procedure (#125115)
Define the intrinsic `CO_REDUCE` and add semantic checks.
A test was already present but was at `XFAIL`. It has been modified to
take new messages into the output.
2025-03-03 20:50:02 +01:00
Peter Klausler
e843d514b1
[flang] Refine handling of SELECT TYPE associations in analyses (#128935)
A few bits of semantic checking need a variant of the
ResolveAssociations utility function that stops when hitting a construct
entity for a type or class guard. This is necessary for cases like the
bug below where the analysis is concerned with the type of the name in
context, rather than its shape or storage or whatever. So add a flag to
ResolveAssociations and GetAssociationRoot to make this happen, and use
it at the appropriate call sites.

Fixes https://github.com/llvm/llvm-project/issues/128608.
2025-02-27 14:32:12 -08:00
Peter Klausler
8b7a90b84b
[flang] Accept proc ptr function result as actual argument without IN… (#128771)
…TENT

A dummy procedure pointer with no INTENT attribute may associate with an
actual argument that is the result of a reference to a function that
returns a procedure pointer, we think.

Fixes https://github.com/llvm/llvm-project/issues/126950.
2025-02-27 14:31:24 -08:00
Peter Klausler
3e3855b0e5
[flang] Don't flag CLASS(*) ASSOCIATED() pointer or target as error (#125890)
As I read the standard, an unlimited polymorphic pointer or target
should be viewed as compatible with any data target or data pointer when
used in the two-argument form of the intrinsic function ASSOCIATED().

Fixes https://github.com/llvm/llvm-project/issues/125774.
2025-02-27 14:28:34 -08:00
Peter Klausler
9a49a03dc9
[flang] Refine handling of NULL() actual to non-optional allocatable … (#116126)
…dummy

We presently allow a NULL() actual argument to associate with a
non-optional dummy allocatable argument only under INTENT(IN). This is
too strict, as it precludes the case of a dummy argument with default
intent. Continue to require that the actual argument be definable under
INTENT(OUT) and INTENT(IN OUT), and (contra XLF) interpret NULL() as
being an expression, not a definable variable, even when it is given an
allocatable MOLD.

Fixes https://github.com/llvm/llvm-project/issues/115984.
2025-02-27 14:27:19 -08:00
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
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
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
3a8a52f4a5
[flang] Make IsCoarray() more accurate (#121415)
A designator without cosubscripts can have subscripts, component
references, substrings, &c. and still have corank. The current
IsCoarray() predicate only seems to work for whole variable/component
references. This was breaking some cases of THIS_IMAGE().
2025-01-08 13:16:56 -08:00