[llvm-branch-commits] [libcxxabi] [libc++abi] Remove has_path_to_static_ptr from dynamic_cast (PR #243821)

Nikolas Klauser via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Nov 18 04:01:29 PST 2026


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/243821

`path_dst_ptr_to_static_ptr` already contains whether we found a path to
static_ptr, so there is no need to track it explicitly.


>From 9d384c528552d54182988320e52ff3be908c080d Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Tue, 17 Nov 2026 18:15:38 +0100
Subject: [PATCH] [libc++abi] Remove has_path_to_static_ptr from dynamic_cast

`path_dst_ptr_to_static_ptr` already contains whether we found a path to
static_ptr, so there is no need to track it explicitly.
---
 libcxxabi/src/private_typeinfo.cpp | 20 +++++++-------------
 libcxxabi/src/private_typeinfo.h   |  2 --
 2 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/libcxxabi/src/private_typeinfo.cpp b/libcxxabi/src/private_typeinfo.cpp
index 7e5c7b657fe84..a42a61a61538c 100644
--- a/libcxxabi/src/private_typeinfo.cpp
+++ b/libcxxabi/src/private_typeinfo.cpp
@@ -178,7 +178,6 @@ const void* dyn_cast_to_derived(
       path_kind::unknown,
       path_kind::unknown,
       0,
-      0,
       true,
       true, // has_unique_dst_type
       false,
@@ -213,7 +212,6 @@ const void* dyn_cast_to_derived(
         path_kind::unknown,
         path_kind::unknown,
         0,
-        0,
         true,
         true, // has_unique_dst_type
         false,
@@ -267,7 +265,6 @@ const void* dyn_cast_try_downcast(
       path_kind::unknown,
       path_kind::unknown,
       0,
-      0,
       true,
       true, // has_unique_dst_type
       false,
@@ -303,7 +300,6 @@ const void* dyn_cast_slow(
       path_kind::unknown,
       path_kind::unknown,
       0,
-      0,
       true,
       0,
       false,
@@ -339,7 +335,6 @@ const void* dyn_cast_slow(
         path_kind::unknown,
         path_kind::unknown,
         0,
-        0,
         true,
         0,
         false,
@@ -350,7 +345,7 @@ const void* dyn_cast_slow(
   if (res == result::failure)
     return nullptr;
   // Query the search.
-  if (info.has_path_to_static_ptr) {
+  if (info.path_dst_ptr_to_static_ptr != path_kind::unknown) {
     if (info.path_dst_ptr_to_static_ptr == path_kind::public_path ||
         (info.number_to_dst_ptr == 0 && info.path_dynamic_ptr_to_static_ptr == path_kind::public_path &&
          info.path_dynamic_ptr_to_dst_ptr == path_kind::public_path))
@@ -923,7 +918,6 @@ result __class_type_info::process_static_type_above_dst(
     // First time here
     info->dst_ptr_leading_to_static_ptr = dst_ptr;
     info->path_dst_ptr_to_static_ptr    = path_below;
-    info->has_path_to_static_ptr        = true;
     // If there is only one dst_type in the entire tree and the path from
     //    there to here is public then we are done!
     return info->has_unique_dst_type && info->path_dst_ptr_to_static_ptr == path_kind::public_path
@@ -1086,7 +1080,7 @@ result __vmi_class_type_info::search_below_dst_impl(
       if (!does_dst_type_point_to_our_static_type) {
         // If there exists another dst with a private path to (static_ptr, static_type), then the cast from
         // (dynamic_ptr, dynamic_type) to dst_type is now ambiguous, so stop search.
-        if (info->has_path_to_static_ptr && info->path_dst_ptr_to_static_ptr == path_kind::not_public_path)
+        if (info->path_dst_ptr_to_static_ptr == path_kind::not_public_path)
           return result::failure;
 
         // We found a dst_type that doesn't point to (static_ptr, static_type)
@@ -1104,7 +1098,7 @@ result __vmi_class_type_info::search_below_dst_impl(
     if (result res = p->search_below_dst<use_strcmp>(info, current_ptr, path_below); res != result::unknown)
       return res;
     if (++p < e) {
-      if ((__flags & __diamond_shaped_mask) || info->has_path_to_static_ptr) {
+      if ((__flags & __diamond_shaped_mask) || info->path_dst_ptr_to_static_ptr != path_kind::unknown) {
         // If there are multiple paths to a base above from here, or if
         //    a dst_type pointing to (static_ptr, static_type) has been found,
         //    then there is no way to break out of this loop early unless
@@ -1122,7 +1116,7 @@ result __vmi_class_type_info::search_below_dst_impl(
           //    then the only reason to continue the search is to make sure
           //    no other dst_type points to (static_ptr, static_type).
           //    If !diamond, then we don't need to search here.
-          if (info->has_path_to_static_ptr && info->path_dst_ptr_to_static_ptr == path_kind::public_path)
+          if (info->path_dst_ptr_to_static_ptr == path_kind::public_path)
             break;
           if (result res = p->search_below_dst<use_strcmp>(info, current_ptr, path_below); res != result::unknown)
             return res;
@@ -1141,7 +1135,7 @@ result __vmi_class_type_info::search_below_dst_impl(
           //    and to check for other dst_types.
           //    If !diamond & !repeat, then there is not a pointer to (static_ptr, static_type)
           //    and not a dst_type under here.
-          if (info->has_path_to_static_ptr)
+          if (info->path_dst_ptr_to_static_ptr != path_kind::unknown)
             break;
           if (result res = p->search_below_dst<use_strcmp>(info, current_ptr, path_below); res != result::unknown)
             return res;
@@ -1207,7 +1201,7 @@ result __si_class_type_info::search_below_dst_impl(
     if (!does_dst_type_point_to_our_static_type) {
       // If there exists another dst with a private path to (static_ptr, static_type), then the cast from
       // (dynamic_ptr, dynamic_type) to dst_type is now ambiguous.
-      if (info->has_path_to_static_ptr && info->path_dst_ptr_to_static_ptr == path_kind::not_public_path)
+      if (info->path_dst_ptr_to_static_ptr == path_kind::not_public_path)
         return result::failure;
 
       // We found a dst_type that doesn't point to (static_ptr, static_type)
@@ -1247,7 +1241,7 @@ result __class_type_info::search_below_dst_impl(
 
   // If there exists another dst with a private path to (static_ptr, static_type), then the cast from
   // (dynamic_ptr, dynamic_type) to dst_type is now ambiguous.
-  if (info->has_path_to_static_ptr && info->path_dst_ptr_to_static_ptr == path_kind::not_public_path)
+  if (info->path_dst_ptr_to_static_ptr == path_kind::not_public_path)
     return result::failure;
 
   // We have haven't been here before
diff --git a/libcxxabi/src/private_typeinfo.h b/libcxxabi/src/private_typeinfo.h
index 83a083c6eda7b..d73ef1439e756 100644
--- a/libcxxabi/src/private_typeinfo.h
+++ b/libcxxabi/src/private_typeinfo.h
@@ -100,8 +100,6 @@ struct _LIBCXXABI_HIDDEN __dynamic_cast_info {
   //    (not used if there is a (static_ptr, static_type) above a dst_type).
   path_kind path_dynamic_ptr_to_dst_ptr;
 
-  // Whether we found dst_types below (static_ptr, static_type)
-  bool has_path_to_static_ptr;
   // Number of dst_types not below (static_ptr, static_type)
   int number_to_dst_ptr;
 



More information about the llvm-branch-commits mailing list