This is an archive of the discontinued LLVM Phabricator instance.

Fix consteval crash when transforming 'this' expressions
ClosedPublic

Authored by aaron.ballman on Oct 14 2021, 8:46 AM.

Details

Summary

When reaching the end of a function body, we need to ensure that the ExitFunctionBodyRAII object is destroyed before we pop the declaration context for the function. Exiting the function body causes us to handle immediate invocations, which involves template transformations that need to know the correct type for this.

This addresses PR48235.

(Note, the diff in Phrabricator looks more awful than it is in reality -- the only change to the code was to add a new compound scope, but indenting the contents of that new scope seems to make for confusing-looking diffs.)

Diff Detail

Event Timeline

aaron.ballman requested review of this revision.Oct 14 2021, 8:46 AM
aaron.ballman created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptOct 14 2021, 8:46 AM
erichkeane added inline comments.Oct 14 2021, 9:04 AM
clang/lib/Sema/SemaDecl.cpp
14839

so the only real change here is that ExitFunctionBodyRAII ends here, instead of the end of the function?

I guess this SEEMS pretty innocuous, I don't know particularly what PopFunctionScopeInfo does well enough to know if this is going to cause problems, but I DO know at least the 14850+ doesn't need to have the function body in scope (and PopDeclContext seems like it doesn't do much?)...

I would think that anything after PopDeclContext would have a problem being in the function body anyway (that is, being in a 'function body' with a mismatched DeclContext seems wrong), so I'm reasonably convinced this is at least non-breaking.

aaron.ballman added inline comments.Oct 14 2021, 9:48 AM
clang/lib/Sema/SemaDecl.cpp
14839

so the only real change here is that ExitFunctionBodyRAII ends here, instead of the end of the function?

That's correct. I added the opening curly brace before the comments on the declaration of ExitRAII, and the close curly brace is on the line with the new comments added to it. Git decided this was the best diff it could come up with for all that re-indentation. :-/

I would think that anything after PopDeclContext would have a problem being in the function body anyway (that is, being in a 'function body' with a mismatched DeclContext seems wrong), so I'm reasonably convinced this is at least non-breaking.

This matches my thinking -- just before we go to pop the declaration context or scope, *that* is when the function body has ended.

erichkeane accepted this revision.Oct 26 2021, 12:04 PM

I think the others had enough time on this one, it LGTM.

This revision is now accepted and ready to land.Oct 26 2021, 12:04 PM
rjmccall accepted this revision.Oct 26 2021, 4:14 PM

This seems reasonable. You could also give ExitFunctionBodyRAII an explicit pop() operation, but either way is fine.

aaron.ballman closed this revision.Oct 27 2021, 8:26 AM

Thanks for the reviews! I've commit in 9fcca8b470fb92466ec4cada9fbeacc90096116d.