379 Commits

Author SHA1 Message Date
Peter Klausler
d418a03e01
[flang] Fix error from semantics on use associated procedure pointer (#107928)
Use associated procedure pointers were eliciting bogus errors from
semantics if their modules also contained generic procedure interfaces
of the same name. (The compiler handles this case correctly when the
specific procedure of the same name is not a pointer.)

With this fix, the test case in
  https://github.com/llvm/llvm-project/issues/107784
no longer experiences semantic errors; however, it now crashes
unexpectedly in lowering.
2024-09-10 14:15:20 -07:00
Peter Klausler
5a229dbca1
[flang] Relax error into a warning (#107489)
The standard requires that a generic interface with the same name as a
derived type contain only functions. We generally allow a generic
interface to contain both functions and subroutines, since there's never
any ambiguity at the point of call; these is helpful when the specific
procedures of two generics are combined during USE association. Emit a
warning instead of a hard error when a generic interface with the same
name as a derived type contains a subroutine to improve portability of
code from compilers that don't check for this condition.
2024-09-10 14:10:40 -07:00
Peter Klausler
4228e28293
[flang] Fix crash in semantics (#106158)
Semantics crashes when merging a USE-associated derived type with a
local generic procedure interface of the same name. (The other direction
works.)
2024-09-04 10:51:52 -07:00
Peter Klausler
961a138237
[flang] Silence spurious error (#106086)
Don't attempt to give an object a default binding label when it shows up
in a declaration after it has already been given an explicit binding
label in an earlier declaration.

Fixes https://github.com/llvm/llvm-project/issues/106019.
2024-08-26 10:56:37 -07:00
Peter Klausler
90d753ab75
[flang] Fix inheritance of IMPLICIT typing rules (#102692)
Interfaces don't inherit the IMPLICIT typing rules of their enclosing
scope, and separate MODULE PROCEDUREs inherit the IMPLICIT typing rules
of submodule in which they are defined, not the rules from their
interface.

Fixes https://github.com/llvm/llvm-project/issues/102558.
2024-08-20 12:03:15 -07:00
Peter Klausler
245eb0a716
[flang] Catch structure constructor in its own type definition (#102241)
The check for a structure constructor to a forward-referenced derived
type wasn't tripping for constructors in the type definition itself. Set
the forward reference flag unconditionally at the beginning of name
resolution for the type definition.
2024-08-08 11:08:00 -07:00
Peter Klausler
d9af9cf436
[flang] Don't set Subroutine flag on PROCEDURE() pointers (#102011)
External procedures about which no characteristics are known -- from
EXTERNAL and PROCEDURE() statements of entities that are never called --
are marked as subroutines. This shouldn't be done for procedure
pointers, however.

Fixes https://github.com/llvm/llvm-project/issues/101908.
2024-08-08 11:05:39 -07:00
Peter Klausler
ed5a78a13f
[flang] Catch ASSOCIATE(x=>assumed_rank) (#100626)
An assumed-rank dummy argument cannot be the variable or expression in
the selector of an ASSOCIATE construct. (SELECT TYPE/RANK are fine.)
2024-07-30 09:44:09 -07:00
Peter Klausler
539a6b500c
[flang] Detect use-before-decl errors on type parameters (#99947)
Ensure that type parameters are declared as such before being referenced
within the derived type definition. (Previously, such references would
resolve to symbols in the enclosing scope.)

This change causes the symbols for the type parameters to be created
when the TYPE statement is processed in name resolution. They are
TypeParamDetails symbols with no KIND/LEN attribute set, and they shadow
any symbols of the same name in the enclosing scope.

When the type parameter declarations are processed, the KIND/LEN
attributes are set. Any earlier reference to a type parameter with no
KIND/LEN attribute elicits an error.

Some members of TypeParamDetails have been retyped &/or renamed.
2024-07-30 09:42:15 -07:00
Peter Klausler
d5285fef00
[flang] Downgrade error message to a portability warning (#98368)
f18 current emits an error when an assignment is made to an array
section with a vector subscript, and the array is finalized with a
non-elemental final subroutine. Some other compilers emit this error
because (I think) they want variables to only be finalized in place, not
by a subroutine call involving copy-in & copy-out of the finalized
elements.

Since many other Fortran compilers can handle this case, and there's
nothing in the standards to preclude it, let's downgrade this error
message to a portability warning.

This patch got complicated because the API for the WhyNotDefinable()
utility routine was such that it would return a message only in error
cases, and there was no provision for returning non-fatal messages. It
now returns either nothing, a fatal message, or a non-fatal warning
message, and all of its call sites have been modified to cope.
2024-07-11 13:12:00 -07:00
Peter Klausler
3602efa78d
[flang] Silence errors on C_LOC/C_FUNLOC in specification expressions (#96108)
Transformational functions from the intrinsic module ISO_C_BINDING are
allowed in specification expressions, so tweak some general checks that
would otherwise trigger error messages about inadmissible targets, dummy
procedures in specification expressions, and pure procedures with impure
dummy procedures.
2024-06-24 09:06:32 -07:00
David Truby
c6b6e18c4d
[flang] Implement !DIR$ VECTOR ALWAYS (#93830)
This patch implements support for the VECTOR ALWAYS directive, which
forces
vectorization to occurr when possible regardless of a decision by the
cost
model. This is done by adding an attribute to the branch into the loop
in LLVM
to indicate that the loop should always be vectorized.

This patch only implements this directive on plan structured do loops 
without labels. Support for unstructured loops and array
expressions is planned for future patches.
2024-06-14 14:10:41 +01:00
Peter Klausler
f3c227b797
[flang] Support BIND(C, NAME="...", CDEFINED) extension (#94402)
This CDEFINED keyword extension to a language-binding-spec signifies
that static storage for an interoperable variable will be allocated
outside of Fortran, probably by a C/C++ external object definition.
2024-06-11 16:56:30 -07:00
Peter Klausler
d03cd05f07
[flang] Propagate the BIND(C) attribute into procedures from their in… (#93994)
…terfaces

In "PROCEDURE(iface) :: proc", if "iface" has the BIND(C) attribute,
then so should proc, as if the declaration had been "PROCEDURE(iface),
BIND(C) :: proc". This had been working in name resolution only in cases
where "iface" had been declared before "proc".

Note that if "iface" is declared with an empty binding name
("BIND(C,NAME='')"), "proc" does not inherit that property. Use an
explicit "BIND(C,NAME='')" on the "PROCEDURE" statement for that.

This behavior is not clearly defined in the standard, but seems to match
what some other Fortran compilers do.
2024-06-03 14:49:08 -07:00
Peter Klausler
74f4034f71
[flang] Fix type inheritance for statement function dummy arguments (#93624)
The code that used existing type declarations (if any) for the names
being used as dummy arguments in a statement function definition would
apply those types only if they came from EntityDetails symbols. This
broke a case in which the type was being inherited from a Cray pointee.

Fixes https://github.com/llvm/llvm-project/issues/93484.
2024-06-03 13:25:57 -07:00
khaki3
3af717d661
[flang] Add parsing of DO CONCURRENT REDUCE clause (#92518)
Derived from #92480. This PR supports parsing of the DO CONCURRENT
REDUCE clause in Fortran 2023. Following the style of the OpenMP parser
in MLIR, the front end accepts both arbitrary operations and procedures
for the REDUCE clause. But later Semantics can notify type errors and
resolve procedure names.
2024-05-30 11:34:19 -07:00
Peter Klausler
c9f94baca5
[flang] Fix crash in error recovery (implicit host association) (#92795)
When a symbol appears in a specification expression in a subprogram
contained in a host program unit, semantics may have to create a symbol
in the host and use host association to it. This shouldn't happen for
nested subprograms that can't import such a symbol, such as interface
blocks by default. Further, when host association fails, semantics
shouldn't crash.

Fixes https://github.com/llvm/llvm-project/issues/92647.
2024-05-23 13:41:08 -07:00
Peter Klausler
70d1844abe
[flang] Fix crash in error recovery (#92786)
EQUIVALENCE set processing assumes that any arrays have explicit shape
and constant lower bounds. When an erroneous program violates those
assumptions, the compiler crashes. Fix.

Fixes https://github.com/llvm/llvm-project/issues/92636.
2024-05-23 13:31:25 -07:00
Valentin Clement (バレンタイン クレメン)
6d50a79b72
[flang][cuda] Implicitly load cudadevice module in device/global subprogram (#92038)
This is a re-worked version of #91668. It adds the `cudadevice` module
and set the `device` attributes on its functions/subroutines so there is
no need for special case in semantic check.
`cudadevice` module is implicitly USE'd in `global`/`device` subprogram.
2024-05-17 13:58:49 -07:00
Peter Klausler
5bbb63bd6d
[flang] Parse REDUCE clauses in !$CUF KERNEL DO (#92154)
A !$CUF KERNEL DO directive is allowed to have advisory REDUCE clauses
similar to those in OpenACC and DO CONCURRENT. Parse and represent them.
Semantic validation will follow.
2024-05-15 16:28:58 -07:00
Peter Klausler
7605ad8a2f
[flang] Always check procedure characterizability (#92008)
When a procedure is defined with a subprogram but never referenced in a
compilation unit, it may not be characterized until lowering, and any
errors in characterization then may crash the compiler. So always ensure
that procedure definitions are characterizable in declaration checking.

Fixes https://github.com/llvm/llvm-project/issues/91845.
2024-05-15 16:08:06 -07:00
Valentin Clement (バレンタイン クレメン)
38b2755983
Revert "[flang][cuda] Implicitly load cudadevice module in device/global subprogram" (#91827)
Reverts llvm/llvm-project#91668
2024-05-10 17:51:30 -07:00
Valentin Clement (バレンタイン クレメン)
f32f6d199a
[flang][cuda] Implicitly load cudadevice module in device/global subprogram (#91668)
Some functions and subroutines are available in device context
(device/global). These functions have interfaces declared in the
`cudadevice` module.

This patch adds interfaces as `__cuda_device_builtins_<fctname>` in a
builtin module and they are USE'd rename in the `cudadevice` module. The
module is implicitly used in device/global subprograms.

The builtin module only contains procedures from section 3.6.4 for now.
2024-05-10 13:41:53 -07:00
Peter Klausler
19b41f40a4
[flang] Complete RESULT() name constraint checking (#91476)
There are two constraints in the language that prohibit the use of an
ENTRY name being used as the RESULT() variable of the function or
another ENTRY name in the same function's scope; neither can the name of
the function be used as the RESULT() of an ENTRY.
    
Move most of the existing partial enforcement of these constraints from
name resolution into declaration checking, complete it, and add more
cases to the tests.
2024-05-09 11:31:13 -07:00
Peter Klausler
22c59e01cd
[flang] Don't crash on bad inherited implied DO type (#91073)
Fortran has an ambiguously defined rule about the typing of index
variables of implied DO loops in DATA statements and array constructors
that omit an explicit type specification. Such indices have the type
that they would have "if they were variables" in the innermost enclosing
scope. Although this could, and perhaps should, be read to mean that
implicit typing rules active in that innermost enclosing scope should be
applied, every other Fortran compiler interprets that language to mean
that if there is a type declaration for that name that is visible from
the enclosing scope, it is applied, and it is an error if that type is
not integer.

Fixes https://github.com/llvm/llvm-project/issues/91053.
2024-05-09 10:17:15 -07:00
Peter Klausler
8ed7ea0896
[flang] Defer conversion of PDT default initializers (#91026)
As the kinds of the integer types of type parameters may well depend on
the values of other type parameters, defer the attempt to convert their
values to the point of type instantiation instead of doing it during
declaration processing.
2024-05-09 09:56:01 -07:00
Peter Klausler
505f6da196
[flang] Ensure all warning/portability messages are guarded by Should… (#90518)
…Warn()

Many warning messages were being emitted unconditionally. Ensure that
all warnings are conditional on a true result from a call to
common::LanguageFeatureControl::ShouldWarn() so that it is easy for a
driver to disable them all, or, in the future, to provide per-warning
control over them.
2024-05-01 14:33:14 -07:00
Peter Klausler
68a27989d0
[flang] Accept and ignore compiler directives between internal subpro… (#89810)
…grams

The parser only recognizes compiler directives that appear within
internal / module subprograms, not those that might appear between them.
Extend to allow them between subprograms as well.
2024-04-24 15:25:19 -07:00
Peter Klausler
c3def59d0f
[flang] Fix bogus error about duplicate binding names (#89786)
Don't call SetBindNameOn() from DeclareUnknownEntity() unless there is
an explicit BIND(C) attribute.

Fixes https://github.com/llvm/llvm-project/issues/89439 and
https://github.com/llvm/llvm-project/issues/89558.
2024-04-24 14:57:00 -07:00
Peter Klausler
59bf49a632
[flang] Fix bogus error on statement function (#89402)
When a statement function in a nested scope has a name that clashes with
a name that exists in the host scope, the compiler can handle it
correctly (with a portability warning)... unless the host scope acquired
the name via USE association. Fix.

Fixes https://github.com/llvm/llvm-project/issues/88678.
2024-04-22 15:12:32 -07:00
Peter Klausler
cb1b846eda
[flang] Improve error reporting for procedures determined by usage (#88184)
When a symbol is known to be a procedure due to its being referenced as
a function or subroutine, improve the error messages that appear if the
symbol is also used as an object by attaching the source location of its
procedural use. Also, for errors spotted in name resolution due to how a
given symbol has been used, don't unconditionally set the symbol's error
flag (which is otherwise generally a good idea, to prevent cascades of
errors), so that more unrelated errors related to usage will appear.
2024-04-22 14:27:39 -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
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
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
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
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
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
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
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
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
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