Eliminate the need for WTFCrashImpl().
authormark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 Feb 2016 22:39:52 +0000 (22:39 +0000)
committermark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 13 Feb 2016 22:39:52 +0000 (22:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=154202

Reviewed by Alexey Proskuryakov.

* wtf/Assertions.cpp:
* wtf/Assertions.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196554 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/Assertions.cpp
Source/WTF/wtf/Assertions.h

index b1ee3e1..af12678 100644 (file)
@@ -1,3 +1,13 @@
+2016-02-13  Mark Lam  <mark.lam@apple.com>
+
+        Eliminate the need for WTFCrashImpl().
+        https://bugs.webkit.org/show_bug.cgi?id=154202
+
+        Reviewed by Alexey Proskuryakov.
+
+        * wtf/Assertions.cpp:
+        * wtf/Assertions.h:
+
 2016-02-12  Sukolsak Sakshuwong  <sukolsak@gmail.com>
 
         Update ICU header files to version 52
index d2e342b..9054e9c 100644 (file)
@@ -313,7 +313,7 @@ void WTFSetCrashHook(WTFCrashHookFunction function)
 }
 
 #if !defined(NDEBUG) || !OS(DARWIN)
-void WTFCrashImpl()
+void WTFCrash()
 {
     if (globalHook)
         globalHook();
@@ -327,8 +327,7 @@ void WTFCrashImpl()
     ((void(*)())0)();
 #endif
 }
-#endif // !defined(NDEBUG) || !OS(DARWIN)
-    
+#else
 // We need to keep WTFCrash() around (even on non-debug OS(DARWIN) builds) as a workaround
 // for presently shipping (circa early 2016) SafariForWebKitDevelopment binaries which still
 // expects to link to it.
@@ -336,6 +335,7 @@ void WTFCrash()
 {
     CRASH();
 }
+#endif // !defined(NDEBUG) || !OS(DARWIN)
 
 void WTFCrashWithSecurityImplication()
 {
index 5a2fbff..39bf3b6 100644 (file)
@@ -152,30 +152,31 @@ WTF_EXPORT_PRIVATE void WTFInstallReportBacktraceOnCrashHook();
 WTF_EXPORT_PRIVATE bool WTFIsDebuggerAttached();
 
 #ifndef CRASH
-#define CRASH() WTFCrashImpl()
-#endif
 
 #if defined(NDEBUG) && OS(DARWIN)
-ALWAYS_INLINE NO_RETURN_DUE_TO_CRASH void WTFCrashImpl()
-{
-    // Crash with a SIGTRAP i.e EXC_BREAKPOINT.
-    // We are not using __builtin_trap because it is only guaranteed to abort, but not necessarily
-    // trigger a SIGTRAP. Instead, we use inline asm to ensure that we trigger the SIGTRAP.
 #if CPU(X86_64) || CPU(X86)
-    asm volatile ("int3");
+#define WTFBreakpointTrap()  asm volatile ("int3")
 #elif CPU(ARM_THUMB2)
-    asm volatile ("bkpt #0");
+#define WTFBreakpointTrap()  asm volatile ("bkpt #0")
 #elif CPU(ARM64)
-    asm volatile ("brk #0");
+#define WTFBreakpointTrap()  asm volatile ("brk #0")
 #else
 #error "Unsupported CPU".
 #endif
-    __builtin_unreachable();
-}
+
+// Crash with a SIGTRAP i.e EXC_BREAKPOINT.
+// We are not using __builtin_trap because it is only guaranteed to abort, but not necessarily
+// trigger a SIGTRAP. Instead, we use inline asm to ensure that we trigger the SIGTRAP.
+#define CRASH() do { \
+    WTFBreakpointTrap(); \
+    __builtin_unreachable(); \
+} while (0)
 #else
-WTF_EXPORT_PRIVATE NO_RETURN_DUE_TO_CRASH void WTFCrashImpl();
+#define CRASH() WTFCrash()
 #endif
 
+#endif // CRASH
+
 WTF_EXPORT_PRIVATE NO_RETURN_DUE_TO_CRASH void WTFCrash();
 
 #ifndef CRASH_WITH_SECURITY_IMPLICATION
@@ -240,17 +241,19 @@ WTF_EXPORT_PRIVATE NO_RETURN_DUE_TO_CRASH void WTFCrashWithSecurityImplication()
 
 #else
 
-#define ASSERT(assertion) \
-    (!(assertion) ? \
-        (WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion), \
-         CRASH()) : \
-        (void)0)
+#define ASSERT(assertion) do { \
+    if (!(assertion)) { \
+        WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion); \
+        CRASH(); \
+    } \
+} while (0)
 
-#define ASSERT_AT(assertion, file, line, function) \
-    (!(assertion) ? \
-        (WTFReportAssertionFailure(file, line, function, #assertion), \
-         CRASH()) :                                                   \
-        (void)0)
+#define ASSERT_AT(assertion, file, line, function) do { \
+    if (!(assertion)) { \
+        WTFReportAssertionFailure(file, line, function, #assertion); \
+        CRASH(); \
+    } \
+} while (0)
 
 #define ASSERT_NOT_REACHED() do { \
     WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, 0); \
@@ -282,12 +285,12 @@ WTF_EXPORT_PRIVATE NO_RETURN_DUE_TO_CRASH void WTFCrashWithSecurityImplication()
 #if ASSERT_MSG_DISABLED
 #define ASSERT_WITH_MESSAGE(assertion, ...) ((void)0)
 #else
-#define ASSERT_WITH_MESSAGE(assertion, ...) do \
+#define ASSERT_WITH_MESSAGE(assertion, ...) do \
     if (!(assertion)) { \
         WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion, __VA_ARGS__); \
         CRASH(); \
     } \
-while (0)
+while (0)
 #endif
 
 /* ASSERT_WITH_MESSAGE_UNUSED */
@@ -295,12 +298,12 @@ while (0)
 #if ASSERT_MSG_DISABLED
 #define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...) ((void)variable)
 #else
-#define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...) do \
+#define ASSERT_WITH_MESSAGE_UNUSED(variable, assertion, ...) do \
     if (!(assertion)) { \
         WTFReportAssertionFailureWithMessage(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion, __VA_ARGS__); \
         CRASH(); \
     } \
-while (0)
+while (0)
 #endif
                         
                         
@@ -312,12 +315,12 @@ while (0)
 
 #else
 
-#define ASSERT_ARG(argName, assertion) do \
+#define ASSERT_ARG(argName, assertion) do \
     if (!(assertion)) { \
         WTFReportArgumentAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #argName, #assertion); \
         CRASH(); \
     } \
-while (0)
+while (0)
 
 #endif
 
@@ -371,7 +374,10 @@ while (0)
 /* RELEASE_ASSERT */
 
 #if ASSERT_DISABLED
-#define RELEASE_ASSERT(assertion) (UNLIKELY(!(assertion)) ? (CRASH()) : (void)0)
+#define RELEASE_ASSERT(assertion) do { \
+    if (UNLIKELY(!(assertion))) \
+        CRASH(); \
+} while (0)
 #define RELEASE_ASSERT_WITH_MESSAGE(assertion, ...) RELEASE_ASSERT(assertion)
 #define RELEASE_ASSERT_NOT_REACHED() CRASH()
 #else