Skip to content

Conversation

@sbc100
Copy link
Collaborator

@sbc100 sbc100 commented Jun 11, 2021

We can simply pass the adjusted pointer location as the final argument to
__cxa_can_catch. This function will set this location on success.

We can simply pass the adjusted pointer location as the inal argument to
`__cxa_can_catch`.  This function will set this location on success.
@sbc100 sbc100 requested review from aheejin and kripken June 11, 2021 23:52
var thrownType = info.get_type();
var catchInfo = new CatchInfo();
catchInfo.set_base_ptr(thrown);
catchInfo.set_adjusted_ptr(thrown);
Copy link
Member

Choose a reason for hiding this comment

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

How are catchInfo's base ptr and adjusted ptr different?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure exactly but this is features of libcxxabi. I think it relates to virtual inheritance.

if (thrown !== adjusted) {
catchInfo.set_adjusted_ptr(adjusted);
}
if ({{{ exportedAsmFunc('___cxa_can_catch') }}}(caughtType, thrownType, catchInfo.get_adjusted_ptr_addr())) {
Copy link
Member

Choose a reason for hiding this comment

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

Previously, the adjusted ptr is set only when we can catch it, but now it is always set. Is this fine?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that is still true.. __cxa_can_catch only writes to its third argument if it returns non-zero:

if (ret) *thrown = temp; // apply changes only if we are catching

Copy link
Member

Choose a reason for hiding this comment

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

Ah right, I was confused.

@sbc100 sbc100 merged commit 2cfa447 into main Jun 14, 2021
@sbc100 sbc100 deleted the optimize_can_catch branch June 14, 2021 19:17
var thrownType = info.get_type();
var catchInfo = new CatchInfo();
catchInfo.set_base_ptr(thrown);
catchInfo.set_adjusted_ptr(thrown);
Copy link
Member

Choose a reason for hiding this comment

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

I don't follow how this is NFC. This extra call will write a change to memory, and if we return on line 401 then it is noticeable, isn't it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh sorry, yes, this is setting the adjusted pointer in all cases, I forgot I ended up adding this line.

Basically __cxa_can_catch expects the existing value here to be the base_ptr and then it updates it accordingly.

The get_exception_ptr method will always prefer the adjusted pointer and fall back to the base ptr if its zero. I think in practice this now means that the fallback is not needed, but I also don't think there is any observable effect. The adjusted pointer will be equal the base pointer in the case that no adjustment was made.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In modifying this code I'm fairly sure we have enough test coverage of this adjustment in our test suite, so if this was not NFC I think we would have seen a test failure.

Copy link
Member

Choose a reason for hiding this comment

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

I see. Seems likely to be correct, yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants