268 Commits

Author SHA1 Message Date
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
c66546bfc8
[flang] Improve error message for polymorphic implicit interface (#177225)
PROCEDURE(CLASS(...)) specifies a procedure with an implicit interface
whose result is polymorphic. That turns out to never be a valid
declaration, since a CLASS(...) function result is required to also be
POINTER or ALLOCATABLE, both of which require the presence of an
explicit interface. We caught this error already, but the message should
be improved for procedures.

Fixes https://github.com/llvm/llvm-project/issues/176861.
2026-01-22 07:33:14 -08:00
Valentin Clement (バレンタイン クレメン)
fe5f6f5be8
[flang][cuda] Allow pointer object with the managed attribute (#177304) 2026-01-22 08:30:09 -07:00
Peter Klausler
bc99ce0426
[flang] Extension: Allow POINTER,INTENT(IN) passed objects (#172175)
ISO Fortran now accepts a non-pointer actual argument to associate with
a dummy argument with the POINTER attribute if it is also INTENT(IN), so
long as the actual argument is a valid target for the pointer. But
passed-object dummy arguments still have a blanket prohibition against
being pointers in the ISO standard. Relax that constraint in the case of
INTENT(IN) so that passed objects can also benefit from the feature.

Fixes https://github.com/llvm/llvm-project/issues/172157.
2025-12-19 14:31:49 -08:00
Jean-Didier PAILLEUX
87fb7b002d
[flang] Adding NOTIFY specifier in image selector and add notify type checks (#148810)
This PR adds support for the NOTIFY specifier in the image selector as
described in the 2023 standard, and add checks for the NOTIFY_TYPE type.
2025-11-05 16:35:25 +01: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
1e237b1785
[flang] Catch function result that is non-pointer procedure (#164664)
A function result that is a procedure must be a procedure pointer.
2025-10-24 14:14:35 -05:00
Peter Klausler
a377b85634
[flang] Adjust needless warning (#164500)
When an external procedure has an explicit interface in one scope, and
an implicit interface in another, and there's at least one call to it
from which dummy argument information can be inferred, don't emit a
warning about potential incompatibility if the only difference in their
characteristics is that one of their interfaces was implicit.
2025-10-24 14:11:22 -05:00
Andre Kuhlenschmidt
d70801b4e7
[flang][semantics] ensure defined io dummies are not arrays. (#162744)
fixes [#162709](https://github.com/llvm/llvm-project/issues/162709)
2025-10-15 18:48:19 -07: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
0b8381aba9
[flang] Fix bogus generic interface error due to hermetic module files (#161607)
When the same generic interface is processed via USE association from
its original module file and from a copy in a hermetic module file, we
need to do a better job at detecting and omitting duplicate specific
procedures. They won't have the same symbol addresses, but they will
have the same name, module name, and characteristics. This will avoid a
bogus error about multiple specific procedures matching the actual
arguments later when the merged generic interface is referenced.
2025-10-03 10:48:32 -07:00
Peter Klausler
1fba01a51d
[flang] Consolidate & clean up COMMON block checks (#161286)
COMMON block checks are split between name resolution and declaration
checking. We generally want declaration checks to take place after name
resolution, and the COMMON block checks that are currently in name
resolution have some derived type analyses that are redundant with the
derived type component iteration framework used elsewhere in semantics.
So move as much as possible into declaration checking, use the component
iteration framework, and cope with the missing COMMON block name case
that arises with blank COMMON when placing the error messages.
2025-10-03 10:47:50 -07:00
Valentin Clement (バレンタイン クレメン)
c242aff245
[flang][cuda][openacc] Create new symbol in host_data region for CUDA Fortran interop (#161613) 2025-10-02 04:43:45 -10:00
Peter Klausler
2b0f25d9c3
[flang] Fix crash in error recovery (#158750)
Code to attach a procedure's declaration to an error message did not
allow for ENTRY names, which can be in the global scope.

Fixes https://github.com/llvm/llvm-project/issues/158405.
2025-09-17 09:15:34 -07:00
Eugene Epshteyn
a34b110797
[flang] Check for BIND(C) name conflicts with alternate entries (#156563)
Added IsAlternateEntry() and modified IsExternalProcedureDefinition() to
also check for alternate entries.

(IsExternalProcedureDefinition() is called from
CheckHelper::CheckGlobalName(), which checks for duplicate global
symbols.)

Fixes #62778
2025-09-03 19:22:34 -04: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
Peter Klausler
b01ab5318e
[flang][CUDA] Apply intrinsic operator overrides (#151018)
Fortran's intrinsic numeric and relational operators can be overridden
with explicit interfaces so long as one or more of the dummy arguments
have the DEVICE attribute. Semantics already allows this without
complaint, but fails to replace the operations with the defined specific
procedure calls when analyzing expressions.
2025-07-30 11:41:40 -07:00
Peter Klausler
3de11b7062
[flang] Catch bad members of BIND(C) COMMON block (#148971)
Variables that can't be BIND(C), like pointers, can't be in a BIND(C)
common block, either.

Fixes https://github.com/llvm/llvm-project/issues/148922.
2025-07-16 09:10:26 -07:00
jeanPerier
621a7d0f66
[flang] silence bogus error with BIND(C) variable in hermetic module (#143737)
The global name semantic check was firing in a bogus way when BIND(C)
variables are in hermetic module.

Do not raise the error if one of the symbol with the conflicting global
name is an "hermetic variant" of the other.
2025-06-11 19:02:47 +02:00
Peter Klausler
4b23d4c7ca
[flang] Extension: allow override of inaccessible DEFERRED binding (#142691)
Inaccessible procedure bindings can't be overridden, but DEFERRED
bindings must be in a non-abstract extension. We presently emit an error
for an attempt to override an inaccessible binding in this case. But
some compilers accept this usage, and since it seems safe enough, I'll
allow it with an optional warning. Codes can avoid this warning and
conform to the standard by changing the deferred bindings to be public.
2025-06-04 09:23:34 -07:00
Peter Klausler
53f0367ab0
[flang] Fix spurious error on defined assignment in PURE (#139186)
An assignment to a whole polymorphic object in a PURE subprogram that is
implemented by means of a defined assignment procedure shouldn't be
subjected to the same definability checks as it would be for an
intrinsic assignment (which would also require it to be allocatable).

Fixes https://github.com/llvm/llvm-project/issues/139129.
2025-05-13 07:48:54 -07:00
Peter Klausler
d90bbf147b
[flang] Stricter checking of v_list DIO arguments (#139329)
Catch assumed-rank arguments to defined I/O subroutines, and ensure that
v_list dummy arguments are vectors.

Fixes https://github.com/llvm/llvm-project/issues/138933.
2025-05-12 12:27:56 -07:00
Peter Klausler
8fc1a6496a
[flang] Emit error when DEFERRED binding overrides non-DEFERRED (#139325)
Fixes https://github.com/llvm/llvm-project/issues/138915.
2025-05-12 12:27:39 -07:00
Andre Kuhlenschmidt
a18adb2358
[flang] fix scoping of cray pointer declarations and add check for initialization (#136776)
This PR:
- makes Cray pointer declarations shadow previous bindings instead of
modifying them,
- errors when the pointee of a cray pointee has the SAVE attribute, and
- adds a missing newline after dumping the list of cray pointers in a
scope.

Closes #135579
2025-05-02 07:35:24 -07:00
Peter Klausler
b99dab2587
[flang] Exempt construct entities from SAVE check for PURE (#131383)
A PURE subprogram can't have a local variable with the SAVE attribute.
An ASSOCIATE or SELECT TYPE construct entity whose selector is a
variable will return true from IsSave(); exclude them from the local
variable check.

Fixes https://github.com/llvm/llvm-project/issues/131356.
2025-03-19 12:01:18 -07:00
Peter Klausler
abebac5b86
[flang] Dig deeper to find more EVENT_TYPE/LOCK_TYPE misuse (#130687)
Only objects may have these types, or have potential subobject
components with these types.
2025-03-19 11:59:18 -07:00
Peter Klausler
b7557ab34d
[flang] Catch disallowed usage of coarrays in defined I/O (#129907)
Defined input/output subroutines must conform to documented interfaces
that do not allow for coarray dummy arguments.
2025-03-10 13:17:50 -07:00
Peter Klausler
f6e83664e0
[flang] Improve two coarray error messages (#129597)
Two messages that complain about local variables mention that they don't
have the SAVE attribute; in both cases, it would be okay if they were
ALLOCATABLE instead. Clarify the messages.
2025-03-03 14:47:02 -08:00
Peter Klausler
b2ba43a9c1
[flang] Refine checking of type-bound generics (#129292)
I merged a patch yesterday
(https://github.com/llvm/llvm-project/pull/128980) that strengthened
error detection of indistinguishable specific procedures in a type-bound
generic procedure, and broke a couple of tests. Refine the check so that
it doesn't flag valid cases of overridden bindings, and add a thorough
test with all of the boundary cases that I can think of.
2025-03-03 14:46:08 -08:00
Peter Klausler
51dc52631c
[flang] Catch more defined I/O conflicts (#129115)
The code that checks for conflicts between type-bound defined I/O
generic procedures and non-type-bound defined I/O interfaces only works
when then procedures are defined in the same module as subroutines. It
doesn't catch conflicts when either are external procedures, procedure
pointers, dummy procedures, &c. Extend the checking to cover those cases
as well.

Fixes https://github.com/llvm/llvm-project/issues/128752.
2025-02-27 16:16:34 -08:00
Kazu Hirata
44c6616a4a [flang] Fix a warning
This patch fixes:

  flang/lib/Semantics/check-declarations.cpp:2009:15: error: unused
  variable 'kind' [-Werror,-Wunused-variable]
2025-02-27 14:48:13 -08:00
Peter Klausler
cbef629838
[flang] Catch type-bound generic with inherited indistinguishable spe… (#128980)
…cific

When checking generic procedures for indistinguishable specific
procedures, don't neglect to include specific procedures from any
accessible instance of the generic procedure inherited from its parent
type..

Fixes https://github.com/llvm/llvm-project/issues/128760.
2025-02-27 14:33:11 -08:00
Peter Klausler
78acf7bb0a
[flang] Enforce C1503 (#128962)
Enforce an obscure constraint from the standard: an abstract interface
is not allowed to have the same name as an intrinsic type keyword. I
suspect this is meant to prevent a declaration like "PROCEDURE(REAL),
POINTER :: P" from being ambiguous.

Fixes https://github.com/llvm/llvm-project/issues/128744.
2025-02-27 14:32:30 -08:00
Peter Klausler
523537f0c9
[flang] Silence spurious error (#128777)
When checking for conflicts between type-bound generic defined I/O
procedures and non-type-bound defined I/O generic interfaces, don't
worry about conflicts where the type-bound generic interface is
inaccessible in the scope around the non-type-bound interface.

Fixes https://github.com/llvm/llvm-project/issues/126797.
2025-02-27 14:31:50 -08:00
Peter Klausler
fce29486ac
[flang] Fix bogus error on defined I/O procedure. (#125898)
The check that "v_list" be deferred shape is just wrong; there are no
deferred shape non-pointer non-allocatable dummy arguments in Fortran.
Correct to check for an assumed shape dummy argument. And de-split the
error messages that were split across multiple source lines, making them
much harder to find with grep.

Fixes https://github.com/llvm/llvm-project/issues/125878.
2025-02-27 14:29:00 -08:00
Peter Klausler
29025a0600
[flang] Catch more semantic errors with coarrays (#125536)
Detect and report a bunch of uncaught semantic errors with coarray
declarations. Add more tests, and clean up bad usage in existing tests.
2025-02-27 14:28:08 -08:00
Valentin Clement (バレンタイン クレメン)
b00b193728
[flang][cuda] Allow POINTER component to have device attribute (#126116) 2025-02-06 19:43:04 -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
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
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
c1c9929028
[flang] Allow a few irrelevant attributes, with warning (#117374)
INTENT, VALUE, and OPTIONAL attributes apply only to dummy arguments. A
couple older compilers accept them, usually with a warning, if they are
applied to names that are not dummy arguments, and they show up in some
older non-portable source code. Change these cases into stern warnings
by default.
2024-12-02 12:25:21 -08:00
Peter Klausler
d20f55fbd5
[flang] Silence bogus error on local proc pointer initializer (#116663)
A procedure pointer is allowed to be initialized with the subprogram in
which it is local, assuming that other requirements are satisfied.

Add a good test for local procedure pointer initialization, as no test
existed for the error message in question.

Fixes https://github.com/llvm/llvm-project/issues/116566.
2024-11-19 16:20:08 -08:00
Peter Klausler
b3026bab91
[flang] Soften interoperability error when standard allows (#115092)
The standard doesn't require that an interoperable procedure's dummy
arguments have interoperable derived types in some cases. Although
nearly all extant Fortran compilers emit errors, some don't, and things
should work; so reduce the current fatal error message to an optional
portability warning.

Fixes https://github.com/llvm/llvm-project/issues/115010.
2024-11-14 14:56:44 -08:00
Valentin Clement (バレンタイン クレメン)
a878dc8fb3
[flang][cuda] Do not emit warning for SHARED variable in device subprogram (#115195)
SHARED attribute is explicitly meant to be used in device subprogram
(https://docs.nvidia.com/hpc-sdk/compilers/cuda-fortran-prog-guide/index.html#cfpg-var-qual-attr-shared).

Do not emit warning.
2024-11-06 13:19:09 -08:00
Peter Klausler
ce5edfd232
[flang] Finer error detection in separate module procedure case (#110912)
When a separate module procedure has a dummy procedure argument that is
simply declared EXTERNAL in its interface but is actually called as a
subroutine or function in its definition, the compiler is emitting an
error message. This is too strong; an error is appropriate only when the
dummy procedure in the definition has an interface that is incompatible
with the one in the interface definition.

However, this is not a safe coding practice, and can lead to trouble
during execution if a function is passed as an actual argument but
called as a subroutine in the procedure (or the other way around), so
add a warning message as well for this case (off by default).

Fixes https://github.com/llvm/llvm-project/issues/110797.
2024-10-07 13:17:10 -07:00
Peter Klausler
0f973ac783
[flang] Tag warnings with LanguageFeature or UsageWarning (#110304)
(This is a big patch, but it's nearly an NFC. No test results have
changed and all Fortran tests in the LLVM test suites work as expected.)

Allow a parser::Message for a warning to be marked with the
common::LanguageFeature or common::UsageWarning that controls it. This
will allow a later patch to add hooks whereby a driver will be able to
decorate warning messages with the names of its options that enable each
particular warning, and to add hooks whereby a driver can map those
enumerators by name to command-line options that enable/disable the
language feature and enable/disable the messages.

The default settings in the constructor for LanguageFeatureControl were
moved from its header file into its C++ source file.

Hooks for a driver to use to map the name of a feature or warning to its
enumerator were also added.

To simplify the tagging of warnings with their corresponding language
feature or usage warning, to ensure that they are properly controlled by
ShouldWarn(), and to ensure that warnings never issue at code sites in
module files, two new Warn() member function templates were added to
SemanticsContext and other contextual frameworks. Warn() can't be used
before source locations can be mapped to scopes, but the bulk of
existing code blocks testing ShouldWarn() and FindModuleFile() before
calling Say() were convertible into calls to Warn(). The ones that were
not convertible were extended with explicit calls to
Message::set_languageFeature() and set_usageWarning().
2024-10-02 08:54:49 -07:00
Peter Klausler
b0bdc7fcc9
[flang] Fix subtle type naming bug in module file output (#108892)
A derived type specification in semantics holds both its source name
(for location purposes) and its ultimate derived type symbol. But for
correct module file generation of a structure constructor using that
derived type spec, the original symbol may be needed so that USE
association can be exposed.

Save both the original symbol and its ultimate symbol in the
DerivedTypeSpec, and collect the right one when traversing expressions
(specifically for handling initialization in module files).

Fixes https://github.com/llvm/llvm-project/issues/108827.
2024-09-18 12:18:50 -07:00
Peter Klausler
8ed8210690
[flang] Downgrade error message to warning (#108115)
It is a non-mandatory error to reference an external procedure via an
implicit interface declaration (EXTERNAL or PROCEDURE()) when the
external procedure has an interface that requires the presence of an
explicit interface to be called.

Until now, the compiler has issued a fatal error message from semantics
for this situation. But (1) there are situations, such as passing such
an EXTERNAL as an actual argument, or as the target of a procedure
pointer assignment, where little or no harm is done, (2) other compilers
don't/can't detect this error, even when the procedure's definition is
in the same source file, and (3) it shows up in some real applications.

So downgrade this error to a stern warning. Perhaps in the future the
compiler could resume emission of a hard error in the cases where the
EXTERNAL procedure is actually known to be called via its implicit
interface.
2024-09-12 09:09:42 -07:00
Peter Klausler
ce392471c0
[flang] Silence spurious error on non-CUDA use of CUDA module (#107444)
When a module file has been compiled with CUDA enabled, don't emit
spurious errors about non-interoperable types when that module is read
by a USE statement in a later non-CUDA compilation.
2024-09-10 14:08:55 -07:00