275 Commits

Author SHA1 Message Date
Eugene Epshteyn
008dc8b5bf
[flang-rt] Fix EXECUTE_COMMAND_LINE() on Windows (#184875)
Detect cmd.exe special status code 9009 that indicates "command not
found" condition. Crash the process if "command not found" detected when
CMDSTAT was not specified.
2026-03-05 18:17:57 -05:00
John Otken
22bf237e74
[flang-rt] Handle NAMELIST logical comments without preceding space (#183202)
If a comment appears immediately after a logical value in a NAMELIST
file, the flang runtime returns IostatGenericError. No error occurs when
a space preceeds the exclamation point. Add code to handle a comment
while parsing logical values.

Co-authored-by: John Otken john.otken@hpe.com
2026-03-05 11:14:33 +05:30
Eugene Epshteyn
82a9948ea4
[flang-rt] Fixes EXECUTE_COMMAND_LINE() status management and double buffering (#184285)
EXECUTE_COMMAND_LINE() without CMDSTAT initiated termination in runtime
if the command returned non-zero status code. For example,
EXECUTE_COMMAND_LINE('false') on Linux would cause "fatal Fortran
runtime error... : Command line execution failed with exit code: 1."
This is too strict: EXECUTE_COMMAND_LINE() successfully called 'false',
it's just 'false' happened to return non-zero status code. ifx and
gfortran don't initiate termination in such case. Changed
EXECUTE_COMMAND_LINE() implementation to behave in similar fashion.

Also during testing discovered that when the output of the program that
uses EXECUTE_COMMAND_LINE(... WAIT=.false.) is piped to a file, the
resulting file has duplicated output lines. This was because fork()
command also ends up duplicating parent's buffered output to the child.
Added flush of all units and C stdio before calling fork().
2026-03-04 22:03:21 -05:00
Joseph Huber
0cbba3ed5f
[flang-rt] Fix incorrect condition for removing backtrace (#184610) 2026-03-04 07:50:48 -06:00
Joseph Huber
dc44bcafe0
[flang-rt] Fix NVPTX builds erroneously using backtrace support (#184415)
Summary:
This is caused  by the CMake hacks I had to do to worm around NVIDIA's
proprietary binaries.
2026-03-03 14:38:53 -06:00
Peter Klausler
d723d14e4c
[flang][runtime] Emit "Infinity" rather than "Inf" when required (#183359)
The ISO Fortran standard requires that numeric output editing produce
the full word "Infinity", rather than my current "Inf", when the output
field is wide enough to hold it. Comply.
2026-03-02 09:45:12 -08:00
kwyatt-ext
ca0e7d31d0
[flang] [flang-rt] Addition of the Fortran 2023 TOKENIZE intrinsic. (#181030)
This implements the TOKENIZE intrinsic per the Fortran 2023 Standard.

TOKENIZE is a more complicated addition to the flang intrinsics, as it
is the first subroutine that has multiple unique footprints. Intrinsic
functions have already addressed this challenge, however subroutines and
functions are processed slightly differently and the function code was
not a good 1:1 solution for the subroutines. To solve this the function
code was used as an example to create error buffering within the
intrinsics Process and select the most appropriate error message for a
given subroutine footprint.

A simple FIR compile test was added to show the proper compilation of
each case. A thorough negative path test has also been added, ensuring
that all possible errors are reported as expected.

Testing prior to commit:

= check-flang ==========================================
```
Testing Time: 139.51s

Total Discovered Tests: 4153
  Unsupported      :   77 (1.85%)
  Passed           : 4065 (97.88%)
  Expectedly Failed:   11 (0.26%)


FLANG Container Test completed 2 minutes (160 s).

Total Time: 2 minutes (160 s)
Completed : Wed Feb 11 04:05:50 PM CST 2026
```

= check-flang-rt ==========================================
```
Testing Time: 1.55s

Total Discovered Tests: 258
  Passed: 258 (100.00%)


FLANG Container Test completed 0 minutes (55 s).

Total Time: 0 minutes (56 s)
Completed : Wed Feb 11 04:08:32 PM CST 2026
```

= llvm-test-suite ==========================================
```
Testing Time: 1886.64s

Total Discovered Tests: 6926
  Passed: 6926 (100.00%)


CCE SLES Container debug compile completed 31 minutes (1895 s).
CCE SLES Container debug install completed in 0 minutes (0 s).

Total Time: 31 minutes (1895 s)
Completed : Wed Feb 11 05:46:52 PM CST 2026
```

Additionally, (FYI) an executable test has been written and will be
added to the llvm-test-suite under a separate PR.

---------

Co-authored-by: Kevin Wyatt <kwyatt@hpe.com>
2026-02-27 18:43:18 +00:00
Joseph Huber
c49460bae7
[flang-rt] Enable more runtime functions for the GPU target (#183649)
Summary:
This enables primarily `stop.cpp` and `descriptor.cpp`. Requires a
little bit of wrangling to get it to compile. Unlike the CUDA build,
this build uses an in-tree libc++ configured for the GPU. This is
configured without thread support, environment, or filesystem, and it is
not POSIX at all. So, no mutexes, pthreads, or get/setenv.

I tested stop, but i don't know if it's actually legal to exit from
OpenMP offloading.
2026-02-27 12:27:39 -06:00
Valentin Clement (バレンタイン クレメン)
26b4c25b8b
[flang][cuda] Add support for cudaStreamDestroy (#183648)
Add specific lowering and entry point for cudaStreamDestroy. Since we
keep associated stream for some allocation, we need to reset it when the
stream is destroy so we don't use it anymore.
2026-02-27 00:24:29 +00:00
Slava Zakharin
a7723994a9
[flang-rt] Get rid of cyclic call chain in ChildIo. (#183369)
This is a follow up on #182635

It was suggested to place `static_assert(std::is_trivially_destructible_c<A>)`
for the `OwningPtr` class. This cannot be done, because there are
non-trivially destructible types used with `OwnerPtr` (e.g. lots of types
that inherit from `IoErrorHandler`, which is not trivially destructible).

This patch brings back the desctructor call into `OwningPtr::delete_ptr`
just to be on the safe side (though, I do not think we had any memory
leaks even without the destructor call), and removes the cyclic
dependency for the `~ChildIo()` caused by `previous_` member.
2026-02-26 08:55:18 -08:00
Peter Klausler
7acc02ff7a
[flang][runtime] Catch EOSHIFT ARRAY/BOUNDARY type mismatch (#183168)
The ARRAY= and optional BOUNDARY= arguments to EOSHIFT must have the
same dynamic type. Add a runtime check.
2026-02-26 07:08:56 -08:00
Peter Klausler
67eb750225
[flang][runtime] Catch asynchronous parent or child I/O (#183161)
ASYNCHRONOUS="YES" is not permitted for either a parent or child data
transfer statement in ISO Fortran (F'2023 12.6.4.8.3 p19). Not that it
matters much -- we don't support true asynchronous I/O anyway -- but
someday we might, and in the meantime it's nice to be able to pass tests
that check conformance.
2026-02-26 07:07:49 -08:00
Peter Klausler
a10e77b1a5
[flang][runtime] Conditionally fail empty ALLOCATE (#182918)
Add an environment variable (FORT_NO_EMPTY_ALLOCATION) that, when set to
1, changes the behavior of an ALLOCATE statement so that it will fail on
an empty allocation rather than its default behavior of allocating one
byte.
2026-02-26 06:55:59 -08:00
Slava Zakharin
553ce3a115
[flang-rt] Temporarily disable destructor call in OwningPtr::delete_ptr. (#182635)
This is causing failures in CUF testing, because the device compiler
cannot identify the static stack size for kernels.
2026-02-20 19:49:54 -08:00
Valentin Clement (バレンタイン クレメン)
9f6ad7654b
[flang][cuda] Use default stream when calling cudaStreamSynchronize without arg (#182623) 2026-02-21 00:05:50 +00:00
Joseph Huber
70b5a1d050
[flang-rt] Add support for formatted I/O on the GPU (#182580)
Summary:
Expands on the previous support to enable formatted output, characters,
and checking basic iostat. We intentionally do not handle cases where
the descriptor is non-null as this is a non-trivial class that cannot
easily be shepherded across the wire.
2026-02-20 14:43:06 -06:00
Joseph Huber
f343cc0eff [flang-rt] Add missing libc dependency to object library 2026-02-20 10:45:38 -06:00
Tom Eccles
f3f0b621f7
[flang-rt] Add sysroot to test (#182508)
This fixes the test on MacOS. Without this change the SDK sysroot is not
set and so the library path is incorrect and the 'System' library cannot
be found.

Test with https://github.com/llvm/llvm-project/pull/182501 so that the
sysroot variable is correctly set.

Assisted-by: Codex
2026-02-20 16:18:44 +00:00
Joseph Huber
21b3461440
[flang-rt] Implement basic support for I/O from OpenMP GPU Offloading (#181039)
Summary:
This PR provides the minimal support for Fortran I/O coming from a GPU
in OpenMP offloading. We use the same support the `libc` uses for its
printing through the RPC server. The helper functions `rpc::dispatch`
and `rpc::invoke` help make this mostly automatic.

Becaus Fortran I/O is not reentrant, the vast majority of complexity
comes from needing to stitch together calls from the GPU until they can
be executed all at once. This is needed not only because of the
limitations of recursive I/O, but without this the output would all be
interleaved because of the GPU's lock-step execution.

As such, the return values from the intermediate functions are
meaningless, all returning true. The final value is correct however. For
cookies we create a context pointer on the server to chain these
together.

Works on both my AMD and NVIDIA GPUs.
```fortran
program hello_gpu
  implicit none

  !$omp target teams num_teams(1)
  !$omp parallel num_threads(2)
    ! Print strings
    print *, "Hello from GPU"
  !$omp end parallel
  !$omp end target teams

end program hello_gpu
```
```console
> flang hello.f90 -O2 -fopenmp --offload-arch=gfx1030 
> ./a.out 
 Hello from GPU
 Hello from GPU
> flang hello.f90 -O2 -fopenmp --offload-arch=sm_89  
> ./a.out 
 Hello from GPU
 Hello from GPU
```
2026-02-20 07:56:59 -06:00
Michael Kruse
398bd9543b
[Flang-RT][unittests] Fix buffer over-read (#182176)
The unittests `Reductions.InfSums` defines a test array descriptor with
shape 2x3 (i.e. 6 elements), but only provides values for 2 elements.
The result is access of likely uninitialized memory when accessing the
additional 4 elements. In most cases the additional values get gobbled
up by the infinity, but if it happens to be NaN or the negated infinity,
the result becomes NaN and fails the test.

Fix by reducing the shabe of the test array to 2. Fixes the flakyness of
the test of the flang-x86_64-windows buildbot.
2026-02-20 09:31:39 +01:00
Valentin Clement (バレンタイン クレメン)
7772a45b1a
[flang][cuda] Add entry points for cudastreamsynchronize (#181932) 2026-02-18 15:54:54 -08:00
Valentin Clement (バレンタイン クレメン)
786b3b4741
[flang][cuda][NFC] Move set/get default stream to its own file (#181927) 2026-02-17 14:43:38 -08:00
Valentin Clement (バレンタイン クレメン)
7ce0c53291
[flang][cuda] Fix return value for CUFSetDefaultStream (#181884)
The interface return an integer value but the entry point and lowering
were missing it.
2026-02-17 13:48:29 -08:00
Valentin Clement (バレンタイン クレメン)
3c32747a7c
[flang][cuda] Lower set/get default stream (#181775) 2026-02-17 09:32:04 -08:00
Valentin Clement (バレンタイン クレメン)
1b2196bd82
[flang][cuda] Add entry point for set/get default stream (#181440) 2026-02-13 17:59:06 -08:00
Valentin Clement (バレンタイン クレメン)
c4170461d7
[flang][cuda] Lower set/get default stream for arrays (#181432) 2026-02-13 23:44:38 +00:00
Valentin Clement (バレンタイン クレメン)
19de5dd722
[flang][cuda] Add CUFSetAssociatedStream entry point (#181313) 2026-02-13 19:15:44 +00:00
Caroline Newcombe
d3a70f3b2c
[flang] Implement 'F_C_STRING' library function (Fortran 2023) (#174474)
Implement `F_C_STRING` to convert a Fortran string to a C
null-terminated string. Documented in F2023 Standard: 18.2.3.9
`F_C_STRING (STRING [, ASIS])`.
2026-02-10 13:30:31 -05:00
Peter Klausler
076da86cd3
[flang][runtime] OPEN(STATUS='NEW') should fail on extant file (#180605)
An OPEN(..., STATUS='NEW') statement should fail when the named file
exists, and also should not delete it when the failure is a recoverable
error.
2026-02-10 09:22:05 -08:00
Peter Klausler
7e1fff4d50
[flang][runtime] Improve handling of short DATE_AND_TIME(VALUES=) (#180557)
When the actual argument associated with the VALUES= dummy argument of
the intrinsic subroutine DATE_AND_TIME has fewer than eight elements, we
crash with an internal error in the runtime.

With this patch, the compiler now checks the size of the vector at
compilation time, when it is known, and gracefully copes with a short
vector at execution time otherwise, without crashing.
2026-02-10 09:21:31 -08:00
Robert Imschweiler
8ee6c63f24
[offload][flang-rt] Fix NVPTX runtime build (#180530)
During the check for availability of `strerror_r`, the host include file is used. This doesn't matter for AMDGPU since it actually performs the link step during `check_cxx_symbol_exists`. But for NVPTX, due to `-c`, it doesn't link and then incorrectly assumes that the symbol exists.
For now, removing `io-error.cpp` from the list of GPU sources is the most sensible option since it's unused.
2026-02-09 22:00:06 +01:00
Peter Klausler
621fe6783f
[flang] Better "out of memory" error for failure to allocate a unit (#179291)
When the I/O runtime fails to allocate storage for an I/O unit, the
error message cites a source location in the runtime library, not the
user program. Thread instances of Terminator through to the code that
attempts the allocation so that the failure has a source position in the
user's program.
2026-02-06 09:28:15 -08:00
Mirko Brkušanin
20b5849e17
[AMDGPU] Define new target gfx1170 (#180185) 2026-02-06 14:38:50 +01:00
Michael Kruse
c15853ec3a
[OpenMP] Remove LLVM_ENABLE_PROJECTS=openmp build mode (#176950)
Reapply #152189 and #174963 which were reverted because it broke
publish-sphinx-docs and publish-doxygen-docs.

The build mode has been deprecated in #136314 and was supposed to be
removed in the LLVM 21 release (#136314).

OpenMP currently supports 4 build modes:

 * `cmake <llvm-project>/llvm -DLLVM_ENABLE_PROJECTS=openmp`
 * `cmake <llvm-project>/llvm -DLLVM_ENABLE_RUNTIMES=openmp` (bootstrapping build)
 * `cmake <llvm-project>/openmp` (standalone build)
 * `cmake <llvm-project>/runtimes -DLLVM_ENABLE_RUNTIMES=openmp` (runtimes default/standalone build)

Each build mode increased the maintanance overhead since all build modes
must continue working and user confusion when there do not (see #151117,
#174126, #154117, ...). Let's finally remove it.
2026-01-30 21:05:29 +01:00
Jean-Didier PAILLEUX
6f8cea3f90
[flang][MIF] Adding Stop and ErrorStop PRIF call procedures (#166787)
This PR proposes to add `Stop` and `ErrorStop` PRIF call procedures to the MIF
dialect. If the `-fcoarray` flag is passed, then all calls to `STOP` and `ERROR
STOP` will use those of PRIF in flang-rt. Thes procedure has been registered 
during the initialization (mif::InitOp).

---------

Co-authored-by: Dan Bonachea <dobonachea@lbl.gov>
2026-01-27 16:54:11 +01:00
Michael Kruse
a871f87830
[flang-rt] Use std::numeric_limits::infinity (#178166)
#175373 introduces a divide-by-zero to create an infinity value, which
is undefined behavior in C++ (C++20 [expr.mul] §4), even when done at
compile-time. This cases flaky test fails with the flang-x86_64-windows
buildbot. Visual Studio 2026 refuses to compile it with error C2124.

Use `std::numeric_limits<float>::infinity()` instead.
2026-01-27 16:31:09 +01:00
Valentin Clement (バレンタイン クレメン)
3d3dd559a0
[flang][cuda] Add support for derived-type component with managed/unified attributes (#177409)
Derived-type components that have the `ALLOCATABLE` or `POINTER`
attribute as well as the CUDA `MANAGED` or `UNIFIED` attribute need to
have a specific allocator index set in the descriptor so the allocation
is done correctly. Without this, the allocation is done in host memory
and will trigger illegal read or write if the component is used on the
device. The correct allocator index was set some time ago for the
`DEVICE` attribute but the `MANAGED` and `UNIFIED` attribute need the
same mechanism.

Since the `Component::Genre` has quite some room I opted to add specific
genre for allocatable and pointer with both managed or unified
attribute.
@klausler Let me know if you would prefer another solution. I was
thinking about a separate field but I wanted to avoid wasting some
bytes.
2026-01-22 13:08:48 -08:00
Michael Kruse
8acf454ed1 Revert "[OpenMP] Remove LLVM_ENABLE_PROJECTS=openmp build mode (#174963)"
This reverts commit f7b5b670c1cf0fe54e59aa0d1f1a11ee66e442ab.

It had broken the publish-doxygen-docs buildbot
2026-01-20 13:00:54 +01:00
Michael Kruse
f7b5b670c1
[OpenMP] Remove LLVM_ENABLE_PROJECTS=openmp build mode (#174963)
Reapply #152189 which was reverted because it broke publish-sphinx-docs.

The build mode has been deprecated in #136314. According to the
deprecation message, it was supposed to be removed in the LLVM 21
release. Each build mode increased the maintanance overhead when
failing, such as in #151117.
2026-01-20 11:55:43 +01:00
Tom Eccles
e03049ec0a
[flang-rt] Fix system_clock scaling on MacOS (#176753)
The less accurate clock was being adjusted for twice: once in
`GetSystemClockCountRate` and again in `ConvertTimevalToCount`.

Also adding missing `static` specifiers I noticed whilst reading the
file. I don't know of a way of meaningfully testing this in the
repository, but the code in the ticket now produces the correct result.

Fixes #176505
2026-01-19 17:54:15 +00:00
Michael Kruse
91b3fe0315
[Flang-RT][CMake] Remove redundant code. NFC. (#175917)
Two methods to extract the same data. Remove the one that is overwritten
later anyway.
2026-01-14 11:07:25 +00:00
Austin Jiang
e6cdfb75ac
Fix typos and spelling errors across codebase (#156270)
Corrected various spelling mistakes such as 'occurred', 'receiver',
'initialized', 'length', and others in comments, variable names,
function names, and documentation throughout the project. These
changes improve code readability and maintain consistency in naming
and documentation.

Co-authored-by: Louis Dionne <ldionne.2@gmail.com>
2026-01-13 11:52:46 -05:00
Joseph Huber
793d9c91f2
[flang-rt] Disable testing support for the GPU cross build (#175583)
Summary:
We're starting to provide the GPU version of the Fortran runtime with
the GPU cross-build semantics. This does not support tests right now but
will attempt to build the unit tests and fail to find gtest for the GPU.
Disable this for now so it can build.
2026-01-13 07:28:42 -06:00
Joseph Huber
0055129eb5
[flang-rt] Fix unused flag warning when compiling for the GPU (#175643)
Summary:
Because we link the `cxx` target directly we do not need to use this
flag, that's also why we pass `-nostdinc++` which makes this an unused
command line flag, hence the warning.
2026-01-13 07:17:54 -06:00
Peter Klausler
a8ba9c4fa2
[flang] Fix spurious NaN result from infinite Kahan summation (#175373)
There are six instances of Kahan's extended precision summation
algorithm in flang/flang-rt, and they share a bug: the calculation of
the correction value produces a Nan due to the subtraction Inf-Inf after
the accumulation saturates to Inf. This leads to the surprising Nan
result from SUM([Inf, 0.]).

This bug doesn't affect run-time calculation of SUM when optimization is
enabled -- lowering emits an open-coded SUM that lacks Kahan summation
-- but it does affect compilation-time folding and -O0 runtime results.

Fix the one instance of Kahan summation in the runtime, and consolidate
the other five instances in Evaluate into one new member function, also
corrected.

Fixes https://github.com/llvm/llvm-project/issues/89528.
2026-01-12 15:40:44 -08:00
liao jun
8a922e8151
[flang-rt][build] Disable build-time warning of '-Wshift-count-negative' from g++ compiler and remove unsupported floating-point data. (#174915)
When building the flang-rt project with the g++ compiler on Linux-X86_64
machine, the compiler gives the following warning:

```
llvm-project/flang-rt/lib/runtime/extensions.cpp:455:26: warning: left shift count is negative [-Wshift-count-negative]
   455 |     mask = ~(unsigned)0u << ((8 - digits) * 4 + 1);
       |            ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~

```

All the discussion records see:
https://github.com/llvm/llvm-project/pull/173955

Co-authored-by: liao jun <liaojun@ultrarisc.com>
2026-01-09 08:19:40 -05:00
Michael Kruse
9ac2d0a9b9 Revert "[OpenMP] Remove LLVM_ENABLE_PROJECTS=openmp build mode (#152189)"
This reverts commit 20d0ec849804218d75647aeafbe23f8a02a83b56.

The publish-sphinx-docs buildbot still uses LLVM_ENABLE_PROJECTS=openmp.
2026-01-08 13:10:46 +01:00
Michael Kruse
20d0ec8498
[OpenMP] Remove LLVM_ENABLE_PROJECTS=openmp build mode (#152189)
The build mode has been deprecated in #136314. According to the
deprecation message, it was supposed to be removed in the LLVM 21
release. Each build mode increased the maintanance overhead when
failing, such as in #151117.

Let's remove it in LLVM 22.
2026-01-08 12:01:07 +00:00
Michael Kruse
75d8654c67
[Flang-RT] Add test dependency (#174427)
When building with `FLANG_RUNTIME_F128_MATH_LIB=libquadmath`, the tests
```
  flang-rt :: Driver/ctofortran.f90
  flang-rt :: Driver/exec.f90
```
also depend on `libflang_rt.quadmath.a`. Add a dependency to ensure it
is built with `ninja check-flang-rt`.
2026-01-05 16:07:17 +00:00
Valentin Clement (バレンタイン クレメン)
a0dfe45036
Reland "[flang][cuda] Add support for derived-type initialization on device #172568" (#174107)
The build bots failure have been address in #174048
2025-12-31 11:26:17 -08:00