Commit Graph

3771 Commits

Author SHA1 Message Date
Adam Balogh 6e9c58946e [Analyzer] Iterator Modeling: Print Container Data and Iterator Positions when printing the Program State
Debugging the Iterator Modeling checker or any of the iterator checkers
is difficult without being able to see the relations between the
iterator variables and their abstract positions, as well as the abstract
symbols denoting the begin and the end of the container.

This patch adds the checker-specific part of the Program State printing
to the Iterator Modeling checker.
2019-12-11 14:20:17 +01:00
Gabor Horvath 8434fbbee6 Revert "[analyzer] Keep track of escaped locals"
It was a step in the right direction but it is not clear how can this
fit into the checker API at this point. The pre-escape happens in the
analyzer core and the checker has no control over it. If the checker
is not interestd in a pre-escape it would need to do additional work
on each escape to check if the escaped symbol is originated from an
"uninteresting" pre-escaped memory region. In order to keep the
checker API simple we abandoned this solution for now.

We will reland this once we have a better answer for what to do on the
checker side.

This reverts commit f3a28202ef.
2019-12-10 16:42:03 -08:00
Gabor Horvath f3a28202ef [analyzer] Keep track of escaped locals
We want to escape all symbols that are stored into escaped regions.
The problem is, we did not know which local regions were escaped. Until now.
This should fix some false positives like the one in the tests.

Differential Revision: https://reviews.llvm.org/D71152
2019-12-10 08:51:33 -08:00
Artem Dergachev 040c39d50f [analyzer] Fix false positive on introspection of a block's internal layout.
When implementation of the block runtime is available, we should not
warn that block layout fields are uninitialized simply because they're
on the stack.
2019-12-06 13:24:20 -08:00
Balázs Kéri 7eafde981c [Checkers] Added support for freopen to StreamChecker.
Summary: Extend StreamChecker with a new evaluation function for API call 'freopen'.

Reviewers: NoQ, baloghadamsoftware, Szelethus, martong

Reviewed By: baloghadamsoftware, martong

Subscribers: martong, rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69948
2019-12-05 11:08:44 +01:00
Artem Dergachev 3c50f2544f [analyzer] Fix more ObjC accessor body farms after 2073dd2d.
Fix a crash when constructing a body farm for accessors of a property
that is declared and @synthesize'd in different (but related) interfaces
with the explicit ivar syntax.

This is a follow-up for 0b58b80e.
2019-12-04 16:29:08 -08:00
Borsik Gabor 89bc4c662c [analyzer] Add custom filter functions for GenericTaintChecker
This patch is the last of the series of patches which allow the user to
annotate their functions with taint propagation rules.

I implemented the use of the configured filtering functions. These
functions can remove taintedness from the symbols which are passed at
the specified arguments to the filters.

Differential Revision: https://reviews.llvm.org/D59516
2019-11-23 20:12:15 +01:00
Artem Dergachev a3b22da4e0 [CFG] Fix a flaky crash in CFGBlock::getLastCondition().
Using an end iterator of an empty CFG block was causing
a garbage pointer dereference.

Differential Revision: https://reviews.llvm.org/D69962
2019-11-21 21:55:58 -08: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
Artem Dergachev 6bbca3411b [CFG] Add a test for a flaky crash in CFGBlock::getLastCondition().
Push the test separately ahead of time in order to find out whether
our Memory Sanitizer bots will be able to find the problem.

If not, I'll add a much more expensive test that repeats the current
test multiple times in order to show up on normal buildbots.
I really apologize for the potential temporary inconvenience!
I'll commit the fix as soon as I get the signal.

Differential Revision: https://reviews.llvm.org/D69962
2019-11-21 18:11:15 -08:00
Adam Balogh 23022b9329 [Analyzer][NFC] Separate white-box tests for iterator modelling from iterator checker tests
The recently committed debug.IteratorDebugging checker enables
standalone white-box testing of the modelling of containers and
iterators. For the three checkers based on iterator modelling only
simple tests are needed.

Differential Revision: https://reviews.llvm.org/D70123
2019-11-14 16:32:19 +01:00
Dávid Bolvanský 5c50109bb5 Fixed more -Wreturn-type tests 2019-11-09 18:13:51 +01:00
Dávid Bolvanský 1da13237a4 [Diagnostics] Try to improve warning message for -Wreturn-type
Summary: I agree with https://easyaspi314.github.io/gcc-vs-clang.html?fbclid=IwAR1VA0qxiWVUusOQUv5z7JESS7ZpeJy-UqAI5mnJscofGLqXcqeErIUB2gU, current warning message is not very good. We should try to improve it..

Reviewers: rsmith, aaron.ballman, easyaspi314

Reviewed By: aaron.ballman

Subscribers: arphaman, Quuxplusone, mehdi_amini, hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D69762
2019-11-09 17:54:58 +01:00
Artem Dergachev e4da37e8a0 [analyzer] Fix skipping the call during inlined defensive check suppression.
When bugreporter::trackExpressionValue() is invoked on a DeclRefExpr,
it tries to do most of its computations over the node in which
this DeclRefExpr is computed, rather than on the error node (or whatever node
is stuffed into it). One reason why we can't simply use the error node is
that the binding to that variable might have already disappeared from the state
by the time the bug is found.

In case of the inlined defensive checks visitor, the DeclRefExpr node
is in fact sometimes too *early*: the call in which the inlined defensive check
has happened might have not been entered yet.

Change the visitor to be fine with tracking dead symbols (which it is totally
capable of - the collapse point for the symbol is still well-defined), and fire
it up directly on the error node. Keep using "LVState" to find out which value
should we be tracking, so that there weren't any problems with accidentally
loading an ill-formed value from a dead variable.

Differential Revision: https://reviews.llvm.org/D67932
2019-11-08 18:27:14 -08:00
Artem Dergachev 57adc37fe5 [analyzer] Nullability: Don't infer nullable when passing as nullable parameter.
You can't really infer anything from that.
2019-11-08 18:27:14 -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
Adam Balogh 0f88caeef8 [Analyzer] Checker for Debugging Iterator Checkers
For white-box testing correct container and iterator modelling it is essential
to access the internal data structures stored for container and iterators. This
patch introduces a simple debug checkers called debug.IteratorDebugging to
achieve this.

Differential Revision: https://reviews.llvm.org/D67156
2019-11-08 08:59:50 +01:00
Artem Dergachev 5e0fb64842 [analyzer] Add test cases for the unsupported C++ constructor modeling.
Namely, for the following items:
- Handle constructors within new[];
- Handle constructors for default arguments.

Update the open projects page with a link to the newly added tests
and more hints for potential contributors.

Patch by Daniel Krupp!

Differential Revision: https://reviews.llvm.org/D69308
2019-11-07 17:15:53 -08:00
Artem Dergachev acac540422 [analyzer] PR41729: CStringChecker: Improve strlcat and strlcpy modeling.
- Fix false positive reports of strlcat.
- The return value of strlcat and strlcpy is now correctly calculated.
- The resulting string length of strlcat and strlcpy is now correctly
  calculated.

Patch by Daniel Krupp!

Differential Revision: https://reviews.llvm.org/D66049
2019-11-07 17:15:53 -08:00
Volodymyr Sapsai 39573daa76 Revert "[analyzer] Add test directory for scan-build."
This reverts commit 0aba69eb1a with
subsequent changes to test files.

It caused test failures on GreenDragon, e.g.,
http://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-incremental/
2019-11-05 14:03:36 -08:00
Devin Coughlin abc04ff401 [analyzer] Require darwin for scan-build tests
Let's at least get some coverage from these tests. We can generalize to
other platforms later.
2019-11-04 21:17:55 -08:00
Devin Coughlin 48223d92a9 [analyzer] Fixup scan-build tests for non-Darwin platforms.
This is a fix to 0aba69eb1a to
address failing bots.
2019-11-04 21:12:11 -08:00
Devin Coughlin 0aba69eb1a [analyzer] Add test directory for scan-build.
The static analyzer's scan-build script is critical infrastructure but
is not well tested. To start to address this, add a new test directory under
tests/Analysis for scan-build lit tests and seed it with several tests. The
goal is that future scan-build changes will be accompanied by corresponding
tests.

Differential Revision: https://reviews.llvm.org/D69781
2019-11-04 20:26:35 -08:00
Balázs Kéri 4980c1333f [clang][analyzer] Using CallDescription in StreamChecker.
Summary:
Recognization of function names is done now with the CallDescription
class instead of using IdentifierInfo. This means function name and
argument count is compared too.
A new check for filtering not global-C-functions was added.
Test was updated.

Reviewers: Szelethus, NoQ, baloghadamsoftware, Charusso

Reviewed By: Szelethus, NoQ, Charusso

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

Tags: #clang

Differential Revision: https://reviews.llvm.org/D67706
2019-10-31 12:38:50 +01:00
Artem Dergachev be86fdb86e [analyzer] Fix off-by-one in operator call parameter binding.
Member operator declarations and member operator expressions
have different numbering of parameters and arguments respectively:
one of them includes "this", the other does not.

Account for this inconsistency when figuring out whether
the parameter needs to be manually rebound from the Environment
to the Store when entering a stack frame of an operator call,
as opposed to being constructed with a constructor and as such
already having the necessary Store bindings.

Differential Revision: https://reviews.llvm.org/D69155
2019-10-23 08:17:02 -07:00
Artem Dergachev 4a5df7312e [analyzer] PR43551: Do not dereferce void* in UndefOrNullArgVisitor.
Patch by Kristóf Umann!

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

llvm-svn: 375329
2019-10-19 01:50:46 +00:00
Artem Dergachev ab2cec8b85 [analyzer] Fix a crash on tracking Objective-C 'self' as a control dependency.
'self' was previously never tracked, but now it can be tracked
because it may be part of a condition.

llvm-svn: 375328
2019-10-19 01:50:43 +00:00
Artem Dergachev b0914e7276 [analyzer] Specify the C++ standard in more tests.
Makes life easier for downstream developers with different default standard.

llvm-svn: 375308
2019-10-19 00:08:17 +00:00
Artem Dergachev 3ff26e27d9 [analyzer] exploded-graph-rewriter: Unforget to censor stmt_ids in the test.
They're not stable across machines.

Fixes buildbots after r375278.

llvm-svn: 375286
2019-10-18 20:48:21 +00:00
Artem Dergachev c6921379f5 [analyzer] exploded-graph-rewriter: Rename Environment to Expressions.
It's less confusing for newcomers.

llvm-svn: 375282
2019-10-18 20:15:41 +00:00
Artem Dergachev 2b4f6df917 [analyzer] Fix FieldRegion dumps.
The '->' thing has always been confusing; the actual operation '->'
translates to a pointer dereference together with adding a FieldRegion,
but FieldRegion on its own doesn't imply an additional pointer
dereference.

llvm-svn: 375281
2019-10-18 20:15:39 +00:00
Artem Dergachev b3e34e043c [analyzer] Drop the logic for collapsing the state if it's same as in preds.
One of the first attempts to reduce the size of the exploded graph dumps
was to skip the state dump as long as the state is the same as in all of
the predecessor nodes. With all the new facilities in place (node joining,
diff dumps), this feature doesn't do much, and when it does,
it's more harmful than useful. Let's remove it.

llvm-svn: 375280
2019-10-18 20:15:35 +00:00
Artem Dergachev d93b810cd6 [analyzer] exploded-graph-rewriter: Fix dump for state 0.
It shouldn't say "unspecified" when the state is specified to be empty.

llvm-svn: 375279
2019-10-18 20:15:32 +00:00
Artem Dergachev 7a17f19709 [analyzer] Fix hidden node traversal in exploded graph dumps.
The joined nodes now actually have the same state. That was intended
from the start but the original implementation turned out to be buggy.

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

llvm-svn: 375278
2019-10-18 20:15:29 +00:00
Artem Dergachev 8b3ef1e45b [analyzer] exploded-graph-rewriter: Fix typo in r375186. Unbreaks tests.
llvm-svn: 375189
2019-10-17 23:27:35 +00:00
Artem Dergachev 14e9eb3d7c [analyzer] Assign truly stable identifiers to exploded nodes.
ExplodedGraph nodes will now have a numeric identifier stored in them
which will keep track of the order in which the nodes were created
and it will be fully deterministic both accross runs and across machines.

This is extremely useful for debugging as it allows reliably setting
conditional breakpoints by node IDs.

llvm-svn: 375186
2019-10-17 23:10:09 +00:00
Artem Dergachev d325196f19 [analyzer] Display cast kinds in program point dumps.
Because cast expressions have their own hierarchy, it's extremely useful
to have some information about what kind of casts are we dealing with.

llvm-svn: 375185
2019-10-17 23:10:05 +00:00
Artem Dergachev 73b67f0b1a [analyzer] exploded-graph-rewriter: Make node headers a bit lighter.
The 50% grey color is too dark on some monitors.

llvm-svn: 375184
2019-10-17 23:10:02 +00:00
Alexey Bataev 9c5d76ff4d [OPENMP]Dow not emit warnings for uninitialized loop counters.
In OpenMP constructs all counters are initialized and we should not emit
warnings about uninitialized privatized loop control variables.

llvm-svn: 375167
2019-10-17 20:35:08 +00:00
Jan Korous c5d14b5c6f [clang-scan-deps] Support for clang --analyze in clang-scan-deps
The goal is to have 100% fidelity in clang-scan-deps behavior when
--analyze is present in compilation command.

At the same time I don't want to break clang-tidy which expects
__static_analyzer__ macro defined as built-in.

I introduce new cc1 options (-setup-static-analyzer) that controls
the macro definition and is conditionally set in driver.

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

llvm-svn: 374815
2019-10-14 20:15:01 +00:00
Erich Keane 5c2c60d2fc Teach CallGraph to look into Generic Lambdas.
CallGraph visited LambdaExpr by getting the Call Operator from
CXXRecordDecl (LambdaExpr::getCallOperator calls
CXXRecordDecl::getLambdaCallOperator), which replaced generic lambda
call operators with the non-instantiated FunctionDecl.  The result was
that the CallGraph would only pick up non-dependent calls.

This patch does a few things:
1- Extend CXXRecordDecl to have a getDependentLambdaCallOperator, which
will get the FunctionTemplateDecl, rather than immediately getting the
TemplateDecl.
2- Define getLambdaCallOperator and getDependentLambdaCallOperator in
terms of a common function.
3- Extend LambdaExpr with a getDependentCallOperator, which just calls
the above function.
4- Changes CallGraph to handle Generic LambdaExprs.

llvm-svn: 373247
2019-09-30 19:12:29 +00:00
Jan Korous b26e9e2a8f Revert "[static analyzer] Define __clang_analyzer__ macro in driver"
This reverts commit fbd13570b0.

llvm-svn: 372687
2019-09-24 03:21:22 +00:00
Jan Korous 5199aa88fe Revert "[static analyzer][test] Test directly that driver sets D__clang_analyzer__"
This reverts commit c7541903d7.

llvm-svn: 372685
2019-09-24 03:19:20 +00:00
Jan Korous c7541903d7 [static analyzer][test] Test directly that driver sets D__clang_analyzer__
Follow-up to fbd13570b0

llvm-svn: 372683
2019-09-24 02:06:59 +00:00
Jan Korous fbd13570b0 [static analyzer] Define __clang_analyzer__ macro in driver
Differential Revision: https://reviews.llvm.org/D67938

llvm-svn: 372679
2019-09-24 00:33:47 +00:00
Richard Trieu 4c05de8c1d Merge and improve code that detects same value in comparisons.
-Wtautological-overlap-compare and self-comparison from -Wtautological-compare
relay on detecting the same operand in different locations.  Previously, each
warning had it's own operand checker.  Now, both are merged together into
one function that each can call.  The function also now looks through member
access and array accesses.

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

llvm-svn: 372453
2019-09-21 03:02:26 +00:00
Richard Trieu 6541c7988b Improve -Wtautological-overlap-compare
Allow this warning to detect a larger number of constant values, including
negative numbers, and handle non-int types better.

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

llvm-svn: 372448
2019-09-21 02:37:10 +00:00
Kristof Umann b8ac93c73b [analyzer] PR43102: Fix an assertion and an out-of-bounds error for diagnostic location construction
Summary:
https://bugs.llvm.org/show_bug.cgi?id=43102

In today's edition of "Is this any better now that it isn't crashing?", I'd like to show you a very interesting test case with loop widening.

Looking at the included test case, it's immediately obvious that this is not only a false positive, but also a very bad bug report in general. We can see how the analyzer mistakenly invalidated `b`, instead of its pointee, resulting in it reporting a null pointer dereference error. Not only that, the point at which this change of value is noted at is at the loop, rather then at the method call.

It turns out that `FindLastStoreVisitor` works correctly, rather the supplied explodedgraph is faulty, because `BlockEdge` really is the `ProgramPoint` where this happens.
{F9855739}
So it's fair to say that this needs improving on multiple fronts. In any case, at least the crash is gone.

Full ExplodedGraph: {F9855743}

Reviewers: NoQ, xazax.hun, baloghadamsoftware, Charusso, dcoughlin, rnkovacs, TWeaver

Subscribers: JesperAntonsson, uabelho, Ka-Ka, bjope, whisperity, szepet, a.sidorin, mikhail.ramalho, donat.nagy, dkrupp, gamesh411, cfe-commits

Tags: #clang

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

llvm-svn: 372269
2019-09-18 22:24:26 +00:00
Artem Dergachev 851e95c1c1 [analyzer] Fix the 'analyzer-enabled-checkers.c' test on non-linux machines.
'-Xclang -triple' doesn't seem to override the default target triple
as reliably as '--target'. This leads to test failing due to
platform-specific checks getting unexpectedly enabled.

llvm-svn: 371781
2019-09-12 22:11:15 +00:00
Kristof Umann d977b67ed6 [analyzer] Don't run the analyzer for -analyzer-list-enabled-checkers
Short and sweet. Whenever I use -analyzer-list-enabled-checkers, I'm only
interested about the configuration, not about the analysis.

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

llvm-svn: 371756
2019-09-12 18:53:48 +00:00
Reid Kleckner 38e033bf33 Re-land Remove REQUIRES:shell from tests that pass for me on Windows
This reverts r371497 (git commit 3d7e9ab7b9)

Reorder `not` with `env` in these two tests so they pass:
  Driver/rewrite-map-in-diagnostics.c
  Index/crash-recovery-modules.m.

This will not be necessary after D66531 lands.

llvm-svn: 371552
2019-09-10 20:15:45 +00:00
James Henderson 3d7e9ab7b9 Revert Remove REQUIRES:shell from tests that pass for me on Windows
This reverts r371478 (git commit a9980f60ce)

llvm-svn: 371497
2019-09-10 08:48:33 +00:00
Reid Kleckner a9980f60ce Remove REQUIRES:shell from tests that pass for me on Windows
I see in the history for some of these tests REQUIRES:shell was used as
a way to disable tests on Windows because they are flaky there. I tried
not to re-enable such tests, but it's possible that I missed some and
this will re-enable flaky tests on Windows. If so, we should disable
them with UNSUPPORTED:system-windows and add a comment that they are
flaky there. So far as I can tell, the lit internal shell is capable of
running all of these tests, and we shouldn't use REQUIRES:shell as a
proxy for Windows.

llvm-svn: 371478
2019-09-10 00:50:32 +00:00
Gabor Borsik 080ecafdd8 Move prop-sink branch to monorepo.
llvm-svn: 371342
2019-09-08 19:23:43 +00:00
Artem Dergachev 6cee434ed1 [analyzer] Add minimal support for fix-it hints.
Allow attaching fixit hints to Static Analyzer BugReports.

Fixits are attached either to the bug report itself or to its notes
(path-sensitive event notes or path-insensitive extra notes).

Add support for fixits in text output (including the default text output that
goes without notes, as long as the fixit "belongs" to the warning).

Add support for fixits in the plist output mode.

Implement a fixit for the path-insensitive DeadStores checker. Only dead
initialization warning is currently covered.

Implement a fixit for the path-sensitive VirtualCall checker when the virtual
method is not pure virtual (in this case the "fix" is to suppress the warning
by qualifying the call).

Both fixits are under an off-by-default flag for now, because they
require more careful testing.

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

llvm-svn: 371257
2019-09-06 20:55:29 +00:00
Artem Dergachev 2b1b4cab96 [analyzer] pr43179: Make CallDescription defensive against C variadic functions.
Most functions that our checkers react upon are not C-style variadic functions,
and therefore they have as many actual arguments as they have formal parameters.

However, it's not impossible to define a variadic function with the same name.
This will crash any checker that relies on CallDescription to check the number
of arguments but silently assumes that the number of parameters is the same.

Change CallDescription to check both the number of arguments and the number of
parameters by default.

If we're intentionally trying to match variadic functions, allow specifying
arguments and parameters separately (possibly omitting any of them).
For now we only have one CallDescription which would make use of those,
namely __builtin_va_start itself.

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

llvm-svn: 371256
2019-09-06 20:55:24 +00: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
Kristof Umann 3b18b050b8 [analyzer] Add a checker option to detect nested dead stores
Enables the users to specify an optional flag which would warn for more dead
stores.
Previously it ignored if the dead store happened e.g. in an if condition.

if ((X = generate())) { // dead store to X
}

This patch introduces the `WarnForDeadNestedAssignments` option to the checker,
which is `false` by default - so this change would not affect any previous
users.
I have updated the code, tests and the docs as well. If I missed something, tell
me.

I also ran the analysis on Clang which generated 14 more reports compared to the
unmodified version. All of them seemed reasonable for me.

Related previous patches:
rGf224820b45c6847b91071da8d7ade59f373b96f3

Reviewers: NoQ, krememek, Szelethus, baloghadamsoftware

Reviewed By: Szelethus

Patch by Balázs Benics!

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

llvm-svn: 370767
2019-09-03 15:22:43 +00:00
Richard Smith 5030928d60 [c++20] Implement semantic restrictions for C++20 designated
initializers.

This has some interesting interactions with our existing extensions to
support C99 designated initializers as an extension in C++. Those are
resolved as follows:

 * We continue to permit the full breadth of C99 designated initializers
   in C++, with the exception that we disallow a partial overwrite of an
   initializer with a non-trivially-destructible type. (Full overwrite
   is OK, because we won't run the first initializer at all.)

 * The C99 extensions are disallowed in SFINAE contexts and during
   overload resolution, where they could change the meaning of valid
   programs.

 * C++20 disallows reordering of initializers. We only check for that for
   the simple cases that the C++20 rules permit (designators of the form
   '.field_name =' and continue to allow reordering in other cases).
   It would be nice to improve this behavior in future.

 * All C99 designated initializer extensions produce a warning by
   default in C++20 mode. People are going to learn the C++ rules based
   on what Clang diagnoses, so it's important we diagnose these properly
   by default.

 * In C++ <= 17, we apply the C++20 rules rather than the C99 rules, and
   so still diagnose C99 extensions as described above. We continue to
   accept designated C++20-compatible initializers in C++ <= 17 silently
   by default (but naturally still reject under -pedantic-errors).

This is not a complete implementation of P0329R4. In particular, that
paper introduces new non-C99-compatible syntax { .field { init } }, and
we do not support that yet.

This is based on a previous patch by Don Hinton, though I've made
substantial changes when addressing the above interactions.

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

llvm-svn: 370544
2019-08-30 22:52:55 +00:00
Artem Dergachev e5c0994ddf [CFG] Fix CFG for statement-expressions in return values.
We're building the CFG from bottom to top, so when the return-value expression
has a non-trivial CFG on its own, we need to continue building from the entry
to the return-value expression CFG rather than from the block to which
we've just appended the return statement.

Fixes a false positive warning "control may reach end of non-void function".

llvm-svn: 370406
2019-08-29 20:37:28 +00:00
Adam Balogh 12f5c7f0c3 [Analyzer] Iterator Checkers - Make range errors and invalidated access fatal
Range errors (dereferencing or incrementing the past-the-end iterator or
decrementing the iterator of the first element of the range) and access of
invalidated iterators lead to undefined behavior. There is no point to
continue the analysis after such an error on the same execution path, but
terminate it by a sink node (fatal error). This also improves the
performance and helps avoiding double reports (e.g. in case of nested
iterators).

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

llvm-svn: 370314
2019-08-29 09:35:47 +00:00
Artem Dergachev ead98ea3eb [CFG] Make representation of destructor calls more accurate.
Respect C++17 copy elision; previously it would generate destructor calls
for elided temporaries, including in initialization and return statements.

Don't generate duplicate destructor calls for statement expressions.

Fix destructors in initialization lists and comma operators.

Improve printing of implicit destructors.

Patch by Nicholas Allegra!

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

llvm-svn: 370247
2019-08-28 18:44:42 +00:00
Artem Dergachev 630f7daf80 [analyzer] Fix analyzer warnings on analyzer.
Write tests for the actual crash that was found. Write comments and refactor
code around 17 style bugs and suppress 3 false positives.

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

llvm-svn: 370246
2019-08-28 18:44:38 +00:00
Artem Dergachev 0909a392f3 [analyzer] pr43036: Fix support for operator 'sizeof...'.
It was known to be a compile-time constant so it wasn't evaluated during
symbolic execution, but it wasn't evaluated as a compile-time constant either.

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

llvm-svn: 370245
2019-08-28 18:44:35 +00:00
Artem Dergachev 8b2a39e937 [analyzer] Trust global initializers when analyzing main().
If the global variable has an initializer, we'll ignore it because we're usually
not analyzing the program from the beginning, which means that the global
variable may have changed before we start our analysis.

However when we're analyzing main() as the top-level function, we can rely
on global initializers to still be valid. At least in C; in C++ we have global
constructors that can still break this logic.

This patch allows the Static Analyzer to load constant initializers from
global variables if the top-level function of the current analysis is main().

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

llvm-svn: 370244
2019-08-28 18:44:32 +00:00
Alexey Bataev 94a170f811 [OPENMP][Analysis] Add analysis of the map clauses.
Summary:
Added basic analysis of map clauses. Only map clauses with to and tofrom
map type must be analyzed since all other map types (alloc, delete, etc.) do not require to use the value of the initial variable, instead they create the new copy of the variable.

Reviewers: NoQ

Subscribers: guansong, cfe-commits, kkwli0, caomhin

Tags: #clang

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

llvm-svn: 370214
2019-08-28 14:55:08 +00:00
Joe Ranieri fce4324f92 Update the SARIF exporter to SARIF 2.1
This updates the SARIF exporter to produce SARIF 2.1 output. The bulk of the diffs come from two changes to SARIF:
* https://github.com/oasis-tcs/sarif-spec/issues/309
* https://github.com/oasis-tcs/sarif-spec/issues/179

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

llvm-svn: 370068
2019-08-27 14:43:54 +00:00
Joe Ranieri 3385c5cc4d Fix a SARIF exporter crash with macro expansions
Differential Revision: https://reviews.llvm.org/D65209

llvm-svn: 370061
2019-08-27 14:20:27 +00:00
Joe Ranieri 68a6a28ef8 Fix text range end columns in SARIF to be exclusive
According to the SARIF specification, "a text region does not include the character specified by endColumn".

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

llvm-svn: 370060
2019-08-27 13:49:45 +00:00
Gabor Marton f035b75d8f [ASTImporter] Fix name conflict handling with different strategies
There are numorous flaws about the name conflict handling, this patch
attempts fixes them. Changes in details:

* HandleNameConflict return with a false DeclarationName

Hitherto we effectively never returned with a NameConflict error, even
if the preceding StructuralMatch indicated a conflict.
Because we just simply returned with the parameter `Name` in
HandleNameConflict and that name is almost always `true` when converted to
`bool`.

* Add tests which indicate wrong NameConflict handling

* Add to ConflictingDecls only if decl kind is different

Note, we might not indicate an ODR error when there is an existing record decl
and a enum is imported with same name.  But there are other cases. E.g. think
about the case when we import a FunctionTemplateDecl with name f and we found a
simple FunctionDecl with name f. They overload.  Or in case of a
ClassTemplateDecl and CXXRecordDecl, the CXXRecordDecl could be the 'templated'
class, so it would be false to report error.  So I think we should report a
name conflict error only when we are 100% sure of that.  That is why I think it
should be a general pattern to report the error only if the kind is the same.

* Fix failing ctu test with EnumConstandDecl

In ctu-main.c we have the enum class 'A' which brings in the enum
constant 'x' with value 0 into the global namespace.
In ctu-other.c we had the enum class 'B' which brought in the same name
('x') as an enum constant but with a different enum value (42). This is clearly
an ODR violation in the global namespace. The solution was to rename the
second enum constant.

 * Introduce ODR handling strategies

Reviewers: a_sidorin, shafik

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

llvm-svn: 370045
2019-08-27 11:36:10 +00:00
Kristof Umann 09ce8ec78a [analyzer] Avoid unnecessary enum range check on LValueToRValue casts
Summary: EnumCastOutOfRangeChecker should not perform enum range checks on LValueToRValue casts, since this type of cast does not actually change the underlying type.   Performing the unnecessary check actually triggered an assertion failure deeper in EnumCastOutOfRange for certain input (which is captured in the accompanying test code).

Reviewers: #clang, Szelethus, gamesh411, NoQ

Reviewed By: Szelethus, gamesh411, NoQ

Subscribers: NoQ, gamesh411, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, donat.nagy, dkrupp, Charusso, bjope, cfe-commits

Tags: #clang

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

llvm-svn: 369760
2019-08-23 14:21:13 +00:00
Artem Dergachev 85f7294e5a [analyzer] CastValueChecker: Correctly model results of based-to-derived casts.
Our SVal hierarchy doesn't allow modeling pointer casts as no-op. The
pointer type is instead encoded into the pointer object. Defer to our
usual pointer casting facility, SValBuilder::evalBinOp().

Fixes a crash.

llvm-svn: 369729
2019-08-23 03:24:04 +00:00
Artem Dergachev 62a76d0ae3 [analyzer] CastValueChecker: Provide DynamicTypeMap with pointer types only.
The idea to drop this requirement is good, but for now every other user
of DynamicTypeInfo expects pointer types.

Fixes a crash.

llvm-svn: 369728
2019-08-23 03:24:01 +00:00
Artem Dergachev af992e6d01 [analyzer] CastValueChecker: Avoid modeling casts between objects.
Our method only works correctly when casting a pointer to a pointer
or a reference to a reference.

Fixes a crash.

llvm-svn: 369727
2019-08-23 03:23:58 +00:00
Artem Dergachev 0900b77db2 [analyzer] DynamicTypeInfo: Avoid putting null regions into dynamic typemap.
Fixes a crash.

llvm-svn: 369726
2019-08-23 03:23:55 +00:00
Kristof Umann 0f9e530c0f [analyzer] Enable control dependency condition tracking by default
This patch concludes my GSoC'19 project by enabling track-conditions by default.

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

llvm-svn: 369616
2019-08-22 03:08:48 +00:00
Csaba Dabis 4d71600c11 [analyzer] CastValueChecker: Model isa(), isa_and_nonnull()
Summary: -

Reviewed By: NoQ

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

llvm-svn: 369615
2019-08-22 02:57:59 +00:00
Kristof Umann 58eb033a49 [analyzer] Don't track the condition of foreach loops
As discussed on the mailing list, notes originating from the tracking of foreach
loop conditions are always meaningless.

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

llvm-svn: 369613
2019-08-22 02:44:19 +00:00
Csaba Dabis 0202c3596c [analyzer] CastValueChecker: Store the dynamic types and casts
Summary:
This patch introduces `DynamicCastInfo` similar to `DynamicTypeInfo` which
is stored in `CastSets` which are storing the dynamic cast informations of
objects based on memory regions. It could be used to store and check the
casts and prevent infeasible paths.

Reviewed By: NoQ

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

llvm-svn: 369605
2019-08-22 00:20:36 +00:00
Csaba Dabis b73a5711f6 [analyzer] TrackConstraintBRVisitor: Do not track unknown values
Summary: -

Reviewers: NoQ, Szelethus

Reviewed By: NoQ, Szelethus

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

llvm-svn: 369604
2019-08-22 00:06:58 +00:00
Kristof Umann d9a81ccf05 [analyzer] Mention whether an event is about a condition in a bug report part 2
In D65724, I do a pretty thorough explanation about how I'm solving this
problem, I think that summary nails whats happening here ;)

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

llvm-svn: 369596
2019-08-21 22:38:00 +00:00
Kristof Umann 49ac7ece16 [analyzer] Don't make ConditionBRVisitor events prunable when the condition is an interesting field
Exactly what it says on the tin! Note that we're talking about interestingness
in general, hence this isn't a control-dependency-tracking specific patch.

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

llvm-svn: 369589
2019-08-21 21:59:22 +00:00
Kristof Umann da648ab8de [analyzer] Mention whether an event is about a condition in a bug report part 1
Can't add much more to the title! This is part 1, the case where the collapse
point isn't in the condition point is the responsibility of ConditionBRVisitor,
which I'm addressing in part 2.

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

llvm-svn: 369574
2019-08-21 20:43:27 +00:00
Artem Dergachev 8eb7a74b78 [analyzer] Fix a crash when destroying a non-region.
Add defensive check that prevents a crash when we try to evaluate a destructor
whose this-value is a concrete integer that isn't a null.

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

llvm-svn: 369450
2019-08-20 21:41:17 +00:00
Artem Dergachev d3971fe97b [analyzer] Improve VirtualCallChecker and enable parts of it by default.
Calling a pure virtual method during construction or destruction
is undefined behavior. It's worth it to warn about it by default.
That part is now known as the cplusplus.PureVirtualCall checker.

Calling a normal virtual method during construction or destruction
may be fine, but does behave unexpectedly, as it skips virtual dispatch.
Do not warn about this by default, but let projects opt in into it
by enabling the optin.cplusplus.VirtualCall checker manually.

Give the two parts differentiated warning text:

  Before:

    Call to virtual function during construction or destruction:
    Call to pure virtual function during construction

    Call to virtual function during construction or destruction:
    Call to virtual function during destruction

  After:

    Pure virtual method call:
    Call to pure virtual method 'X::foo' during construction
        has undefined behavior

    Unexpected loss of virtual dispatch:
    Call to virtual method 'Y::bar' during construction
        bypasses virtual dispatch

Also fix checker names in consumers that support them (eg., clang-tidy)
because we now have different checker names for pure virtual calls and
regular virtual calls.

Also fix capitalization in the bug category.

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

llvm-svn: 369449
2019-08-20 21:41:14 +00:00
Artem Dergachev 8cf3dfea54 [CallGraph] Take into accound calls that aren't within any function bodies.
This patch improves Clang call graph analysis by adding in expressions
that are not found in regular function bodies, such as default arguments
or member initializers.

Patch by Joshua Cranmer!

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

llvm-svn: 369321
2019-08-20 02:22:37 +00:00
Kristof Umann 032e1fdcd4 [analyzer] Turn an assert into an if condition
Shocker, turns out that terminator conditions that are binary operators
aren't always logical operators.

llvm-svn: 369195
2019-08-17 16:49:54 +00:00
Balazs Keri e13e836480 [ASTImporter] Import ctor initializers after setting flags.
Summary:
Code to import "ctor initializers" at import of functions
is moved to be after the flags in the newly created function
are imported. This fixes an error when the already created but
incomplete (flags are not set) function declaration is accessed.

Reviewers: martong, shafik, a_sidorin, a.sidorin

Reviewed By: shafik

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

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

llvm-svn: 369098
2019-08-16 12:10:03 +00:00
Csaba Dabis a079a42708 [analyzer] Analysis: Silence checkers
Summary:
This patch introduces a new `analyzer-config` configuration:
`-analyzer-config silence-checkers`
which could be used to silence the given checkers.

It accepts a semicolon separated list, packed into quotation marks, e.g:
`-analyzer-config silence-checkers="core.DivideZero;core.NullDereference"`

It could be used to "disable" core checkers, so they model the analysis as
before, just if some of them are too noisy it prevents to emit reports.

This patch also adds support for that new option to the scan-build.
Passing the option `-disable-checker core.DivideZero` to the scan-build
will be transferred to `-analyzer-config silence-checkers=core.DivideZero`.

Reviewed By: NoQ, Szelethus

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

llvm-svn: 369078
2019-08-16 01:53:14 +00:00
Kristof Umann 571c52af58 [analyzer][NFC] Prove that we only track the evaluated part of the condition
...because we're working with a BugReporterVisitor, and the non-evaluated part
of the condition isn't in the bugpath.

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

llvm-svn: 368853
2019-08-14 13:51:52 +00:00
Kristof Umann dd53bdbfde [analyzer][CFG] Don't track the condition of asserts
Well, what is says on the tin I guess!

Some more changes:

* Move isInevitablySinking() from BugReporter.cpp to CFGBlock's interface
* Rename and move findBlockForNode() from BugReporter.cpp to
ExplodedNode::getCFGBlock()

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

llvm-svn: 368836
2019-08-14 12:20:08 +00:00
Balazs Keri c509594319 [ASTImporter] Import default expression of param before creating the param.
Summary:
The default expression of a parameter variable should be imported before
the parameter variable object is created. Otherwise the function is created
with an incomplete parameter variable (default argument is nullptr) and in
this intermediary state the expression is imported. This import can have
a reference to the incomplete parameter variable that causes crash.

Reviewers: martong, a.sidorin, shafik

Reviewed By: martong

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

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

llvm-svn: 368818
2019-08-14 09:41:39 +00:00
Kristof Umann 967583bc08 [analyzer] Note last writes to a condition only in a nested stackframe
Exactly what it says on the tin! The comments in the code detail this a
little more too.

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

llvm-svn: 368817
2019-08-14 09:39:38 +00:00
Kristof Umann 0df9c8c578 [analyzer] Track the right hand side of the last store regardless of its value
Summary:
The following code snippet taken from D64271#1572188 has an issue: namely,
because `flag`'s value isn't undef or a concrete int, it isn't being tracked.

int flag;
bool coin();

void foo() {
  flag = coin();
}

void test() {
  int *x = 0;
  int local_flag;
  flag = 1;

  foo();
  local_flag = flag;
  if (local_flag)
    x = new int;

  foo();
  local_flag = flag;
  if (local_flag)
    *x = 5;
}

This, in my opinion, makes no sense, other values may be interesting too.
Originally added by rC185608.

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

llvm-svn: 368773
2019-08-13 23:48:10 +00:00
Kristof Umann 46929df723 [analyzer] Prune calls to functions with linear CFGs that return a non-zero constrained value
During the evaluation of D62883, I noticed a bunch of totally
meaningless notes with the pattern of "Calling 'A'" -> "Returning value"
-> "Returning from 'A'", which added no value to the report at all.

This patch (not only affecting tracked conditions mind you) prunes
diagnostic messages to functions that return a value not constrained to
be 0, and are also linear.

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

llvm-svn: 368771
2019-08-13 23:22:33 +00:00
Artem Dergachev daf41722bd [analyzer] exploded-graph-rewriter: Implement displaying Store pointers.
They're useful when trying to understand what's going on
inside your LazyCompoundValues.

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

llvm-svn: 368769
2019-08-13 23:04:56 +00:00
Artem Dergachev 9289681ea3 [analyzer] exploded-graph-rewriter: Implement manual graph trimming.
When -trim-egraph is unavailable (say, when you're debugging a crash on
a real-world code that takes too long to reduce), it makes sense to view
the untrimmed graph up to the crashing node's predecessor, then dump the ID
(or a pointer) of the node in the attached debugger, and then trim
the dumped graph in order to keep only paths from the root to the node.

The newly added --to flag does exactly that:

$ exploded-graph-rewriter.py ExprEngine.dot --to 0x12229acd0

Multiple nodes can be specified. Stable IDs of nodes can be used
instead of pointers.

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

llvm-svn: 368768
2019-08-13 23:04:53 +00:00
Artem Dergachev 0b26891f3f [analyzer] exploded-graph-rewriter: NFC: Refactor explorers into trimmers.
Explorers aren't the right abstraction. For the purposes of displaying svg files
we don't care in which order do we explore the nodes. We may care about this for
other analyses, but we're not there yet.

The function of cutting out chunks of the graph is performed poorly by
the explorers, because querying predecessors/successors on the explored nodes
yields original successors/predecessors even if they aren't being explored.

Introduce a new entity, "trimmers", that do one thing but to it right: cut out
chunks of the graph. Trimmers mutate the graph, so stale edges aren't even
visible to their consumers in the pipeline. Additionally, trimmers are
intrinsically composable: multiple trimmers can be applied to the graph
sequentially.

Refactor the single-path explorer into the single-path trimmer.
Rename the test file for consistency.

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

llvm-svn: 368767
2019-08-13 23:04:50 +00:00
Artem Dergachev e9e3635453 [analyzer] exploded-graph-rewriter: Open the converted graph immediately.
Change the default behavior: the tool no longer dumps the rewritten .dot file
to stdout, but instead it automatically converts it into an .html file
(which essentially wraps an .svg file) and immediately opens it with
the default web browser.

This means that the tool should now be fairly easy to use:

  $ exploded-graph-rewriter.py /tmp/ExprEngine.dot

The benefits of wrapping the .svg file into an .html file are:

    - It'll open in a web browser, which is the intended behavior.
      An .svg file would be open with an image viewer/editor instead.
    - It avoids the white background around the otherwise dark svg area
      in dark mode.

The feature can be turned off by passing a flag '--rewrite-only'.
The LIT substitution is updated to enforce the old mode because
we don't want web browsers opening on our buildbots.

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

llvm-svn: 368766
2019-08-13 23:04:47 +00:00
Artem Dergachev f5a60e590f [analyzer] Disable the checker-plugins test on Darwin.
Fixes a buildbot.

llvm-svn: 368765
2019-08-13 23:04:44 +00:00
Gabor Horvath c1dafd7b53 More warnings regarding gsl::Pointer and gsl::Owner attributes
Differential Revision: https://reviews.llvm.org/D65120

llvm-svn: 368446
2019-08-09 15:16:35 +00:00
Csaba Dabis cf229d5752 [analyzer] CastValueChecker: Model castAs(), getAs()
Summary: Thanks to Kristóf Umann for the great idea!

Reviewed By: NoQ

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

llvm-svn: 368383
2019-08-09 02:24:42 +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
Alexey Bataev 195ae90307 [OPENMP]Add support for analysis of linear variables and step.
Summary:
Added support for basic analysis of the linear variables and linear step
expression. Linear loop iteration variables must be excluded from this
analysis, only non-loop iteration variables must be analyzed.

Reviewers: NoQ

Subscribers: guansong, cfe-commits, caomhin, kkwli0

Tags: #clang

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

llvm-svn: 368295
2019-08-08 13:42:45 +00:00
Balazs Keri 4e79097dc7 [CrossTU] Handle case when no USR could be generated during Decl search.
Summary:
When searching for a declaration to be loaded the "lookup name" for every
other Decl is computed. If the USR can not be determined here should be
not an assert, instead skip this Decl.

Reviewers: martong

Reviewed By: martong

Subscribers: rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

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

llvm-svn: 368020
2019-08-06 12:10:16 +00:00
Adam Balogh 8557f17d88 [Analyzer] Iterator Checkers - Fix for Crash on Iterator Differences
Iterators differences were mistakenly handled as random decrements which
causes an assertion. This patch fixes this.

llvm-svn: 367802
2019-08-05 06:45:41 +00:00
Csaba Dabis 7740c6d643 [analyzer] StackFrameContext: Add NodeBuilderContext::blockCount() to its profile
Summary:
It allows discriminating between stack frames of the same call that is
called multiple times in a loop.

Thanks to Artem Dergachev for the great idea!

Reviewed By: NoQ

Tags: #clang

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

llvm-svn: 367608
2019-08-01 20:41:13 +00:00
Nico Weber 5c2d5f066f Rename two clang tests from .cc to .cpp.
clang/test/lit.cfg.py doesn't list .cc as test extension, so these
tests never ran.

Tweak one of the two tests to actually pass, now that it runs.
(The other one was already passing.)

llvm-svn: 367574
2019-08-01 15:06:57 +00:00
Johannes Doerfert 3be25e7947 [Fix] Customize warnings for missing built-in types
If we detect a built-in declaration for which we cannot derive a type
matching the pattern in the Builtins.def file, we currently emit a
warning that the respective header is needed. However, this is not
necessarily the behavior we want as it has no connection to the location
of the declaration (which can actually be in the header in question).
Instead, this warning is generated
  - if we could not build the type for the pattern on file (for some
    reason). Here we should make the reason explicit. The actual problem
    is otherwise circumvented as the warning is misleading, see [0] for
    an example.
  - if we could not build the type for the pattern because we do not
    have a type on record, possible since D55483, we should not emit any
    warning. See [1] for a legitimate problem.

This patch address both cases. For the "setjmp" family a new warning is
introduced and for built-ins without type on record, so far
"pthread_create", we do not emit the warning anymore.

Also see: PR40692

[0] https://lkml.org/lkml/2019/1/11/718
[1] https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=235583

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

llvm-svn: 367387
2019-07-31 05:16:38 +00:00
Reid Kleckner 2336c1b872 Fix taint-generic.c on Windows, handle case in OS error
llvm-svn: 367249
2019-07-29 18:48:50 +00:00
Gabor Borsik 4bde15fe1e [analyzer] Add yaml parser to GenericTaintChecker
While we implemented taint propagation rules for several
builtin/standard functions, there's a natural desire for users to add
such rules to custom functions.

A series of patches will implement an option that allows users to
annotate their functions with taint propagation rules through a YAML
file. This one adds parsing of the configuration file, which may be
specified in the commands line with the analyzer config:
alpha.security.taint.TaintPropagation:Config. The configuration may
contain propagation rules, filter functions (remove taint) and sink
functions (give a warning if it gets a tainted value).

I also added a new header for future checkers to conveniently read YAML
files as checker options.

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

llvm-svn: 367190
2019-07-28 13:38:04 +00:00
Alexey Bataev 8a8c69808c [OPENMP]Add support for analysis of reduction variables.
Summary:
Reduction variables are the variables, for which the private copies
must be created in the OpenMP regions. Then they are initialized with
the predefined values depending on the reduction operation. After exit
from the OpenMP region the original variable is updated using the
reduction value and the value of the original reduction variable.

Reviewers: NoQ

Subscribers: guansong, jdoerfert, caomhin, kkwli0, cfe-commits

Tags: #clang

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

llvm-svn: 367116
2019-07-26 14:50:05 +00:00
Balazs Keri f34da181d2 Fix failing test plist-macros-with-expansion-ctu.c
llvm-svn: 367013
2019-07-25 12:46:42 +00:00
Balazs Keri aeac909329 [CrossTU] Fix plist macro expansion if macro in other file.
Summary:
When cross TU analysis is used it is possible that a macro expansion
is generated for a macro that is defined (and used) in other than
the main translation unit. To get the expansion for it the source
location in the original source file and original preprocessor
is needed.

Reviewers: martong, xazax.hun, Szelethus, ilya-biryukov

Reviewed By: Szelethus

Subscribers: mgorny, NoQ, ilya-biryukov, rnkovacs, dkrupp, Szelethus, gamesh411, cfe-commits

Tags: #clang

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

llvm-svn: 367006
2019-07-25 10:53:22 +00:00
Alexey Bataev 25569296c6 [OPENMP]Add support for analysis of firstprivate variables.
Summary:
Firstprivate variables are the variables, for which the private copies
must be created in the OpenMP regions and must be initialized with the
original values. Thus, we must report if the uninitialized variable is
used as firstprivate.

Reviewers: NoQ

Subscribers: guansong, jdoerfert, caomhin, kkwli0, cfe-commits

Tags: #clang

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

llvm-svn: 366689
2019-07-22 13:51:07 +00:00
Csaba Dabis 68983321cc [analyzer] MallocChecker: Prevent Integer Set Library false positives
Summary:
Integer Set Library using retain-count based allocation which is not
modeled in MallocChecker.

Reviewed By: NoQ

Tags: #clang

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

llvm-svn: 366391
2019-07-18 00:03:55 +00:00
Alexey Bataev 48f5a43bcc [OPENMP]Fix PR42632: crash on the analysis of the OpenMP constructs.
Fixed processing of the CapturedStmt children to fix the crash of the
OpenMP constructs during analysis.

llvm-svn: 366357
2019-07-17 18:03:39 +00:00
Alexey Bataev 655cb4a2d7 [OPENMP]Add support for analysis of if clauses.
Summary:
Added support for analysis of if clauses in the OpenMP directives to be
able to check for the use of uninitialized variables.

Reviewers: NoQ

Subscribers: guansong, jfb, jdoerfert, caomhin, kkwli0, cfe-commits

Tags: clang

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

llvm-svn: 366211
2019-07-16 14:51:46 +00:00
Ali Tamur e7e8789a63 Revert "[OPENMP]Add support for analysis of if clauses."
This reverts commit rL366068.
The patch broke 86 tests under clang/test/OpenMP/ when run with address sanitizer.

llvm-svn: 366169
2019-07-16 03:20:15 +00:00
Alexey Bataev 63d00b19e5 [OPENMP]Add support for analysis of if clauses.
Summary:
Added support for analysis of if clauses in the OpenMP directives to be
able to check for the use of uninitialized variables.

Reviewers: NoQ

Subscribers: guansong, jfb, jdoerfert, caomhin, kkwli0, cfe-commits

Tags: #clang

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

llvm-svn: 366068
2019-07-15 14:46:23 +00:00
Artem Dergachev 8bd441af8b NFC: Unforget a colon in a few CHECK: directives.
Differential Revision: https://reviews.llvm.org/D64526

llvm-svn: 365863
2019-07-12 02:16:56 +00:00
Artem Dergachev ed035ff826 [analyzer] exploded-graph-rewriter: Improve source location dumps.
- Correctly display macro expansion and spelling locations.
- Use the same procedure to display location context call site locations.
- Display statement IDs for program points.

llvm-svn: 365861
2019-07-12 02:10:33 +00:00
Artem Dergachev fc6059e8b9 [analyzer] exploded-graph-rewriter: Fix filenames in program point.
Fix a typo in JSON field name.

llvm-svn: 365827
2019-07-11 21:27:42 +00:00
Alexey Bataev c2c21ef9d2 [OPENMP]Initial fix PR42392: Improve -Wuninitialized warnings for OpenMP programs.
Summary:
Some OpenMP clauses rely on the values of the variables. If the variable
is not initialized and used in OpenMP clauses that depend on the
variables values, it should be reported that the uninitialized variable
is used in the OpenMP clause expression.
This patch adds initial processing for uninitialized variables in OpenMP
constructs. Currently, it checks for use of the uninitialized variables
in the structured blocks.

Reviewers: NoQ, Szelethus, dcoughlin, xazax.hun, a.sidorin, george.karpenkov, szepet

Subscribers: rnkovacs, guansong, jfb, jdoerfert, cfe-commits

Tags: #clang

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

