llvm-capstone/libcxxabi/test
Iain Sandoe d5f84e6121
[libc++abi] Handle catch null pointer-to-object (#68076)
This addresses cases (currently failing) where we throw a null
pointer-to-object and fixes #64953.

We are trying to satisfy the following bullet from the C++ ABI 15.3:

* the handler is of type cv1 T* cv2 and E is a pointer type that can be
converted to the type of the handler by either or both of:

  - a standard pointer conversion (4.10 [conv.ptr]) not involving
    conversions to private or protected or ambiguous classes.

  - a qualification conversion.

The existing implementation assesses the ambiguity of bases by computing
the offsets to them; ambiguous cases are then when the same base appears
at different offsets. The computation of offset includes indirecting
through the vtables to find the offsets to virtual bases.

When the thrown pointer points to a real object, this is quite efficient
since, if the base is found, and it is not ambiguous and on a public
path, the offset is needed to return the adjusted pointer (and the
indirections are not particularly expensive to compute).

However, when we throw a null pointer-to-object, this scheme is no
longer applicable (and the code currently bypasses the relevant
computations, leading to the incorrect catches reported in the issue).

-----

The solution proposed here takes a composite approach:

1. When the pointer-to-object points to a real instance (well, at least,
it is determined to be non-null), we use the existing scheme.

2. When the pointer-to-object is null:

  * We note that there is no real object.
  * When we are processing non-virtual bases, we continue to compute the
    offsets, but for a notional dummy object based at 0. This is OK, since
    we never need to access the object content for non-virtual bases.
  * When we are processing a path with one or more virtual bases, we
    remember a cookie corresponding to the inner-most virtual base found so
    far (and set the notional offset to 0). Offsets to inner non-virtual
    bases are then computed as normal.

A base is then ambiguous iff:
* There is a recorded virtual base cookie and that is different from the
  current one or,
* The non-virtual base offsets differ.

When a handler for a pointer succeeds in catching a base pointer for a
thrown null pointer-to-object, we still return a nullptr (so the
adjustment to the pointer is not required and need not be computed).

Since we noted that there was no object when starting the search for
ambiguous bases, we know that we can skip the pointer adjustment.

This was originally uploaded as https://reviews.llvm.org/D158769.
Fixes #64953
2024-01-08 17:11:14 -05:00
..
configs [libc++] Run picolibc tests with qemu 2023-11-29 17:21:08 -05:00
native [libc++abi] Fix test on Android (#74753) 2023-12-13 12:48:54 -05:00
support
vendor [runtimes][NFC] Remove trailing whitespace 2023-11-17 16:50:49 -05:00
backtrace_test.pass.cpp [libc++abi][test][VE] Add UNSUPPORTED to pass tests on VE 2023-09-14 08:13:02 +09:00
catch_array_01.pass.cpp
catch_array_02.pass.cpp
catch_class_01.pass.cpp
catch_class_02.pass.cpp
catch_class_03.pass.cpp
catch_class_04.pass.cpp
catch_const_pointer_nullptr.pass.cpp
catch_function_01.pass.cpp [libc++] Use the stdlib=<LIB> Lit feature instead of use_system_cxx_lib 2023-03-30 06:57:56 -04:00
catch_function_02.pass.cpp
catch_function_03.pass.cpp [libc++] Use the stdlib=<LIB> Lit feature instead of use_system_cxx_lib 2023-03-30 06:57:56 -04:00
catch_in_noexcept.pass.cpp
catch_member_data_pointer_01.pass.cpp [libc++] Use the stdlib=<LIB> Lit feature instead of use_system_cxx_lib 2023-03-30 06:57:56 -04:00
catch_member_function_pointer_01.pass.cpp
catch_member_function_pointer_02.pass.cpp [runtimes][NFC] Remove old Lit annotations for gcc-12 and clang-14 2023-09-21 17:13:31 -04:00
catch_member_pointer_nullptr.pass.cpp [libc++] Use the stdlib=<LIB> Lit feature instead of use_system_cxx_lib 2023-03-30 06:57:56 -04:00
catch_multi_level_pointer.pass.cpp [libc++] Add a picolibc test configuration with exceptions enabled (#75462) 2023-12-18 10:25:50 -05:00
catch_null_pointer_to_object_pr64953.pass.cpp [libc++abi] Handle catch null pointer-to-object (#68076) 2024-01-08 17:11:14 -05:00
catch_pointer_nullptr.pass.cpp [libc++] Use the stdlib=<LIB> Lit feature instead of use_system_cxx_lib 2023-03-30 06:57:56 -04:00
catch_pointer_reference.pass.cpp
catch_ptr_02.pass.cpp [libcxxabi] [test] Don't cast a pointer to long, fixing the test on Windows 2023-04-12 10:17:21 +03:00
catch_ptr.pass.cpp
catch_reference_nullptr.pass.cpp [libc++abi] Use std::nullptr_t instead of declaring it manually 2022-11-04 15:51:44 -07:00
CMakeLists.txt [runtimes] Fix parsing of LIB{CXX,CXXABI,UNWIND}_TEST_PARAMS (#67691) 2023-10-04 18:11:37 -04:00
cxa_bad_cast.pass.cpp
cxa_bad_typeid.pass.cpp
cxa_thread_atexit_test.pass.cpp
cxa_vec_new_overflow_PR41395.pass.cpp [libcxxabi] [test] Avoid mingw warnings about missing a return statement 2023-04-19 13:35:37 +03:00
dynamic_cast3.pass.cpp
dynamic_cast5.pass.cpp
dynamic_cast14.pass.cpp
dynamic_cast.pass.cpp [libc++] Use the stdlib=<LIB> Lit feature instead of use_system_cxx_lib 2023-03-30 06:57:56 -04:00
exception_object_alignment.2.pass.cpp [libc++][test] Add '-Wdeprecated-copy', '-Wdeprecated-copy-dtor' warnings to the test suite 2023-09-12 08:53:38 -04:00
exception_object_alignment.pass.cpp [libc++] Use the stdlib=<LIB> Lit feature instead of use_system_cxx_lib 2023-03-30 06:57:56 -04:00
forced_unwind1.pass.cpp [libc++abi][test][VE] Add UNSUPPORTED to pass tests on VE 2023-09-14 08:13:02 +09:00
forced_unwind2.pass.cpp [libc++abi][test][VE] Add UNSUPPORTED to pass tests on VE 2023-09-14 08:13:02 +09:00
forced_unwind3.pass.cpp [libc++abi][test][VE] Add UNSUPPORTED to pass tests on VE 2023-09-14 08:13:02 +09:00
forced_unwind4.pass.cpp [libc++][Android] Include cstdlib to define __BIONIC__ 2022-12-09 15:16:20 -08:00
guard_test_basic.pass.cpp [libc++] Granularize <type_traits> includes in <utility> 2022-12-22 23:17:47 +01:00
guard_threaded_test.pass.cpp
incomplete_type.sh.cpp [libc++] Use the stdlib=<LIB> Lit feature instead of use_system_cxx_lib 2023-03-30 06:57:56 -04:00
inherited_exception.pass.cpp
lit.cfg.py [NFC][Py Reformat] Reformat python files in libcxx/libcxxabi 2023-05-25 11:15:34 +02:00
noexception1.pass.cpp
noexception2.pass.cpp
noexception3.pass.cpp
noexception4.pass.cpp
test_aux_runtime_op_array_new.pass.cpp [libc++] Use the stdlib=<LIB> Lit feature instead of use_system_cxx_lib 2023-03-30 06:57:56 -04:00
test_aux_runtime.pass.cpp
test_demangle.pass.cpp [libc++] Add initial support for picolibc 2023-11-29 10:43:16 -05:00
test_exception_address_alignment.pass.cpp [libc++] Use the stdlib=<LIB> Lit feature instead of use_system_cxx_lib 2023-03-30 06:57:56 -04:00
test_exception_storage.pass.cpp [libc++abi] Overhaul test_exception_storage.pass.cpp 2023-09-11 14:14:41 -04:00
test_exception_storage.threads.pass.cpp [libc++abi] Overhaul test_exception_storage.pass.cpp 2023-09-11 14:14:41 -04:00
test_fallback_malloc.pass.cpp [libc++abi] Avoid raw calls to assert() in libc++abi (#71121) 2023-11-23 18:21:43 -05:00
test_guard.pass.cpp
test_vector1.pass.cpp
test_vector2.pass.cpp [libc++abi] Disable test with a leaks 2023-10-26 21:48:56 -07:00
test_vector3.pass.cpp
thread_local_destruction_order.pass.cpp [libcxxabi] [test] Mark thread_local_destruction_order.pass.cpp unsupported for mingw targets 2023-04-11 00:01:38 +03:00
uncaught_exception.pass.cpp
uncaught_exceptions.pass.cpp [libc++] Use the stdlib=<LIB> Lit feature instead of use_system_cxx_lib 2023-03-30 06:57:56 -04:00
unittest_demangle.pass.cpp [libc++abi] Avoid including source files into unittest_demangle 2023-06-15 11:45:05 -04:00
unwind_01.pass.cpp
unwind_02.pass.cpp
unwind_03.pass.cpp
unwind_04.pass.cpp
unwind_05.pass.cpp
unwind_06.pass.cpp