Commit Graph

250 Commits

Author SHA1 Message Date
Galina Kistanova 45fbb597ec Added braces to work around gcc warning in googletest: suggest explicit braces to avoid ambiguous 'else'. NFC.
llvm-svn: 305507
2017-06-15 21:01:24 +00:00
Richard Smith d9259c2f5e Remove 'Filename' parameter from BeginSourceFileAction.
No-one was using this, and it's not meaningful in general -- FrontendActions
can be run on inputs that don't have a corresponding source file. The current
frontend input can be obtained by asking the FrontendAction if any future
action actually needs it.

llvm-svn: 305045
2017-06-09 01:36:10 +00:00
Serge Pavlov c46064c2a9 Method loadFromCommandLine should be able to report errors
Now FixedCompilationDatabase::loadFromCommandLine has no means to report
which error occurred if it fails to create compilation object. This is
a block for implementing D33013, because after that change driver will
refuse to create compilation if command line contains erroneous options.

This change adds additional argument to loadFromCommandLine, which is
assigned error message text if compilation object was not created. This is
the same way as other methods of CompilationDatabase report failure.

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

llvm-svn: 303741
2017-05-24 11:57:37 +00:00
Alex Lorenz 3b21d372c2 [AST] RecursiveASTVisitor should not crash on lambdas with type attributes
rdar://31960860

llvm-svn: 302689
2017-05-10 16:21:00 +00:00
Eric Liu fc9213e0e5 Add ASTMatchRefactorer and ReplaceNodeWithTemplate to RefactoringCallbacks
Summary: This is the first change as part of developing a clang-query based search and replace tool.

Reviewers: klimek, bkramer, ioeric, sbenza, jbangert

Reviewed By: ioeric, jbangert

Subscribers: sbenza, ioeric, cfe-commits

Patch by Julian Bangert!

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

llvm-svn: 302624
2017-05-10 07:48:45 +00:00
Rui Ueyama 0fcbb2893e Revert r301487: Replace HashString algorithm with xxHash64
This reverts commit r301487 to make buildbots green.

llvm-svn: 301491
2017-04-26 23:15:10 +00:00
Rui Ueyama 87b30ac9d3 Replace HashString algorithm with xxHash64
The previous algorithm processed one character at a time, which is very
painful on a modern CPU. Replace it with xxHash64, which both already
exists in the codebase and is fairly fast.

Patch from Scott Smith!

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

llvm-svn: 301487
2017-04-26 22:45:04 +00:00
Haojian Wu ce27e59b3e Add `replace` interface with range in AtomicChange.
Reviewers: ioeric

Reviewed By: ioeric

Subscribers: alexshap, klimek, cfe-commits

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

llvm-svn: 299073
2017-03-30 13:07:38 +00:00
Juergen Ributzka abbef0ef07 Revert "Added `applyAtomicChanges` function."
This broke GreenDragon:
http://lab.llvm.org:8080/green/job/clang-stage2-cmake-modulesRDA_build/4776/

Reverting this commit and all follow-up commits.

llvm-svn: 298967
2017-03-29 00:24:36 +00:00
Juergen Ributzka c9b250611f Revert "Try to unbreak buildbots after r298913."
llvm-svn: 298966
2017-03-29 00:24:34 +00:00
Eric Liu be8d7a32c2 Try to unbreak buildbots after r298913.
llvm-svn: 298919
2017-03-28 13:56:19 +00:00
Eric Liu ea5c4a7ca3 Added `applyAtomicChanges` function.
Summary: ... which applies a set of `AtomicChange`s on code.

Reviewers: klimek, djasper

Reviewed By: djasper

Subscribers: cfe-commits

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

llvm-svn: 298913
2017-03-28 13:05:32 +00:00
Eric Liu 373c182a07 Add missing implementation for AtomicChange::replace(...)
Summary: Just realized the implementation is missing...

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

