[PATCH] D118509: [flang] Implement a runtime routine to report fatal errors with source position
Pete Steinfeld via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 28 13:22:19 PST 2022
PeteSteinfeld created this revision.
Herald added a project: Flang.
PeteSteinfeld requested review of this revision.
Herald added subscribers: llvm-commits, jdoerfert.
Herald added a project: LLVM.
The title says it all.
I implemented a routine called "Crash" and added a test.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D118509
Files:
flang/include/flang/Runtime/stop.h
flang/runtime/stop.cpp
flang/unittests/Runtime/Stop.cpp
Index: flang/unittests/Runtime/Stop.cpp
===================================================================
--- flang/unittests/Runtime/Stop.cpp
+++ flang/unittests/Runtime/Stop.cpp
@@ -83,3 +83,14 @@
}
TEST(TestProgramEnd, AbortTest) { EXPECT_DEATH(RTNAME(Abort)(), ""); }
+
+TEST(TestProgramEnd, CrashTest) {
+ static const std::string crashMessage{"bad user code"};
+ static const std::string fileName{"file name"};
+ static const std::string headMessage{"fatal Fortran runtime error\\("};
+ static const std::string tailMessage{":343\\): "};
+ static const std::string fullMessage{
+ headMessage + fileName + tailMessage + crashMessage};
+ EXPECT_DEATH(RTNAME(Crash)(crashMessage.c_str(), fileName.c_str(), 343),
+ fullMessage.c_str());
+}
Index: flang/runtime/stop.cpp
===================================================================
--- flang/runtime/stop.cpp
+++ flang/runtime/stop.cpp
@@ -143,4 +143,10 @@
}
[[noreturn]] void RTNAME(Abort)() { std::abort(); }
+
+[[noreturn]] void RTNAME(Crash)(
+ const char *message, const char *source, int line) {
+ Fortran::runtime::Terminator terminator{source, line};
+ terminator.Crash(message);
+}
}
Index: flang/include/flang/Runtime/stop.h
===================================================================
--- flang/include/flang/Runtime/stop.h
+++ flang/include/flang/Runtime/stop.h
@@ -30,6 +30,10 @@
NORETURN void RTNAME(Exit)(int status = EXIT_SUCCESS);
NORETURN void RTNAME(Abort)(NO_ARGUMENTS);
+// Crash with an error message when the program dynamically violates a Fortran
+// constraint.
+NORETURN void RTNAME(Crash)(const char *message, const char *source, int line);
+
FORTRAN_EXTERN_C_END
#endif // FORTRAN_RUNTIME_STOP_H_
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118509.404148.patch
Type: text/x-patch
Size: 1730 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220128/c233f7d0/attachment.bin>
More information about the llvm-commits
mailing list