Commit Graph

2328 Commits

Author SHA1 Message Date
Jordan Rose 000bac5e17 [analyzer] RetainCountChecker: don't try to track ivars known to be nil.
We expect in general that any nil value has no retain count information
associated with it; violating this results in unexpected state unification
/later/ when we decide to throw the information away. Unexpectedly caching
out can lead to an assertion failure or crash.

rdar://problem/19862648

llvm-svn: 229934
2015-02-19 23:57:04 +00:00
Anton Yartsev 5b5c7cec08 [analyzer] Different handling of alloca().
+ separate bug report for "Free alloca()" error to be able to customize checkers responsible for this error.
+ Muted "Free alloca()" error for NewDelete checker that is not responsible for c-allocated memory, turned on for unix.MismatchedDeallocator checker.
+ RefState for alloca() - to be able to detect usage of zero-allocated memory by upcoming ZeroAllocDereference checker.
+ AF_Alloca family to handle alloca() consistently - keep proper family in RefState, handle 'alloca' by getCheckIfTracked() facility, etc.
+ extra tests.

llvm-svn: 229850
2015-02-19 13:36:20 +00:00
Anton Yartsev e5c0c14213 [analyzer] Refactoring: clarified the way the proper check kind is chosen.
llvm-svn: 229593
2015-02-18 00:39:06 +00:00
Benjamin Kramer f989042f18 Prefer SmallVector::append/insert over push_back loops. Clang edition.
Same functionality, but hoists the vector growth out of the loop.

llvm-svn: 229508
2015-02-17 16:48:30 +00:00
Benjamin Kramer 07a7ff3bce Analyzer: Replace a set of particularly ugly faux variadics.
llvm-svn: 229325
2015-02-15 20:11:07 +00:00
Anton Yartsev b3fa86d6f3 [analyzer] Pass actual state to alloc/dealloc handling functions.
The state obtained from CheckerContext::getState() may be outdated by the time the alloc/dealloc handling function is called (e.g. the state was modified but the transition was not performed). State argument was added to all alloc/dealloc handling functions in order to get the latest state and to allow sequential calls to those functions.

llvm-svn: 228737
2015-02-10 20:13:08 +00:00
Gabor Horvath c18a11397c [Static Analyzer] The name of the checker that reports a bug is added
to the plist output. This check_name field does not guaranteed to be the
same as the name of the checker in the future.

Reviewer: Anna Zaks

Differential Revision: http://reviews.llvm.org/D6841

llvm-svn: 228624
2015-02-09 22:52:26 +00:00
Benjamin Kramer b4ef66832d Update APIs that return a pair of iterators to return an iterator_range instead.
Convert uses of those APIs into ranged for loops. NFC.

llvm-svn: 228404
2015-02-06 17:25:10 +00:00
Anna Zaks f4c7ce8a37 [analyzer] Relax an assertion in VisitLvalArraySubscriptExpr
The analyzer thinks that ArraySubscriptExpr cannot be an r-value (ever).
However, it can be in some corner cases. Specifically, C forbids expressions
of unqualified void type from being l-values.