llvm-svn: 297289
2017-03-08 15:53:10 +00:00
Eric Liu 9e745b7292 Introducing clang::tooling::AtomicChange for refactoring tools.
Summary:
An AtomicChange is used to create and group a set of source edits, e.g.
replacements or header insertions. Edits in an AtomicChange should be related,
e.g. replacements for the same type reference and the corresponding header
insertion/deletion.

An AtomicChange is uniquely identified by a key position and will either be
fully applied or not applied at all. The key position should be the location
of the key syntactical element that is being changed, e.g. the call to a
refactored method.

Next step: add a tool that applies AtomicChange.

Reviewers: klimek, djasper

Reviewed By: klimek

Subscribers: alexshap, cfe-commits, djasper, mgorny

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

llvm-svn: 296616
2017-03-01 13:14:01 +00:00
Alexander Kornienko 9bab199146 [clang-tidy] Add check name to YAML export
Add a field indicating the associated check for every replacement to the YAML
report generated with the '-export-fixes' option.  Update
clang-apply-replacements to handle the new format.

Patch by Alpha Abdoulaye!

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

llvm-svn: 290892
2017-01-03 14:35:47 +00:00
Richard Smith 30e304e2a6 Remove custom handling of array copies in lambda by-value array capture and
copy constructors of classes with array members, instead using
ArrayInitLoopExpr to represent the initialization loop.

This exposed a bug in the static analyzer where it was unable to differentiate
between zero-initialized and unknown array values, which has also been fixed
here.

llvm-svn: 289618
2016-12-14 00:03:17 +00:00
Daniel Jasper 03a04fe95f clang-format: Separate out a language kind for ObjC.
While C(++) and ObjC are generally formatted the same way and can be
mixed, people might want to choose different styles based on the
language. This patch recognizes .m and .mm files as ObjC and also
implements a very crude detection of whether or not a .h file contains
ObjC code. This can be improved over time.

Also move most of the ObjC tests into their own test file to keep file
size maintainable.

llvm-svn: 289428
2016-12-12 12:42:29 +00:00
Joerg Sonnenberger 399aea300f Extend CompilationDatabase by a field for the output filename
In bigger projects like an Operating System, the same source code is
often compiled in slightly different ways. This could be the difference
between PIC and non-PIC code for static vs dynamic libraries, it could
also be the difference between size optimised versions of tools for
ramdisk images. At the moment, the compilation database has no way to
distinguish such cases. As first step, add a field in the JSON format
for it and process it accordingly.

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

llvm-svn: 288436
2016-12-01 23:37:45 +00:00
Reid Kleckner 9e749f6636 Avoid lambdas in default member initializers to work around clang bug
On Windows, Clang is mangling lambdas in default member initializers
incorrectly. See PR31197.

This is causing redness on the self-host bots. Work around the problem
locally so we aren't blind to further issues.

llvm-svn: 288089
2016-11-28 23:58:04 +00:00
Eric Liu 6135581cdf Do not do raw name replacement when FromDecl is a class forward-declaration.
Summary:
If the `FromDecl` is a class forward declaration, the reference is
still considered as referring to the original definition given the nature
of forward-declarations, so we can't do a raw name replacement in this case.

Reviewers: bkramer

Subscribers: cfe-commits, klimek

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

llvm-svn: 287929
2016-11-25 16:02:49 +00:00
Eric Liu eddec09ee4 Consider nested namespaces in the canonical namespace as canonical as well.
Summary:
For example, this case was missed when looking for different but canonical
namespaces. UseContext in this case should be considered as in the canonical
namespace.
```
namespace a { namespace b { <FromContext> } }
namespace a { namespace b { namespace c { <UseContext> } } }
```
Added some commenting.

Reviewers: bkramer

Subscribers: klimek, cfe-commits

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

llvm-svn: 287924
2016-11-25 12:39:03 +00:00
Eric Liu e86a5f4c65 Make llvm::Error generated from replacement interfaces more specific.
Summary:
The new error information contains the type of error (e.g. overlap or bad file path)
and the replacement(s) that is causing the error. This enables us to resolve some errors.
For example, for insertion at the same location conflict, we need to know the
existing replacement which conflicts with the new replacement in order to calculate
the new position to be insert before/after the existing replacement (for merging).

