Skip to content
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

fix Issue 18966 - extern(C++) constructor should match C++ semantics … #8362

Merged
merged 1 commit into from
Jun 17, 2018

Conversation

rainers
Copy link
Member

@rainers rainers commented Jun 16, 2018

…assigning vtable

set vtbl after exlicit or implicit call to super() in C++ constructors

@dlang-bot
Copy link
Contributor

dlang-bot commented Jun 16, 2018

Thanks for your pull request, @rainers!

Bugzilla references

Auto-close Bugzilla Severity Description
18966 critical extern(C++) constructor should match C++ semantics assigning vtable

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "stable + dmd#8362"

@TurkeyMan
Copy link
Contributor

LGTM :)

@TurkeyMan
Copy link
Contributor

Hey @MartinNowak, I saw you branched the beta for the next release.
I just wanted you to be aware that this PR completes a large body of work, which I think will be one of the biggest headline features for 2.081. Just wanted to check that we'll be able to get it in there, and that the branch isn't frozen?

@TurkeyMan
Copy link
Contributor

If reviewers could expedite this PR, it should be in 2.081 along with all the other extern(C++) work this cycle.

@JinShil JinShil added this to the 2.081.0 milestone Jun 17, 2018
@JinShil JinShil added the Vision Vision Plan https://wiki.dlang.org/Vision/2018H1 label Jun 17, 2018
Copy link
Member

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good to me based on the diff, but I'm not that familiar with C++, s.t. I would feel comfortable with approving it.

…assigning vtable

set vtbl after exlicit or implicit call to super() in C++ constructors
@rainers rainers changed the base branch from master to stable June 17, 2018 16:18
@rainers
Copy link
Member Author

rainers commented Jun 17, 2018

Rebased to stable.

@dnadlinger
Copy link
Member

Someone else should have a look at the backend part of the commit, but the changes make sense and I see no reason not to trust Rainer to get this right. Having a known-buggy implementation in 2.081 is worse than having a unreviewed one, so merging now to make sure this isn't lost.

@dlang-bot dlang-bot merged commit 297844f into dlang:stable Jun 17, 2018
ibuclaw added a commit to ibuclaw/dmd that referenced this pull request Jun 20, 2018
As per dlang#8362, this function also needs calling from the backend.
kinke added a commit to ldc-developers/ldc that referenced this pull request Jun 23, 2018
There's a new need to access a class' vtable symbol, see dlang/dmd#8362.

Use it as alias to the actual vtable symbol with different type (dummy:
`i8*`, actual: `[N x i8*]`) and mangled name.

I tried matching the special symbol's mangled name and using an
appropriate static array front-end type for it, but then casting the
symbol address for the assignment leads to issues if the ctor is @safe.
So I decided to handle it in DtoSymbolAddress().

Unfortunately, this seems not to solve the extern(C++) issues exposed by
LDC self-compilation yet.
{
// if super is defined in C++, it sets the vtable pointer to the base class
// so we have to rewrite it, but still return 'this' from super() call:
// (auto tmp = super(), this.__vptr = __vtbl, tmp)
Copy link
Contributor

@kinke kinke Aug 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This vtbl assignment cannot be interpreted at compile-time, see https://forum.dlang.org/thread/ghusgzuqpcskhwzmlwbh@forum.dlang.org. Happening here:

pointer cast from cpp.Y to immutable(void*)** is not supported at compile time

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does CTFE assign vtables?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually an issue? Any class with an opaque constructor (ie, is defined in C++) can't possibly CTFE...?

Copy link
Contributor

@kinke kinke Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, if there's an external ctor, CTFE will fail anyway (untested :]). If they're all in D, it used to work before, so it's clearly a regression, and resetting the vptr can probably be safely skipped during CTFE (something like __ctfe || (this.__vptr = __vtbl)).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> #8533

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, if that logic is only performed when the base constructor is extern, then it should still be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge Bug Fix Vision Vision Plan https://wiki.dlang.org/Vision/2018H1
Projects
None yet
7 participants