Commit Graph

5461 Commits

Author SHA1 Message Date
Fangrui Song a996cc217c Remove unused #include "llvm/ADT/Optional.h" 2022-12-05 06:31:11 +00:00
Qihan Cai d9df5bb8cf [flang] Diagnostic for shape argument in c_f_pointer
Fix #59177, add check for dimensionality for shape argument against rank of FPTR argument in c_f_pointer

Reviewed By: peixin

Differential Revision: https://reviews.llvm.org/D138743
2022-12-05 14:09:04 +11:00
Peter Klausler 4b7428e151 [flang] Don't propagate PRIVATE into submodule module files
Module files for submodules should not contain PRIVATE attributes,
since everything in them is local to the parent module and
accessible to all descendant submodules.

Differential Revision: https://reviews.llvm.org/D139160
2022-12-04 17:00:13 -08:00
Peter Klausler 2577cb7a20 [flang] Check restrictions on TRANSFER()
Enforce detectable compilation-time violations of restrictions on the
arguments to the TRANSFER() intrinsic function (16.9.163) with
error messages, and mark other potential problems with warnings.

Differential Revision: https://reviews.llvm.org/D139157
2022-12-04 15:29:12 -08:00
Kazu Hirata 7f773ce6fc [flang] Use std::nullopt instead of None (NFC)
I've verified that every single instance of std::nullopt in this patch
affects generated files and would reduce the number of warnings if
None were deprecated.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-04 14:40:10 -08:00
Kazu Hirata 8d6589cba7 [flang] Use std::nullopt instead of None (NFC)
I've verified that every change in this patch affects generated files
and would reduce the number of warnings if None were deprecated.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-04 13:52:47 -08:00
Fangrui Song 12f6ac39bc [flang] Fix pgoOpt 2022-12-04 21:29:00 +00:00
Peter Klausler af54b676e4 [flang] Emit errors and warnings about DIM= arguments to intrinsic functions
The semantics of many transformational intrinsic functions, especially
reductions like SUM(), are determined by the static presence or absence
of a DIM= argument.  In the case of an actual DIM= argument that is
syntactically present but could be dynamically absent at execution time
(due to being OPTIONAL, POINTER, or ALLOCATABLE), f18 should emit some
kind of diagnostic message.

Other compilers either ignore this possibility or treat it as a hard
error; neither really seems correct, so let's do something more nuanced.

For cases where the dynamic absence of a value for DIM doesn't pose
as much of a risk because it lowering is going to assume that it's
equal to 1 anyway, emit only a portability warning.

For other cases where the generated code or runtime support library
will need the value of DIM= during execution, emit a warning that
the use of an OPTIONAL/POINTER/ALLOCATABLE variable or component
here is dicey and should be reconsidered.

While here, also catch bad constant DIM= values.

Differential Revision: https://reviews.llvm.org/D139155
2022-12-04 13:04:36 -08:00
Peter Klausler faa1338ccd [flang] Check constraint C834 on INTENT(OUT) assumed-size dummy arrays
An assumed-size dummy array argument with INTENT(OUT) can't have a type
that might require any runtime (re)initialization, since the size of the
array is not known.

Differential Revision: https://reviews.llvm.org/D139149
2022-12-04 10:38:42 -08:00
Kazu Hirata 63b63c3dcd [flang/unittests] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03 19:08:01 -08:00
Peter Klausler dc0d56febb [flang] Warn about local names that are the same as their enclosing program unit
Modules, submodules, main programs, and BLOCK DATA subprograms have names
that cannot be used within their scope, so we allow those names to be
used for other entities in the scope.  This might not be entirely
conformant with the language standard, so warn about it.

Differential Revision: https://reviews.llvm.org/D139146
2022-12-03 17:47:35 -08:00
Peter Klausler e86e2ab973 [flang] More error checking for ASSOCIATED()
The TARGET= argument of the ASSOCIATED() intrinsic function must be a valid
pointer assignment statement target.  Ensure that it does not contain a vector
subscript or any coindexing, either of which would imply a data copy into
temporary storage.

Differential Revision: https://reviews.llvm.org/D139145
2022-12-03 17:42:43 -08:00
Peter Klausler 9c1ad89d0e [flang] Emit portability warning for assigned FORMAT use
Emit a portability warning about usage of a deprecated feature
when an I/O data transfer statement uses a scalar integer
variable as an assigned format.

Differential Revision: https://reviews.llvm.org/D139144
2022-12-03 16:29:17 -08:00
Peter Klausler 066aecff92 [flang] INTENT(IN) pointer may not be forwarded to INTENT(IN OUT) or (OUT) dummy
19.6.8 forbids using an INTENT(IN) pointer dummy argument in a pointer association
context, and associated such a pointer with a dummy argument of INTENT(IN OUT) or
INTENT(OUT) is a circumstance that needs to be caught as an error.

Differential Revision: https://reviews.llvm.org/D139138
2022-12-03 16:28:17 -08:00
Peter Klausler 1623aee41a [flang] Check constraint C1577 for statement functions
Check most of the requiremens of constraint C1577 for statement functions.
The restrictions that prevent recursion are hard errors; the others seem
to be benign legacies and are caught as portability warnings.

Differential Revision: https://reviews.llvm.org/D139136
2022-12-03 15:43:47 -08:00
Peter Klausler bb7e31bccf [flang] Don't repeat module procedure interface from ancestor in *.mod file
When a submodule defines a module procedure whose interface was declared
in an ancestor (sub)module, don't repeat the definition of that interface
in the submodule's *.mod file output.

Differential Revision: https://reviews.llvm.org/D139132
2022-12-03 13:39:33 -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
Kazu Hirata 9a41739565 [flang] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03 12:14:21 -08:00
Peter Klausler 32332909f4 [flang] Disable flang/test/Semantics/resolve110.f90 on Windows
This test crashes Semantics (infinite recursion?) only when built with MSVC;
need to investigate further, disabling test for now.
2022-12-03 11:23:17 -08:00
Peter Klausler fee041f69d [flang] Document and warn about an extension
Standard Fortran allows type-bound procedure bindings to only
be called, and disallows them from being used in other contexts
where a procedure name can be: as the target of a procedure pointer
assignment statement, and as an actual argument that corresponds
to a dummy procedure.  So long as the interfaces match, there's
no good reason for these uses to be errors, and there some obvious
use cases in polymorphic programming.  So emit portability warnings
rather than errors, and document this usage as an extension.

Differential Revision: https://reviews.llvm.org/D139127
2022-12-03 11:09:59 -08:00
Peter Klausler d7a1351bb8 [flang] Enforce accessibility requirement on type-bound generic operators, &c.
Type-bound generics like operator(+) and assignment(=) need to not be
PRIVATE if they are used outside the module in which they are declared.

Differential Revision: https://reviews.llvm.org/D139123
2022-12-03 10:12:58 -08:00
Peter Klausler 7d147a3263 [flang] Warn on missing colons (C768)
In a derived type definition, a type bound procedure declaration
statement with neither interface nor attributes is required by constraint
C768 to have the optional "::" between the PROCEDURE keyword and the
bindings if any binding has a renaming with "=>".  The colons are
not actually necessary for a correct and unambiguous parse, so
emit a warning when they are missing.

Differential Revision: https://reviews.llvm.org/D139065
2022-12-03 09:27:39 -08:00
Peter Klausler 2f999cce19 [flang] Respect function vs subroutine distinction in generic matching
When checking the specific procedures of a generic interface for a
match against a given set of actual arguments, be sure to not match
a function against a subroutine call or vice versa.  (We generally
catch and warn about attempts to declare mixed interfaces, but they
are usually conforming and can be inadvertently created when generics
are merged due to USE and host association.)

Differential Revision: https://reviews.llvm.org/D139059
2022-12-03 07:53:04 -08:00
Peter Klausler 8a1f12c6fb [flang] Warn about more continuation lines than the standard permits
f18 doesn't have any limit on continuation lines in fixed or free form
source (other than available memory), but the standard does.  Emit
a portability warning when it is exceeded.

Differential Revision: https://reviews.llvm.org/D139055
2022-12-02 17:07:11 -08:00
Peter Klausler 629a29cacc [flang][examples] Fix build of flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp (take 2)
Need to add casts to std::string.
2022-12-02 16:15:20 -08:00
Peter Klausler 5ea0ba2c13 [flang] Enforce more restrictions on I/O data list items
12.6.3p5 requires an I/O data list item to have a defined I/O procedure
if it is polymorphic.  (We could defer this checking to the runtime,
but no other Fortran compiler does so, and we would also have to be
able to catch the case of an allocatable or pointer direct component
in the absence of a defined I/O subroutine.)

Also includes a patch to name resolution that ensures that a
SELECT TYPE construct entity is polymorphic in the domain of a
CLASS IS guard.

Also ensures that non-defined I/O of types with PRIVATE components
is caught.

Differential Revision: https://reviews.llvm.org/D139050
2022-12-02 16:10:52 -08:00
Peter Klausler bc83d1c655 [flang] Enforce restrictions on intrinsic assignment
When the left-hand side of an intrinsic assignment statement is
polymorphic, the LHS must be a whole allocatable variable or
component and may not be a coarray (10.2.2.1p1(1)).

Differential Revision: https://reviews.llvm.org/D139049
2022-12-02 15:23:38 -08:00
Peter Klausler 8d23614a29 [flang] Disallow NULL() as an expression where it cannot appear
A NULL() pointer is generally not a valid expression (as opposed to
a variable) apart from some initialization contexts and some actual
arguments.

Differential Revision: https://reviews.llvm.org/D139047
2022-12-02 14:36:51 -08:00
Peter Klausler 56b7db9e07 [flang] Change error to portability warning
The standard does *not* require that a real or imaginary part of a complex
literal constant be a scalar if it is a named constant.  Downgrade a
recently installed check to a portability warning, and document it.

Differential Revision: https://reviews.llvm.org/D139046
2022-12-02 13:45:41 -08:00
River Riddle b74192b7ae [mlir] Remove support for non-prefixed accessors
This finishes off a year long pursuit to LLVMify the generated
operation accessors, prefixing them with get/set. Support for
any other accessor naming is fully removed after this commit.

https://discourse.llvm.org/t/psa-raw-accessors-are-being-removed/65629

Differential Revision: https://reviews.llvm.org/D136727
2022-12-02 13:32:36 -08:00
Peter Klausler 7efec1a40a [flang] Don't emit spurious error for polymorphic actual argument in PURE
Definability checking is unconditionally flagging the use of a polymorphic
variable as an actual argument for a procedure reference in a PURE subprogram
unless the corresponding dummy is INTENT(IN).  This isn't necessary, since
an INTENT(OUT) polymorphic dummy is already caught as an error in the definition
of the callee, which must also be PURE; and an INTENT(IN OUT) or intent-free
dummy is allowed to be passed a polymorphic actual in a PURE context, with
any attempt to deallocate it being caught in the callee.

So add a flag to the definability checker to disable the "polymorphic
definition in PURE context" check when using it to check actual arguments.

Differential Revision: https://reviews.llvm.org/D139044
2022-12-02 13:17:06 -08:00
Peter Klausler 745f6fcd2b [flang][examples] Fix usage of EnumToString()
EnumToString() now returns a string_view; usage in
  examples/FlangOmpReport/FlangOmpReportVisitor.cpp
needs to be updated.  Pushing without review to get
flang build bots back up.
2022-12-02 13:16:40 -08:00
Peter Klausler 78da80e2ef [flang] Restore C702 check for ProcEntity symbols
A recent change moved some checking code from name resolution into
declaration checking, and inadvertently disabled C702 checking for
procedure entities.  Fix.

Differential Revision: https://reviews.llvm.org/D139043
2022-12-02 12:06:49 -08:00
Peter Klausler 0d58834700 [flang] Check discrepancies between local & available global subprograms
When a scope declares the name and perhaps some characteristics of
an external subprogram using any of the many means that Fortran supplies
for doing such a thing, and that external subprogram's definition is
available, check the local declaration against the external definition.
In particular, if the global definition's interface cannot be called
by means of an implicit interface, ensure that references are via an
explicit and compatible interface.

Further, extend call site checking so that when a local declaration
exists for a known global symbol and the arguments are valid for that
local declaration, the arguments are checked against the global's
interface, just are is already done when no local declaration exists.

Differential Revision: https://reviews.llvm.org/D139042
2022-12-02 11:11:31 -08:00
Peter Klausler 01688ee9df [flang] Accommodate unknowable CHARACTER length in evaluate::ArrayConstructor<>
The internal representation for array constructors in expressions during semantic
analysis needs to be able to accommodate circumstances (e.g. TRIM(), substrings)
in which the length of the elements in the array is either unknown or cannot be
represented as a context-free integer expression.

Differential Revision: https://reviews.llvm.org/D139041
2022-12-02 10:37:28 -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
Usman Nadeem 3951a73490 [Flang][Driver] Handle target CPU and features
This patch:

- Adds target-feature and target-cpu to FC1Options.
- Moves getTargetFeatures() from Clang.cpp to CommonArgs.cpp.
- Processes target cpu and features in the flang driver. Right now
  features are only added for AArch64/x86 because I only did basic
  testing on them but it should generally work for others as well.
  Option handling is similar to clang.
- Adds appropriate structures in TargetOptions and passes them to
  the target machine.

What's missing:

- Adding the CPU info and the features as attributes in the LLVM IR
  module.
- Processing target specific flags, e.g. SVE vector bits for AArch64,
  ABI etc.

Differential Revision: https://reviews.llvm.org/D137995

Change-Id: Ib081a74ea98617674845518a5d2754edba596418
2022-12-02 09:37:53 -08:00
Jean Perier 655d994adc [flang] fix unused-but-set-parameter warning in ConvertExprToHLFIR.cpp
Some named value operands are not used yet (TODOs). Some compilers
complain about it. Remove names of unused parameters.

Differential Revision: https://reviews.llvm.org/D139207
2022-12-02 17:57:12 +01:00
Jean Perier f24466cf62 [flang] Lower conversions to HLFIR
Differential Revision: https://reviews.llvm.org/D139196
2022-12-02 16:19:38 +01:00
Valentin Clement f8ea349a6d
[flang] Perform assignment to polymorphic allocatable with runtime call
Lower assignment to polymorphic allocatable to the `Assign` runtime
call.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D139192
2022-12-02 15:51:20 +01:00
Jean Perier ffdb5f951c [flang] add missing unreachable in D139179
Fix bot failure https://lab.llvm.org/buildbot/#/builders/160/builds/13647
caused by https://reviews.llvm.org/D139179.

Even if the switch is fully covering, adding an unreachable after is
required to cover all path since the switch argument could be a broken
value that does not belong to the enum.
2022-12-02 05:46:22 -08:00
Jean Perier 12c8797fc4 [flang] Lower unary operation to HLFIR
Lower not, negate, and complex component to HLFIR.
Parentheses is the only remaining operation, but needs some
care/thinking to properly deal with character/derived variables.

Differential Revision: https://reviews.llvm.org/D139186
2022-12-02 14:22:41 +01:00
Jean Perier fed3d272da [flang] Make SetLength TODO explicit in HLFIR
evaluate::SetLength is the last intrinsic binary operation
that needs to be lowered to HLFIR. It will require an hlfir.set_length
op or hlfir.as_expr to convert the result to an expression. Add a TODO
for now.

Differential Revision: https://reviews.llvm.org/D139183
2022-12-02 14:21:27 +01:00
Jean Perier 26ceeee757 [flang] Lower complex constructor to HLFIR
Differential Revision: https://reviews.llvm.org/D139180
2022-12-02 14:20:22 +01:00
Jean Perier 248fcb13be [flang] Lower logical operations to HLFIR
Differential Revision: https://reviews.llvm.org/D139179
2022-12-02 14:19:12 +01:00
Jean Perier 12530711fc [flang] Lower relational to HLFIR
Differential Revision: https://reviews.llvm.org/D139176
2022-12-02 14:18:10 +01:00
Valentin Clement c44292f15b
[flang] Enable character type guard in select type
SELECT TYPE lower and conversion was not handling
`character` type guard. This add support for it.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D139106
2022-12-02 09:53:48 +01:00
Jean Perier 991a90a00d [flang] Lower evaluate::Extremum
Update BinaryOp<T>::gen so that const T& is threaded and some
operation knowledge that is not encoded by the type T or the arguments
can be used. For Extremum, it is the order (Greater or Lesser) that is
required, but this will also be required for evaluate::Relational.

Differential Revision: https://reviews.llvm.org/D139124
2022-12-02 09:29:39 +01:00
Slava Zakharin 68755f223f Revert "[flang] Use proper attributes for runtime calls with 'i1' arguments/returns."
This reverts commit d5b0de35bd.
2022-12-01 10:32:33 -08:00
Jean Perier 319f0221ee [flang] hlfir.associate and hlfir.end_associate codegen
Add hlfir.associate and hlfir.end_associate codegen.
To properly allow reusing the bufferized expression storage for the
newly created variable, bufferization of hlfir.expr has to be updated
so that hlfir.expr are translated to a variable and a boolean to
indicate if the variable storage needs to be freed after the expression
was used. That way the responsibility to free the bufferized expression
can be passed to the variable user, and applied in the
hlfir.end_associate.

Right now, not of the bufferized expression are heap allocated, so
generating the conditional freemem in hlfir.end_associate is left as
a TODO for when it can be tested.

Differential Revision: https://reviews.llvm.org/D139020
2022-12-01 17:58:28 +01:00