Commit Graph

3593 Commits

Author SHA1 Message Date
Yitzhak Mandelbaum 3f1ab737e2 [LibTooling] Relax Transformer to allow rewriting macro expansions
Summary:
Currently, Transformer rejects any changes to source locations inside macro
expansions. This change relaxes that constraint to allow rewrites when the
entirety of the expansion is replaced, since that can be mapped to replacing the
entirety of the expansion range in the file source.  This change makes
Transformer consistent with the handling of edit ranges in `clang::edit::Commit`
(which is used, for example, for applying `FixItHint`s from diagnostics).

Reviewers: ilya-biryukov

Subscribers: gribozavr, cfe-commits

Tags: #clang

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

llvm-svn: 366473
2019-07-18 17:44:54 +00:00
Yitzhak Mandelbaum 2e97a1e19e [LibTooling] Add function to translate and validate source range for editing
Summary:
Adds the function `getRangeForEdit` to validate that a given source range is
editable and, if needed, translate it into a range in the source file (for
example, if it's sourced in macro expansions).

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 366469
2019-07-18 17:26:57 +00:00
Ilya Biryukov abc744d263 Revert r366449: [CrossTU] Add a function to retrieve original source location.
Reason: the commit breaks layering by adding a dependency on ASTUnit
(which is inside clangFrontend) from the ASTImporter (which is inside
clangAST).

llvm-svn: 366453
2019-07-18 15:43:26 +00:00
Balazs Keri d2c576110e [CrossTU] Add a function to retrieve original source location.
Summary:
A new function will be added to get the original SourceLocation
for a SourceLocation that was imported as result of getCrossTUDefinition.
The returned SourceLocation is in the context of the (original)
SourceManager for the original source file. Additionally the
ASTUnit object for that source file is returned. This is needed
to get a SourceManager to operate on with the returned source location.

The new function works if multiple different source files are loaded
with the same CrossTU context.

This patch can be treated as part of a bigger change that is needed to
improve macro expansion handliong at plist generation.

Reviewers: martong, shafik, a_sidorin, xazax.hun

Reviewed By: martong

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

Tags: #clang

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

llvm-svn: 366449
2019-07-18 15:23:10 +00:00
Gabor Marton ae512b83d5 [ASTImporter] Fix structural eq of lambdas
Summary:
The structural equivalence check reported false eq between lambda classes
with different parameters in their call signature.
The solution is to check the methods for equality too in case of lambda
classes.

Reviewers: a_sidorin, a.sidorin

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

Tags: #clang

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

llvm-svn: 366332
2019-07-17 14:40:09 +00:00
Gabor Marton aefcf5100a [ASTImporter] Fix LLDB lookup in transparent ctx and with ext src
Summary:
With LLDB we use localUncachedLookup(), however, that fails to find
Decls when a transparent context is involved and the given DC has
external lexical storage.  The solution is to use noload_lookup, which
works well with transparent contexts.  But, we cannot use only the
noload_lookup since the slow case of localUncachedLookup is still needed
in some other cases.

These other cases are handled in ASTImporterLookupTable, but we cannot
use that with LLDB since that traverses through the AST which initiates
the load of external decls again via DC::decls().

We must avoid loading external decls during the import becuase
ExternalASTSource is implemented with ASTImporter, so external loads
during import results in uncontrolled and faulty import.

Reviewers: shafik, teemperor, jingham, clayborg, a_sidorin, a.sidorin

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

Tags: #clang, #lldb

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

llvm-svn: 366325
2019-07-17 13:47:46 +00:00
Ben Hamilton f4c2d57f76 [clang-format] Don't detect call to ObjC class method as C++11 attribute specifier
Summary:
Previously, clang-format detected something like the following as a C++11 attribute specifier.

  @[[NSArray class]]

instead of an array with an Objective-C method call inside. In general, when the attribute specifier checking runs, if it sees 2 identifiers in a row, it decides that the square brackets represent an Objective-C method call. However, here, `class` is tokenized as a keyword instead of an identifier, so this check fails.

To fix this, the attribute specifier first checks whether the first square bracket has an "@" before it. If it does, then that square bracket is not the start of a attribute specifier because it is an Objective-C array literal. (The assumption is that @[[.*]] is not valid C/C++.)

Contributed by rkgibson2.

Reviewers: benhamilton

Reviewed By: benhamilton

Subscribers: aaron.ballman, cfe-commits

Tags: #clang

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

llvm-svn: 366267
2019-07-16 21:29:40 +00:00
Jan Korous c5e7a3d710 [DirectoryWatcher][test] Relax test assumptions
Workaround for FSEvents sometimes sending notifications for events that happened
before DirectoryWatcher was created.

This caused tests to be flaky on green dragon.

llvm-svn: 366138
2019-07-15 22:11:51 +00:00
Jan Korous 5076038bb0 [DirectoryWatcher][NFC][test] Add typedef for enum
llvm-svn: 366137
2019-07-15 22:11:28 +00:00
Balazs Keri 14d115ff98 [ASTImporter] Using Lang_CXX14 in ASTImporterVisibilityTest.
Summary:
These tests may work with C++14 language constructs in the future
(variable templates and others).
To avoid warnings about language version C++ version constants in the tests
are updated.

Reviewers: martong, a.sidorin

Reviewed By: martong

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

Tags: #clang

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

llvm-svn: 366061
2019-07-15 12:16:30 +00:00
Jan Korous 4765aa14ff [DirectoryWatcher][test][NFC] Add information to test failure reports
llvm-svn: 365976
2019-07-13 00:09:04 +00:00
Sam McCall 5d9d7c59ee Re-land [JSONCompilationDatabase] Strip distcc/ccache/gomacc wrappers from parsed commands.
Use //net/dir like other test cases for windows compatibility

llvm-svn: 365975
2019-07-12 23:38:31 +00:00
Jan Korous 000ba715dd [DirectoryWatcher][NFC] Silence warnings in release build
llvm-svn: 365968
2019-07-12 22:25:17 +00:00
Jan Korous 77dd8a7928 Reland [clang] DirectoryWatcher
This reverts commit f561227d13.

- DirectoryWatcher
- Fix the build for platforms that don't have DW implementated.
- Fix the threading dependencies (thanks to compnerd).

llvm-svn: 365954
2019-07-12 20:34:10 +00:00
Jan Korous f561227d13 Revert "Reland [clang] DirectoryWatcher"
This reverts commit fdcb7f47e7.

llvm-svn: 365948
2019-07-12 19:54:36 +00:00
Jan Korous fdcb7f47e7 Reland [clang] DirectoryWatcher
This reverts commit abce8c457d.

+ Fix the build for platforms that don't have DW implementated.

llvm-svn: 365947
2019-07-12 19:47:55 +00:00
Russell Gallop 614a78c15a Revert "[JSONCompilationDatabase] Strip distcc/ccache/gomacc wrappers from parsed commands."
New test is failing on Windows bot

This reverts commit 9c0391b36a.

llvm-svn: 365906
2019-07-12 15:15:56 +00:00
Sam McCall 9c0391b36a [JSONCompilationDatabase] Strip distcc/ccache/gomacc wrappers from parsed commands.
Summary:
It's common to use compiler wrappers by setting CC="gomacc clang++".
This results in both args appearing in compile_commands.json, and clang's driver
can't handle this.

This patch attempts to recognize this pattern (by looking for well-known
wrappers) and dropping argv0 in this case.

It conservatively ignores other cases for now:
 - wrappers with unknown names
 - wrappers that accept -flags
 - wrappers where the compiler to use is implied (usually cc or gcc)

This is done at the JSONCompilationDatabase level rather than somewhere more
fundamental, as (hopefully) this isn't a general conceptual problem, but a messy
aspect of the nature of the ecosystem around compile_commands.json.
i.e. compilation databases more tightly tied to the build system should not have
this problem.

Reviewers: phosek, klimek

Subscribers: llvm-commits

Tags: #llvm

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

llvm-svn: 365887
2019-07-12 10:11:40 +00:00
Fangrui Song ff6836f429 [test] Delete trailing spaces from YAML tests
llvm-svn: 365873
2019-07-12 05:59:28 +00:00
Alex Lorenz 9a6c17b5b8 [clang-scan-deps] Dependency directives source minimizer:
single quotes are not digit separators after a valid character literal prefix

The single quote character can act as a c++ digit separator.
However, the minimizer shouldn't treat it as such when it's actually following
a valid character literal prefix, like L, U, u, or u8.

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

llvm-svn: 365700
2019-07-10 22:00:59 +00:00
Reid Kleckner abce8c457d Revert [clang] DirectoryWatcher
This reverts r365574 (git commit 31babea94a)

llvm-svn: 365581
2019-07-09 23:22:01 +00:00
Jan Korous 31babea94a [clang] DirectoryWatcher
Asynchronously monitors specified directory for changes and passes notifications to provided callback.

Dependency for index-while-building.

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

llvm-svn: 365574
2019-07-09 22:44:48 +00:00
Ilya Biryukov 51dad4196e [Syntax] Move roles into a separate enum
To align with reviewer's suggestions.

llvm-svn: 365479
2019-07-09 13:31:43 +00:00
Ilya Biryukov 9b3f38f990 Reland r365355: [Syntax] Introduce syntax trees
With a fix to a PS4 buildbot crash.

llvm-svn: 365466
2019-07-09 11:32:13 +00:00
Simon Pilgrim 7e3b22758d Revert rL365355 : [Syntax] Introduce syntax trees
Summary:
A tooling-focused alternative to the AST. This commit focuses on the
memory-management strategy and the structure of the AST.

More to follow later:
  - Operations to mutate the syntax trees and corresponding textual
    replacements.
  - Mapping between clang AST nodes and syntax tree nodes.
  - More node types corresponding to the language constructs.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: llvm-commits, mgorny, cfe-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D61637
........
Fixes buildbots which were crashing on SyntaxTests.exe

llvm-svn: 365465
2019-07-09 11:26:35 +00:00
Balazs Keri eb79b25b44 [ASTImporter] Added visibility context check for EnumDecl.
Summary:
ASTImporter makes now difference between enums with same name in different translation
units if these are not visible outside.
("Scoped enums" are not handled yet.)

Reviewers: martong, a.sidorin, shafik, a_sidorin

Reviewed By: a_sidorin

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

Tags: #clang

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

llvm-svn: 365464
2019-07-09 11:08:18 +00:00
Ilya Biryukov b736969edd [Syntax] Introduce syntax trees
Summary:
A tooling-focused alternative to the AST. This commit focuses on the
memory-management strategy and the structure of the AST.

More to follow later:
  - Operations to mutate the syntax trees and corresponding textual
    replacements.
  - Mapping between clang AST nodes and syntax tree nodes.
  - More node types corresponding to the language constructs.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: llvm-commits, mgorny, cfe-commits

Tags: #clang, #llvm

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

llvm-svn: 365355
2019-07-08 17:25:02 +00:00
Gabor Marton e73805f80e [ASTImporter] Fix import of lambda in function param
Summary:
The current import implementation fails to import the definition of a
lambda class if the lambda class is defined in a function param.
E.g., the lambda class below will be imported without any methods:
```
  template <typename F>
  void f(F L = [](){}) {}
```

Reviewers: a_sidorin, a.sidorin, shafik

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

Tags: #clang

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

llvm-svn: 365315
2019-07-08 12:49:13 +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
Joel E. Denny 87856e739c [Rewrite] Try to fix buildbot link fail left by r365263
http://lab.llvm.org:8011/builders/clang-ppc64le-linux-multistage/builds/10272

llvm-svn: 365264
2019-07-06 16:28:32 +00:00
Joel E. Denny 7770f83d61 [Rewrite] Try to fix buildbot link fail caused by r365258
http://lab.llvm.org:8011/builders/clang-ppc64le-linux-multistage/builds/10270

llvm-svn: 365263
2019-07-06 13:44:57 +00:00
Joel E. Denny adeb5ac2d6 [Rewrite] Extend to further accept CharSourceRange
Some Rewrite functions are already overloaded to accept
CharSourceRange, and this extends others in the same manner.  I'm
calling these in code that's not ready to upstream, but I figure they
might be useful to others in the meantime.

Reviewed By: jdoerfert

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

llvm-svn: 365258
2019-07-06 02:55:06 +00:00
Kristof Umann c8499ae35a Removed the test case added in D63538 due to windows buildbot failures
llvm-svn: 365209
2019-07-05 14:22:10 +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
Kristof Umann 433edaed12 Fix a buildbot failure due to the AST's lifetime ending before the test
llvm-svn: 365181
2019-07-05 11:14:57 +00:00
Kristof Umann 2e2db937cd [analyzer][Dominators][NFC] Add unit tests
Differential Revision: https://reviews.llvm.org/D62611

llvm-svn: 365179
2019-07-05 10:16:36 +00:00
Kristof Umann d5c9d9b682 [CFG] Add a new function to get the proper condition of a CFGBlock
getTerminatorCondition() returned a condition that may be outside of the
block, while the new function returns the proper one:

if (A && B && C) {}

Return C instead of A && B && C.

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

llvm-svn: 365177
2019-07-05 09:52:00 +00:00
Tom Stellard 2e97d2aa1b cmake: Add CLANG_LINK_CLANG_DYLIB option
Summary:
Setting CLANG_LINK_CLANG_DYLIB=ON causes clang tools to link against
libclang_shared.so instead of the individual component libraries.

Reviewers: mgorny, beanz, smeenai, phosek, sylvestre.ledru

Subscribers: arphaman, cfe-commits, llvm-commits

Tags: #clang

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

llvm-svn: 365092
2019-07-03 22:45:55 +00:00
Francis Visoiu Mistrih e0308279cb [Bitcode] Move Bitstream to a separate library
This moves Bitcode/Bitstream*, Bitcode/BitCodes.h to Bitstream/.

This is needed to avoid a circular dependency when using the bitstream
code for parsing optimization remarks.

Since Bitcode uses Core for the IR part:

libLLVMRemarks -> Bitcode -> Core

and Core uses libLLVMRemarks to generate remarks (see
IR/RemarkStreamer.cpp):

Core -> libLLVMRemarks

we need to separate the Bitstream and Bitcode part.

For clang-doc, it seems that it doesn't need the whole bitcode layer, so
I updated the CMake to only use the bitstream part.

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

llvm-svn: 365091
2019-07-03 22:40:07 +00:00
Ivan Donchevskii 080014ee6d [clang-tidy] Fix the YAML created for checks like modernize-pass-by-value
Currently this check generates the replacement with the newline in the end.
The proper way to export it to YAML is to have two \n\n instead of one.
Without this fix clients should reinterpret the replacement as
"#include <utility> " instead of "#include <utility>\n"

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

llvm-svn: 365017
2019-07-03 10:21:50 +00:00
Kadir Cetinkaya 1f6d9845d8 [clang][HeaderSearch] Shorten paths for includes in mainfile's directory
Summary:
Currently HeaderSearch only looks at SearchDir's passed into it, but in
addition to those paths headers can be relative to including file's directory.

This patch makes sure that is taken into account.

Reviewers: gribozavr

Subscribers: jkorous, arphaman, cfe-commits

Tags: #clang

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

llvm-svn: 365005
2019-07-03 07:47:19 +00:00
Sam McCall 04ee232ff2 clang-format: Add new style option AlignConsecutiveMacros
This option behaves similarly to AlignConsecutiveDeclarations and
AlignConsecutiveAssignments, aligning the assignment of C/C++
preprocessor macros on consecutive lines.

I've worked in many projects (embedded, mostly) where header files full
of large, well-aligned "#define" blocks are a common pattern. We
normally avoid using clang-format on these files, since it ruins any
existing alignment in said blocks. This style option will align "simple"
PP macros (no parameters) and PP macros with parameter lists on
consecutive lines.

Related Bugzilla entry (thanks mcuddie):
https://llvm.org/bugs/show_bug.cgi?id=20637

Patch by Nick Renieris (VelocityRa)!

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

llvm-svn: 364938
2019-07-02 15:53:14 +00:00
Yitzhak Mandelbaum 727bdcb237 [LibTooling] Extend `RewriteRule` with support for adding includes.
Summary:
This revision allows users to specify the insertion of an included directive (at
the top of the file being rewritten) as part of a rewrite rule.  These
directives are bundled with `RewriteRule` cases, so that different cases can
potentially result in different include actions.

Reviewers: ilya-biryukov, gribozavr

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 364917
2019-07-02 13:11:04 +00:00
Kadir Cetinkaya 7d719b75ea [clang][ArgumentAdjusters] Do not add fsyntax-only if already exists
Reviewers: hokein

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 364904
2019-07-02 10:45:53 +00:00
Gabor Marton 4f883f1c39 [ASTImporter] Structural eq: handle DependentScopeDeclRefExpr
Summary:
Structural equivalence did not handle dependent template args properly
when the arg contained a DependentScopeDeclRefExpr.

Reviewers: a_sidorin, a.sidorin

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

Tags: #clang

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

llvm-svn: 364889
2019-07-02 07:36:39 +00:00
Artem Dergachev f301096f51 [analyzer] NFC: CallDescription: Implement describing C library functions.
When matching C standard library functions in the checker, it's easy to forget
that they are often implemented as macros that are expanded to builtins.

Such builtins would have a different name, so matching the callee identifier
would fail, or may sometimes have more arguments than expected, so matching
the exact number of arguments would fail, but this is fine as long as we have
all the arguments that we need in their respective places.

This patch adds a set of flags to the CallDescription class so that to handle
various special matching rules, and adds the first flag into this set,
which enables a more fuzzy matching for functions that
may be implemented as compiler builtins.

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

llvm-svn: 364867
2019-07-01 23:02:07 +00:00
Artem Dergachev ec8e95640f [analyzer] NFC: Add a convenient CallDescriptionMap class.
It encapsulates the procedure of figuring out whether a call event
corresponds to a function that's modeled by a checker.

Checker developers no longer need to worry about performance of
lookups into their own custom maps.

Add unittests - which finally test CallDescription itself as well.

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

llvm-svn: 364866
2019-07-01 23:02:03 +00:00
Gabor Marton 2afbfb6b22 [ASTImporter] Mark erroneous nodes in shared st
Summary:
Now we store the errors for the Decls in the "to" context too. For
that, however, we have to put these errors in a shared state (among all
the ASTImporter objects which handle the same "to" context but different
"from" contexts).

After a series of imports from different "from" TUs we have a "to" context
which may have erroneous nodes in it. (Remember, the AST is immutable so
there is no way to delete a node once we had created it and we realized
the error later.) All these erroneous nodes are marked in
ASTImporterSharedState::ImportErrors.  Clients of the ASTImporter may
use this as an input. E.g. the static analyzer engine may not try to
analyze a function if that is marked as erroneous (it can be queried via
ASTImporterSharedState::getImportDeclErrorIfAny()).

Reviewers: a_sidorin, a.sidorin, shafik

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

Tags: #clang

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

llvm-svn: 364785
2019-07-01 15:37:07 +00:00
Gabor Marton 1ad4b99d94 [ASTImporter] Mark erroneous nodes in from ctx
Summary:
During import of a specific Decl D, it may happen that some AST nodes
had already been created before we recognize an error. In this case we
signal back the error to the caller, but the "to" context remains
polluted with those nodes which had been created. Ideally, those nodes
should not had been created, but that time we did not know about the
error, the error happened later.  Since the AST is immutable (most of
the cases we can't remove existing nodes) we choose to mark these nodes
as erroneous.
Here are the steps of the algorithm:
1) We keep track of the nodes which we visit during the import of D: See
ImportPathTy.
2) If a Decl is already imported and it is already on the import path
(we have a cycle) then we copy/store the relevant part of the import
path. We store these cycles for each Decl.
3) When we recognize an error during the import of D then we set up this
error to all Decls in the stored cycles for D and we clear the stored
cycles.

