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

Alexander Shaposhnikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 25 13:15:02 PDT 2022


alexander-shaposhnikov created this revision.
alexander-shaposhnikov added reviewers: aganea, dblaikie.
alexander-shaposhnikov created this object with visibility "All Users".
Herald added subscribers: dexonsmith, hiraditya.
Herald added a project: All.
alexander-shaposhnikov requested review of this revision.
Herald added a project: LLVM.

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


Repository:
  rG LLVM Github Monorepo

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.425008.patch
Type: text/x-patch
Size: 1857 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220425/0733177d/attachment.bin>


More information about the llvm-commits mailing list