Skip to content

[WebAssembly] __USING_WASM_EXCEPTIONS__ -> __WASM_EXCEPTIONS__ - #92840

Merged
aheejin merged 2 commits into
llvm:mainfrom
aheejin:wasm_exceptions
May 22, 2024
Merged

aheejin merged 2 commits into
llvm:mainfrom
aheejin:wasm_exceptions

Conversation

@aheejin

@aheejin aheejin commented May 21, 2024

Copy link
Copy Markdown
Member

We've decided to change __USING_WASM_EXCEPTIONS__ preprocessor to __WASM_EXCEPTIONS__ given that it's more concise.

We've decided to change `__USING_WASM_EXCEPTIONS__` preprocessor to
`__WASM_EXCEPTIONS__` given that it's more concise.
@aheejin
aheejin requested a review from sbc100 May 21, 2024 01:44
@aheejin
aheejin requested review from a team as code owners May 21, 2024 01:44
@llvmbot llvmbot added libc++abi libc++abi C++ Runtime Library. Not libc++. libunwind labels May 21, 2024
@llvmbot

llvmbot commented May 21, 2024 •

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-libunwind

@llvm/pr-subscribers-libcxxabi

Author: Heejin Ahn (aheejin)

Changes

We've decided to change __USING_WASM_EXCEPTIONS__ preprocessor to __WASM_EXCEPTIONS__ given that it's more concise.


Full diff: https://github.com/llvm/llvm-project/pull/92840.diff