Reviewers: a_sidorin, a.sidorin, shafik

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

Tags: #clang

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

llvm-svn: 364771
2019-07-01 14:19:53 +00:00
Gabor Marton 17c3eafb2e [ASTImporter] Propagate error from ImportDeclContext
Summary:
During analysis of one project we failed to import one
CXXDestructorDecl. But since we did not propagate the error in
importDeclContext we had a CXXRecordDecl without a destructor. Then the
analyzer engine had a CallEvent where the nonexistent dtor was requested
(crash).

Solution is to propagate the errors we have during importing a
DeclContext.

Reviewers: a_sidorin, a.sidorin, shafik

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

Tags: #clang

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

llvm-svn: 364752
2019-07-01 12:44:39 +00:00
Kadir Cetinkaya 0a43d1fa71 [clang][Tooling] Fix windows build-bots after rL364386
llvm-svn: 364396
2019-06-26 08:39:42 +00:00
Kadir Cetinkaya c3a7302397 [clang][Tooling] Infer target and mode from argv[0] when using JSONCompilationDatabase
Summary:
Wraps JSON compilation database with a target and mode adding database
wrapper. So that driver can correctly figure out which toolchain to use.

Note that clients that wants to make use of this target discovery mechanism
needs to link in TargetsInfos and initialize them at startup.

