Commit Graph

4457 Commits

Author SHA1 Message Date
Damian Rouson
565f5dfa1f [flang] test conforming & non-conforming lcobound
Add a test with standard-conforming  non-conforming lcobound()
intrinsic function invocations.  Also test that several
non-conforming lcobound() invocations generate the correct error
messages.

Differential Revision: https://reviews.llvm.org/DD123747
2022-05-18 16:55:48 -07:00
Diana Picus
1c0b03f6e7 [flang][driver] Support parsing response files
Add support for reading response files in the flang driver. Response
files contain command line arguments and are used whenever a command
becomes longer than the shell/environment limit. Response files are
recognized via the special "@path/to/response/file.rsp" syntax, which
distinguishes them from other file inputs.

This patch hardcodes GNU tokenization, since we don't have a CL mode for
the driver. In the future we might want to add a --rsp-quoting command
line option, like clang has, to accommodate Windows platforms.

Differential Revision: https://reviews.llvm.org/D124846
2022-05-18 08:25:45 +00:00
Diana Picus
6bcafce103 [flang][Runtime] Use proper prototypes in Fortran_main. NFCI
This is compiled as C code, so it's a good idea to be explicit about the
prototype. Clang complains about this when -Wstrict-prototypes is used.

Differential Revision: https://reviews.llvm.org/D125672
2022-05-18 08:04:09 +00:00
rkayaith
7814b559bd [GreedyPatternRewriter] Avoid reversing constant order
The previous fix from af371f9f98 only applied when using a bottom-up
traversal. The change here applies the constant preprocessing logic to the
top-down case as well. This resolves the issue with the canonicalizer pass still
reordering constants, since it uses a top-down traversal by default.

Fixes #51892

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D125623
2022-05-18 00:55:59 -07:00
Peixin-Qiao
5646d82885 [flang] Add one semantic check for elemental call arguments
As Fortran 2018 15.8.1(3), in a reference to an elemental procedure, if
any argument is an array, each actual argument that corresponds to an
INTENT (OUT) or INTENT (INOUT) dummy argument shall be an array. Add
this semantic check.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D125685
2022-05-17 15:11:46 +08:00
Peixin-Qiao
f305ac3d5d [flang][OpenMP] Support lowering to MLIR for ordered clause
This supports the lowering parse-tree to MLIR for ordered clause in
worksharing-loop directive. Also add the test case for operation
conversion.

Part of this patch is from the fir-dev branch of
https://github.com/flang-compiler/f18-llvm-project.

Co-authored-by: Sourabh Singh Tomar <SourabhSingh.Tomar@amd.com>

Reviewed By: kiranchandramohan, NimishMishra

