This revision was automatically updated to reflect the committed changes. Closed by commit rC359263: [analyzer] RetainCount: Allow offsets in return values. (authored by dergachev, committed by ).
Changed prior to commit: https://reviews.llvm.org/D60991?vs=196170&id=196781#toc Repository: rC Clang CHANGES SINCE LAST ACTION https://reviews.llvm.org/D60991/new/ https://reviews.llvm.org/D60991 Files: lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp test/Analysis/retain-release.mm Index: test/Analysis/retain-release.mm =================================================================== --- test/Analysis/retain-release.mm +++ test/Analysis/retain-release.mm @@ -515,3 +515,35 @@ } } + +namespace reinterpret_casts { + +void *foo() { + void *p = const_cast<void *>( + reinterpret_cast<const void *>(CFArrayCreate(0, 0, 0, 0))); + void *q = reinterpret_cast<void *>( + reinterpret_cast<char *>(p) + 1); + // FIXME: Should warn about a leak here. The function should return at +0, + // but it returns at +1 instead. + return q; +} + +void *fooCreate() { + void *p = const_cast<void *>( + reinterpret_cast<const void *>(CFArrayCreate(0, 0, 0, 0))); + void *q = reinterpret_cast<void *>( + reinterpret_cast<char *>(p) + 1); + // The function follows the Create Rule. + return q; // no-warning +} + +void *fooBar() CF_RETURNS_RETAINED { + void *p = const_cast<void *>( + reinterpret_cast<const void *>(CFArrayCreate(0, 0, 0, 0))); + void *q = reinterpret_cast<void *>( + reinterpret_cast<char *>(p) + 1); + // The function follows the Create Rule. + return q; // no-warning +} + +} Index: lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp +++ lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp @@ -970,8 +970,10 @@ return Pred; ProgramStateRef state = C.getState(); - SymbolRef Sym = - state->getSValAsScalarOrLoc(RetE, C.getLocationContext()).getAsLocSymbol(); + // We need to dig down to the symbolic base here because various + // custom allocators do sometimes return the symbol with an offset. + SymbolRef Sym = state->getSValAsScalarOrLoc(RetE, C.getLocationContext()) + .getAsLocSymbol(/*IncludeBaseRegions=*/true); if (!Sym) return Pred;
Index: test/Analysis/retain-release.mm =================================================================== --- test/Analysis/retain-release.mm +++ test/Analysis/retain-release.mm @@ -515,3 +515,35 @@ } } + +namespace reinterpret_casts { + +void *foo() { + void *p = const_cast<void *>( + reinterpret_cast<const void *>(CFArrayCreate(0, 0, 0, 0))); + void *q = reinterpret_cast<void *>( + reinterpret_cast<char *>(p) + 1); + // FIXME: Should warn about a leak here. The function should return at +0, + // but it returns at +1 instead. + return q; +} + +void *fooCreate() { + void *p = const_cast<void *>( + reinterpret_cast<const void *>(CFArrayCreate(0, 0, 0, 0))); + void *q = reinterpret_cast<void *>( + reinterpret_cast<char *>(p) + 1); + // The function follows the Create Rule. + return q; // no-warning +} + +void *fooBar() CF_RETURNS_RETAINED { + void *p = const_cast<void *>( + reinterpret_cast<const void *>(CFArrayCreate(0, 0, 0, 0))); + void *q = reinterpret_cast<void *>( + reinterpret_cast<char *>(p) + 1); + // The function follows the Create Rule. + return q; // no-warning +} + +} Index: lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp =================================================================== --- lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp +++ lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp @@ -970,8 +970,10 @@ return Pred; ProgramStateRef state = C.getState(); - SymbolRef Sym = - state->getSValAsScalarOrLoc(RetE, C.getLocationContext()).getAsLocSymbol(); + // We need to dig down to the symbolic base here because various + // custom allocators do sometimes return the symbol with an offset. + SymbolRef Sym = state->getSValAsScalarOrLoc(RetE, C.getLocationContext()) + .getAsLocSymbol(/*IncludeBaseRegions=*/true); if (!Sym) return Pred;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits