Commit Graph

2837 Commits

Author SHA1 Message Date
Alex Lorenz 46103e0ede Fix PR13910: Don't warn that __builtin_unreachable() is unreachable
Differential Revision: https://reviews.llvm.org/D25321

llvm-svn: 299951
2017-04-11 15:36:06 +00:00
Ivan Krasin 1e1acbc95b Fix unused lambda capture. Follow up to r299653.
llvm-svn: 299671
2017-04-06 17:42:05 +00:00
Artem Dergachev da9e718fb4 [analyzer] Reland r299544 "Add a modular constraint system to the CloneDetector"
Hopefully fix crashes by unshadowing the variable.


Original commit message:

A big part of the clone detection code is functionality for filtering clones and
clone groups based on different criteria. So far this filtering process was
hardcoded into the CloneDetector class, which made it hard to understand and,
ultimately, to extend.

This patch splits the CloneDetector's logic into a sequence of reusable
constraints that are used for filtering clone groups. These constraints
can be turned on and off and reodreder at will, and new constraints are easy
to implement if necessary.

Unit tests are added for the new constraint interface.

This is a refactoring patch - no functional change intended.

Patch by Raphael Isemann!

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

llvm-svn: 299653
2017-04-06 14:34:07 +00:00
Artem Dergachev c4aee48b9f Revert "[analyzer] Add a modular constraint system to the CloneDetector"
This reverts commit r299544.

Crashes on tests on some buildbots.

llvm-svn: 299550
2017-04-05 15:06:17 +00:00
Artem Dergachev f8b4fc38fd [analyzer] Add a modular constraint system to the CloneDetector
A big part of the clone detection code is functionality for filtering clones and
clone groups based on different criteria. So far this filtering process was
hardcoded into the CloneDetector class, which made it hard to understand and,
ultimately, to extend.

This patch splits the CloneDetector's logic into a sequence of reusable
constraints that are used for filtering clone groups. These constraints
can be turned on and off and reodreder at will, and new constraints are easy
to implement if necessary.

Unit tests are added for the new constraint interface.

This is a refactoring patch - no functional change intended.

Patch by Raphael Isemann!

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

llvm-svn: 299544
2017-04-05 14:17:36 +00:00
Alex Lorenz 6615f2b3d6 -Wunreachable-code: 'true' and 'false' should not be treated as configuration
macros

Clang should emit -Wunreachable-code warnings in C mode for code that's
unreachable because of a 'false' or '!true' condition.

llvm-svn: 299541
2017-04-05 14:07:21 +00:00
Simon Pilgrim 2c51880a82 Spelling mistakes in comments. NFCI. (PR27635)
llvm-svn: 299083
2017-03-30 14:13:19 +00:00
Adam Nemet 484aa45153 Encapsulate FPOptions and use it consistently
Sema holds the current FPOptions which is adjusted by 'pragma STDC
FP_CONTRACT'.  This then gets propagated into expression nodes as they are
built.

This encapsulates FPOptions so that this propagation happens opaquely rather
than directly with the fp_contractable on/off bit.  This allows controlled
transitioning of fp_contractable to a ternary value (off, on, fast).  It will
also allow adding more fast-math flags later.

This is toward moving fp-contraction=fast from an LLVM TargetOption to a
FastMathFlag in order to fix PR25721.

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

llvm-svn: 298877
2017-03-27 19:17:25 +00:00
Martin Bohme 0c11c29121 [analyzer] Fix crash when building CFG with variable of incomplete type
Summary:
I've included a unit test with a function template containing a variable
of incomplete type. Clang compiles this without errors (the standard
does not require a diagnostic in this case). Without the fix, this case
triggers the crash.

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

llvm-svn: 297129
2017-03-07 08:42:37 +00:00
Benjamin Kramer 357c9e1a4b Make helpers static. NFC.
llvm-svn: 294838
2017-02-11 12:21:17 +00:00
Sylvestre Ledru fccc52aa66 Remove unused 'using' declaration. Found by clang-tidy: misc-unused-using-decls NFC
llvm-svn: 293381
2017-01-28 13:41:50 +00:00
Artem Dergachev 12caf8e1e6 [analyzer] Consider function call arguments while building CallGraph.
Function call can appear in the arguments of another function call, eg.:

  foo(bar());

This patch adds support for such cases.

Patch by Ivan Sidorenko!

Differential revision: https://reviews.llvm.org/D28905

llvm-svn: 293280
2017-01-27 12:14:56 +00:00
Richard Smith 509bbd1a66 PR31631: fix bad CFG (and bogus warnings) when an if-statement has an init-statement and has binary operator as its condition.
llvm-svn: 291964
2017-01-13 22:16:41 +00:00
Alex Lorenz 569ad73d6b Avoid multiple -Wunreachable-code diagnostics that are triggered by
the same source range and use the unary operator fixit only when it
actually silences the warning.

rdar://24570531

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

llvm-svn: 291757
2017-01-12 10:48:03 +00:00
Devin Coughlin aac894feba [analyzer] Fix crash in body farm for getter without implicit self.
Fix a crash in body farm when synthesizing a getter for a property
synthesized for a property declared in a protocol on a class extension
that shadows a declaration of the property in a category.

In this case, Sema doesn't fill in the implicit 'self' parameter for the getter
in the category, which leads to a crash when trying to synthesize the getter
for it.

To avoid the crash, skip getter synthesis in body farm if the self parameter is
not filled int.

rdar://problem/29938138

llvm-svn: 291635
2017-01-11 01:02:34 +00:00
Richard Trieu 6a6af52ba6 Extend -Wtautological-overlap-compare to more cases.
Previously, -Wtautological-overlap-compare did not warn on cases where the
boolean expression was in an assignment or return statement.  This patch
should cause all boolean statements to be passed to the tautological compare
checks in the CFG analysis.

This is one of the issues from PR13101

llvm-svn: 290920
2017-01-04 00:46:30 +00:00
Mehdi Amini ab11d83048 Fix os_log formating with arbitrary precision and field width
llvm-svn: 289761
2016-12-15 04:02:31 +00:00
Haojian Wu 053499841a [StaticAnalysis] Remove unnecessary parameter in CallGraphNode::addCallee.
Summary:
Remove the CallGraph in addCallee as it is not used in addCallee.
It decouples addCallee from CallGraph, so that we can use CallGraphNode
within our customized CallGraph.

Reviewers: bkramer

Subscribers: cfe-commits, ioeric

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

llvm-svn: 289431
2016-12-12 14:12:10 +00:00
Richard Smith b8c0f553ed DR1295 and cleanup for P0135R1: Make our initialization code more directly
mirror the description in the standard. Per DR1295, this means that binding a
const / rvalue reference to a bit-field no longer "binds directly", and per
P0135R1, this means that we materialize a temporary in reference binding
after adjusting cv-qualifiers and before performing a derived-to-base cast.

In C++11 onwards, this should have fixed the last case where we would
materialize a temporary of the wrong type (with a subobject adjustment inside
the MaterializeTemporaryExpr instead of outside), but we still have to deal
with that possibility in C++98, unless we want to start using xvalues to
represent materialized temporaries there too.

llvm-svn: 289250
2016-12-09 18:49:13 +00:00
Martin Bohme f44cde8b73 CFGBuilder: Fix crash when visiting delete expression on dependent type
Summary:
CXXDeleteExpr::getDestroyedType() can return a null QualType if the destroyed
type is a dependent type. This patch protects against this.

Reviewers: klimek

Subscribers: cfe-commits

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

llvm-svn: 288665
2016-12-05 11:33:19 +00:00
Richard Smith 4baaa5ab52 DR616, and part of P0135R1: member access (or pointer-to-member access) on a
temporary produces an xvalue, not a prvalue. Support this by materializing the
temporary prior to performing the member access.

llvm-svn: 288563
2016-12-03 01:14:32 +00:00
Tim Shen 43ee05e804 [ReachableCode] Skip over ExprWithCleanups in isConfigurationValue
Summary: Fixes pr29152.

Reviewers: rsmith, pirama, krememek

Subscribers: cfe-commits

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

llvm-svn: 285657
2016-11-01 00:19:04 +00:00
Piotr Padlewski 2f8b97f3a6 NFC small format
llvm-svn: 285496
2016-10-29 15:28:25 +00:00
Mehdi Amini 9825ab0433 Fix handling of %% format specifier in os_log builtins.
Returning `false` was stopping the parsing of further arguments,
which wasn't intended.

llvm-svn: 285047
2016-10-25 00:48:48 +00:00
Mehdi Amini 06d367c6c6 Add support for __builtin_os_log_format[_buffer_size]
This reverts commit r285007 and reapply r284990, with a fix for the
opencl test that I broke. Original commit message follows:

These new builtins support a mechanism for logging OS events, using a
printf-like format string to specify the layout of data in a buffer.
The _buffer_size version of the builtin can be used to determine the size
of the buffer to allocate to hold the data, and then __builtin_os_log_format
can write data into that buffer. This implements format checking to report
mismatches between the format string and the data arguments. Most of this
code was written by Chris Willmore.

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

