[flang-commits] [flang] [llvm] [flang-rt] Add fatal diagnostics with integer values (PR #231241)
via flang-commits
flang-commits at lists.llvm.org
Tue Oct 13 04:16:55 PDT 2026
================
@@ -249,4 +253,72 @@ RT_OPTNONE_ATTR void FORTRAN_PROCEDURE_NAME(backtrace)() { PrintBacktrace(); }
const char *message, const char *source, int line) {
Fortran::runtime::Terminator{source, line}.Crash(message);
}
+
+RT_OFFLOAD_API_GROUP_BEGIN
+[[noreturn]] RT_API_ATTRS void RTNAME(ReportFatalUserErrorValues)(
+ const char *message, const char *source, int line, long long v0,
+ long long v1, long long v2, long long v3) {
+ Fortran::runtime::Terminator{source, line}.Crash(message, v0, v1, v2, v3);
+}
+
+[[noreturn]] RT_API_ATTRS void RTNAME(ReportFatalUserErrorValueArray)(
+ const char *message, const char *source, int line, std::size_t count,
+ const long long *values) {
+ Fortran::runtime::Terminator terminator{source, line};
+ RUNTIME_CHECK(terminator, message && (count == 0 || values));
+
+ // Reserve enough space for every value, its sign, and the unchanged format.
+ // Allocation is confined to this fatal path, and no diagnostic is truncated.
+ constexpr std::size_t maxValueChars{
+ std::numeric_limits<unsigned long long>::digits10 + 2};
+ std::size_t messageLength{Fortran::runtime::strlen(message)};
+ if (messageLength == std::numeric_limits<std::size_t>::max() ||
+ count > (std::numeric_limits<std::size_t>::max() - messageLength - 1) /
+ maxValueChars) {
+ terminator.Crash("Fatal error message size overflow");
+ }
+ char *buffer{static_cast<char *>(Fortran::runtime::AllocateMemoryOrCrash(
+ terminator, messageLength + count * maxValueChars + 1))};
----------------
jeanPerier wrote:
Right, allocating here could be trouble in general. Thanks to your comment, I actually found that we have a streaming crash API that also removes the need to do the custom integer formatting, so I decided to just always use it for simplicity.
Note that the concurrent case in general has limitations as the messages will be interleaved. I do not want to start messing with locks at that point, so I just documented that interleaving will happen when used concurrently, we can refine the parallel case later.
https://github.com/llvm/llvm-project/pull/231241
More information about the flang-commits
mailing list