<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/113286>113286</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Incorrect DCE with `fvirtual-function-elimination fvisibility=hidden`
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Umesh-k26
</td>
</tr>
</table>
<pre>
Reproducer:
```
// RUN: clang++ -O1 -flto -fvirtual-function-elimination -fvisibility=hidden %s
#include <stdio.h>
class MyClass {
public:
virtual int foo(int e) {
return 42+e;
}
};
int main() {
MyClass c;
using casted_foo_t = int (MyClass::*)(long);
auto casted_foo = (casted_foo_t)&MyClass::foo;
printf("%d\n", (c.*casted_foo)(2));
}
```
Output:
`Segmentation fault (core dumped)`
The type metadata node for `foo` ( !"_ZTSM7MyClassFiiE.virtual" ) and `casted_foo_t` ( !"_ZTSM7MyClassFilE.virtual" ) is different.
In GlobalDCE, these callsites are analyzed only with type metadata, and address taken here is not captured.
`GlobalStatus` might not help here, as the virtual-function's use-list only contains vtables and not the callsites.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8lE2PGjkTxz9NcSmBmmq6Gw59mIHhUQ55ImWSy15Gxq6mvTE28stE7Kdf2fQMQ7K7CNmGcv3qX-WyRQj6aJl7aB6h2c1EiqPz_fcTh3H-g9rZwalL_5XP3qkk2UP9gFDtoHqAtpq-15-0B9rj1-__z1ukEfYI9Aj0iPMvS5wPJjqcD6_axyTMfEhWRu3snI0-aSvyupiDPmij4wXq3aiVYotATXgLUWsrTVKMUG9DVNotRqifJmsZpREh4OfLtszQPV7_PqeD0RLqaRci4iQFtY04OAe0zisG2tzccPp4jslbXBHQI0P9wQrdbgrf7d4N1zHjTkJboPVv0DeB8g6WgrZHlCJEVi-Dcy8Rod4VhUDryScnUT8APQBtgNbG5UJv7jgiRfcBUyBA64_g4tzeIXMRPlLOXts4FPUE1ChotrYstwW2AHq4Ea9iqEw3Mbfq_NIsZfyS4jnF90OBtnrm44ltvLbDIJIpiUvnGVU6nVll-D3k28gYL2fGE0ehRBRonWIcnEdoq6ysrTBTEGgJRC9_fHv-3E2J77V-WkyNAESYz0lYlT3vitVW_04wvxF0QKWHgT3buJhuyyeL_zPuIMxu-5QrGEcOjFIYE3TkgMIzCivM5S9W6Ky54E8dx_vMsl9WJ5TyHAJG8YMtjuw5h7QuohTnmDyrt6jvhb3Gfo4ippCzOenjGIvLyOZcGIUesjD89ZYCdQFT4LnRIV7VSWej0DbgaxQHkxOwqvCy_3taC5ypvlabeiNm3C872jTrddssZ2Nfr9ZNLbkR1HZScC06XtVSyqGtRNdtljPdU0WrZUVUbZZdvVyIZiWoqpXkppZiTbCq-CS0WRjzelo4f5zpEBL3y2VN63ZmxIFNKO8akeWfWKy5gZvdzPfZaX5IxwCrKqcVbpioo-H-k5XOe5YRd9un62nkhvrPF-yfHrBc7lnyph9jPJerVl7Ko45jOiykOwHtc-hpmp-9-5NlBNoXwQFoP2X02tPfAQAA__9C6rm_">