Commit Graph

185 Commits

Author SHA1 Message Date
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
Peter Klausler
2236048f5f [flang] Further refine errors vs warnings for ambiguous generics (#80161)
Ensure that the compiler emits a hard error for a generic interface with
ambiguous specific procedures when it is declared as such, and the
ambiguity doesn't involve optional or unlimited polymorphic dummy data
arguments. But: emit an optional portability warning when the ambiguity
in the generic interface is due to USE association's merging of multiple
generics, as USE association may involve modules not under control of
the programmer; we'll emit a hard error message if any the actual
arguments in a particular reference to the generic procedure doesn't
resolve to exactly one specific procedure. And don't emit warnings when
potential ambiguity due to USE association is taking place in a module
file; the warnings, if any, will have been produced when the module file
was compiled.
2024-02-20 14:52:25 -08:00
Peter Klausler
2ba94bfb46 [flang] Downgrade a too-strong error message to a warning (#80095)
When a compilation unit has an interface to an external subroutine or
function, and there is a global object (like a module) with the same
name, we're emitting an error. This is too strong, the program will
still build. This comes up in real applications, too. Downgrade the
error to a warning.
2024-01-31 11:56:40 -08:00
Peter Klausler
3d1157000d [flang] Restore error status for many indistinguishable specifics (#79927)
A recent patch to allow pFUnit to compile softened the diagnostic about
indistinguishable specific procedures to a portability warning. It turns
out that this was overkill -- for specific procedures containing no
optional or unlimited polymorphic dummy data arguments, a diagnosis of
"indistinguishable" can still be a hard error.

So adjust the analysis to be tri-state: two procedures are either
definitely distinguishable, definitely indistinguishable without
optionals or unlimited polymorphics, or indeterminate. Emit errors as
before for the definitely indistinguishable cases; continue to emit
portability warnings for the indeterminate cases.

When this patch is merged, all but one of the dozen or so tests that I
disabled in llvm-test-suite can be re-enabled.
2024-01-29 17:31:35 -08:00
Peter Klausler
37180ed743 [flang] Turn "error" cases into warning for "indistinguishable" specific procedures (#79621)
When a generic procedure interface, either declared or the result of
    merging two use-associated generics, has two specific procedures
    that are not distinguishable according to the rules in F'2023
    subclause 15.4.3.4.5, emit a portability warning rather than a
    hard error message.  The rules in that subclause are not adequate
    to detect pairs of specific procedures that admit an ambiguous
    reference, as demonstrated by a case that arose in pFUnit.  Further,
    these distinguishability checks, even if sufficient to the task
    of detecting pairs of specifics capable of ambiguous references,
    should only apply to pairs where *every* reference would have to
    be ambiguous -- and this can and is validated at every reference
    anyway.  Last, only XLF enforces these incomplete and needless
    distinguishability rules -- every other compiler seems to just
    check that each procedure reference resolves to exactly one
    specific procedure.
    
    If the standard were to complete lose subclause 15.4.3.4.5 and
    its related note (C.11.6) -- which admits that the rules are
    incomplete! -- and simply require that each generic procedure
    reference resolve unambiguously to exactly one specific, nobody
    would miss them.  This patch changes this compiler to give them
    lip service when requested, but they are now otherwise ignored.
2024-01-29 14:36:37 -08:00
Peter Klausler
b788d6283d [flang] More Cray pointee checks (#78624)
Cray pointees may not appear in COMMON blocks or EQUIVALENCE groups.

Fixes llvm-test-suite/Fortran/gfortran/regression/cray_pointers_4.f90.
2024-01-25 15:03:23 -08:00
Tom Eccles
50e2581a19 [flang] Allow assumed-shape element pass to dummy arg with ignore_tkr (#78196)
This is allowed by gfortran and ifort with `![GCC|DEC]$ ATTRIBUTES
NO_ARG_CHECK`
2024-01-22 23:16:22 +00:00
Peter Klausler
691770ca67 [flang] Add portability warning for F'2008 feature (#77526)
Using the VALUE attribute for assumed-length CHARACTER dummy arguments
became standard in F'2008 but still lacks widespread implementation;
emit a portability warning when they are enabled.

Resolves llvm-test-suite/Fortran/gfortran/regression/value_5.f90.
2024-01-15 12:31:52 -08:00
Peter Klausler
7b80123387 [flang] More support for assumed-size Cray pointees (#77381)
Recognize Cray pointees as such when they are declared as assumed size
arrays, and don't emit a bogus error message about implied shape arrays.

Fixes https://github.com/llvm/llvm-project/issues/77330.
2024-01-15 12:08:00 -08:00
Peter Klausler
6d4c88786a [flang] Allow use of COMMON in PURE (#76741)
Although COMMON variables implicitly have the SAVE attribute, and
variables with the SAVE attribute are generally disallowed in PURE
subprograms, we must allow the use of COMMON in PURE as an exception.
F'2023 constraint C1598 applies only to local variables.
2024-01-15 09:20:20 -08:00
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