Note, the analyzer will keep modeling the subscript expr as an l-value. The
analyzer should be treating void* as a char array
(https://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Pointer-Arith.html).

llvm-svn: 228249
2015-02-05 01:02:59 +00:00
Anna Zaks 33f0632640 [analyzer] Do not crash in the KeychainAPI checker on user defined 'free()'.
llvm-svn: 228248
2015-02-05 01:02:56 +00:00
Anna Zaks 486a0ff4b7 [analyzer] Look for allocation site in the parent frames as well as the current one.
Instead of handling edge cases (mostly involving blocks), where we have difficulty finding
an allocation statement, allow the allocation site to be in a parent node.

Previously we assumed that the allocation site can always be found in the same frame
as allocation, but there are scenarios in which an element is leaked in a child
frame but is allocated in the parent.

llvm-svn: 228247
2015-02-05 01:02:53 +00:00
Anna Zaks 7b6da65990 [analyzer] Don't skip analyzing the functions in preprocessed files.
The change in main file detection ended up disabling the path-sensitive
analysis of functions within preprocessed files.

llvm-svn: 228246
2015-02-05 01:02:47 +00:00
Jordan Rose cb5386cbfc [analyzer] RetainCountChecker: be forgiving when ivars are accessed directly.
A refinement of r204730, itself a refinement of r198953, to better handle
cases where an object is accessed both through a property getter and
through direct ivar access. An object accessed through a property should
always be treated as +0, i.e. not owned by the caller. However, an object
accessed through an ivar may be at +0 or at +1, depending on whether the
ivar is a strong reference. Outside of ARC, we don't always have that
information.

The previous attempt would clear out the +0 provided by a getter, but only
if that +0 hadn't already participated in other retain counting operations.
(That is, "self.foo" is okay, but "[[self.foo retain] autorelease]" is
problematic.) This turned out to not be good enough when our synthesized
getters get involved.

This commit drops the notion of "overridable" reference counting and instead
just tracks whether a value ever came from a (strong) ivar. If it has, we
allow one more release than we otherwise would. This has the added benefit
of being able to catch /some/ overreleases of instance variables, though
it's not likely to come up in practice.

We do still get some false negatives because we currently throw away
refcount state upon assigning a value into an ivar. We should probably
improve on that in the future, especially once we synthesize setters as
well as getters.

rdar://problem/18075108

llvm-svn: 228174
2015-02-04 19:24:52 +00:00
Richard Smith fee9e20b90 Fix layering violation: include/clang/Basic/PlistSupport.h should not include
files from include/clang/Lex. Clean up module map.

llvm-svn: 227361
2015-01-28 20:14:54 +00:00
Pavel Labath bb917683b6 Test commit, no changes.
llvm-svn: 226552
2015-01-20 09:47:57 +00:00
Richard Trieu d4b05cef6b Remove std::move that was preventing return value optimization.
llvm-svn: 226357
2015-01-17 00:46:55 +00:00
Chandler Carruth 0d9593ddec [cleanup] Re-sort *all* #include lines with llvm/utils/sort_includes.py
Sorry for the noise, I managed to miss a bunch of recent regressions of
include orderings here. This should actually sort all the includes for
Clang. Again, no functionality changed, this is just a mechanical
cleanup that I try to run periodically to keep the #include lines as
regular as possible across the project.

llvm-svn: 225979
2015-01-14 11:29:14 +00:00
Reid Kleckner ee7cf84c8f Use nullptr to silence -Wsentinel when self-hosting on Windows
Richard rejected my Sema change to interpret an integer literal zero in
a varargs context as a null pointer, so -Wsentinel sees an integer
literal zero and fires off a warning. Only CodeGen currently knows that
it promotes integer literal zeroes in this context to pointer size on
Windows.  I didn't want to teach -Wsentinel about that compatibility
hack. Therefore, I'm migrating to C++11 nullptr.

llvm-svn: 223079
2014-12-01 22:02:27 +00:00
David Blaikie 82e95a3c79 Update for LLVM API change to make Small(Ptr)Set::insert return pair<iterator, bool> as per the C++ standard's associative container concept.
llvm-svn: 222335
2014-11-19 07:49:47 +00:00
David Blaikie 3c8c46efd7 clang-format a recent commit I made
llvm-svn: 222317
2014-11-19 05:48:40 +00:00
David Blaikie 13156b689e Standardize on StringMap::insert, removing uses of StringMap::GetOrCreateValue.
llvm-svn: 222306
2014-11-19 03:06:06 +00:00
David Blaikie 1cbb971c2d Remove some redundant virtual specifiers on overriden functions.
llvm-svn: 222024
2014-11-14 19:09:44 +00:00
Richard Smith 0f0af19b05 [c++1z] N4295: fold-expressions.
This is a new form of expression of the form:

  (expr op ... op expr)

where one of the exprs is a parameter pack. It expands into

  (expr1 op (expr2onwards op ... op expr))

(and likewise if the pack is on the right). The non-pack operand can be
omitted; in that case, an empty pack gives a fallback value or an error,
depending on the operator.

llvm-svn: 221573
2014-11-08 05:07:16 +00:00
Michael J. Spencer 04162eaced [llvm-api-change] Use findProgramByName.
llvm-svn: 221222
2014-11-04 01:30:55 +00:00
Reid Kleckner 8cd0079d16 Use the new LLVM_END_WITH_NULL name
llvm-svn: 221217
2014-11-04 01:13:43 +00:00
Kaelyn Takata e1f49d545d Add the initial TypoExpr AST node for delayed typo correction.
llvm-svn: 220692
2014-10-27 18:07:20 +00:00
Anton Yartsev 6ca45c92a9 [analyzer] Move the NewDeleteLeaks checker from CplusplusAlpha to Cplusplus package.
llvm-svn: 220289
2014-10-21 12:41:36 +00:00
Ted Kremenek 0c28bc20da [analyzer] Tweak MallocSizeOfChecker to not warn when using sizeof(void*) to allocate a bunch of any pointer type.
This suppresses a common false positive when analyzing libc++.

Along the way, introduce some tests to show this checker actually
works with C++ static_cast<>.

llvm-svn: 220160
2014-10-19 07:30:55 +00:00
Jordan Rose 679659f58c [analyzer] Check all 'nonnull' attributes, not just the first one.
Patch by Daniel Fahlgren!

llvm-svn: 219625
2014-10-13 19:38:02 +00:00
Benjamin Kramer ad8e079c61 Reduce double set lookups. NFC.
llvm-svn: 219504
2014-10-10 15:32:48 +00:00
Daniel Dunbar 214671f98c [Analysis] Add missing newlines at end of file.
llvm-svn: 219439
2014-10-09 20:34:45 +00:00
Alexey Bataev ec4747802a Fix for bug http://llvm.org/PR17427.
Assertion failed: "Computed __func__ length differs from type!"
Reworked PredefinedExpr representation with internal StringLiteral field for function declaration.
Differential Revision: http://reviews.llvm.org/D5365

llvm-svn: 219393
2014-10-09 08:45:04 +00:00
Alexey Bataev 13314bf526 [OPENMP] 'omp teams' directive basic support.
Includes parsing and semantic analysis for 'omp teams' directive support from OpenMP 4.0. Adds additional analysis to 'omp target' directive with 'omp teams' directive.  

llvm-svn: 219385
2014-10-09 04:18:56 +00:00
Renato Golin 9804fa5d48 Revert "[OPENMP] 'omp teams' directive basic support. Includes parsing and semantic analysis for 'omp teams' directive support from OpenMP 4.0. Adds additional analysis to 'omp target' directive with 'omp teams' directive."
This reverts commit r219197 because it broke ARM self-hosting buildbots with
segmentation fault errors in many tests.

llvm-svn: 219289
2014-10-08 09:06:45 +00:00
Alexey Bataev 941bbec6f4 [OPENMP] 'omp teams' directive basic support.
Includes parsing and semantic analysis for 'omp teams' directive support from OpenMP 4.0. Adds additional analysis to 'omp target' directive with 'omp teams' directive.

llvm-svn: 219197
2014-10-07 10:13:33 +00:00
Benjamin Kramer 719772c269 Remove stray enum keywords. MSVC sees this as a redeclaration at global scope.
llvm-svn: 219031
2014-10-03 22:20:30 +00:00
Anna Zaks 0820e13e2a [analyzer] Refactor and cleanup IsCompleteType
There are three copies of IsCompleteType(...) functions in CSA and all
of them are incomplete (I experienced  crashes in some CSA's test cases).
I have replaced these function calls with Type::isIncompleteType() calls.

A patch by Aleksei Sidorin!

llvm-svn: 219026
2014-10-03 21:49:03 +00:00
Anna Zaks d79b840716 [analyzer] Make Malloc Checker track memory allocated by if_nameindex
The MallocChecker does currently not track the memory allocated by
if_nameindex. That memory is dynamically allocated and should be freed
by calling if_freenameindex. The attached patch teaches the checker
about these functions.

Memory allocated by if_nameindex is treated as a separate allocation
"family". That way the checker can verify it is freed by the correct
function.

A patch by Daniel Fahlgren!

llvm-svn: 219025
2014-10-03 21:48:59 +00:00
Anna Zaks 2d2f137ed4 [analyzer] Make CStringChecker correctly calculate return value of mempcpy
The return value of mempcpy is only correct when the destination type is
one byte in size. This patch casts the argument to a char* so the
calculation is also correct for structs, ints etc.

A patch by Daniel Fahlgren!

llvm-svn: 219024
2014-10-03 21:48:54 +00:00
Alexander Musman e4e893bb36 [OPENMP] Parsing/Sema of directive omp parallel for simd
llvm-svn: 218299
2014-09-23 09:33:00 +00:00
Alexey Bataev 0bd520b767 [OPENMP] Initial parsing/sema analysis of 'target' directive.
llvm-svn: 218110
2014-09-19 08:19:49 +00:00
Alexander Musman f82886e502 Parsing/Sema of directive omp for simd
llvm-svn: 218029
2014-09-18 05:12:34 +00:00
Benjamin Kramer 22c68ef845 Avoid some unnecessary SmallVector copies.
No functionality change.

llvm-svn: 217586
2014-09-11 14:13:49 +00:00
Jordan Rose 21933ccdd7 Teach the analyzer that __builtin_assume_aligned returns its first argument.
Patch by Daniel Fahlgren!

llvm-svn: 217461
2014-09-09 21:42:16 +00:00
Jordan Rose f69e65f75c [analyzer] Don't crash if malloc() has an unexpected function prototype.
Patch by Daniel Fahlgren!

llvm-svn: 217258
2014-09-05 16:33:51 +00:00
David Blaikie a48a53cc8e unique_ptrify AnalysisConsumer.cpp::CreateUbiViz
llvm-svn: 217212
2014-09-05 00:14:57 +00:00
David Blaikie ad464dbf0b Remove a use of raw pointer ownership (then non-ownership) in TrimmedGraph::popNextReportGraph
(just cleaning up unique_ptr stuff by finding interesting 'reset' calls
at the moment)

llvm-svn: 217210
2014-09-05 00:11:25 +00:00
David Blaikie b564d1fb43 unique_ptrify ExplodedGraph::trim
llvm-svn: 217208
2014-09-05 00:04:19 +00:00
David Blaikie 7c35f6194f unique_ptrify the result of ConstraintManagerCreator and StoreManagerCreator
llvm-svn: 217206
2014-09-04 23:54:37 +00:00
David Blaikie 91e7902622 unique_ptrify BugReporter::visitors
llvm-svn: 217205
2014-09-04 23:54:33 +00:00