Issue 14211 - Compiler should devirtualize calls to members of final class#4427
Merged
braddr merged 1 commit intodlang:masterfrom Feb 21, 2015
Merged
Issue 14211 - Compiler should devirtualize calls to members of final class#4427braddr merged 1 commit intodlang:masterfrom
braddr merged 1 commit intodlang:masterfrom
Conversation
Contributor
|
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();
} |
Contributor
Author
|
@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();
} |
Contributor
|
Urrgh. Why are we calling invariants on classes that don't have invariants? |
Contributor
Author
|
Class B is not final, so its derived class may define invariants. |
Contributor
|
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.
Contributor
Author
|
Good idea! Added test. |
Contributor
|
I'm not 100% sure this should be in the frontend, but it doesn't look like it will do any harm. |
Contributor
|
Auto-merge toggled on |
braddr
added a commit
that referenced
this pull request
Feb 21, 2015
Issue 14211 - Compiler should devirtualize calls to members of final class
Contributor
|
win32 just went red on the autotester. Any idea how this could have caused it? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.