Commit Graph

47 Commits

Author SHA1 Message Date
Kirstóf Umann 5192783bb2 [analyzer][RetainCount] Tie diagnostics to osx.cocoa.RetainCount rather then RetainCountBase, for the most part
Similarly to other patches of mine, I'm trying to uniformize the checker
interface so that dependency checkers don't emit diagnostics. The checker that
made me most anxious so far was definitely RetainCount, because it is definitely
impacted by backward compatibility concerns, and implements a checker hierarchy
that is a lot different to other examples of similar size. Also, I don't have
authority, nor expertise regarding ObjC related code, so I welcome any
objection/discussion!

Differential Revision: https://reviews.llvm.org/D78099
2020-05-27 00:01:47 +02:00
Kirstóf Umann 66224d309d [analyzer][ObjCGenerics] Don't emit diagnostics under the name core.DynamicTypePropagation
Differential Revision: https://reviews.llvm.org/D78124
2020-05-20 00:19:20 +02:00
Kirstóf Umann e4e1080a58 [analyzer][Nullability] Don't emit under the checker name NullabilityBase
Differential Revision: https://reviews.llvm.org/D78122
2020-05-19 17:04:06 +02:00
Artem Dergachev 0b58b80edb [analyzer] Fix Objective-C accessor body farms after 2073dd2d.
Fix a canonicalization problem for the newly added property accessor stubs that
was causing a wrong decl to be used for 'self' in the accessor's body farm.

Fix a crash when constructing a body farm for accessors of a property
that is declared and @synthesize'd in different (but related) interfaces.

Differential Revision: https://reviews.llvm.org/D70158
2019-11-21 18:59:46 -08:00
Adrian Prantl 2073dd2da7 Redeclare Objective-C property accessors inside the ObjCImplDecl in which they are synthesized.
This patch is motivated by (and factored out from)
https://reviews.llvm.org/D66121 which is a debug info bugfix. Starting
with DWARF 5 all Objective-C methods are nested inside their
containing type, and that patch implements this for synthesized
Objective-C properties.

1. SemaObjCProperty populates a list of synthesized accessors that may
   need to inserted into an ObjCImplDecl.

2. SemaDeclObjC::ActOnEnd inserts forward-declarations for all
   accessors for which no override was provided into their
   ObjCImplDecl. This patch does *not* synthesize AST function
   *bodies*. Moving that code from the static analyzer into Sema may
   be a good idea though.

3. Places that expect all methods to have bodies have been updated.

I did not update the static analyzer's inliner for synthesized
properties to point back to the property declaration (see
test/Analysis/Inputs/expected-plists/nullability-notes.m.plist), which
I believed to be more bug than a feature.

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

rdar://problem/53782400
2019-11-08 08:23:22 -08:00
Kristof Umann 1b439659a8 [analyzer] NonNullParamChecker and CStringChecker parameter number in checker message
There are some functions which can't be given a null pointer as parameter either
because it has a nonnull attribute or it is declared to have undefined behavior
(e.g. strcmp()). Sometimes it is hard to determine from the checker message
which parameter is null at the invocation, so now this information is included
in the message.

This commit fixes https://bugs.llvm.org/show_bug.cgi?id=39358

Reviewed By: NoQ, Szelethus, whisperity

Patch by Tibor Brunner!

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

llvm-svn: 370798
2019-09-03 17:57:01 +00:00
Csaba Dabis 124ef7fce4 [analyzer] ConditionBRVisitor: Fix HTML PathDiagnosticPopUpPieces
Summary:
A condition could be a multi-line expression where we create the highlight
in separated chunks. PathDiagnosticPopUpPiece is not made for that purpose,
it cannot be added to multiple lines because we have only one ending part
which contains all the notes. So that it cannot have multiple endings and
therefore this patch narrows down the ranges of the highlight to the given
interesting variable of the condition. It prevents HTML-breaking injections.

Reviewed By: NoQ

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

llvm-svn: 368382
2019-08-09 02:20:44 +00:00
Hubert Tong 15e3e95263 [analyzer][NFC][tests] Pre-normalize expected-plists
As suggested in the review for D62949, this patch pre-normalizes the
reference expected output plist files by removing lines containing
fields for which we expect differences that should be ignored.

llvm-svn: 362877
2019-06-08 13:51:37 +00:00
Hubert Tong 7081efcc58 [analyzer][NFC][tests] Remove unused expected-plist files
llvm-svn: 362876
2019-06-08 13:48:25 +00:00
Csaba Dabis 2e896b8b39 [analyzer] ConditionBRVisitor: Boolean support
Summary: -

Reviewers: NoQ, george.karpenkov

Reviewed By: NoQ, george.karpenkov

Subscribers: cfe-commits, xazax.hun, baloghadamsoftware, szepet, a.sidorin,
             mikhail.ramalho, Szelethus, donat.nagy, dkrupp

Tags: #clang

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

llvm-svn: 362027
2019-05-29 20:34:29 +00:00
Csaba Dabis d1f0ec3f64 [analyzer] ConditionBRVisitor: MemberExpr support
Summary: -

Reviewers: NoQ, george.karpenkov

Reviewed By: NoQ

Subscribers: cfe-commits, xazax.hun, baloghadamsoftware, szepet, a.sidorin,
             mikhail.ramalho, Szelethus, donat.nagy, dkrupp

Tags: #clang

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

llvm-svn: 362026
2019-05-29 20:29:02 +00:00
Csaba Dabis 8193ea60f6 [analyzer] ConditionBRVisitor: Test 'add-pop-up-notes=false'
Summary: -

Reviewers: NoQ, alexfh

Reviewed By: alexfh

Subscribers: cfe-commits, xazax.hun, baloghadamsoftware, szepet, a.sidorin,
             mikhail.ramalho, Szelethus, donat.nagy, dkrupp

Tags: #clang

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

llvm-svn: 362023
2019-05-29 20:13:29 +00:00
Csaba Dabis 4b0184b2d3 [analyzer] ConditionBRVisitor: Enhance to write out more information
Summary:
Add extra messages to the bug report to inform the user why the analyzer
`Taking true/false branch`.

Reviewers: NoQ, george.karpenkov

Reviewed By: NoQ

Subscribers: gerazo, gsd, dkrupp, whisperity, baloghadamsoftware, xazax.hun,
             eraman, szepet, a.sidorin, mikhail.ramalho, Szelethus,
             donat.nagy, cfe-commits

Tags: #clang

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

llvm-svn: 362020
2019-05-29 20:06:09 +00:00
Hubert Tong 0b4699b931 [analyzer][tests][NFC] Add EOF newlines, normalize reference expected files
Reference expected files not ending with a newline are normalized to
have said newlines. Additionally `plist-macros-with-expansion.cpp.plist`
is modified to add a line that is ignored by `%diff_plist`, but not by
the more sensitive pattern proposed by
http://lists.llvm.org/pipermail/cfe-dev/2019-April/061904.html for
`%normalize_plist`.

llvm-svn: 359692
2019-05-01 15:57:00 +00:00
Kristof Umann 7b907bed3c [analyzer] Fix function macro crash
Re-commit D57893.

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

llvm-svn: 356142
2019-03-14 13:38:16 +00:00
Kristof Umann e58dde2a80 Revert "[analyzer] Fix function macro crash"
Buildbot breaks when LLVm is compiled with memory sanitizer.

WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0xa3d16d8 in getMacroNameAndPrintExpansion(blahblah)
                             lib/StaticAnalyzer/Core/PlistDiagnostics.cpp:903:11
llvm-svn: 355911
2019-03-12 11:22:30 +00:00
Kristof Umann 9f92b3d081 [analyzer] Fix function macro crash
When there is a functor-like macro which is passed as parameter to another
"function" macro then its parameters are not listed at the place of expansion:

#define foo(x) int bar() { return x; }
#define hello(fvar) fvar(0)
hello(foo)
int main() { 1 / bar(); }

Expansion of hello(foo) asserted Clang, because it expected an l_paren token in
the 3rd line after "foo", since it is a function-like token.

Patch by Tibor Brunner!

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

llvm-svn: 355903
2019-03-12 10:03:32 +00:00
Kristof Umann b4cdfe8e7f [analyzer] Fix infinite recursion in printing macros
In the commited testfile, macro expansion (the one implemented for the plist
output) runs into an infinite recursion. The issue originates from the algorithm
being faulty, as in

#define value REC_MACRO_FUNC(value)

the "value" is being (or at least attempted) expanded from the same macro.

The solved this issue by gathering already visited macros in a set, which does
resolve the crash, but will result in an incorrect macro expansion, that would
preferably be fixed down the line.

Patch by Tibor Brunner!

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

llvm-svn: 355705
2019-03-08 16:26:29 +00:00
George Karpenkov 77eae6d4c4 [analyzer] [RetainCountChecker] Bugfix for tracking top-level parameters of Objective-C methods
Differential Revision: https://reviews.llvm.org/D57433

llvm-svn: 352588
2019-01-30 02:11:04 +00:00
George Karpenkov d37ff4e888 [analyzer] [RetainCountChecker] Track input parameters to the top-level function
Track them for ISL/OS objects by default, and for NS/CF under a flag.

rdar://47536377

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

llvm-svn: 352534
2019-01-29 19:29:59 +00:00
Kristof Umann 8fd74ebfc0 [analyzer] Reimplement dependencies between checkers
Unfortunately, up until now, the fact that certain checkers depended on one
another was known, but how these actually unfolded was hidden deep within the
implementation. For example, many checkers (like RetainCount, Malloc or CString)
modelled a certain functionality, and exposed certain reportable bug types to
the user. For example, while MallocChecker models many many different types of
memory handling, the actual "unix.MallocChecker" checker the user was exposed to
was merely and option to this modeling part.

Other than this being an ugly mess, this issue made resolving the checker naming
issue almost impossible. (The checker naming issue being that if a checker
registered more than one checker within its registry function, both checker
object recieved the same name) Also, if the user explicitly disabled a checker
that was a dependency of another that _was_ explicitly enabled, it implicitly,
without "telling" the user, reenabled it.

Clearly, changing this to a well structured, declarative form, where the
handling of dependencies are done on a higher level is very much preferred.

This patch, among the detailed things later, makes checkers declare their
dependencies within the TableGen file Checkers.td, and exposes the same
functionality to plugins and statically linked non-generated checkers through
CheckerRegistry::addDependency. CheckerRegistry now resolves these dependencies,
makes sure that checkers are added to CheckerManager in the correct order,
and makes sure that if a dependency is disabled, so will be every checker that
depends on it.

In detail:

* Add a new field to the Checker class in CheckerBase.td called Dependencies,
which is a list of Checkers.
* Move unix checkers before cplusplus, as there is no forward declaration in
tblgen :/
* Add the following new checkers:
  - StackAddrEscapeBase
  - StackAddrEscapeBase
  - CStringModeling
  - DynamicMemoryModeling (base of the MallocChecker family)
  - IteratorModeling (base of the IteratorChecker family)
  - ValistBase
  - SecuritySyntaxChecker (base of bcmp, bcopy, etc...)
  - NSOrCFErrorDerefChecker (base of NSErrorChecker and  CFErrorChecker)
  - IvarInvalidationModeling (base of IvarInvalidation checker family)
  - RetainCountBase (base of RetainCount and OSObjectRetainCount)
* Clear up and registry functions in MallocChecker, happily remove old FIXMEs.
* Add a new addDependency function to CheckerRegistry.
* Neatly format RUN lines in files I looked at while debugging.

Big thanks to Artem Degrachev for all the guidance through this project!

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

llvm-svn: 352287
2019-01-26 20:06:54 +00:00
Kristof Umann f52f4f636f [analyzer] Split unix.API up to UnixAPIMisuseChecker and UnixAPIPortabilityChecker
The actual implementation of unix.API features a dual-checker: two checkers in
one, even though they don't even interact at all. Split them up, as this is a
problem for establishing dependencies.

I added no new code at all, just merely moved it around.

Since the plist files change (and that's a benefit!) this patch isn't NFC.

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

llvm-svn: 352278
2019-01-26 15:56:40 +00:00
George Karpenkov 5be959c88e [analyzer] Support for OSObjects out parameters in RetainCountChecker
rdar://46357478
rdar://47121327

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

llvm-svn: 350982
2019-01-11 23:35:17 +00:00
George Karpenkov dfd6f7db9b [analyzer] [NFC] Fix the FIXME in tests
llvm-svn: 350946
2019-01-11 18:12:49 +00:00
George Karpenkov 0bb17c4634 [analyzer] Update the category name for RetainCountChecker reports
..now that it includes OSObjects

rdar://46509986

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

llvm-svn: 350869
2019-01-10 18:16:25 +00:00
George Karpenkov 4f64b38f56 [analyzer] Quote the type of the leaked/problematic object in diagnostics for readability
Differential Revision: https://reviews.llvm.org/D56344

llvm-svn: 350867
2019-01-10 18:15:57 +00:00
Kristof Umann 09e86e77c9 Revert rC349281 '[analyzer][MallocChecker][NFC] Document and reorganize some functions'
llvm-svn: 349340
2018-12-17 12:07:57 +00:00
Kristof Umann a82810c56b [analyzer][MallocChecker] Improve warning messages on double-delete errors
Differential Revision: https://reviews.llvm.org/D54834

llvm-svn: 349283
2018-12-15 18:41:37 +00:00
Kristof Umann 5f9981f8a5 [analyzer][PlistMacroExpansion] Part 5.: Support for # and ##
From what I can see, this should be the last patch needed to replicate macro
argument expansions.

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

llvm-svn: 348025
2018-11-30 19:21:35 +00:00
George Karpenkov f893ea1592 [analyzer] Add the type of the leaked object to the diagnostic message
If the object is a temporary, and there is no variable it binds to,
let's at least print out the object name in order to help differentiate
it from other temporaries.

rdar://45175098

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

llvm-svn: 347943
2018-11-30 02:17:44 +00:00
George Karpenkov a1c3bb88ee [analyzer] Reference leaked object by name, even if it was created in an inlined function.
rdar://45532181

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

llvm-svn: 347942
2018-11-30 02:17:31 +00:00
Kristof Umann 8de6062010 [analyzer][PlistMacroExpansion] Part 4.: Support for __VA_ARGS__
Differential Revision: https://reviews.llvm.org/D52986

llvm-svn: 347888
2018-11-29 17:09:41 +00:00
Kristof Umann 08d92e4a10 [analyzer][PlistMacroExpansion] Part 3.: Macro arguments are expanded
This part focuses on expanding macro arguments.

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

llvm-svn: 347629
2018-11-27 02:28:23 +00:00
Kristof Umann 3800257fba Reland '[analyzer][PlistMacroExpansion] Part 2.: Retrieving the macro name and primitive expansion'
llvm-svn: 346111
2018-11-05 02:14:36 +00:00
Kristof Umann d96bdd2402 Revert '[analyzer][PlistMacroExpansion] Part 2.: Retrieving the macro name and primitive expansion'
llvm-svn: 346096
2018-11-04 14:18:37 +00:00
Kristof Umann 7430213d8e [analyzer][PlistMacroExpansion] Part 2.: Retrieving the macro name and primitive expansion
This patch adds a couple new functions to acquire the macro's name, and also
expands it, although it doesn't expand the arguments, as seen from the test files

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

llvm-svn: 346095
2018-11-04 13:59:44 +00:00
Kristof Umann 7d6d9eb688 [analyzer][PlistMacroExpansion] Part 1.: New expand-macros flag
This is the first part of the implementation of the inclusion of macro
expansions into the plist output. It adds a new flag that adds a new
"macro_expansions" entry to each report that has PathDiagnosticPieces that were
expanded from a macro. While there's an entry for each macro expansion, both
the name of the macro and what it expands to is missing, and will be implemented
in followup patches.

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

llvm-svn: 345724
2018-10-31 14:54:27 +00:00
Richard Smith 8baa50013c [cxx2a] P0614R1: Support init-statements in range-based for loops.
We don't yet support this for the case where a range-based for loop is
implicitly rewritten to an ObjC for..in statement.

llvm-svn: 343350
2018-09-28 18:44:09 +00:00
George Karpenkov 04553e530f [analyzer] Process state in checkEndFunction in RetainCountChecker
Modify the RetainCountChecker to perform state "adjustments" in
checkEndFunction, as performing work in PreStmt<ReturnStmt> does not
work with destructors.
The previous version made an implicit assumption that no code runs
after the return statement is executed.

rdar://43945028

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

llvm-svn: 342770
2018-09-21 20:37:20 +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 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
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