<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/64383>64383</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Thrown null pointer cannot be caught with base-class catch
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          zhusihang
      </td>
    </tr>
</table>

<pre>
    ### The problem
for example
```
#include <iostream>

struct A {};
struct B : virtual A {};
struct C : virtual A {};
struct D : virtual A {};
struct E : private B, public C, private D {};

extern "C" void abort ();

void fne (E *e)
{
  throw e;
}

void check(E *e)
{
  try { fne(e); }
  catch(A *p) { std::cout << "caught" << std::endl; }
  catch(...) { std::cout << "catch(...) abort" << std::endl; abort(); }
  return;
}

int main ()
{
  E e;
  check ((E *)0);
  return 0;
}
```
There are a standard pointer conversion  not involving conversions to pointers to private or protected or ambiguous classes:
E --- C --- A
However it caught by `catch(...)`, which clearly is a bug.

### Analysis
For the above scenario, a null pointer of type E is thrown, according to the implementation of process_found_base_class in libcxx:

* E---B>>>A: firstly, dst_ptr_leading_to_static_ptr in the record has just been initialized to 0, and the 'thrown to catch' path is recorded as `not_public_path`, while dst_ptr_leading_to_static_ptr is assigned a value of adjustedPtr, which is also 0;
* E>>>C>>>A: Second, dst_ptr_leading_to_static_ptr is still equal 0, which is considered to be the first matching type found, and the  'thrown to catch' path is recorded as the current path type as `public_path`, adjustedPtr == 0;
* E---D>>>A: the value of dst_ptr_leading_to_static_ptr is still 0, it is considered that the matching type is found for the first time, and the throwtocatch path is recorded as not_public_path
The final recorded 'thrown to catch' path type is not_public_path, which means that there is no public path and cannot be caught.
Overall, since the value of adjust ptr is always 0, the third search result covers the second public inheritance path.

### Solution
According to this link[https://github.com/llvm/llvm-project/issues/17595](https://github.com/llvm/llvm-project/issues/17595), the pointer of the base class should be able to catch the null pointer

`AdjustedPtr` is a variableļ¼Œ which may cause corner cases as a branch condition. Is it more reasonable to `use number_to_static_ptr` as a branch condition?

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyklk-T2jwSxj-NuHRBGXkAc-DA39o97VYld0qWG6xEllhJ9gz59FstGQaTTDLv-1YxDEjt7tbvkR4hvFdng7hisw2b7UaiDbV1qx9161UtzHlU2uq6YjxPL_haI1ycLTU2LNuxbH2yDvBNNBeNaYDNs_6VvvJcGanbCoHlW2V9cCgalu_76fjug2tlgDWwxYYtdizfDMY3wPI1dMqFVugPo7afitp9Kmofoy5OdSIgbBjfwqUttZKwjZ_7id3z4-kd3wI6A4zzLeMcOqsqEKV1ARgvGF8-hcf5k0Ga3QPja6SYFLDoIwFC7ewr4Puzi91PSWSN8vvvs7gr9UzlGC8wNQP3XABSBFkzXqwpxYXxZQz3oWL5muVradtAQrJ8S-uToj3XgRbZj90D0VT6g9STyeTPeQehEd7vqvQBxc_rcRhaZz6ipkyARihzE-YZ1_4BOCS8KTQhZnyZPep5KwfZLwoOz8XXGh2CoD_wQZhKuAouVpmADqQ1HTqvrAEwNoAyndWdMueHGQ_B3h5In_tNaR2d0IAyYEVfRFOqc2tbD1IL79ETutjDHsbjMWzjez_0L_uKHTpQAZK2UF6BzbOhILQKvoXXWskapEbh9BWUBwFle548An53jrUR-uqVT-MH6yDUSMJ1CF6iEU5ZSirAtFrfUdgThOsFYU_54xkwMUpK6yoiEmxMpMiBGjRBBMJmTwRBovfHk21NdSyFx2MEAMqAVqV8e7uDuPW6hv14PN6QO8UXbTE4KeeDvlLVyofjJbijRkG1j8EePRWUNEp5qROH1BrUwsO31gcoEQ0oo4ISWv3AijqO-ISp4gOML9LCaKYHvYCLCDWtOaXDCoQnIYwNx2RFR4p4V0Ljn9rz0Lt9BQI6oVskTKKiLrH6b3DvmlKs9vZxHxOcO5jtENEXlNZUnyDkwQelNeD_yH2zQUFpjVcVukSoxMgmwoeGoESxaStEQR8B_gWCFC5b59CENB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