[libcxx-commits] [libcxxabi] 3723ac3 - [libc++abi][NFC] Return const void* from __dynamic_cast (#223737)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Sep 16 03:18:42 PDT 2026
Author: Nikolas Klauser
Date: 2026-09-16T12:18:35+02:00
New Revision: 3723ac3407bc09d0b822df08f17228eed8fa76a3
URL: https://github.com/llvm/llvm-project/commit/3723ac3407bc09d0b822df08f17228eed8fa76a3
DIFF: https://github.com/llvm/llvm-project/commit/3723ac3407bc09d0b822df08f17228eed8fa76a3.diff
LOG: [libc++abi][NFC] Return const void* from __dynamic_cast (#223737)
`__dynamic_cast` is only called magically by the compiler, so it really
doesn't matter what the exact protoype is as long as it's ABI
compatible. Making the return type a `const void*` simplifies the
implementation a bit though.
Added:
Modified:
libcxxabi/src/private_typeinfo.cpp
Removed:
################################################################################
diff --git a/libcxxabi/src/private_typeinfo.cpp b/libcxxabi/src/private_typeinfo.cpp
index c94ebad26f3f7..1b74bd28435db 100644
--- a/libcxxabi/src/private_typeinfo.cpp
+++ b/libcxxabi/src/private_typeinfo.cpp
@@ -872,7 +872,7 @@ bool __pointer_to_member_type_info::can_catch_nested(const __shim_type_info* thr
// (static_ptr, static_type), then return dynamic_ptr.
// Else return nullptr.
-extern "C" _LIBCXXABI_FUNC_VIS void*
+extern "C" _LIBCXXABI_FUNC_VIS const void*
__dynamic_cast(const void* static_ptr,
const __class_type_info* static_type,
const __class_type_info* dst_type,
@@ -880,28 +880,20 @@ __dynamic_cast(const void* static_ptr,
// Get (dynamic_ptr, dynamic_type) from static_ptr
derived_object_info derived_info = dyn_cast_get_derived_info(static_ptr);
- // Initialize answer to nullptr. This will be changed from the search
- // results if a non-null answer is found. Regardless, this is what will
- // be returned.
- const void* dst_ptr = 0;
-
// Find out if we can use a giant short cut in the search
if (is_equal(derived_info.dynamic_type, dst_type, false)) {
- dst_ptr = dyn_cast_to_derived(
+ return dyn_cast_to_derived(
static_ptr, derived_info.dynamic_ptr, static_type, dst_type, derived_info.offset_to_derived, src2dst_offset);
} else {
// Optimize toward downcasting: let's first try to do a downcast before
// falling back to the slow path.
- dst_ptr = dyn_cast_try_downcast(
- static_ptr, derived_info.dynamic_ptr, dst_type, derived_info.dynamic_type, src2dst_offset);
+ if (const void* res = dyn_cast_try_downcast(
+ static_ptr, derived_info.dynamic_ptr, dst_type, derived_info.dynamic_type, src2dst_offset))
+ return res;
- if (!dst_ptr) {
- dst_ptr = dyn_cast_slow(
- static_ptr, derived_info.dynamic_ptr, static_type, dst_type, derived_info.dynamic_type, src2dst_offset);
- }
+ return dyn_cast_slow(
+ static_ptr, derived_info.dynamic_ptr, static_type, dst_type, derived_info.dynamic_type, src2dst_offset);
}
-
- return const_cast<void*>(dst_ptr);
}
#pragma GCC diagnostic pop
More information about the libcxx-commits
mailing list