6 Files Affected:

  • (modified) libcxxabi/include/cxxabi.h (+1-1)
  • (modified) libcxxabi/src/cxa_exception.cpp (+1-1)
  • (modified) libcxxabi/src/cxa_exception.h (+1-1)
  • (modified) libcxxabi/src/cxa_personality.cpp (+18-18)
  • (modified) libunwind/src/Unwind-wasm.c (+2-2)
  • (modified) libunwind/src/libunwind.cpp (+2-2)
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index d0701181751c5..9d9beecf751fc 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -53,7 +53,7 @@ __cxa_init_primary_exception(void* object, std::type_info* tinfo, void(_LIBCXXAB
 // 2.4.3 Throwing the Exception Object
 extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
 __cxa_throw(void *thrown_exception, std::type_info *tinfo,
-#ifdef __USING_WASM_EXCEPTIONS__
+#ifdef __WASM_EXCEPTIONS__
             // In Wasm, a destructor returns its argument
             void *(_LIBCXXABI_DTOR_FUNC *dest)(void *));
 #else
diff --git a/libcxxabi/src/cxa_exception.cpp b/libcxxabi/src/cxa_exception.cpp
index 65e9f4504ddad..3141d50a6bb92 100644
--- a/libcxxabi/src/cxa_exception.cpp
+++ b/libcxxabi/src/cxa_exception.cpp
@@ -267,7 +267,7 @@ will call terminate, assuming that there was no handler for the
 exception.
 */
 void
-#ifdef __USING_WASM_EXCEPTIONS__
+#ifdef __WASM_EXCEPTIONS__
 // In Wasm, a destructor returns its argument
 __cxa_throw(void *thrown_object, std::type_info *tinfo, void *(_LIBCXXABI_DTOR_FUNC *dest)(void *)) {
 #else
diff --git a/libcxxabi/src/cxa_exception.h b/libcxxabi/src/cxa_exception.h
index 10712f6f47bb5..7800b940b83f7 100644
--- a/libcxxabi/src/cxa_exception.h
+++ b/libcxxabi/src/cxa_exception.h
@@ -43,7 +43,7 @@ struct _LIBCXXABI_HIDDEN __cxa_exception {
 
     //  Manage the exception object itself.
     std::type_info *exceptionType;
-#ifdef __USING_WASM_EXCEPTIONS__
+#ifdef __WASM_EXCEPTIONS__
     // In Wasm, a destructor returns its argument
     void *(_LIBCXXABI_DTOR_FUNC *exceptionDestructor)(void *);
 #else
diff --git a/libcxxabi/src/cxa_personality.cpp b/libcxxabi/src/cxa_personality.cpp
index d95d781319401..843a18a4cbd8a 100644
--- a/libcxxabi/src/cxa_personality.cpp
+++ b/libcxxabi/src/cxa_personality.cpp
@@ -70,7 +70,7 @@ extern "C" EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD,
 +------------------+--+-----+-----+------------------------+--------------------------+
 | callSiteTableLength | (ULEB128) | Call Site Table length, used to find Action table |
 +---------------------+-----------+---------------------------------------------------+
-#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__USING_WASM_EXCEPTIONS__)
+#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__WASM_EXCEPTIONS__)
 +---------------------+-----------+------------------------------------------------+
 | Beginning of Call Site Table            The current ip lies within the           |
 | ...                                     (start, length) range of one of these    |
@@ -84,7 +84,7 @@ extern "C" EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD,
 | +-------------+---------------------------------+------------------------------+ |
 | ...                                                                              |
 +----------------------------------------------------------------------------------+
-#else  // __USING_SJLJ_EXCEPTIONS__ || __USING_WASM_EXCEPTIONS__
+#else  // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__
 +---------------------+-----------+------------------------------------------------+
 | Beginning of Call Site Table            The current ip is a 1-based index into   |
 | ...                                     this table.  Or it is -1 meaning no      |
@@ -97,7 +97,7 @@ extern "C" EXCEPTION_DISPOSITION _GCC_specific_handler(PEXCEPTION_RECORD,
 | +-------------+---------------------------------+------------------------------+ |
 | ...                                                                              |
 +----------------------------------------------------------------------------------+
-#endif // __USING_SJLJ_EXCEPTIONS__ || __USING_WASM_EXCEPTIONS__
+#endif // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__
 +---------------------------------------------------------------------+
 | Beginning of Action Table       ttypeIndex == 0 : cleanup           |
 | ...                             ttypeIndex  > 0 : catch             |
@@ -547,7 +547,7 @@ void
 set_registers(_Unwind_Exception* unwind_exception, _Unwind_Context* context,
               const scan_results& results)
 {
-#if defined(__USING_SJLJ_EXCEPTIONS__) || defined(__USING_WASM_EXCEPTIONS__)
+#if defined(__USING_SJLJ_EXCEPTIONS__) || defined(__WASM_EXCEPTIONS__)
 #define __builtin_eh_return_data_regno(regno) regno
 #elif defined(__ibmxl__)
 // IBM xlclang++ compiler does not support __builtin_eh_return_data_regno.
@@ -642,7 +642,7 @@ static void scan_eh_tab(scan_results &results, _Unwind_Action actions,
     // Get beginning current frame's code (as defined by the
     // emitted dwarf code)
     uintptr_t funcStart = _Unwind_GetRegionStart(context);
-#if defined(__USING_SJLJ_EXCEPTIONS__) || defined(__USING_WASM_EXCEPTIONS__)
+#if defined(__USING_SJLJ_EXCEPTIONS__) || defined(__WASM_EXCEPTIONS__)
     if (ip == uintptr_t(-1))
     {
         // no action
@@ -652,9 +652,9 @@ static void scan_eh_tab(scan_results &results, _Unwind_Action actions,
     else if (ip == 0)
         call_terminate(native_exception, unwind_exception);
     // ip is 1-based index into call site table
-#else  // !__USING_SJLJ_EXCEPTIONS__ && !__USING_WASM_EXCEPTIONS__
+#else  // !__USING_SJLJ_EXCEPTIONS__ && !__WASM_EXCEPTIONS__
     uintptr_t ipOffset = ip - funcStart;
-#endif // !__USING_SJLJ_EXCEPTIONS__ && !__USING_WASM_EXCEPTIONS__
+#endif // !__USING_SJLJ_EXCEPTIONS__ && !__WASM_EXCEPTIONS__
     const uint8_t* classInfo = NULL;
     // Note: See JITDwarfEmitter::EmitExceptionTable(...) for corresponding
     //       dwarf emission
@@ -675,7 +675,7 @@ static void scan_eh_tab(scan_results &results, _Unwind_Action actions,
     // Walk call-site table looking for range that
     // includes current PC.
     uint8_t callSiteEncoding = *lsda++;
-#if defined(__USING_SJLJ_EXCEPTIONS__) || defined(__USING_WASM_EXCEPTIONS__)
+#if defined(__USING_SJLJ_EXCEPTIONS__) || defined(__WASM_EXCEPTIONS__)
     (void)callSiteEncoding;  // When using SjLj/Wasm exceptions, callSiteEncoding is never used
 #endif
     uint32_t callSiteTableLength = static_cast<uint32_t>(readULEB128(&lsda));
@@ -686,7 +686,7 @@ static void scan_eh_tab(scan_results &results, _Unwind_Action actions,
     while (callSitePtr < callSiteTableEnd)
     {
         // There is one entry per call site.
-#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__USING_WASM_EXCEPTIONS__)
+#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__WASM_EXCEPTIONS__)
         // The call sites are non-overlapping in [start, start+length)
         // The call sites are ordered in increasing value of start
         uintptr_t start = readEncodedPointer(&callSitePtr, callSiteEncoding);
@@ -694,15 +694,15 @@ static void scan_eh_tab(scan_results &results, _Unwind_Action actions,
         uintptr_t landingPad = readEncodedPointer(&callSitePtr, callSiteEncoding);
         uintptr_t actionEntry = readULEB128(&callSitePtr);
         if ((start <= ipOffset) && (ipOffset < (start + length)))
-#else  // __USING_SJLJ_EXCEPTIONS__ || __USING_WASM_EXCEPTIONS__
+#else  // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__
         // ip is 1-based index into this table
         uintptr_t landingPad = readULEB128(&callSitePtr);
         uintptr_t actionEntry = readULEB128(&callSitePtr);
         if (--ip == 0)
-#endif // __USING_SJLJ_EXCEPTIONS__ || __USING_WASM_EXCEPTIONS__
+#endif // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__
         {
             // Found the call site containing ip.
-#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__USING_WASM_EXCEPTIONS__)
+#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__WASM_EXCEPTIONS__)
             if (landingPad == 0)
             {
                 // No handler here
@@ -710,9 +710,9 @@ static void scan_eh_tab(scan_results &results, _Unwind_Action actions,
                 return;
             }
             landingPad = (uintptr_t)lpStart + landingPad;
-#else  // __USING_SJLJ_EXCEPTIONS__ || __USING_WASM_EXCEPTIONS__
+#else  // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__
             ++landingPad;
-#endif // __USING_SJLJ_EXCEPTIONS__ || __USING_WASM_EXCEPTIONS__
+#endif // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__
             results.landingPad = landingPad;
             if (actionEntry == 0)
             {
@@ -838,7 +838,7 @@ static void scan_eh_tab(scan_results &results, _Unwind_Action actions,
                 action += actionOffset;
             }  // there is no break out of this loop, only return
         }
-#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__USING_WASM_EXCEPTIONS__)
+#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__WASM_EXCEPTIONS__)
         else if (ipOffset < start)
         {
             // There is no call site for this ip
@@ -846,7 +846,7 @@ static void scan_eh_tab(scan_results &results, _Unwind_Action actions,
             // Possible stack corruption.
             call_terminate(native_exception, unwind_exception);
         }
-#endif // !__USING_SJLJ_EXCEPTIONS__ && !__USING_WASM_EXCEPTIONS__
+#endif // !__USING_SJLJ_EXCEPTIONS__ && !__WASM_EXCEPTIONS__
     }  // there might be some tricky cases which break out of this loop
 
     // It is possible that no eh table entry specify how to handle
@@ -903,7 +903,7 @@ _UA_CLEANUP_PHASE
 */
 
 #if !defined(_LIBCXXABI_ARM_EHABI)
-#ifdef __USING_WASM_EXCEPTIONS__
+#ifdef __WASM_EXCEPTIONS__
 _Unwind_Reason_Code __gxx_personality_wasm0
 #elif defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
 static _Unwind_Reason_Code __gxx_personality_imp
@@ -972,7 +972,7 @@ __gxx_personality_v0
             exc->languageSpecificData = results.languageSpecificData;
             exc->catchTemp = reinterpret_cast<void*>(results.landingPad);
             exc->adjustedPtr = results.adjustedPtr;
-#ifdef __USING_WASM_EXCEPTIONS__
+#ifdef __WASM_EXCEPTIONS__
             // Wasm only uses a single phase (_UA_SEARCH_PHASE), so save the
             // results here.
             set_registers(unwind_exception, context, results);
diff --git a/libunwind/src/Unwind-wasm.c b/libunwind/src/Unwind-wasm.c
index f7f39d38b59c1..b18b32c5d1784 100644
--- a/libunwind/src/Unwind-wasm.c
+++ b/libunwind/src/Unwind-wasm.c
@@ -14,7 +14,7 @@
 
 #include "config.h"
 
-#ifdef __USING_WASM_EXCEPTIONS__
+#ifdef __WASM_EXCEPTIONS__
 
 #include "unwind.h"
 #include <threads.h>
@@ -120,4 +120,4 @@ _Unwind_GetRegionStart(struct _Unwind_Context *context) {
   return 0;
 }
 
-#endif // defined(__USING_WASM_EXCEPTIONS__)
+#endif // defined(__WASM_EXCEPTIONS__)
diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
index 217dde9098637..561c68eb33e28 100644
--- a/libunwind/src/libunwind.cpp
+++ b/libunwind/src/libunwind.cpp
@@ -26,7 +26,7 @@
 #include <sanitizer/asan_interface.h>
 #endif
 
-#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__USING_WASM_EXCEPTIONS__)
+#if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__WASM_EXCEPTIONS__)
 #include "AddressSpace.hpp"
 #include "UnwindCursor.hpp"
 
@@ -348,7 +348,7 @@ void __unw_remove_dynamic_eh_frame_section(unw_word_t eh_frame_start) {
 
 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
 #endif // !defined(__USING_SJLJ_EXCEPTIONS__) &&
-       // !defined(__USING_WASM_EXCEPTIONS__)
+       // !defined(__WASM_EXCEPTIONS__)
 
 #ifdef __APPLE__
 

@github-actions

github-actions Bot commented May 21, 2024 •

Copy link
Copy Markdown

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff f6ff87dd90074b694e420d93389c749189bca0ec 478a176f3670266c835fa0fbe6448964d5c2bfe8 -- libcxxabi/include/cxxabi.h libcxxabi/src/cxa_exception.cpp libcxxabi/src/cxa_exception.h libcxxabi/src/cxa_personality.cpp libunwind/src/Unwind-wasm.c libunwind/src/libunwind.cpp
View the diff from clang-format here.
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index 9d9beecf75..58e240cdf3 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -51,14 +51,13 @@ extern _LIBCXXABI_FUNC_VIS __cxa_exception*
 __cxa_init_primary_exception(void* object, std::type_info* tinfo, void(_LIBCXXABI_DTOR_FUNC* dest)(void*)) throw();
 
 // 2.4.3 Throwing the Exception Object
-extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void
-__cxa_throw(void *thrown_exception, std::type_info *tinfo,
-#ifdef __WASM_EXCEPTIONS__
-            // In Wasm, a destructor returns its argument
-            void *(_LIBCXXABI_DTOR_FUNC *dest)(void *));
-#else
+extern _LIBCXXABI_FUNC_VIS _LIBCXXABI_NORETURN void __cxa_throw(void* thrown_exception, std::type_info* tinfo,
+#  ifdef __WASM_EXCEPTIONS__
+                                                                // In Wasm, a destructor returns its argument
+                                                                void*(_LIBCXXABI_DTOR_FUNC* dest)(void*));
+#  else
             void (_LIBCXXABI_DTOR_FUNC *dest)(void *));
-#endif
+#  endif
 
 // 2.5.3 Exception Handlers
 extern _LIBCXXABI_FUNC_VIS void *
diff --git a/libcxxabi/src/cxa_exception.cpp b/libcxxabi/src/cxa_exception.cpp
index 3141d50a6b..3889fef1d6 100644
--- a/libcxxabi/src/cxa_exception.cpp
+++ b/libcxxabi/src/cxa_exception.cpp
@@ -269,7 +269,7 @@ exception.
 void
 #ifdef __WASM_EXCEPTIONS__
 // In Wasm, a destructor returns its argument
-__cxa_throw(void *thrown_object, std::type_info *tinfo, void *(_LIBCXXABI_DTOR_FUNC *dest)(void *)) {
+__cxa_throw(void* thrown_object, std::type_info* tinfo, void*(_LIBCXXABI_DTOR_FUNC* dest)(void*)) {
 #else
 __cxa_throw(void *thrown_object, std::type_info *tinfo, void (_LIBCXXABI_DTOR_FUNC *dest)(void *)) {
 #endif
diff --git a/libcxxabi/src/cxa_personality.cpp b/libcxxabi/src/cxa_personality.cpp
index 843a18a4cb..eb18932ef0 100644
--- a/libcxxabi/src/cxa_personality.cpp
+++ b/libcxxabi/src/cxa_personality.cpp
@@ -548,7 +548,7 @@ set_registers(_Unwind_Exception* unwind_exception, _Unwind_Context* context,
               const scan_results& results)
 {
 #if defined(__USING_SJLJ_EXCEPTIONS__) || defined(__WASM_EXCEPTIONS__)
-#define __builtin_eh_return_data_regno(regno) regno
+#  define __builtin_eh_return_data_regno(regno) regno
 #elif defined(__ibmxl__)
 // IBM xlclang++ compiler does not support __builtin_eh_return_data_regno.
 #define __builtin_eh_return_data_regno(regno) regno + 3
@@ -694,157 +694,133 @@ static void scan_eh_tab(scan_results &results, _Unwind_Action actions,
         uintptr_t landingPad = readEncodedPointer(&callSitePtr, callSiteEncoding);
         uintptr_t actionEntry = readULEB128(&callSitePtr);
         if ((start <= ipOffset) && (ipOffset < (start + length)))
-#else  // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__
-        // ip is 1-based index into this table
+#else  // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__                                                             \
+       // ip is 1-based index into this table
         uintptr_t landingPad = readULEB128(&callSitePtr);
         uintptr_t actionEntry = readULEB128(&callSitePtr);
         if (--ip == 0)
 #endif // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__
         {
-            // Found the call site containing ip.
+          // Found the call site containing ip.
 #if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__WASM_EXCEPTIONS__)
-            if (landingPad == 0)
-            {
-                // No handler here
-                results.reason = _URC_CONTINUE_UNWIND;
-                return;
-            }
-            landingPad = (uintptr_t)lpStart + landingPad;
+          if (landingPad == 0) {
+            // No handler here
+            results.reason = _URC_CONTINUE_UNWIND;
+            return;
+          }
+          landingPad = (uintptr_t)lpStart + landingPad;
 #else  // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__
-            ++landingPad;
+          ++landingPad;
 #endif // __USING_SJLJ_EXCEPTIONS__ || __WASM_EXCEPTIONS__
-            results.landingPad = landingPad;
-            if (actionEntry == 0)
-            {
-                // Found a cleanup
-                results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
+          results.landingPad = landingPad;
+          if (actionEntry == 0) {
+            // Found a cleanup
+            results.reason = (actions & _UA_SEARCH_PHASE) ? _URC_CONTINUE_UNWIND : _URC_HANDLER_FOUND;
+            return;
+          }
+          // Convert 1-based byte offset into
+          const uint8_t* action = actionTableStart + (actionEntry - 1);
+          bool hasCleanup = false;
+          // Scan action entries until you find a matching handler, cleanup, or the end of action list
+          while (true) {
+            const uint8_t* actionRecord = action;
+            int64_t ttypeIndex = readSLEB128(&action);
+            if (ttypeIndex > 0) {
+              // Found a catch, does it actually catch?
+              // First check for catch (...)
+              const __shim_type_info* catchType =
+                  get_shim_type_info(static_cast<uint64_t>(ttypeIndex), classInfo, ttypeEncoding, native_exception,
+                                     unwind_exception, base);
+              if (catchType == 0) {
+                // Found catch (...) catches everything, including
+                // foreign exceptions. This is search phase, cleanup
+                // phase with foreign exception, or forced unwinding.
+                assert(actions & (_UA_SEARCH_PHASE | _UA_HANDLER_FRAME | _UA_FORCE_UNWIND));
+                results.ttypeIndex = ttypeIndex;
+                results.actionRecord = actionRecord;
+                results.adjustedPtr = get_thrown_object_ptr(unwind_exception);
+                results.reason = _URC_HANDLER_FOUND;
                 return;
-            }
-            // Convert 1-based byte offset into
-            const uint8_t* action = actionTableStart + (actionEntry - 1);
-            bool hasCleanup = false;
-            // Scan action entries until you find a matching handler, cleanup, or the end of action list
-            while (true)
-            {
-                const uint8_t* actionRecord = action;
-                int64_t ttypeIndex = readSLEB128(&action);
-                if (ttypeIndex > 0)
-                {
-                    // Found a catch, does it actually catch?
-                    // First check for catch (...)
-                    const __shim_type_info* catchType =
-                        get_shim_type_info(static_cast<uint64_t>(ttypeIndex),
-                                           classInfo, ttypeEncoding,
-                                           native_exception, unwind_exception,
-                                           base);
-                    if (catchType == 0)
-                    {
-                        // Found catch (...) catches everything, including
-                        // foreign exceptions. This is search phase, cleanup
-                        // phase with foreign exception, or forced unwinding.
-                        assert(actions & (_UA_SEARCH_PHASE | _UA_HANDLER_FRAME |
-                                          _UA_FORCE_UNWIND));
-                        results.ttypeIndex = ttypeIndex;
-                        results.actionRecord = actionRecord;
-                        results.adjustedPtr =
-                            get_thrown_object_ptr(unwind_exception);
-                        results.reason = _URC_HANDLER_FOUND;
-                        return;
-                    }
-                    // Else this is a catch (T) clause and will never
-                    //    catch a foreign exception
-                    else if (native_exception)
-                    {
-                        __cxa_exception* exception_header = (__cxa_exception*)(unwind_exception+1) - 1;
-                        void* adjustedPtr = get_thrown_object_ptr(unwind_exception);
-                        const __shim_type_info* excpType =
-                            static_cast<const __shim_type_info*>(exception_header->exceptionType);
-                        if (adjustedPtr == 0 || excpType == 0)
-                        {
-                            // Something very bad happened
-                            call_terminate(native_exception, unwind_exception);
-                        }
-                        if (catchType->can_catch(excpType, adjustedPtr))
-                        {
-                            // Found a matching handler. This is either search
-                            // phase or forced unwinding.
-                            assert(actions &
-                                   (_UA_SEARCH_PHASE | _UA_FORCE_UNWIND));
-                            results.ttypeIndex = ttypeIndex;
-                            results.actionRecord = actionRecord;
-                            results.adjustedPtr = adjustedPtr;
-                            results.reason = _URC_HANDLER_FOUND;
-                            return;
-                        }
-                    }
-                    // Scan next action ...
+              }
+              // Else this is a catch (T) clause and will never
+              //    catch a foreign exception
+              else if (native_exception) {
+                __cxa_exception* exception_header = (__cxa_exception*)(unwind_exception + 1) - 1;
+                void* adjustedPtr = get_thrown_object_ptr(unwind_exception);
+                const __shim_type_info* excpType =
+                    static_cast<const __shim_type_info*>(exception_header->exceptionType);
+                if (adjustedPtr == 0 || excpType == 0) {
+                  // Something very bad happened
+                  call_terminate(native_exception, unwind_exception);
                 }
-                else if (ttypeIndex < 0)
-                {
-                    // Found an exception specification.
-                    if (actions & _UA_FORCE_UNWIND) {
-                        // Skip if forced unwinding.
-                    } else if (native_exception) {
-                        // Does the exception spec catch this native exception?
-                        __cxa_exception* exception_header = (__cxa_exception*)(unwind_exception+1) - 1;
-                        void* adjustedPtr = get_thrown_object_ptr(unwind_exception);
-                        const __shim_type_info* excpType =
-                            static_cast<const __shim_type_info*>(exception_header->exceptionType);
-                        if (adjustedPtr == 0 || excpType == 0)
-                        {
-                            // Something very bad happened
-                            call_terminate(native_exception, unwind_exception);
-                        }
-                        if (exception_spec_can_catch(ttypeIndex, classInfo,
-                                                     ttypeEncoding, excpType,
-                                                     adjustedPtr,
-                                                     unwind_exception, base))
-                        {
-                            // Native exception caught by exception
-                            // specification.
-                            assert(actions & _UA_SEARCH_PHASE);
-                            results.ttypeIndex = ttypeIndex;
-                            results.actionRecord = actionRecord;
-                            results.adjustedPtr = adjustedPtr;
-                            results.reason = _URC_HANDLER_FOUND;
-                            return;
-                        }
-                    } else {
-                        // foreign exception caught by exception spec
-                        results.ttypeIndex = ttypeIndex;
-                        results.actionRecord = actionRecord;
-                        results.adjustedPtr =
-                            get_thrown_object_ptr(unwind_exception);
-                        results.reason = _URC_HANDLER_FOUND;
-                        return;
-                    }
-                    // Scan next action ...
-                } else {
-                    hasCleanup = true;
+                if (catchType->can_catch(excpType, adjustedPtr)) {
+                  // Found a matching handler. This is either search
+                  // phase or forced unwinding.
+                  assert(actions & (_UA_SEARCH_PHASE | _UA_FORCE_UNWIND));
+                  results.ttypeIndex = ttypeIndex;
+                  results.actionRecord = actionRecord;
+                  results.adjustedPtr = adjustedPtr;
+                  results.reason = _URC_HANDLER_FOUND;
+                  return;
                 }
-                const uint8_t* temp = action;
-                int64_t actionOffset = readSLEB128(&temp);
-                if (actionOffset == 0)
-                {
-                    // End of action list. If this is phase 2 and we have found
-                    // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
-                    // otherwise return _URC_CONTINUE_UNWIND.
-                    results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE
-                                         ? _URC_HANDLER_FOUND
-                                         : _URC_CONTINUE_UNWIND;
-                    return;
+              }
+              // Scan next action ...
+            } else if (ttypeIndex < 0) {
+              // Found an exception specification.
+              if (actions & _UA_FORCE_UNWIND) {
+                // Skip if forced unwinding.
+              } else if (native_exception) {
+                // Does the exception spec catch this native exception?
+                __cxa_exception* exception_header = (__cxa_exception*)(unwind_exception + 1) - 1;
+                void* adjustedPtr = get_thrown_object_ptr(unwind_exception);
+                const __shim_type_info* excpType =
+                    static_cast<const __shim_type_info*>(exception_header->exceptionType);
+                if (adjustedPtr == 0 || excpType == 0) {
+                  // Something very bad happened
+                  call_terminate(native_exception, unwind_exception);
+                }
+                if (exception_spec_can_catch(ttypeIndex, classInfo, ttypeEncoding, excpType, adjustedPtr,
+                                             unwind_exception, base)) {
+                  // Native exception caught by exception
+                  // specification.
+                  assert(actions & _UA_SEARCH_PHASE);
+                  results.ttypeIndex = ttypeIndex;
+                  results.actionRecord = actionRecord;
+                  results.adjustedPtr = adjustedPtr;
+                  results.reason = _URC_HANDLER_FOUND;
+                  return;
                 }
-                // Go to next action
-                action += actionOffset;
-            }  // there is no break out of this loop, only return
+              } else {
+                // foreign exception caught by exception spec
+                results.ttypeIndex = ttypeIndex;
+                results.actionRecord = actionRecord;
+                results.adjustedPtr = get_thrown_object_ptr(unwind_exception);
+                results.reason = _URC_HANDLER_FOUND;
+                return;
+              }
+              // Scan next action ...
+            } else {
+              hasCleanup = true;
+            }
+            const uint8_t* temp = action;
+            int64_t actionOffset = readSLEB128(&temp);
+            if (actionOffset == 0) {
+              // End of action list. If this is phase 2 and we have found
+              // a cleanup (ttypeIndex=0), return _URC_HANDLER_FOUND;
+              // otherwise return _URC_CONTINUE_UNWIND.
+              results.reason = hasCleanup && actions & _UA_CLEANUP_PHASE ? _URC_HANDLER_FOUND : _URC_CONTINUE_UNWIND;
+              return;
+            }
+            // Go to next action
+            action += actionOffset;
+          } // there is no break out of this loop, only return
         }
 #if !defined(__USING_SJLJ_EXCEPTIONS__) && !defined(__WASM_EXCEPTIONS__)
-        else if (ipOffset < start)
-        {
-            // There is no call site for this ip
-            // Something bad has happened.  We should never get here.
-            // Possible stack corruption.
-            call_terminate(native_exception, unwind_exception);
+        else if (ipOffset < start) {
+          // There is no call site for this ip
+          // Something bad has happened.  We should never get here.
+          // Possible stack corruption.
+          call_terminate(native_exception, unwind_exception);
         }
 #endif // !__USING_SJLJ_EXCEPTIONS__ && !__WASM_EXCEPTIONS__
     }  // there might be some tricky cases which break out of this loop
@@ -903,7 +879,7 @@ _UA_CLEANUP_PHASE
 */
 
 #if !defined(_LIBCXXABI_ARM_EHABI)
-#ifdef __WASM_EXCEPTIONS__
+#  ifdef __WASM_EXCEPTIONS__
 _Unwind_Reason_Code __gxx_personality_wasm0
 #elif defined(__SEH__) && !defined(__USING_SJLJ_EXCEPTIONS__)
 static _Unwind_Reason_Code __gxx_personality_imp
@@ -972,7 +948,7 @@ __gxx_personality_v0
             exc->languageSpecificData = results.languageSpecificData;
             exc->catchTemp = reinterpret_cast<void*>(results.landingPad);
             exc->adjustedPtr = results.adjustedPtr;
-#ifdef __WASM_EXCEPTIONS__
+#  ifdef __WASM_EXCEPTIONS__
             // Wasm only uses a single phase (_UA_SEARCH_PHASE), so save the
             // results here.
             set_registers(unwind_exception, context, results);

@aheejin

aheejin commented May 21, 2024

Copy link
Copy Markdown
Member Author

It is hard to fix the clang-format errors because the modified files generally don't conform to the clang-format style anyway, so clang-format my change currently affects hundreds of unrelated lines.

aheejin@aheejin:~/llvm-project/libunwind$ git clang-format main
changed files:
    libcxxabi/include/cxxabi.h
    libcxxabi/src/cxa_exception.cpp
    libcxxabi/src/cxa_personality.cpp

aheejin@aheejin:~/llvm-project/libunwind$ git diff --stat
 libcxxabi/include/cxxabi.h        |  13 +-
 libcxxabi/src/cxa_exception.cpp   |   2 +-
 libcxxabi/src/cxa_personality.cpp | 256 ++++++++++++++++++----------------------
 3 files changed, 123 insertions(+), 148 deletions(-)

@sbc100

sbc100 commented May 21, 2024

Copy link
Copy Markdown
Contributor

It is hard to fix the clang-format errors because the modified files generally don't conform to the clang-format style anyway, so clang-format my change currently affects hundreds of unrelated lines.

aheejin@aheejin:~/llvm-project/libunwind$ git clang-format main
changed files:
    libcxxabi/include/cxxabi.h
    libcxxabi/src/cxa_exception.cpp
    libcxxabi/src/cxa_personality.cpp

aheejin@aheejin:~/llvm-project/libunwind$ git diff --stat
 libcxxabi/include/cxxabi.h        |  13 +-
 libcxxabi/src/cxa_exception.cpp   |   2 +-
 libcxxabi/src/cxa_personality.cpp | 256 ++++++++++++++++++----------------------
 3 files changed, 123 insertions(+), 148 deletions(-)

I think in these cases is fine to ignore the warnings to fit in with existing style.

@aheejin

aheejin commented May 22, 2024

Copy link
Copy Markdown
Member Author

The other CI failure doesn't seem to be related. Merging.

@aheejin
aheejin merged commit 64f6406 into llvm:main May 22, 2024
@aheejin
aheejin deleted the wasm_exceptions branch May 22, 2024 04:01
aheejin added a commit to emscripten-core/emscripten that referenced this pull request Nov 20, 2024
paleauraaaa pushed a commit to paleauraaaa/llvm-project that referenced this pull request Oct 7, 2026
…92840)

We've decided to change `__USING_WASM_EXCEPTIONS__` preprocessor to
`__WASM_EXCEPTIONS__` given that it's more concise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++abi libc++abi C++ Runtime Library. Not libc++. libunwind

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants