Commit Graph

1214 Commits

Author SHA1 Message Date
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
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
Mike Spertus cf45cb0b9d Improve MSVC visualization of annot_template_id tokens
Now shows the actual annotated template. E.g.,
{annot_template_id (A<int, double>)}

Also a few miscellaneous fixes to visualizers of other types

llvm-svn: 365248
2019-07-05 21:41:30 +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
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 5fcf92e153 [analyzer] exploded-graph-rewriter: NFC: Add more comments.
llvm-svn: 364991
2019-07-03 01:26:38 +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
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
Mike Spertus fb133b0aab Various tweaks to MSVC natvis visualizers
Make more consistent use of na format.
Improve visualization of deduction guides.
Add visualizer for explicit specifier (including conditionally explicit)
Fix some typos

llvm-svn: 364724
2019-06-30 22:04:25 +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
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
Artem Dergachev b9c94f946f [analyzer] NFC: exploded-graph-rewriter: Extract some code into functions.
Differential Revision: https://reviews.llvm.org/D63684

llvm-svn: 364267
2019-06-25 02:16:50 +00:00
Mike Spertus 08c699a110 MSVC visualizers for type aliases
For example, the following TypeAliasTemplateDecl now displays in the autos window as
template<class T> using type_identity_t = type_identity<T>::type;

llvm-svn: 364145
2019-06-23 01:15:48 +00:00
Mike Spertus d050479be5 Natural MSVC visualization of constructors
E.g., Allow MSVC to visualize a CXXConstructorDecl like 
Constructor { Y(type_identity_t<T>)}

llvm-svn: 364138
2019-06-22 18:56:40 +00:00
Richard Smith 78b239ea67 P0840R2: support for [[no_unique_address]] attribute
Summary:
Add support for the C++2a [[no_unique_address]] attribute for targets using the Itanium C++ ABI.

This depends on D63371.

Reviewers: rjmccall, aaron.ballman

Subscribers: dschuff, aheejin, cfe-commits

Tags: #clang

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

llvm-svn: 363976
2019-06-20 20:44:45 +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
Mike Spertus 1f50697abc Various improvements to Clang MSVC Visualizer
This change adds/improves MSVC visualizers for many Clang types, including array types, trailing return types in function, deduction guides, a fix for OpaquePtr, etc. It also replaces all of the view(deref) with the "na" formatter, which is a better built-in natvis technique for doing the same thing. 

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

llvm-svn: 363574
2019-06-17 16:12:45 +00:00
Artem Dergachev 44fb55bf96 [analyzer] exploded-graph-rewriter: Add the missing license header!
llvm-svn: 362575
2019-06-05 02:09:49 +00:00
Sven van Haastregt 79a222fcf8 [OpenCL] Declare builtin functions using TableGen
This patch adds a `-fdeclare-opencl-builtins` command line option to
the clang frontend.  This enables clang to verify OpenCL C builtin
function declarations using a fast StringMatcher lookup, instead of
including the opencl-c.h file with the `-finclude-default-header`
option.  This avoids the large parse time penalty of the header file.

This commit only adds the basic infrastructure and some of the OpenCL
builtins.  It does not cover all builtins defined by the various OpenCL
specifications.  As such, it is not a replacement for
`-finclude-default-header` yet.

RFC: http://lists.llvm.org/pipermail/cfe-dev/2018-November/060041.html

Co-authored-by: Pierre Gondois
Co-authored-by: Joey Gouly
Co-authored-by: Sven van Haastregt

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

llvm-svn: 362371
2019-06-03 09:39:11 +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
Richard Smith 2e2c02c0cd Add script to update OpenMP -ast-dump test expectations, and use it to
regenerate the test expectations.

(Only two tests change, as a result of no longer matching the 0x in a
pointer; the other tests were already excluding that.)

llvm-svn: 362316
2019-06-02 04:00:38 +00:00
John McCall 2c91c3b7af Add the `objc_class_stub` attribute.
Swift requires certain classes to be not just initialized lazily on first
use, but actually allocated lazily using information that is only available
at runtime.  This is incompatible with ObjC class initialization, or at least
not efficiently compatible, because there is no meaningful class symbol
that can be put in a class-ref variable at load time.  This leaves ObjC
code unable to access such classes, which is undesirable.

objc_class_stub says that class references should be resolved by calling
a new ObjC runtime function with a pointer to a new "class stub" structure.
Non-ObjC compilers (like Swift) can simply emit this structure when ObjC
interop is required for a class that cannot be statically allocated,
then apply this attribute to the `@interface` in the generated ObjC header
for the class.

This attribute can be thought of as a generalization of the existing
`objc_runtime_visible` attribute which permits more efficient class
resolution as well as supporting the additon of categories to the class.
Subclassing these classes from ObjC is currently not allowed.

Patch by Slava Pestov!

llvm-svn: 362054
2019-05-30 04:09:01 +00:00
Artem Dergachev e8b29c00dd [analyzer] SATestBuild.py: Use driver for analyzing single-file tests.
Don't bother coming up with a -cc1 run-line ourselves.

This, in particular, gets rid of a macOS-specific code path.

llvm-svn: 362009
2019-05-29 18:49:31 +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
Aaron Ballman 4c9e1d2262 Clang-formatting the header in advance of other planned changes; NFC.
llvm-svn: 361378
2019-05-22 13:01:28 +00:00
Reid Kleckner 10dd7f1422 Make clang/utils/creduce-clang-crash.py executable
llvm-svn: 359722
2019-05-01 20:15:39 +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
Amy Huang 124debd0d2 creduce-clang-crash: add -F flag to grep to avoid interpreting string as regex
llvm-svn: 359216
2019-04-25 18:00:25 +00:00
Fangrui Song 899d13926d Use llvm::stable_sort
llvm-svn: 359098
2019-04-24 14:43:05 +00:00
Amy Huang 06d2fa7b47 Fixes in creduce-clang-crash.py for clang crash message parsing and reading the command from the repro script.
llvm-svn: 359054
2019-04-24 00:28:23 +00:00
Kristof Umann b4788b26e2 [analyzer][NFC] Reimplement checker options
TL;DR:

* Add checker and package options to the TableGen files
* Added a new class called CmdLineOption, and both Package and Checker recieved
   a list<CmdLineOption> field.
* Added every existing checker and package option to Checkers.td.
* The CheckerRegistry class
  * Received some comments to most of it's inline classes
  * Received the CmdLineOption and PackageInfo inline classes, a list of
     CmdLineOption was added to CheckerInfo and PackageInfo
  * Added addCheckerOption and addPackageOption
  * Added a new field called Packages, used in addPackageOptions, filled up in
     addPackage

Detailed description:

In the last couple months, a lot of effort was put into tightening the
analyzer's command line interface. The main issue is that it's spectacularly
easy to mess up a lenghty enough invocation of the analyzer, and the user was
given no warnings or errors at all in that case.

We can divide the effort of resolving this into several chapters:

* Non-checker analyzer configurations:
    Gather every analyzer configuration into a dedicated file. Emit errors for
    non-existent configurations or incorrect values. Be able to list these
    configurations. Tighten AnalyzerOptions interface to disallow making such
    a mistake in the future.

* Fix the "Checker Naming Bug" by reimplementing checker dependencies:
    When cplusplus.InnerPointer was enabled, it implicitly registered
    unix.Malloc, which implicitly registered some sort of a modeling checker
    from the CStringChecker family. This resulted in all of these checker
    objects recieving the name "cplusplus.InnerPointer", making AnalyzerOptions
    asking for the wrong checker options from the command line:
      cplusplus.InnerPointer:Optimisic
    istead of
      unix.Malloc:Optimistic.
    This was resolved by making CheckerRegistry responsible for checker
    dependency handling, instead of checkers themselves.

* Checker options: (this patch included!)
    Same as the first item, but for checkers.

(+ minor fixes here and there, and everything else that is yet to come)

There were several issues regarding checker options, that non-checker
configurations didn't suffer from: checker plugins are loaded runtime, and they
could add new checkers and new options, meaning that unlike for non-checker
configurations, we can't collect every checker option purely by generating code.
Also, as seen from the "Checker Naming Bug" issue raised above, they are very
rarely used in practice, and all sorts of skeletons fell out of the closet while
working on this project.

They were extremely problematic for users as well, purely because of how long
they were. Consider the following monster of a checker option:

  alpha.cplusplus.UninitializedObject:CheckPointeeInitialization=false

While we were able to verify whether the checker itself (the part before the
colon) existed, any errors past that point were unreported, easily resulting
in 7+ hours of analyses going to waste.

This patch, similarly to how dependencies were reimplemented, uses TableGen to
register checker options into Checkers.td, so that Checkers.inc now contains
entries for both checker and package options. Using the preprocessor,
Checkers.inc is converted into code in CheckerRegistry, adding every builtin
(checkers and packages that have an entry in the Checkers.td file) checker and
package option to the registry. The new addPackageOption and addCheckerOption
functions expose the same functionality to statically-linked non-builtin and
plugin checkers and packages as well.

Emitting errors for incorrect user input, being able to list these options, and
some other functionalies will land in later patches.

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

llvm-svn: 358752
2019-04-19 12:32:10 +00:00
Amy Huang 57f686310e Remove --show-includes flag in crash reduce script
llvm-svn: 358590
2019-04-17 16:20:56 +00:00
George Burgess IV 5456beb944 Various fixes and additions to creduce-clang-crash.py
Some more additions to the script - mainly reducing the clang args after
the creduce run by removing them one by one and seeing if the crash
reproduces. Other things:

- remove the --crash flag when "fatal error" occurs
- fixed to read stack trace functions from the top
- run creduce on a copy of the original file

Patch by Amy Huang!

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

llvm-svn: 357290
2019-03-29 17:50:43 +00:00
George Burgess IV eda3d11d14 creduce-clang-crash.py: preprocess file + reduce commandline
This CL causes our creduce-clang-crash.py util to:

- try to preprocess the file before reducing
- try to remove some command line arguments
- now require a llvm bin directory, since the generated crash script
  doesn't have an absolute path for clang

It also marks it as executable, since I forgot to do that in the last
commit. :)

Patch by Amy Huang!

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

llvm-svn: 356636
2019-03-21 01:01:53 +00:00
George Burgess IV 87565fe734 Add a creduce script for clang crashes
This CL adds a script that calls C-Reduce on an input file and given the
clang crash script, which is used to generate an interestingness test
for C-Reduce.

Patch by Amy Huang!

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

llvm-svn: 355944
2019-03-12 17:48:53 +00:00
Fangrui Song 9ac13a1244 Use llvm::is_contained. NFC
llvm-svn: 353635
2019-02-10 05:54:57 +00:00
George Karpenkov a64b205ae7 [analyzer] [testing] Inside CmpRuns.py output also print the filename of the first item in the path
Differential Revision: https://reviews.llvm.org/D57783

llvm-svn: 353228
2019-02-05 22:26:57 +00:00
Stephen Kelly 6d110d6afe [ASTDump] Rename methods which are conceptually Visits
This is consistent with the TextNodeDumper, and is the appropriate name
for the traverser class which will be extracted.

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

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

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

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

In detail:

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

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

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

llvm-svn: 352287
2019-01-26 20:06:54 +00:00