Skip to content

Commit

Permalink
[analyzer] RetainCount: Fix os_returns_retained_on_zero with weird re…
Browse files Browse the repository at this point in the history
…turn types.

The checker was crashing when it was trying to assume a structure
to be null or non-null so that to evaluate the effect of the annotation.

Differential Revision: https://reviews.llvm.org/D61958

llvm-svn: 360790
  • Loading branch information
haoNoQ authored and MrSidims committed May 24, 2019
1 parent 2a802c9 commit feb3861
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Expand Up @@ -537,6 +537,11 @@ updateOutParameters(ProgramStateRef State, const RetainSummary &Summ,
ProgramStateRef AssumeZeroReturn = State;

if (SplitNecessary) {
if (!CE.getResultType()->isScalarType()) {
// Structures cannot be assumed. This probably deserves
// a compiler warning for invalid annotations.
return {State};
}
if (auto DL = L.getAs<DefinedOrUnknownSVal>()) {
AssumeNonZeroReturn = AssumeNonZeroReturn->assume(*DL, true);
AssumeZeroReturn = AssumeZeroReturn->assume(*DL, false);
Expand Down
13 changes: 13 additions & 0 deletions clang/test/Analysis/osobject-retain-release.cpp
Expand Up @@ -702,3 +702,16 @@ OSObject *testSuppressionForMethodsEndingWithMatching(IOService *svc,
// returning from it at +0.
return table; // no-warning
}

namespace weird_result {
struct WeirdResult {
int x, y, z;
};

WeirdResult outParamWithWeirdResult(OS_RETURNS_RETAINED_ON_ZERO OSObject **obj);

WeirdResult testOutParamWithWeirdResult() {
OSObject *obj;
return outParamWithWeirdResult(&obj); // no-warning
}
} // namespace weird_result

0 comments on commit feb3861

Please sign in to comment.