1 //===----------------------- private_typeinfo.cpp -------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "private_typeinfo.h"
11 
12 // The flag _LIBCXX_DYNAMIC_FALLBACK is used to make dynamic_cast more
13 // forgiving when type_info's mistakenly have hidden visibility and thus
14 // multiple type_infos can exist for a single type.
15 //
16 // When _LIBCXX_DYNAMIC_FALLBACK is defined, and only in the case where
17 // there is a detected inconsistency in the type_info hierarchy during a
18 // dynamic_cast, then the equality operation will fall back to using strcmp
19 // on type_info names to determine type_info equality.
20 //
21 // This change happens *only* under dynamic_cast, and only when
22 // dynamic_cast is faced with the choice:  abort, or possibly give back the
23 // wrong answer.  If when the dynamic_cast is done with this fallback
24 // algorithm and an inconsistency is still detected, dynamic_cast will call
25 // abort with an appropriate message.
26 //
27 // The current implementation of _LIBCXX_DYNAMIC_FALLBACK requires a
28 // printf-like function called syslog:
29 //
30 //     void syslog(int facility_priority, const char* format, ...);
31 //
32 // If you want this functionality but your platform doesn't have syslog,
33 // just implement it in terms of fprintf(stderr, ...).
34 //
35 // _LIBCXX_DYNAMIC_FALLBACK is currently off by default.
36 
37 
38 #include <string.h>
39 
40 
41 #ifdef _LIBCXX_DYNAMIC_FALLBACK
42 #include "abort_message.h"
43 #include <sys/syslog.h>
44 #endif
45 
46 // On Windows, typeids are different between DLLs and EXEs, so comparing
47 // type_info* will work for typeids from the same compiled file but fail
48 // for typeids from a DLL and an executable. Among other things, exceptions
49 // are not caught by handlers since can_catch() returns false.
50 //
51 // Defining _LIBCXX_DYNAMIC_FALLBACK does not help since can_catch() calls
52 // is_equal() with use_strcmp=false so the string names are not compared.
53 
54 #ifdef _WIN32
55 #include <string.h>
56 #endif
57 
58 namespace __cxxabiv1
59 {
60 
61 #pragma GCC visibility push(hidden)
62 
63 inline
64 bool
65 is_equal(const std::type_info* x, const std::type_info* y, bool use_strcmp)
66 {
67 #ifndef _WIN32
68     if (!use_strcmp)
69         return x == y;
70     return strcmp(x->name(), y->name()) == 0;
71 #else
72     return (x == y) || (strcmp(x->name(), y->name()) == 0);
73 #endif
74 }
75 
76 
77 // __shim_type_info
78 
79 __shim_type_info::~__shim_type_info()
80 {
81 }
82 
83 void __shim_type_info::noop1() const {}
84 void __shim_type_info::noop2() const {}
85 
86 // __fundamental_type_info
87 
88 // This miraculously (compiler magic) emits the type_info's for:
89 //   1. all of the fundamental types
90 //   2. pointers to all of the fundamental types
91 //   3. pointers to all of the const fundamental types
92 __fundamental_type_info::~__fundamental_type_info()
93 {
94 }
95 
96 // __array_type_info
97 
98 __array_type_info::~__array_type_info()
99 {
100 }
101 
102 // __function_type_info
103 
104 __function_type_info::~__function_type_info()
105 {
106 }
107 
108 // __enum_type_info
109 
110 __enum_type_info::~__enum_type_info()
111 {
112 }
113 
114 // __class_type_info
115 
116 __class_type_info::~__class_type_info()
117 {
118 }
119 
120 // __si_class_type_info
121 
122 __si_class_type_info::~__si_class_type_info()
123 {
124 }
125 
126 // __vmi_class_type_info
127 
128 __vmi_class_type_info::~__vmi_class_type_info()
129 {
130 }
131 
132 // __pbase_type_info
133 
134 __pbase_type_info::~__pbase_type_info()
135 {
136 }
137 
138 // __pointer_type_info
139 
140 __pointer_type_info::~__pointer_type_info()
141 {
142 }
143 
144 // __pointer_to_member_type_info
145 
146 __pointer_to_member_type_info::~__pointer_to_member_type_info()
147 {
148 }
149 
150 // can_catch
151 
152 // A handler is a match for an exception object of type E if
153 //   1. The handler is of type cv T or cv T& and E and T are the same type
154 //      (ignoring the top-level cv-qualifiers), or
155 //   2. the handler is of type cv T or cv T& and T is an unambiguous public
156 //       base class of E, or
157 //   3. the handler is of type cv1 T* cv2 and E is a pointer type that can be
158 //      converted to the type of the handler by either or both of
159 //      A. a standard pointer conversion (4.10) not involving conversions to
160 //         pointers to private or protected or ambiguous classes
161 //      B. a qualification conversion
162 //   4. the handler is a pointer or pointer to member type and E is
163 //      std::nullptr_t.
164 
165 // adjustedPtr:
166 //
167 // catch (A& a) : adjustedPtr == &a
168 // catch (A* a) : adjustedPtr == a
169 // catch (A** a) : adjustedPtr == a
170 //
171 // catch (D2& d2) : adjustedPtr == &d2  (d2 is base class of thrown object)
172 // catch (D2* d2) : adjustedPtr == d2
173 // catch (D2*& d2) : adjustedPtr == d2
174 //
175 // catch (...) : adjustedPtr == & of the exception
176 //
177 // If the thrown type is nullptr_t and the caught type is a pointer to
178 // member type, adjustedPtr points to a statically-allocated null pointer
179 // representation of that type.
180 
181 // Handles bullet 1
182 bool
183 __fundamental_type_info::can_catch(const __shim_type_info* thrown_type,
184                                    void*&) const
185 {
186     return is_equal(this, thrown_type, false);
187 }
188 
189 bool
190 __array_type_info::can_catch(const __shim_type_info*, void*&) const
191 {
192     // We can get here if someone tries to catch an array by reference.
193     //   However if someone tries to throw an array, it immediately gets
194     //   converted to a pointer, which will not convert back to an array
195     //   at the catch clause.  So this can never catch anything.
196     return false;
197 }
198 
199 bool
200 __function_type_info::can_catch(const __shim_type_info*, void*&) const
201 {
202     // We can get here if someone tries to catch a function by reference.
203     //   However if someone tries to throw a function, it immediately gets
204     //   converted to a pointer, which will not convert back to a function
205     //   at the catch clause.  So this can never catch anything.
206     return false;
207 }
208 
209 // Handles bullet 1
210 bool
211 __enum_type_info::can_catch(const __shim_type_info* thrown_type,
212                             void*&) const
213 {
214     return is_equal(this, thrown_type, false);
215 }
216 
217 #ifdef __clang__
218 #pragma clang diagnostic push
219 #pragma clang diagnostic ignored "-Wmissing-field-initializers"
220 #endif
221 
222 // Handles bullets 1 and 2
223 bool
224 __class_type_info::can_catch(const __shim_type_info* thrown_type,
225                              void*& adjustedPtr) const
226 {
227     // bullet 1
228     if (is_equal(this, thrown_type, false))
229         return true;
230     const __class_type_info* thrown_class_type =
231         dynamic_cast<const __class_type_info*>(thrown_type);
232     if (thrown_class_type == 0)
233         return false;
234     // bullet 2
235     __dynamic_cast_info info = {thrown_class_type, 0, this, -1, 0};
236     info.number_of_dst_type = 1;
237     thrown_class_type->has_unambiguous_public_base(&info, adjustedPtr, public_path);
238     if (info.path_dst_ptr_to_static_ptr == public_path)
239     {
240         adjustedPtr = const_cast<void*>(info.dst_ptr_leading_to_static_ptr);
241         return true;
242     }
243     return false;
244 }
245 
246 #ifdef __clang__
247 #pragma clang diagnostic pop
248 #endif
249 
250 void
251 __class_type_info::process_found_base_class(__dynamic_cast_info* info,
252                                                void* adjustedPtr,
253                                                int path_below) const
254 {
255     if (info->dst_ptr_leading_to_static_ptr == 0)
256     {
257         // First time here
258         info->dst_ptr_leading_to_static_ptr = adjustedPtr;
259         info->path_dst_ptr_to_static_ptr = path_below;
260         info->number_to_static_ptr = 1;
261     }
262     else if (info->dst_ptr_leading_to_static_ptr == adjustedPtr)
263     {
264         // We've been here before.  Update path to "most public"
265         if (info->path_dst_ptr_to_static_ptr == not_public_path)
266             info->path_dst_ptr_to_static_ptr = path_below;
267     }
268     else
269     {
270         // We've detected an ambiguous cast from (thrown_class_type, adjustedPtr)
271         //   to a static_type
272         info->number_to_static_ptr += 1;
273         info->path_dst_ptr_to_static_ptr = not_public_path;
274         info->search_done = true;
275     }
276 }
277 
278 void
279 __class_type_info::has_unambiguous_public_base(__dynamic_cast_info* info,
280                                                void* adjustedPtr,
281                                                int path_below) const
282 {
283     if (is_equal(this, info->static_type, false))
284         process_found_base_class(info, adjustedPtr, path_below);
285 }
286 
287 void
288 __si_class_type_info::has_unambiguous_public_base(__dynamic_cast_info* info,
289                                                   void* adjustedPtr,
290                                                   int path_below) const
291 {
292     if (is_equal(this, info->static_type, false))
293         process_found_base_class(info, adjustedPtr, path_below);
294     else
295         __base_type->has_unambiguous_public_base(info, adjustedPtr, path_below);
296 }
297 
298 void
299 __base_class_type_info::has_unambiguous_public_base(__dynamic_cast_info* info,
300                                                     void* adjustedPtr,
301                                                     int path_below) const
302 {
303     ptrdiff_t offset_to_base = 0;
304     if (adjustedPtr != nullptr)
305     {
306         offset_to_base = __offset_flags >> __offset_shift;
307         if (__offset_flags & __virtual_mask)
308         {
309             const char* vtable = *static_cast<const char*const*>(adjustedPtr);
310             offset_to_base = *reinterpret_cast<const ptrdiff_t*>(vtable + offset_to_base);
311         }
312     }
313     __base_type->has_unambiguous_public_base(
314             info,
315             static_cast<char*>(adjustedPtr) + offset_to_base,
316             (__offset_flags & __public_mask) ? path_below : not_public_path);
317 }
318 
319 void
320 __vmi_class_type_info::has_unambiguous_public_base(__dynamic_cast_info* info,
321                                                    void* adjustedPtr,
322                                                    int path_below) const
323 {
324     if (is_equal(this, info->static_type, false))
325         process_found_base_class(info, adjustedPtr, path_below);
326     else
327     {
328         typedef const __base_class_type_info* Iter;
329         const Iter e = __base_info + __base_count;
330         Iter p = __base_info;
331         p->has_unambiguous_public_base(info, adjustedPtr, path_below);
332         if (++p < e)
333         {
334             do
335             {
336                 p->has_unambiguous_public_base(info, adjustedPtr, path_below);
337                 if (info->search_done)
338                     break;
339             } while (++p < e);
340         }
341     }
342 }
343 
344 // Handles bullet 1 for both pointers and member pointers
345 bool
346 __pbase_type_info::can_catch(const __shim_type_info* thrown_type,
347                              void*&) const
348 {
349     bool use_strcmp = this->__flags & (__incomplete_class_mask |
350                                        __incomplete_mask);
351     if (!use_strcmp) {
352         const __pbase_type_info* thrown_pbase = dynamic_cast<const __pbase_type_info*>(
353                 thrown_type);
354         if (!thrown_pbase) return false;
355         use_strcmp = thrown_pbase->__flags & (__incomplete_class_mask |
356                                               __incomplete_mask);
357     }
358     return is_equal(this, thrown_type, use_strcmp);
359 }
360 
361 #ifdef __clang__
362 #pragma clang diagnostic push
363 #pragma clang diagnostic ignored "-Wmissing-field-initializers"
364 #endif
365 
366 // Handles bullets 1, 3 and 4
367 // NOTE: It might not be safe to adjust the pointer if it is not not a pointer
368 // type. Only adjust the pointer after we know it is safe to do so.
369 bool
370 __pointer_type_info::can_catch(const __shim_type_info* thrown_type,
371                                void*& adjustedPtr) const
372 {
373     // bullet 4
374     if (is_equal(thrown_type, &typeid(std::nullptr_t), false)) {
375       adjustedPtr = nullptr;
376       return true;
377     }
378 
379     // bullet 1
380     if (__pbase_type_info::can_catch(thrown_type, adjustedPtr)) {
381         if (adjustedPtr != NULL)
382             adjustedPtr = *static_cast<void**>(adjustedPtr);
383         return true;
384     }
385     // bullet 3
386     const __pointer_type_info* thrown_pointer_type =
387         dynamic_cast<const __pointer_type_info*>(thrown_type);
388     if (thrown_pointer_type == 0)
389         return false;
390     // Do the dereference adjustment
391     if (adjustedPtr != NULL)
392         adjustedPtr = *static_cast<void**>(adjustedPtr);
393     // bullet 3B
394     if (thrown_pointer_type->__flags & ~__flags)
395         return false;
396     if (is_equal(__pointee, thrown_pointer_type->__pointee, false))
397         return true;
398     // bullet 3A
399     if (is_equal(__pointee, &typeid(void), false)) {
400         // pointers to functions cannot be converted to void*.
401         // pointers to member functions are not handled here.
402         const __function_type_info* thrown_function =
403             dynamic_cast<const __function_type_info*>(thrown_pointer_type->__pointee);
404         return (thrown_function == nullptr);
405     }
406     // Handle pointer to pointer
407     const __pointer_type_info* nested_pointer_type =
408         dynamic_cast<const __pointer_type_info*>(__pointee);
409     if (nested_pointer_type) {
410         if (~__flags & __const_mask) return false;
411         return nested_pointer_type->can_catch_nested(thrown_pointer_type->__pointee);
412     }
413 
414     // Handle pointer to pointer to member
415     const __pointer_to_member_type_info* member_ptr_type =
416         dynamic_cast<const __pointer_to_member_type_info*>(__pointee);
417     if (member_ptr_type) {
418         if (~__flags & __const_mask) return false;
419         return member_ptr_type->can_catch_nested(thrown_pointer_type->__pointee);
420     }
421 
422     // Handle pointer to class type
423     const __class_type_info* catch_class_type =
424         dynamic_cast<const __class_type_info*>(__pointee);
425     if (catch_class_type == 0)
426         return false;
427     const __class_type_info* thrown_class_type =
428         dynamic_cast<const __class_type_info*>(thrown_pointer_type->__pointee);
429     if (thrown_class_type == 0)
430         return false;
431     __dynamic_cast_info info = {thrown_class_type, 0, catch_class_type, -1, 0};
432     info.number_of_dst_type = 1;
433     thrown_class_type->has_unambiguous_public_base(&info, adjustedPtr, public_path);
434     if (info.path_dst_ptr_to_static_ptr == public_path)
435     {
436         if (adjustedPtr != NULL)
437             adjustedPtr = const_cast<void*>(info.dst_ptr_leading_to_static_ptr);
438         return true;
439     }
440     return false;
441 }
442 
443 bool __pointer_type_info::can_catch_nested(
444     const __shim_type_info* thrown_type) const
445 {
446   const __pointer_type_info* thrown_pointer_type =
447         dynamic_cast<const __pointer_type_info*>(thrown_type);
448     if (thrown_pointer_type == 0)
449         return false;
450     // bullet 3B
451     if (thrown_pointer_type->__flags & ~__flags)
452         return false;
453     if (is_equal(__pointee, thrown_pointer_type->__pointee, false))
454         return true;
455     // If the pointed to types differ then the catch type must be const
456     // qualified.
457     if (~__flags & __const_mask)
458         return false;
459 
460     // Handle pointer to pointer
461     const __pointer_type_info* nested_pointer_type =
462         dynamic_cast<const __pointer_type_info*>(__pointee);
463     if (nested_pointer_type) {
464         return nested_pointer_type->can_catch_nested(
465             thrown_pointer_type->__pointee);
466     }
467 
468     // Handle pointer to pointer to member
469     const __pointer_to_member_type_info* member_ptr_type =
470         dynamic_cast<const __pointer_to_member_type_info*>(__pointee);
471     if (member_ptr_type) {
472         return member_ptr_type->can_catch_nested(thrown_pointer_type->__pointee);
473     }
474 
475     return false;
476 }
477 
478 bool __pointer_to_member_type_info::can_catch(
479     const __shim_type_info* thrown_type, void*& adjustedPtr) const {
480     // bullet 4
481     if (is_equal(thrown_type, &typeid(std::nullptr_t), false)) {
482       // We assume that the pointer to member representation is the same for
483       // all pointers to data members and for all pointers to member functions.
484       struct X {};
485       if (dynamic_cast<const __function_type_info*>(__pointee)) {
486         static int (X::*const null_ptr_rep)() = nullptr;
487         adjustedPtr = const_cast<int (X::**)()>(&null_ptr_rep);
488       } else {
489         static int X::*const null_ptr_rep = nullptr;
490         adjustedPtr = const_cast<int X::**>(&null_ptr_rep);
491       }
492       return true;
493     }
494 
495     // bullet 1
496     if (__pbase_type_info::can_catch(thrown_type, adjustedPtr))
497         return true;
498 
499     const __pointer_to_member_type_info* thrown_pointer_type =
500         dynamic_cast<const __pointer_to_member_type_info*>(thrown_type);
501     if (thrown_pointer_type == 0)
502         return false;
503     if (thrown_pointer_type->__flags & ~__flags)
504         return false;
505     if (!is_equal(__pointee, thrown_pointer_type->__pointee, false))
506         return false;
507     if (is_equal(__context, thrown_pointer_type->__context, false))
508         return true;
509 
510     // [except.handle] does not allow the pointer-to-member conversions mentioned
511     // in [mem.conv] to take place. For this reason we don't check Derived->Base
512     // for Derived->Base conversions.
513 
514     return false;
515 }
516 
517 bool __pointer_to_member_type_info::can_catch_nested(
518     const __shim_type_info* thrown_type) const
519 {
520     const __pointer_to_member_type_info* thrown_member_ptr_type =
521         dynamic_cast<const __pointer_to_member_type_info*>(thrown_type);
522     if (thrown_member_ptr_type == 0)
523         return false;
524     if (~__flags & thrown_member_ptr_type->__flags)
525         return false;
526     if (!is_equal(__pointee, thrown_member_ptr_type->__pointee, false))
527         return false;
528     if (!is_equal(__context, thrown_member_ptr_type->__context, false))
529         return false;
530     return true;
531 }
532 
533 #ifdef __clang__
534 #pragma clang diagnostic pop
535 #endif
536 
537 #pragma GCC visibility pop
538 #pragma GCC visibility push(default)
539 
540 #ifdef __clang__
541 #pragma clang diagnostic push
542 #pragma clang diagnostic ignored "-Wmissing-field-initializers"
543 #endif
544 
545 // __dynamic_cast
546 
547 // static_ptr: pointer to an object of type static_type; nonnull, and since the
548 //   object is polymorphic, *(void**)static_ptr is a virtual table pointer.
549 //   static_ptr is &v in the expression dynamic_cast<T>(v).
550 // static_type: static type of the object pointed to by static_ptr.
551 // dst_type: destination type of the cast (the "T" in "dynamic_cast<T>(v)").
552 // src2dst_offset: a static hint about the location of the
553 //                 source subobject with respect to the complete object;
554 //                 special negative values are:
555 //                     -1: no hint
556 //                     -2: static_type is not a public base of dst_type
557 //                     -3: static_type is a multiple public base type but never a
558 //                         virtual base type
559 //                 otherwise, the static_type type is a unique public nonvirtual
560 //                 base type of dst_type at offset src2dst_offset from the
561 //                 origin of dst_type.
562 //
563 // (dynamic_ptr, dynamic_type) are the run time type of the complete object
564 // referred to by static_ptr and a pointer to it.  These can be found from
565 // static_ptr for polymorphic types.
566 // static_type is guaranteed to be a polymorphic type.
567 //
568 // (dynamic_ptr, dynamic_type) is the root of a DAG that grows upward.  Each
569 // node of the tree represents a base class/object of its parent (or parents) below.
570 // Each node is uniquely represented by a pointer to the object, and a pointer
571 // to a type_info - its type.  Different nodes may have the same pointer and
572 // different nodes may have the same type.  But only one node has a specific
573 // (pointer-value, type) pair.  In C++ two objects of the same type can not
574 // share the same address.
575 //
576 // There are two flavors of nodes which have the type dst_type:
577 //    1.  Those that are derived from (below) (static_ptr, static_type).
578 //    2.  Those that are not derived from (below) (static_ptr, static_type).
579 //
580 // Invariants of the DAG:
581 //
582 // There is at least one path from the root (dynamic_ptr, dynamic_type) to
583 // the node (static_ptr, static_type).  This path may or may not be public.
584 // There may be more than one such path (some public some not).  Such a path may
585 // or may not go through a node having type dst_type.
586 //
587 // No node of type T appears above a node of the same type.  That means that
588 // there is only one node with dynamic_type.  And if dynamic_type == dst_type,
589 // then there is only one dst_type in the DAG.
590 //
591 // No node of type dst_type appears above a node of type static_type.  Such
592 // DAG's are possible in C++, but the compiler computes those dynamic_casts at
593 // compile time, and only calls __dynamic_cast when dst_type lies below
594 // static_type in the DAG.
595 //
596 // dst_type != static_type:  The compiler computes the dynamic_cast in this case too.
597 // dynamic_type != static_type:  The compiler computes the dynamic_cast in this case too.
598 //
599 // Returns:
600 //
601 // If there is exactly one dst_type of flavor 1, and
602 //    If there is a public path from that dst_type to (static_ptr, static_type), or
603 //    If there are 0 dst_types of flavor 2, and there is a public path from
604 //        (dynamic_ptr, dynamic_type) to (static_ptr, static_type) and a public
605 //        path from (dynamic_ptr, dynamic_type) to the one dst_type, then return
606 //        a pointer to that dst_type.
607 // Else if there are 0 dst_types of flavor 1 and exactly 1 dst_type of flavor 2, and
608 //    if there is a public path from (dynamic_ptr, dynamic_type) to
609 //    (static_ptr, static_type) and a public path from (dynamic_ptr, dynamic_type)
610 //    to the one dst_type, then return a pointer to that one dst_type.
611 // Else return nullptr.
612 //
613 // If dynamic_type == dst_type, then the above algorithm collapses to the
614 // following cheaper algorithm:
615 //
616 // If there is a public path from (dynamic_ptr, dynamic_type) to
617 //    (static_ptr, static_type), then return dynamic_ptr.
618 // Else return nullptr.
619 
620 extern "C" _LIBCXXABI_FUNC_VIS void *
621 __dynamic_cast(const void *static_ptr, const __class_type_info *static_type,
622                const __class_type_info *dst_type,
623                std::ptrdiff_t src2dst_offset) {
624     // Possible future optimization:  Take advantage of src2dst_offset
625     // Currently clang always sets src2dst_offset to -1 (no hint).
626 
627     // Get (dynamic_ptr, dynamic_type) from static_ptr
628     void **vtable = *static_cast<void ** const *>(static_ptr);
629     ptrdiff_t offset_to_derived = reinterpret_cast<ptrdiff_t>(vtable[-2]);
630     const void* dynamic_ptr = static_cast<const char*>(static_ptr) + offset_to_derived;
631     const __class_type_info* dynamic_type = static_cast<const __class_type_info*>(vtable[-1]);
632 
633     // Initialize answer to nullptr.  This will be changed from the search
634     //    results if a non-null answer is found.  Regardless, this is what will
635     //    be returned.
636     const void* dst_ptr = 0;
637     // Initialize info struct for this search.
638     __dynamic_cast_info info = {dst_type, static_ptr, static_type, src2dst_offset, 0};
639 
640     // Find out if we can use a giant short cut in the search
641     if (is_equal(dynamic_type, dst_type, false))
642     {
643         // Using giant short cut.  Add that information to info.
644         info.number_of_dst_type = 1;
645         // Do the  search
646         dynamic_type->search_above_dst(&info, dynamic_ptr, dynamic_ptr, public_path, false);
647 #ifdef _LIBCXX_DYNAMIC_FALLBACK
648         // The following if should always be false because we should definitely
649         //   find (static_ptr, static_type), either on a public or private path
650         if (info.path_dst_ptr_to_static_ptr == unknown)
651         {
652             // We get here only if there is some kind of visibility problem
653             //   in client code.
654             syslog(LOG_ERR, "dynamic_cast error 1: Both of the following type_info's "
655                     "should have public visibility.  At least one of them is hidden. %s"
656                     ", %s.\n", static_type->name(), dynamic_type->name());
657             // Redo the search comparing type_info's using strcmp
658             info = {dst_type, static_ptr, static_type, src2dst_offset, 0};
659             info.number_of_dst_type = 1;
660             dynamic_type->search_above_dst(&info, dynamic_ptr, dynamic_ptr, public_path, true);
661         }
662 #endif  // _LIBCXX_DYNAMIC_FALLBACK
663         // Query the search.
664         if (info.path_dst_ptr_to_static_ptr == public_path)
665             dst_ptr = dynamic_ptr;
666     }
667     else
668     {
669         // Not using giant short cut.  Do the search
670         dynamic_type->search_below_dst(&info, dynamic_ptr, public_path, false);
671  #ifdef _LIBCXX_DYNAMIC_FALLBACK
672         // The following if should always be false because we should definitely
673         //   find (static_ptr, static_type), either on a public or private path
674         if (info.path_dst_ptr_to_static_ptr == unknown &&
675             info.path_dynamic_ptr_to_static_ptr == unknown)
676         {
677             syslog(LOG_ERR, "dynamic_cast error 2: One or more of the following type_info's "
678                             " has hidden visibility.  They should all have public visibility.  "
679                             " %s, %s, %s.\n", static_type->name(), dynamic_type->name(),
680                     dst_type->name());
681             // Redo the search comparing type_info's using strcmp
682             info = {dst_type, static_ptr, static_type, src2dst_offset, 0};
683             dynamic_type->search_below_dst(&info, dynamic_ptr, public_path, true);
684         }
685 #endif  // _LIBCXX_DYNAMIC_FALLBACK
686         // Query the search.
687         switch (info.number_to_static_ptr)
688         {
689         case 0:
690             if (info.number_to_dst_ptr == 1 &&
691                     info.path_dynamic_ptr_to_static_ptr == public_path &&
692                     info.path_dynamic_ptr_to_dst_ptr == public_path)
693                 dst_ptr = info.dst_ptr_not_leading_to_static_ptr;
694             break;
695         case 1:
696             if (info.path_dst_ptr_to_static_ptr == public_path ||
697                    (
698                        info.number_to_dst_ptr == 0 &&
699                        info.path_dynamic_ptr_to_static_ptr == public_path &&
700                        info.path_dynamic_ptr_to_dst_ptr == public_path
701                    )
702                )
703                 dst_ptr = info.dst_ptr_leading_to_static_ptr;
704             break;
705         }
706     }
707     return const_cast<void*>(dst_ptr);
708 }
709 
710 #ifdef __clang__
711 #pragma clang diagnostic pop
712 #endif
713 
714 #pragma GCC visibility pop
715 #pragma GCC visibility push(hidden)
716 
717 // Call this function when you hit a static_type which is a base (above) a dst_type.
718 // Let caller know you hit a static_type.  But only start recording details if
719 // this is (static_ptr, static_type) -- the node we are casting from.
720 // If this is (static_ptr, static_type)
721 //   Record the path (public or not) from the dst_type to here.  There may be
722 //   multiple paths from the same dst_type to here, record the "most public" one.
723 //   Record the dst_ptr as pointing to (static_ptr, static_type).
724 //   If more than one (dst_ptr, dst_type) points to (static_ptr, static_type),
725 //   then mark this dyanmic_cast as ambiguous and stop the search.
726 void
727 __class_type_info::process_static_type_above_dst(__dynamic_cast_info* info,
728                                                  const void* dst_ptr,
729                                                  const void* current_ptr,
730                                                  int path_below) const
731 {
732     // Record that we found a static_type
733     info->found_any_static_type = true;
734     if (current_ptr == info->static_ptr)
735     {
736         // Record that we found (static_ptr, static_type)
737         info->found_our_static_ptr = true;
738         if (info->dst_ptr_leading_to_static_ptr == 0)
739         {
740             // First time here
741             info->dst_ptr_leading_to_static_ptr = dst_ptr;
742             info->path_dst_ptr_to_static_ptr = path_below;
743             info->number_to_static_ptr = 1;
744             // If there is only one dst_type in the entire tree and the path from
745             //    there to here is public then we are done!
746             if (info->number_of_dst_type == 1 && info->path_dst_ptr_to_static_ptr == public_path)
747                 info->search_done = true;
748         }
749         else if (info->dst_ptr_leading_to_static_ptr == dst_ptr)
750         {
751             // We've been here before.  Update path to "most public"
752             if (info->path_dst_ptr_to_static_ptr == not_public_path)
753                 info->path_dst_ptr_to_static_ptr = path_below;
754             // If there is only one dst_type in the entire tree and the path from
755             //    there to here is public then we are done!
756             if (info->number_of_dst_type == 1 && info->path_dst_ptr_to_static_ptr == public_path)
757                 info->search_done = true;
758         }
759         else
760         {
761             // We've detected an ambiguous cast from (static_ptr, static_type)
762             //   to a dst_type
763             info->number_to_static_ptr += 1;
764             info->search_done = true;
765         }
766     }
767 }
768 
769 // Call this function when you hit a static_type which is not a base (above) a dst_type.
770 // If this is (static_ptr, static_type)
771 //   Record the path (public or not) from (dynamic_ptr, dynamic_type) to here.  There may be
772 //   multiple paths from (dynamic_ptr, dynamic_type) to here, record the "most public" one.
773 void
774 __class_type_info::process_static_type_below_dst(__dynamic_cast_info* info,
775                                                  const void* current_ptr,
776                                                  int path_below) const
777 {
778     if (current_ptr == info->static_ptr)
779     {
780         // Record the most public path from (dynamic_ptr, dynamic_type) to
781         //                                  (static_ptr, static_type)
782         if (info->path_dynamic_ptr_to_static_ptr != public_path)
783             info->path_dynamic_ptr_to_static_ptr = path_below;
784     }
785 }
786 
787 // Call this function when searching below a dst_type node.  This function searches
788 // for a path to (static_ptr, static_type) and for paths to one or more dst_type nodes.
789 // If it finds a static_type node, there is no need to further search base classes
790 // above.
791 // If it finds a dst_type node it should search base classes using search_above_dst
792 // to find out if this dst_type points to (static_ptr, static_type) or not.
793 // Either way, the dst_type is recorded as one of two "flavors":  one that does
794 // or does not point to (static_ptr, static_type).
795 // If this is neither a static_type nor a dst_type node, continue searching
796 // base classes above.
797 // All the hoopla surrounding the search code is doing nothing but looking for
798 // excuses to stop the search prematurely (break out of the for-loop).  That is,
799 // the algorithm below is simply an optimization of this:
800 // void
801 // __vmi_class_type_info::search_below_dst(__dynamic_cast_info* info,
802 //                                         const void* current_ptr,
803 //                                         int path_below) const
804 // {
805 //     typedef const __base_class_type_info* Iter;
806 //     if (this == info->static_type)
807 //         process_static_type_below_dst(info, current_ptr, path_below);
808 //     else if (this == info->dst_type)
809 //     {
810 //         // Record the most public access path that got us here
811 //         if (info->path_dynamic_ptr_to_dst_ptr != public_path)
812 //             info->path_dynamic_ptr_to_dst_ptr = path_below;
813 //         bool does_dst_type_point_to_our_static_type = false;
814 //         for (Iter p = __base_info, e= __base_info + __base_count; p < e; ++p)
815 //         {
816 //             p->search_above_dst(info, current_ptr, current_ptr, public_path);
817 //             if (info->found_our_static_ptr)
818 //                 does_dst_type_point_to_our_static_type = true;
819 //             // break out early here if you can detect it doesn't matter if you do
820 //         }
821 //         if (!does_dst_type_point_to_our_static_type)
822 //         {
823 //             // We found a dst_type that doesn't point to (static_ptr, static_type)
824 //             // So record the address of this dst_ptr and increment the
825 //             // count of the number of such dst_types found in the tree.
826 //             info->dst_ptr_not_leading_to_static_ptr = current_ptr;
827 //             info->number_to_dst_ptr += 1;
828 //         }
829 //     }
830 //     else
831 //     {
832 //         // This is not a static_type and not a dst_type.
833 //         for (Iter p = __base_info, e = __base_info + __base_count; p < e; ++p)
834 //         {
835 //             p->search_below_dst(info, current_ptr, public_path);
836 //             // break out early here if you can detect it doesn't matter if you do
837 //         }
838 //     }
839 // }
840 void
841 __vmi_class_type_info::search_below_dst(__dynamic_cast_info* info,
842                                         const void* current_ptr,
843                                         int path_below,
844                                         bool use_strcmp) const
845 {
846     typedef const __base_class_type_info* Iter;
847     if (is_equal(this, info->static_type, use_strcmp))
848         process_static_type_below_dst(info, current_ptr, path_below);
849     else if (is_equal(this, info->dst_type, use_strcmp))
850     {
851         // We've been here before if we've recorded current_ptr in one of these
852         //   two places:
853         if (current_ptr == info->dst_ptr_leading_to_static_ptr ||
854             current_ptr == info->dst_ptr_not_leading_to_static_ptr)
855         {
856             // We've seen this node before, and therefore have already searched
857             // its base classes above.
858             //  Update path to here that is "most public".
859             if (path_below == public_path)
860                 info->path_dynamic_ptr_to_dst_ptr = public_path;
861         }
862         else  // We have haven't been here before
863         {
864             // Record the access path that got us here
865             //   If there is more than one dst_type this path doesn't matter.
866             info->path_dynamic_ptr_to_dst_ptr = path_below;
867             // Only search above here if dst_type derives from static_type, or
868             //    if it is unknown if dst_type derives from static_type.
869             if (info->is_dst_type_derived_from_static_type != no)
870             {
871                 // Set up flags to record results from all base classes
872                 bool is_dst_type_derived_from_static_type = false;
873                 bool does_dst_type_point_to_our_static_type = false;
874                 // We've found a dst_type with a potentially public path to here.
875                 // We have to assume the path is public because it may become
876                 //   public later (if we get back to here with a public path).
877                 // We can stop looking above if:
878                 //    1.  We've found a public path to (static_ptr, static_type).
879                 //    2.  We've found an ambiguous cast from (static_ptr, static_type) to a dst_type.
880                 //        This is detected at the (static_ptr, static_type).
881                 //    3.  We can prove that there is no public path to (static_ptr, static_type)
882                 //        above here.
883                 const Iter e = __base_info + __base_count;
884                 for (Iter p = __base_info; p < e; ++p)
885                 {
886                     // Zero out found flags
887                     info->found_our_static_ptr = false;
888                     info->found_any_static_type = false;
889                     p->search_above_dst(info, current_ptr, current_ptr, public_path, use_strcmp);
890                     if (info->search_done)
891                         break;
892                     if (info->found_any_static_type)
893                     {
894                         is_dst_type_derived_from_static_type = true;
895                         if (info->found_our_static_ptr)
896                         {
897                             does_dst_type_point_to_our_static_type = true;
898                             // If we found what we're looking for, stop looking above.
899                             if (info->path_dst_ptr_to_static_ptr == public_path)
900                                 break;
901                             // We found a private path to (static_ptr, static_type)
902                             //   If there is no diamond then there is only one path
903                             //   to (static_ptr, static_type) and we just found it.
904                             if (!(__flags & __diamond_shaped_mask))
905                                 break;
906                         }
907                         else
908                         {
909                             // If we found a static_type that isn't the one we're looking
910                             //    for, and if there are no repeated types above here,
911                             //    then stop looking.
912                             if (!(__flags & __non_diamond_repeat_mask))
913                                 break;
914                         }
915                     }
916                 }
917                 if (!does_dst_type_point_to_our_static_type)
918                 {
919                     // We found a dst_type that doesn't point to (static_ptr, static_type)
920                     // So record the address of this dst_ptr and increment the
921                     // count of the number of such dst_types found in the tree.
922                     info->dst_ptr_not_leading_to_static_ptr = current_ptr;
923                     info->number_to_dst_ptr += 1;
924                     // If there exists another dst with a private path to
925                     //    (static_ptr, static_type), then the cast from
926                     //     (dynamic_ptr, dynamic_type) to dst_type is now ambiguous,
927                     //      so stop search.
928                     if (info->number_to_static_ptr == 1 &&
929                             info->path_dst_ptr_to_static_ptr == not_public_path)
930                         info->search_done = true;
931                 }
932                 // If we found no static_type,s then dst_type doesn't derive
933                 //   from static_type, else it does.  Record this result so that
934                 //   next time we hit a dst_type we will know not to search above
935                 //   it if it doesn't derive from static_type.
936                 if (is_dst_type_derived_from_static_type)
937                     info->is_dst_type_derived_from_static_type = yes;
938                 else
939                     info->is_dst_type_derived_from_static_type = no;
940             }
941         }
942     }
943     else
944     {
945         // This is not a static_type and not a dst_type.
946         const Iter e = __base_info + __base_count;
947         Iter p = __base_info;
948         p->search_below_dst(info, current_ptr, path_below, use_strcmp);
949         if (++p < e)
950         {
951             if ((__flags & __diamond_shaped_mask) || info->number_to_static_ptr == 1)
952             {
953                 // If there are multiple paths to a base above from here, or if
954                 //    a dst_type pointing to (static_ptr, static_type) has been found,
955                 //    then there is no way to break out of this loop early unless
956                 //    something below detects the search is done.
957                 do
958                 {
959                     if (info->search_done)
960                         break;
961                     p->search_below_dst(info, current_ptr, path_below, use_strcmp);
962                 } while (++p < e);
963             }
964             else if (__flags & __non_diamond_repeat_mask)
965             {
966                 // There are not multiple paths to any base class from here and a
967                 //   dst_type pointing to (static_ptr, static_type) has not yet been
968                 //   found.
969                 do
970                 {
971                     if (info->search_done)
972                         break;
973                     // If we just found a dst_type with a public path to (static_ptr, static_type),
974                     //    then the only reason to continue the search is to make sure
975                     //    no other dst_type points to (static_ptr, static_type).
976                     //    If !diamond, then we don't need to search here.
977                     if (info->number_to_static_ptr == 1 &&
978                               info->path_dst_ptr_to_static_ptr == public_path)
979                         break;
980                     p->search_below_dst(info, current_ptr, path_below, use_strcmp);
981                 } while (++p < e);
982             }
983             else
984             {
985                 // There are no repeated types above this node.
986                 // There are no nodes with multiple parents above this node.
987                 // no dst_type has been found to (static_ptr, static_type)
988                 do
989                 {
990                     if (info->search_done)
991                         break;
992                     // If we just found a dst_type with a public path to (static_ptr, static_type),
993                     //    then the only reason to continue the search is to make sure sure
994                     //    no other dst_type points to (static_ptr, static_type).
995                     //    If !diamond, then we don't need to search here.
996                     // if we just found a dst_type with a private path to (static_ptr, static_type),
997                     //    then we're only looking for a public path to (static_ptr, static_type)
998                     //    and to check for other dst_types.
999                     //    If !diamond & !repeat, then there is not a pointer to (static_ptr, static_type)
1000                     //    and not a dst_type under here.
1001                     if (info->number_to_static_ptr == 1)
1002                         break;
1003                     p->search_below_dst(info, current_ptr, path_below, use_strcmp);
1004                 } while (++p < e);
1005             }
1006         }
1007     }
1008 }
1009 
1010 // This is the same algorithm as __vmi_class_type_info::search_below_dst but
1011 //   simplified to the case that there is only a single base class.
1012 void
1013 __si_class_type_info::search_below_dst(__dynamic_cast_info* info,
1014                                        const void* current_ptr,
1015                                        int path_below,
1016                                        bool use_strcmp) const
1017 {
1018     if (is_equal(this, info->static_type, use_strcmp))
1019         process_static_type_below_dst(info, current_ptr, path_below);
1020     else if (is_equal(this, info->dst_type, use_strcmp))
1021     {
1022         // We've been here before if we've recorded current_ptr in one of these
1023         //   two places:
1024         if (current_ptr == info->dst_ptr_leading_to_static_ptr ||
1025             current_ptr == info->dst_ptr_not_leading_to_static_ptr)
1026         {
1027             // We've seen this node before, and therefore have already searched
1028             // its base classes above.
1029             //  Update path to here that is "most public".
1030             if (path_below == public_path)
1031                 info->path_dynamic_ptr_to_dst_ptr = public_path;
1032         }
1033         else  // We have haven't been here before
1034         {
1035             // Record the access path that got us here
1036             //   If there is more than one dst_type this path doesn't matter.
1037             info->path_dynamic_ptr_to_dst_ptr = path_below;
1038             // Only search above here if dst_type derives from static_type, or
1039             //    if it is unknown if dst_type derives from static_type.
1040             if (info->is_dst_type_derived_from_static_type != no)
1041             {
1042                 // Set up flags to record results from all base classes
1043                 bool is_dst_type_derived_from_static_type = false;
1044                 bool does_dst_type_point_to_our_static_type = false;
1045                 // Zero out found flags
1046                 info->found_our_static_ptr = false;
1047                 info->found_any_static_type = false;
1048                 __base_type->search_above_dst(info, current_ptr, current_ptr, public_path, use_strcmp);
1049                 if (info->found_any_static_type)
1050                 {
1051                     is_dst_type_derived_from_static_type = true;
1052                     if (info->found_our_static_ptr)
1053                         does_dst_type_point_to_our_static_type = true;
1054                 }
1055                 if (!does_dst_type_point_to_our_static_type)
1056                 {
1057                     // We found a dst_type that doesn't point to (static_ptr, static_type)
1058                     // So record the address of this dst_ptr and increment the
1059                     // count of the number of such dst_types found in the tree.
1060                     info->dst_ptr_not_leading_to_static_ptr = current_ptr;
1061                     info->number_to_dst_ptr += 1;
1062                     // If there exists another dst with a private path to
1063                     //    (static_ptr, static_type), then the cast from
1064                     //     (dynamic_ptr, dynamic_type) to dst_type is now ambiguous.
1065                     if (info->number_to_static_ptr == 1 &&
1066                             info->path_dst_ptr_to_static_ptr == not_public_path)
1067                         info->search_done = true;
1068                 }
1069                 // If we found no static_type,s then dst_type doesn't derive
1070                 //   from static_type, else it does.  Record this result so that
1071                 //   next time we hit a dst_type we will know not to search above
1072                 //   it if it doesn't derive from static_type.
1073                 if (is_dst_type_derived_from_static_type)
1074                     info->is_dst_type_derived_from_static_type = yes;
1075                 else
1076                     info->is_dst_type_derived_from_static_type = no;
1077             }
1078         }
1079     }
1080     else
1081     {
1082         // This is not a static_type and not a dst_type
1083         __base_type->search_below_dst(info, current_ptr, path_below, use_strcmp);
1084     }
1085 }
1086 
1087 // This is the same algorithm as __vmi_class_type_info::search_below_dst but
1088 //   simplified to the case that there is no base class.
1089 void
1090 __class_type_info::search_below_dst(__dynamic_cast_info* info,
1091                                     const void* current_ptr,
1092                                     int path_below,
1093                                     bool use_strcmp) const
1094 {
1095     if (is_equal(this, info->static_type, use_strcmp))
1096         process_static_type_below_dst(info, current_ptr, path_below);
1097     else if (is_equal(this, info->dst_type, use_strcmp))
1098     {
1099         // We've been here before if we've recorded current_ptr in one of these
1100         //   two places:
1101         if (current_ptr == info->dst_ptr_leading_to_static_ptr ||
1102             current_ptr == info->dst_ptr_not_leading_to_static_ptr)
1103         {
1104             // We've seen this node before, and therefore have already searched
1105             // its base classes above.
1106             //  Update path to here that is "most public".
1107             if (path_below == public_path)
1108                 info->path_dynamic_ptr_to_dst_ptr = public_path;
1109         }
1110         else  // We have haven't been here before
1111         {
1112             // Record the access path that got us here
1113             //   If there is more than one dst_type this path doesn't matter.
1114             info->path_dynamic_ptr_to_dst_ptr = path_below;
1115             // We found a dst_type that doesn't point to (static_ptr, static_type)
1116             // So record the address of this dst_ptr and increment the
1117             // count of the number of such dst_types found in the tree.
1118             info->dst_ptr_not_leading_to_static_ptr = current_ptr;
1119             info->number_to_dst_ptr += 1;
1120             // If there exists another dst with a private path to
1121             //    (static_ptr, static_type), then the cast from
1122             //     (dynamic_ptr, dynamic_type) to dst_type is now ambiguous.
1123             if (info->number_to_static_ptr == 1 &&
1124                     info->path_dst_ptr_to_static_ptr == not_public_path)
1125                 info->search_done = true;
1126             // We found that dst_type does not derive from static_type
1127             info->is_dst_type_derived_from_static_type = no;
1128         }
1129     }
1130 }
1131 
1132 // Call this function when searching above a dst_type node.  This function searches
1133 // for a public path to (static_ptr, static_type).
1134 // This function is guaranteed not to find a node of type dst_type.
1135 // Theoretically this is a very simple function which just stops if it finds a
1136 // static_type node:  All the hoopla surrounding the search code is doing
1137 // nothing but looking for excuses to stop the search prematurely (break out of
1138 // the for-loop).  That is, the algorithm below is simply an optimization of this:
1139 // void
1140 // __vmi_class_type_info::search_above_dst(__dynamic_cast_info* info,
1141 //                                         const void* dst_ptr,
1142 //                                         const void* current_ptr,
1143 //                                         int path_below) const
1144 // {
1145 //     if (this == info->static_type)
1146 //         process_static_type_above_dst(info, dst_ptr, current_ptr, path_below);
1147 //     else
1148 //     {
1149 //         typedef const __base_class_type_info* Iter;
1150 //         // This is not a static_type and not a dst_type
1151 //         for (Iter p = __base_info, e = __base_info + __base_count; p < e; ++p)
1152 //         {
1153 //             p->search_above_dst(info, dst_ptr, current_ptr, public_path);
1154 //             // break out early here if you can detect it doesn't matter if you do
1155 //         }
1156 //     }
1157 // }
1158 void
1159 __vmi_class_type_info::search_above_dst(__dynamic_cast_info* info,
1160                                         const void* dst_ptr,
1161                                         const void* current_ptr,
1162                                         int path_below,
1163                                         bool use_strcmp) const
1164 {
1165     if (is_equal(this, info->static_type, use_strcmp))
1166         process_static_type_above_dst(info, dst_ptr, current_ptr, path_below);
1167     else
1168     {
1169         typedef const __base_class_type_info* Iter;
1170         // This is not a static_type and not a dst_type
1171         // Save flags so they can be restored when returning to nodes below.
1172         bool found_our_static_ptr = info->found_our_static_ptr;
1173         bool found_any_static_type = info->found_any_static_type;
1174         // We've found a dst_type below with a path to here.  If the path
1175         //    to here is not public, there may be another path to here that
1176         //    is public.  So we have to assume that the path to here is public.
1177         //  We can stop looking above if:
1178         //    1.  We've found a public path to (static_ptr, static_type).
1179         //    2.  We've found an ambiguous cast from (static_ptr, static_type) to a dst_type.
1180         //        This is detected at the (static_ptr, static_type).
1181         //    3.  We can prove that there is no public path to (static_ptr, static_type)
1182         //        above here.
1183         const Iter e = __base_info + __base_count;
1184         Iter p = __base_info;
1185         // Zero out found flags
1186         info->found_our_static_ptr = false;
1187         info->found_any_static_type = false;
1188         p->search_above_dst(info, dst_ptr, current_ptr, path_below, use_strcmp);
1189         if (++p < e)
1190         {
1191             do
1192             {
1193                 if (info->search_done)
1194                     break;
1195                 if (info->found_our_static_ptr)
1196                 {
1197                     // If we found what we're looking for, stop looking above.
1198                     if (info->path_dst_ptr_to_static_ptr == public_path)
1199                         break;
1200                     // We found a private path to (static_ptr, static_type)
1201                     //   If there is no diamond then there is only one path
1202                     //   to (static_ptr, static_type) from here and we just found it.
1203                     if (!(__flags & __diamond_shaped_mask))
1204                         break;
1205                 }
1206                 else if (info->found_any_static_type)
1207                 {
1208                     // If we found a static_type that isn't the one we're looking
1209                     //    for, and if there are no repeated types above here,
1210                     //    then stop looking.
1211                     if (!(__flags & __non_diamond_repeat_mask))
1212                         break;
1213                 }
1214                 // Zero out found flags
1215                 info->found_our_static_ptr = false;
1216                 info->found_any_static_type = false;
1217                 p->search_above_dst(info, dst_ptr, current_ptr, path_below, use_strcmp);
1218             } while (++p < e);
1219         }
1220         // Restore flags
1221         info->found_our_static_ptr = found_our_static_ptr;
1222         info->found_any_static_type = found_any_static_type;
1223     }
1224 }
1225 
1226 // This is the same algorithm as __vmi_class_type_info::search_above_dst but
1227 //   simplified to the case that there is only a single base class.
1228 void
1229 __si_class_type_info::search_above_dst(__dynamic_cast_info* info,
1230                                        const void* dst_ptr,
1231                                        const void* current_ptr,
1232                                        int path_below,
1233                                        bool use_strcmp) const
1234 {
1235     if (is_equal(this, info->static_type, use_strcmp))
1236         process_static_type_above_dst(info, dst_ptr, current_ptr, path_below);
1237     else
1238         __base_type->search_above_dst(info, dst_ptr, current_ptr, path_below, use_strcmp);
1239 }
1240 
1241 // This is the same algorithm as __vmi_class_type_info::search_above_dst but
1242 //   simplified to the case that there is no base class.
1243 void
1244 __class_type_info::search_above_dst(__dynamic_cast_info* info,
1245                                     const void* dst_ptr,
1246                                     const void* current_ptr,
1247                                     int path_below,
1248                                     bool use_strcmp) const
1249 {
1250     if (is_equal(this, info->static_type, use_strcmp))
1251         process_static_type_above_dst(info, dst_ptr, current_ptr, path_below);
1252 }
1253 
1254 // The search functions for __base_class_type_info are simply convenience
1255 //   functions for adjusting the current_ptr and path_below as the search is
1256 //   passed up to the base class node.
1257 
1258 void
1259 __base_class_type_info::search_above_dst(__dynamic_cast_info* info,
1260                                          const void* dst_ptr,
1261                                          const void* current_ptr,
1262                                          int path_below,
1263                                          bool use_strcmp) const
1264 {
1265     ptrdiff_t offset_to_base = __offset_flags >> __offset_shift;
1266     if (__offset_flags & __virtual_mask)
1267     {
1268         const char* vtable = *static_cast<const char*const*>(current_ptr);
1269         offset_to_base = *reinterpret_cast<const ptrdiff_t*>(vtable + offset_to_base);
1270     }
1271     __base_type->search_above_dst(info, dst_ptr,
1272                                   static_cast<const char*>(current_ptr) + offset_to_base,
1273                                   (__offset_flags & __public_mask) ?
1274                                       path_below :
1275                                       not_public_path,
1276                                   use_strcmp);
1277 }
1278 
1279 void
1280 __base_class_type_info::search_below_dst(__dynamic_cast_info* info,
1281                                          const void* current_ptr,
1282                                          int path_below,
1283                                          bool use_strcmp) const
1284 {
1285     ptrdiff_t offset_to_base = __offset_flags >> __offset_shift;
1286     if (__offset_flags & __virtual_mask)
1287     {
1288         const char* vtable = *static_cast<const char*const*>(current_ptr);
1289         offset_to_base = *reinterpret_cast<const ptrdiff_t*>(vtable + offset_to_base);
1290     }
1291     __base_type->search_below_dst(info,
1292                                   static_cast<const char*>(current_ptr) + offset_to_base,
1293                                   (__offset_flags & __public_mask) ?
1294                                       path_below :
1295                                       not_public_path,
1296                                   use_strcmp);
1297 }
1298 
1299 #pragma GCC visibility pop
1300 
1301 }  // __cxxabiv1
1302