175 Commits

Author SHA1 Message Date
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
0e1bb1d835
[flang] Don't convert actual arguments when interface is implicit (#89795)
When the interface of a procedure is implicit at the point of call,
don't perform actual argument type conversion to the types of the dummy
arguments. This was inadvertently taking place in a case where the
procedure has an implicit interface but was also defined in the same
source file, so that its characteristics were known.
2024-04-24 15:08:22 -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
e8572d0fc9
[flang] Don't emit conversion error for max(a,b, optionalCharacter) (#88156)
A recent patch added an error message for whole optional dummy argument
usage as optional arguments (third or later) to MAX and MIN when those
names required type conversion, since that conversion only works when
the optional arguments are present. This check shouldn't care about
character lengths. Make it so.
2024-04-22 14:13:00 -07:00
Peter Klausler
97e3f605d5
[flang] Don't allow non-standard data conversions of potentially abse… (#87391)
…nt arguments

Arguments to the intrinsic functions MAX and MIN after the first two are
optional. When these actual arguments might not be present at run time,
emit a compilation time error if they require data conversion (a
non-standard but nearly universal language extension); such a conversion
would crash if the argument was absent.

Other compilers either disallow data conversions entirely on MAX/MIN or
crash at run time if a converted argument is absent.

Fixes https://github.com/llvm/llvm-project/issues/87046.
2024-04-08 11:56:36 -07:00
Peter Klausler
3ada883f7c
[flang][runtime] Runtime support for REDUCE() (#86214)
Supports the REDUCE() transformational intrinsic function of Fortran
(see F'2023 16.9.173) in a manner similar to the existing support for
SUM(), PRODUCT(), &c. There are APIs for total reductions to scalar
results, and APIs for partial reductions that reduce the rank of the
argument by one.

This implementation requires more functions than other reductions
because the various possible types of the user-supplied OPERATION=
function need to be elaborated.

Once the basic API in reduce.h has been approved, later patches will
implement lowering.

REDUCE() is primarily for completeness, not portability; only one other
Fortran compiler implements this F'2018 feature today, and only some
types work correctly with it.
2024-03-26 09:21:16 -07:00
Peter Klausler
03e50c4514
[flang] Emit warning when Hollerith actual passed to CLASS(*) (#84084)
When a Hollerith actual argument is associated with an unlimited
polymorphic dummy argument, it's treated as if it were CHARACTER. Some
other compilers treat it as if it had been BOZ, so emit a portability
warning.

Resolves https://github.com/llvm/llvm-project/issues/83548.
2024-03-13 14:11: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
Katherine Rasmussen
8b38970811
[flang] Add image_index to list of intrinsics and add tests (#79519)
Add image_index to the list of intrinsic functions and add additional
check on its args in check-call.cpp. Add two semantics tests for
image_index.
2024-01-30 16:01:02 -08:00
Peter Klausler
3bca8506ab
[flang] Correct checking of PRESENT() (#78364)
The argument to the PRESENT() intrinsic function must be the name of a a
whole OPTIONAL dummy argument.

Fixes llvm-test-suite/Fortran/gfortran/regression/present_1.f90.
2024-01-25 14:20:16 -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
f9b089a7c0
[flang] Fix semantic checks for MOVE_ALLOC (#77362)
The checking of calls to the intrinsic subroutine MOVE_ALLOC is not
insisting that its first two arguments be whole allocatable variables or
components. Fix, move the code into check-calls.cpp (a better home for
such things), and clean up the tests.

Fixes https://github.com/llvm/llvm-project/issues/77230.
2024-01-15 11:57:37 -08:00
Peter Klausler
828bfbef17
[flang] Suppress error meant to prevent discontiguous association whe… (#73175)
…n actual argument is contiguous

When an element of a contiguous pointer array or assumed-shape array is
associated as an actual argument with an assumed-size dummy array, don't
flag the usage as an error.
2023-11-30 13:15:42 -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
bf4a876309
[flang] Move and extend REDUCE() compile-time checking (#72570)
Move the code to check the arguments of references to the intrinsic
function REDUCE() into Semantics/check-calls.cpp, and add checks for
several requirements from the standard that weren't yet caught.
2023-11-30 11:44:43 -08:00
Peter Klausler
89165e8b1d
[flang][openacc] Disable CUDA argument checks in OpenACC regions (#72310)
Checks for CUDA Fortran data attribute compatibility don't need to be
applied in OpenACC regions.
2023-11-30 10:58:51 -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
f2bf44b6ec
[flang][preprocessor] Finesse disabling of function-like macros (#71589)
During function-like macro expansion in a standard C/C++ preprocessor,
the macro being expanded is disabled from recursive macro expansion. The
implementation in this compiler's preprocessor, however, was too broad;
the macro expansion needs to be disabled for the "rescanning" phase
only, not for actual argument expansion.

(Also corrects an obsolete comment elsewhere that was noticed during
reduction of an original test case.)
2023-11-13 15:25:10 -08:00
Peter Klausler
36ad3431bb
[flang] Don't accept NULL() actual for assumed-rank dummy (#71574)
A NULL() pointer without MOLD= cannot be allowed to be associated with
an assumed-rank dummy argument, as its rank is not well-defined and
neither the RANK() intrinsic function or the SELECT RANK construct will
work in the callee.
2023-11-13 15:14:05 -08:00
Peter Klausler
9652e9b741
[flang] Catch non-CONTIGUOUS assumed-rank with ASYNCHRONOUS/VOLATILE … (#71243)
…forwarded to CONTIGUOUS dummy

No object with the ASYNCHRONOUS or VOLATILE attribute can go through the
copy-in/copy-out protocol necessary for argument association with a
contiguous dummy array argument. The check for this constraint missed
the case of an assumed-rank array without an explicit CONTIGUOUS
attribute being forwarded on to a CONTIGUOUS dummy argument.
2023-11-13 14:41:50 -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
61d361d69b
[flang] Extension: accept NULL([MOLD=]) for ALLOCATABLE INTENT(IN) du… (#66256)
…mmy argument

Several compilers accept a null pointer (with or without a MOLD=) as an
actual argument for association with an INTENT(IN) allocatable dummy
argument. At runtime, the allocatable dummy argument appears to be in
the unallocated state. This seems useful, unambiguous, unlikely to
invalidate conforming code, and works with Intel, NAG, & XLF, so it
should be supported with an optional portability warning in this
compiler as well.
2023-09-18 12:37:46 -07:00
Peter Klausler
b76e08db9c
[flang] Accept NULL() actual for optional allocatable dummy argument (#66251)
A NULL() pointer is an acceptable actual argument for association with
an (absent) optional allocatable dummy argument. Semantics was
unconditionally emitting an error that the actual argument is not
allocatable.
2023-09-18 11:54:27 -07: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
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
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
David Truby
a519d76a03 [flang] Fix calls to interfaces with logical literal arguments
Fixes: 64698

Differential Revision: https://reviews.llvm.org/D157987
2023-08-16 10:13:46 +01:00
Kelvin Li
f50eaea8ce [flang] Add PowerPC vec_splat, vec_splats and vec_splat_s32 intrinsic
Co-authored-by: Paul Scoropan <1paulscoropan@gmail.com>

Differential Revision: https://reviews.llvm.org/D157728
2023-08-14 16:15:28 -04:00
David Truby
e63382542f [flang] Allow logical expressions as arguments with changed logical kind
This patch enables logical expressions to be used as arguments when the
default logical kind is changed (e.g. using -fdefault-integer-8) by
converting the type of the logical expression argument to the type of
the dummy argument in the function.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D157600
2023-08-14 13:05:21 +00:00
Kelvin Li
d652884eb2 [flang] Add PowerPC vec_extract, vec_insert, vec_mergeh, vec_mergel, vec_perm and ver_permi intrinsic
Co-authored-by: Paul Scoropan <1paulscoropan@gmail.com>
Co-authored-by: Mark Danial <Mark.Danial@ibm.com>

Differential Revision: https://reviews.llvm.org/D156197
2023-08-10 16:20:05 -04:00
Peter Klausler
458d9fbdc7
[flang] Catch more bad TARGET= arguments to ASSOCIATED()
The TARGET= argument to the intrinsic function ASSOCIATED() must be
a valid target for the POINTER= argument, but we are missing some
cases, such as parenthesized expressions.  Add more checking, and
restructure the logic a bit to make the case analysis structure
more clear.

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

Differential Revision: https://reviews.llvm.org/D157341
2023-08-08 11:44:04 -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
Kelvin Li
2c2d427ca3 [flang] Add a subset of PowerPC MMA (Matrix Multiply Accelerate) intrinsics
This patch includes the a subset of MMA intrinsics that are included in
the mma intrinsic module:

mma_assemble_acc
mma_assemble_pair
mma_build_acc
mma_disassemble_acc
mma_disassemble_pair

Submit on behalf of Daniel Chen <cdchen@ca.ibm.com>

Differential Revision: https://reviews.llvm.org/D155725
2023-07-27 14:30:06 -04:00
Peter Klausler
8ceba5980c
[flang] Ensure that NULL(without MOLD=) not passed to dummy argument with assumed type parameters
A dummy argument with an assumed (*) character length or derived type parameter
value specification needs to be associated with an actual argument that can
supply a value for it, so make sure that a NULL without a MOLD= is not being
passed.

Differential Revision: https://reviews.llvm.org/D155971
2023-07-21 14:13:16 -07:00
Kelvin Li
99dc3935b9 [flang] Add PowerPC vec_convert, vec_ctf and vec_cvf intrinsic
Co-authored-by: Paul Scoropan <1paulscoropan@gmail.com>

Differential Revision: https://reviews.llvm.org/D155235
2023-07-19 22:27:55 -04:00
Peter Klausler
22ed61ed87
[flang] Emit errors on vector subscripts with duplicated elements when object must be definable
When the left-hand side of an assignment, or any other context demanding
definability, comprises a designator with a vector subscript that is
known at compilation time to have one or more duplicated elements,
emit an error message.

Differential Revision: https://reviews.llvm.org/D155492
2023-07-17 12:20:16 -07:00
Kelvin Li
10124b3e1e [flang] Add PowerPC vec_sl, vec_sld, vec_sldw, vec_sll, vec_slo, vec_srl and vec_sro intrinsic
Co-authored-by: pscoro

Differential Revision: https://reviews.llvm.org/D154563
2023-07-12 17:39:13 -04: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
Dmitriy Smirnov
bc4586da6e [Flang][OpenMP] Lower allocatable or pointer in private clause
This patch lowers allocatables and pointers named in "private" OpenMP clause.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D148570
2023-07-03 16:46:02 +00:00
Peter Klausler
7871deb821
[flang] Add optional portability warning for upcoming Fortran 202X/3 breaking change
The soon-to-be-published next revision of the ISO Fortran language standard
contains a couple of breaking changes to previous specifications that may cause
existing programs to silently change their behavior.

For the change that introduces automatic reallocation of deferred length
allocatable character scalar variables when they appear as the targets
of internal WRITE statements, as IOMSG=/ERRMSG= variables, as outputs
of INQUIRE specifiers, or as INTENT(OUT) arguments to intrinsic
procedures, this patch adds an optional portability warning.

Differential Revision: https://reviews.llvm.org/D154242
2023-07-03 09:07:00 -07:00
Peter Klausler
9299bde9e3
[flang] Relax ALLOCATABLE/POINTER actual argument checks under INTENT(IN)
Per 15.5.2.5 p2, when both a dummy data object and its associated
actual argument are ALLOCATABLE or POINTER, there are rules requiring
that both be unlimited polymorphic if either is, and that both be
polymorphic if either is.  The justifications for the first restriction
is that the called procedure might change the type of an unlimited
polymorphic dummy argument, but as this cannot occur for a dummy
argument with INTENT(IN), we can relax the check to an optional
portability warning.  The justification for the second restriction
is that some implementations would have to create a type descriptor
to associate a monomorphic allocatable/pointer actual argument with
a polymorphic dummy argument, and that doesn't apply to f18 since we
use descriptors for them anyways.

Relaxing these needless checks allows more library procedures to
use "class(*), dimension(..), pointer, intent(in)" dummy arguments
in explicit interfaces.

Differential Revision: https://reviews.llvm.org/D151941
2023-06-02 08:06:20 -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
Kelvin Li
f6e8b3ec8d [flang] Don't convert actual argument if IGNORE_TKR is present for the corresponding dummy
This patch is to remove the conversion of the actual argument that
is associated with the dummy argument specified with the IGNORE_TKR
directive.

Commit on behalf of @danielcchen

Differential Revision: https://reviews.llvm.org/D151401
2023-05-25 13:26:11 -04:00
Peter Klausler
ede83e0eb8
[flang] Fix llvm-test-suite/Fortran/gfortran/torture/execute/st_function_1.f90
I just broke the test llvm-test-suite/Fortran/gfortran/torture/execute/st_function_1.f90
with a recent patch.  The bug was obvious, as is the fix, which works, so
I'm just pushing it directly to make the build bots happy.
2023-05-16 15:10:28 -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
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
Jie Fu
a8f1185a7f [flang] Fix -Wsign-compare in check-call.cpp (NFC)
/data/llvm-project/flang/lib/Semantics/check-call.cpp🔢29: error: comparison of integers of different signs: 'int' and 'size_type' (aka 'unsigned long') [-Werror,-Wsign-compare]
  CHECK(index >= 0 && index < actuals.size());
                      ~~~~~ ^ ~~~~~~~~~~~~~~
/data/llvm-project/flang/include/flang/Common/idioms.h:89:20: note: expanded from macro 'CHECK'
                   ^
1 error generated.
2023-04-04 22:52:13 +08:00
Paul Scoropan
adc56f37cd [Flang][PowerPC] Implement PPC mtfsf/mtfsfi intrinsics
Implements the PowerPC mtfsf and mtfsfi intrinsics as well as introduces semantic error checking code for PowerPC intrinsics

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D144876
2023-04-04 13:42:00 +00:00