Commit Graph

311 Commits

Author SHA1 Message Date
John McCall 4db5c3c83a In ARC, reclaim all return values of retainable type, not just those
where we have an immediate need of a retained value.

As an exception, don't do this when the call is made as the immediate
operand of a __bridge retain.  This is more in the way of a workaround
than an actual guarantee, so it's acceptable to be brittle here.

rdar://problem/9504800

llvm-svn: 134605
2011-07-07 06:58:02 +00:00
Douglas Gregor 5c70b06feb Teach the static analyzer's interpretation of Cocoa conventions to
obey the objc_method_family attribute when provided. Fixes
<rdar://problem/9726279>.

llvm-svn: 134493
2011-07-06 16:00:34 +00:00
Eric Christopher bf15d2b311 Update for llvm commit r134291.
Fixes rdar://9714064

llvm-svn: 134292
2011-07-02 00:20:22 +00:00
Jordy Rose 4d3c1511ac [analyzer] Use UnknownVal when default-initializing arrays whose element types we don't model, to distinguish them from uninitialized arrays (PR10163).
llvm-svn: 133937
2011-06-27 20:36:38 +00:00
Douglas Gregor fe31481f68 Introduce a new AST node describing reference binding to temporaries.
MaterializeTemporaryExpr captures a reference binding to a temporary
value, making explicit that the temporary value (a prvalue) needs to
be materialized into memory so that its address can be used. The
intended AST invariant here is that a reference will always bind to a
glvalue, and MaterializeTemporaryExpr will be used to convert prvalues
into glvalues for that binding to happen. For example, given

  const int& r = 1.0;

The initializer of "r" will be a MaterializeTemporaryExpr whose
subexpression is an implicit conversion from the double literal "1.0"
to an integer value. 

IR generation benefits most from this new node, since it was
previously guessing (badly) when to materialize temporaries for the
purposes of reference binding. There are likely more refactoring and
cleanups we could perform there, but the introduction of
MaterializeTemporaryExpr fixes PR9565, a case where IR generation
would effectively bind a const reference directly to a bitfield in a
struct. Addresses <rdar://problem/9552231>.

llvm-svn: 133521
2011-06-21 17:03:29 +00:00
Jordy Rose b41f7c55f5 [analyzer] Finish size argument checking for strncat (and strncpy).
llvm-svn: 133472
2011-06-20 21:55:40 +00:00
Jordy Rose 789adbb3ed [analyzer] Replace stream-built error message with constant string. No functionality change.
llvm-svn: 133410
2011-06-20 03:51:53 +00:00
Jordy Rose 328deeed7f [analyzer] Re-enable checking for strncpy, along with a new validation of the size argument. strncat is not yet up-to-date, but I'm leaving it enabled for now (there shouldn't be any false positives, at least...)
llvm-svn: 133408
2011-06-20 03:49:16 +00:00
Jordy Rose dceb0cf3f3 [analyzer] Eliminate "byte string function" from CStringChecker's diagnostics, and make it easier to provide custom messages for overflow checking, in preparation for re-enabling strncpy checking.
llvm-svn: 133406
2011-06-20 02:06:40 +00:00
John McCall 640767fff6 Initialize a couple of variables to shut GCC up.
llvm-svn: 133246
2011-06-17 06:50:50 +00:00
Jordy Rose c026370858 [analyzer] Clean up modeling of strcmp, including cases where a string literal has an embedded null character, and where both arguments are the same buffer. Also use nested ifs rather than early returns; in this case early returns will lose any assumptions we've made earlier in the function.
llvm-svn: 133154
2011-06-16 07:13:34 +00:00
Jordy Rose 0585a61821 [analyzer] Fix trivial errors in previous commit.
I will not commit without building first.
I will not commit without building first.
I will not commit without building first...

llvm-svn: 133150
2011-06-16 05:56:50 +00:00
Jordy Rose 455bd58d4e [analyzer] Cleanup: mainly 80-char violations and preferring SValBuilder::getComparisonType() to just referencing IntTy.
llvm-svn: 133149
2011-06-16 05:51:02 +00:00
John McCall 31168b077c Automatic Reference Counting.
Language-design credit goes to a lot of people, but I particularly want
to single out Blaine Garst and Patrick Beard for their contributions.

Compiler implementation credit goes to Argyrios, Doug, Fariborz, and myself,
in no particular order.

llvm-svn: 133103
2011-06-15 23:02:42 +00:00
Jordy Rose 634c12d23f [analyzer] Revise CStringChecker's modelling of strcpy() and strcat():
- (bounded copies) Be more conservative about how much is being copied.
- (str(n)cat) If we can't compute the exact final length of an append operation, we can still lower-bound it.
- (stpcpy) Fix the conjured return value at the end to actually be returned.

This requires these supporting changes:
- C string metadata symbols are still live even when buried in a SymExpr.
- "Hypothetical" C string lengths, to represent a value that /will/ be passed to setCStringLength() if all goes well. (The idea is to allow for temporary constrainable symbols that may end up becoming permanent.)
- The 'checkAdditionOverflow' helper makes sure that the two strings being appended in a strcat don't overflow size_t. This should never *actually* happen; the real effect is to keep the final string length from "wrapping around" in the constraint manager.

This doesn't actually test the "bounded" operations (strncpy and strncat) because they can leave strings unterminated. Next on the list!

llvm-svn: 133046
2011-06-15 05:52:56 +00:00
Jordy Rose 0e9fb28e95 [analyzer] If a C string length is UnknownVal, clear any existing length binding. No tests yet because the only thing that sets string length is strcpy(), and that needs some work anyway.
llvm-svn: 133044
2011-06-15 05:14:03 +00:00
Jordy Rose b891bd8a3c [analyzer] When performing a binary operation on symbolic operands, we convert the symbol values to a common type. But in a relational operation, the result is an 'int' or 'bool', which may not be the appropriate type to convert the operands to. In these cases, use the left-hand operand's type as the conversion type.
There's no associated test for this because fully-constrained symbolic values are evaluated ahead of time in normal expressions. This can only come up in checker-constructed expressions (like the ones in an upcoming patch to CStringChecker).

