https://github.com/DanielKristofKiss updated 
https://github.com/llvm/llvm-project/pull/98648

>From 240add341b2c0a1be3d1ebf21938e70e51669126 Mon Sep 17 00:00:00 2001
From: Daniel Kiss <daniel.k...@arm.com>
Date: Fri, 12 Jul 2024 15:56:40 +0200
Subject: [PATCH 1/2] [libunwind] Fix ubsan issue

---
 libunwind/src/UnwindCursor.hpp | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 2ec60e4c123d5..01a61cea53ffa 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -230,8 +230,13 @@ void DwarfFDECache<A>::iterateCacheEntries(void (*func)(
 }
 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
 
-
-#define arrayoffsetof(type, index, field) ((size_t)(&((type *)0)[index].field))
+template <typename TYPE, typename FIELD>
+__attribute__((no_sanitize("undefined"))) static inline size_t
+_arrayoffsetof(int index, FIELD TYPE::*field) {
+  return ((size_t)(&(((TYPE *)0)[index].*field)));
+}
+#define arrayoffsetof(type, index, field)                                      
\
+  _arrayoffsetof<struct type>(index, &type::field)
 
 #if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
 template <typename A> class UnwindSectionHeader {

>From a9f5774e9847082ce16f2a04e8a4d4ce456dfc62 Mon Sep 17 00:00:00 2001
From: Daniel Kiss <daniel.k...@arm.com>
Date: Fri, 12 Jul 2024 20:59:48 +0200
Subject: [PATCH 2/2] Simplify the code.

---
 libunwind/src/UnwindCursor.hpp | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 01a61cea53ffa..1fa95b4ebee19 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -230,13 +230,8 @@ void DwarfFDECache<A>::iterateCacheEntries(void (*func)(
 }
 #endif // defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
 
-template <typename TYPE, typename FIELD>
-__attribute__((no_sanitize("undefined"))) static inline size_t
-_arrayoffsetof(int index, FIELD TYPE::*field) {
-  return ((size_t)(&(((TYPE *)0)[index].*field)));
-}
 #define arrayoffsetof(type, index, field)                                      
\
-  _arrayoffsetof<struct type>(index, &type::field)
+  (sizeof(type) * (index) + offsetof(type, field))
 
 #if defined(_LIBUNWIND_SUPPORT_COMPACT_UNWIND)
 template <typename A> class UnwindSectionHeader {

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to