29 Commits

Author SHA1 Message Date
Peter Klausler
fc97d2e68b
[flang] Add UNSIGNED (#113504)
Implement the UNSIGNED extension type and operations under control of a
language feature flag (-funsigned).

This is nearly identical to the UNSIGNED feature that has been available
in Sun Fortran for years, and now implemented in GNU Fortran for
gfortran 15, and proposed for ISO standardization in J3/24-116.txt.

See the new documentation for details; but in short, this is C's
unsigned type, with guaranteed modular arithmetic for +, -, and *, and
the related transformational intrinsic functions SUM & al.
2024-12-18 07:02:37 -08:00
Peter Klausler
fc1c481cf4
[flang][preprocessor] Change handling of macros in text from Fortran … (#108113)
…INCLUDE lines

The compiler current treats an INCLUDE line as essentially a synonym for
a preprocessing #include directive. The causes macros that have been
defined at the point where the INCLUDE line is processed to be replaced
within the text of the included file.

This behavior is surprising to users who expect an INCLUDE line to be
expanded into its contents *after* preprocessing has been applied to the
original source file, with no further macro expansion.

Change INCLUDE line processing to use a fresh instance of Preprocessor
containing no macro definitions except _CUDA in CUDA Fortran
compilations and, if the original file was being preprocessed, the
standard definitions of __FILE__, __LINE__, and so forth.
2024-09-12 09:08:00 -07:00
Michael Klemm
2f8b64d327
[flang][runtime] Build ISO_FORTRAN_ENV to export kind arrays as linkable symbols (#95388)
Moves definitions of the kind arrays into a Fortran MODULE to not only
emit the MOD file, but also compile that MODULE file into an object
file. This file is then linked into libFortranRuntime.so.

Eventually this workaround PR shoud be redone and a proper runtime build
should be setup that will then also compile Fortran MODULE files.

Fixes #89403

---------

Co-authored-by: Valentin Clement (バレンタイン クレメン) <clementval@gmail.com>
Co-authored-by: Michael Kruse <github@meinersbur.de>
2024-07-19 19:37:24 +02: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
Michael Klemm
ab32a3c166
[flang] Do not leak intrinsics used by ISO_C_BINDING and ISO_FORTRAN_ENV (#79006)
This resolves bug #78953. Intrinsics used by the MODULE definition are
being declared PRIVATE, so that they do not leak into the namespace of
the code that USEs the modules.
2024-01-23 08:43:29 +01:00
Katherine Rasmussen
a2d7af757b
[flang] Add notify-type and notify-wait-stmt (#76594)
Add `notify-type` to `iso_fortran_env` module. Add `notify-wait-stmt` to
the parser and add checks for constraints on the statement, `C1177` and
`C1178`, from the Fortran 2023 standard. Add three semantics tests for
`notify-wait-stmt`.
2024-01-02 10:40:47 -08:00
Peter Klausler
8f3357b75b
[flang][runtime] Don't use -1 in I/O API for "default unit" (#76642)
The I/O runtime's API allows -1 to be passed for a unit number in a
READ, WRITE, or PRINT statement, where it gets replaced by 5 or 6 as
appropriate. This turns out to have been a bad idea, as it prevents the
I/O runtime from detecting and reporting a program's invalid attempt to
use -1 as an I/O unit number. So just pass 5 or 6 as appropriate.
2024-01-02 09:44:16 -08:00
Peter Klausler
5a402c5622
[flang] USE-associated explicit INTRINSIC names (#76199)
The compiler doesn't USE-associate names of intrinsic procedures from
modules (in the absence of ONLY:), so that the associating scope doesn't
get populated with names of intrinsics that were used only in
declarations (e.g., SELECTED_REAL_KIND). A recent bug report (below)
shows that we should modify that policy in the case of names that appear
in explicit INTRINSIC attribute statements. The behaviors of other
Fortran compilers are not consistent and the requirements of the
standard are not clear; this fix follows the precedent set by gfortran
and nvfortran.

Fixes https://github.com/llvm/llvm-project/issues/72084.
2023-12-26 16:03:03 -08:00
vdonaldson
3aba9264b3
[flang] IEEE_ARITHMETIC and IEEE_EXCEPTIONS intrinsic module procedures (#74138)
Implement a selection of intrinsic module procedures that involve
exceptions.

 - IEEE_GET_FLAG
 - IEEE_GET_HALTING_MODE
 - IEEE_GET_MODES
 - IEEE_GET_STATUS
 - IEEE_LOGB
 - [f23] IEEE_MAX, IEEE_MAX_MAG, IEEE_MAX_NUM, IEEE_MAX_NUM_MAG
 - [f23] IEEE_MIN, IEEE_MIN_MAG, IEEE_MIN_NUM, IEEE_MIN_NUM_MAG
 - IEEE_QUIET_EQ, IEEE_QUIET_GE, IEEE_QUIET_GT,
 - IEEE_QUIET_LE, IEEE_QUIET_LT, IEEE_QUIET_NE
 - IEEE_SET_FLAG
 - IEEE_SET_HALTING_MODE
 - IEEE_SET_MODES
 - IEEE_SET_STATUS
 - IEEE_SIGNALING_EQ, IEEE_SIGNALING_GE, IEEE_SIGNALING_GT,
 - IEEE_SIGNALING_LE, IEEE_SIGNALING_LT, IEEE_SIGNALING_NE
 - IEEE_SUPPORT_FLAG
 - IEEE_SUPPORT_HALTING
2023-12-04 09:55:54 -08:00
Hussain Kadhem
541f5c4a6d Flang implementation for COMPILER_VERSION and COMPILER_OPTIONS intrinsics
This revision implements the Fortran intrinsic procedures COMPILER_VERSION and COMPILER_OPTIONS from the iso_fortran_env module.
To be able to set the COMPILER_OPTIONS string according to the original compiler driver invocation, a string is passed to the frontend driver using the environment variable FLANG_COMPILER_OPTIONS_STRING, for lack of a better mechanism.

Fixes #59233

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D140524
2023-06-01 12:35:16 -04:00
Katherine Rasmussen
aa1a2ffdbf [flang] Add atomic_fetch_or to the list of intrinsics
Add the atomic subroutine, atomic_fetch_or, to the list of
intrinsic subroutines. Add new enumerators to deal with the rank
of the atom dummy argument, and the kind of atomic_int_kind. Use
check for a coindexed-object for the fourth dummy argument. Move
atomic_int_kind and atomic_logical_kind definitions from
iso_fortran_env module to the __fortran_builtins module to allow
for access to those values when analyzing `atomic_fetch_or`
calls in flang/lib/Evaluate/intrinsics.cpp.

Reviewed By: jeanPerier

Differential Revision: https://reviews.llvm.org/D133174
2022-09-29 09:29:27 -07:00
Peter Klausler
f329cf97f2 [flang] Change names of specific procedures of generic interfaces in intrinsic modules
Intrinsic procedures in intrinsic modules that have (or better, *are*) generic interfaces
must not have specific procedures with the same name according to the Fortran
standard (17.11.1); i.e., a user program is allowed to define a procedure
of the same name as one of these generic interfaces, even when the generic is
in scope.

Differential Revision: https://reviews.llvm.org/D131108
2022-08-09 08:51:59 -07:00
V Donaldson
aba0d3cd94 [flang] Intrinsic module file update
Use symbolic iostat values in iso_fortran_env.f90.
Add generic names to the interfaces in __fortran_ieee_exceptions.f90.
2022-07-13 10:27:03 -07:00
V Donaldson
949c39efb1 [flang] Update intrinsic module source files
The f18 standard defines several intrinsic modules containing definitions
and declarations for various constants, types, and procedures.  This PR adds
declarations for missing procedures in these modules.
2022-05-25 16:56:30 -07:00
Peter Klausler
a62b60167d [flang] Predefine unit 0 connected to stderr
This is a near-universal language extension; external unit 0
is preconnected to the standard error output.

Differential Revision: https://reviews.llvm.org/D114298
2021-11-22 09:02:39 -08:00
Peter Klausler
830c0b9023 [flang] Move runtime API headers to flang/include/flang/Runtime
Move the closure of the subset of flang/runtime/*.h header files that
are referenced by source files outside flang/runtime (apart from unit tests)
into a new directory (flang/include/flang/Runtime) so that relative
include paths into ../runtime need not be used.

flang/runtime/pgmath.h.inc is moved to flang/include/flang/Evaluate;
it's not used by the runtime.

Differential Revision: https://reviews.llvm.org/D109107
2021-09-03 11:08:34 -07:00
peter klausler
03f1c9fa85 [flang] Fix errors in ISO_FORTRAN_ENV module for REAL128
Some parameters of 128-bit IEEE floating-point numbers were
incorrect, leading to a failure to define REAL128 to 16.

Differential Revision: https://reviews.llvm.org/D95387
2021-01-25 13:41:32 -08:00
peter klausler
95696d563b [flang] Progress on Fortran I/O runtime
Use internal units for internal I/O state

Replace use of virtual functions

reference_wrapper

Internal formatted output to array descriptor

Delete dead code

Begin list-directed internal output

Refactorings and renamings for clarity

List-directed external I/O (character)

COMPLEX list-directed output

Control list items

First cut at unformatted I/O

More OPEN statement work; rename class to ExternalFileUnit

Complete OPEN (exc. for POSITION=), add CLOSE()

OPEN(POSITION=)

Flush buffers on crash and for terminal output; clean up

Documentation

Fix backquote in documentation

Fix typo in comment

Begin implementation of input

Refactor binary floating-point properties to a new header, simplify numeric output editing

Dodge spurious GCC 7.2 build warning

Address review comments

Original-commit: flang-compiler/f18@9c4bba11cf
Reviewed-on: https://github.com/flang-compiler/f18/pull/982
2020-02-13 10:31:26 -08:00
Gary Klimowicz
cea1040d51 [flang] Minor format change to LLVM license lines
Replace comment lines containing all dashes with the
proper ===-----....----=== markers.

Original-commit: flang-compiler/f18@a8936b0d41
Reviewed-on: https://github.com/flang-compiler/f18/pull/922
2020-01-10 12:12:03 -08:00
Tim Keith
96ce00bba2 [flang] Add .mod file dependencies
Make compilation of other predefined module files depend on
__fortran_builtins.mod. Currently only iso_c_binding.f90 and
iso_fortran_env.f90 depend on it but others could in the future.

Create the .f18.mod files by copying from the .mod files so that
we don't have to worry about dependencies for those.

Original-commit: flang-compiler/f18@8209ad3d32
Reviewed-on: https://github.com/flang-compiler/f18/pull/899
2019-12-31 14:08:12 -08:00
peter klausler
ec833a6bb7 [flang] Patch build problem
Original-commit: flang-compiler/f18@a668512100
Reviewed-on: https://github.com/flang-compiler/f18/pull/898
2019-12-31 09:19:08 -08:00
peter klausler
663db2741d [flang] C_F_POINTER
Emit INTRINSIC statements in module files

Argument checking utility

Complete error checking

Original-commit: flang-compiler/f18@9c6a88f048
Reviewed-on: https://github.com/flang-compiler/f18/pull/896
2019-12-31 08:34:53 -08:00
Gary Klimowicz
9e7548ab31 [flang] Flang relicensing changes for LLVM Apache 2.0 license
This changes the license information in many of the flang source files.
- Renamed LICENSE to LICENSE.txt.
- NVIDIA Copyright lines have been removed.
- Initial lines for files follow the LLVM coding convention (file name on the first line; Emacs mode information on the first line).
- License references have been replaced with the abridged LLVM text.
- License information was removed from the test files.
- No file header was placed on test files (these weren't in most LLVM test files).
- License information was added to documentation files where it was missing.

We did not add brief file summaries to the initial line.

See http://llvm.org/docs/DeveloperPolicy.html#new-llvm-project-license-framework
for a description of the new license.

See http://llvm.org/docs/CodingStandards.html#file-headers
for a description of the new LLVM standard file header.

Original-commit: flang-compiler/f18@add6cde724
Reviewed-on: https://github.com/flang-compiler/f18/pull/887
2019-12-23 10:26:16 -08:00
peter klausler
e46cd9ee18 [flang] Fold MERGE, use it in ISO_FORTRAN_ENV
Reduce use of intrinsic type KIND codes in ISO_FORTRAN_ENV

Use COUNT([x]) rather than MERGE(1,0,x)

Fix problems in array constructor expression analysis

Original-commit: flang-compiler/f18@79018f7126
Reviewed-on: https://github.com/flang-compiler/f18/pull/836
2019-11-22 14:16:48 -08:00
peter klausler
fc94aa6d32 [flang] Define runtime I/O library interface to be used by generated code.
Original-commit: flang-compiler/f18@82cb9b0c87
Reviewed-on: https://github.com/flang-compiler/f18/pull/802
2019-11-19 10:11:23 -08:00
Steve Scalpone
02a9cdb3fd [flang] Define iso_fortran_env error_unit.
Provisionally use a value of 0 to match PGI.

Original-commit: flang-compiler/f18@ec7f0a0968
Reviewed-on: https://github.com/flang-compiler/f18/pull/722
2019-09-09 12:57:10 -07:00
Tim Keith
050a921aaf [flang] Fix errors in tests and predefined modules
There were many places in tests and predefined modules that had
incorrect code that we weren't detecting until now.

Most of the problems were deferred-shape arrays that should have
been implied-shape. For example:
`real, parameter :: a(:) = [1.0, 2.0]`
should have `(*)` rather than `(:)`.

There were also a few places with deferred-shape arrays that were
not allocatable/pointer or explicit-shape ones that were.

Original-commit: flang-compiler/f18@0a959ce1d8
Reviewed-on: https://github.com/flang-compiler/f18/pull/630
2019-08-07 10:51:35 -07:00
peter klausler
f7c34914de [flang] Add LOGICAL8, &c.
Original-commit: flang-compiler/f18@fd8df8cd8f
Reviewed-on: https://github.com/flang-compiler/f18/pull/531
Tree-same-pre-rewrite: false
2019-06-28 09:16:44 -07:00
peter klausler
d8f72a3105 [flang] Placeholder for standard module iso_fortran_env
Original-commit: flang-compiler/f18@386ebb0490
Reviewed-on: https://github.com/flang-compiler/f18/pull/485
Tree-same-pre-rewrite: false
2019-06-06 13:42:33 -07:00