diff options
author | Eric Fiselier <eric@efcs.ca> | 2015-04-03 02:26:37 +0300 |
---|---|---|
committer | Eric Fiselier <eric@efcs.ca> | 2015-04-03 02:26:37 +0300 |
commit | 1b00fc5d8133bab423fc15eb9ce0e930fa0fc709 (patch) | |
tree | f4ce7d87c402556d744d90d0673c0b5a150d5e98 /libcxxabi/src/private_typeinfo.cpp | |
parent | 696f275954488b7291faf8058a62c62992c33885 (diff) |
[libcxxabi] Fix multi-level pointer conversions and pointer to member conversion detection.
Summary:
Currently there are bugs in out detection of multi-level pointer conversions and pointer to member conversions. This patch fixes the following issues.
* Allow multi-level pointers with different nested qualifiers.
* Allow multi-level mixed pointers to objects and pointers to members with different nested qualifiers.
* Allow conversions from `int Base::*` to `int Derived::*` but only for non-nested pointers.
There is still some work that needs to be done to clean this patch up but I want to get some input on it.
Open questions:
* Does `__pointer_to_member_type_info::can_catch(...)` need to adjust the pointer if a base to derived conversion is performed?
Reviewers: danalbert, compnerd, mclow.lists
Reviewed By: mclow.lists
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D8758
llvm-svn: 233984
Diffstat (limited to 'libcxxabi/src/private_typeinfo.cpp')
-rw-r--r-- | libcxxabi/src/private_typeinfo.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/libcxxabi/src/private_typeinfo.cpp b/libcxxabi/src/private_typeinfo.cpp index d410dabf7a71..65cb6ed35a68 100644 --- a/libcxxabi/src/private_typeinfo.cpp +++ b/libcxxabi/src/private_typeinfo.cpp @@ -389,6 +389,24 @@ __pointer_type_info::can_catch(const __shim_type_info* thrown_type, // bullet 3A if (is_equal(__pointee, &typeid(void), false)) return true; + + // Handle pointer to pointer + const __pointer_type_info* nested_pointer_type = + dynamic_cast<const __pointer_type_info*>(__pointee); + if (nested_pointer_type) { + if (~__flags & __const_mask) return false; + return nested_pointer_type->can_catch_nested(thrown_pointer_type->__pointee); + } + + // Handle pointer to pointer to member + const __pointer_to_member_type_info* member_ptr_type = + dynamic_cast<const __pointer_to_member_type_info*>(__pointee); + if (member_ptr_type) { + if (~__flags & __const_mask) return false; + return member_ptr_type->can_catch_nested(thrown_pointer_type->__pointee); + } + + // Handle pointer to class type const __class_type_info* catch_class_type = dynamic_cast<const __class_type_info*>(__pointee); if (catch_class_type == 0) @@ -409,6 +427,83 @@ __pointer_type_info::can_catch(const __shim_type_info* thrown_type, return false; } +bool __pointer_type_info::can_catch_nested( + const __shim_type_info* thrown_type) const +{ + const __pointer_type_info* thrown_pointer_type = + dynamic_cast<const __pointer_type_info*>(thrown_type); + if (thrown_pointer_type == 0) + return false; + // bullet 3B + if (thrown_pointer_type->__flags & ~__flags) + return false; + if (is_equal(__pointee, thrown_pointer_type->__pointee, false)) + return true; + // If the pointed to types differ then the catch type must be const + // qualified. + if (~__flags & __const_mask) + return false; + + // Handle pointer to pointer + const __pointer_type_info* nested_pointer_type = + dynamic_cast<const __pointer_type_info*>(__pointee); + if (nested_pointer_type) { + return nested_pointer_type->can_catch_nested( + thrown_pointer_type->__pointee); + } + + // Handle pointer to pointer to member + const __pointer_to_member_type_info* member_ptr_type = + dynamic_cast<const __pointer_to_member_type_info*>(__pointee); + if (member_ptr_type) { + return member_ptr_type->can_catch_nested(thrown_pointer_type->__pointee); + } + + return false; +} + +bool __pointer_to_member_type_info::can_catch( + const __shim_type_info* thrown_type, void*& adjustedPtr) const { + // bullets 1 and 4 + if (__pbase_type_info::can_catch(thrown_type, adjustedPtr)) + return true; + + const __pointer_to_member_type_info* thrown_pointer_type = + dynamic_cast<const __pointer_to_member_type_info*>(thrown_type); + if (thrown_pointer_type == 0) + return false; + if (thrown_pointer_type->__flags & ~__flags) + return false; + if (!is_equal(__pointee, thrown_pointer_type->__pointee, false)) + return false; + if (is_equal(__context, thrown_pointer_type->__context, false)) + return true; + + __dynamic_cast_info info = {__context, 0, thrown_pointer_type->__context, -1, 0}; + info.number_of_dst_type = 1; + __context->has_unambiguous_public_base(&info, adjustedPtr, public_path); + if (info.path_dst_ptr_to_static_ptr == public_path) + return true; + + return false; +} + +bool __pointer_to_member_type_info::can_catch_nested( + const __shim_type_info* thrown_type) const +{ + const __pointer_to_member_type_info* thrown_member_ptr_type = + dynamic_cast<const __pointer_to_member_type_info*>(thrown_type); + if (thrown_member_ptr_type == 0) + return false; + if (~__flags & thrown_member_ptr_type->__flags) + return false; + if (!is_equal(__pointee, thrown_member_ptr_type->__pointee, false)) + return false; + if (!is_equal(__context, thrown_member_ptr_type->__context, false)) + return false; + return true; +} + #ifdef __clang__ #pragma clang diagnostic pop #endif |