Differential Revision: https://reviews.llvm.org/D125456
2022-05-17 15:07:52 +08:00
River Riddle
a6cef03f66 [mlir] Remove the type keyword from type alias definitions
This was carry over from LLVM IR where the alias definition can
be ambiguous, but MLIR type aliases have no such problems.
Having the `type` keyword is superfluous and doesn't add anything.
This commit drops it, which also nicely aligns with the syntax for
attribute aliases (which doesn't have a keyword).

Differential Revision: https://reviews.llvm.org/D125501
2022-05-16 13:54:02 -07:00
Diana Picus
3d2e05d542 [flang] Install Fortran_main library
At the moment the Fortran_main library is not installed, so it cannot be
found by the driver when run from an install directory. This patch fixes
the issue by replacing llvm_add_library with add_flang_library, which
already contains all the proper incantations for installing a library.
It also enhances add_flang_library to support a STATIC arg which forces
the library to be static even when BUILD_SHARED_LIBS is on.

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

Co-authored-by: Dan Palermo <Dan.Palermo@amd.com>
2022-05-16 08:30:53 +00:00
Andrzej Warzynski
ea18987094 [flang][nfc] Fix driver method names overridden by the plugins
After the recent re-factoring of the driver code
(https://reviews.llvm.org/D125007), `ExecuteAction` was renamed as
`executeAction`. This patch updates the examples in Flang accordingly.

If you set `FLANG_BUILD_EXAMPLES` to `On` when building Flang, then the
refactoring from D125007 would have caused build failures for you. This
patch fixes that.

This is fairly straightforward and fixes buildbot failures, so I'm
sending this without a review.
2022-05-15 17:58:04 +00:00
Andrzej Warzynski
1e462fafdf [flang][driver] Switch to the MLIR coding style in the driver (nfc)
This patch re-factors the driver code in LLVM Flang (frontend +
compiler) to use the MLIR style. For more context, please see:
https://discourse.llvm.org/t/rfc-coding-style-in-the-driver/

Most changes here are rather self-explanatory. Accessors are renamed to
be more consistent with the rest of LLVM (e.g. allSource -->
getAllSources). Additionally, MLIR clang-tidy files are added in the
affected directories.

clang-tidy and clang-format files were copied from MLIR. Small
additional changes are made to silence clang-tidy/clang-format
warnings.

[1] https://mlir.llvm.org/getting_started/DeveloperGuide/

Differential Revision: https://reviews.llvm.org/D125007
2022-05-14 10:27:06 +00:00
Chris Lattner
27478872fd [ParseResult] Fix warning in flang build, incorporate feedback from River.
The warning caused build errors on a couple flang testers that are
building with -Werror.  The diagnostic change makes the generated
error correct.

This is a followup to https://reviews.llvm.org/D125549

Differential Revision: https://reviews.llvm.org/D125587
2022-05-13 23:30:27 +01:00
PeixinQiao
a2ac0bb2f1 [flang] Warn for the limit on name length
As fortran 2018 C601, the maximum length of a name is 63 characters.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D125371
2022-05-13 22:43:12 +08:00
Eric Schweitz
6822ed035f Fixes a performance problem with lowering of forall loops and creating
too many temporaries.

Fix clang-format errors.

Differential Revision: https://reviews.llvm.org/D125336
2022-05-12 08:11:58 -07:00
Peter Klausler
d80d812df0 [flang] Fix check for assumed-size arguments to SHAPE() & al.
The predicate that is used to detect an invalid assumed-size argument
to the intrinsic functions SHAPE, SIZE, & LBOUND gives false results
for arguments whose shapes are not calculatable at compilation time.
Replace with an explicit test for an assumed-size array dummy argument
symbol.

Differential Revision: https://reviews.llvm.org/D125342
2022-05-11 10:33:17 -07:00
Peter Klausler
3a26596af3 [flang] Fold complex component references
Complex component references (z%RE, z%IM) of complex named constants
should be evaluated at compilation time.

Differential Revision: https://reviews.llvm.org/D125341
2022-05-11 10:04:13 -07:00
Peter Steinfeld
d4609ae47d [flang] Change "bad kind" messages in the runtime to "not yet implemented"
Similar to change D125046.

If a programmer is able to compile and link a program that contains types that
are not yet supported by the runtime, it must be because they're not yet
implemented.

This change will make it easier to find unimplemented code in tests.

Differential Revision: https://reviews.llvm.org/D125267
2022-05-10 20:08:03 -07:00
Peter Klausler
2cd95504df [flang] Allow local variables and function result inquiries in specification expressions
Inquiries into the bounds, size, and length of local variables (and function results)
are acceptable specification expressions.  A recent change allowed them for dummy
arguments that are not OPTIONAL or INTENT(OUT), but didn't address other object
entities.

Differential Revision: https://reviews.llvm.org/D125343
2022-05-10 16:47:03 -07:00
Peter Klausler
940871dd28 [flang] Enforce limit on rank + corank
Fortran 2018 requires that a compiler allow objects whose rank + corank
is 15, and that's our maximum; detect and diagnose violations.

Differential Revision: https://reviews.llvm.org/D125153
2022-05-10 08:53:08 -07:00
Peter Klausler
71728360ad [flang] Fold real-valued MODULO() and MOD()
Evaluate real-valued references to the intrinsic functions MODULO
and MOD at compilation time without recourse to an external math
library.

Differential Revision: https://reviews.llvm.org/D125151
2022-05-10 08:15:29 -07:00
Peter Klausler
9e50168be4 [flang] Fold real-valued DIM()
Fold references to the intrinsic function DIM with constant real
arguments.  And clean up folding of comparisons with NaNs to address
a problem noticed in testing -- NaNs should successfully compare
unequal to all values, including themselves, instead of failing all
comparisons.

Differential Revision: https://reviews.llvm.org/D125146
2022-05-10 07:45:41 -07:00
Shraiysh Vaishay
04cb01cf10 [flang][OpenMP] Lowering for task construct
This patch adds lowering for task construct from Fortran to
`omp.task` operation in OpenMPDialect Dialect (mlir). Also added tests
for the same.

Reviewed By: kiranchandramohan, peixin

Differential Revision: https://reviews.llvm.org/D124138
2022-05-10 10:42:08 +05:30
Peter Klausler
8c407f4a11 [flang] Allow ENTRY function result symbol usage before the ENTRY
In a function, ENTRY E without an explicit RESULT() creates a
function result entity also named E that is storage associated with
the enclosing function's result.  f18 was emitting an incorrect error
message if that function result E was referenced without any
declaration prior to its ENTRY statement when it should have been
implicitly declared instead.

Differential Revision: https://reviews.llvm.org/D125144
2022-05-09 19:12:23 -07:00
Peter Klausler
8594b051fb [flang] Accept POINTER followed by INTERFACE
As is already supported for dummy procedures, we need to also accept
declarations of procedure pointers that consist of a POINTER attribute
statement followed by an INTERFACE block.  (The case of an INTERFACE
block followed by a POINTER statement already works.)

While cleaning this case up, adjust the utility predicate IsProcedurePointer()
to recognize it (namely a SubprogramDetails symbol with Attr::POINTER)
and delete IsProcName().  Extend tests, and add better comments to
symbol.h to document the two ways in which procedure pointers are
represented.

Differential Revision: https://reviews.llvm.org/D125139
2022-05-09 18:37:09 -07:00
Peter Klausler
eef76f9821 [flang] Reverse a reversed type compatibility check
The semantic test for an intrinsic assignment to a polymorphic
derived type entity from a type that is an extension of its base
type was reversed, so it would allow assignments that it shouldn't
and disallowed some that it should; and the test case for it
incorectly assumed that the invalid semantics were correct.
Fix the code and the test, and add a new test for the invalid
case (LHS type is an extension of the RHS type).

Differential Revision: https://reviews.llvm.org/D125135
2022-05-09 17:55:10 -07:00
Peter Klausler
5d5d2a0b19 [flang] Refine error checking in specification expressions
The rules in the Fortran standard for specification expressions
are full of special cases and exceptions, and semantics didn't get
them exactly right.  It is valid to refer to an INTENT(OUT) dummy
argument in a specification expression in the context of a
specification inquiry function like SIZE(); it is not valid to
reference an OPTIONAL dummy argument outside of the context of
PRESENT.  This patch makes the specification expression checker
a little context-sensitive about whether it's examining an actual
argument of a specification inquiry intrinsic function or not.

Differential Revision: https://reviews.llvm.org/D125131
2022-05-09 17:50:12 -07:00
Peter Klausler
3382edf9b9 [flang] Allow implicit declaration of DATA objects in inner procedures
DATA statements in inner procedures were not treating undeclared objects
as implicitly declared variables if the DATA statement appeared in a
specification part; they were treated as host-associated symbols instead.
This was incorrect.  Fix DATA statement name resolution to always treat
DATA as if it had appeared in the executable part.

Differential Revision: https://reviews.llvm.org/D125129
2022-05-09 17:49:47 -07:00
Peter Klausler
78a166b47b [flang] Allow NULL() actual argument for optional dummy procedure
A disassociated procedure pointer is allowed to be passed as an absent
actual argument that corresponds to an optional dummy procedure,
but not NULL(); accept that case as well.

Differential Revision: https://reviews.llvm.org/D125127
2022-05-09 17:41:39 -07:00
Peter Klausler
45ac2c730b [flang] Allow PDTs with LEN parameters in REDUCE()
The type compatibility checks for the ARRAY= argument and the dummy
arguments and result of the OPERATION= argument to the REDUCE intrinsic
function need to allow for parameterized data types with LEN parameters.
(Their values are required to be identical but this is not a numbered
constraint requiring a compilation time check).

Differential Revision: https://reviews.llvm.org/D125124
2022-05-09 17:40:50 -07:00
Peter Klausler
948d0b340b [flang] Correct actual/dummy procedure compatibility for ALLOCATABLE/POINTER functions
Functions returning ALLOCATABLE or POINTER arrays have descriptor inquiries in
their results' shape expressions that won't compare equal.  These functions
need only be checked for compatible ranks (& of course other characteristics).

Differential Revision: https://reviews.llvm.org/D125123
2022-05-09 16:40:21 -07:00
Peter Klausler
6f14dbedd9 [flang] Fix to UnwrapConvertedExpr()
The utility UnwrapConvertedExpr() was failing to unwrap a
converted TypeParamInquiry operation when called from runtime
derived type description table construction, leading to an
abort in semantics.

Differential Revision: https://reviews.llvm.org/D125119
2022-05-09 16:39:15 -07:00
Peter Klausler
a054c88205 [flang] Ensure that structure constructors fold parameter references
Structure contructors for instances of parameterized derived types
must have their components' values folded in the context of the values
of the type parameters.

Differential Revision: https://reviews.llvm.org/D125116
2022-05-09 16:09:49 -07:00
Peter Klausler
be768164a7 [flang] Refine handling of short character actual arguments
Actual arguments whose lengths are less than the expected length
of their corresponding dummy argument are errors; but this needs
to be refined.  Short actual arguments that are variables remain
errors, but those that are expressions can be (again) extended on
the right with blanks.

Differential Revision: https://reviews.llvm.org/D125115
2022-05-09 15:39:48 -07:00
Peter Klausler
85fdbc1569 [flang] Correct folding of SPREAD() for higher ranks
The construction of the dimension order vector used to populate the
result array was incorrect, leading to a scrambled-looking result
for rank-3 and higher results.  Fix, and extend tests.

Differential Revision: https://reviews.llvm.org/D125113
2022-05-09 15:09:39 -07:00
Peter Klausler
18dd123c56 [flang] Operands of SIGN() need not have same kind
The standard requires that the operands of the intrinsic function
SIGN() must have the same type (INTEGER or REAL), but they are not
required to have the same kind.

Differential Revision: https://reviews.llvm.org/D125105
2022-05-09 14:39:26 -07:00
Peter Klausler
1cff71b975 [flang] Fold intrinsic functions SPACING() and RRSPACING()
The related real number system inquiry functions SPACING()
and RRSPACING() can be folded for constant arguments.
See 16.9.164 & 16.9.180 in Fortran 2018.

Differential Revision: https://reviews.llvm.org/D125100
2022-05-09 14:09:29 -07:00
Peter Klausler
460fc79a08 [flang] Fold intrinsic inquiry functions SAME_TYPE_AS() and EXTENDS_TYPE_OF()
When the result can be known at compilation time, fold it.
Success depends on whether the operands are polymorphic.
When neither one is polymorphic, the result is known and can
be either .TRUE. or .FALSE.; when either one is polymorphic,
a .FALSE. result still can be discerned.

Differential Revision: https://reviews.llvm.org/D125062
2022-05-09 13:38:18 -07:00
Peter Klausler
72831a592e [flang][runtime] BACKSPACE after non-advancing I/O
A BACKSPACE statement on a unit after a READ or WRITE with ADVANCE="NO"
must reset the position to the beginning of the record, not to the
beginning of the previous one.

Differential Revision: https://reviews.llvm.org/D125057
2022-05-09 13:00:41 -07:00
Peter Klausler
28b5e99a4c [flang][runtime] (G0) for CHARACTER means (A), not (A0)
I'm emitting zero characters for (G0) formatting of CHARACTER values
instead of using their lengths to determine the output field width.

Differential Revision: https://reviews.llvm.org/D125056
2022-05-09 13:00:15 -07:00
Peter Klausler
fb9ec95cf0 [flang][runtime] Enforce restrictions on unlimited format repetition
A repeated format item group with an unlimited ('*') repetition count
can appear only as the last item at the top level of a format; it can't
be nested in more parentheses and it can't be followed by anything
else.

Differential Revision: https://reviews.llvm.org/D125054
2022-05-09 12:48:23 -07:00
Peter Klausler
cea8b8a72d [flang][runtime] Don't pad CHARACTER input at end of record unless PAD='YES'
When formatted CHARACTER input runs into the end of an input record,
the runtime usually fills the remainder of the variable with spaces,
but this should be conditional, and not done when PAD='NO'.

And while here, add some better comments to two members of connection.h
to make their non-obvious relationship more clear.

Differential Revision: https://reviews.llvm.org/D125053
2022-05-09 12:39:43 -07:00
Peter Klausler
2f31b4b10a [flang][runtime] Fix input of NAN(...) on non-fast path
The closing parenthesis needs to be consumed when a NaN
with parenthesized (ignored) information is read on the
real input path that preprocesses input characters before
passing them to the decimal-to-binary converter.

Differential Revision: https://reviews.llvm.org/D125048
2022-05-09 12:38:31 -07:00
Jean Perier
d38915ffeb [flang] Fix windows bot after D125140
The ifdef is not required in the header, common::int128_t is always
defined. The function declaration must be available in lowering
regardless of the host int128_t support.

Differential Revision: https://reviews.llvm.org/D125211
2022-05-09 15:24:14 +02:00
Jean Perier
ed0341788a [flang] retain binding label of entry subprograms
When processing an entry-stmt in name resolution, attrs_ was
reset before SetBindNameOn was called, causing the symbol to lose
the binding label information.

Differential Revision: https://reviews.llvm.org/D125097
2022-05-09 09:50:17 +02:00
Peixin-Qiao
c207e36025 [flang] Enforce a program not including more than one main program
As Fortran 2018 5.2.2 states, a program shall consist of exactly one
main program. Add this semantic check.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D125186
2022-05-09 10:48:06 +08:00
Eric Schweitz
1bffc75383 Upstream support for POINTER assignment in FORALL.
Reviewed By: vdonaldson, PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D125140
2022-05-06 19:52:47 -07:00
River Riddle
a8308020ac [mlir] Remove special case parsing/printing of func operations
This was leftover from when the standard dialect was destroyed, and
when FuncOp moved to the func dialect. Now that these transitions
have settled a bit we can drop these.

Most updates were handled using a simple regex: replace `^( *)func` with `$1func.func`

Differential Revision: https://reviews.llvm.org/D124146
2022-05-06 13:36:15 -07:00
Daniil Dudkin
2c27d5b36a [flang] Fix internal error with DATA-statement style initializers
The code below causes flang to crash with an exception.
After fixing the crash flang with an internal error "no symbol found for 'bar'"
This change fixes all the issues.

  program name
    implicit none
    integer, parameter :: bar = 1
    integer foo(bar) /bar*2/
  end program name

Reviewed By: kiranchandramohan, klausler

Differential Revision: https://reviews.llvm.org/D124914
2022-05-06 18:21:34 +03:00
PeixinQiao
2472b6869a [flang] Add one semantic check for masked array assignment
As Fortran 2018 states, in each where-assignment-stmt, the mask-expr and
the variable being defined shall be arrays of the same shape. The
previous check does not consider checking if it is an array.

Reviewed By: klausler

Differential Revision: https://reviews.llvm.org/D125022
2022-05-06 22:19:20 +08:00
PeixinQiao
ffc7f9d542 [flang] Support external procedure passed as actual argument with implicit character type
As Fortran 2018 15.5.2.9 point 2, the actual argument and dummy argument
have the same type and type parameters and an external function with
assumed character length may be associated with a dummy argument with
explicit character length. As Fortran 2018 15.5.2.9 point 7, if an
external procedure is used as an actual argument, it can be explicitly
declared to have the EXTERNAL attribute. This supports the external
procedure passed as actual argument with implicit character type, either
explicit character length or assumed character length.

Reviewed By: Jean Perier, klausler

Differential Revision: https://reviews.llvm.org/D124345
2022-05-06 22:14:51 +08:00
PeixinQiao
ac0f4c8f36 [flang] Fix AllocaOp/AllocMemOp type conversion
For arrays without a constant interior or arrays of character with
dynamic length arrays, the data types are converted to a pointer to the
element type, so the scale size of the constant extents needs to be
counted. The previous AllocaOp conversion does not consider the arrays
of character with dynamic length arrays, and the previous AllocMemOp
conversion does not consider arrays without a constant interior. This
fixes them and refactors the code so that it can be shared. Also add
the test cases.

Reviewed By: Jean Perier

Differential Revision: https://reviews.llvm.org/D124766
2022-05-06 22:10:13 +08:00