103 Commits

Author SHA1 Message Date
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
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
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
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
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
Peter Klausler
a54e8b2cc4
[flang] Silence bogus error about insufficiently defined interfaces (#116694)
The interfaces of separate module procedures are sufficiently well
defined in a submodule to be used in a local generic interface; the
compiler just needed to work a little harder to find them.

Fixes https://github.com/llvm/llvm-project/issues/116567.
2024-11-19 16:20:23 -08:00
Valentin Clement (バレンタイン クレメン)
30d80009e5
[flang][cuda] Allow SHARED actual to DEVICE dummy (#115215)
Update the compatibility rules to allow SHARED actual argument passed to
DEVICE dummy argument. Emit a warning in that case.
2024-11-06 17:45:58 -08: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
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
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
Valentin Clement
3e930864eb
Reland [flang][cuda] Update attribute compatibily check for unified matching rule 2024-04-30 21:14:12 -07:00
Valentin Clement (バレンタイン クレメン)
306ae14fac
Revert "[flang][cuda] Update attribute compatibily check for unified matching rule" (#90696)
Reverts llvm/llvm-project#90679
2024-04-30 20:05:04 -07:00
Valentin Clement (バレンタイン クレメン)
86e5d6f1d8
[flang][cuda] Update attribute compatibily check for unified matching rule (#90679)
This patch updates the compatibility checks for CUDA attribute iin
preparation to implement the matching rules described in section 3.2.3.
We this patch the compiler will still emit an error when there is
multiple specific procedures that matches since the matching distances
is not yet implemented. This will be done in a separate patch.


https://docs.nvidia.com/hpc-sdk/archive/24.3/compilers/cuda-fortran-prog-guide/index.html#cfref-var-attr-unified-data

gpu=unified and gpu=managed are not part of this patch since these
options are not recognized by flang yet.
2024-04-30 19:58:46 -07:00
Peter Klausler
cb26391968
[flang] Make proc characterization error conditional for generics (#89429)
When the characteristics of a procedure depend on a procedure that
hasn't yet been defined, the compiler currently emits an unconditional
error message. This includes the case of a procedure whose
characteristics depend, perhaps indirectly, on itself. However, in the
case where the characteristics of a procedure are needed to resolve a
generic, we should not emit an error for a hitherto undefined procedure
-- either the call will resolve to another specific procedure, in which
case the error is spurious, or it won't, and then an error will issue
anyway.

Fixes https://github.com/llvm/llvm-project/issues/88677.
2024-04-22 15:21:45 -07: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
Peter Klausler
f31ac3cb1f
[flang] Handle implied ASYNCHRONOUS attribute (#82638)
The standard states that data objects involved in an asynchronous data
transfer statement gain the ASYNCHRONOUS attribute implicitly in the
surrounding subprogram or BLOCK scope. This attribute affects the checks
in call semantics, as an ASYNCHRONOUS actual object associated with an
ASYNCHRONOUS dummy argument must not require data copies in or out.

(Most compilers don't implement implied ASYNCHRONOUS attributes
correctly; XLF gets these right, and GNU is close.)
2024-03-01 14:43:31 -08:00
Jean Perier
38b54c72ca [flang] fix shared library builds after #81166
Fix https://lab.llvm.org/buildbot/#/builders/268/builds/7826

IsDerivedTypeWithLengthParameter cannot be used here, it would make
libFortranEvaluate dependent on linFortranSemantics.
Replace by loop through parameter values.
2024-02-09 00:50:48 -08:00
jeanPerier
b477d39bf6
[flang] Align runtime info and lowering regarding passing ABIs (#81166)
Runtime derived type info contains information to tell the runtime if
some argument in a user defined assignment must be passed with a
descriptor or not. This information was not properly build, it would
tell the runtime that TARGET argument must be passed via descriptor,
which is incorrect.

Share the logic between lowering and runtime info generation to
determine if an argument must be passed by descriptor or not.
2024-02-09 09:10:49 +01: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
6e0a2031f0
[flang] Catch name resolution error due to global scoping (#77683)
In
    CALL FOO
    PRINT *, ABS(FOO)
we currently resolve the first FOO to a global external subprogram, but
then the second FOO is treated as an implicitly typed local variable.
This happens because the name FOO is not present in the local scope.

Fix by adding FOO to the local scope using a place-holding
HostAssocDetails symbol whose existence prevents the creation of another
FOO in the local scope. The symbol stored in the parser::Name parse tree
nodes or used in typed expressions will all continue to point to the
global external subprogram.

Resolves llvm-test-suite/Fortran/gfortran/regression/pr71859.f90.
2024-01-15 12:40:46 -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
e86591b37d
[flang] Improve procedure interface compatibility checking for dummy … (#72704)
…arrays

When comparing dummy array extents, cope with references to symbols
better (including references to other dummy arguments), and emit
warnings in dubious cases that are not equivalent but not provably
incompatible.
2023-11-30 12:22:04 -08:00
Peter Klausler
29fd3e2aa8
[flang] Allow polymorphic actual to implicit interface (#70873)
Semantics is emitting an error when an actual argument to a procedure
that has an implicit interface has a polymorphic type. This is too
general; while TYPE(*) and CLASS(*) unlimited polymorphic items require
the presence of an explicit procedure interface, CLASS(T) data can be
passed over an implicit interface to a procedure expecting a
corresponding dummy argument with TYPE(T), so long as T is not
parameterized.

(Only XLF handles this usage correctly among other Fortran compilers.)

(Making this work in the case of an actual CLASS(T) array may well
require additional changes in lowering to copy data to/from a temporary
buffer to ensure contiguity when the actual type of the array is an
extension of T.)
2023-11-13 13:31:58 -08: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
c704050929
[flang] Reduce implicit interface compatibility warnings due to length (#69385)
When a procedure with an implicit interface is called from two call
sites with distinct argument types, we emit a warning. This can lead to
a lot of output when the actual argument types are differing-length
character, and the warnings are less important since the procedure may
well have been defined with assumed-length character dummy arguments. So
let cases like CALL MYERROR('ab'); CALL MYERROR('abc') slide by without
a warning.
2023-10-31 10:12:16 -07:00
jeanPerier
09c544e760
[flang] Do not propagate BIND(C) from main entry to ENTRY (#67554)
15.6.2.6 point 11/12/13 tells that entries do inherit the
RECURSIVE/PURE/ELEMENTAL aspects from the main entry, but nothing as
such is said for BIND(C). It seems each entry can independently have
BIND(C) or not.

Update characterization to not propagate this info in-between entries.

Add a lowering test for a tricky case of the character return where the
return ABI is different for the result with and without BIND(C), but the
results storage should be associated regardless of the ABI.
2023-09-27 19:40:24 +02:00
Peter Klausler
f025e41174
[flang] Accept pointer-valued function results as ASSOCIATED() arguments (#66238)
The POINTER= and TARGET= arguments to the intrinsic function
ASSOCIATED() can be the results of references to functions that return
object pointers or procedure pointers. NULL() was working well but not
program-defined pointer-valued functions. Correct the validation of
ASSOCIATED() and extend the infrastructure used to detect and
characterize procedures and pointers.
2023-09-18 08:22:18 -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
5718a4256b
[flang] Catch insufficient actual elements/characters associated with longer dummy argument
Check for cases of storage sequence association in which an element or
substring is an actual argument associated with a dummy argument array
that can be detected as being larger than the remaining elements or characters
in the actual argument's storage sequence.

Differential Revision: https://reviews.llvm.org/D156757
2023-08-01 13:31:45 -07:00
Peter Klausler
f7e4304120
[flang] Strengthen procedure compatibility checking
Add more checks to procedure compatibility testing for procedure pointer
assignments, actual procedure arguments, &c.  Specifically, don't
allow corresponding dummy data objects to differ in their use
of polymorphism, assumed size arrays, or assumed shape arrays.

Differential Revision: https://reviews.llvm.org/D155974
2023-07-21 14:44:10 -07:00
Peter Klausler
6ceba01a4d
[flang] More actual argument warnings
Emit warnings when CHARACTER lengths or array sizes of actual
and dummy arguments mismatch in risky ways.

Differential Revision: https://reviews.llvm.org/D154370
2023-07-03 12:49:17 -07:00
Peter Klausler
f513bd8088
[flang] CUDA Fortran - part 4/5: definability and characteristics
Extend the definability and procedure characteristics checking
infrastructure in semantics to check for context-dependent CUDA object
definability violations and problems with CUDA attribute incompatibility
in procedure interfaces.

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

Differential Revision: https://reviews.llvm.org/D150163
2023-05-31 14:25:38 -07:00
Peter Klausler
e5ccfbbfde
[flang] Respect !DIR$ IGNORE_TKR in generic matching
Generic matching needs to relax argument compatibility checks when
dummy arguments have !DIR$ IGNORE_TKR directives.

Differential Revision: https://reviews.llvm.org/D150806
2023-05-18 11:26:16 -07:00
Peter Klausler
a88cee1fd0
[flang] Semantics for ISO_C_BINDING's C_LOC()
Make __builtin_c_loc() into an intrinsic function and verify the
special semantic requirements on its actual arguments.

Differential Revision: https://reviews.llvm.org/D149988
2023-05-08 15:58:09 -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
Peter Klausler
ae426a054b [flang] Detect obvious argument shape incompatibility when checking procedure compatibility
The compiler presently detects different dummy object array ranks;
extend the compatibility check to also note discrepancies in corresponding
constant dummy argument extents.

Differential Revision: https://reviews.llvm.org/D145748
2023-03-10 09:45:00 -08:00
Peter Klausler
bdbebef828 [flang] Warn about inconsistent implicit interfaces
When a global procedure has no explicit interface, emit warnings
when its references are inconsistent implicit procedure interfaces.

Differential Revision: https://reviews.llvm.org/D145097
2023-03-02 15:16:13 -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
c6b9df0fbd [flang] Refine procedure compatibility checking
The test for compatible function results needs to be nearly strict
equality of their types, not the usual actual/dummy type compatibility
test used in other situations.  The exceptional case is that assumed
length CHARACTER function results are compatible with explicit length
results of the same kind.  In particular, a function returning a
polymorphic pointer is not compatible with a function returning a
monomorphic pointer even of the same declared type.

Differential Revision: https://reviews.llvm.org/D145094
2023-03-02 09:22:06 -08:00
Peter Klausler
f28c1a9df2 [flang] Conform with standard (mostly) for character length mismatches on arguments
Fortran 2018 defines some flavors of dummy arguments to require exact
matching of character lengths between dummy and actual arguments;
these situations tend to be those in which the interface must be
explicit and a descriptor is involved: assumed shape, assumed rank,
allocatable, and pointer.

Fortran allows an actual argument in other cases to have a longer
length than the dummy argument; as a common extension, we support a
shorter actual argument as well by means of blank padding, but should
emit a warning.

Differential Revision: https://reviews.llvm.org/D143821
2023-02-13 15:07:40 -08:00
Peter Klausler
50960e9383 [flang] Catch character length errors in pointer associations
When character lengths are known at compilation time, report an error
when a data target with a known length does not match the explicit length
of a pointer that is being associated with it; see 10.2.2.3 paragraph 5.

Differential Revision: https://reviews.llvm.org/D142755
2023-02-01 12:12:43 -08:00
Peter Klausler
042c964d60 [flang] Fix defined I/O semantics crash & missing errors that exposed it
Semantics crashes when emitting runtime derived type information tables
for a type that has user-defined I/O procedures declared outside the
type with explicit INTERFACE blocks (as opposed to a GENERIC binding
within the type).  This is due to the runtime table constructor
adding a table entry for each specific procedure of any explicit interface
 of the right kind (e.g., READ(UNFORMATTED)) that it found, rather than
just the ones that pertain to the derived type in question.  But
semantics also wasn't checking such interfaces for distinguishable
specific procedures, either.

Clean these up, improve the spelling of defined I/O procedure kinds
in error messages ("read(formatted)" rather than "READFORMATTED"),
and make error messages stemming from macro expansions only have
one "error:" prefix on the original message so that a new test
would work.

Differential Revision: https://reviews.llvm.org/D142769
2023-01-29 10:15:27 -08:00
Peter Klausler
036701a177 [flang] Correct procedure pointer (or dummy) compatibility check
Fix a subtle bug in procedure compatibility checking with base
derived types vs. their extensions to ensure that a procedure
expecting an extended type cannot be associated with a pointer
(or dummy procedure) to a procedure expecting a base type.

  subroutine s1(base); ... subroutine s2(extended)
  procedure(s1), pointer :: p
  p => s2 ! <- must be caught as an error

Differential Revision: https://reviews.llvm.org/D142753
2023-01-27 14:53:09 -08:00
Peter Klausler
635656f4ff [flang] Expunge needless semantics::ProcInterface
The ProcInterface structure is used only by ProcEntityDetails; it represents
what a program might have put in parentheses in a procedure-declaration-stmt,
either the name of a procedure interface or a declaration-type-spec.

If a procedure entity has an implicit interface, the function result
type (if any) can be kept in EntityDetails::type_, which already exists
and is currently redundant for ProcEntityDetails symbols.

All that is really needed is a nullable Symbol pointer in ProcEntityDetails
to point to the procedure's explicit interface, when it has one.

Also, catch the case where a procedure has an explicit interface
and a program attempts to also give it a type.

Differential Revision: https://reviews.llvm.org/D140134
2022-12-16 10:44:29 -08:00
Peter Klausler
9114ce4d1d [flang] Take character function length into account when testing compatibility
When a character-valued function is passed as an actual argument, and both
the actual function and the dummy argument have explicit result lengths, take them
into account when testing for compatibility.

Differential Revision: https://reviews.llvm.org/D139129
2022-12-03 12:35:23 -08:00
Peter Klausler
bcba39a56f [flang] Restore ENUM_CLASS() to be compilation-time code
Rework some recent changes to the ENUM_CLASS() macro so that
all of the construction of enumerator-to-name string mapping
data structures is again performed at compilation time.

Differential Revision: https://reviews.llvm.org/D137859
2022-12-02 09:55:45 -08:00
Peter Steinfeld
74d5c3c0f0 [Flang] Run clang-format on all flang files
This will make it easier for me to do reviews.

Differential Revision: https://reviews.llvm.org/D137291
2022-11-03 09:26:22 -07:00
Peter Klausler
66fdfff7bc [flang] Require explicit interface for some dummy procedures
Some of the circumstances that require that a procedure have an
explicit interface at a point of call due to a characteristic of
a dummy argument apply to dummy procedures, too.

Differential Revision: https://reviews.llvm.org/D136994
2022-10-30 17:11:25 -07:00
Kazu Hirata
3850edd9e0 Use llvm::count_if (NFC) 2022-09-03 11:17:35 -07:00
Peter Klausler
c1a77839cc [flang] Avoid spurious error message in function result compatibility
When checking function interface compatibility for procedure pointer
assignment/initialization or actual/dummy procedure association, don't
emit a diagnositic about function result shape incompatibility unless
the interfaces differ in rank or have distinct constant extents on a
dimension.  Function results whose dimensions are determined by dummy
arguments or host-associated variables are not necessarily incompatible.

Differential Revision: https://reviews.llvm.org/D132162
2022-08-18 14:58:16 -07:00