Reviewers: klimek, bkramer

Subscribers: djasper, cfe-commits

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

llvm-svn: 287639
2016-11-22 13:46:42 +00:00
Eric Liu 6b3a7ccc7c Fix memory leak caused by r286096.
llvm-svn: 286132
2016-11-07 18:40:41 +00:00
Eric Liu cf2913c6f1 Deduplicate replacements by FileEntry instead of file names.
Summary:
The current version does not deduplicate equivalent file paths correctly.
For example, a relative path and an absolute path are considered inequivalent.
Comparing FileEnry addresses these issues.

Reviewers: djasper

Subscribers: alexshap, klimek, cfe-commits

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

llvm-svn: 286096
2016-11-07 06:08:23 +00:00
Aaron Ballman 6b42a5b0fd Turn on the /bigobj switch for RecursiveASTVisitorTest.cpp; we are now bumping up against that limit with MSVC 2015 in Win64 debug build mode.
llvm-svn: 285810
2016-11-02 14:31:36 +00:00
Malcolm Parsons 9bd85d2286 [RecursiveASTVisitor] Visit the implicit expression of a CXXDefaultArgExpr
Summary:
The matcher
varDecl(hasDescendant(
    callExpr(hasDeclaration(functionDecl(unless(isNoThrow()))))))
didn't match calls from default arguments because the expression
for a CXXDefaultArgExpr was not visited.

Reviewers: klimek, jdennett, alexfh, aaron.ballman

Subscribers: aaron.ballman, cfe-commits

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

llvm-svn: 285239
2016-10-26 20:39:54 +00:00
Eric Liu c45343ea28 Try to fix windows bot file path style failure caused by r284219.
llvm-svn: 284222
2016-10-14 10:10:26 +00:00
Eric Liu cefe763dd2 Deduplicate sets of replacements by file names.
Summary:
If there are multiple <File, Replacements> pairs with the same file
path after removing dots, we only keep one pair (with path after dots being
removed) and discard the rest.

Reviewers: djasper

Subscribers: klimek, hokein, bkramer, cfe-commits

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

llvm-svn: 284219
2016-10-14 09:32:06 +00:00
Eric Liu 6ef82b6754 Merge conflicting replacements when they are order-independent.
Summary:
Now two replacements are considered order-independent if applying them in
either order produces the same result. These include (but not restricted
to) replacements that:
  - don't overlap (being directly adjacent is fine) and
  - are overlapping deletions.
  - are insertions at the same offset and applying them in either order
    has the same effect, i.e. X + Y = Y + X if one inserts text X and the
    other inserts text Y.

Discussion about this design can be found in D24717

Reviewers: djasper, klimek

Subscribers: omtcyfz, cfe-commits

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

llvm-svn: 282577
2016-09-28 11:02:16 +00:00
Eric Liu 9df9b6fd6d Recommit r281457 "Supports adding insertion around non-insertion replacements".
Summary:
Diff to r281457:
- added a test case `CalculateRangesOfInsertionAroundReplacement`.

Reviewers: djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 281891
2016-09-19 08:40:42 +00:00
Artem Belevich 05a4034bc3 Revert r281457 "Supports adding insertion around non-insertion replacements."
Commit was breaking our internal tests.

llvm-svn: 281557
2016-09-14 23:03:06 +00:00
Eric Liu ac73ea34a4 Supports adding insertion around non-insertion replacements.
Summary:
Extend `tooling::Replacements::add()` to support adding order-independent replacements.

Two replacements are considered order-independent if one of the following conditions is true:
  - They do not overlap. (This is already supported.)
  - One replacement is insertion, and the other is a replacement with
    length > 0, and the insertion is adjecent to but not contained in the
    other replacement. In this case, the replacement should always change
    the original code instead of the inserted text.

Reviewers: klimek, djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 281457
2016-09-14 13:04:51 +00:00
Olivier Goffart b37a5e3a71 Fix colored diagnostics from tools
r271042 changed the way the diagnostic arguments are parsed. It assumes that
the diagnostics options were already parsed by the "Driver".
For tools using clang::Tooling, the diagnostics argument were not parsed.

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

llvm-svn: 280118
2016-08-30 17:42:29 +00:00
Zachary Turner 9e60a2ad73 Resubmit "[Tooling] Parse compilation database command lines on Windows."
This patch introduced the ability to decide at runtime whether to parse
JSON compilation database command lines using Gnu syntax or Windows
syntax.  However, there were many existing unit tests written that
hardcoded Gnu-specific paths.  These tests were now failing because
the auto-detection logic was choosing to parse them using Windows
rules.

This resubmission of the patch fixes this by introducing an enum
which defines the syntax mode, which defaults to auto-detect, but
for which the unit tests force Gnu style parsing.

Reviewed By: alexfh
Differential Revision: https://reviews.llvm.org/D23628

llvm-svn: 279120
2016-08-18 19:31:48 +00:00
Martin Bohme d5f94a6a59 Visit lambda capture inits from RecursiveASTVisitor::TraverseLambdaCapture().
Summary:
rL277342 made RecursiveASTVisitor visit lambda capture initialization
expressions (these are the Exprs in LambdaExpr::capture_inits()).

jdennett identified two issues with rL277342 (see comments there for details):

- It visits initialization expressions for implicit lambda captures, even if
  shouldVisitImplicitCode() returns false.

- It visits initialization expressions for init captures twice (because these
  were already traveresed in TraverseLambdaCapture() before rL277342)

This patch fixes these issues and moves the code for traversing initialization
expressions into TraverseLambdaCapture().

This patch also makes two changes required for the tests:

- It adds Lang_CXX14 to the Language enum in TestVisitor.

- It adds a parameter to ExpectedLocationVisitor::ExpectMatch() that specifies
  the number of times a match is expected to be seen.

Reviewers: klimek, jdennett, alexfh

Subscribers: cfe-commits

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

llvm-svn: 278933
2016-08-17 14:59:53 +00:00
Eric Liu 73337f3dfa Fixes calculateRangesAfterReplacements crash when Replacements is empty.
Reviewers: klimek, djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 278004
2016-08-08 13:37:39 +00:00
Manuel Klimek 16c6d0ac37 Fix bug in conflict check for Replacements::add().
We would not detect conflicts when inserting insertions at the same
offset as previously contained replacements.

llvm-svn: 277603
2016-08-03 15:12:00 +00:00
Manuel Klimek dcb910b1cf Fix quadratic runtime when adding items to tooling::Replacements.
Previously, we would search through all replacements when inserting a
new one to check for overlaps. Instead, make use of the fact that we
already have a set of replacments without overlaps to find the potential
overlap with lower_bound.

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

llvm-svn: 277597
2016-08-03 14:12:17 +00:00
Martin Bohme 78bac52e14 Make RecursiveASTVisitor visit lambda capture initialization expressions
Summary:
Lambda capture initializations are part of the explicit source code and
therefore should be visited by default but, so far, RecursiveASTVisitor does not
visit them.

This appears to be an oversight. Because the lambda body needs custom handling
(calling TraverseLambdaBody()), the DEF_TRAVERSE_STMT for LambdaExpr sets
ShouldVisitChildren to false but then neglects to visit the lambda capture
initializations. This patch adds code to visit the expressions associated with
lambda capture initializations.

Reviewers: klimek

Subscribers: cfe-commits

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

llvm-svn: 277342
2016-08-01 12:15:46 +00:00
Eric Liu 40ef2fb363 Implement tooling::Replacements as a class.
Summary:
- Implement clang::tooling::Replacements as a class to provide interfaces to
  control how replacements for a single file are combined and provide guarantee
  on the order of replacements being applied.
- tooling::Replacements only contains replacements for the same file now.
  Use std::map<std::string, tooling::Replacements> to represent multi-file
  replacements.
