Commit Graph

3066 Commits

Author SHA1 Message Date
Adam Balogh bf77ab7f0e [Analyzer] Commit fix for rL341790/rC341790
Test file was accidentally not added for rL341790/rC341790 and subsequant patches.

llvm-svn: 341795
2018-09-10 09:19:54 +00:00
Adam Balogh 2e7cb34d0f [Analyzer] Iterator Checker - Part 8: Support for assign, clear, insert, emplace and erase operations
This patch adds support for the following operations in the iterator checkers: assign, clear, insert, insert_after, emplace, emplace_after, erase and erase_after. This affects mismatched iterator checks ("this" and parameter must match) and invalidation checks (according to the standard).

Differential Revision: https://reviews.llvm.org/D32904

llvm-svn: 341794
2018-09-10 09:07:47 +00:00
Adam Balogh 9a48ba6b4a [Analyzer] Iterator Checker - Part 7: Support for push and pop operations
This patch adds support for the following operations in the iterator checkers: push_back, push_front, emplace_back, emplace_front, pop_back and pop_front. This affects iterator range checks (range is extended after push and emplace and reduced after pop operations) and invalidation checks (according to the standard).

Differential Revision: https://reviews.llvm.org/D32902

llvm-svn: 341793
2018-09-10 09:06:31 +00:00
Adam Balogh 21583b733a [Analyzer] Iterator Checker - Part 4: Mismatched iterator checker for function parameters
New check added to the checker which checks whether iterator parameters of template functions typed by the same template parameter refer to the same container.

Differential Revision: https://reviews.llvm.org/D32845

llvm-svn: 341790
2018-09-10 09:03:22 +00:00
George Karpenkov 8a88c83593 Revert "Revert "Revert "Revert "[analyzer] Add coverage information to plist output, update tests""""
This reverts commit 2f5d71d9fa135be86bb299e7d773036e50bf1df6.

Hopefully fixing tests on Windows.

llvm-svn: 341719
2018-09-07 21:58:24 +00:00
Simon Pilgrim b746df0b0a Revert "Revert "Revert "[analyzer] Add coverage information to plist output, update tests"""
Reverts analyzer tests from rL341627 again as they still broke windows buildbots

llvm-svn: 341648
2018-09-07 10:27:16 +00:00
George Karpenkov d7acacab94 Revert "Revert "[analyzer] Add coverage information to plist output, update tests""
This reverts commit a39bcab414dd7ace7e490363ecdf01ecce7743fc.

Reverting the revert, fixing tests.

llvm-svn: 341627
2018-09-07 02:02:35 +00:00
George Karpenkov 4762fb5d11 Revert "[analyzer] Add coverage information to plist output, update tests"
This reverts commit 03d183b6b94eda27ce66a4f9b87a00b0a148cf9e.

Temporary revert until the tests are fixed.

llvm-svn: 341626
2018-09-07 01:39:23 +00:00
George Karpenkov bb313b797d [analyzer] Add coverage information to plist output, update tests
Split tests which were still using FileCheck to compare plists.

Differential Revision: https://reviews.llvm.org/D51515

llvm-svn: 341621
2018-09-07 00:44:17 +00:00
George Karpenkov 55e3d1ec35 [analyzer] Do not add invalid source location to the coverage information
Invalid source locations may arise from generated code.

Differential Revision: https://reviews.llvm.org/D51761

llvm-svn: 341618
2018-09-07 00:43:17 +00:00
George Karpenkov 95363e378a [analyzer] Remove traces of ubigraph visualization
Ubigraph project has been dead since about 2008, and to the best of my
knowledge, no one was using it.
Previously, I wasn't able to launch the existing binary at all.

Differential Revision: https://reviews.llvm.org/D51655

llvm-svn: 341601
2018-09-06 23:07:47 +00:00
Artem Dergachev 73b38668ce [analyzer] InnerPointerChecker: Fix a segfault when checking symbolic strings.
Return value of dyn_cast_or_null should be checked before use.
Otherwise we may put a null pointer into the map as a key and eventually
crash in checkDeadSymbols.

Differential Revision: https://reviews.llvm.org/D51385

llvm-svn: 341092
2018-08-30 18:45:05 +00:00
George Karpenkov 574d78e78e [analyzer] Improve tracing for uninitialized struct fields
rdar://13729267

Differential Revision: https://reviews.llvm.org/D51323

llvm-svn: 340986
2018-08-29 22:48:50 +00:00
Artem Dergachev 4e864b8329 [analyzer] Support modeling no-op BaseToDerived casts in ExprEngine.
Introduce a new MemRegion sub-class, CXXDerivedObjectRegion, which is
the opposite of CXXBaseObjectRegion, to represent such casts. Such region is
a bit weird because it is by design bigger than its super-region.
But it's not harmful when it is put on top of a SymbolicRegion
that has unknown extent anyway.

Offset computation for CXXDerivedObjectRegion and proper modeling of casts
still remains to be implemented.

Differential Revision: https://reviews.llvm.org/D51191

llvm-svn: 340984
2018-08-29 22:43:31 +00:00
Artem Dergachev 5a3beea0e3 [analyzer] CFRetainReleaseChecker: Don't check C++ methods with the same name.
Don't try to understand what's going on when there's a C++ method called eg.
CFRetain().

Refactor the checker a bit, to use more modern APIs.

Differential Revision: https://reviews.llvm.org/D50866

llvm-svn: 340982
2018-08-29 22:39:20 +00:00
Artem Dergachev ed19831f63 [CFG] [analyzer] Disable argument construction contexts for variadic functions.
The analyzer doesn't make use of them anyway and they seem to have
pretty weird AST from time to time, so let's just skip them for now.

Fixes a crash reported as pr37769.

Differential Revision: https://reviews.llvm.org/D50855

llvm-svn: 340977
2018-08-29 22:05:35 +00:00
Artem Dergachev 594b5410a6 [CFG] [analyzer] Disable argument construction contexts for variadic functions.
The analyzer doesn't make use of them anyway and they seem to have
pretty weird AST from time to time, so let's just skip them for now.

Fixes pr37769.

Differential Revision: https://reviews.llvm.org/D50824

llvm-svn: 340975
2018-08-29 21:50:52 +00:00
George Karpenkov e12dcf124b [analyzer] Fix tests on 32-bit platforms by specifying the tuple explicitly
llvm-svn: 340972
2018-08-29 21:18:47 +00:00
George Karpenkov 9ff67a9dda [analyzer] Resolve the crash in ReturnUndefChecker
By making sure the returned value from getKnownSVal is consistent with
the value used inside expression engine.

PR38427

Differential Revision: https://reviews.llvm.org/D51252

llvm-svn: 340965
2018-08-29 20:29:59 +00:00
George Karpenkov a393e68b27 [analyzer] Move analyzer-eagerly-assume to AnalyzerOptions, enable by default
Differential Revision: https://reviews.llvm.org/D51251

llvm-svn: 340963
2018-08-29 20:29:17 +00:00
Adam Balogh 2cfbe933a1 [Analyzer] Iterator Checker - Part 3: Invalidation check, first for (copy) assignments
We add check for invalidation of iterators. The only operation we handle here
is the (copy) assignment.

Differential Revision: https://reviews.llvm.org/D32747

llvm-svn: 340805
2018-08-28 08:41:15 +00:00
George Karpenkov ab0011ebc0 [analyzer] Preliminary version of retain count checking for OSObjects
Has quite a lot of false positives, disabled behind the flag.

Differential Revision: https://reviews.llvm.org/D50880

llvm-svn: 340502
2018-08-23 00:26:59 +00:00
George Karpenkov c433011e02 Revert "[CStringSyntaxChecker] Check strlcat sizeof check"
This reverts commit 3073790e87378fea9a68fb052185fec9596ef135.

The check is not correct, strlact(dest, "mystr", sizeof(dest)) is fine.

llvm-svn: 340501
2018-08-23 00:02:35 +00:00
George Karpenkov b45bf3bb8b Revert "[CStringSyntaxChecker] Reduces space around error message for strlcat."
This reverts commit 6b43b80320722da41ca6ef7a3b57cc300fb83094.

llvm-svn: 340500
2018-08-23 00:02:12 +00:00
George Karpenkov baa78cc6d3 [analyzer] Track non-zero values in ReturnVisitor
Tracking those can help to provide much better diagnostics in many cases.

In general, most of the visitor machinery should be refactored to allow
tracking the origin of arbitrary values.

rdar://36039765

Differential Revision: https://reviews.llvm.org/D51131

llvm-svn: 340475
2018-08-22 23:17:25 +00:00
Kristof Umann b59b45e7f1 [analyzer][UninitializedObjectChecker] Explicit namespace resolution for inherited data members
For the following example:

  struct Base {
    int x;
  };

  // In a different translation unit

  struct Derived : public Base {
    Derived() {}
  };

For a call to Derived::Derived(), we'll receive a note that
this->x is uninitialized. Since x is not a direct field of Derived,
it could be a little confusing. This patch aims to fix this, as well
as the case when the derived object has a field that has the name as
an inherited uninitialized data member:

  struct Base {
    int x; // note: uninitialized field 'this->Base::x'
  };

  struct Derived : public Base {
    int x = 5;
    Derived() {}
  };

Differential Revision: https://reviews.llvm.org/D50905

llvm-svn: 340272
2018-08-21 12:16:59 +00:00
Kristof Umann 646019655c [analyzer][UninitializedObjectChecker] Refactoring p6.: Move dereferencing to a function
Now that it has it's own file, it makes little sense for
isPointerOrReferenceUninit to be this large, so I moved
dereferencing to a separate function.

Differential Revision: https://reviews.llvm.org/D50509

llvm-svn: 340265
2018-08-21 10:45:21 +00:00
George Karpenkov bc0cddf0c8 [analyzer] Re-instate support for MakeCollectable is RetainCountChecker
Differential Revision: https://reviews.llvm.org/D50872

llvm-svn: 340097
2018-08-17 21:42:59 +00:00
George Karpenkov 7390ddc968 [analyzer] Drop support for GC mode in RetainCountChecker
A lot of code in RetainCountChecker deals with GC mode.
Given that GC mode is deprecated, Apple does not ship runtime for it,
and modern compiler toolchain does not support it, it makes sense to
remove the code dealing with it in order to aid understanding of
RetainCountChecker.

Differential Revision: https://reviews.llvm.org/D50747

llvm-svn: 340091
2018-08-17 21:40:38 +00:00
David Carlier 6a691a0b7c [CStringSyntaxChecker] Reduces space around error message for strlcat.
llvm-svn: 339808
2018-08-15 20:09:52 +00:00
Artem Dergachev 3ccf14eb8e [analyzer] Add support for constructors of arguments.
Once CFG-side support for argument construction contexts landed in r338436,
the analyzer could make use of them to evaluate argument constructors properly.

When evaluated as calls, constructors of arguments now use the variable region
of the parameter as their target. The corresponding stack frame does not yet
exist when the parameter is constructed, and this stack frame is created
eagerly.

Construction of functions whose body is unavailable and of virtual functions
is not yet supported. Part of the reason is the analyzer doesn't consistently
use canonical declarations o identify the function in these cases, and every
re-declaration or potential override comes with its own set of parameter
declarations. Also it is less important because if the function is not
inlined, there's usually no benefit in inlining the argument constructor.

Differential Revision: https://reviews.llvm.org/D49443

llvm-svn: 339745
2018-08-15 00:33:55 +00:00
Artem Dergachev c531d54967 [CFG] [analyzer] Find argument constructors in CXXTemporaryObjectExprs.
CXXTemporaryObjectExpr is a sub-class of CXXConstructExpr. If it has arguments
that are structures passed by value, their respective constructors need to be
handled by providing a ConstructionContext, like for regular function calls and
for regular constructors.

Differential Revision: https://reviews.llvm.org/D50487

llvm-svn: 339727
2018-08-14 21:10:46 +00:00
Artem Dergachev bf33a2cdf2 [analyzer] Add a test forgotten in r339088.
Differential Revision: https://reviews.llvm.org/D50363

llvm-svn: 339726
2018-08-14 21:06:30 +00:00
Kristof Umann 5a42441d81 [analyzer][UninitializedObjectChecker] Void pointers are casted back to their dynamic type in note message
Differential Revision: https://reviews.llvm.org/D49228

llvm-svn: 339653
2018-08-14 08:20:51 +00:00
David Carlier 54fc3767fc [CStringSyntaxChecker] Check strlcat sizeof check
- Assuming strlcat is used with strlcpy we check as we can if the last argument does not equal os not larger than the buffer.
- Advising the proper usual pattern.

Reviewers: NoQ, george.karpenkov

Reviewed By: george.karpenkov

Differential Revision: https://reviews.llvm.org/D49722

llvm-svn: 339641
2018-08-14 05:12:53 +00:00
Richard Smith 5b2636142a Move test inputs into Inputs directory.
We don't need a new ExpectedOutputs/ convention. Expected outputs are
just another form of test input.

