[PATCH] D124414: [Support] Factor out isCrash from throwIfCrash

Alexander Shaposhnikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 26 17:53:20 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6beb2db7d168: [Support] Factor out isCrash from throwIfCrash (authored by alexander-shaposhnikov).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D124414/new/

https://reviews.llvm.org/D124414

Files:
  llvm/include/llvm/Support/CrashRecoveryContext.h
  llvm/lib/Support/CrashRecoveryContext.cpp


Index: llvm/lib/Support/CrashRecoveryContext.cpp
===================================================================
--- llvm/lib/Support/CrashRecoveryContext.cpp
+++ llvm/lib/Support/CrashRecoveryContext.cpp
@@ -442,7 +442,7 @@
   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 @@
   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
Index: llvm/include/llvm/Support/CrashRecoveryContext.h
===================================================================
--- llvm/include/llvm/Support/CrashRecoveryContext.h
+++ llvm/include/llvm/Support/CrashRecoveryContext.h
@@ -101,6 +101,9 @@
   /// 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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124414.425373.patch
Type: text/x-patch
Size: 1857 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220427/961861d5/attachment.bin>


More information about the llvm-commits mailing list