[WTF] Make CRASH_WITH_INFO more useful when using GCC
https://bugs.webkit.org/show_bug.cgi?id=235573

Make CRASH_WITH_INFO() print out the additional information instead of silently crash
when WebKit is compiled with GCC.

Reviewed by Yusuke Suzuki.

* wtf/Assertions.h: Add a variant of CRASH_WITH_INFO() which uses __VA_OPT__ for
GCC and Clang; MSVC is left with the existing version as the version currently in
use is not happy about __VA_OPT__.
(CRASH_WITH_INFO): Deleted inline function for GCC.
(CRASH_WITH_SECURITY_IMPLICATION_AND_INFO): Ditto.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@288577 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog
index ba78ac1..b0606b5 100644
--- a/Source/WTF/ChangeLog
+++ b/Source/WTF/ChangeLog
@@ -1,3 +1,19 @@
+2022-01-25  Adrian Perez de Castro  <aperez@igalia.com>
+
+        [WTF] Make CRASH_WITH_INFO more useful when using GCC
+        https://bugs.webkit.org/show_bug.cgi?id=235573
+
+        Make CRASH_WITH_INFO() print out the additional information instead of silently crash
+        when WebKit is compiled with GCC.
+
+        Reviewed by Yusuke Suzuki.
+
+        * wtf/Assertions.h: Add a variant of CRASH_WITH_INFO() which uses __VA_OPT__ for
+        GCC and Clang; MSVC is left with the existing version as the version currently in
+        use is not happy about __VA_OPT__.
+        (CRASH_WITH_INFO): Deleted inline function for GCC.
+        (CRASH_WITH_SECURITY_IMPLICATION_AND_INFO): Ditto.
+
 2022-01-24  Mark Lam  <mark.lam@apple.com>
 
         Rename Vector and FixedVector::findMatching to findIf to match stl naming.
diff --git a/Source/WTF/wtf/Assertions.h b/Source/WTF/wtf/Assertions.h
index 57ae606..97eb7fa 100644
--- a/Source/WTF/wtf/Assertions.h
+++ b/Source/WTF/wtf/Assertions.h
@@ -760,31 +760,20 @@
 #ifndef CRASH_WITH_INFO
 // This is useful if you are going to stuff data into registers before crashing, like the
 // crashWithInfo functions below.
-#if COMPILER(CLANG) || COMPILER(MSVC)
+#if COMPILER(MSVC)
+// FIXME: Re-check whether MSVC 2020 supports __VA_OPT__ and remove the special
+//        casing once older versions of the compiler are no longer supported.
 #define CRASH_WITH_INFO(...) do { \
         WTF::isIntegralOrPointerType(__VA_ARGS__); \
         compilerFenceForCrash(); \
         WTFCrashWithInfo(__LINE__, __FILE__, WTF_PRETTY_FUNCTION, __COUNTER__, ##__VA_ARGS__); \
     } while (false)
 #else
-// GCC does not allow ##__VA_ARGS__ unless GNU extensions are enabled (--std=gnu++NN instead of
-// --std=c++NN) and I think we don't want that, so we'll have a fallback path for GCC. Obviously
-// this will not actually succeed at getting the desired info into registers before crashing, but
-// it's just a fallback anyway.
-//
-// FIXME: When we enable C++20, we should replace ##__VA_ARGS__ with format __VA_OPT__(,) __VA_ARGS__
-// so that we can remove this fallback.
-inline NO_RETURN_DUE_TO_CRASH void CRASH_WITH_INFO(...)
-{
-    CRASH();
-}
-
-// We must define this here because CRASH_WITH_INFO() is not defined as a macro.
-// FIXME: Remove this when upgrading to C++20.
-inline NO_RETURN_DUE_TO_CRASH void CRASH_WITH_SECURITY_IMPLICATION_AND_INFO(...)
-{
-    CRASH();
-}
+#define CRASH_WITH_INFO(...) do { \
+        WTF::isIntegralOrPointerType(__VA_ARGS__); \
+        compilerFenceForCrash(); \
+        WTFCrashWithInfo(__LINE__, __FILE__, WTF_PRETTY_FUNCTION, __COUNTER__ __VA_OPT__(,) __VA_ARGS__); \
+    } while (false)
 #endif
 #endif // CRASH_WITH_INFO