Commit Graph

2303 Commits

Author SHA1 Message Date
Kaelyn Takata e1f49d545d Add the initial TypoExpr AST node for delayed typo correction.
llvm-svn: 220692
2014-10-27 18:07:20 +00:00
Anton Yartsev 6ca45c92a9 [analyzer] Move the NewDeleteLeaks checker from CplusplusAlpha to Cplusplus package.
llvm-svn: 220289
2014-10-21 12:41:36 +00:00
Ted Kremenek 0c28bc20da [analyzer] Tweak MallocSizeOfChecker to not warn when using sizeof(void*) to allocate a bunch of any pointer type.
This suppresses a common false positive when analyzing libc++.

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

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

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

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

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

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

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

A patch by Aleksei Sidorin!

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

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

A patch by Daniel Fahlgren!

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

A patch by Daniel Fahlgren!

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

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

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

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

llvm-svn: 217210
2014-09-05 00:11:25 +00:00
David Blaikie b564d1fb43 unique_ptrify ExplodedGraph::trim
llvm-svn: 217208
2014-09-05 00:04:19 +00:00
David Blaikie 7c35f6194f unique_ptrify the result of ConstraintManagerCreator and StoreManagerCreator
llvm-svn: 217206
2014-09-04 23:54:37 +00:00
David Blaikie 91e7902622 unique_ptrify BugReporter::visitors
llvm-svn: 217205
2014-09-04 23:54:33 +00:00
David Blaikie 53dd8fea69 unique_ptrify clang::ento::createCheckerManager
llvm-svn: 216765
2014-08-29 20:11:03 +00:00
David Blaikie c9950cb1dd unique_ptrify PathDiagnosticConsumer::HandlePathDiagnostic
FoldingSet, another intrusive data structure that could use some
unique_ptr love on its interfaces. Eventually.

llvm-svn: 216764
2014-08-29 20:06:10 +00:00
Anna Zaks d5478fdd8f Add an option to silence all analyzer warnings.
People have been incorrectly using "-analyzer-disable-checker" to
silence analyzer warnings on a file, when analyzing a project. Add
the "-analyzer-disable-all-checks" option, which would allow the
suppression and suggest it as part of the error message for
"-analyzer-disable-checker". The idea here is to compose this with
"--analyze" so that users can selectively opt out specific files from
static analysis.

llvm-svn: 216763
2014-08-29 20:01:38 +00:00
David Blaikie 43e3717bdb unique_ptrify thep passing of BugReports to BugReportEquivClass
I suspect llvm::ilist should take elements by unique_ptr, since it does
take ownership of the element (by stitching it into the linked list) -
one day.

llvm-svn: 216761
2014-08-29 19:57:52 +00:00
David Blaikie 8d05190e1d unique_ptrify PathDiagnostic::setEndOfPath's argument
Again, if shared ownership is the right model here (I assume it is,
given graph algorithms & such) this could be tidied up (the 'release'
call removed in favor of something safer) by having
IntrunsiveRefCntPointer constructible from a unique_ptr.

(& honestly I'd probably favor taking a page out of shared_ptr's book,
allowing implicit construction from a unique_ptr rvalue, and only allow
explicit from a raw pointer - currently IntrusiveRefCntPointer can
implicitly own from a raw pointer, which seems unsafe)

llvm-svn: 216752
2014-08-29 18:18:47 +00:00
David Blaikie d15481ccea unique_ptr-ify PathDiagnosticPiece ownership
llvm-svn: 216751
2014-08-29 18:18:43 +00:00
NAKAMURA Takumi 37011a1e24 [CMake] clangStaticAnalyzerFrontend: Add clangLex, corresponding to r216550.
llvm-svn: 216664
2014-08-28 12:42:28 +00:00
Ted Kremenek eeccb30b94 Add support for the static analyzer to synthesize function implementations from external model files.
Currently the analyzer lazily models some functions using 'BodyFarm',
which constructs a fake function implementation that the analyzer
can simulate that approximates the semantics of the function when
it is called.  BodyFarm does this by constructing the AST for
such definitions on-the-fly.  One strength of BodyFarm
is that all symbols and types referenced by synthesized function
bodies are contextual adapted to the containing translation unit.
The downside is that these ASTs are hardcoded in Clang's own
source code.

A more scalable model is to allow these models to be defined as source
code in separate "model" files and have the analyzer use those
definitions lazily when a function body is needed.  Among other things,
it will allow more customization of the analyzer for specific APIs
and platforms.

This patch provides the initial infrastructure for this feature.
It extends BodyFarm to use an abstract API 'CodeInjector' that can be
used to synthesize function bodies.  That 'CodeInjector' is
implemented using a new 'ModelInjector' in libFrontend, which lazily
parses a model file and injects the ASTs into the current translation
unit.  

Models are currently found by specifying a 'model-path' as an
analyzer option; if no path is specified the CodeInjector is not
used, thus defaulting to the current behavior in the analyzer.

Models currently contain a single function definition, and can
be found by finding the file <function name>.model.  This is an
initial starting point for something more rich, but it bootstraps
this feature for future evolution.

This patch was contributed by Gábor Horváth as part of his
Google Summer of Code project.

Some notes:

- This introduces the notion of a "model file" into
  FrontendAction and the Preprocessor.  This nomenclature
  is specific to the static analyzer, but possibly could be
  generalized.  Essentially these are sources pulled in
  exogenously from the principal translation.

  Preprocessor gets a 'InitializeForModelFile' and
  'FinalizeForModelFile' which could possibly be hoisted out
  of Preprocessor if Preprocessor exposed a new API to
  change the PragmaHandlers and some other internal pieces.  This
  can be revisited.

  FrontendAction gets a 'isModelParsingAction()' predicate function
  used to allow a new FrontendAction to recycle the Preprocessor
  and ASTContext.  This name could probably be made something
  more general (i.e., not tied to 'model files') at the expense
  of losing the intent of why it exists.  This can be revisited.

- This is a moderate sized patch; it has gone through some amount of
  offline code review.  Most of the changes to the non-analyzer
  parts are fairly small, and would make little sense without
  the analyzer changes.

- Most of the analyzer changes are plumbing, with the interesting
  behavior being introduced by ModelInjector.cpp and
  ModelConsumer.cpp.

- The new functionality introduced by this change is off-by-default.
  It requires an analyzer config option to enable.

llvm-svn: 216550
2014-08-27 15:14:15 +00:00
Craig Topper 5fc8fc2d31 Simplify creation of a bunch of ArrayRefs by using None, makeArrayRef or just letting them be implicitly created.
llvm-svn: 216528
2014-08-27 06:28:36 +00:00
Richard Smith 588bd9b7f8 Fix representation of __attribute__((nonnull)) to support correctly modeling
the no-arguments case. Don't expand this to an __attribute__((nonnull(A, B,
C))) attribute, since that does the wrong thing for function templates and
varargs functions.

In passing, fix a grammar error in the diagnostic, a crash if
__attribute__((nonnull(N))) is applied to a varargs function,
a bug where the same null argument could be diagnosed multiple
times if there were multiple nonnull attributes referring to it,
and a bug where nonnull attributes would not be accumulated correctly
across redeclarations.

llvm-svn: 216520
2014-08-27 04:59:42 +00:00
Rafael Espindola dae941a6c8 Update for llvm api change.
llvm-svn: 216397
2014-08-25 18:17:04 +00:00
Jordan Rose 19ecd635fe [analyzer] Remove check covered by -Wobjc-missing-super-calls.
The ObjCDealloc checker is currently disabled because it was too aggressive, but this
is a good first step in getting it back to a useful state.

Patch by David Kilzer!

llvm-svn: 216272
2014-08-22 16:57:33 +00:00
Fariborz Jahanian 78e9debf68 Objective-C. Warn if user has made explicit call
to +initilize as this results in an extra call
to this method. rdar://16628028

llvm-svn: 216271
2014-08-22 16:57:26 +00:00
Benjamin Kramer cb4efc1028 [analyzer] Don't warn on virtual calls in ctors to final methods.
The call will never go to a more derived class, but that's intentional in those
cases.

llvm-svn: 216167
2014-08-21 10:25:03 +00:00
Jordan Rose ba129af62a [analyzer] UnixAPI: Check that the third argument to open(2) (if present) is an integer.
Patch by Daniel Fahlgren.

llvm-svn: 216079
2014-08-20 16:58:09 +00:00
Jordan Rose cd4db5c6d2 [analyzer] UnixAPI: Check when open(2) is called with more than three arguments.
Patch by Daniel Fahlgren.

llvm-svn: 216078
2014-08-20 16:58:03 +00:00
Jordan Rose f3544e913d [analyzer] IdenticalExpr: don't try to compare integer literals with different widths.
PR20659. Patch by Anders Rönnholm.

llvm-svn: 216076
2014-08-20 16:51:26 +00:00
Jordan Rose b6100301e8 [analyzer] IdenticalExpr: use getBytes rather than getString to compare string literals.
PR20693. Patch by Anders Rönnholm.

llvm-svn: 216075
2014-08-20 16:51:18 +00:00
Benjamin Kramer 2f5db8b3db Header guard canonicalization, clang part.
Modifications made by clang-tidy with minor tweaks.

llvm-svn: 215557
2014-08-13 16:25:19 +00:00
Manuel Klimek f67672e41c Work around missing handling of temporaries bound to default arguments.
Yet more problems due to the missing CXXBindTemporaryExpr in the CFG for
default arguments.

Unfortunately we cannot just switch off inserting temporaries for the
corresponding default arguments, as that breaks existing tests
(test/SemaCXX/return-noreturn.cpp:245).

llvm-svn: 215554
2014-08-13 15:25:55 +00:00
Jordan Rose 1a9c0d141c [analyzer] Check for negative values used as the size of a C variable-length array.
Patch by Daniel Fahlgren!

llvm-svn: 215456
2014-08-12 16:44:22 +00:00
Manuel Klimek 26f649f3f4 Work around default parameter problem in the static analyzer.
In cases like:
  struct C { ~C(); }
  void f(C c = C());
  void t() {
    f();
  }

We currently do not add the CXXBindTemporaryExpr for the temporary (the
code mentions that as the default parameter expressions are owned by
the declaration, we'd otherwise add the same expression multiple times),
but we add the temporary destructor pointing to the CXXBindTemporaryExpr.
We need to fix that before we can re-enable the assertion.

llvm-svn: 215357
2014-08-11 14:54:30 +00:00
David Blaikie 6beb6aa8f0 Recommit 213307: unique_ptr-ify ownership of ASTConsumers (reverted in r213325)
After post-commit review and community discussion, this seems like a
reasonable direction to continue, making ownership semantics explicit in
the source using the type system.

llvm-svn: 215323
2014-08-10 19:56:51 +00:00
David Blaikie 1c5a38584d Simplify ownership of ExplodedGraph in the CoreEngine by removing unique_ptr indirection.
Summary: I was going to fix the use of raw pointer ownership in "takeGraph" when I realized that function was unused and the whole ExplodedGraph could just be owned by value without the std::unique_ptr indirection at all.

Reviewers: jordan_rose

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

llvm-svn: 215257
2014-08-08 23:36:37 +00:00
Manuel Klimek b5616c9f8d Re-applying r214962.
Changes to the original patch:
- model the CFG for temporary destructors in conditional operators so that
  the destructors of the true and false branch are always exclusive. This
  is necessary because we must not have impossible paths for the path
  based analysis to work.
- add multiple regression tests with ternary operators

Original description:
Fix modelling of non-lifetime-extended temporary destructors in the
analyzer.

Changes to the CFG:
When creating the CFG for temporary destructors, we create a structure
that mirrors the branch structure of the conditionally executed
temporary constructors in a full expression.
The branches we create use a CXXBindTemporaryExpr as terminator which
corresponds to the temporary constructor which must have been executed
to enter the destruction branch.

2. Changes to the Analyzer:
When we visit a CXXBindTemporaryExpr we mark the CXXBindTemporaryExpr as
executed in the state; when we reach a branch that contains the
corresponding CXXBindTemporaryExpr as terminator, we branch out
depending on whether the corresponding CXXBindTemporaryExpr was marked
as executed.

llvm-svn: 215096
2014-08-07 10:42:17 +00:00