llvm-svn: 285019
2016-10-24 20:39:34 +00:00
Mehdi Amini 9c39fdceda Revert "Add support for __builtin_os_log_format[_buffer_size]"
This reverts commit r284990, two opencl test are broken

llvm-svn: 285007
2016-10-24 19:41:36 +00:00
Mehdi Amini 29034362ae Add support for __builtin_os_log_format[_buffer_size]
These new builtins support a mechanism for logging OS events, using a
printf-like format string to specify the layout of data in a buffer.
The _buffer_size version of the builtin can be used to determine the size
of the buffer to allocate to hold the data, and then __builtin_os_log_format
can write data into that buffer. This implements format checking to report
mismatches between the format string and the data arguments. Most of this
code was written by Chris Willmore.

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

llvm-svn: 284990
2016-10-24 16:56:23 +00:00
Benjamin Kramer 33e9760376 Remove move constructors that are identical to the generated default move ctor.
llvm-svn: 284856
2016-10-21 18:55:07 +00:00
Benjamin Kramer c3f89253ae Retire llvm::alignOf in favor of C++11 alignof.
No functionality change intended.

llvm-svn: 284730
2016-10-20 14:27:22 +00:00
Alexander Shaposhnikov fd905fcc14 [analyzer] Remove superquadratic behaviour from DataflowWorklist
The class DataflowWorklist internally maintains a sorted list of pointers to CFGBlock
and the method enqueuePredecessors has to call sortWorklist to maintain the invariant. 
The implementation based on vector + sort works well for small sizes 
but gets infeasible for relatively large sizes. In particular the issue takes place 
for some cryptographic libraries which use code generation. 
The diff replaces vector + sort with priority queue.
For one of the implementations of AES this patch reduces 
the time for analysis from 204 seconds to 8 seconds.

Test plan: make -j8 check-clang

Differential revision: https://reviews.llvm.org/D25503

llvm-svn: 284166
2016-10-13 21:31:46 +00:00
Justin Lebar 5f3d1dc44c [Analysis] Use unique_ptr for CallGraph::FunctionMap.
Reviewers: timshen

Subscribers: cfe-commits

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

llvm-svn: 283775
2016-10-10 16:26:48 +00:00
Justin Lebar 5cb35e1676 [Analysis] Use unique_ptr in AnalyaisDeclContextManager's ContextMap.
Reviewers: timshen

Subscribers: cfe-commits

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

llvm-svn: 283774
2016-10-10 16:26:44 +00:00
Artem Dergachev 4eca0de7b7 [analyzer] Re-apply r283094 "Improve CloneChecker diagnostics"
The parent commit (r283092) was reverted before and now finally landed.

llvm-svn: 283661
2016-10-08 10:54:30 +00:00
NAKAMURA Takumi 90893f0eab Revert r283106, "Wdocumentation fix"
It should depend on r283094 and r283182.

llvm-svn: 283195
2016-10-04 08:32:33 +00:00
Vitaly Buka 1a8d52d1ae Revert "[analyzer] Improve CloneChecker diagnostics" as its depends on reverted r283092
This reverts commit r283094.

llvm-svn: 283182
2016-10-04 02:40:35 +00:00
Simon Pilgrim efd4006080 Wdocumentation fix
llvm-svn: 283106
2016-10-03 12:37:08 +00:00
Daniel Marjamaki 042a3c5a2d [StaticAnalyzer] Fix UnreachableCode false positives.
When there is 'do { } while (0);' in the code the ExplodedGraph and UnoptimizedCFG did not match.

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

llvm-svn: 283095
2016-10-03 08:28:51 +00:00
Artem Dergachev c87d2a613e [analyzer] Improve CloneChecker diagnostics
Highlight code clones referenced by the warning message with the help of
the extra notes feature recently introduced in r283092.

Change warning text to more clang-ish. Remove suggestions from the copy-paste
error checker diagnostics, because currently our suggestions are strictly 50%
wrong (we do not know which of the two code clones contains the error), and
for that reason we should not sound as if we're actually suggesting this.
Hopefully a better solution would bring them back.

Make sure the suspicious clone pair structure always mentions
the correct variable for the second clone.

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

llvm-svn: 283094
2016-10-03 08:11:50 +00:00
Justin Lebar 9091055efa Move UTF functions into namespace llvm.
Summary:
This lets people link against LLVM and their own version of the UTF
library.

I determined this only affects llvm, clang, lld, and lldb by running

$ git grep -wl 'UTF[0-9]\+\|\bConvertUTF\bisLegalUTF\|getNumBytesFor' | cut -f 1 -d '/' | sort | uniq
  clang
  lld
  lldb
  llvm

Tested with

  ninja lldb
  ninja check-clang check-llvm check-lld

(ninja check-lldb doesn't complete for me with or without this patch.)

Reviewers: rnk

Subscribers: klimek, beanz, mgorny, llvm-commits

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

llvm-svn: 282822
2016-09-30 00:38:45 +00:00
Artem Dergachev 5f94b089e9 [analyzer] Fix CloneDetector crash on calling methods of class templates.
If a call expression represents a method call of a class template,
and the method itself isn't templated, then the method may be considered
to be a template instantiation without template specialization arguments.

No longer crash when we could not find template specialization arguments.

Patch by Raphael Isemann!

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

llvm-svn: 279529
2016-08-23 16:42:00 +00:00
Simon Pilgrim e62d0da8cc Wdocumentation fix
llvm-svn: 279382
2016-08-20 20:21:27 +00:00
Artem Dergachev 5657486854 [analyzer] Use faster hashing (MD5) in CloneDetector.
This replaces the old approach of fingerprinting every AST node into a string,
which avoided collisions and was simple to implement, but turned out to be
extremely ineffective with respect to both performance and memory.

The collisions are now dealt with in a separate pass, which no longer causes
performance problems because collisions are rare.

Patch by Raphael Isemann!

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

llvm-svn: 279378
2016-08-20 17:35:53 +00:00
Benjamin Kramer f3b323debc [Sema] Don't crash on scanf on forward-declared enums.
This is valid in GNU C, which allows pointers to incomplete enums. GCC
just pretends that the underlying type is 'int' in those cases, follow
that behavior.

llvm-svn: 279374
2016-08-20 16:51:33 +00:00
Artem Dergachev 51b9a0e8e8 [analyzer] Make CloneDetector consider macro expansions.
So far macro-generated code was treated by the CloneDetector as normal code.
This caused that some macros where reported as false-positive clones because
large chunks of code coming from otherwise concise macro expansions were treated
as copy-pasted code.

This patch ensures that macros are treated in the same way as literals/function
calls. This prevents macros that expand into multiple statements
from being reported as clones.

Patch by Raphael Isemann!

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

llvm-svn: 279367
2016-08-20 10:06:59 +00:00
Artem Dergachev 5183888813 [analyzer] Make CloneDetector consider template arguments.
For example, code samples `isa<Stmt>(S)' and `isa<Expr>(S)'
are no longer considered to be clones.

Patch by Raphael Isemann!

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

llvm-svn: 279366
2016-08-20 09:57:21 +00:00
Artem Dergachev 2fc1985db3 [analyzer] Teach CloneDetector to find clones that look like copy-paste errors.
The original clone checker tries to find copy-pasted code that is exactly
identical to the original code, up to minor details.

As an example, if the copy-pasted code has all references to variable 'a'
replaced with references to variable 'b', it is still considered to be
an exact clone.

The new check finds copy-pasted code in which exactly one variable seems
out of place compared to the original code, which likely indicates
a copy-paste error (a variable was forgotten to be renamed in one place).

Patch by Raphael Isemann!

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

llvm-svn: 279056
2016-08-18 12:29:41 +00:00
Artem Dergachev cad151491e [analyzer] Fix a crash in CloneDetector when calling functions by pointers.
CallExpr may have a null direct callee when the callee function is not
known in compile-time. Do not try to take callee name in this case.

Patch by Raphael Isemann!

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

llvm-svn: 278238
2016-08-10 16:25:16 +00:00
Vassil Vassilev 5721e0f37a [analyzer] Try to fix coverity CID 1360469.
Patch by Raphael Isemann!

llvm-svn: 278110
2016-08-09 10:00:23 +00:00
Artem Dergachev 7a0088bbae [analyzer] Make CloneDetector recognize different variable patterns.
CloneDetector should be able to detect clones with renamed variables.
However, if variables are referenced multiple times around the code sample,
the usage patterns need to be recognized.

For example, (x < y ? y : x) and (y < x ? y : x) are no longer clones,
however (a < b ? b : a) is still a clone of the former.

Variable patterns are computed and compared during a separate filtering pass.

Patch by Raphael Isemann!

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

llvm-svn: 277757
2016-08-04 19:37:00 +00:00
Devin Coughlin 6eb1ca7416 [CFG] Fix crash finding destructor of lifetime-extended temporary.
Fix a crash under -Wthread-safety when finding the destructor for a
lifetime-extending reference.

A patch by Nandor Licker!

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

llvm-svn: 277522
2016-08-02 21:07:23 +00:00