<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/116070>116070</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] Question about devirtualization
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vient
</td>
</tr>
</table>
<pre>
Here is the test case
```cpp
struct A {
virtual int f() {
return 1;
}
int call_f() {
return f();
}
};
struct C final: public A {
int f() override {
return 3;
}
};
int test1(C& c) {
return c.f();
}
int test2(C& c) {
return c.call_f();
}
```
Both Clang and GCC devirtualize `f` call in `test1` but not in `test2` - why is that so? `C` is final, what is the scenario when call to `C::call_f` does not lead to `C::f`?
https://godbolt.org/z/6Kv38jeYo
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMU01v2zAM_TX0hWigD9txDj6kDrwBO-240yBbdKxCtQJJTtH--kGx26bJBiwIYOhRfOTjE1UI5jgR1VA8QnHI1BxH5-uzoSlmndOv9XfyhCZgHAkjhYi9CgTsAGwPJVv-_em0ICH6uY-4R9g-Lggi4tn4OCuLZoo4gKhA7K4ueIqzn5CDvEqB7WGt8QGl7F5Z-_ueYv2tTGv8k--TbHv4QL803OBgJmVB7vE0d9b0txKuW3dn8t5outcg_6HhrmyiS8PkIKoGRIn9naCVst_cyrkZzTuV-A-q6_H9he_dzuX46OKIjVXTEdWk8VvToKbVSvNGCCUboGQXT9BM6bxIKhl2c8TJxStYJPgBX8bX5TGpiMGBbFO8STETVg9Egy8pvL650NOkvHH4MtK0FItuyZJ7kPtVU8lQOwqXqpaU_nopxUG2i7AxxlNIuGhBtEenO2fjxvkjiPYNRFv-OMvqiX65TNdS7-ROZVTzreQFl3kls7FmLM9zGjohpeCsq0jtRLfLu6Ha9lUlh8zUgomccy55UVRMbhSrNHHNtd7xYugryBk9K2M31p6fU-3MhDBTzXnJtiyzqiMbLkspRJ88ACHSfvo6JTx08zFAzqwJMXxSRBPtZZOXjOKAP2cK0bgJVefmeO2fSnA2e1vfjMPEce42vXsG0Sbm9fNw8u6J-giivXQaQLRrs-da_AkAAP__D8Y3Cw">