llvm-svn: 365786
2019-07-11 14:54:17 +00:00
Csaba Dabis 693936ab8f [analyzer] CastValueChecker: Model casts
Summary:
It models the LLVM casts:
- `cast<>`
- `dyn_cast<>`
- `cast_or_null<>`
- `dyn_cast_or_null<>`

It has a very basic support without checking the `classof()` function.

(It reapplies the reverted 'llvm-svn: 365582' patch with proper test file.)

Reviewed By: NoQ

Tags: #clang

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

llvm-svn: 365585
2019-07-10 00:20:03 +00:00
Csaba Dabis 6a29680efb Revert "[analyzer] CastValueChecker: Model casts"
This reverts commit 27cf666443.

llvm-svn: 365584
2019-07-09 23:47:09 +00:00
Csaba Dabis 27cf666443 [analyzer] CastValueChecker: Model casts
Summary:
It models the LLVM casts:
- `cast<>`
- `dyn_cast<>`
- `cast_or_null<>`
- `dyn_cast_or_null<>`

It has a very basic support without checking the `classof()` function.

Reviewed By: NoQ

Tags: #clang

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

llvm-svn: 365582
2019-07-09 23:33:23 +00:00
Artem Dergachev c6b5c5b925 [analyzer] exploded-graph-rewriter: Implement a topology-only mode.
In this mode the rewriter will only rewrite program points
and omit program states. Useful for understanding
the rough topology of the graph.

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

llvm-svn: 365410
2019-07-08 23:54:14 +00:00
Artem Dergachev 78566e454f [analyzer] exploded-graph-rewriter: Implement a single-path mode.
Instead of rewriting the whole graph, rewrite the leftmost path in the
graph. Useful for trimmed graphs that are still too large to display due
to multiple equivalent reports mixed into them.

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

llvm-svn: 365409
2019-07-08 23:54:11 +00:00
Endre Fulop 0752d12c09 [analyzer] Add analyzer option to limit the number of imported TUs
Summary:
During CTU analysis of complex projects, the loaded AST-contents of
imported TUs can grow bigger than available system memory. This option
introduces a threshold on the number of TUs to be imported for a single
TU in order to prevent such cases.

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

llvm-svn: 365314
2019-07-08 12:37:10 +00:00
Kristof Umann b55745606f [analyzer] Add a debug analyzer config to place an event for each tracked condition
Differential Revision: https://reviews.llvm.org/D63642

llvm-svn: 365208
2019-07-05 14:00:08 +00:00
Kristof Umann 258e5e457a [analyzer] Track terminator conditions on which a tracked expression depends
This patch is a major part of my GSoC project, aimed to improve the bug
reports of the analyzer.

TL;DR: Help the analyzer understand that some conditions are important,
and should be explained better. If an CFGBlock is a control dependency
of a block where an expression value is tracked, explain the condition
expression better by tracking it.

if (A) // let's explain why we believe A to be true
  10 / x; // division by zero

This is an experimental feature, and can be enabled by the
off-by-default analyzer configuration "track-conditions".

In detail:

This idea was inspired by the program slicing algorithm. Essentially,
two things are used to produce a program slice (a subset of the program
relevant to a (statement, variable) pair): data and control
dependencies. The bug path (the linear path in the ExplodedGraph that leads
from the beginning of the analysis to the error node) enables to
analyzer to argue about data dependencies with relative ease.

Control dependencies are a different slice of the cake entirely.

Just because we reached a branch during symbolic execution, it
doesn't mean that that particular branch has any effect on whether the
bug would've occured. This means that we can't simply rely on the bug
path to gather control dependencies.

In previous patches, LLVM's IDFCalculator, which works on a control flow
graph rather than the ExplodedGraph was generalized to solve this issue.
We use this information to heuristically guess that the value of a tracked
expression depends greatly on it's control dependencies, and start
tracking them as well.

After plenty of evaluations this was seen as great idea, but still
lacking refinements (we should have different descriptions about a
conditions value), hence it's off-by-default.

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

llvm-svn: 365207
2019-07-05 13:29:54 +00:00
Kristof Umann 5e17ee1e35 [analyzer][IDF] Add a control dependency calculator + a new debug checker
I intend to improve the analyzer's bug reports by tracking condition
expressions.

01 bool b = messyComputation();
02 int i = 0;
03 if (b) // control dependency of the bug site, let's explain why we assume val
04        // to be true
05   10 / i; // warn: division by zero

I'll detail this heuristic in the followup patch, strictly related to this one
however:

* Create the new ControlDependencyCalculator class that uses llvm::IDFCalculator
  to (lazily) calculate control dependencies for Clang's CFG.
* A new debug checker debug.DumpControlDependencies is added for lit tests
* Add unittests

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

llvm-svn: 365197
2019-07-05 12:17:44 +00:00
Gabor Marton e712295f11 [CTU] Add support for virtual functions
Reviewers: Szelethus, xazax.hun

Subscribers: rnkovacs, dkrupp, gamesh411, cfe-commits

Tags: #clang

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

llvm-svn: 365133
2019-07-04 11:39:00 +00:00
Csaba Dabis 57835bcfbd [analyzer] ReturnValueChecker: Model the guaranteed boolean return value of function calls
Summary: It models the known LLVM methods paired with their class.

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: dschuff, aheejin, mgorny, szepet, rnkovacs, a.sidorin,
             mikhail.ramalho, donat.nagy, dkrupp, cfe-commits

Tags: #clang

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

llvm-svn: 365103
2019-07-04 00:50:50 +00:00
Artem Dergachev 78c0aefb22 [analyzer] exploded-graph-rewriter: Implement a black-and-white color scheme.
For accessibility!

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

llvm-svn: 365085
2019-07-03 20:48:23 +00:00
Kristof Umann 71a9dc39e4 [analyzer][Dominator] Add post dominators to CFG + a new debug checker
Transform clang::DominatorTree to be able to also calculate post dominators.

* Tidy up the documentation
* Make it clang::DominatorTree template class (similarly to how
  llvm::DominatorTreeBase works), rename it to clang::CFGDominatorTreeImpl
* Clang's dominator tree is now called clang::CFGDomTree
* Clang's brand new post dominator tree is called clang::CFGPostDomTree
* Add a lot of asserts to the dump() function
* Create a new checker to test the functionality

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

llvm-svn: 365028
2019-07-03 11:39:12 +00:00
Kristof Umann 85211c0835 [Dominators] PR42041: Skip nullpointer successors
https://bugs.llvm.org/show_bug.cgi?id=42041

In Clang's CFG, we use nullpointers to represent unreachable nodes, for
example, in the included testfile, block B0 is unreachable from block
B1, resulting in a nullpointer dereference somewhere in
llvm::DominatorTreeBase<clang::CFGBlock, false>::recalculate.

This patch fixes this issue by specializing
llvm::DomTreeBuilder::SemiNCAInfo::ChildrenGetter::Get for
clang::CFG to not contain nullpointer successors.

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

llvm-svn: 365026
2019-07-03 11:14:42 +00:00
Artem Dergachev ab758ba128 [analyzer] exploded-graph-rewriter: Implement bug nodes and sink nodes.
Add a label to nodes that have a bug report attached or on which
the analysis was generally interrupted.

Fix printing has_report and implement printing is_sink in the graph dumper.

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

llvm-svn: 364992
2019-07-03 01:26:41 +00:00
Artem Dergachev 48a5c83af4 [analyzer] exploded-graph-rewriter: Collapse very long statement pretty-prints.
When printing various statements that include braces (compound
statements, lambda expressions, statement-expressions, etc.),
replace the code between braces with '...'.

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

llvm-svn: 364990
2019-07-03 01:26:35 +00:00
Artem Dergachev deb7accbea [analyzer] exploded-graph-rewriter: Implement checker messages.
They are displayed as raw lines and diffed via difflib on a per-checker basis.

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

llvm-svn: 364989
2019-07-03 01:26:32 +00:00
Artem Dergachev ad38e58ef2 [analyzer] exploded-graph-rewriter: Implement a dark color scheme.
Addresses a popular request. Activated via --dark.

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

llvm-svn: 364882
2019-07-02 02:17:56 +00:00
Artem Dergachev 2ca5355712 [analyzer] exploded-graph-rewriter: Improve program point dumps.
- Take advantage of the stmt_point_kind.
- Dump block IDs for BlockEntrance nodes.
- Don't dump huge compound statements on PurgeDeadSymbols nodes.
- Rename Edge to BlockEdge for consistency.
- Tweak colors.

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

llvm-svn: 364881
2019-07-02 02:17:53 +00:00
Artem Dergachev 0a77d9192a [analyzer] exploded-graph-rewriter: Add support for objects under construction.
This trait is Environment-like, so there was a chance to re-use a lot of code.

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

llvm-svn: 364880
2019-07-02 02:17:50 +00:00
Nathan Huckleberry 121401425d [analyzer] Support kfree in MallocChecker
Summary:
kmalloc is freed with kfree in the linux kernel. kmalloc support was
added in r204832, but kfree was not. Adding kfree fixes incorrectly
detected memory leaks.

Reviewers: NoQ, nickdesaulniers, dcoughlin, Szelethus

Reviewed By: NoQ, Szelethus

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

Tags: #clang

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

llvm-svn: 364875
2019-07-01 23:29:10 +00:00
Artem Dergachev dbad95d390 [analyzer] exploded-graph-rewriter: NFC: Add a forgotten test file.
This fell off of r364865.

llvm-svn: 364871
2019-07-01 23:06:08 +00:00
Artem Dergachev ceb639dbee [analyzer] Fix invalidation when returning into a ctor initializer.
Due to RVO the target region of a function that returns an object by
value isn't necessarily a temporary object region; it may be an
arbitrary memory region. In particular, it may be a field of a bigger
object.

Make sure we don't invalidate the bigger object when said function is
evaluated conservatively.

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

llvm-svn: 364870
2019-07-01 23:02:18 +00:00
Artem Dergachev 512f4838c4 [analyzer] NonnullGlobalConstants: Don't be confused by a _Nonnull attribute.
The NonnullGlobalConstants checker models the rule "it doesn't make sense
to make a constant global pointer and initialize it to null"; it makes sure
that whatever it's initialized with is known to be non-null.

Ironically, annotating the type of the pointer as _Nonnull breaks the checker.

Fix handling of the _Nonnull annotation so that it was instead one more reason
to believe that the value is non-null.

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

llvm-svn: 364869
2019-07-01 23:02:14 +00:00
Artem Dergachev 35fdec1b54 [analyzer] CStringChecker: Modernize to use CallDescriptions.
This patch uses the new CDF_MaybeBuiltin flag to handle C library functions.
It's mostly an NFC/refactoring pass, but it does fix a bug in handling memset()
when it expands to __builtin___memset_chk() because the latter has
one more argument and memset() handling code was trying to match
the exact number of arguments. Now the code is deduplicated and there's
less room for mistakes.

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

llvm-svn: 364868
2019-07-01 23:02:10 +00:00
Artem Dergachev 02f91ddf1b [analyzer] exploded-graph-rewriter: Add support for dynamic types.
Slightly cleanup emission of horizontal lines and unhardcode the title
for generic maps.

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

llvm-svn: 364865
2019-07-01 23:01:59 +00:00
Artem Dergachev 5a72338bf5 [analyzer] exploded-graph-rewriter: Implement program point tags.
Keep them on a separate line for more visibility.

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

llvm-svn: 364864
2019-07-01 23:01:55 +00:00
Nathan Huckleberry 13fde7a89a [analyzer] Fix clang-tidy crash on GCCAsmStmt
Summary:
Added entry in switch statement to recognize GCCAsmStmt
as a possible block terminator.

Handling to build CFG using GCCAsmStmt was already implemented.

Reviewers: nickdesaulniers, george.karpenkov, NoQ

Reviewed By: nickdesaulniers, NoQ

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

Tags: #clang

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

llvm-svn: 364605
2019-06-27 22:46:40 +00:00
Artem Dergachev 628f36ff70 [analyzer] exploded-graph-rewriter: Prettier location context dumps.
Make them span wider.

llvm-svn: 364365
2019-06-26 00:14:49 +00:00
Csaba Dabis 0cdd13c05a [analyzer] print() JSONify: Create pointers
Summary: -

Reviewers: NoQ

Reviewed By: NoQ

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

Tags: #clang

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

llvm-svn: 364271
2019-06-25 03:17:55 +00:00
Csaba Dabis c55170c031 [analyzer] JsonSupport: Escape escapes
Summary: -

Reviewers: NoQ

Reviewed By: NoQ

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

Tags: #clang

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

llvm-svn: 364270
2019-06-25 03:08:32 +00:00
Artem Dergachev 14f4de9bb9 [analyzer] exploded-graph-rewriter: Fix escaping for bitwise-or.
'|' is a special character in graphviz, so it needs to be properly
escaped and unescaped.

llvm-svn: 364269
2019-06-25 02:16:56 +00:00
Artem Dergachev beb85ad66d [analyzer] exploded-graph-rewriter: Add support for range constraints.
Diff support included.

A cheap solution is implemented that treats range constraints as
"some sort of key-value map", so it's going to be trivial
to add support for other such maps later, such as dynamic type info.

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

llvm-svn: 364268
2019-06-25 02:16:53 +00:00
Richard Smith 7939ba08ab [cxx2a] P1236R1: the validity of a left shift does not depend on the
value of the LHS operand.

llvm-svn: 364265
2019-06-25 01:45:26 +00:00
Csaba Dabis 49885b1245 [analyzer] ExprEngine: Escape pointers in bitwise operations
Summary:
After evaluation it would be an Unknown value and tracking would be lost.

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
             dkrupp, cfe-commits

Tags: #clang

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

llvm-svn: 364259
2019-06-25 00:44:33 +00:00
Csaba Dabis 3a4a60eb6a [analyzer] print() JSONify: ProgramPoint revision
Summary: Now we also print out the filename with its path.

Reviewers: NoQ

Reviewed By: NoQ

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

Tags: #clang

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

llvm-svn: 364197
2019-06-24 16:19:39 +00:00
Csaba Dabis 906d494b6e [analyzer] Fix JSON dumps for ExplodedNodes
Summary:
- Now we could see the `has_report` property in `trim-egraph` mode.
- This patch also removes the trailing comma after each node.

Reviewers: NoQ

Reviewed By: NoQ

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

Tags: #clang

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

llvm-svn: 364193
2019-06-24 16:06:44 +00:00
Artem Dergachev 5c287f751a [analyzer] DeadStores: Update the crude suppression for files generated by IIG.
They changed the comments that we were looking for.

llvm-svn: 363995
2019-06-20 22:29:40 +00:00
David Zarzycki f237c7d411 [Testing] Dumping the graph requires assertions be enabled
llvm-svn: 363916
2019-06-20 09:58:58 +00:00
Artem Dergachev 5740e77f03 [analyzer] exploded-graph-rewriter: Implement a --diff mode.
In this mode the tool would avoid duplicating the contents of the
program state on every node, replacing them with a diff-like dump
of changes that happened on that node.

This is useful because most of the time we only interested in whether
the effect of the statement was modeled correctly. A diffed graph would
also be much faster to load and navigate, being much smaller than
the original graph.

The diffs are computed "semantically" as opposed to plain text diffs.
I.e., the diff algorithm is hand-crafted separately for every state trait,
taking the underlying data structures into account. This is especially nice
for Environment because textual diffs would have been terrible.
On the other hand, it requires some boilerplate to implement.

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

llvm-svn: 363898
2019-06-19 23:33:59 +00:00
Artem Dergachev b50d167358 [analyzer] exploded-graph-rewriter: Fix escaping StringRegions.
Quotes around StringRegions are now escaped and unescaped correctly,
producing valid JSON.

Additionally, add a forgotten escape for Store values.

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

llvm-svn: 363897
2019-06-19 23:33:55 +00:00
Artem Dergachev 064c8c689a [analyzer] Fix JSON dumps for store clusters.
Include a unique pointer so that it was possible to figure out if it's
the same cluster in different program states. This allows comparing
dumps of different states against each other.

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

llvm-svn: 363896
2019-06-19 23:33:51 +00:00
Artem Dergachev f9f6cdb1a8 [analyzer] Fix JSON dumps for location contexts.
Location context ID is a property of the location context, not of an item
within it. It's useful to know the id even when there are no items
in the context, eg. for the purposes of figuring out how did contents
of the Environment for the same location context changed across states.

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

llvm-svn: 363895
2019-06-19 23:33:48 +00:00
Artem Dergachev 3bb7b2ec7f [analyzer] Fix JSON dumps for dynamic type information.
They're now valid JSON.

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

llvm-svn: 363894
2019-06-19 23:33:45 +00:00
Artem Dergachev 3707b05211 [analyzer] DeadStores: Add a crude suppression files generated by DriverKit IIG.
IIG is a replacement for MIG in DriverKit: IIG is autogenerating C++ code.
Suppress dead store warnings on such code, as the tool seems to be producing
them regularly, and the users of IIG are not in position to address these
warnings, as they don't control the autogenerated code. IIG-generated code
is identified by looking at the comments at the top of the file.

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

llvm-svn: 363892
2019-06-19 23:33:39 +00:00
Artem Dergachev b03854f8e8 [analyzer] RetainCount: Add support for OSRequiredCast().
It's a new API for custom RTTI in Apple IOKit/DriverKit framework that is
similar to OSDynamicCast() that's already supported, but crashes instead of
returning null (and therefore causing UB when the cast fails unexpectedly).
Kind of like cast_or_null<> as opposed to dyn_cast_or_null<> in LLVM's RTTI.

Historically, RetainCountChecker was responsible for modeling OSDynamicCast.
This is simply an extension of the same functionality.

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

llvm-svn: 363891
2019-06-19 23:33:34 +00:00
Hubert Tong 64b60df99f [analyzer] SARIF: Add EOF newline; replace diff_sarif
Summary:
This patch applies a change similar to rC363069, but for SARIF files.

The `%diff_sarif` lit substitution invokes `diff` with a non-portable
`-I` option. The intended effect can be achieved by normalizing the
inputs to `diff` beforehand. Such normalization can be done with
`grep -Ev`, which is also used by other tests.

Additionally, this patch updates the SARIF output to have a newline at
the end of the file. This makes it so that the SARIF file qualifies as a
POSIX text file, which increases the consumability of the generated file
in relation to various tools.

Reviewers: NoQ, sfertile, xingxue, jasonliu, daltenty, aaron.ballman

Reviewed By: aaron.ballman

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

Tags: #clang

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

llvm-svn: 363822
2019-06-19 15:27:35 +00:00
Hubert Tong 122bd782d6 [analyzer][NFC][tests] Pre-normalize expected-sarif files
As discussed in the review for D62952, this patch pre-normalizes the
reference expected output sarif files by removing lines containing
fields for which we expect differences that should be ignored.

llvm-svn: 363788
2019-06-19 11:19:51 +00:00
Csaba Dabis 4d4ef2a167 [analyzer] ReturnVisitor: more portable test case
llvm-svn: 363515
2019-06-16 17:29:37 +00:00
Kristof Umann e20b388e2f [analyzer] Push correct version of 'Track indices of arrays'
Messed up the commit, oops.

llvm-svn: 363512
2019-06-16 15:41:25 +00:00
Kristof Umann 33b46a6df0 [analyzer] Track indices of arrays
Often times, when an ArraySubscriptExpr was reported as null or
undefined, the bug report was difficult to understand, because the
analyzer explained why arr[i] has that value, but didn't realize that in
fact i's value is very important as well. This patch fixes this by
tracking the indices of arrays.

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

llvm-svn: 363510
2019-06-16 14:52:56 +00:00
Csaba Dabis 077f13c612 [analyzer] ReturnVisitor: Bypass everything to see inlined calls
Summary:
When we traversed backwards on ExplodedNodes to see where processed the
given statement we `break` too early. With the current approach we do not
miss the CallExitEnd ProgramPoint which stands for an inlined call.

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
             dkrupp, cfe-commits

Tags: #clang

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

llvm-svn: 363491
2019-06-15 10:05:49 +00:00
Richard Smith 27252a1f95 PR23833, DR2140: an lvalue-to-rvalue conversion on a glvalue of type
nullptr_t does not access memory.

We now reuse CK_NullToPointer to represent a conversion from a glvalue
of type nullptr_t to a prvalue of nullptr_t where necessary.

This reinstates r363337, reverted in r363352.

llvm-svn: 363429
2019-06-14 17:46:38 +00:00
Nico Weber 3d02b895ed Revert 363295, it caused PR42276. Also revert follow-ups 363337, 363340.
Revert 363340 "Remove unused SK_LValueToRValue initialization step."
Revert 363337 "PR23833, DR2140: an lvalue-to-rvalue conversion on a glvalue of type"
Revert 363295 "C++ DR712 and others: handle non-odr-use resulting from an lvalue-to-rvalue conversion applied to a member access or similar not-quite-trivial lvalue expression."

llvm-svn: 363352
2019-06-14 04:05:17 +00:00
Richard Smith 0476d069e3 PR23833, DR2140: an lvalue-to-rvalue conversion on a glvalue of type
nullptr_t does not access memory.

We now reuse CK_NullToPointer to represent a conversion from a glvalue
of type nullptr_t to a prvalue of nullptr_t where necessary.

This reinstates r345562, reverted in r346065, now that CodeGen's
handling of non-odr-used variables has been fixed.

llvm-svn: 363337
2019-06-13 23:31:04 +00:00
Hubert Tong 61c848d254 Reapply r362994 & co "[analyzer][tests] Add normalize_plist to replace diff_plist"
Following r363007, which reverted r362998, r362996, and r362994,
reapply with adjustments for the CRLF differences encountered with
Windows. Namely, the `-b` option of `diff` is employed, and the `grep`
patterns have `$` replaced with `[[:space:]]*$`.

llvm-svn: 363069
2019-06-11 14:21:32 +00:00
Reid Kleckner e7ea1834f4 Revert r362994 & co "[analyzer][tests] Add normalize_plist to replace diff_plist"
Reverts r362998, r362996, and r362994 because the tests do not pass on
Windows due to CRLF changes. Adding back `-w` to diff is not enough, the
new grep substitution doesn't work on Windows, and fixing it is
non-trivial.

llvm-svn: 363007
2019-06-10 23:25:43 +00:00
Hubert Tong dbc85509ba [analyzer][tests] Use normalize_plist in place of diff_plist (`tail` cases)
Summary:
The `%diff_plist` lit substitution invokes `diff` with a non-portable
`-I` option. The intended effect can be achieved by normalizing the
inputs to `diff` beforehand. Such normalization can be done with
`grep -Ev`, which is also used by other tests.

This patch applies the change (adjusted for review comments) described
in http://lists.llvm.org/pipermail/cfe-dev/2019-April/061904.html
mechanically to the cases where the output file is piped to
`%diff_plist` via `tail`. `%diff_plist` is then, being unused, removed.

The changes were applied via a script.

Reviewers: NoQ, sfertile, xingxue, jasonliu, daltenty

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

Tags: #clang

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

llvm-svn: 362998
2019-06-10 22:40:35 +00:00
Hubert Tong 65db5d4cb5 [analyzer][tests] Use normalize_plist in place of diff_plist (`cat` cases)
Summary:
The `%diff_plist` lit substitution invokes `diff` with a non-portable
`-I` option. The intended effect can be achieved by normalizing the
inputs to `diff` beforehand. Such normalization can be done with
`grep -Ev`, which is also used by other tests.

This patch applies the change (adjusted for review comments) described
in http://lists.llvm.org/pipermail/cfe-dev/2019-April/061904.html
mechanically to the cases where the output file is piped to
`%diff_plist` via `cat`.

The changes were applied via a script, except that
`clang/test/Analysis/NewDelete-path-notes.cpp` and
`clang/test/Analysis/plist-macros-with-expansion.cpp` were each adjusted
for the line-continuation on the relevant `RUN` step.

Reviewers: NoQ, sfertile, xingxue, jasonliu, daltenty

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

Tags: #clang

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

llvm-svn: 362996
2019-06-10 22:37:31 +00:00
Hubert Tong c867b92217 [analyzer][tests] Add normalize_plist to replace diff_plist
Summary:
The `%diff_plist` lit substitution invokes `diff` with a non-portable
`-I` option. The intended effect can be achieved by normalizing the
inputs to `diff` beforehand. Such normalization can be done with
`grep -Ev`, which is also used by other tests.

This patch applies the change (adjusted for review comments) described
in http://lists.llvm.org/pipermail/cfe-dev/2019-April/061904.html to the
specific case shown in the list message. Mechanical changes to the other
affected files will follow in later patches.

Reviewers: NoQ, sfertile, xingxue, jasonliu, daltenty

Reviewed By: NoQ

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

Tags: #clang

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

llvm-svn: 362994
2019-06-10 22:33:34 +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
Keno Fischer 6f48c07620 [analyzer] Add werror flag for analyzer warnings
Summary:
We're using the clang static analyzer together with a number of
custom analyses in our CI system to ensure that certain invariants
are statiesfied for by the code every commit. Unfortunately, there
currently doesn't seem to be a good way to determine whether any
analyzer warnings were emitted, other than parsing clang's output
(or using scan-build, which then in turn parses clang's output).
As a simpler mechanism, simply add a `-analyzer-werror` flag to CC1
that causes the analyzer to emit its warnings as errors instead.
I briefly tried to have this be `Werror=analyzer` and make it go
through that machinery instead, but that seemed more trouble than
it was worth in terms of conflicting with options to the actual build
and special cases that would be required to circumvent the analyzers
usual attempts to quiet non-analyzer warnings. This is simple and it
works well.

Reviewed-By: NoQ, Szelethusw
Differential Revision: https://reviews.llvm.org/D62885

llvm-svn: 362855
2019-06-07 23:34:00 +00:00
Artem Dergachev 1611cc1cba [analyzer] exploded-graph-rewriter: Pick up python from cmake in tests.
This should fix NetBSD buildbots.

llvm-svn: 362574
2019-06-05 02:09:29 +00:00
Jennifer Yu b8fee677bf Re-check in clang support gun asm goto after fixing tests.
llvm-svn: 362410
2019-06-03 15:57:25 +00:00
Artem Dergachev c3236cd200 Revert "[analyzer] exploded-graph-rewriter: An attempt to fix Windows buildbots."
This reverts commit r362343.

Instead, disable tests on Windows for now.

llvm-svn: 362347
2019-06-03 00:21:00 +00:00
Artem Dergachev 0ac4ab48fc [analyzer] exploded-graph-rewriter: An attempt to fix Windows buildbots.
Breakage caused by r362340.

llvm-svn: 362343
2019-06-02 23:17:56 +00:00
Artem Dergachev 162360774e [analyzer] exploded-graph-rewriter: Initial commit.
This is a utility to improve readability and generally manipulate
GraphViz dumps of the analysis graph. Such dumps are often huge and
not only hard to read, but also often hang the viewer apps with their
mere size. Such script should significantly improve debugging experience.

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

llvm-svn: 362340
2019-06-02 21:40:53 +00:00
Don Hinton ccbda6b000 [test] Fix plugin tests
Recommit of r361790 that was temporarily reverted in r361793 due to bot breakage.

Summary:
The following changes were required to fix these tests:

1) Change LLVM_ENABLE_PLUGINS to an option and move it to
   llvm/CMakeLists.txt with an appropriate default -- which matches
   the original default behavior.

2) Move the plugins directory from clang/test/Analysis
   clang/lib/Analysis.  It's not enough to add an exclude to the
   lit.local.cfg file because add_lit_testsuites recurses the tree and
   automatically adds the appropriate `check-` targets, which don't
   make sense for the plugins because they aren't tests and don't
   have `RUN` statements.

   Here's a list of the `clang-check-anlysis*` targets with this
   change:

```
  $ ninja -t targets all| sed -n "s/.*\/\(check[^:]*\):.*/\1/p" | sort -u | grep clang-analysis
  check-clang-analysis
  check-clang-analysis-checkers
  check-clang-analysis-copypaste
  check-clang-analysis-diagnostics
  check-clang-analysis-engine
  check-clang-analysis-exploration_order
  check-clang-analysis-html_diagnostics
  check-clang-analysis-html_diagnostics-relevant_lines
  check-clang-analysis-inlining
  check-clang-analysis-objc
  check-clang-analysis-unified-sources
  check-clang-analysis-z3
```

3) Simplify the logic and only include the subdirectories under
   clang/lib/Analysis/plugins if LLVM_ENABLE_PLUGINS is set.

Reviewed By: NoQ

Tags: #clang, #llvm

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

llvm-svn: 362328
2019-06-02 15:53:43 +00:00
Richard Smith 2fdd95c1c8 Defer capture initialization for blocks until after we've left the
function scope.

This removes one of the last few cases where we build expressions in the
wrong function scope context. No functionality change intended.

llvm-svn: 362178
2019-05-31 00:45:09 +00:00
Erich Keane d0f34fd198 Revert "clang support gnu asm goto."
This reverts commit 954ec09aed.

Reverting due to test failures as requested by Jennifer Yu.

Conflicts:
	clang/test/CodeGen/asm-goto.c

llvm-svn: 362106
2019-05-30 15:38:02 +00:00
Csaba Dabis 32d545f930 [analyzer] print() JSONify chain: Fix possible build-bot breaks
Summary:
Printing constructing_objects could be non-deterministic as it is a map.

llvm-svn: 362101
2019-05-30 15:15:57 +00:00
Csaba Dabis 17604c3486 [analyzer] print() JSONify chain: Fix build-bot breaks
Summary:
Printing out a map structure different in different environments so that
this patch generalize the test-case to check for the 'no stmt'-case
anywhere in the Store.

llvm-svn: 362098
2019-05-30 14:48:43 +00:00
Jennifer Yu 954ec09aed clang support gnu asm goto.
Syntax:
  asm [volatile] goto ( AssemblerTemplate
                      :
                      : InputOperands
                      : Clobbers
                      : GotoLabels)

https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html

New llvm IR is "callbr" for inline asm goto instead "call" for inline asm
For:
asm goto("testl %0, %0; jne %l1;" :: "r"(cond)::label_true, loop);
IR:
callbr void asm sideeffect "testl $0, $0; jne ${1:l};", "r,X,X,~{dirflag},~{fpsr},~{flags}"(i32 %0, i8* blockaddress(@foo, %label_true), i8* blockaddress(@foo, %loop)) #1
          to label %asm.fallthrough [label %label_true, label %loop], !srcloc !3

asm.fallthrough:                                

Compiler need to generate:
1> a dummy constarint 'X' for each label.
2> an unique fallthrough label for each asm goto stmt " asm.fallthrough%number".


Diagnostic 
1>	duplicate asm operand name are used in output, input and label.
2>	goto out of scope.

llvm-svn: 362045
2019-05-30 01:05:46 +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
Csaba Dabis 1d7ca67769 [analyzer] [NFC] PathDiagnostic: Create PathDiagnosticPopUpPiece
Summary:
This new piece is similar to our macro expansion printing in HTML reports:
On mouse-hover event it pops up on variables. Similar to note pieces it
supports `plist` diagnostics as well.

It is optional, on by default: `add-pop-up-notes=true`.

Extra: In HTML reports `background-color: LemonChiffon` was too light,
changed to `PaleGoldenRod`.

Reviewers: NoQ, alexfh

Reviewed By: NoQ

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

Tags: #clang

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

llvm-svn: 362014
2019-05-29 19:21:59 +00:00
Csaba Dabis ee37e28fd1 [analyzer] print() JSONify chain: Generic stmt_id
Summary: Some environment create less statements so make them generic.
llvm-svn: 362011
2019-05-29 18:58:41 +00:00
Csaba Dabis 13e491cca5 [analyzer] print() JSONify: getNodeLabel implementation
Summary: This patch also rewrites the ProgramPoint printing.

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: cfe-commits, szepet, rnkovacs, a.sidorin, mikhail.ramalho,
             donat.nagy, dkrupp

Tags: #clang

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

llvm-svn: 361997
2019-05-29 18:05:53 +00:00
Csaba Dabis df0a42127c [analyzer] print() JSONify: Program state implementation
Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
             dkrupp

Tags: #clang

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

llvm-svn: 361983
2019-05-29 16:22:21 +00:00
Csaba Dabis b7ca72a113 [analyzer] print() JSONify: Checker messages implementation
Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
             dkrupp

Tags: #clang

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

llvm-svn: 361982
2019-05-29 16:02:33 +00:00
Csaba Dabis 35e54eb31e [analyzer] print() JSONify: Constructing objects implementation
Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
             dkrupp

Tags: #clang

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

llvm-svn: 361980
2019-05-29 15:58:26 +00:00
Csaba Dabis 32981637ce [analyzer] print() JSONify: Type information implementation
Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
             dkrupp

Tags: #clang

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

llvm-svn: 361979
2019-05-29 15:53:12 +00:00
Csaba Dabis 5df5eb8816 [analyzer] print() JSONify: Constraints implementation
Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
             dkrupp

Tags: #clang

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

llvm-svn: 361978
2019-05-29 15:43:26 +00:00
Csaba Dabis 9ce3746604 [analyzer] print() JSONify: Environment implementation
Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
             dkrupp

Tags: #clang

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

llvm-svn: 361976
2019-05-29 15:36:58 +00:00
Csaba Dabis 124cba0b81 [analyzer] print() JSONify: Store implementation
Summary: -

Reviewers: NoQ, xazax.hun, ravikandhadai, baloghadamsoftware, Szelethus

Reviewed By: NoQ

Subscribers: szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy,
             dkrupp

Tags: #clang

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

llvm-svn: 361972
2019-05-29 15:25:19 +00:00
Don Hinton 102b4b2486 Revert [test] Fix plugin tests
This reverts r361790 (git commit fe5eaab2b5)

It's causing buildbot breakage, so reverting while I investigate.

llvm-svn: 361793
2019-05-28 06:38:16 +00:00
Don Hinton fe5eaab2b5 [test] Fix plugin tests
Summary:
The following changes were required to fix these tests:

1) Change LLVM_ENABLE_PLUGINS to an option and move it to
   llvm/CMakeLists.txt with an appropriate default -- which matches
   the original default behavior.

2) Move the plugins directory from clang/test/Analysis
   clang/lib/Analysis.  It's not enough to add an exclude to the
   lit.local.cfg file because add_lit_testsuites recurses the tree and
   automatically adds the appropriate `check-` targets, which don't
   make sense for the plugins because they aren't tests and don't
   have `RUN` statements.

   Here's a list of the `clang-check-anlysis*` targets with this
   change:

```
  $ ninja -t targets all| sed -n "s/.*\/\(check[^:]*\):.*/\1/p" | sort -u | grep clang-analysis
  check-clang-analysis
  check-clang-analysis-checkers
  check-clang-analysis-copypaste
  check-clang-analysis-diagnostics
  check-clang-analysis-engine
  check-clang-analysis-exploration_order
  check-clang-analysis-html_diagnostics
  check-clang-analysis-html_diagnostics-relevant_lines
  check-clang-analysis-inlining
  check-clang-analysis-objc
  check-clang-analysis-unified-sources
  check-clang-analysis-z3
```

3) Simplify the logic and only include the subdirectories under
   clang/lib/Analysis/plugins if LLVM_ENABLE_PLUGINS is set.

Reviewed By: NoQ

Tags: #clang, #llvm

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

llvm-svn: 361790
2019-05-28 06:26:58 +00:00
Akira Hatanaka a846427ad0 Revert "[Analysis] Link library dependencies to Analysis plugins"
This reverts commit r361340. The following builder has been broken for
the past few days because of this commit:

http://green.lab.llvm.org/green/job/clang-stage2-cmake-RgSan/

Also revert r361399, which was committed to fix r361340.

llvm-svn: 361685
2019-05-25 00:50:03 +00:00
Artem Dergachev ef0aab3138 [analyzer] Add a prunable note for skipping vbase inits in subclasses.
When initialization of virtual base classes is skipped, we now tell the user
about it, because this aspect of C++ isn't very well-known.

The implementation is based on the new "note tags" feature (r358781).
In order to make use of it, allow note tags to produce prunable notes,
and move the note tag factory to CoreEngine.

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

llvm-svn: 361682
2019-05-24 23:37:11 +00:00
Artem Dergachev 192a7474d6 [CFG] Add branch to skip vbase inits when they're handled by superclass.
This patch adds the run-time CFG branch that would skip initialization of
virtual base classes depending on whether the constructor is called from a
superclass constructor or not. Previously the Static Analyzer was already
skipping virtual base-class initializers in such constructors, but it wasn't
skipping their arguments and their potential side effects, which was causing
pr41300 (and was generally incorrect). The previous skipping behavior is
now replaced with a hard assertion that we're not even getting there due
to how our CFG works.

The new CFG element is under a CFG build option so that not to break other
consumers of the CFG by this change. Static Analyzer support for this change
is implemented.

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

llvm-svn: 361681
2019-05-24 23:37:08 +00:00
Mandeep Singh Grang 0cdc5dddca [Analyzer] Checker for non-determinism caused by iteration of unordered container of pointers
Summary: Added a checker for non-determinism caused by iterating unordered containers like std::unordered_set containing pointer elements.

Reviewers: NoQ, george.karpenkov, whisperity, Szelethus, baloghadamsoftware

Reviewed By: Szelethus

Subscribers: mgorny, xazax.hun, baloghadamsoftware, szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat.nagy, dkrupp, jdoerfert, Charusso, cfe-commits

Tags: #clang

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

llvm-svn: 361664
2019-05-24 19:24:08 +00:00
Artem Dergachev 425e565783 [analyzer] NFC: Prevent multi-file plist test from spamming up the build folder.
It was producing an HTML report with a random name on every tests run
and never cleaned those up.

llvm-svn: 361592
2019-05-24 02:29:18 +00:00
Artem Dergachev 1293de8b17 [CFG] NFC: Modernize a test file for constructor initializer CFGs.
Move FileCheck directives around so that it was easy to understand
what tests what and what effect do changes have.

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

llvm-svn: 361587
2019-05-24 01:34:26 +00:00
Kristof Umann ac95c86511 [analyzer] List checker/plugin options in 3 categories: released, alpha, developer
Same patch as D62093, but for checker/plugin options, the only
difference being that options for alpha checkers are implicitly marked
as alpha.

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

llvm-svn: 361566
2019-05-23 22:52:09 +00:00
Kristof Umann 7e55ed84d0 [analyzer] Hide developer-only checker/package options by default
These options are now only visible under
-analyzer-checker-option-help-developer.

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

llvm-svn: 361561
2019-05-23 22:07:16 +00:00
Kristof Umann 5bc40d9b18 [analyzer] List checkers in 3 categories: released, alpha, developer
Previously, the only way to display the list of available checkers was
to invoke the analyzer with -analyzer-checker-help frontend flag. This
however wasn't really great from a maintainer standpoint: users came
across checkers meant strictly for development purposes that weren't to
be tinkered with, or those that were still in development. This patch
creates a clearer division in between these categories.

From now on, we'll have 3 flags to display the list checkers. These
lists are mutually exclusive and can be used in any combination (for
example to display both stable and alpha checkers).

-analyzer-checker-help: Displays the list for stable, production ready
                        checkers.

-analyzer-checker-help-alpha: Displays the list for in development
                              checkers. Enabling is discouraged
                              for non-development purposes.

-analyzer-checker-help-developer: Modeling and debug checkers. Modeling
                                  checkers shouldn't be enabled/disabled
                                  by hand, and debug checkers shouldn't
                                  be touched by users.

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

llvm-svn: 361558
2019-05-23 21:46:51 +00:00
Kristof Umann e8df27d925 [analyzer] Add a new frontend flag to display all checker options
Add the new frontend flag -analyzer-checker-option-help to display all
checker/package options.

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

llvm-svn: 361552
2019-05-23 20:47:28 +00:00
Kristof Umann 8cffa84850 [analyzer][NFC] Prettify some RUN: lines in test files.
This is a test commit in disguise.

llvm-svn: 361505
2019-05-23 15:49:04 +00:00
Petr Hosek c87a45d471 [Analysis] Link library dependencies to Analysis plugins
These are needed to avoid undefined symbols which aren't satisfied
by Clang itself.

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

llvm-svn: 361340
2019-05-22 00:47:37 +00:00
Kristof Umann f40c18b628 [analyzer] PR41753: Include complex integer types in NonLoc::isCompoundType
https://bugs.llvm.org/show_bug.cgi?id=41753

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

llvm-svn: 361099
2019-05-18 12:34:08 +00:00
Kristof Umann 83cc1b35d1 [analyzer] Remove the default value arg from getChecker*Option
Since D57922, the config table contains every checker option, and it's default
value, so having it as an argument for getChecker*Option is redundant.

By the time any of the getChecker*Option function is called, we verified the
value in CheckerRegistry (after D57860), so we can confidently assert here, as
any irregularities detected at this point must be a programmer error. However,
in compatibility mode, verification won't happen, so the default value must be
restored.

This implies something else, other than adding removing one more potential point
of failure -- debug.ConfigDumper will always contain valid values for
checker/package options!

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

llvm-svn: 361042
2019-05-17 15:52:13 +00:00
Kristof Umann 85cf76e783 [analyzer] Validate checker option names and values
Validate whether the option exists, and also whether the supplied value is of
the correct type. With this patch, invoking the analyzer should be, at least
in the frontend mode, a lot safer.

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

llvm-svn: 361011
2019-05-17 09:51:59 +00:00
Kristof Umann 30b2307da8 [analyzer] Insert checker options into AnalyzerOption::ConfigTable
The more entries we have in AnalyzerOptions::ConfigTable, the more helpful
debug.ConfigDumper is. With this patch, I'm pretty confident that it'll now emit
the entire state of the analyzer, minus the frontend flags.

It would be nice to reserve the config table specifically to checker options
only, as storing the regular analyzer configs is kinda redundant.

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

llvm-svn: 361006
2019-05-17 09:29:44 +00:00
Petr Hosek b7804ef3a7 [Analysis] Only run plugins tests if plugins are actually enabled
When plugins aren't enabled, don't try to run plugins tests. Don't
enable plugins unconditionally based on the platform, instead check
if LLVM shared library is actually being built which may not be the
case for every host configuration, even if the host itself supports
plugins.

This addresses test failures introduced by r360891/D59464.

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

llvm-svn: 360991
2019-05-17 06:07:37 +00:00
Kristof Umann daa91492dd [analyzer] Add a test plugin for checker option handling
Differential Revision: https://reviews.llvm.org/D59465

llvm-svn: 360910
2019-05-16 15:55:07 +00:00
Kristof Umann 1b93a24c29 Reland "[analyzer] Add an example plugin for checker dependency handling"
Buildbots complained that they couldn't find the newly added plugins.

The solution was to move the check-clang cmake target closer to the bottom of
the file, after the new dependencies are added.

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

llvm-svn: 360891
2019-05-16 13:22:04 +00:00
Kristof Umann 750a45fe25 Revert "[analyzer] Add a test for plugins using checker dependencies"
Buildbots don't seem to find the new plugin.

llvm-svn: 360805
2019-05-15 20:19:51 +00:00
Kristof Umann 47241aaff7 [analyzer] Add a test for plugins using checker dependencies
Also, I moved the existing analyzer plugin to test/ as well, in order not to
give the illusion that the analyzer supports plugins -- it's capable of handling
them, but does not _support_ them.

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

llvm-svn: 360799
2019-05-15 19:47:26 +00:00
Artem Dergachev 07c7257cdc [analyzer] RetainCount: Fix os_returns_retained_on_zero with weird return types.
The checker was crashing when it was trying to assume a structure
to be null or non-null so that to evaluate the effect of the annotation.

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

llvm-svn: 360790
2019-05-15 18:41:32 +00:00
Artem Dergachev 70b654fa9b [analyzer] MIGChecker: Add support for os_ref_retain().
Suppress MIG checker false positives that occur when the programmer increments
the reference count before calling a MIG destructor, and the MIG destructor
literally boils down to decrementing the reference count.

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

llvm-svn: 360737
2019-05-15 01:19:19 +00:00
Artem Dergachev b3fc9df481 [analyzer] Fix a crash when doing RVO from within blocks.
When looking for the location context of the call site, unwrap block invocation
contexts because they are attached to the current AnalysisDeclContext
while what we need is the previous AnalysisDeclContext.

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

llvm-svn: 360202
2019-05-07 22:33:13 +00:00
Kristof Umann aa9d2623a0 [analyzer][UninitializedObjectChecker] PR41741: Regard all scalar types as primitive.
https://bugs.llvm.org/show_bug.cgi?id=41741

Pretty much the same as D61246 and D61106, this time for __complex__ types. Upon
further investigation, I realized that we should regard all types
Type::isScalarType returns true for as primitive, so I merged 
isMemberPointerType(), isBlockPointerType() and isAnyComplexType()` into that
instead.

I also stumbled across yet another bug,
https://bugs.llvm.org/show_bug.cgi?id=41753, but it seems to be unrelated to
this checker.

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

llvm-svn: 359998
2019-05-05 19:42:33 +00:00
Kristof Umann 9f7fc9838a [analyzer] Don't display implementation checkers under -analyzer-checker-help, but do under the new flag -analyzer-checker-help-hidden
During my work on analyzer dependencies, I created a great amount of new
checkers that emitted no diagnostics at all, and were purely modeling some
function or another.

However, the user shouldn't really disable/enable these by hand, hence this
patch, which hides these by default. I intentionally chose not to hide alpha
checkers, because they have a scary enough name, in my opinion, to cause no
surprise when they emit false positives or cause crashes.

The patch introduces the Hidden bit into the TableGen files (you may remember
it before I removed it in D53995), and checkers that are either marked as
hidden, or are in a package that is marked hidden won't be displayed under
-analyzer-checker-help. -analyzer-checker-help-hidden, a new flag meant for
developers only, displays the full list.

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

llvm-svn: 359720
2019-05-01 19:56:47 +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
Hubert Tong 46e0fc88cc [analyzer][tests] Use diff_plist, correct order of arguments for missed cases; NFC
For various files under `clang/test/Analysis`, D52036 applied
`%diff_plist` to replace `diff` invocations with certain options and
D56340 swapped the order of the arguments so that the reference file
comes first. The tests that used `tail` to filter the test output were
not modified accordingly. This patch applies the corresponding update
to those tests.

llvm-svn: 359691
2019-05-01 15:53:56 +00:00
Kristof Umann c21ec00d28 [analyzer][UninitializedObjectChecker] PR41611: Regard vector types as primitive
https://bugs.llvm.org/show_bug.cgi?id=41611

Similarly to D61106, the checker ran over an llvm_unreachable for vector types:

struct VectorSizeLong {
  VectorSizeLong() {}
  __attribute__((__vector_size__(16))) long x;
};

void __vector_size__LongTest() {
  VectorSizeLong v;
}
Since, according to my short research,

"The vector_size attribute is only applicable to integral and float scalars,
although arrays, pointers, and function return values are allowed in conjunction
with this construct."
[src: https://gcc.gnu.org/onlinedocs/gcc-4.6.1/gcc/Vector-Extensions.html#Vector-Extensions]

vector types are safe to regard as primitive.

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

llvm-svn: 359539
2019-04-30 08:47:56 +00:00
Artem Dergachev ab7747b727 [analyzer] Treat functions without run-time branches as "small".
Currently we always inline functions that have no branches, i.e. have exactly
three CFG blocks: ENTRY, some code, EXIT. This makes sense because when there
are no branches, it means that there's no exponential complexity introduced
by inlining such function. Such functions also don't trigger various fundamental
problems with our inlining mechanism, such as the problem of inlined
defensive checks.

Sometimes the CFG may contain more blocks, but in practice it still has
linear structure because all directions (except, at most, one) of all branches
turned out to be unreachable. When this happens, still treat the function
as "small". This is useful, in particular, for dealing with C++17 if constexpr.

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

llvm-svn: 359531
2019-04-30 03:01:02 +00:00
Artem Dergachev eb71c0c961 [analyzer] SmartPtrModeling: Fix a null dereference.
Don't crash when trying to model a call in which the callee is unknown
in compile time, eg. a pointer-to-member call.

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

llvm-svn: 359530
2019-04-30 03:00:57 +00:00
Artem Dergachev 48e7a2fa8c [analyzer] RetainCount: Add a suppression for "the Matching rule".
In the OSObject universe there appears to be another slightly popular contract,
apart from "create" and "get", which is "matching". It optionally consumes
a "table" parameter and if a table is passed, it fills in the table and
returns it at +0; otherwise, it creates a new table, fills it in and
returns it at +1.

For now suppress false positives by doing a conservative escape on all functions
that end with "Matching", which is the naming convention that seems to be
followed by all such methods.

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

llvm-svn: 359264
2019-04-26 02:05:18 +00:00
Artem Dergachev e264ac6ae1 [analyzer] RetainCount: Allow offsets in return values.
Because RetainCountChecker has custom "local" reasoning about escapes,
it has a separate facility to deal with tracked symbols at end of analysis
and check them for leaks regardless of whether they're dead or not.
This facility iterates over the list of tracked symbols and reports
them as leaks, but it needs to treat the return value specially.

Some custom allocators tend to return the value with an offset, storing
extra metadata at the beginning of the buffer. In this case the return value
would be a non-base region. In order to avoid false positives, we still need to
find the original symbol within the return value, otherwise it'll be unable
to match it to the item in the list of tracked symbols.

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

llvm-svn: 359263
2019-04-26 02:05:15 +00:00
Artem Dergachev b591845f4b [analyzer] Fix crash when returning C++ objects from ObjC messages-to-nil.
the assertion is in fact incorrect: there is a cornercase in Objective-C++
in which a C++ object is not constructed with a constructor, but merely
zero-initialized. Namely, this happens when an Objective-C message is sent
to a nil and it is supposed to return a C++ object.

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

llvm-svn: 359262
2019-04-26 02:05:12 +00:00
Artem Dergachev ecefce6a49 [analyzer] Add FIXMEs for alpha.unix.cstring.OutOfBounds false positives.
Caused by incorrect strlcat() modeling in r332303,
cf. https://bugs.llvm.org/show_bug.cgi?id=37687#c8

llvm-svn: 359237
2019-04-25 20:30:14 +00:00
Kristof Umann f46c58e0c6 [analyzer][UninitializedObjectChecker] PR41590: Regard _Atomic types as primitive
https://bugs.llvm.org/show_bug.cgi?id=41590

For the following code snippet, UninitializedObjectChecker crashed:

struct MyAtomicInt {
  _Atomic(int) x;
  MyAtomicInt() {}
};

void entry() {
  MyAtomicInt b;
}

The problem was that _Atomic types were not regular records, unions,
dereferencable or primitive, making the checker hit the llvm_unreachable at
lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp:347.
The solution is to regard these types as primitive as well. The test case shows
that with this addition, not only are we able to get rid of the crash, but we
can identify x as uninitialized.

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

llvm-svn: 359230
2019-04-25 20:00:51 +00:00