[llvm] 6beb2db - [Support] Factor out isCrash from throwIfCrash
Alexander Shaposhnikov via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 26 17:53:17 PDT 2022
Author: Alexander Shaposhnikov
Date: 2022-04-27T00:52:53Z
New Revision: 6beb2db7d168a952b4b97ca8b1e7f1b8f63460cb
URL: https://github.com/llvm/llvm-project/commit/6beb2db7d168a952b4b97ca8b1e7f1b8f63460cb
DIFF: https://github.com/llvm/llvm-project/commit/6beb2db7d168a952b4b97ca8b1e7f1b8f63460cb.diff
LOG: [Support] Factor out isCrash from throwIfCrash
This diff factors out the check "isCrash" from the static method "throwIfCrash".
This is a helper function that can be useful in debugging / analysis, in particular,
I'm planning to use it in the future patches for lld-fuzzer.
Test plan:
1/ ninja check-all
2/ export LLD_IN_TEST=5 ninja check-lld
Differential revision: https://reviews.llvm.org/D124414
Added:
Modified:
llvm/include/llvm/Support/CrashRecoveryContext.h
llvm/lib/Support/CrashRecoveryContext.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/CrashRecoveryContext.h b/llvm/include/llvm/Support/CrashRecoveryContext.h
index f60e7335e197d..26ddf97b3ef02 100644
--- a/llvm/include/llvm/Support/CrashRecoveryContext.h
+++ b/llvm/include/llvm/Support/CrashRecoveryContext.h
@@ -101,6 +101,9 @@ class CrashRecoveryContext {
/// return failure from RunSafely(). This function does not return.
[[noreturn]] void HandleExit(int RetCode);
+ /// Return true if RetCode indicates that a signal or an exception occurred.
+ static bool isCrash(int RetCode);
+
/// Throw again a signal or an exception, after it was catched once by a
/// CrashRecoveryContext.
static bool throwIfCrash(int RetCode);
diff --git a/llvm/lib/Support/CrashRecoveryContext.cpp b/llvm/lib/Support/CrashRecoveryContext.cpp
index c4847d862739c..292ba63d14aa5 100644
--- a/llvm/lib/Support/CrashRecoveryContext.cpp
+++ b/llvm/lib/Support/CrashRecoveryContext.cpp
@@ -442,7 +442,7 @@ bool CrashRecoveryContext::RunSafely(function_ref<void()> Fn) {
llvm_unreachable("Most likely setjmp wasn't called!");
}
-bool CrashRecoveryContext::throwIfCrash(int RetCode) {
+bool CrashRecoveryContext::isCrash(int RetCode) {
#if defined(_WIN32)
// On Windows, the high bits are reserved for kernel return codes. Values
// starting with 0x80000000 are reserved for "warnings"; values of 0xC0000000
@@ -451,12 +451,21 @@ bool CrashRecoveryContext::throwIfCrash(int RetCode) {
unsigned Code = ((unsigned)RetCode & 0xF0000000) >> 28;
if (Code != 0xC && Code != 8)
return false;
- ::RaiseException(RetCode, 0, 0, NULL);
#else
// On Unix, signals are represented by return codes of 128 or higher.
// Exit code 128 is a reserved value and should not be raised as a signal.
if (RetCode <= 128)
return false;
+#endif
+ return true;
+}
+
+bool CrashRecoveryContext::throwIfCrash(int RetCode) {
+ if (!isCrash(RetCode))
+ return false;
+#if defined(_WIN32)
+ ::RaiseException(RetCode, 0, 0, NULL);
+#else
llvm::sys::unregisterHandlers();
raise(RetCode - 128);
#endif
More information about the llvm-commits
mailing list