This is an archive of the discontinued LLVM Phabricator instance.

[analyzer] Ignore annotations if func is inlined.
ClosedPublic

Authored by aabbaabb on Nov 20 2020, 5:18 PM.

Details

Summary

When we annotating a function header so that it could be used by other TU, we also need to make sure the function is parsed correctly within the same TU.
So if we can find the function's implementation, ignore the annotations, otherwise, false positive would occur.
Move the escape by value case to post call and do not escape the handle if the function is inlined and we have analyzed the handle.

Tests: unit test.

Diff Detail

Event Timeline

aabbaabb created this revision.Nov 20 2020, 5:18 PM
aabbaabb requested review of this revision.Nov 20 2020, 5:18 PM

Thanks for working on this check! Please add the [analyzer] tag to the title of these patches.

Unfortunately, might be a hard problem to solve depending on what you want, see my comments inline.
The question is, do you actually need to skip annotation processing both in pre and postCall?

We usually check preconditions in pre, and apply effects from postconditions in post. So you might be
lucky, and it might be enough to only modify the checkPostCall. Do you observe any false positives
from checkPreCall?

clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
312

The analyzer has complex logic to decide when to "inline" a function. In this context, inline means to analyze the body at this call site (not actual inlining). Unfortunately, the analyzer might not inline a function even when the body is available (e.g. when running out of some budget like max call stack). Moreover, it might inline functions without a body (see BodyFarm for details). The bottom line is that having a function body is not a good proxy to determine whether a function body will be analyzed or not. Fortunately, it is much easier in the post-call statement as we can observe after the fact whether inlining was done.

347

Here you can use C.wasInlined to achieve what you want. See my comment above why.

xazax.hun requested changes to this revision.Nov 26 2020, 3:03 AM
This revision now requires changes to proceed.Nov 26 2020, 3:03 AM
aabbaabb updated this revision to Diff 308828.Dec 1 2020, 5:51 PM
aabbaabb marked 2 inline comments as done.
aabbaabb retitled this revision from Ignore annotations if func implementation is known. to [analyzer] Ignore annotations if func is inlined..
aabbaabb edited the summary of this revision. (Show Details)
xazax.hun accepted this revision.Dec 2 2020, 3:49 AM

LGTM, thanks!

This revision is now accepted and ready to land.Dec 2 2020, 3:49 AM
martong removed a subscriber: martong.Dec 2 2020, 3:51 AM
steakhal added inline comments.Dec 2 2020, 11:08 AM
clang/test/Analysis/fuchsia_handle.cpp
352

Could we see which handle leaked?
Oh, I see, a is closed, so the only handle that could leak is b.
Before the patch, it was not reported, but now it is.

Am I right?

Regardless, IMO it would be cleaner to have some note about this in the expected message.

aabbaabb updated this revision to Diff 309122.Dec 2 2020, 6:57 PM
aabbaabb marked an inline comment as done.
aabbaabb added inline comments.
clang/test/Analysis/fuchsia_handle.cpp
352

updated comment.

aabbaabb marked an inline comment as done.Dec 2 2020, 7:09 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptDec 7 2020, 11:28 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript