aboutsummaryrefslogtreecommitdiff
path: root/lib/StaticAnalyzer/Checkers
AgeCommit message (Collapse)Author
2013-03-26[analyzer] Make sure IDC works for ‘NSContainer value/key is nil’ checks.Anna Zaks
Register the nil tracking visitors with the region and refactor trackNullOrUndefValue a bit. Also adds the cast and paren stripping before checking if the value is an OpaqueValueExpr or ExprWithCleanups. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178093 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-25[analyzer] Adds cplusplus.NewDelete checker that check for memory leaks, ↵Anton Yartsev
double free, and use-after-free problems of memory managed by new/delete. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177849 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-23[analyzer] Warn when a nil key or value are passed to NSMutableDictionary ↵Anna Zaks
and ensure it works with subscripting. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177789 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-21[analyzer] Print return values from debug.DumpCalls checker.Jordan Rose
Debug utility only, no functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177649 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-18[analyzer] Warn when a ‘nil’ object is added to NSArray or NSMutableArray.Anna Zaks
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177318 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-15[analyzer] Address a TODO in the StreamChecker; otherwise the output is ↵Anna Zaks
non-deterministic. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177207 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-13[analyzer] fixed the logic changed by r176949Anton Yartsev
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176956 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-13Refactoring:Anton Yartsev
+ Individual Report* method for each bug type + Comment improved: missing non-trivial alloca() case annotated + 'range' parameter of ReportBadFree() capitalized + 'SymbolRef Sym = State->getSVal(A, C.getLocationContext()).getAsSymbol();' shorten to 'SymbolRef Sym = C.getSVal(A).getAsSymbol();' git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176949 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-09[analyzer] Rename AttrNonNullChecker -> NonNullParamCheckerAnna Zaks
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176755 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-09[analyzer] Be more consistent about Objective-C methods that free memory.Jordan Rose
Previously, MallocChecker's pointer escape check and its post-call state update for Objective-C method calls had a fair amount duplicated logic and not-entirely-consistent checks. This commit restructures all this to be more consistent and possibly allow us to be more aggressive in warning about double-frees. New policy (applies to system header methods only): (1) If this is a method we know about, model it as taking/holding ownership of the passed-in buffer. (1a) ...unless there's a "freeWhenDone:" parameter with a zero (NO) value. (2) If there's a "freeWhenDone:" parameter (but it's not a method we know about), treat the buffer as escaping if the value is non-zero (YES) and non-escaping if it's zero (NO). (3) If the first selector piece ends with "NoCopy" (but it's not a method we know about and there's no "freeWhenDone:" parameter), treat the buffer as escaping. The reason that (2) and (3) don't explicitly model the ownership transfer is because we can't be sure that they will actually free the memory using free(), and we wouldn't want to emit a spurious "mismatched allocator" warning (coming in Anton's upcoming patch). In the future, we may have an idea of a "generic deallocation", i.e. we assume that the deallocator is correct but still continue tracking the region so that we can warn about double-frees. Patch by Anton Yartsev, with modifications from me. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176744 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-07[analyzer] Warn on passing a reference to null pointer as an argument in a callAnna Zaks
Warn about null pointer dereference earlier when a reference to a null pointer is passed in a call. The idea is that even though the standard might allow this, reporting the issue earlier is better for diagnostics (the error is reported closer to the place where the pointer was set to NULL). This also simplifies analyzer’s diagnostic logic, which has to track “where the null came from”. As a consequence, some of our null pointer warning suppression mechanisms started triggering more often. TODO: Change the name of the file and class to reflect the new check. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176612 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-07[analyzer] Check for returning null references in ReturnUndefChecker.Jordan Rose
Officially in the C++ standard, a null reference cannot exist. However, it's still very easy to create one: int &getNullRef() { int *p = 0; return *p; } We already check that binds to reference regions don't create null references. This patch checks that we don't create null references by returning, either. <rdar://problem/13364378> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176601 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-06[analyzer] Pass the correct Expr to the bug reporter visitors when dealing ↵Anna Zaks
with CompoundLiteralExpr This allows us to trigger the IDC visitor in the added test case. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176577 91177308-0d34-0410-b5e6-96231b3b80d8
2013-03-04[analyzer] Don't let cf_audited_transfer override CFRetain semantics.Jordan Rose
We weren't treating a cf_audited_transfer CFRetain as returning +1 because its name doesn't contain "Create" or "Copy". Oops! Fortunately, the standard definitions of these functions are not marked audited. <rdar://problem/13339601> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176463 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-26[analyzer] StackAddrEscapeChecker: strip qualifiers from temporary types.Jordan Rose
With the new support for trivial copy constructors, we are not always consistent about whether a CXXTempObjectRegion gets reused or created from scratch, which affects whether qualifiers are preserved. However, we probably don't care anyway. This also switches to using the current PrintingPolicy for the type, which means C++ types don't get a spurious 'struct' prefix anymore. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176068 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-25[analyzer] Restrict ObjC type inference to methods that have related result ↵Anna Zaks
type. This addresses a case when we inline a wrong method due to incorrect dynamic type inference. Specifically, when user code contains a method from init family, which creates an instance of another class. Use hasRelatedResultType() to find out if our inference rules should be triggered. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176054 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-24[analyzer] tracking stores/constraints now works for ObjC ivars or struct ↵Ted Kremenek
fields. This required more changes than I originally expected: - ObjCIvarRegion implements "canPrintPretty" et al - DereferenceChecker indicates the null pointer source is an ivar - bugreporter::trackNullOrUndefValue() uses an alternate algorithm to compute the location region to track by scouring the ExplodedGraph. This allows us to get the actual MemRegion for variables, ivars, fields, etc. We only hand construct a VarRegion for C++ references. - ExplodedGraph no longer drops nodes for expressions that are marked 'lvalue'. This is to facilitate the logic in the previous bullet. This may lead to a slight increase in size in the ExplodedGraph, which I have not measured, but it is likely not to be a big deal. I have validated each of the changed plist output. Fixes <rdar://problem/12114812> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175988 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-24Add "KnownSVal" to represent SVals that cannot be UnknownSVal.Ted Kremenek
This provides a few sundry cleanups, and allows us to provide a compile-time check for a case that was a runtime assertion. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175987 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-23Remove the CFGElement "Invalid" state.David Blaikie
Use Optional<CFG*> where invalid states were needed previously. In the one case where that's not possible (beginAutomaticObjDtorsInsert) just use a dummy CFGAutomaticObjDtor. Thanks for the help from Jordan Rose & discussion/feedback from Ted Kremenek and Doug Gregor. Post commit code review feedback on r175796 by Ted Kremenek. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175938 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-21Add back implicitly dropped const.David Blaikie
(found due to incoming improvements to llvm::cast machinery that will error on this sort of mistake) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175817 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-21Replace ProgramPoint llvm::cast support to be well-defined.David Blaikie
See r175462 for another example/more details. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175812 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-21Replace CFGElement llvm::cast support to be well-defined.David Blaikie
See r175462 for another example/more details. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175796 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-21Avoid implicit conversions of Optional<T> to bool.David Blaikie
This is a precursor to making Optional<T>'s operator bool 'explicit' when building Clang & LLVM as C++11. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175722 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-21Use None rather than Optional<T>() where possible.David Blaikie
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175705 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-20Include llvm::Optional in clang/Basic/LLVM.hDavid Blaikie
Post-commit CR feedback from Jordan Rose regarding r175594. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175679 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-20Remove redundant Optional type in favor of llvm::OptionalDavid Blaikie
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175678 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-20Replace SVal llvm::cast support to be well-defined.David Blaikie
See r175462 for another example/more details. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175594 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-18Disable dead stores checker for template instantations. Fixes ↵Ted Kremenek
<rdar://problem/13213575>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175425 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-14objective-C: synthesize properties in order of theirFariborz Jahanian
declarations to synthesize their ivars in similar determinstic order so they are laid out in a determinstic order. // rdar://13192366 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175214 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-09Remove some stray uses of <ctype.h> functions.Jordan Rose
These are causing assertions on some MSVC builds. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174805 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-09[analyzer] Invalidation checker: move the "missing implementation" checkAnna Zaks
The missing definition check should be in the same category as the missing ivar validation - in this case, the intent is to invalidate in the given class, as described in the declaration, but the implementation does not perform the invalidation. Whereas the MissingInvalidationMethod checker checks the cases where the method intention is not to invalidate. The second checker has potential to have a much higher false positive rate. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174787 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-08[analyzer] Move DefaultBool so that all checkers can share it.Anna Zaks
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174782 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-08[analyzer] Split IvarInvalidation into two checkersAnna Zaks
Separate the checking for the missing invalidation methods into a separate checker so that it can be turned on/off independently. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174781 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-08[analyzer] IvarInvalidation: refactor, pull out the diagnostic printingAnna Zaks
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174780 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-08[analyzer] IvarInvalidation: add annotation for partial invalidationAnna Zaks
The new annotation allows having methods that only partially invalidate IVars and might not be called from the invalidation methods directly (instead, are guaranteed to be called before the invalidation occurs). The checker is going to trust the programmer to call the partial invalidation method before the invalidator.This is common in cases when partial object tear down happens before the death of the object. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174779 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-07[analyzer] Report bugs when freeing memory with offset pointerAnna Zaks
The malloc checker will now catch the case when a previously malloc'ed region is freed, but the pointer passed to free does not point to the start of the allocated memory. For example: int *p1 = malloc(sizeof(int)); p1++; free(p1); // warn From the "memory.LeakPtrValChanged enhancement to unix.Malloc" entry in the list of potential checkers. A patch by Branden Archer! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174678 91177308-0d34-0410-b5e6-96231b3b80d8
2013-02-07[analyzer] Add pointer escape type param to checkPointerEscape callbackAnna Zaks
The checkPointerEscape callback previously did not specify how a pointer escaped. This change includes an enum which describes the different ways a pointer may escape. This enum is passed to the checkPointerEscape callback when a pointer escapes. If the escape is due to a function call, the call is passed. This changes previous behavior where the call is passed as NULL if the escape was due to indirectly invalidating the region the pointer referenced. A patch by Branden Archer! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174677 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-31[analyzer]RetainCount: Fix an autorelease related false positive.Anna Zaks
The Cnt variable is adjusted (incremented) for simplification of checking logic. The increment should not be stored in the state. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174104 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-31[analyzer] Don't track autorelease pools created by +new.Jordan Rose
This matches our behavior for autorelease pools created by +alloc. Some people like to create autorelease pools in one method and release them somewhere else. If you want safe autorelease pool semantics, use the new ARC-compatible syntax: @autoreleasepool { ... } <rdar://problem/13121353> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174096 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-26[analyzer] Track null object lvalues back through C++ method calls.Jordan Rose
The expression 'a->b.c()' contains a call to the 'c' method of 'a->b'. We emit an error if 'a' is NULL, but previously didn't actually track the null value back through the 'a->b' expression, which caused us to miss important false-positive-suppression cases, including <rdar://problem/12676053>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173547 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-26[analyzer] bugreporter::getDerefExpr now takes a Stmt, not an ExplodedNode.Jordan Rose
This allows it to be used in places where the interesting statement doesn't match up with the current node. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173546 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-23Add missing null check. Not sure why my tests passed before.Ted Kremenek
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173292 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-23Honor attribute 'analyzer_noreturn' on Objective-C methods.Ted Kremenek
This isn't likely a full solution, but it catches the common cases and can be refined over time. Fixes <rdar://problem/11634353>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173291 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-17[analyzer] DirectIvarAssignment: allow suppression annotation on Ivars.Anna Zaks
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172766 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-17Implement C++11 semantics for [[noreturn]] attribute. This required splittingRichard Smith
it apart from [[gnu::noreturn]] / __attribute__((noreturn)), since their semantics are not equivalent (for instance, we treat [[gnu::noreturn]] as affecting the function type, whereas [[noreturn]] does not). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172691 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-16Rework the traversal of Objective-C categories and extensions toDouglas Gregor
consider (sub)module visibility. The bulk of this change replaces myriad hand-rolled loops over the linked list of Objective-C categories/extensions attached to an interface declaration with loops using one of the four new category iterator kinds: visible_categories_iterator: Iterates over all visible categories and extensions, hiding any that have their "hidden" bit set. This is by far the most commonly used iterator. known_categories_iterator: Iterates over all categories and extensions, ignoring the "hidden" bit. This tends to be used for redeclaration-like traversals. visible_extensions_iterator: Iterates over all visible extensions, hiding any that have their "hidden" bit set. known_extensions_iterator: Iterates over all extensions, whether they are visible to normal name lookup or not. The effect of this change is that any uses of the visible_ iterators will respect module-import visibility. See the new tests for examples. Note that the old accessors for categories and extensions are gone; there are *Raw() forms for some of them, for those (few) areas of the compiler that have to manipulate the linked list of categories directly. This is generally discouraged. Part two of <rdar://problem/10634711>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172665 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-16[analyzer] Add an annotation to allow suppression of direct ivarAnna Zaks
assignment git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172597 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-16[analyzer] Fix warning typo.Anna Zaks
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172596 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-16[analyzer] Refactor: parameter rename.Anna Zaks
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172595 91177308-0d34-0410-b5e6-96231b3b80d8
2013-01-14[analyzer] -drain is not an alias for -release.Jordan Rose
This was previously added to support -[NSAutoreleasePool drain], which behaves like -release under non-GC and "please collect" under GC. We're not currently modeling the autorelease pool stack, though, so we can just take this out entirely. Fixes PR14927. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172444 91177308-0d34-0410-b5e6-96231b3b80d8