Reviewers: ilya-biryukov

Subscribers: mgorny, cfe-commits

Tags: #clang

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

llvm-svn: 364386
2019-06-26 07:39:03 +00:00
Gabor Marton 303c9861e9 [ASTImporter] Store import errors for Decls
Summary:
We add a new member which is a mapping from the already-imported
declarations in the "from" context to the error status of the import of
that declaration.  This map contains only the declarations that were not
correctly imported. The same declaration may or may not be included in
ImportedDecls. This map is updated continuously during imports and never
cleared (like ImportedDecls).  In Import(Decl*) we use this mapping, so
if there was a previous failed import we return with the existing error.

We add/remove from the Lookuptable in consistency with ImportedFromDecls.
When we map a decl in the 'to' context to something in the 'from'
context then and only then we add it to the lookup table. When we
remove a mapping then and only then we remove it from the lookup table.

This patch is the first in a series of patches whose aim is to further
strengthen the error handling in ASTImporter.

Reviewers: a_sidorin, a.sidorin, shafik

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

Tags: #clang

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

llvm-svn: 364279
2019-06-25 08:00:51 +00:00
Ilya Biryukov 5e69f27ef7 [Syntax] Do not glue multiple empty PP expansions to a single mapping
Summary:
This change makes sure we have a single mapping for each macro expansion,
even if the result of expansion was empty.