llvm-svn: 133041
2011-06-15 04:55:49 +00:00
Jordy Rose bc7483f505 [analyzer] CStringChecker checks functions in the C standard library, not C++. Its external name is now unix.experimental.CString.
llvm-svn: 132958
2011-06-14 01:40:43 +00:00
Jordy Rose 45d8c12b68 [analyzer] Change large if body to early return. No functionality change.
llvm-svn: 132956
2011-06-14 01:26:48 +00:00
Jordy Rose d359289669 [analyzer] Fix modeling of strnlen to be more conservative. Move tests we can't properly model (yet?) to string-fail.c.
llvm-svn: 132955
2011-06-14 01:15:31 +00:00
Jordy Rose 1734737d9f [analyzer] PR8962 again. Ban ParenExprs (and friends) from block-level expressions (by calling IgnoreParens before adding expressions to blocks). Undo 132769 (LiveVariables' local IgnoreParens), since it's no longer necessary.
Also, have Environment stop looking through NoOp casts; it didn't match the behavior of LiveVariables. And once that's gone, the whole cast block of that switch is unnecessary.

llvm-svn: 132840
2011-06-10 08:49:37 +00:00
Jordy Rose ab8a668849 [analyzer] Look through __extension__ expressions in a GRState's Environment. Fixes PR8962.
llvm-svn: 132762
2011-06-08 22:47:39 +00:00
Jordy Rose fb5e8c2814 [analyzer] Change an indent-if to an early return. No functionality change.
llvm-svn: 132618
2011-06-04 01:50:25 +00:00
Jordy Rose 097c5397a8 [analyzer] Don't crash when copying an unknown number of bytes with memcpy(). Also handle all memcpy-family return values in evalCopyCommon(), rather than having some outside and some inside.
llvm-svn: 132617
2011-06-04 01:47:27 +00:00
Jordy Rose 64ae92e5c5 [analyzer] Remove extra assignment that actually lost a few of the assumptions.
llvm-svn: 132614
2011-06-04 01:22:21 +00:00
Tanya Lattner 55808c1026 Add support for builtin astype:
__builtin_astype(): Used to reinterpreted as another data type of the same size using for both scalar and vector data types.
Added test case.

llvm-svn: 132612
2011-06-04 00:47:47 +00:00
Jordy Rose 4451cd4511 [analyzer] Fix comment for (still-disabled) evalStrncpy
llvm-svn: 132608
2011-06-04 00:05:23 +00:00
Jordy Rose 63b84be6cb [analyzer] Fix handling of "copy zero bytes" for memcpy and friends.
llvm-svn: 132607
2011-06-04 00:04:22 +00:00
Jordy Rose aee7fb9e64 [analyzer] __mempcpy_chk is the same as mempcpy (at least to CStringChecker)
llvm-svn: 132605
2011-06-03 23:42:56 +00:00
Ted Kremenek f230198f15 Tighen analyzer diagnostics w.r.t ObjC/CF leaks.
llvm-svn: 132130
2011-05-26 18:45:44 +00:00
Ted Kremenek 4c5d2888f4 static analyzer: when conservatively evaluating functions, don't invalidate the values of globals when the called function is strlen.
llvm-svn: 132100
2011-05-25 23:57:29 +00:00
Ted Kremenek 86d49ce20c Teach analyzer about cf_returns_not_retained for C functions.
llvm-svn: 132049
2011-05-25 06:29:39 +00:00
Ted Kremenek 8e2c9b0180 Enhance retain/release checker to flag warnings when functions returning CG types do not follow the Core Foundation naming conventions.
llvm-svn: 132048
2011-05-25 06:19:45 +00:00
Douglas Gregor 61b6e49ee1 A few more is(Un)signedIntegerType/is(Un)signedOrEnumerationType cleanups.
llvm-svn: 131793
2011-05-21 16:28:01 +00:00
Ted Kremenek 109b127e02 Fix regression in static analyzer's handling of prefix '--' operator. It was being treated as postfix '--' in C mode.
llvm-svn: 131770
2011-05-20 23:40:06 +00:00
Douglas Gregor 6ab2fa8f78 Introduce Type::isSignedIntegerOrEnumerationType() and
Type::isUnsignedIntegerOrEnumerationType(), which are like
Type::isSignedIntegerType() and Type::isUnsignedIntegerType() but also
consider the underlying type of a C++0x scoped enumeration type.

Audited all callers to the existing functions, switching those that
need to also handle scoped enumeration types (e.g., those that deal
with constant values) over to the new functions. Fixes PR9923 /
<rdar://problem/9447851>.

llvm-svn: 131735
2011-05-20 16:38:50 +00:00
Ted Kremenek f377cb82f9 Teach RegionStore not to symbolic array values whose indices it cannot reason about.
llvm-svn: 131702
2011-05-19 23:37:58 +00:00
Ted Kremenek 5f06955aa0 Teach static analyzer to analyze Objective-C methods in category implementations.
llvm-svn: 131614
2011-05-19 00:56:53 +00:00
Alexis Hunt 4a8ea1092a Modify some deleted function methods to better reflect reality:
- New isDefined() function checks for deletedness
 - isThisDeclarationADefinition checks for deletedness
 - New doesThisDeclarationHaveABody() does what
   isThisDeclarationADefinition() used to do
 - The IsDeleted bit is not propagated across redeclarations
 - isDeleted() now checks the canoncial declaration
 - New isDeletedAsWritten() does what it says on the tin.
 - isUserProvided() now correct (thanks Richard!)

This fixes the bug that we weren't catching

void foo() = delete;
void foo() {}

as being a redefinition.

llvm-svn: 131013
2011-05-06 20:44:56 +00:00
Ted Kremenek e69ab05f6e Add Checker callback for running a checker at the end of processing an entire TranslationUnit. Patch by Lei Zhang.
llvm-svn: 130913
2011-05-05 03:41:17 +00:00
Lenny Maiorani 5066858bcd Removing strncpy() checking in CString checker for now. Some significant changes need to be made to properly support modeling of it since it potentially leaves strings non-null terminated.
llvm-svn: 130758
2011-05-03 16:34:26 +00:00
Ted Kremenek e9f364f658 Tweak the retain/release checker to not stop tracking retained objects when calling C++ methods. This is a temporary solution to prune false positives until we have a general story using annotations.
llvm-svn: 130726
2011-05-02 21:21:42 +00:00
Ted Kremenek aa181174e7 Augment retain/release checker to not warn about tracked objects passed as arguments to C++ constructors. This is a stop-gap measure for Objective-C++ code that uses smart pointers to manage reference counts.
llvm-svn: 130711
2011-05-02 19:42:42 +00:00
Lenny Maiorani 0b510279c6 Implements strncasecmp() checker and simplifies some of the logic around creating substrings if necessary and calling the appropriate StringRef::compare/compare_lower().
llvm-svn: 130708
2011-05-02 19:05:49 +00:00
Ted Kremenek 8067746554 Move the SelfInit checker to the 'cocoa.experimental' package.
llvm-svn: 130598
2011-04-30 06:46:45 +00:00
Lenny Maiorani 18470e3287 Use StringRef::substr() and unbounded StringRef::compare() instead of bounded version of StringRef::compare() because bounded version of StringRef::compare() is going to be removed.
llvm-svn: 130425
2011-04-28 19:31:12 +00:00
Lenny Maiorani ed2cc6ccbb Eliminates an assert in the strncpy/strncat checker caused by not validating a cast was successful. If the value of an argument was unknown, the cast would result in a NULL pointer which was later being dereferenced.
This fixes Bugzilla #9806.

llvm-svn: 130422
2011-04-28 18:59:43 +00:00
Lenny Maiorani 4af23c8159 Implements strcasecmp() checker in Static Analyzer.
llvm-svn: 130398
2011-04-28 15:09:11 +00:00
John Wiegley 1c0675e155 Parsing/AST support for Structured Exception Handling
Patch authored by Sohail Somani.

Provide parsing and AST support for Windows structured exception handling.

llvm-svn: 130366
2011-04-28 01:08:34 +00:00
John Wiegley 6242b6a688 Implementation of Embarcadero array type traits
Patch authored by John Wiegley.

These are array type traits used for parsing code that employs certain
features of the Embarcadero C++ compiler: __array_rank(T) and
__array_extent(T, Dim).

llvm-svn: 130351
2011-04-28 00:16:57 +00:00