- Error handling for the interface change will be improved in followup patches.

Reviewers: djasper, klimek

Subscribers: cfe-commits

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

llvm-svn: 277335
2016-08-01 10:16:37 +00:00
Martin Bohme edb25bdb07 Revert "Make RecursiveASTVisitor visit lambda capture initialization expressions"
This reverts commit r276755.

(Broke clang-tidy check modernize-loop-convert.)

llvm-svn: 276759
2016-07-26 16:01:55 +00:00
Martin Bohme d9a3521552 Make RecursiveASTVisitor visit lambda capture initialization expressions
Summary:
Lambda capture initializations are part of the explicit source code and therefore should be visited by default but, so far, RecursiveASTVisitor does not visit them.

This appears to be an oversight. Because the lambda body needs custom handling (calling TraverseLambdaBody()), the DEF_TRAVERSE_STMT for LambdaExpr sets ShouldVisitChildren to false but then neglects to visit the lambda capture initializations. This patch adds code to visit the expressions associated with lambda capture initializations.

Reviewers: klimek

Subscribers: klimek, cfe-commits

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

llvm-svn: 276755
2016-07-26 15:19:10 +00:00
Eric Liu df5bcea088 [Tooling] skip anonymous namespaces when checking if typeLoc references a type decl from a different canonical namespace.
Summary:
[Tooling] skip anonymous namespaces when checking if typeLoc
references a type decl from a different canonical namespace.

Reviewers: bkramer

Subscribers: cfe-commits, klimek

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

llvm-svn: 276754
2016-07-26 14:53:05 +00:00
Mehdi Amini 9670f847b8 [NFC] Header cleanup
Summary: Removed unused headers, replaced some headers with forward class declarations

Patch by: Eugene <claprix@yandex.ru>

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

llvm-svn: 275882
2016-07-18 19:02:11 +00:00
Eric Liu 4f8d99433d Make tooling::applyAllReplacements return llvm::Expected<string> instead of empty string to indicate potential error.
Summary:
return llvm::Expected<> to carry error status and error information.
This is the first step towards introducing "Error" into tooling::Replacements.

Reviewers: djasper, klimek

Subscribers: ioeric, klimek, cfe-commits

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

llvm-svn: 275062
2016-07-11 13:53:12 +00:00
Siva Chandra 0ea80f883c [Tooling] Add optional argument to getFullyQualifiedName to prepend "::".
Reviewers: rsmith, saugustine, rnk

Subscribers: klimek, cfe-commits

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

llvm-svn: 274185
2016-06-29 22:38:59 +00:00
Eric Liu 8b636db8d4 Added calculateRangesAfterReplaments() to calculate affacted ranges in the new code.
Summary:
Added calculateRangesAfterReplaments() to calculate original ranges as well as
newly affacted ranges in the new code.

Reviewers: klimek, djasper

Subscribers: cfe-commits, klimek

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

llvm-svn: 273290
2016-06-21 17:56:31 +00:00
NAKAMURA Takumi c690ee046e ToolingTests/runToolOnCode.TestSkipFunctionBody: Appease msc targets.
llvm-svn: 272985
2016-06-17 02:04:51 +00:00
Olivier Goffart f9e890cbf9 Fix a few issues while skipping function bodies
- In functions with try { } catch { }, only the try block would be
   skipped, not the catch blocks

 - The template functions would still be parsed.

 - The initializers within a constructor would still be parsed.

 - The inline functions within class would still be stored, only to be
   discared later.

 - Invalid code with try would assert (as in "int foo() try assert_here")

This attempt to do even less while skipping function bodies.

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

llvm-svn: 272963
2016-06-16 21:40:06 +00:00
Etienne Bergeron 53276d1221 [tooling] FixItHint Tooling refactoring
Summary:
This is the refactoring to lift some FixItHint into tooling.
used by: http://reviews.llvm.org/D19807

Reviewers: klimek, alexfh

Subscribers: cfe-commits

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

llvm-svn: 269188
2016-05-11 14:31:39 +00:00