To achieve that, we take information from PPCallbacks::MacroExpands into
account. Previously we relied only on source locations of expanded tokens.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 364236
2019-06-24 21:39:51 +00:00
Gauthier Harnisch e1f4ba85e5 [clang] Adapt ASTMatcher to explicit(bool) specifier
Summary:
Changes:
 - add an ast matcher for deductiong guide.
 - allow isExplicit matcher for deductiong guide.
 - add hasExplicitSpecifier matcher which give access to the expression of the explicit specifier if present.

Reviewers: klimek, rsmith, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: aaron.ballman, cfe-commits

Tags: #clang

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

llvm-svn: 363855
2019-06-19 18:27:56 +00:00
Jordan Rupprecht ff384a2d1c [clang][test] Add missing LambdaTemplateParams test and migrate from getLocStart
These were removed a long time ago in r341573, but this test was missed because it was not in cmake

llvm-svn: 363848
2019-06-19 17:43:58 +00:00
Ilya Biryukov 26c066d66d [Syntax] Fix a crash when dumping empty token buffer
llvm-svn: 363801
2019-06-19 13:56:36 +00:00
Ilya Biryukov 5aed309a4f [Syntax] Add a helper to find expansion by its first spelled token
Summary: Used in clangd for a code tweak that expands a macro.

Reviewers: sammccall

Reviewed By: sammccall

Subscribers: kadircet, cfe-commits

Tags: #clang

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

llvm-svn: 363698
2019-06-18 16:27:27 +00:00
Dmitri Gribenko 31d68804fd Added AST matcher for ignoring elidable constructors
Summary: Added AST matcher for ignoring elidable move constructors

Reviewers: hokein, gribozavr

Reviewed By: hokein, gribozavr

Subscribers: cfe-commits

Tags: #clang

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

Patch by Johan Vikström.

llvm-svn: 363262
2019-06-13 13:48:24 +00:00
Alex Lorenz 514cfdb18d [test] Reinstate the assignment to the diagnostic log in the unittest
from r363009

The diagnostic log is now set to "-" which forces it to use STDERR
instead of the filesystem. A new comment is added to explain why
the assignment is needed in the test.

llvm-svn: 363199
2019-06-12 20:35:44 +00:00
Erich Keane d65ef6735a Fix for r42230, MSVC test failure in DependencyDirectivesSourceMinimizerTest.cpp
r362459 introduced DependencyDirectivesSourceMinimizerTest.cpp, which
hits an MSVC bug:
developercommunity.visualstudio.com/content/problem/67300/stringifying-raw-string-literal.html

This only happens when the parameter to a macro is stringified in the
macro.  This patch removes the string from the assert so that the
warning no longer happens.

llvm-svn: 363074
2019-06-11 14:58:26 +00:00
Nikolai Kosjar 8edd8da487 [libclang] Allow skipping warnings from all included files
Depending on the included files and the used warning flags, e.g. -
Weverything, a huge number of warnings can be reported for included
files. As processing that many diagnostics comes with a performance
impact and not all clients are interested in those diagnostics, add a
flag to skip them.

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

llvm-svn: 363067
2019-06-11 14:14:24 +00:00
Gabor Marton dd2b76e13e [ASTImporter] Fix unhandled cases in ASTImporterLookupTable
Summary:
In most cases the FriendDecl contains the declaration of the befriended
class as a child node, so it is discovered during the recursive
visitation. However, there are cases when the befriended class is not a
child, thus it must be fetched explicitly from the FriendDecl, and only
then can we add it to the lookup table.
(Note, this does affect only CTU and does not affect LLDB, because we
cannot and do not use the ASTImporterLookupTable in LLDB.)

Reviewers: a_sidorin, a.sidorin, shafik

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

Tags: #clang

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

llvm-svn: 363062
2019-06-11 13:35:25 +00:00
Ilya Biryukov edea75d6f4 [Frontend] Avoid creating auxilary files during a unit test. NFC
A test added in r363009 logs diagnostics into a file inside current
working directory. This breaks when the directory is not writable.

This looks like a debugging output in the first place, the test passes
without it anyway.

llvm-svn: 363041
2019-06-11 09:52:30 +00:00
Alex Lorenz 88377d8db7 [Frontend] SetUpDiagnosticLog should handle unowned diagnostic consumer
in the compiler

The function SetUpDiagnosticLog that was called from createDiagnostics didn't
handle the case where the diagnostics engine didn't own the diagnostics consumer.
This is a potential problem for a clang tool, in particular some of the follow-up
patches for clang-scan-deps will need this fix.

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

llvm-svn: 363009
2019-06-10 23:32:42 +00:00
Francois Ferrand e8a301f87f clang-format: better handle namespace macros
Summary:
Other macros are used to declare namespaces, and should thus be handled
similarly. This is the case for crpcut's TESTSUITE macro, or for
unittest-cpp's SUITE macro:

      TESTSUITE(Foo) {
      TEST(MyFirstTest) {
        assert(0);
      }
      } // TESTSUITE(Foo)

This patch deals with this cases by introducing a new option to specify
lists of namespace macros. Internally, it re-uses the system already in
place for foreach and statement macros, to ensure there is no impact on
performance.

Reviewers: krasimir, djasper, klimek

Reviewed By: klimek

Subscribers: acoomans, cfe-commits, klimek

Tags: #clang

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

llvm-svn: 362740
2019-06-06 20:06:23 +00:00
Kadir Cetinkaya 51f85b40bc [clang][HeaderSearch] Consider all path separators equal
Reviewers: ilya-biryukov, sammccall

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 362731
2019-06-06 18:49:16 +00:00
Yitzhak Mandelbaum 2e4a628c06 [LibTooling] Add insert/remove convenience functions for creating `ASTEdit`s.
Summary: `change()` is an all purpose function; the revision adds simple shortcuts for the specific operations of inserting (before/after) or removing source.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 362707
2019-06-06 14:20:29 +00:00
Pengxuan Zheng e34d1a4e07 [cmake] Remove duplicate TestingSupport library for linking
Summary: This patch cleans up a duplicate use of TestingSupport library.

Subscribers: mgorny, cfe-commits

Tags: #clang

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

llvm-svn: 362637
2019-06-05 19:44:08 +00:00
Ilya Biryukov f4302ad35e [Syntax] Do not depend on llvm targets for Syntax tests. NFC
They are not required and only slow down the build.

llvm-svn: 362530
2019-06-04 17:15:48 +00:00
Alex Lorenz 6e2d36b60b Add clang source minimizer that reduces source to directives
that might affect the dependency list for a compilation

This commit introduces a dependency directives source minimizer to clang
that minimizes header and source files to the minimum necessary preprocessor
directives for evaluating includes. It reduces the source down to #define, #include,

The source minimizer works by lexing the input with a custom fast lexer that recognizes
the preprocessor directives it cares about, and emitting those directives in the minimized source.
It ignores source code, comments, and normalizes whitespace. It gives up and fails if seems
any directives that it doesn't recognize as valid (e.g. #define 0).

In addition to the source minimizer this patch adds a
-print-dependency-directives-minimized-source CC1 option that allows you to invoke the minimizer
from clang directly.

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

llvm-svn: 362459
2019-06-03 22:59:17 +00:00
Francois Ferrand c5227a1f53 [clang-format] Allow configuring list of function-like macros that resolve to a type
Summary:
Adds a `TypenameMacros` configuration option that causes certain identifiers to be handled in a way similar to `typeof()`.

This is enough to:
- Prevent misinterpreting declarations of pointers to such types as expressions (`STACK_OF(int) * foo` -> `STACK_OF(int) *foo`),
- Avoid surprising line breaks in variable/struct field declarations (`STACK_OF(int)\nfoo;` -> `STACK_OF(int) foo;`, see https://bugs.llvm.org/show_bug.cgi?id=30353).

Reviewers: Typz, krasimir, djasper

Reviewed By: Typz

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361986
2019-05-29 16:30:47 +00:00
Francois Ferrand 0a729261e2 [NFC] clang-format: Use LLVM style in NamespaceEndCommentsFixerTest
As pointed out in https://reviews.llvm.org/D37813#inline-555026, the
code which is formatted does not match LLVM formatting style.

Technically this is not a problem since these tests bypass most of the
formatter, but it can be misleading.

llvm-svn: 361984
2019-05-29 16:22:43 +00:00
Yitzhak Mandelbaum e1312c54d3 [LibTooling] Add `before` and `after` selectors for selecting point-ranges relative to nodes.
Summary:
The `before` and `after` selectors allow users to specify a zero-length range --
a point -- at the relevant location in an AST-node's source.  Point ranges can
be useful, for example, to insert a change using an API that takes a range to be
modified (e.g. `tooling::change()`).

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361955
2019-05-29 12:40:36 +00:00
Ilya Biryukov b1296faee0 [CodeComplete] Set preferred type for qualified-id
Reviewers: kadircet

Reviewed By: kadircet

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361838
2019-05-28 15:21:03 +00:00
Kadir Cetinkaya 20c3c4fe5a [clang] Respect TerseOutput when printing lambdas
Reviewers: ilya-biryukov, hokein, sammccall

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361771
2019-05-27 16:20:45 +00:00
Balazs Keri c8272195cd [ASTImporter] Added visibility context check for CXXRecordDecl.
Summary:
ASTImporter makes now difference between classes with same name in different
translation units if these are not visible outside. These classes are not linked
into one decl chain.

Reviewers: martong, a.sidorin, shafik

Reviewed By: shafik

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

Tags: #clang

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

llvm-svn: 361752
2019-05-27 09:36:00 +00:00
Duncan P. N. Exon Smith d4a9cae965 Add missing newline at end of file
llvm-svn: 361708
2019-05-25 22:38:02 +00:00
Nico Weber bab1d8edcf Rename clangToolingRefactor to clangToolingRefactoring for consistency with its directory
See "[cfe-dev] The name of clang/lib/Tooling/Refactoring".

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

llvm-svn: 361684
2019-05-25 00:27:19 +00:00
Yitzhak Mandelbaum fab7205ac4 [LibTooling] Add Explanation parameter to `makeRule`.
Summary:
Conceptually, a single-case RewriteRule has a matcher, edit(s) and an (optional)
explanation. `makeRule` previously only took the matcher and edit(s). This
change adds (optional) support for the explanation.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361643
2019-05-24 15:11:45 +00:00
Thomas Lively a8e0d49c0c Fix unresolved symbols when linking tools/clang/unittests/Tooling/ToolingTests
Summary: Add correct cmake dependencies so that `ToolingTests` link
successfully.

Patch by Guanzhong Chen

Reviewers: tlively, aheejin

Reviewed By: tlively

Subscribers: mgorny, cfe-commits

Tags: #clang

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

llvm-svn: 361536
2019-05-23 18:55:00 +00:00
Yitzhak Mandelbaum 1f46d524a1 [LibTooling] Update Stencil to use RangeSelector
Add support for creating a `StencilPart` from any `RangeSelector`, which
broadens the scope of `Stencil`.

Correspondingly, deprecate Stencil's specialized combinators `node` and `sNode`
in favor of using the new `selection` combinator directly (with the appropriate
range selector).

Reviewers: sbenza

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361413
2019-05-22 18:03:00 +00:00
Yitzhak Mandelbaum 3ec50e292f [LibTooling] Update Transformer to use RangeSelector instead of NodePart enum.
Transformer provides an enum to indicate the range of source text to be edited.
That support is now redundant with the new (and more general) RangeSelector
library, so we remove the custom enum support in favor of supporting any
RangeSelector.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361392
2019-05-22 14:48:19 +00:00
Ilya Biryukov e7230ea7c9 Reland r361148 with a fix to the buildbot failure.
Reverted in r361377.
Also reland the '.gn' files (reverted in r361389).

llvm-svn: 361391
2019-05-22 14:44:45 +00:00
Russell Gallop fd22d7f861 Revert r361148 "[Syntax] Introduce TokenBuffer, start clangToolingSyntax library"
Also reverted r361264 "[Syntax] Rename TokensTest to SyntaxTests. NFC"
which built on it. This is because there were hitting an assert on bots

http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast
http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast

llvm-svn: 361377
2019-05-22 12:50:52 +00:00
Yitzhak Mandelbaum f0d9cfa591 [LibTooling] Address post-commit feedback for r361152
Fixes a redundant dependency and moves another to its proper place.

Reviewers: thakis

Subscribers: mgorny, cfe-commits

Tags: #clang

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

llvm-svn: 361285
2019-05-21 18:48:58 +00:00
Ilya Biryukov 6c0531222a [Syntax] Rename TokensTest to SyntaxTests. NFC
To be more consistent with conventions used in the codebase. The new
name will be a better fit when more bits of the syntax library land.

llvm-svn: 361264
2019-05-21 14:37:41 +00:00
Nikolai Kosjar 295c19e948 [Preamble] Reuse preamble even if an unsaved file does not exist
When a preamble is created an unsaved file not existing on disk is
already part of PrecompiledPreamble::FilesInPreamble. However, when
checking whether the preamble can be re-used, a failed stat of such an
unsaved file invalidated the preamble, which led to pointless and time
consuming preamble regenerations on subsequent reparses.

Do not require anymore that unsaved files should exist on disk.

This avoids costly preamble invalidations depending on timing issues for
the cases where the file on disk might be removed just to be regenerated
a bit later.

It also allows an IDE to provide in-memory files that might not exist on
disk, e.g. because the build system hasn't generated those yet.

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

llvm-svn: 361226
2019-05-21 07:26:59 +00:00
Nico Weber 4522e26696 Try to fix build with older gccs after r361152
Also merge the cmake change there to the gn build.

llvm-svn: 361209
2019-05-21 00:27:26 +00:00
Dmitri Gribenko 76e3a04951 Renamed `apply` to `select` to avoid ADL conflict with `std::apply`
Summary:
`std::apply` in C++14 and above is defined with two unrestricted arguments, and
it wins overload resolution in this case.

Reviewers: ilya-biryukov

Subscribers: cfe-commits, ymandel

Tags: #clang

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

llvm-svn: 361170
2019-05-20 16:30:49 +00:00
Yitzhak Mandelbaum ef29c6a63e [LibTooling] Fix build break in test after r361152.
r361152 broke gcc builds.

llvm-svn: 361160
2019-05-20 14:44:40 +00:00
Yitzhak Mandelbaum 27872b8d55 [LibTooling] Add RangeSelector library for defining source ranges based on bound AST nodes.
Summary:

The RangeSelector library defines a combinator language for specifying source
ranges based on bound ids for AST nodes.  The combinator approach follows the
design of the AST matchers.  The RangeSelectors defined here will be used in
both RewriteRule, for specifying source affected by edit, and in Stencil for
specifying source to use constructively in a replacement.

Reviewers: ilya-biryukov

Subscribers: mgorny, cfe-commits

Tags: #clang

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

llvm-svn: 361152
2019-05-20 13:15:14 +00:00
Ilya Biryukov ddd5d5dbc8 [Syntax] Introduce TokenBuffer, start clangToolingSyntax library
Summary:
TokenBuffer stores the list of tokens for a file obtained after
preprocessing. This is a base building block for syntax trees,
see [1] for the full proposal on syntax trees.

This commits also starts a new sub-library of ClangTooling, which
would be the home for the syntax trees and syntax-tree-based refactoring
utilities.

[1]: https://lists.llvm.org/pipermail/cfe-dev/2019-February/061414.html

Reviewers: gribozavr, sammccall

Reviewed By: sammccall

Subscribers: mgrang, riccibruno, Eugene.Zelenko, mgorny, jdoerfert, cfe-commits

Tags: #clang

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

llvm-svn: 361148
2019-05-20 13:00:42 +00:00
Gabor Marton 1d51e3e6ee [ASTImporter] Enable disabled but passing tests
Reviewers: a_sidorin, a.sidorin, shafik

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

Tags: #clang

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

llvm-svn: 361139
2019-05-20 10:38:14 +00:00
Stephen Kelly ad3314b146 Add a Visit overload for DynTypedNode to ASTNodeTraverser
Reviewers: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361117
2019-05-19 13:03:48 +00:00
Nico Weber e78ac9cc72 Revert r361033 "Add a Visit overload for DynTypedNode to ASTNodeTraverser"
It fails to build on some bots.

Also revert follow-up r361055.

llvm-svn: 361059
2019-05-17 18:31:24 +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
Yitzhak Mandelbaum 8369a9beb7 [LibTooling] Add support to Transformer for composing rules as an ordered choice.
This revision updates `RewriteRule` to support multiple subrules that are
interpreted as an ordered-choice (apply the first one that matches). With this
feature, users can write the rules that appear later in the list of subrules
knowing that previous rules' patterns *have not matched*, freeing them from
reasoning about those cases in the current pattern.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361037
2019-05-17 14:23:33 +00:00
Stephen Kelly 0855896c68 Add a Visit overload for DynTypedNode to ASTNodeTraverser
Reviewers: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 361033
2019-05-17 13:55:28 +00:00
Stephen Kelly d147cea3b9 Move TraversalKind enum to ast_type_traits
Summary:
Make it usable outside of ASTMatchFinder.  This will make it possible to
use this enum to control whether certain implicit nodes are skipped
while AST dumping for example.

Reviewers: klimek, aaron.ballman

Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 360920
2019-05-16 17:57:38 +00:00