llvm-svn: 339634
2018-08-14 00:18:48 +00:00
George Karpenkov e3b1d96218 [analyzer] Fix UninitializedObjectChecker to not crash on uninitialized "id" fields
Differential Revision: https://reviews.llvm.org/D50673

llvm-svn: 339631
2018-08-13 23:32:15 +00:00
George Karpenkov 2997a3042e [analyzer] [NFC] Introduce separate targets for testing the analyzer: check-clang-analyzer and check-clang-analyzer-z3
Current testing setup for analyzer tests with Z3 is rather inconvenient:

There's no way to run the analyzer tests separately (I use
LIT_FILTER=Analysis ninja check-clang, but a direct target is nicer).

When Clang is built with Z3 support, there's no way to *not* run tests
with Z3 solver, and this is often desired, as tests with Z3 solver take
a very long time.

This patch introduces two extra targets:

 - check-clang-analyzer
 - check-clang-analyzer-z3

which solve those problems.

Differential Revision: https://reviews.llvm.org/D50594

llvm-svn: 339629
2018-08-13 23:12:43 +00:00
Kristof Umann 015b059569 [analyzer][UninitializedObjectChecker] Refactoring p4.: Wrap FieldRegions and reduce weight on FieldChainInfo
Before this patch, FieldChainInfo used a spaghetti: it took care of way too many cases,
even though it was always meant as a lightweight wrapper around
ImmutableList<const FieldRegion *>.
This problem is solved by introducing a lightweight polymorphic wrapper around const
FieldRegion *, FieldNode. It is an interface that abstracts away special cases like
pointers/references, objects that need to be casted to another type for a proper note
messages.

Changes to FieldChainInfo:

  * Now wraps ImmutableList<const FieldNode &>.
  * Any pointer/reference related fields and methods were removed
  * Got a new add method. This replaces it's former constructors as a way to create a
    new FieldChainInfo objects with a new element.

Changes to FindUninitializedField:

  * In order not to deal with dynamic memory management, when an uninitialized field is
    found, the note message for it is constructed and is stored instead of a
    FieldChainInfo object. (see doc around addFieldToUninits).

Some of the test files are changed too, from now on uninitialized pointees of references
always print "uninitialized pointee" instead of "uninitialized field" (which should've
really been like this from the beginning).

I also updated every comment according to these changes.

Differential Revision: https://reviews.llvm.org/D50506

llvm-svn: 339599
2018-08-13 18:43:08 +00:00
Reka Kovacs bb2749a594 [analyzer] InnerPointerChecker: improve warning messages and notes.
Differential Revision: https://reviews.llvm.org/D49570

llvm-svn: 339489
2018-08-10 23:56:57 +00:00
George Karpenkov 2537972f25 [analyzer] [NFC] [tests] Move plist-based diagnostics tests to separate files, use diff instead of a FileCheck - II
Some files were missed by https://reviews.llvm.org/D50545

Differential Revision: https://reviews.llvm.org/D50590

llvm-svn: 339488
2018-08-10 23:51:43 +00:00
George Karpenkov e99ba6e1f9 [analyzer] Record nullability implications on getting items from NSDictionary
If we get an item from a dictionary, we know that the item is non-null
if and only if the key is non-null.

This patch is a rather hacky way to record this implication, because
some logic needs to be duplicated from the solver.
And yet, it's pretty simple, performant, and works.

Other possible approaches:

 - Record the implication, in future rely on Z3 to pick it up.
 - Generalize the current code and move it to the constraint manager.

rdar://34990742

Differential Revision: https://reviews.llvm.org/D50124

llvm-svn: 339482
2018-08-10 22:27:04 +00:00
George Karpenkov b5dd3ccdbd [analyzer] Fix tracking expressions through negation operator
Differential Revision: https://reviews.llvm.org/D50537

llvm-svn: 339476
2018-08-10 21:42:19 +00:00
George Karpenkov 09a9e3abfe [analyzer] [NFC] [tests] Move plist-based diagnostics tests to separate files, use diff instead of a FileCheck
Some of the analyzer tests check the exact plist output, in order to
verify that the diagnostics produced is correct.
Current testing setup has many issues:

plist output clobbers tests, making them harder to read
it is impossible to debug test failures given error messages from FileCheck.
The only recourse is manually creating the files and using the diff
again, it is impossible to update the tests given the error message:
the only process is a tedious manual one,
going from a separate plist file to CHECK directives.

This patch offers a much better approach of using "diff" directly in place of FileCheck,
and moving tests to separate files.

Generated using the following script:

