summaryrefslogtreecommitdiff
path: root/flang-rt
AgeCommit message (Collapse)Author
2025-11-20[flang-rt] Fix TypeCategory for quad-precision COMPLEX (#168090)Carlos Seo
Modify the TypeCategory for quad-precision COMPLEX to CFI_type_float128_Complex so it matches the TypeCode returned by SELECT TYPE lowering. Fixes #134565
2025-11-19[flang][runtime] Control stream truncation via runtime environment (#168415)Peter Klausler
The ISO Fortran standards don't say whether a WRITE to a formatted stream unit should truncate the unit if there has been any repositioning (via POS= control list specifiers) to an earlier point in the stream. But units with sequential records do truncate on writes after BACKSPACE and REWIND statements, and many compilers (including this one) truncate stream units too. Since some compilers don't truncate streams, this patch adds an environment variable FORT_TRUNCATE_STREAM that can be set to 0 to disable truncation and ease porting to flang-new of codes that depend on that behavior. Fixes https://github.com/llvm/llvm-project/issues/167569.
2025-11-14[flang][runtime] Advance output record in specific case (#167786)Peter Klausler
When a formatted WRITE takes place in a defined output subroutine called from a context in which record advancement is allowed, such as NAMELIST, the char-string-edit-descs in the format can trigger record advancement. Also clean up confusing messiness lingering from the separation of iostat.h two headers in flang/.../Runtime. iostat.h didn't need to be put into flang/.../Runtime since it's included only by flang-rt, and iostat-consts.h doesn't need one of its includes. Fixes https://github.com/llvm/llvm-project/issues/167757.
2025-11-12[runtimes][GTest] LLVM-independent unittests (#164794)Michael Kruse
The LLVM-customized GTest has a dependency on LLVM to support `llvm::raw_ostream` and hence has to link to LLVMSupport. The runtimes use the LLVMSupport from the bootstrapping LLVM build. The problem is that the boostrapping compiler and the runtimes target can diverge in their ABI, even in the runtimes default build. For instance, Clang is built using gcc which uses libstdc++, but the runtimes is built by Clang which can be configured to use libcxx by default. Altough it does not use gcc, this issue has caused [flang-aarch64-libcxx](https://lab.llvm.org/buildbot/#/builders/89)) to break, and is still (again?) broken. This patch makes the runtimes' GTest independent from LLVMSupport so we do not link any runtimes component with LLVM components. Runtime projects that use GTest unittests: * flang-rt * libc * compiler-rt: Adds `gtest-all.cpp` with [GTEST_NO_LLVM_SUPPORT=1](https://github.com/llvm/llvm-project/blob/f801b6f67ea896d6e4d2de38bce9a79689ceb254/compiler-rt/CMakeLists.txt#L723) to each unittest without using `llvm_gtest`. Not touched by this PR. * openmp: Handled by #159416. Not touched for now by this PR to avoid conflict. The current state of this PR tries to reuse https://github.com/llvm/llvm-project/blob/main/third-party/unittest/CMakeLists.txt as much as possible, altough personally I would prefer to make it use "modern CMake" style. third-party/unittest/CMakeLists.txt will detect whether it is used in runtimes build and adjaust accordingly. It creates a different target for LLVM (`llvm_gtest`, NFCI) and another one for the runtimes (`runtimes_gtest`). It is not possible to reuse `llvm_gtest` for both since `llvm_gtest` is imported using `find_package(LLVM)` if configured using LLVM_INSTALL_GTEST. An alias `default_gtest` is used to select between the two. `default_gtest` could also be used for openmp which also supports standalone and [LLVM_ENABLE_PROJECTS](https://github.com/llvm/llvm-project/pull/152189) build mode.
2025-11-11[flang-rt] Use dlsym to access char** environ on FreeBSD (#158477)Gleb Popov
2025-11-07[flang][runtime] Allow some list-directed child output to advance (#166847)Peter Klausler
List-directed child input is allowed to advance to new records in some circumstances, and list-directed output should be as well so that e.g. NAMELIST output via a defined WRITE(FORMATTED) generic doesn't get truncated by FORT_FMT_RECL. Fixes https://github.com/llvm/llvm-project/issues/166804.
2025-10-29[flang][rt] Add install target for header files (#165610)Valentin Clement (バレンタイン クレメン)
2025-10-24[flang][runtime] Tweak GetNextNonBlank() performance (#164521)Peter Klausler
When skipping blanks during input from an ASCII file, scan the buffered characters directly when possible rather than using the more general path. This adds complexity, but shaves a few percent off the runtime of a code that reads in millions of list-directed integers (best time over multiple runs goes from 17.56 to 16.84 sec).
2025-10-24[flang][cuda] Remove error check from allocation and free call (#165022)Valentin Clement (バレンタイン クレメン)
As in https://github.com/llvm/llvm-project/pull/164463, do not do error checking in the runtime itself but let error go through as user might want to catch them for error recovery.
2025-10-21[flang][cuda][rt] Do not check error on kernel launch (#164463)Valentin Clement (バレンタイン クレメン)
Align behavior with other CUDA compiler.
2025-10-21Revert "[flang][cuda][rt] Canonicalize block size values" (#164460)Valentin Clement (バレンタイン クレメン)
Reverts llvm/llvm-project#164321 Align behavior with other CUDA Compiler
2025-10-20[flang][cuda][rt] Canonicalize block size values (#164321)Valentin Clement (バレンタイン クレメン)
Set block size x and y to 1024 if the given value is higher. Set block z to 64 if the given value is higher.
2025-10-16[Flang-RT] Fix GCC 15.1 Fortran Runtime libstdc++ Undefined Symbols (#157385)Patrick Simmons
Define the _GLIBCXX_THROW_OR_ABORT macro to not use its _EXC argument. _EXC may contain an expression constructing an std::exception object which is non-inline and therefore require a link dependency on the libstdc++ runtime. In -fno-exceptions builds it is typically optimized away when appearing in unreachable code, but is still present when compiling with -O0 when compiling with Clang. --------- Co-authored-by: Michael Kruse <github@meinersbur.de>
2025-10-08[flang][NFC] Revise crash msg for GeneralCharFunc (#162292)Connector Switch
2025-10-03[flang][rt] Add noinline attributes for CUDA compile path for successful ↵modiking
compilation (#161760) NVCC does more aggressive inlining than Clang/GCC causing the exported functions in extrema.cpp and findloc.cpp to become extremely large from function specializations leading to compilation timeouts. Marking the 2 functions in this change as noinline for NVCC alleviates this problem as it removes the worst of the cross-matrix argument specializations. Also remove the workaround in https://github.com/llvm/llvm-project/pull/156542 that opted out findloc.cpp from the CUDA flang-rt build Testing: ninja flang-rt builds in ~30 minutes, these 2 files build in ~3 minutes
2025-10-03[flang] use specialized scan/verify version for char (#161767)Connector Switch
The specialized version has a time complexity of `O(n)`.
2025-10-01[flang][runtime] fix intrinsics case of extends_type_of (#161466)Andre Kuhlenschmidt
Fixes https://github.com/llvm/llvm-project/issues/155459 by making sure the cases are considered in the right order. Previously intrinsics types where overriding the pointer cases which have higher precedence in the specification. Also passes the following [tests](https://github.com/llvm/llvm-test-suite/pull/287).
2025-09-30[flang][runtime] Expand IOTYPE and V_LIST (#160744)Peter Klausler
The IOTYPE and V_LIST dummy arguments to a defined formatted I/O subroutine are extracted from a DT edit descriptor in a FORMAT. They are currently stored in the DataEdit structure, and their maximum sizes are rather small since DataEdits are sometimes returned or passed by value. This patch moves their storage into the FormattedIoStatementState structure and enlarges them a bit. Fixes https://github.com/llvm/llvm-project/issues/154954.
2025-09-30[flang][runtime] Let more list-directed child input advance (#160590)Peter Klausler
Whether list-directed child READ statements should be allowed to advance to further records is neither explicit in the standard nor consistent in existing Fortran implementations. We allow child namelist READ statements to advance, but not other list- directed child input. This patch refines our interpretation of this case. Child namelist READ statements continue to be able to advance; in addition, non-namelist child READ statements can now advance if their parent READ statement is a list-directed input statement at the top level, or a child that could. But non-namelist list-directed child input taking place in a context with explicit format control won't advance to following records, so that the format-controlled parent READ statement can retain control over record advancement. Also corrects two cases of record repositioning in numeric input editing, which were failing under child input because they weren't allowing for left tab limits. Fixes https://github.com/llvm/llvm-project/issues/160351.
2025-09-26[flang][cuda] Handle zero sized allocation correctly (#160929)Valentin Clement (バレンタイン クレメン)
Like on the host allocate 1 byte when zero size is requested.
2025-09-26[flang-rt] Set _POSIX_C_SOURCE on Darwin (#160130)Leandro Lupori
Clang on Darwin enables non-POSIX extensions by default. This causes some macros to leak, such as HUGE from <math.h>, which causes some conflicts with Flang symbols (but not with Flang-RT, for now). It also causes some Flang-RT extensions to be disabled, such as FDATE, that checks for _POSIX_C_SOURCE. Setting _POSIX_C_SOURCE avoids these issues. This is already being done in Flang, but it was not ported to Flang-RT. This also fixes check-flang-rt on Darwin, as NoArgv.FdateNotSupported is broken since the flang runtime was moved to flang-rt. Fixes #82036
2025-09-23[flang][runtime] Use dumber but faster check for list-directed repeti… ↵Peter Klausler
(#159867) …tion When scanning list-directed input for nulls and repetition counts, the current library depends on having each record be prescanned for the presence of asterisk characters. It turns out that the overhead of calling memchr(...,'*',...) on each record doesn't pay off, especially on systems without SIMD-vectorized memchr implementations -- even on those, it's faster (about 10%) to just scan ahead for asterisks when decimal digits are encountered. Only when an asterisk is present, which is not common, should we then bother to convert the digits to their integer value.
2025-09-22Use CreateProcessW explicitly to improve compatibility (#160096)Yuriy Chernyshov
We compile our monorepo with `/D_MBCS` and flang-rt compilation breaks as it explicitly uses `wchar_t` (i. e. not TCHAR). Use STARTUPINFOW / CreateProcessW method explicitly to make the code work disregarding global settings.
2025-09-19[LLVM] Simplify GPU runtimes flag handling (#159802)Joseph Huber
Summary: The AMDGPU hack can be removed, and we no longer need to skip 90% of the `HandleLLVMOptions` if we work around NVPTX earlier. Simplifies the interface by removing duplicated logic and keeps the GPU targets from being weirdly divergent on some flags.
2025-09-19[flang] Implement FNUM() (#159433)Peter Klausler
The GNU Fortran library function FNUM(u) returns the UNIX file descriptor that corresponds to an open Fortran unit number, if any; otherwise -1. This implementation is a library extension only, not an intrinsic.
2025-09-17[Flang][runtime] Fix RENAME intrinsic, remove trailing blanks (#159123)Michael Klemm
The RENAME intrinsic did not correctly remove trailing spaces from filenames. This PR introduces code to remove trailing blanks as documented by GFortran. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-09-17[flang][runtime] Fix bug with NAMELIST in child input (#159173)Peter Klausler
Don't let "hitSlash_" flag in child input propagate back to the parent input statement's state when the child input was NAMELIST and the NAMELIST input has properly consumed the terminal '/' character. (It can get set if NAMELIST item input ran into it.) The current failure to reset that flag is causing list-directed parent input to stop early. Fixes https://github.com/llvm/llvm-project/issues/159127.
2025-09-17[flang][runtime] Block bad left tabbing in child I/O (#158758)Peter Klausler
Child I/O subroutines are not supposed to use T or TL control edit descriptors in formats to move the position in the current record to a point before where it stood at the time of their calls (F'2023 12.6.4.8.3 paragraph 18), but we should also guard against attempts to do so, using the same means used to prevent such attempts in non-advancing I/O. Fixes https://github.com/llvm/llvm-project/issues/158723.
2025-09-17[flang][runtime] Disable namelist storage sequence input when defined (#158708)Peter Klausler
The runtime supports a near-universal extension to namelist input that allows reading a sequence of values into a storage sequence beginning at an array element, e.g. &NML A(2)=1. 2. 3. / . Disable this extension when the type of the array has a defined formatted READ subroutine defined. That defined input procedure may itself not be using list-directed input, and might not notice a following slash or new input item name as such. Fixes https://github.com/llvm/llvm-project/issues/158496.
2025-09-15[flang] Add header includes to make headers compile standalone. (#158215)Adrian Kuegel
When compiling headers standalone, we need additional header includes.
2025-09-14[flang] Implement DSECNDS intrinsic (PGI extension) (#157573)Šárka Holendová
Add support for DSECNDS, the double-precision variant of SECNDS. The implementation mirrors SECNDS, reusing the shared `SecndsImpl<T>` runtime template. Includes: - Registration in intrinsics table - Lowering handler and runtime call wiring - Hook into shared SecndsImpl in extensions.cpp - Documentation in Intrinsics.md - Regression test dsecnds.f90 CC @eugeneepshteyn @klausler --------- Co-authored-by: Eugene Epshteyn <eepshteyn@nvidia.com>
2025-09-11[flang-rt] Use -Wp to undefine macros (#156034)Nikita Popov
If the macro was previously defined with `-Wp,-D` then a later `-U` is *not* going to take effect, the `-Wp` flag takes precedence. Instead use `-Wp,-U`. This works regardless of whether the original definition was provided via `-D` or `-Wp,-D`. Also make sure these flags only get passed to the C++ compiler -- they are only relevant there, and flang does not support `-Wp`.
2025-09-10[flang][runtime] Preserve some list-directed input state in child (#157571)Peter Klausler
Child list-directed input needs to inherit and return the state used to process trailing separators (eatComma_) and terminal '/' (hitSlash_) from any parent list-directed input statement. Fixes https://github.com/llvm/llvm-project/issues/157509 and https://github.com/llvm/llvm-project/issues/154971.
2025-09-09[flang][cuda] Remove set_allocator_idx operation (#157747)Valentin Clement (バレンタイン クレメン)
The allocator index is set from the component genre #157731 . There is no more need of an operation to set it at a later point.
2025-09-09[flang] Add special genre for allocatable and pointer device component (#157731)Valentin Clement (バレンタイン クレメン)
Allocatable and pointer device components need a different allocator index to be set in their descriptor when it is establish. This PR adds two genre for the components `AllocatableDevice` and `PointerDevice` so the correct allocator index can be set accordingly.
2025-09-02[flang][rt] Remove findloc.cpp from supported_sources fro CUDA build (#156542)Valentin Clement (バレンタイン クレメン)
findloc.cpp is causing memory exhaustion with higher compute capabilities. Also it is a very expensive file to build. Remove it from the supported_sources for CUDA build until we can lower its memory footprint.
2025-08-29[flang] Fix a warningKazu Hirata
This patch fixes: flang-rt/lib/runtime/descriptor.cpp:30:19: error: first argument in call to 'memcpy' is a pointer to non-trivially copyable type 'Fortran::runtime::Descriptor' [-Werror,-Wnontrivial-memcall]
2025-08-29[Flang][OpenMP][Runtime] Minor Flang runtime for OpenMP AMDGPU modifications ↵agozillon
(#152631) We have some modifications downstream to compile the flang runtime for amdgpu using clang OpenMP, some more hacky than others to workaround (hopefully temporary) compiler issues. The additions here are the non-hacky alterations. Main changes: * Create freestanding versions of memcpy, strlen and memmove, and replace std:: references with these so that we can default to std:: when it's available, or our own Flang implementation when it's not. * Wrap more bits and pieces of the library in declare target wrappers (RT_* macros). * Fix some warnings that'll pose issues with werror on, in this case having the namespace infront of variables passed to templates. Another minor issues that'll likely still pop up depending on the program you're linking with is that abort will be undefined, it is perhaps possible to solve it with a freestanding implementation as with memcpy etc. but we end up with multiple definitions in this case. An alternative is to create an empty extern "c" version (which can be empty or forwrd on to the builtin). Co-author: Dan Palermo Dan.Palermo@amd.com
2025-08-29[flang-rt] Enable lit internal shell by default (#156095)Aiden Grossman
This patch enables the lit internal shell by default for testing flang-rt. The lit internal shell is able to run tests a bit faster as it avoids having to fork bash for every run line and also produces nicer debug information on failures. This is part of #102704.
2025-08-29[flang-rt] Set supported_sources when ↵Valentin Clement (バレンタイン クレメン)
FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT=CUDA (#156078) When building for the CUDA support sources should be set to the gpu sources.
2025-08-29[flang-rt][device] Silence warning missing return statement at end of ↵Valentin Clement (バレンタイン クレメン)
non-void function (#156077) - Silence warning when using `FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT=CUDA`
2025-08-29[flang-rt] Add the ability to have user supplied callback functions to ↵David Parks
further customize the runtime environment. (#155646) Add the ability to have pre and post call back functions to ExecutionEnvironment::Configure() to allow further customization of the flang runtime environment (called from _FortranAStartProgam) in situations where either the desired features/functionality are proprietary or are too specific to be accepted by the flang community. Example: Custom constructor object linked with flang objects: ``` #include "flang-rt/runtime/environment.h" #include "flang/Runtime/entry-names.h" #include "flang/Runtime/extensions.h" namespace Fortran::runtime { // Do something specific to the flang runtime environment prior to the // core logic of ExecutionEnvironment::Configure(). static void CustomPreConfigureEnv(int argc, const char *argv[], const char *envp[], const EnvironmentDefaultList *envDefaultList) { puts(__func__); } // Do something specific to the flang runtime environment after running the // core logic of ExecutionEnvironment::Configure(). static void CustomPostConfigureEnv(int argc, const char *argv[], const char *envp[], const EnvironmentDefaultList *envDefaultList) { puts(__func__); } void __attribute__((constructor)) CustomInitCstor(void) { // Possibilities: // RTNAME(RegisterConfigureEnv)(&CustomPreConfigureEnv, // &CustomPostConfigureEnv); RTNAME(RegisterConfigureEnv)(nullptr, // &CustomPostConfigureEnv); RTNAME(RegisterConfigureEnv)(&CustomPreConfigureEnv, nullptr); } } // namespace Fortran::runtime ``` --------- Co-authored-by: David Parks <dparks@nvidia.com>
2025-08-29[flang][runtime][NFC] Clean up Fortran::common::optional<> usage (#155728)Peter Klausler
When somebody replaced uses of std::optional<> in the runtime with a new optional<> defined locally, many needless top-level Fortran:: namespace qualifiers were added, which are inconsistent with namespace usage in the runtime. Clean them up.
2025-08-29[flang][runtime] Handle ALLOCATE(..., short SOURCE=) (#155715)Peter Klausler
Ensure that blank padding takes place when a fixed-length character allocatable is allocated with a short SOURCE= specifier. While here, clean up DoFromSourceAssign() so that it uses a temporary descriptor on the stack rather than allocating one from the heap. Fixes https://github.com/llvm/llvm-project/issues/155703.
2025-08-29[flang][runtime] Handle null list-directed fields in child input (#155707)Peter Klausler
List-directed input statements maintain two flags ("eatComma_" and "hitSlash_") in their state that allow GetNextDataEdit() to detect and handle field separators (usually ',') and slashes in the input stream. For list-directed input in a defined input subroutine, it's necessary to copy those flags from the parent list-directed input statement (if any) and update them afterwards. Fixes https://github.com/llvm/llvm-project/issues/154791.
2025-08-29[flang] Support UNSIGNED ** (#154601)Peter Klausler
GNU Fortran added support for UNSIGNED ** UNSIGNED power operations; we should do the same for portability. This actually simplifies semantics a bit, since I had to go out of my way to exclude Power as a supported operation for UNSIGNED.
2025-08-28[flang] Don't associate pointers with zero sized storage targets (#155867)Eugene Epshteyn
Fixes #155481
2025-08-27[Flang-RT][OpenMP] Define _GLIBCXX_NO_ASSERTIONS (#155440)Michael Kruse
Since GCC 15.1, libstdc++ enabled assertions/hardening by default in non-optimized (-O0) builds [1]. That is, _GLIBCXX_ASSERTIONS is defined in the libstdc++ headers itself so defining/undefining it on the compiler command line no longer has an effect in non-optimized builds. As the commit message[2] suggests, define _GLIBCXX_NO_ASSERTIONS instead. For libstdc++ headers before 15.1, -U_GLIBCXX_ASSERTIONS still has to be on the command line as well. Defining _GLIBCXX_NO_ASSERTIONS was previously proposed in #152223 [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112808 [2] https://github.com/gcc-mirror/gcc/commit/361d230fd7800a7e749aba8ed020f54f5c26d504
2025-08-22[flang][cuda] Remove TODO for descriptor with addendum (#155012)users/bwendling/cfi-salt-libclangValentin Clement (バレンタイン クレメン)
Addendum is allocated as part of the descriptor so there is no need for extra care.
2025-08-21Revert "Fix Debug Build Using GCC 15" (#154877)dpalermo
Reverts llvm/llvm-project#152223