[flang-commits] [flang] eb93322 - [flang] Implement a runtime routine to report fatal errors with source position
Peter Steinfeld via flang-commits
flang-commits at lists.llvm.org
Fri Jan 28 15:48:33 PST 2022
Author: Peter Steinfeld
Date: 2022-01-28T15:46:00-08:00
New Revision: eb933225f491e2063ba47e18a1153829cb32676c
URL: https://github.com/llvm/llvm-project/commit/eb933225f491e2063ba47e18a1153829cb32676c
DIFF: https://github.com/llvm/llvm-project/commit/eb933225f491e2063ba47e18a1153829cb32676c.diff
LOG: [flang] Implement a runtime routine to report fatal errors with source position
The title says it all.
I implemented a routine called "Crash" and added a test.
Differential Revision: https://reviews.llvm.org/D118509
Added:
Modified:
flang/include/flang/Runtime/stop.h
flang/runtime/stop.cpp
flang/unittests/Runtime/Stop.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Runtime/stop.h b/flang/include/flang/Runtime/stop.h
index 8a2fed9e7290b..b129734d3432f 100644
--- a/flang/include/flang/Runtime/stop.h
+++ b/flang/include/flang/Runtime/stop.h
@@ -30,6 +30,10 @@ NORETURN void RTNAME(ProgramEndStatement)(NO_ARGUMENTS);
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_
diff --git a/flang/runtime/stop.cpp b/flang/runtime/stop.cpp
index c7dbe7e4619f8..8d43ad8593c1d 100644
--- a/flang/runtime/stop.cpp
+++ b/flang/runtime/stop.cpp
@@ -143,4 +143,9 @@ void RTNAME(PauseStatementText)(const char *code, std::size_t length) {
}
[[noreturn]] void RTNAME(Abort)() { std::abort(); }
+
+[[noreturn]] void RTNAME(Crash)(
+ const char *message, const char *source, int line) {
+ Fortran::runtime::Terminator{source, line}.Crash(message);
+}
}
diff --git a/flang/unittests/Runtime/Stop.cpp b/flang/unittests/Runtime/Stop.cpp
index 4160a1dcf4269..ace69bf5ee256 100644
--- a/flang/unittests/Runtime/Stop.cpp
+++ b/flang/unittests/Runtime/Stop.cpp
@@ -83,3 +83,14 @@ TEST(TestProgramEnd, ExitTest) {
}
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());
+}
More information about the flang-commits
mailing list