Commit Graph

1221 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
Peter Klausler
e1ad2735c3 [flang] Clean up ISO_FORTRAN_ENV, fix NUMERIC_STORAGE_SIZE (#87566)
Address TODOs in the intrinsic module ISO_FORTRAN_ENV, and extend the
implementation of NUMERIC_STORAGE_SIZE so that the calculation of its
value is deferred until it is needed so that the effects of
-fdefault-integer-8 or -fdefault-real-8 are reflected. Emit a warning
when NUMERIC_STORAGE_SIZE is used from the module file and the default
integer and real sizes do not match.

Fixes https://github.com/llvm/llvm-project/issues/87476.
2024-04-08 11:57:01 -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
aace1e1719 [flang] Improve error message with declaration (#87294)
When a program attempts to use a non-object entity as the base of a
component reference or type parameter inquiry, the message is somewhat
uninformative and the position of the entity's declaration will not
reflect any updates made to the symbol during name resolution.

Includes some NFC C++17 style clean-up on some code noticed while
debugging (missing mandatory braces).
2024-04-08 11:55:03 -07:00
Peter Klausler
af61d08280 [flang] Handle forward reference to shadowing derived type from IMPLICIT (#87280)
A derived type name in an IMPLICIT statement might be a host association
or it might be a forward reference to a local derived type, which may be
shadowing a host-associated name. Add a scan over the specification part
in search of derived type definitions to determine the right
interpretation.

Fixes https://github.com/llvm/llvm-project/issues/87215.
2024-04-08 11:54:37 -07:00
Peter Klausler
92ecc22b8d [flang] Fix crash in semantics on bad program (#87199)
Don't accept a putative statement function definition for a symbol that
is a subprogram but can't possibly be a statement function.

Fixes https://github.com/llvm/llvm-project/issues/86936.
2024-04-08 11:53:49 -07:00
Valentin Clement (バレンタイン クレメン)
896b5e5571 [flang][cuda] Allow list-directed PRINT and WRITE stmt in device code (#87415)
The specification allow list-directed PRINT and WRITE statements to
appear in device code. This patch relax the semantic check to allow
them.

3.6.11.
List-directed PRINT and WRITE statements to the default unit may be used
when compiling for compute capability 2.0 and higher; all other uses of
PRINT and WRITE are disallowed.
2024-04-08 09:59:12 -07:00
Valentin Clement (バレンタイン クレメン)
0aa982fb32 [flang][cuda] Add restriction on implicit data transfer (#87720)
In section 3.4.2, some example of illegal data transfer using expression
are given. One of it is when multiple device objects are part of an
expression in the rhs. Current implementation allow a single device
object in such case. This patch adds a similar restriction.
2024-04-05 13:40:38 -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
harishch4
f546b6ef3c [Flang] Relaxing an error when contiguous pointer is assigned to a non-contig… (#86781)
…uous function.

Fix from [thtsikas](https://github.com/thtsikas) based on a discussion
in
[slack](https://flang-compiler.slack.com/archives/C5C58TT32/p1711124374836079).

Example:
```
Program test
  Integer, Pointer, Contiguous :: cont(:)
  Interface
     Function f()
       Integer, Pointer :: f(:)
     End Function
  End Interface
  cont => f()
  Print *, cont(3)
End Program

Function f()
  Integer, Pointer :: f(:)
  Allocate (f(4),Source=[1,1,42,1])
  ! f => f(4:1:-1)        !! not contiguous, runtime error
End Function f
```

Understanding is that the standard intended to allow this pattern. The
restriction 10.2.2.3 p6 Data pointer assignment "If the pointer object
has the CONTIGUOUS attribute, the pointer target shall be contiguous."
is not associated with a numbered constraint. If there is a mechanism
for injecting runtime checks, this would be a place to do it. Absent
that, a warning is the best we can do.

No other compiler treats contigPtr => func() as an error when func() is
not CONTIGUOUS, so a warning would probably be better for consistency.
https://godbolt.org/z/5cM6roeEE
2024-04-01 17:13:22 +05:30
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
f92f775212 [flang][NFC] Address reported "possible missing return" (#86523)
A function uses "if constexpr" to consider all possible types in a
variant, but looks as if it can fall out without returning an
expression. Add a final "else" with a crash to make things more clear
and to protect against unlikely future extensions of the type.

Fixes https://github.com/llvm/llvm-project/issues/86391.
2024-03-26 10:02:22 -07:00
Peter Klausler
8f01ecaeb8 [flang] Special-case handling of INTRINSIC in type-decl-stmt (#86518)
Fortran allows the INTRINSIC attribute to be specified with a distinct
attribute statement, and also as part of the attribute list of a
type-declaration-stmt. This is an odd case (especially as the declared
type is mandated to be ignored if it doesn't match the type of the
intrinsic function) that can lead to odd error messages and crashes,
since the rest of name resolution expects that intrinsics with explicit
declarations will have been declared with INTRINSIC attribute
statements. Resolve by handling an "inline" INTRINSIC attribute as a
special case while processing a type-declaration-stmt, so that

  real, intrinsic :: acos, asin, atan

is processed exactly as if it had been

  intrinsic acos, asin, atan; real acos, asin, atan

Fixes https://github.com/llvm/llvm-project/issues/86382.
2024-03-26 09:50:37 -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
f50f0caf87 [flang] Fix crash in name resolution (#85835)
ConvertToObjectEntity() returns true for use- and host-associated object
symbols, too. Ensure in this case that the symbol really is a
non-associated object.

Fixes https://github.com/llvm/llvm-project/issues/85776.
2024-03-26 08:59:22 -07:00
Leandro Lupori
edcf65d40c [flang][OpenMP] Allow loop iteration variables in DSA clauses (#86194)
Iteration variables of non-associated loops may be listed in DSA
clauses.

Fixes https://github.com/llvm/llvm-project/issues/78938
2024-03-25 08:48:11 -03:00
jeanPerier
de7a50fb88 [flang] Fix lowering of host associated cray pointee symbols (#86121)
Cray pointee symbols can be host associated from a module or host
procedure while the related cray pointer is not explicitly associated.
This caused the "not yet implemented: lowering symbol to HLFIR" to fire
when lowering a reference to the cray pointee and fetching the cray
pointer.

This patch:
- Ensures cray pointers are always instantiated when instantiating a
cray pointee.
- Fix internal procedure lowering to deal with cray pointee host
association like it does for pointers (the lowering strategy for cray
pointee is to create a pointer that is updated with the cray pointer
value before being fetched).

This should fix the bug reported in
https://github.com/llvm/llvm-project/issues/85420.
2024-03-22 11:13:04 +01:00
harishch4
a7eaae4ec6 [Flang] Fix to the module procedure interface block ignoring implicit… (#85735)
… of host scoping unit.

Fix as proposed by @thtsikas [here
](11d07d9ef6 (commitcomment-139798026)).
2024-03-19 22:46:57 +05:30
Kelvin Li
a5f576e596 [flang] Diagnose calling impure final procedure due to finalization in FORALL (#85685)
This patch checks the LHS of an assignment in a FORALL loop and
diagnoses if any impure final procedure is called.
2024-03-18 21:35:56 -04:00
Peter Klausler
d0d9839b14 [flang] Fix crash on erroneous program (#85615) (#85659)
Replace a pointer that should never be null with a reference argument so
that it's always defined.

Fixes https://github.com/llvm/llvm-project/issues/85615.
2024-03-18 14:14:41 -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
Kelvin Li
0c21377aea [flang] Diagnose the impure procedure reference in finalization according to the rank of the entity (#85475)
Use the rank of the array section to determine which final procedure
would be called in diagnosing whether that procedure is impure or not.
2024-03-18 10:59:47 -04:00
Tom Eccles
53d8c6b1b1 [flang][Semantics][OpenMP] set intrinsic attr for reductions (#85114)
Reductions such as min are intrinsic procedures. This distinguishes them
from user defined reductions. Previously, the intrinsic attribute was
not set when visiting reduction clauses causing them to be missed.

wsloop-reduction-min.f90 (the other min reduction test) worked because
it contained "min" used as an intrinsic inside of the body of the
reduction. This allowed ResolveNamesVisitor::HandleProcedureName to set
the correct attribute on that Symbol.
2024-03-15 11:12:09 +00:00
Peter Klausler
dc55c4435d [flang] Clip circular dependence between implementation modules (#85309)
flang/module/__fortran_type_info.mod uses __fortran_builtins.mod, but it
is also implicitly used when compiling __fortran_builtins.f90 (or
anything else). If __fortran_type_info.mod finds an old
__fortran_builtins.mod file, compilation can fail while building the new
one.

Break the dependence by *not* generating runtime derived type
information for __fortran_builtins.f90.
2024-03-14 15:29:06 -07:00
Peter Klausler
702a86a8f1 [flang] Correct accessibility of name that is both generic and derive… (#85098)
…d type

When the same name is used for a derived type and generic interface in a
module, and no explicit PUBLIC or PRIVATE statement appears for the name
but the derived type definition does have an explicit accessibility,
that accessibility must also apply to the generic interface.
2024-03-13 15:13:56 -07:00
Peter Klausler
5661188c57 [flang] Support multiple distinct module files with same name in one … (#84838)
…compilation

Allow multiple module files with the same module name to exist in one
compilation; distinct modules are distinguished by their hashes.
2024-03-13 14:42:40 -07:00
Peter Klausler
ccfb9e6eb7 [flang] Omit parent components for references to bindings (#84836)
https://github.com/llvm/llvm-project/pull/78593 changed expression
semantics to always include the names of parent components that were
necessary to access an inherited component. This turns out to have
broken calls to inherited NOPASS procedure bindings. Update the patch to
omit explicit parent components when accessing bindings, while retaining
them for component accesses (including procedure components).
2024-03-13 14:30:04 -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
agozillon
096ee4e16f [Flang][OpenMP] Implement "promotion" of use_device_ptr non-cptr arguments to use_device_addr (#82834)
This effectively implements some now deprecated OpenMP functionality
that some applications (most notably at the moment GenASiS)
unfortunately depend on (deprecated in specification version 5.2):

"If a list item in a use_device_ptr clause is not of type C_PTR, the
behavior is as if the list item appeared in a use_device_addr clause.
Support for such list items in a use_device_ptr clause is deprecated."

This PR downgrades the hard-error to a deprecated warning and "promotes"
the above cases by simply moving the offending operands from the
use_device_ptr value list to the back of the use_device_addr list (and
moves the related symbols, locs and types that form the BlockArgs
correspondingly) and then the generation of the target data construct
proceeds as normal.
2024-03-13 16:18:21 +01:00
Krzysztof Parzyszek
141ebdd242 [Frontend][OpenMP] introduce OMP.h header file, use it instead of OMP… (#84188)
….h.inc

The consumers of OpenMP-related definitions include a TableGen-generated
file OMP.h.inc. Having a separate OMP.h allows putting additional
declarations in there that are not auto-generated.

This patch is NFC.
2024-03-08 07:21:42 -06: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
13cd0a905b [flang] Skim usage before marking unknown module externals as subrout… (#83897)
…ines

Name resolution needs to delay its default determination of module
external procedures as subroutines until after it has skimmed the
execution parts of module procedures.

Fixes https://github.com/llvm/llvm-project/issues/83622.
2024-03-05 11:41:12 -08:00
Peter Klausler
069aee0793 [flang] Rework F'2023 constraint C1167 checking (#83888)
The code that verifies that the type in a TYPE IS or CLASS IS clause is
a match or an extension of the type of the SELECT TYPE selector needs
rework to avoid emitting a bogus error for a test.

Fixes https://github.com/llvm/llvm-project/issues/83612.
2024-03-05 11:28:11 -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
e09e9567fc [flang] Downgrade error to warning (#83032)
It's probably a bad idea to have a Cray pointer whose type is a derived
type that is not a sequence type, but the feature is a nonstandard
extension in the first place. Downgrade the message to a warning.

Fixes https://github.com/llvm/llvm-project/issues/82210.
2024-03-01 16:54:35 -08:00
Peter Klausler
2445a96ff2 [flang] Enforce F'2023 C1520 correctly (#82842)
When a procedure declaration statement has a binding label, it must
declare no more than one procedure.

Fixes https://github.com/llvm/llvm-project/issues/82528.
2024-03-01 16:49:43 -08:00
Peter Klausler
f4215f7140 [flang] Fix handling of shadowed procedure name used as interface (#82837)
Use BypassGeneric() to process the name of an interface in a procedure
declaration statement, so that if it's the name of a generic with a
homonymous specific procedure, that's what defines the interface.

Fixes https://github.com/llvm/llvm-project/issues/82267.
2024-03-01 16:42:00 -08:00
Peter Klausler
8bcb1ceded [flang] Allow PROCEDURE() with explicit type elsewhere (#82835)
Fortran allows a procedure declaration statement with no interface or
type, with an explicit type declaration statement elsewhere being used
to define a function's result.

Fixes https://github.com/llvm/llvm-project/issues/82006.
2024-03-01 16:31:13 -08:00
Peter Klausler
189d89a92c [flang] Ensure names resolve in DATA statement objects (#82825)
When DATA statement objects have derived types obtained by implicit
typing rules, their types aren't known until specification part
processing is complete. In the case of a derived type, any component
name in a designator may still be in need of name resolution. Take care
of it in the deferred check visitor that runs at the end of name
resolution in each specification and execution part.

Fixes https://github.com/llvm/llvm-project/issues/82069.
2024-03-01 16:19:01 -08:00
Peter Klausler
147f54e36a [flang] Accept whole assumed-size arrays as variable selectors (#82806)
Include variable selectors ("select type (x => y)") as a context in
which a whole assumed-size array may legitimately appear.

Fixes https://github.com/llvm/llvm-project/issues/81910.
2024-03-01 16:08:45 -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
Peter Klausler
e8a9aa26f7 [flang] Fix "suspicious condition" in C++ usage (#82790)
Address a reported C++ coding "suspicious condition".

Fixes https://github.com/llvm/llvm-project/issues/80807.
2024-03-01 15:46:12 -08:00
Peter Klausler
a56ef9f9ce [flang] Catch attempt to type a subroutine (#82704)
The presence of a type in the prefix of a SUBROUTINE statement should
elicit an error message, not a crash.

Fixes https://github.com/llvm/llvm-project/issues/80530.
2024-03-01 15:23:24 -08:00
Peter Klausler
8f80d466d5 [flang] Fix crash in statement function semantics (bug #80532) (#82702)
When statement function expressions are analyzed, ensure that the
semantics context has a valid location set, otherwise a type spec (like
"integer::") can lead to a crash.

Fixes https://github.com/llvm/llvm-project/issues/80532.
2024-03-01 15:10:47 -08:00
Peter Klausler
8f141490b9 [flang] Fix separate MODULE PROCEDURE when binding label exists (#82686)
When a separate module procedure is defined with a MODULE PROCEDURE and
its corresponding interface has a binding label, the compiler was
emitting an error about mismatching binding labels because the binding
label wasn't being copied into the subprogram's definition.
2024-03-01 14:57:28 -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
Peter Klausler
f7a15e0021 [flang] Use module file hashes for more checking and disambiguation (#80354)
f18's module files are Fortran with a leading header comment containing
the module file format version and a hash of the following contents.
This hash is currently used only to protect module files against
corruption and truncation.

Extend the use of these hashes to catch or avoid some error cases. When
one module file depends upon another, note its hash in additional module
file header comments. This allows the compiler to detect when the module
dependency is on a module file that has been updated. Further, it allows
the compiler to find the right module file dependency when the same
module file name appears in multiple directories on the module search
path.

The order in which module files are written, when multiple modules
appear in a source file, is such that every dependency is written before
the module(s) that depend upon it, so that their hashes are known.

A warning is emitted when a module file is not the first hit on the
module file search path.

Further work is needed to add a compiler option that emits (larger)
stand-alone module files that incorporate copies of their dependencies
rather than relying on search paths. This will be desirable for
application libraries that want to ship only "top-level" module files
without needing to include their dependencies.

Another future work item would be to admit multiple modules in the same
compilation with the same name if they have distinct hashes.
2024-03-01 13:58:36 -08:00
Peter Klausler
31ab2c4f61 [flang] Ensure USE-associated objects can be in NAMELIST (#82846)
The name resolution for NAMELIST objects didn't allow for symbols that
are not ObjectEntityDetails symbols.

Fixes https://github.com/llvm/llvm-project/issues/82574.
2024-02-23 21:15:32 -06:00
Valentin Clement (バレンタイン クレメン)
5c90527b43 [flang][cuda] Allow object with SHARED attribute as definable (#82822)
A semantic error was raised in device subprogram like: 

```
attributes(global) subroutine devsubr2()
   real, shared :: rs
   rs = 1
end subroutine
```

Object with the SHARED attribute can be can be read or written by all
threads in the block.


https://docs.nvidia.com/hpc-sdk/archive/24.1/compilers/cuda-fortran-prog-guide/index.html#cfpg-var-qual-attr-shared
2024-02-23 12:56:41 -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