aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-07-02[clang][StaticAnalyzer] Avoid 'raw_string_ostream::str' (NFC)Youngsuk Kim1-6/+6
Since `raw_string_ostream` doesn't own the string buffer, it is desirable (in terms of memory safety) for users to directly reference the string buffer rather than use `raw_string_ostream::str()`. Work towards TODO comment to remove `raw_string_ostream::str()`.
2024-04-11[NFC][Clang] Improve const correctness for IdentifierInfo (#79365)Bill Wendling1-2/+2
The IdentifierInfo isn't typically modified. Use 'const' wherever possible.
2024-01-01[analyzer][NFC] Cleanup BugType lazy-init patterns (#76655)Balazs Benics1-30/+18
Cleanup most of the lazy-init `BugType` legacy. Some will be preserved, as those are slightly more complicated to refactor. Notice, that the default category for `BugType` is `LogicError`. I omitted setting this explicitly where I could. Please, actually have a look at the diff. I did this manually, and we rarely check the bug type descriptions and stuff in tests, so the testing might be shallow on this one.
2023-12-13[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)Kazu Hirata1-2/+2
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-07-10[NFC] Initialize class member pointers to nullptr.Sindhu Chittireddy1-1/+1
Reviewed here: https://reviews.llvm.org/D153926
2023-07-05[analyzer][NFC] Move away from using raw-for loops inside StaticAnalyzerBalazs Benics1-2/+2
I'm involved with the Static Analyzer for the most part. I think we should embrace newer language standard features and gradually move forward. Differential Revision: https://reviews.llvm.org/D154325
2023-06-16[NFC] Fix potential dereferencing of null return value.Sindhu Chittireddy1-1/+3
Replace getAs with castAs and add assert if needed. Differential Revision: https://reviews.llvm.org/D152977
2023-01-14[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-2/+2
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14[clang] Add #include <optional> (NFC)Kazu Hirata1-0/+1
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-08Fix duplicate word typos; NFCRageking81-1/+1
This revision fixes typos where there are 2 consecutive words which are duplicated. There should be no code changes in this revision (only changes to comments and docs). Do let me know if there are any undesirable changes in this revision. Thanks.
2022-06-20[clang] Don't use Optional::getValue (NFC)Kazu Hirata1-2/+2
2020-08-03[analyzer] Simplify function SVal::getAsSymbolicExpression and similar onesDenys Petrov1-1/+1
Summary: Simplify functions SVal::getAsSymbolicExpression SVal::getAsSymExpr and SVal::getAsSymbol. After revision I concluded that `getAsSymbolicExpression` and `getAsSymExpr` repeat functionality of `getAsSymbol`, thus them can be removed. Fix: Remove functions SVal::getAsSymbolicExpression and SVal::getAsSymExpr. Differential Revision: https://reviews.llvm.org/D85034
2020-03-27[analyzer][NFC] Change LangOptions to CheckerManager in the shouldRegister* ↵Kirstóf Umann1-1/+2
functions Some checkers may not only depend on language options but also analyzer options. To make this possible this patch changes the parameter of the shouldRegister* function to CheckerManager to be able to query the analyzer options when deciding whether the checker should be registered. Differential Revision: https://reviews.llvm.org/D75271
2019-09-11[analyzer] NFC: Move PathDiagnostic classes to libAnalysis.Artem Dergachev1-1/+1
At this point the PathDiagnostic, PathDiagnosticLocation, PathDiagnosticPiece structures no longer rely on anything specific to Static Analyzer, so we can move them out of it for everybody to use. PathDiagnosticConsumers are still to be handed off. Differential Revision: https://reviews.llvm.org/D67419 llvm-svn: 371661
2019-09-09[analyzer] NFC: Introduce sub-classes for path-sensitive and basic reports.Artem Dergachev1-7/+6
Checkers are now required to specify whether they're creating a path-sensitive report or a path-insensitive report by constructing an object of the respective type. This makes BugReporter more independent from the rest of the Static Analyzer because all Analyzer-specific code is now in sub-classes. Differential Revision: https://reviews.llvm.org/D66572 llvm-svn: 371450
2019-03-08[analyzer] Emit an error rather than assert on invalid checker option inputKristof Umann1-6/+2
Asserting on invalid input isn't very nice, hence the patch to emit an error instead. This is the first of many patches to overhaul the way we handle checker options. Differential Revision: https://reviews.llvm.org/D57850 llvm-svn: 355704
2019-01-26[analyzer] Supply all checkers with a shouldRegister functionKristof Umann1-0/+4
Introduce the boolean ento::shouldRegister##CHECKERNAME(const LangOptions &LO) function very similarly to ento::register##CHECKERNAME. This will force every checker to implement this function, but maybe it isn't that bad: I saw a lot of ObjC or C++ specific checkers that should probably not register themselves based on some LangOptions (mine too), but they do anyways. A big benefit of this is that all registry functions now register their checker, once it is called, registration is guaranteed. This patch is a part of a greater effort to reinvent checker registration, more info here: D54438#1315953 Differential Revision: https://reviews.llvm.org/D55424 llvm-svn: 352277
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2019-01-10[analyzer] Update the category name for RetainCountChecker reportsGeorge Karpenkov1-3/+3
..now that it includes OSObjects rdar://46509986 Differential Revision: https://reviews.llvm.org/D56404 llvm-svn: 350869
2018-12-15[analyzer][NFC] Move CheckerRegistry from the Core directory to FrontendKristof Umann1-1/+1
ClangCheckerRegistry is a very non-obvious, poorly documented, weird concept. It derives from CheckerRegistry, and is placed in lib/StaticAnalyzer/Frontend, whereas it's base is located in lib/StaticAnalyzer/Core. It was, from what I can imagine, used to circumvent the problem that the registry functions of the checkers are located in the clangStaticAnalyzerCheckers library, but that library depends on clangStaticAnalyzerCore. However, clangStaticAnalyzerFrontend depends on both of those libraries. One can make the observation however, that CheckerRegistry has no place in Core, it isn't used there at all! The only place where it is used is Frontend, which is where it ultimately belongs. This move implies that since include/clang/StaticAnalyzer/Checkers/ClangCheckers.h only contained a single function: class CheckerRegistry; void registerBuiltinCheckers(CheckerRegistry &registry); it had to re purposed, as CheckerRegistry is no longer available to clangStaticAnalyzerCheckers. It was renamed to BuiltinCheckerRegistration.h, which actually describes it a lot better -- it does not contain the registration functions for checkers, but only those generated by the tblgen files. Differential Revision: https://reviews.llvm.org/D54436 llvm-svn: 349275
2018-12-15[analyzer] ObjCDealloc: Fix a crash when a class attempts to deallocate a class.Artem Dergachev1-0/+4
The checker wasn't prepared to see the dealloc message sent to the class itself rather than to an instance, as if it was +dealloc. Additionally, it wasn't prepared for pure-unknown or undefined self values. The new guard covers that as well, but it is annoying to test because both kinds of values shouldn't really appear and we generally want to get rid of all of them (by modeling unknown values with symbols and by warning on use of undefined values before they are used). The CHECK: directive for FileCheck at the end of the test looks useless, so i removed it. Differential Revision: https://reviews.llvm.org/D55680 llvm-svn: 349228
2018-09-25[analyzer] NFC: Legalize state manager factory injection.Artem Dergachev1-9/+1
When a checker maintains a program state trait that isn't a simple list/set/map, but is a combination of multiple lists/sets/maps (eg., a multimap - which may be implemented as a map from something to set of something), ProgramStateManager only contains the factory for the trait itself. All auxiliary lists/sets/maps need a factory to be provided by the checker, which is annoying. So far two checkers wanted a multimap, and both decided to trick the ProgramStateManager into keeping the auxiliary factory within itself by pretending that it's some sort of trait they're interested in, but then never using this trait but only using the factory. Make this trick legal. Define a convenient macro. One thing that becomes apparent once all pieces are put together is that these two checkers are in fact using the same factory, because the type that identifies it, ImmutableMap<const MemRegion *, ImmutableSet<SymbolRef>>, is the same. This situation is different from two checkers registering similar primitive traits. Differential Revision: https://reviews.llvm.org/D51388 llvm-svn: 343035
2018-07-16[analyzer] Make checkEndFunction() give access to the return statement.Reka Kovacs1-2/+2
Differential Revision: https://reviews.llvm.org/D49387 llvm-svn: 337215
2018-01-26[NFC] fix trivial typos in comments and documentsHiroshi Inoue1-1/+1
"in in" -> "in", "on on" -> "on" etc. llvm-svn: 323509
2018-01-22[NFC] fix trivial typos in commentsHiroshi Inoue1-1/+1
"the the" -> "the" llvm-svn: 323078
2016-10-16Revert "[analyzer] Re-apply r283093 "Add extra notes to ObjCDeallocChecker""Devin Coughlin1-35/+3
Revert: r283662: [analyzer] Re-apply r283093 "Add extra notes to ObjCDeallocChecker" r283660: [analyzer] Fix build error after r283660 - remove constexpr strings. It was causing an internal build bot to fail. It looks like in some cases adding an extra note can cause scan-build plist output to drop a diagnostic altogether. llvm-svn: 284317
2016-10-12[analyzer] DeallocChecker: Don't warn about directly-set IBOutlet ivars on macOSDevin Coughlin1-0/+31
On macOS (but not iOS), if an ObjC property has no setter, the nib-loading code for an IBOutlet is documented as directly setting the backing ivar without retaining the value -- even if the property is 'retain'. This resulted in false positives from the DeallocChecker for code that did not release such ivars in -dealloc. To avoid these false positives, treat IBOutlet ivars that back a property without a setter as having an unknown release requirement in macOS. rdar://problem/28507353 llvm-svn: 284084
2016-10-08[analyzer] Fix build error after r283660 - remove constexpr strings.Artem Dergachev1-2/+8
llvm-svn: 283662
2016-10-08[analyzer] Re-apply r283093 "Add extra notes to ObjCDeallocChecker"Artem Dergachev1-3/+29
The parent commit (r283092) was reverted before and now finally landed. llvm-svn: 283660
2016-10-04Revert "[analyzer] Add extra notes to ObjCDeallocChecker" as its depends on ↵Vitaly Buka1-29/+3
reverted r283092 This reverts commit r283093. llvm-svn: 283181
2016-10-03[analyzer] Add extra notes to ObjCDeallocCheckerArtem Dergachev1-3/+29
The report is now highlighting instance variables and properties referenced by the warning message with the help of the extra notes feature recently introduced in r283092. Differential Revision: https://reviews.llvm.org/D24915 llvm-svn: 283093
2016-07-28[analyzer] Fix misleading indentation in ObjCDeallocChecker. NFC.Devin Coughlin1-1/+1
llvm-svn: 277009
2016-07-13[analyzer] Implement a methond to discover origin region of a symbol.Artem Dergachev1-9/+1
This encourages checkers to make logical decisions depending on value of which region was the symbol under consideration introduced to denote. A similar technique is already used in a couple of checkers; they were modified to call the new method. Differential Revision: http://reviews.llvm.org/D22242 llvm-svn: 275290
2016-06-22[analyzer] Teach ObjCDeallocChecker about XCTestCaseDevin Coughlin1-9/+11
Like with SenTestCase, subclasses of XCTestCase follow a "tear down" idiom to release instance variables and so typically do not release ivars in -dealloc. This commit applies the existing special casing for SenTestCase to XCTestCase as well. rdar://problem/25884696 llvm-svn: 273441
2016-03-25[analyzer] Add CIFIlter modeling to DeallocChecker.Devin Coughlin1-10/+56
The -dealloc method in CIFilter is highly unusual in that it will release instance variables belonging to its *subclasses* if the variable name starts with "input" or backs a property whose name starts with "input". Subclasses should not release these ivars in their own -dealloc method -- doing so could result in an over release. Before this commit, the DeallocChecker would warn about missing releases for such "input" properties -- which could cause users of the analyzer to add over releases to silence the warning. To avoid this, DeallocChecker now treats CIFilter "input-prefixed" ivars as MustNotReleaseDirectly and so will not require a release. Further, it will now warn when such an ivar is directly released in -dealloc. rdar://problem/25364901 llvm-svn: 264463
2016-03-04[analyzer] Add diagnostic in ObjCDeallocChecker for use of -dealloc instead ↵Devin Coughlin1-32/+92
of -release. In dealloc methods, the analyzer now warns when -dealloc is called directly on a synthesized retain/copy ivar instead of -release. This is intended to find mistakes of the form: - (void)dealloc { [_ivar dealloc]; // Mistaken call to -dealloc instead of -release [super dealloc]; } rdar://problem/16227989 llvm-svn: 262729
2016-03-03[analyzer] ObjCDeallocChecker: Only check for nil-out when type is retainable.Devin Coughlin1-1/+5
This fixes a crash when setting a property of struct type in -dealloc. llvm-svn: 262659
2016-03-01[analyzer] Update CheckObjCDealloc diagnostic for missing -dealloc.Devin Coughlin1-10/+18
Update the diagnostic for classes missing -dealloc to mention an instance variable that needs to be released. llvm-svn: 262277
2016-02-29[analyzer] Teach CheckObjCDealloc about Block_release().Devin Coughlin1-10/+38
It now treats Block_release(b) as a release in addition to [b release]. llvm-svn: 262272
2016-02-29[analyzer] Don't treat calls to system headers as escaping in CheckObjCDealloc.Devin Coughlin1-21/+96
This prevents false negatives when a -dealloc method, for example, removes itself as as an observer with [[NSNotificationCenter defaultCenter] removeObserver:self]. It is unlikely that passing 'self' to a system header method will release 'self''s instance variables, so this is unlikely to produce false positives. A challenge here is that while CheckObjCDealloc no longer treats these calls as escaping, the rest of the analyzer still does. In particular, this means that loads from the same instance variable before and after a call to a system header will result in different symbols being loaded by the region store. To account for this, the checker now treats different ivar symbols with the same instance and ivar decl as the same for the purpose of release checking and more eagerly removes a release requirement when an instance variable is assumed to be nil. This was not needed before because when an ivar escaped its release requirement was always removed -- now the requirement is not removed for calls to system headers. llvm-svn: 262261
2016-02-26[analyzer] Prune some incorrect \param doc comment annotations.Devin Coughlin1-12/+12
llvm-svn: 261970
2016-02-26Checkers/CheckObjCDealloc.cpp: Prune "\param". [-Wdocumentation]NAKAMURA Takumi1-1/+1
llvm-svn: 261963
2016-02-25[analyzer] Reapply r261917 with a fix.Devin Coughlin1-175/+752
This reapplies "[analyzer] Make ObjCDeallocChecker path sensitive." (r261917) with a fix for an error on some bots about specializing a template from another namespace. llvm-svn: 261929
2016-02-25Revert "[analyzer] Make ObjCDeallocChecker path sensitive."Devin Coughlin1-748/+175
This reverts commit r261917. It broke the bots. llvm-svn: 261921
2016-02-25[analyzer] Make ObjCDeallocChecker path sensitive.Devin Coughlin1-175/+748
Convert the ObjCDeallocChecker to be path sensitive. The primary motivation for this change is to prevent false positives when -dealloc calls helper invalidation methods to release instance variables, but it additionally improves precision when -dealloc contains control flow. It also reduces the need for pattern matching. The check for missing -dealloc methods remains AST-based. Part of rdar://problem/6927496 Differential Revision: http://reviews.llvm.org/D17511 llvm-svn: 261917
2016-02-11[analyzer] Improve pattern matching in ObjCDealloc checker.Devin Coughlin1-8/+17
Look through PseudoObjectExpr and OpaqueValueExprs when scanning for release-like operations. This commit also adds additional tests in anticipation of re-writing this as a path-sensitive checker. llvm-svn: 260608
2016-02-06[analyzer] DeallocChecker: Don't warn on release of readonly assign property ↵Devin Coughlin1-0/+6
in dealloc. It is common for the ivars for read-only assign properties to always be stored retained, so don't warn for a release in dealloc for the ivar backing these properties. llvm-svn: 259998
2016-01-27[analyzer] ObjCDeallocChecker: Only operate on classes with retained properties.Devin Coughlin1-50/+64
Previously the ObjC Dealloc Checker only checked classes with ivars, not retained properties, which caused three bugs: - False positive warnings about a missing -dealloc method in classes with only ivars. - Missing warnings about a missing -dealloc method on classes with only properties. - Missing warnings about an over-released or under-released ivar associated with a retained property in classes with only properties. The fix is to check only classes with at least one retained synthesized property. This also exposed a bug when reporting an over-released or under-released property that did not contain a synthesize statement. The checker tried to associate the warning with an @synthesize statement that did not exist, which caused an assertion failure in debug builds. The fix is to fall back to the @property statement in this case. A patch by David Kilzer! Part of rdar://problem/6927496 Differential Revision: http://reviews.llvm.org/D5023 llvm-svn: 258896
2015-09-08[analyzer] Apply whitespace cleanups by Honggyu Kim.Ted Kremenek1-2/+2
llvm-svn: 246978
2015-07-03Rewrite users of Stmt::child_begin/end into for-range loops.Benjamin Kramer1-2/+2
No functionality change intended. llvm-svn: 241355