Author: tstellar Date: Fri May 8 10:10:43 2015 New Revision: 236862 URL: http://llvm.org/viewvc/llvm-project?rev=236862&view=rev Log: Merging r233984: ------------------------------------------------------------------------ r233984 | ericwf | 2015-04-02 16:26:37 -0700 (Thu, 02 Apr 2015) | 22 lines
[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 ------------------------------------------------------------------------ Added: libcxxabi/branches/release_36/test/catch_multi_level_pointer.pass.cpp - copied unchanged from r233984, libcxxabi/trunk/test/catch_multi_level_pointer.pass.cpp Modified: libcxxabi/branches/release_36/ (props changed) libcxxabi/branches/release_36/src/private_typeinfo.cpp libcxxabi/branches/release_36/src/private_typeinfo.h Propchange: libcxxabi/branches/release_36/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Fri May 8 10:10:43 2015 @@ -1 +1 @@ -/libcxxabi/trunk:226818-226820,226822-226824,228359,231839,231852 +/libcxxabi/trunk:226818-226820,226822-226824,228359,231839,231852,233984 Modified: libcxxabi/branches/release_36/src/private_typeinfo.cpp URL: http://llvm.org/viewvc/llvm-project/libcxxabi/branches/release_36/src/private_typeinfo.cpp?rev=236862&r1=236861&r2=236862&view=diff ============================================================================== --- libcxxabi/branches/release_36/src/private_typeinfo.cpp (original) +++ libcxxabi/branches/release_36/src/private_typeinfo.cpp Fri May 8 10:10:43 2015 @@ -383,6 +383,24 @@ __pointer_type_info::can_catch(const __s // 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) @@ -403,6 +421,84 @@ __pointer_type_info::can_catch(const __s 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 #pragma GCC visibility pop Modified: libcxxabi/branches/release_36/src/private_typeinfo.h URL: http://llvm.org/viewvc/llvm-project/libcxxabi/branches/release_36/src/private_typeinfo.h?rev=236862&r1=236861&r2=236862&view=diff ============================================================================== --- libcxxabi/branches/release_36/src/private_typeinfo.h (original) +++ libcxxabi/branches/release_36/src/private_typeinfo.h Fri May 8 10:10:43 2015 @@ -230,6 +230,7 @@ class __attribute__ ((__visibility__("de public: __attribute__ ((__visibility__("hidden"))) virtual ~__pointer_type_info(); __attribute__ ((__visibility__("hidden"))) virtual bool can_catch(const __shim_type_info*, void*&) const; + __attribute__ ((__visibility__("hidden"))) bool can_catch_nested(const __shim_type_info*) const; }; class __attribute__ ((__visibility__("default"))) __pointer_to_member_type_info @@ -239,6 +240,8 @@ public: const __class_type_info* __context; __attribute__ ((__visibility__("hidden"))) virtual ~__pointer_to_member_type_info(); + __attribute__ ((__visibility__("hidden"))) virtual bool can_catch(const __shim_type_info*, void*&) const; + __attribute__ ((__visibility__("hidden"))) bool can_catch_nested(const __shim_type_info*) const; }; #pragma GCC visibility pop _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
