Page MenuHomePhabricator

[analyzer] Support allocClassWithName in OSObjectCStyleCast checker
ClosedPublic

Authored by vsavchenko on Mar 29 2021, 5:47 AM.

Details

Summary

allocClassWithName allocates an object with the given type.
The type is actually provided as a string argument (type's name).
This creates a possibility for not particularly useful warnings
from the analyzer.

In order to combat with those, this patch checks for casts of the
allocClassWithName results to types mentioned directly as its
argument. All other uses of this method should be reasoned about
as before.

rdar://72165694

Diff Detail

Event Timeline

vsavchenko created this revision.Mar 29 2021, 5:47 AM
vsavchenko requested review of this revision.Mar 29 2021, 5:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2021, 5:47 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
NoQ accepted this revision.Mar 29 2021, 11:04 PM

LGTM! Thanks for formatting ^.^

WDYT about a heuristic that literally matches the source code of the casted expression as plain text to see if it mentions the type? Like, regardless of allocClassWithName(), if it mentions the type it probably has something to do with that type.

This revision is now accepted and ready to land.Mar 29 2021, 11:04 PM
In D99500#2657675, @NoQ wrote:

LGTM! Thanks for formatting ^.^

WDYT about a heuristic that literally matches the source code of the casted expression as plain text to see if it mentions the type? Like, regardless of allocClassWithName(), if it mentions the type it probably has something to do with that type.

This idea sounds good in general, but it feels like it can backfire in some cases. As any regex-like solution, it will have ridiculous corner cases when the name of the type is too generic and can appear as a sub-word.