[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:17:16 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");
+ }
----------------
jeanPerier wrote:
The format and conversion count are now validated before printing or reading values. Streaming removes allocation and buffer sizing entirely, including the strlen == SIZE_MAX check.
https://github.com/llvm/llvm-project/pull/231241
More information about the flang-commits
mailing list