Commit Graph

168 Commits

Author SHA1 Message Date
Peter Klausler
a4745ff99b [flang] Detect more misparsed statement functions (same name as funct… (#73852)
…ion result)

A function can't return a statement function, so an apparent attempt to
define a statement function with the same name as the function's result
must be a misparsed assignment statement.
2023-11-30 13:35:07 -08:00
Peter Klausler
1c91d9bdea [flang] Ensure that portability warnings are conditional (#71857)
Before emitting a warning message, code should check that the usage in
question should be diagnosed by calling ShouldWarn(). A fair number of
sites in the code do not, and can emit portability warnings
unconditionally, which can confuse a user that hasn't asked for them
(-pedantic) and isn't terribly concerned about portability *to* other
compilers.

Add calls to ShouldWarn() or IsEnabled() around messages that need them,
and add -pedantic to tests that now require it to test their portability
messages, and add more expected message lines to those tests when
-pedantic causes other diagnostics to fire.
2023-11-13 16:13:50 -08:00
Peter Klausler
b288b412ed [flang] Enforce C839 (#71239)
An assumed-rank array may not be a coarray and may not have the VALUE
attribute.
2023-11-13 14:31:20 -08:00
Peter Klausler
9191738764 [flang] Accept CONTIGUOUS attribute when redundant (#70853)
As an extension, accept the redundant use of the CONTIGUOUS attribute
when applied to scalars and to simply contiguous objects, with a
portability warning.
2023-10-31 16:04:35 -07:00
Peter Klausler
f19af90cf8 [flang][cuda] Remove check for obsolete constraint (#70707)
The online CUDA Fortran documentation states that a device subprogram
must be a top-level module subprogram, but this has turned out to be an
obsolete constraint. Stop enforcing it.
2023-10-31 12:39:18 -07:00
Peter Klausler
11529d5b3b [flang] Fine-tune function result equivalence checking (#70260)
When a separate module function's definition has a redundant interface
-- it's defined with MODULE FUNCTION, not MODULE PROCEDURE -- the check
for result type equivalence needs to allow for character lengths that
are the results of specification expressions. At present,
identical-looking length specification expression don't compare equal,
since they can refer to distinct dummy argument symbols. Ensure just
that they are both constant or not, and if constant, that the lengths
have the same value.
2023-10-31 12:05:29 -07:00
Peter Klausler
e87cdda35e [flang] Fix bogus error on aliased derived type (#69959)
When a derived type definition is visible by two or more names in the
same scope due to USE renaming, any generic ASSIGNMENT(=) or OPERATOR()
bindings in the type will produce incorrect error messages about
indistinguishable specific procedures. This is due to the use of a
std::vector<> to hold a sequence of symbols and some derived information
for the specific procedures of the generic name. Change to a std::map<>
indexed by the ultimate symbol of each specific so that duplicates
cannot arise.
2023-10-31 11:26:30 -07:00
Peter Klausler
a9b3f20015 [flang] Fix regression in submodule symbol checking (#69778)
The change https://github.com/llvm/llvm-project/pull/67361 removed
submodule name symbols from the name dictionaries of their parent
(sub)modules to prevent needless errors about name clashes, but these
symbols still need to be checked for things like excessive length.
2023-10-31 10:49:01 -07:00
Peter Klausler
c2f642d90d [flang] Derived type structural equivalence (#69376)
F'202X 7.5.2.4 describes conditions under which two derived type
definitions are to be considered equivalent. These rules are already
implemented in Evaluate/type.cpp but not exposed for general use;
rearrange the code a little so that the compatibility checking of
separate module procedure interfaces and explicit definitions can use it
to avoid emitting a bogus error message.

Fixes https://github.com/llvm/llvm-project/issues/67946.
2023-10-30 16:41:08 -07:00
jeanPerier
1062c140f8 [flang] Prevent IR name clashes between BIND(C) and external procedures (#66777)
Defining a procedure with a BIND(C, NAME="...") where the binding label
matches the assembly name of a non BIND(C) external procedure in the
same file causes a failure when generating the LLVM IR because of the
assembly symbol name clash.

Prevent this crash with a clearer semantic error.
2023-09-20 10:00:28 +02:00
Peter Klausler
338e312503 [flang] Fix bogus warning about missing FINAL on assumed-rank (#66250)
The warning message about a derived type not having a FINAL subroutine
for a particular object's rank should not issue for an assumed-rank
dummy argument.
2023-09-18 11:40:55 -07:00
Peter Klausler
f82ee15554 [flang] Don't check dummy vs. actual result rank for assumed-rank poi… (#66237)
…nters

When associating a function result pointer as an actual argument with a
dummy pointer that is assumed-rank, don't emit a bogus error.
2023-09-13 16:52:15 -07:00
Peter Klausler
c0f5015afb [flang] Foil attempts to put automatic objects in COMMON (#66228)
We were catching automatic objects in modules and SAVE, but not in
COMMON blocks.

Fixes https://github.com/llvm/llvm-project/issues/65003.
2023-09-13 14:33:59 -07:00
Peter Klausler
0c0b2ea988 [flang] Check procedure pointer initializations; clean up ELEMENTAL
Implements compatibility checking for initializers in procedure pointer
declarations.  This work exposed some inconsistency in how ELEMENTAL
interfaces were handled and checked, from both unrestricted intrinsic
functions and others, and some refinements needed for function result
compatbility checking; these have also been ironed out.  Some new
warnings are now emitted, and this affected a dozen or so tests.

Differential Revision: https://reviews.llvm.org/D159026
2023-08-29 15:08:23 -07:00
Peter Klausler
031b4e5e79 [flang] Support SELECT RANK on allocatables & pointers
Unlike other executable constructs with associating selectors, the
selector of a SELECT RANK construct can have the ALLOCATABLE or POINTER
attribute, and will work as an allocatable or object pointer within
each rank case, so long as there is no RANK(*) case.

Getting this right exposed a correctness risk with the popular
predicate IsAllocatableOrPointer() -- it will be true for procedure
pointers as well as object pointers, and in many contexts, a procedure
pointer should not be acceptable.  So this patch adds the new predicate
IsAllocatableOrObjectPointer(), and updates some call sites of the original
function to use the new one.

Differential Revision: https://reviews.llvm.org/D159043
2023-08-29 14:56:15 -07:00
Peter Klausler
77e965ef45 [flang] Allow for submodule override of module procedure
When checking that a module procedure definition is unique, allow for
the possibility that a submodule may contain a module procedure
interface that shadows a module procedure of the same name in its
(sub)module parent.   In other words, module procedure definitions
need only be unique in the tree of submodules rooted at the (sub)module
containing the relevant module procedure interface.

Differential Revision: https://reviews.llvm.org/D159033
2023-08-29 09:00:26 -07:00
Peter Klausler
6bc14f238e [flang] Foil attempts to require interoperable pointers be CONTIGUOUS
BIND(C) interoperable pointer descriptors may not be required to be
CONTIGUOUS in procedure interfaces.

(Also fixed erroneous true result from IsDescriptor() predicate for
assumed-size arrays that was exposed by testing.)

Fixes llvm-test-suite/Fortran/gfortran/regression/bind_c_contiguous.f90.

Differential Revision: https://reviews.llvm.org/D157342
2023-08-08 11:44:46 -07:00
Peter Klausler
d325c5d00b [flang] Extension: unrestricted intrinsics as specifics in generics
At least one other Fortran compiler supports the use of unrestricted intrinsic
functions as specific procedures in generic interfaces, and the usage seems
to be both useful and unambiguous.  Support it with a portability warning.

Fixes llvm-test-suite/Fortran/gfortran/regression/pr95500.f90.

Differential Revision: https://reviews.llvm.org/D157333
2023-08-08 10:46:24 -07:00
Peter Klausler
24d293913c [flang] Fix portability warning that was incorrectly an "else if"
A semantics check for an assumed-length dummy procedure pointer was
inappropriately part of an "else" clause for a preceding check,
causing it to not be applied in all situations.

Differential Revision: https://reviews.llvm.org/D155975
2023-07-21 15:34:53 -07:00
Peter Klausler
24445fc15c [flang] Disallow ASYNCHRONOUS for subroutine
The check for inappropriate usage of the ASYNCHRONOUS attribute
needed to be moved in declaration checking so that it can catch
attempts to use it on a subroutine.

Differential Revision: https://reviews.llvm.org/D155970
2023-07-21 13:40:30 -07:00
Peter Klausler
0bb3260b7c [flang] Fix constraint check on CLASS() entities
Entities declared with CLASS() must be dummy arguments, allocatables,
or pointers.  This constraint check is currently correct for objects
but not for procedures, and getting it right needs to avoid being
confused between pointers to procedures and pointers returned by
procedures.

Differential Revision: https://reviews.llvm.org/D155491
2023-07-17 12:19:30 -07:00
Peter Klausler
80a54edc14 [flang] Disallow noninteroperable dummy procedures from interoperable procedures
A BIND(C) interoperable procedure must have only interoperable dummy procedures.

Differential Revision: https://reviews.llvm.org/D155488
2023-07-17 11:33:04 -07:00
Peter Klausler
1c900ed373 [flang] Catch error: COMMON block and implicit interface external subprogram with same name
Declaration checking catches the error of a COMMON block and a subprogram
definition having the same name, but misses the case of a COMMON block
and an a reference to an external subprogram with an implicit interface.
Fix.  Fixes bug https://github.com/llvm/llvm-project/issues/63247.

Differential Revision: https://reviews.llvm.org/D153786
2023-06-27 13:18:30 -07:00
Kelvin Li
a734de6d37 [flang] semantic checking for unsupported features in PPC vector type
Assumed-shape, deferred-shape and assumed rank entities of PPC vector
type are not supported.

Differential Revision: https://reviews.llvm.org/D152864
2023-06-14 10:44:16 -04:00
Peter Klausler
3332dc3258 [flang] CUDA Fortran - part 3/5: declarations checking
Implements checks for CUDA Fortran attributes on objects, types, and
subprograms.  Includes a couple downgrades of existing errors into
warnings that were exposed during testing.

Depends on https://reviews.llvm.org/D150159 &
https://reviews.llvm.org/D150161.

Differential Revision: https://reviews.llvm.org/D150162
2023-05-31 10:42:26 -07:00
Peter Klausler
a8654b4457 [flang] More precise CONTIGUOUS checking
A recent fix to avoid bogus errors with the CONTIGUOUS attribute caused
declaration checking to miss errors with applications of CONTIGUOUS to
names that are not variables.  Restore those error messages, and
add tests to ensure that the original problem remains fixed while
the recent regressions have been resolved.

Differential Revision: https://reviews.llvm.org/D151124
2023-05-22 12:02:50 -07:00
Peter Klausler
28cc9606c0 [flang] Fix bogus errors about CONTIGUOUS attribute
Incorrect error messages were issuing for symbol table entries
with the CONTIGUOUS attribute that didn't deserve them, like
host association symbols.  Put the CONTIGUOUS check into
CheckObjectEntity().

Differential Revision: https://reviews.llvm.org/D150712
2023-05-16 14:01:24 -07:00
Peter Klausler
191d48723f [flang] Finer control over warnings
Establish a set of optional usage warnings, and enable some
only in "-pedantic" mode that, in our subjective experience
with application codes, seem to issue frequently without
indicating usage that really needs to be corrected.  By default,
with this patch the compiler should appear to be somewhat less
persnickety but not less informative.

Differential Revision: https://reviews.llvm.org/D150710
2023-05-16 13:56:24 -07:00
Peter Klausler
78f19d9ba5 [flang] Relax two !DIR$ IGNORE_TKR error cases with descriptor arguments
Allow two currently erroneous cases of !DIR$ IGNORE_TKR errors: allocatable
and pointers, and IGNORE_TKR(R) on (other) arguments passed via descriptors.
Downgrade these cases to warnings when they appear in external interfaces,
since their implementations may well be in C.  But retain the error status
on these cases for module procedures, since the Fortran implementation
probably can't work.

Differential Revision: https://reviews.llvm.org/D148833
2023-04-20 13:40:10 -07:00
Peter Klausler
864cb2aa45 [flang] Semantics for !DIR$ IGNORE_TKR
Implement semantics for the IGNORE_TKR directive as it is interpreted
by the PGI / NVFORTRAN compiler.

Differential Revision: https://reviews.llvm.org/D148643
2023-04-19 09:39:37 -07:00
Jean Perier
6f5df4199e [flang] Fold IS_CONTIGUOUS for TYPE(*) when possible
TYPE(*) arguments fell through in IS_CONTIGUOUS folding
because they are not Expr<SomeType>. Expose entry point for
symbols in IsContiguous and use that.

The added test revealed that IS_CONTIGUOUS was folded to
false for assumed rank arguments. Fix this: the contiguity of
assumed rank without the CONTIGUOUS argument can only be
verified at runtime.

Differential Revision: https://reviews.llvm.org/D148128
2023-04-14 08:42:25 +02:00
Peter Klausler
7cf1608b4d [flang] Rework handling of non-type-bound user-defined I/O
A fairly recent introduction of runtime I/O APIs called OutputDerivedType()
and InputDerivedType() didn't cover NAMELIST I/O's need to access
non-type-bound generic interfaces for user-defined derived type I/O
when those generic interfaces are defined in some scope other than the
one that defines the derived type.

The patch adds a new data structure shared between lowering
and the runtime that can represent all of the cases that can
arise with non-type-bound defined I/O.  It can represent
scopes in which non-type-bound defined I/O generic interfaces
are inaccessible, too, due to IMPORT statements.

The data structure is now an operand to OutputDerivedType() and
InputDerivedType() as well as a data member in the NamelistGroup
structure.

Differential Revision: https://reviews.llvm.org/D148257
2023-04-13 15:35:01 -07:00
Peter Klausler
e9a8ab004c [flang] Use definability tests for better PURE constraint checking
Many semantic checks for constraints related to PURE subprograms
can be implemented in terms of Semantics' "definable.h" utilities,
slightly expanded.  Replace some particular PURE constraint
checks with calls to WhyNotDefinable(), except for cases that
had better specific error messages, and start checking some
missing constraints with DEALLOCATE statements and local
variable declarations.

Differential Revision: https://reviews.llvm.org/D147389
2023-04-03 07:00:07 -07:00
Peter Klausler
5296292717 [flang] Fix checks for USE-associated UDDTIO & their character argument kinds
Call GetUltimate() before checking a user-defined derived type I/O specific
procedure so that the checks work on a USE-associated procedure.  And
require their character arguments to have the default CHARACTER kind.

Differential Revision: https://reviews.llvm.org/D147386
2023-04-01 14:13:11 -07:00
Peter Klausler
86ce609d3f [flang] Fix CONTIGUOUS attribute checking
A CONTIGUOUS entity must be an array pointer, assumed-shape dummy array,
or assumed-rank dummy argument (C752, C830).  As currently implemented,
f18 only implements the array requirement if the entity is a pointer.
Combine these checks and start issuing citations to scalars.

Differential Revision: https://reviews.llvm.org/D146588
2023-03-28 04:44:01 -07:00
Peter Klausler
41a964cff0 [flang] Settle ambiguity between C795 and C721
C721 says that a type parameter value of '*' is permitted in the type-spec
for a named constant; C795 says that such type parameters are allowed
in type-specs only for a few kinds of things, not including named
constants.  The interpretation seems to depend on context, with C721
applying to intrinsic types (i.e., character) and C795 applying only
to derived types.

Differential Revision: https://reviews.llvm.org/D146586
2023-03-27 17:37:30 -07:00
Peter Klausler
3f6e0c24e6 [flang] Move SAVE attribute checks to declaration checking
Constraint checking for explicit SAVE attributes is more
accurate when done along with other declaration checking, rather
than on the fly during name resolution.  This allows us to
catch attempts to attach explicit SAVE attributes to anything
that can't have one (constraints C859, C860).

Also delete `IsSave()`, whose few remaining uses were changed to the
more general `IsSaved()` predicate that seems more correct for
those uses, returning true for both explicit and implied SAVE
attributes.

Differential Revision: https://reviews.llvm.org/D146579
2023-03-27 15:53:44 -07:00
Peter Klausler
2e0873c75e [flang] Fix check for PRIVATE override of PUBLIC t.b.p.
A PRIVATE procedure binding in a derived type extension may not
be an override of a PUBLIC procedure binding.  Declaration checking
for this case was working only in the presence of an explicit
PUBLIC accessibility attribute, when it should be checking for the
absence of a PRIVATE accessibility attribute.

Differential Revision: https://reviews.llvm.org/D146577
2023-03-27 15:43:43 -07:00
Peter Klausler
982614fa47 [flang] Warn about inconsistent external procedure interfaces
When multiple scopes in a compilation define interfaces (explicit
or implicit) for an external procedure, warn when those interfaces
are inconsistent.

Differential Revision: https://reviews.llvm.org/D146574
2023-03-27 15:15:46 -07:00
Peter Klausler
fe8abccbcd [flang] Catch attempt to apply ASYNCHRONOUS attribute to a non-variable
Complain about the ASYNCHRONOUS attribute on symbols that aren't
variables.

Differential Revision: https://reviews.llvm.org/D146573
2023-03-27 15:14:44 -07:00
Peter Klausler
88a097d129 [flang] Diagnose bad attributes of implicit interface externals
Procedures with the EXTERNAL attribute (explicit or implied) are
not permitted to be ALLOCATABLE or be arrays if their interfaces
are implicit.

Differential Revision: https://reviews.llvm.org/D146572
2023-03-27 15:05:33 -07:00
Peter Klausler
09b00ab489 [flang] Handle dynamic and remotely scoped non-type-bound UDDTIO subroutines
The present I/O infrastructure for user-defined derived type I/O
subroutines works fine for type-bound I/O generic bindings.  It also works
for explicit INTERFACE blocks and GENERIC statements that define
UDDIO subroutines in the same scope as the definition of the derived type,
so long as the specific procedures in those bindings are module procedures
or external procedures.

For non-type-bound UDDTIO specific procedures that are dummy procedures,
thunks of inner procedures, or procedure pointers, or that are defined with
interfaces or GENERIC outside the scope of the definition of the derived
type, a new runtime I/O API is needed so that lowering can generate
a call that supplies the appropriate procedure as well as the defined
type instance.

This patch specifies and implements this new runtime API and provides
utility routines for lowering to use to determine whether it should be
called for any particular OutputItem or InputItem in the parse tree.

Differential Revision: https://reviews.llvm.org/D146571
2023-03-27 14:56:25 -07:00
Peter Klausler
7cc4e980e0 [flang] Accept non-interoperable LOGICAL scalar dummy arguments
Some Fortran compilers allow kinds of LOGICAL other than C_BOOL
for the types of dummy arguments to interoperable (BIND(C))
procedures.  As any kind of LOGICAL can be converted to any
other without loss of information, this seems to be a useful
unambiguous extension that is attested in real codes; accept it
for scalars with a portability warning.

Differential Revision: https://reviews.llvm.org/D145968
2023-03-13 17:58:42 -07:00
Peter Klausler
199402c378 [flang] Check dummy arguments of BIND(C) procedures
Declaration checking in semantics was only examining symbols with
explicit BIND(C) attributes; extend it to also check dummy arguments
to such procedures.

Differential Revision: https://reviews.llvm.org/D145746
2023-03-10 09:36:05 -08:00
Peter Klausler
a183668ac6 [flang] Move check for statement function in BLOCK construct
A BLOCK construct may not contain a statement function definition;
but it may of course contain an assignment statement with an array
element on its left-hand side that looks like a statement function
definition.  These misparsed statement functions are converted
into assignment statements during semantics once it is clear what
they are.  Move the C1107 check for a statement function definition
in a block construct into declaration checking, which is where it
probably should have been in the first place anyway.

Differential Revision: https://reviews.llvm.org/D145112
2023-03-02 13:48:09 -08:00
Peter Klausler
a3c6a7d53d [flang] Stricter interface compatibility checking for TBP overrides
The compiler currently ignores attributes for PASS dummy arguments that
are incompatible between a type-bound procedure in an extended type and
the binding of the same name that it overrides in an ancestor type,
if any.  Strengthen this checking so that discrepancies between attributes
and intents are caught, and add some tests.

Differential Revision: https://reviews.llvm.org/D145110
2023-03-02 10:20:33 -08:00
Peter Klausler
69e2665c8b [flang] BIND(C,NAME=...) corrections
The Fortran standard's various restrictions on the use of BIND(C)
often depend more on the presence or absence of an explicit NAME=
specification rather than on its value, but semantics and module
file generation aren't making distinctions between explicit NAME=
specifications that happen to match the default name and declarations
that don't have NAME=.  Tweak semantics and module file generation
to conform, and also complain when named BIND(C) attributes are
erroneously applied to entities that can't support them, like
ABSTRACT interfaces.

Differential Revision: https://reviews.llvm.org/D145107
2023-03-02 10:10:06 -08:00
Peter Klausler
bd87f2df4a [flang] Enforce prohibition against empty interoperable arrays
Fortran doesn't allow a BIND(C) variable or a component of a BIND(C)
type to be an array with no elements.

Differential Revision: https://reviews.llvm.org/D145106
2023-03-02 09:55:08 -08:00
Peter Klausler
7020180226 [flang] A TBP override may not make a public binding private
When a procedure binding in a derived type has PRIVATE accessibility,
it may not be an override of a type-bound procedure that is accessible.

Differential Revision: https://reviews.llvm.org/D145104
2023-03-02 09:51:21 -08:00
Peter Klausler
e86bf46825 [flang] Disallow intrinsics and statement functions from generics
Generic interfaces are not permitted to have intrinsic procedures or
statement functions as specific procedures.

Differential Revision: https://reviews.llvm.org/D145103
2023-03-02 09:50:49 -08:00