Author: tstellar Date: Fri May 8 10:37:37 2015 New Revision: 236868 URL: http://llvm.org/viewvc/llvm-project?rev=236868&view=rev Log: Merging r236299: ------------------------------------------------------------------------ r236299 | ericwf | 2015-04-30 18:49:37 -0700 (Thu, 30 Apr 2015) | 7 lines
Disallow conversions from function pointers to void*. Function pointers and member function pointers cannot be converted to void*. libc++abi incorrectly allows this conversion for function pointers. Review URL: http://reviews.llvm.org/D8811 ------------------------------------------------------------------------ Modified: libcxxabi/branches/release_36/ (props changed) libcxxabi/branches/release_36/src/private_typeinfo.cpp libcxxabi/branches/release_36/test/catch_function_01.cpp Propchange: libcxxabi/branches/release_36/ ------------------------------------------------------------------------------ --- svn:mergeinfo (original) +++ svn:mergeinfo Fri May 8 10:37:37 2015 @@ -1 +1 @@ -/libcxxabi/trunk:226818-226820,226822-226824,228359,231839,231852,233984,234254 +/libcxxabi/trunk:226818-226820,226822-226824,228359,231839,231852,233984,234254,236299 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=236868&r1=236867&r2=236868&view=diff ============================================================================== --- libcxxabi/branches/release_36/src/private_typeinfo.cpp (original) +++ libcxxabi/branches/release_36/src/private_typeinfo.cpp Fri May 8 10:37:37 2015 @@ -381,9 +381,13 @@ __pointer_type_info::can_catch(const __s if (is_equal(__pointee, thrown_pointer_type->__pointee, false)) return true; // bullet 3A - if (is_equal(__pointee, &typeid(void), false)) - return true; - + if (is_equal(__pointee, &typeid(void), false)) { + // pointers to functions cannot be converted to void*. + // pointers to member functions are not handled here. + const __function_type_info* thrown_function = + dynamic_cast<const __function_type_info*>(thrown_pointer_type->__pointee); + return (thrown_function == nullptr); + } // Handle pointer to pointer const __pointer_type_info* nested_pointer_type = dynamic_cast<const __pointer_type_info*>(__pointee); Modified: libcxxabi/branches/release_36/test/catch_function_01.cpp URL: http://llvm.org/viewvc/llvm-project/libcxxabi/branches/release_36/test/catch_function_01.cpp?rev=236868&r1=236867&r2=236868&view=diff ============================================================================== --- libcxxabi/branches/release_36/test/catch_function_01.cpp (original) +++ libcxxabi/branches/release_36/test/catch_function_01.cpp Fri May 8 10:37:37 2015 @@ -11,11 +11,19 @@ #include <cassert> +template <class Tp> +bool can_convert(Tp) { return true; } + +template <class> +bool can_convert(...) { return false; } + void f() {} int main() { typedef void Function(); + assert(!can_convert<Function&>(&f)); + assert(!can_convert<void*>(&f)); try { throw f; // converts to void (*)() @@ -25,7 +33,15 @@ int main() { assert(false); } + catch (void*) // can't catch as void* + { + assert(false); + } + catch(Function*) + { + } catch (...) { + assert(false); } } _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