```
import os
import glob
import re
import subprocess

diagnostics_key = "// CHECK:  <key>diagnostics</key>"

def process_file(f, data):
    idx = data.index(diagnostics_key)
    plist_out_f = 'ExpectedOutputs/plists/%s.plist' % f
    plist_out_folder = os.path.join('ExpectedOutputs/plists/', os.path.dirname(f))
    plist_data = data[idx:]
    plist_data = plist_data.replace('// CHECK: ', '')
    plist_data = plist_data.replace('// CHECK-NEXT: ', '')
    plist_data += "</dict>\n</plist>\n"
    data = data[:idx]

    ptn = re.compile("FileCheck --?input-file(=| )(%t|%t\.plist) %s")

    if not ptn.findall(data):
        print "none found =/ skipping..."
        return

    data = ptn.sub(lambda m: "tail -n +11 %s | diff -u -w - %%S/../%s" % (m.group(2), plist_out_f), data)

    with open(f, 'w') as out_f:
        out_f.write(data)

    subprocess.check_call(["mkdir", "-p", plist_out_folder])
    with open(plist_out_f, 'w') as out_f:
        out_f.write(plist_data)

def main():
    files = glob.glob("**/*.*")
    for f in files:
        with open(f) as f_handler:
            data = f_handler.read()
        if diagnostics_key in data:
            print "Converting %s" %f
            process_file(f, data)

if __name__ == "__main__":
    main()
```

Differential Revision: https://reviews.llvm.org/D50545

llvm-svn: 339475
2018-08-10 21:36:45 +00:00
George Karpenkov 088adbfa16 Invalidate static locals when escaping lambdas
Lambdas can affect static locals even without an explicit capture.

rdar://39537031

Differential Revision: https://reviews.llvm.org/D50368

llvm-svn: 339459
2018-08-10 18:28:04 +00:00
George Karpenkov cf40ba8284 [analyzer] Fix the bug in UninitializedObjectChecker caused by not handling block pointers
Differential Revision: https://reviews.llvm.org/D50523

llvm-svn: 339369
2018-08-09 19:03:12 +00:00
Kristof Umann ef9af05539 [analyzer][UninitializedObjectChecker] Pointer/reference objects are dereferenced according to dynamic type
This patch fixed an issue where the dynamic type of pointer/reference
object was known by the analyzer, but wasn't obtained in the checker,
which resulted in false negatives. This should also increase reliability
of the checker, as derefencing is always done now according to the
dynamic type (even if that happens to be the same as the static type).

Special thanks to Artem Degrachev for setting me on the right track.

Differential Revision: https://reviews.llvm.org/D49199

llvm-svn: 339240
2018-08-08 13:18:53 +00:00
Kristof Umann 0735cfbd84 [analyzer][UninitializedObjectChecker] Fixed a false negative by no longer filtering out certain constructor calls
As of now, all constructor calls are ignored that are being called
by a constructor. The point of this was not to analyze the fields
of an object, so an uninitialized field wouldn't be reported
multiple times.

This however introduced false negatives when the two constructors
were in no relation to one another -- see the test file for a neat
example for this with singletons. This patch aims so fix this issue.

Differential Revision: https://reviews.llvm.org/D48436

llvm-svn: 339237
2018-08-08 12:23:02 +00:00
Matt Davis 95dd80c2e8 [analyzer] Avoid querying this-pointers for static-methods.
Summary:
The loop-widening code processes c++ methods looking for `this` pointers.  In
the case of static methods (which do not have `this` pointers), an assertion
was triggering.   This patch avoids trying to process `this` pointers for
static methods, and thus avoids triggering the assertion .


Reviewers: dcoughlin, george.karpenkov, NoQ

Reviewed By: NoQ

Subscribers: NoQ, xazax.hun, szepet, a.sidorin, mikhail.ramalho, cfe-commits

Differential Revision: https://reviews.llvm.org/D50408

llvm-svn: 339201
2018-08-07 23:13:28 +00:00
Kristof Umann a3f7b58742 [analyzer][UninitializedObjectChecker] New flag to turn off dereferencing
Even for a checker being in alpha, some reports about pointees held so little
value to the user that it's safer to disable pointer/reference chasing for now.
It can be enabled with a new flag, in which case checker should function as it
has always been. This can be set with `CheckPointeeInitialization`.

Differential Revision: https://reviews.llvm.org/D49438

llvm-svn: 339135
2018-08-07 12:55:26 +00:00