This is an archive of the discontinued LLVM Phabricator instance.

Fix assertion failure "PathDiagnosticSpotPiece's must have a valid location." in ReturnPtrRange checker on builtin functions
ClosedPublic

Authored by arseniy-sonar on Nov 25 2022, 7:00 AM.

Details

Summary

Fixes #55347
Builtin functions (such ast std::move, std::forward, std::as_const) have a body generated during the analysis not related to any source file so their statements have no valid source locations.
ReturnPtrRange checker should not report issues for these builtin functions because they only forward its parameter and do not create any new pointers.

Diff Detail

Event Timeline

arseniy-sonar created this revision.Nov 25 2022, 7:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 25 2022, 7:00 AM
Herald added a subscriber: rnkovacs. · View Herald Transcript
arseniy-sonar requested review of this revision.Nov 25 2022, 7:00 AM
steakhal resigned from this revision.Nov 25 2022, 7:08 AM

I already reviewed this internally. For me, it looks great.

@arseniy-sonar consider adding the Fixes #55347 marker to the summary, so the commit will auto-reference the fixed issue.
Also mention the commit author sign to which we should accredit this revision if accepted.

arseniy-sonar edited the summary of this revision. (Show Details)Nov 25 2022, 7:17 AM
NoQ accepted this revision.Nov 28 2022, 1:14 PM

LGTM, thanks!

This patch seems obvious but please upload with context next time (https://llvm.org/docs/Phabricator.html#phabricator-request-review-web).

clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp
48

I suspect that you might run into more similar problems with functions coming from "body farms". A direct check like

RetE->getBeginLoc().isValid()

might be more reliable.

You might need to check the entire range though. We probably need a unified solution for such checks, because many checkers end up implementing them.

This revision is now accepted and ready to land.Nov 28 2022, 1:14 PM
steakhal added inline comments.Nov 28 2022, 2:13 PM
clang/lib/StaticAnalyzer/Checkers/ReturnPointerRangeChecker.cpp
48

We were actually considering it. We decided against it to keep the impact of this fix minimal.

That being said, I wonder if a similar check should be at some higher level API, lets say inside the emitReport.
That way no chevker would experience such crashes. WDYT?

I think we should backport this to release/16.x.
Here is the ticket for it: https://github.com/llvm/llvm-project/issues/61115