This patch supports std::data and std::addressof functions.
rdar://73463300
Differential D99260
[analyzer] Fix false positives in inner pointer checker (PR49628) vsavchenko on Mar 24 2021, 6:18 AM. Authored by
Details This patch supports std::data and std::addressof functions. rdar://73463300
Diff Detail
Event TimelineComment Actions I recommend splitting this into two. I would happily accept the part about std::data(). IMO std::addressof() should be modelled via evalCall as a pure function, instead of hacking it into the InnerPtrChecker. Comment Actions It does make sense to split these in two, but I'm not so sure about evalCall. It is definitely not something that InnerPtrChecker should be bothered with. Another point is that std::addressof might be only one of the function receiving a non-const reference and not modifying it, so it would
But it has a T & overload as well, and this is the one causing the FP.
Comment Actions
evalCall should work great for this purpose but definitely not in this checker. Also this checker would still exercise its checkPostCall so it would still need to be silenced even if evalCall is implemented.
Comment Actions In https://bugs.llvm.org/show_bug.cgi?id=45786 the godbolt link shows that there are still problems with addressof (yes, their "trunk" clang is fresh enough). They seem to have __addressof instead of addressof so maybe we should cover that case real quick. Or maybe outright suppress reference invalidation on double-underscore functions because the checker generally relies on the number of standard functions that don't invalidate references while taking a non-const reference being very limited but this limit definitely doesn't take double-underscore functions into account. Comment Actions Ah, yep. Just got back from my vacation! Comment Actions Based on the comment from @vsavchenko , I had made an addition for a check for __addressof alongside addressof in the checker. What would be the correct way of pushing the diff here? Should I reopen this revision or use the update diff button on the top? I apologize, I'm completely new to pushing changes to LLVM. Thanks, |
This will crash if someone overloads std::data with 0 arguments because your CallDescriptions don't require a specific number of arguments. (They're not allowed to do that, yes, but we're still not allowed to crash.)