[libcxx-commits] [libcxx] Fix typeinfo for undefined sanitizer (PR #121228)

Valery Mironov via libcxx-commits libcxx-commits at lists.llvm.org
Fri Dec 27 23:04:29 PST 2024


https://github.com/MBkkt updated https://github.com/llvm/llvm-project/pull/121228

>From 3d8fb18949dba038667e6d8983948b85a73cefdb Mon Sep 17 00:00:00 2001
From: Valery Mironov <valera.mironow at gmail.com>
Date: Fri, 27 Dec 2024 23:39:58 +0300
Subject: [PATCH 1/2] Fix typeinfo for undefined sanitizer

This happened to me when I compiled my code on x86_64 linux (ubuntu 24.04) with clang-18 and everything except glibc built from source (llvm 19, llvm source)

I found this solution and luckily it works!
https://github.com/emscripten-core/emscripten/pull/13367
https://github.com/emscripten-core/emscripten/issues/13330

I saw that issue is abandoned, so I decided to try to push it in upstream
---
 libcxx/include/typeinfo | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/include/typeinfo b/libcxx/include/typeinfo
index 799c6ebd5ecbbf..a900ccaf7e24bb 100644
--- a/libcxx/include/typeinfo
+++ b/libcxx/include/typeinfo
@@ -315,7 +315,8 @@ public:
 
   _LIBCPP_HIDE_FROM_ABI size_t hash_code() const _NOEXCEPT { return __impl::__hash(__type_name); }
 
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator==(const type_info& __arg) const _NOEXCEPT {
+  // We need to inline this code because otherwise we will get a stack overflow with undefined sanitizer.
+  _LIBCPP_HIDE_FROM_ABI _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator==(const type_info& __arg) const _NOEXCEPT {
     // When evaluated in a constant expression, both type infos simply can't come
     // from different translation units, so it is sufficient to compare their addresses.
     if (__libcpp_is_constant_evaluated()) {

>From 7924abbd54b319d7f8504d135071a935142b8249 Mon Sep 17 00:00:00 2001
From: Valery Mironov <valera.mironow at gmail.com>
Date: Sat, 28 Dec 2024 10:04:20 +0300
Subject: [PATCH 2/2] Format changes

---
 libcxx/include/typeinfo | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libcxx/include/typeinfo b/libcxx/include/typeinfo
index a900ccaf7e24bb..6bca852e218709 100644
--- a/libcxx/include/typeinfo
+++ b/libcxx/include/typeinfo
@@ -316,7 +316,8 @@ public:
   _LIBCPP_HIDE_FROM_ABI size_t hash_code() const _NOEXCEPT { return __impl::__hash(__type_name); }
 
   // We need to inline this code because otherwise we will get a stack overflow with undefined sanitizer.
-  _LIBCPP_HIDE_FROM_ABI _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator==(const type_info& __arg) const _NOEXCEPT {
+  _LIBCPP_HIDE_FROM_ABI _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR_SINCE_CXX23 bool
+  operator==(const type_info& __arg) const _NOEXCEPT {
     // When evaluated in a constant expression, both type infos simply can't come
     // from different translation units, so it is sufficient to compare their addresses.
     if (__libcpp_is_constant_evaluated()) {



More information about the libcxx-commits mailing list