<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64951>64951</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[libc++abi] coredump case of __dynamic_cast
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Jolyon0202
</td>
</tr>
</table>
<pre>
We found a testcast(from dejac++) coredump when using libc++'s dynamic_cast. And we are not sure that it's used ro crash while looking in A for my_module. The test case if here: https://godbolt.org/z/6rh6zf88e
`
extern "C" int puts (const char *);
extern "C" void abort ();
struct my_object
{
my_object() { puts ("in my_object ctor");}
virtual ~my_object() { puts ("in my_object dtor"); }
};
my_object* my_module_ptr = 0;
struct my_module : my_object
{
my_module()
{
puts ("in my_module ctor, setting up ptr");
my_module_ptr = this;
}
~my_module() { puts ("in my_module dtor");}
};
struct D
{
D() { puts ("in D ctor"); }
virtual ~D();
};
D::~D()
{
puts ("in D dtor");
puts ("before DCASTing to my_module*");
if (my_module_ptr == 0){
puts ("nullptr");
}
my_module* m = dynamic_cast<my_module*>(my_module_ptr);
puts ("ok");
if (m != my_module_ptr){
puts ("abort");
abort ();
}
puts ("after DCASTing to my_module*");
}
struct my_interface
{
my_interface() { puts ("in my_interface ctor");}
~my_interface() { puts ("in my_interface dtor");}
};
struct myif : virtual my_interface
{
myif() { puts ("in myif ctor");}
~myif() { puts ("in myif dtor");}
};
struct A: virtual myif
{
A() { puts ("in A ctor"); }
~A() { puts ("in A dtor"); }
D d;
};
struct B: virtual myif
{
B() { puts ("in B ctor"); }
~B() { puts ("in B dtor"); }
D d;
};
struct C : my_module, A, B
{
C() { puts ("in C ctor");}
~C() { puts ("in C dtor"); }
};
int main(int, char**)
{
C t;
}
`
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVkuPozgQ_jXmUpqImITHgQOBzWGvO9IeI4NN8AzYkW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