-
-
Notifications
You must be signed in to change notification settings - Fork 609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 14211 - Compiler should devirtualize calls to members of final class #4427
Conversation
|
You could test this by corrupting the vtable of a class and checking the call succeeds anyway. eg void main()
{
auto c = new Class();
*cast(void**)c = null;
c.func();
} |
|
@yebblies Unfortunately the test does not work for non-release build, because a class method asserts invariant and it requires valid this instance reference. class B
{
void func()
{
// _d_invariant() call will cause Access Violaton
}
}
final class C : B
{
}
void main()
{
auto c = new C();
*cast(void**)c = null;
c.func();
} |
|
Urrgh. Why are we calling invariants on classes that don't have invariants? |
|
Class B is not final, so its derived class may define invariants. |
|
Ah, that makes sense. extern(C++)
class B
{
void func()
{
}
}
extern(C++)
final class C : B
{
}
void main()
{
auto c = new C();
*cast(void**)c = null;
c.func();
} |
…nal class Add `CallExp::directcall` to handle devirtualizing of virtual function call in front-end. It can also handle a direct call with `DotTypeExp` by the same logic.
|
Good idea! Added test. |
|
I'm not 100% sure this should be in the frontend, but it doesn't look like it will do any harm. |
|
Auto-merge toggled on |
Issue 14211 - Compiler should devirtualize calls to members of final class
|
win32 just went red on the autotester. Any idea how this could have caused it? |
https://issues.dlang.org/show_bug.cgi?id=14211
Add
CallExp::directcallto handle devirtualizing of virtual function call in front-end.It can also handle a direct call with
DotTypeExpby the same logic.