Commit Graph

227 Commits

Author SHA1 Message Date
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
Peter Klausler
7cc789bcfb [flang] Silence spurious errors from benign USE errors (#106097)
When USE association encounters a conflict that can't be resolved, it
produces a "UseError" symbol that will trigger an error message if that
symbol is ever actually used. UseError symbols that aren't used are
benign.

Ensure that UseError symbols don't run the gamut of declaration
checking. They were getting through, and could lead to spurious error
messages.

Fixes https://github.com/llvm/llvm-project/issues/106020.
2024-08-26 10:57:00 -07:00
Peter Klausler
25822dc392 [flang] Fix searches for polymorphic components (#102212)
FindPolymorphicAllocatableUltimateComponent needs to be
FindPolymorphicAllocatablePotentialComponent. The current search is
missing cases where a derived type has an allocatable component whose
type has a polymorphic allocatable component.
2024-08-08 11:07:40 -07:00
Peter Klausler
e83c5b25f3 [flang] Warn about automatic data in main program, disallow in BLOCK … (#102045)
…DATA

We allow automatic data objects in the specification part of the main
program; add an optional portability warning and documentation. Don't
allow them in BLOCK DATA. They're already disallowed as module
variables.
2024-08-08 11:06:32 -07:00
Peter Klausler
539a6b500c [flang] Detect use-before-decl errors on type parameters (#99947)
Ensure that type parameters are declared as such before being referenced
within the derived type definition. (Previously, such references would
resolve to symbols in the enclosing scope.)

This change causes the symbols for the type parameters to be created
when the TYPE statement is processed in name resolution. They are
TypeParamDetails symbols with no KIND/LEN attribute set, and they shadow
any symbols of the same name in the enclosing scope.

When the type parameter declarations are processed, the KIND/LEN
attributes are set. Any earlier reference to a type parameter with no
KIND/LEN attribute elicits an error.

Some members of TypeParamDetails have been retyped &/or renamed.
2024-07-30 09:42:15 -07:00
Peter Klausler
d6f314ce87 [flang] Accept IGNORE_TKR in separate module procedure interface (#98374)
We emit an incorrect error message when !DIR$ IGNORE_TKR appears in a
separate module procedure's interface declaration.

Fixes https://github.com/llvm/llvm-project/issues/98210.
2024-07-11 13:30:16 -07:00
Peter Klausler
d5285fef00 [flang] Downgrade error message to a portability warning (#98368)
f18 current emits an error when an assignment is made to an array
section with a vector subscript, and the array is finalized with a
non-elemental final subroutine. Some other compilers emit this error
because (I think) they want variables to only be finalized in place, not
by a subroutine call involving copy-in & copy-out of the finalized
elements.

Since many other Fortran compilers can handle this case, and there's
nothing in the standards to preclude it, let's downgrade this error
message to a portability warning.

This patch got complicated because the API for the WhyNotDefinable()
utility routine was such that it would return a message only in error
cases, and there was no provision for returning non-fatal messages. It
now returns either nothing, a fatal message, or a non-fatal warning
message, and all of its call sites have been modified to cope.
2024-07-11 13:12:00 -07:00
Peter Klausler
60c90336b6 [flang] Silence over-eager warning about interoperable character length (#97353)
Make the results of the two IsInteroperableIntrinsicType() utility
routines a tri-state std::optional<bool> so that cases where the
character length is simply unknown can be distinguished from those cases
where the length is known and not acceptable. Use this distinction to
not emit a confusing warning about interoperability with C_LOC()
arguments when the length is unknown and might well be acceptable during
execution.
2024-07-11 12:43:53 -07:00
Peter Klausler
9ab292d726 [flang] Add/fix some semantic checks for assumed-rank (#96194)
Catch some cases where assumed rank dummy arguments are not allowed.
2024-06-24 09:57:30 -07:00
Peter Klausler
3602efa78d [flang] Silence errors on C_LOC/C_FUNLOC in specification expressions (#96108)
Transformational functions from the intrinsic module ISO_C_BINDING are
allowed in specification expressions, so tweak some general checks that
would otherwise trigger error messages about inadmissible targets, dummy
procedures in specification expressions, and pure procedures with impure
dummy procedures.
2024-06-24 09:06:32 -07:00
jeanPerier
73cf014223 [flang] harden TypeAndShape for assumed-ranks (#96234)
SIZEOF and C_SIZEOF were broken for assumed-ranks because
`TypeAndShape::MeasureSizeInBytes` behaved as a scalar because the
`TypeAndShape::shape_` member was the same for scalar and assumed-ranks.

The easy fix would have been to add special handling in
`MeasureSizeInBytes` for assumed-ranks using the TypeAndShape
attributes, but I think this solution would leave `TypeAndShape::shape_`
manipulation fragile to future developers. Hence, I went for the
solution that turn shape_ into a `std::optional<Shape>`.
2024-06-24 10:21:04 +02:00
Peter Klausler
055df491ed [flang] Allow interoperable object to have interoperable derived type… (#94768)
… that's not BIND(C)

An interoperable BIND(C) object with a derived type should have a
BIND(C) derived type, but will now work with a derived type that
satisfies all of the requirements of a BIND(C) derived type.
2024-06-11 17:15:04 -07:00
Peter Klausler
8bcf40ba88 [flang] Adjust new warnings for extensions (#94485)
Prevent messages from module files, respect the language feature flags
when enabling the relaxed PURE dummy argument checking, and check that
the new warnings are enabled.
2024-06-11 17:09:17 -07:00
Peter Klausler
67081badfc [flang] Enforce F'2023 C15121 (#94418)
No specification expression in the declaration of the result variable of
an elemental function may depend on the value of a dummy argument. This
ensures that all of the results have the same type when the elemental
function is applied to the elements of an array.
2024-06-11 17:07:37 -07:00
Peter Klausler
56cd8a50b3 [flang] Relax BIND(C) derived type component check (#94392)
Allow an explicit BIND(C) derived type to have a non-BIND(C) component
so long as the component's type is interoperable and it satisfies all
other constraints.
2024-06-11 16:38:51 -07:00
Peter Klausler
0ee71124f4 [flang] Refine checks for intrinsic operator conflicts with CUDA defi… (#94389)
…ned operators

The checks for conflicts between defined operators/assignments and the
intrinsic operators/assignment need to take CUDA procedure and data
attributes into account to avoid false positive error messages.
2024-06-11 16:11:20 -07:00
Peter Klausler
b61d7ec16b [flang] Relax constraints on PURE/ELEMENTAL dummy arguments (#93748)
The standard requires that dummy arguments to PURE functions be
INTENT(IN) or VALUE, but PURE subroutines are allowed to have modifiable
dummy arguments. This makes it impossible to declare atomic operations
as PURE functions, which consequently makes such atomic operations
ineligible for use in parallel constructs and DO CONCURRENT.

This patch downgrades this error to a warning by default, which can be
seen with -pedantic & al. and remain an error with -Werror.
2024-06-03 13:46:31 -07:00
Peter Klausler
e2a3880d7f [flang] Revert two new interoperability semantic checks (#93112)
Two checks related to BIND(C) vs non-BIND(C) entry points with the same
dummy argument added by https://github.com/llvm/llvm-project/pull/92474
have turned out to be unnecessary. Revert them and adjust the tests.
2024-05-23 16:36:18 -07:00
Peter Klausler
c24f881340 [flang] Silence warnings from module files after recent change (#92834)
I modified declaration checking for interoperable objects to buffer its
generated messages as I had previously done for derived types and
procedure interfaces, but failed to modify all of the message creation
statements to use the new buffer, so some are now escaping when a module
file is being compiled. Fix to ensure that the new buffer is always
used.
2024-05-23 15:45:19 -07:00
Peter Klausler
6d2b23c46e [flang] Fix crash in error recovery (bad binding) (#92800)
A type-bound procedure that's bound to a name that isn't a procedure is
caught as an error, but can also lead to a crash in compatibility
checking later. Make that code more robust to failure.

Fixes https://github.com/llvm/llvm-project/issues/92678.
2024-05-23 15:14:18 -07:00
Peter Klausler
ab7930bd9f [flang] Relax checking of dummy procedures under BIND(C) (#92474)
As was done recently to allow derived types that are not explicitly
BIND(C), but meet the requirements of BIND(C), to be acceptable for use
in contexts nominally requiring BIND(C), this patch allows procedures
that are not explicitly BIND(C) to be used in contexts that nominally
require BIND(C) so long as (1) they meet the requirements of BIND(C),
and (2) don't use dummy arguments whose implementations may vary under
BIND(C), such as VALUE.
2024-05-17 15:50:46 -07:00
Peter Klausler
463f58a564 [flang] Further work on relaxing BIND(C) enforcement (#92029)
When a BIND(C) interface or subprogram has a dummy argument whose
derived type is not BIND(C) but meets the constraints and requirements
of a BIND(C) type, accept it with a warning.
2024-05-15 16:18:47 -07:00
Peter Klausler
7605ad8a2f [flang] Always check procedure characterizability (#92008)
When a procedure is defined with a subprogram but never referenced in a
compilation unit, it may not be characterized until lowering, and any
errors in characterization then may crash the compiler. So always ensure
that procedure definitions are characterizable in declaration checking.

Fixes https://github.com/llvm/llvm-project/issues/91845.
2024-05-15 16:08:06 -07:00
Valentin Clement (バレンタイン クレメン)
7c555cb234 [flang][cuda] Reapply restriction on kernel subprogram but not device (#91764)
The restriction was completely removed in #89677. This was a bit too
much. Reapply the restriction on elemental, pure and recursive but only
for kernel subprogram (`grid_global` and `global` attributes).
2024-05-10 10:47:04 -07:00
Peter Klausler
19b41f40a4 [flang] Complete RESULT() name constraint checking (#91476)
There are two constraints in the language that prohibit the use of an
ENTRY name being used as the RESULT() variable of the function or
another ENTRY name in the same function's scope; neither can the name of
the function be used as the RESULT() of an ENTRY.
    
Move most of the existing partial enforcement of these constraints from
name resolution into declaration checking, complete it, and add more
cases to the tests.
2024-05-09 11:31:13 -07:00
Peter Klausler
90501be35b [flang] Accept interoperable types without BIND(C) (#91363)
A derived type that meets (most of) the requirements of an interoperable
type but doesn't actually have the BIND(C) attribute can be accepted as
an interoperable type, with optional warnings.
2024-05-09 11:04:50 -07:00
Peter Klausler
d742c2aa25 [flang] Move EQUIVALENCE object checking to check-declarations.cpp (#91259)
Move EQUIVALENCE object checking from resolve-names-utils.cpp to
check-declarations.cpp, where it can work on fully resolved symbols and
reduce clutter in name resolution. Add a check for EQUIVALENCE objects
that are not ObjectEntityDetails symbols so that attempts to equivalence
a procedure are caught.
2024-05-09 10:53:29 -07:00
Peter Klausler
505f6da196 [flang] Ensure all warning/portability messages are guarded by Should… (#90518)
…Warn()

Many warning messages were being emitted unconditionally. Ensure that
all warnings are conditional on a true result from a call to
common::LanguageFeatureControl::ShouldWarn() so that it is easy for a
driver to disable them all, or, in the future, to provide per-warning
control over them.
2024-05-01 14:33:14 -07:00
Peter Klausler
465807eedc [flang] Catch missing "not a dummy argument" cases (#90268)
Declaration checking is looking for inappropriate usage of the INTENT,
VALUE, & OPTIONAL attributes in multiple places, and some oddball cases
like ENTRY points are not checked. Centralize the check for attributes
that apply only to dummy arguments into one spot.
2024-05-01 12:25:31 -07:00
Valentin Clement (バレンタイン クレメン)
1fb5083aed [flang][cuda] Accept variable with UNIFIED attribute in main (#90647)
UNIFIED variables are accept in program scope. Update the check to allow
them.
2024-04-30 14:11:35 -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
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 (バレンタイン クレメン)
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 (バレンタイン クレメン)
3090efc6b6 [flang][cuda] Relax semantic for device variable in block construct (#89330) 2024-04-18 18:12:41 -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
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
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
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
Peter Klausler
83ca78deb9 [flang] Emit "raw" name for procedure interface in module file (#83915)
Save both the raw procedure interface symbol as well as the result of
passing it through GetUltimate() and BypassGeneric() in symbol table
entries with ProcEntityDetails. The raw symbol of the interface needs to
be the one used for emitting procedure symbols to module files.

Fixes https://github.com/llvm/llvm-project/issues/83836.
2024-03-05 12:00:46 -08:00
Peter Klausler
3cef82d607 [flang] Fix bogus error message about invalid polymorphic entity (#83733)
The check for declarations of polymorphic entities was emitting a bogus
error for one (or more) layers of pointers to procedures returning
pointers to polymorphic types.

Fixes https://github.com/llvm/llvm-project/issues/83292.
2024-03-05 10:57:38 -08:00
Peter Klausler
1c530b3d9f [flang] Whether a procedure's interface is explicit or not is not a d… (#82796)
…istinguishing characteristic

We note whether a procedure's interface is explicit or implicit as an
attribute of its characteristics, so that other semantics can be checked
appropriately, but this internal attribute should not be used as a
distinguishing characteristic in itself.

Fixes https://github.com/llvm/llvm-project/issues/81876.
2024-03-01 15:56:40 -08:00
Valentin Clement (バレンタイン クレメン)
99f31bab86 [flang][cuda] Fix semantic for the CONSTANT attribute (#82821)
Object with the CONSTANT attribute cannot be declared in the host
subprogram.

It can be declared in a module or a device subprogram.

Adapt the semantic check to trigger the error in host subprogram.
2024-02-23 12:56:24 -08:00