This is an archive of the discontinued LLVM Phabricator instance.

[ms-cxxabi] Elide dtor access checks for pass-by-val objects in callees
ClosedPublic

Authored by hans on Dec 14 2013, 5:27 PM.

Details

Summary

The ABI imposes the practical requirement that the destructors can be called, but the standard does not require access checks here. This is a stab at eliding those access checks to avoid rejecting valid code, as discussed in http://llvm-reviews.chandlerc.com/D2401?id=6089#inline-12829

Diff Detail

Event Timeline

rnk added a comment.Dec 17 2013, 2:01 PM

Rather than threading a CheckDtorAccess bool through everywhere, I think you can inline a small portion of the body of FinalizeVarWithDestructor into CheckFunctionDefinition and skip the access check. Most of it is probably dead. That's what I did initially in http://llvm-reviews.chandlerc.com/D929.

hans added a comment.Dec 17 2013, 2:49 PM

Rather than threading a CheckDtorAccess bool through everywhere, I think you can inline a small portion of the body of FinalizeVarWithDestructor into CheckFunctionDefinition and skip the access check. Most of it is probably dead. That's what I did initially in http://llvm-reviews.chandlerc.com/D929.

That just removes one level of threading though. We still need to thread it through MarkFunctionReferenced to suppress access checks for base class dtors etc. when defining an implicit destructor, and that's where the ugliness comes from :/

hans updated this revision to Unknown Object (????).Dec 17 2013, 2:54 PM

Inlining the relevant part of FinalizeVarWithDestructor makes it look like this.

hans added a comment.Dec 18 2013, 3:56 PM

The problem is that MarkFunctionReferenced does access checks as it marks functions as referenced. This makes perfect sense, except here when we want to be able to call the dtor but bypass the access check.

Richard: it would be interesting to hear your thoughts on this. Is the added plumbing of this boolean variable through the various functions an acceptable approach? Would it be ok to avoid that with some mechanism to "trap" access check errors (maybe a flag on Sema)? Or is it not worth the hassle to change this?

I don't think we should elide these checks. This would lead us to behave
differently than MSVC inside of SFINAE contexts.

Sent from my phone.

rsmith added a comment.Jan 9 2014, 4:08 PM

I think you should only be removing the direct access check of the parameter type, and not handling the base and member access checks -- they're effectively part of generating the destructor definition for the parameter's type, and aren't affected by which TU the check is performed in.

I don't think we should elide these checks. This would lead us to behave
differently than MSVC inside of SFINAE contexts.

If I understand correctly, these checks only occur as part of handling a function definition, which is not a SFINAE context, so I think this is not an issue.

hans updated this revision to Unknown Object (????).Jan 10 2014, 8:50 AM

Thanks Richard! New patch attached/uploaded that only elides the direct access check. Does this look OK?

rsmith accepted this revision.Jan 10 2014, 7:13 PM

LGTM

hans closed this revision.Jan 13 2014, 9:29 AM

Closed by commit rL199120 (authored by @hans).