This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Fix a crash in NoStateChangeVisitor with body-farmed stack frames.
ClosedPublic

Authored by NoQ on Feb 10 2022, 7:36 PM.

Details

Summary

LocationContext::getDecl() isn't useful for obtaining the "farmed" body because the (synthetic) body statement isn't actually attached to the (natural-grown) declaration in the AST. This manifests in hard crashes every time the visitor tries to scan the body-farmed stack frame.

Note that it's technically possible to obtain and scan the body. It's useless to do so though, given that you can't put notes into it, given that it doesn't map into any user source code.

The C test case is libdispatch/blocks-specific but the C++ test case is something that can happen to everybody, even though the premise is roughly the same.

Diff Detail

Event Timeline

NoQ created this revision.Feb 10 2022, 7:36 PM
NoQ requested review of this revision.Feb 10 2022, 7:36 PM

I dont even see why should the no-state-changed-visitor attempt to do anything with that call. It should have disarm itself when it reaches the allocation. It its not the case, we should probably consider fixing that as well in a followup.
Please consider rearranging the code to make it possible for the synthetized callee to actually deallocate the memory.

NoQ updated this revision to Diff 408012.Feb 11 2022, 1:09 PM

Oh, great point. Added tests that were crashing the other way round so that to demonstrate that this fix is still justified. But I agree that the visitor can totally terminate early so that to make the original tests pass for two reasons!

steakhal accepted this revision.Feb 14 2022, 9:40 AM

Thanks.

This revision is now accepted and ready to land.Feb 14 2022, 9:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 17 2022, 10:13 AM