Commit Graph

62 Commits

Author SHA1 Message Date
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
Haojian Wu f2879d8a48 [clang-tidy] Add fix descriptions to clang-tidy checks.
Summary:
Motivation/Context: in the code review system integrating with clang-tidy,
clang-tidy doesn't provide a human-readable description of the fix. Usually
developers have to preview a code diff (before vs after apply the fix) to
understand what the fix does before applying a fix.

This patch proposes that each clang-tidy check provides a short and
actional fix description that can be shown in the UI, so that users can know
what the fix does without previewing diff.

This patch extends clang-tidy framework to support fix descriptions (will add implementations for
existing checks in the future). Fix descriptions and fixes are emitted via diagnostic::Note (rather than
attaching the main warning diagnostic).

Before this patch:

```
void MyCheck::check(...) {
   ...
   diag(loc, "my check warning") <<  FixtItHint::CreateReplacement(...);
}
```

After:

```
void MyCheck::check(...) {
   ...
   diag(loc, "my check warning"); // Emit a check warning
   diag(loc, "fix description", DiagnosticIDs::Note) << FixtItHint::CreateReplacement(...); // Emit a diagnostic note and a fix
}
```

Reviewers: sammccall, alexfh

Reviewed By: alexfh

Subscribers: MyDeveloperDay, Eugene.Zelenko, aaron.ballman, JonasToth, xazax.hun, jdoerfert, cfe-commits

Tags: #clang-tools-extra, #clang

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

llvm-svn: 358576
2019-04-17 12:53:59 +00:00
Chandler Carruth 2946cd7010 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351636
2019-01-19 08:50:56 +00:00
Eric Liu 25b689ee11 Deduplicate replacements from diagnostics.
Summary:
After r329813, clang-apply-replacements stopped deduplicating identical
replacements; however, tools like clang-tidy relies on the deduplication of
identical dignostics replacements from different TUs to apply fixes correctly.

This change partially roll back the behavior by deduplicating changes from
diagnostics. Ideally, we should deduplicate on diagnostics level, but we need to
figure out an effecient way.

Reviewers: bkramer

Subscribers: cfe-commits

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

llvm-svn: 342951
2018-09-25 08:24:07 +00:00
Eric Liu fa63e9831e Replace hardcoded format styles in a few tools with the default style in libFormat.
llvm-svn: 338696
2018-08-02 10:30:56 +00:00
Zinovy Nis a1ef2f7b19 [clang-apply-replacements] Make clang-apply-replacements installable
Add a new target for install: install-clang-apply-replacements.
So if you need clang-tidy and clang-apply-replacements tools only, 
you may build and install only these tools:

    make install-clang-tidy install-clang-apply-replacements

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

llvm-svn: 330509
2018-04-21 15:01:33 +00:00
Benjamin Kramer 8d2acfd8e8 [clang-apply-replacements] Always initialize FormatStyle.
The cleanup logic reads from this for cleanups even if reformatting is
not requested.

Found by msan.

llvm-svn: 329894
2018-04-12 10:35:24 +00:00
Roman Lebedev 34812c0d0d [clang-apply-replacements] Don't forget to link to clangToolingRefactor
Fixes build:

[1/3] Linking CXX shared library lib/libclangApplyReplacements.so.7svn
FAILED: lib/libclangApplyReplacements.so.7svn
<...>
/usr/local/bin/ld.lld: error: undefined symbol: clang::tooling::AtomicChange::replace(clang::SourceManager const&, clang::SourceLocation, unsigned int, llvm::StringRef)
>>> referenced by ApplyReplacements.cpp
>>>               tools/clang/tools/extra/clang-apply-replacements/CMakeFiles/clangApplyReplacements.dir/lib/Tooling/ApplyReplacements.cpp.o:(clang::replace::mergeAndDeduplicate(std::vector<clang::tooling::TranslationUnitReplacements, std::allocator<clang::tooling::TranslationUnitReplacements> > const&, std::vector<clang::tooling::TranslationUnitDiagnostics, std::allocator<clang::tooling::TranslationUnitDiagnostics> > const&, llvm::DenseMap<clang::FileEntry const*, std::vector<clang::tooling::AtomicChange, std::allocator<clang::tooling::AtomicChange> >, llvm::DenseMapInfo<clang::FileEntry const*>, llvm::detail::DenseMapPair<clang::FileEntry const*, std::vector<clang::tooling::AtomicChange, std::allocator<clang::tooling::AtomicChange> > > >&, clang::SourceManager&))

/usr/local/bin/ld.lld: error: undefined symbol: clang::tooling::applyAtomicChanges[abi:cxx11](llvm::StringRef, llvm::StringRef, llvm::ArrayRef<clang::tooling::AtomicChange>, clang::tooling::ApplyChangesSpec const&)
>>> referenced by ApplyReplacements.cpp
>>>               tools/clang/tools/extra/clang-apply-replacements/CMakeFiles/clangApplyReplacements.dir/lib/Tooling/ApplyReplacements.cpp.o:(clang::replace::applyChanges[abi:cxx11](llvm::StringRef, std::vector<clang::tooling::AtomicChange, std::allocator<clang::tooling::AtomicChange> > const&, clang::tooling::ApplyChangesSpec const&, clang::DiagnosticsEngine&))
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Refs. D43764, rL329813

llvm-svn: 329892
2018-04-12 10:01:20 +00:00
Malcolm Parsons 7c3e14b63b [clang-apply-replacements] Convert tooling::Replacements to tooling::AtomicChange for conflict resolving of changes, code cleanup, and code formatting.
Summary:
By converting Replacements by AtomicChange, clang-apply-replacements is able like clang-tidy to automatically cleanup and format changes.
This should permits to close this ticket: https://bugs.llvm.org/show_bug.cgi?id=35051 and attempt to follow hints from https://reviews.llvm.org/D43500 comments.

Reviewers: klimek, ioeric

Reviewed By: ioeric

Subscribers: malcolm.parsons, mgorny, cfe-commits

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

Patch by Jeremy Demeule.

llvm-svn: 329813
2018-04-11 14:39:17 +00:00
Shoaib Meenai d806af3499 [CMake] Use PRIVATE in target_link_libraries for executables
We currently use target_link_libraries without an explicit scope
specifier (INTERFACE, PRIVATE or PUBLIC) when linking executables.
Dependencies added in this way apply to both the target and its
dependencies, i.e. they become part of the executable's link interface
and are transitive.

Transitive dependencies generally don't make sense for executables,
since you wouldn't normally be linking against an executable. This also
causes issues for generating install export files when using
LLVM_DISTRIBUTION_COMPONENTS. For example, clang has a lot of LLVM
library dependencies, which are currently added as interface
dependencies. If clang is in the distribution components but the LLVM
libraries it depends on aren't (which is a perfectly legitimate use case
if the LLVM libraries are being built static and there are therefore no
run-time dependencies on them), CMake will complain about the LLVM
libraries not being in export set when attempting to generate the
install export file for clang. This is reasonable behavior on CMake's
part, and the right thing is for LLVM's build system to explicitly use
PRIVATE dependencies for executables.

Unfortunately, CMake doesn't allow you to mix and match the keyword and
non-keyword target_link_libraries signatures for a single target; i.e.,
if a single call to target_link_libraries for a particular target uses
one of the INTERFACE, PRIVATE, or PUBLIC keywords, all other calls must
also be updated to use those keywords. This means we must do this change
in a single shot. I also fully expect to have missed some instances; I
tested by enabling all the projects in the monorepo (except dragonegg),
and configuring both with and without shared libraries, on both Darwin
and Linux, but I'm planning to rely on the buildbots for other
configurations (since it should be pretty easy to fix those).

Even after this change, we still have a lot of target_link_libraries
calls that don't specify a scope keyword, mostly for shared libraries.
I'm thinking about addressing those in a follow-up, but that's a
separate change IMO.

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

llvm-svn: 319840
2017-12-05 21:49:56 +00:00
Kevin Funk bb5cfb5dd3 [clang-tidy] clang-apply-replacements: Don't insert null entry
Summary:
[clang-tidy] clang-apply-replacements: Don't insert null entry

Fix crash when running clang-apply-replacements on YML files which
contain an invalid file path. Make sure we never add a nullptr into the
map. The previous code started adding nullptr to the map after the first
warnings via errs() has been emitted.

Backtrace:
```
Starting program:
/home/kfunk/devel/build/llvm/bin/clang-apply-replacements /tmp/tmpIqtp7m
[Thread debugging using libthread_db enabled]
Using host libthread_db library
"/lib/x86_64-linux-gnu/libthread_db.so.1".
Described file '.moc/../../../../../../src/qt5.8/qtremoteobjects/src/remoteobjects/qremoteobjectregistrysource_p.h' doesn't exist. Ignoring...
...

Program received signal SIGSEGV, Segmentation fault.
main (argc=<optimized out>, argv=<optimized out>) at /home/kfunk/devel/src/llvm/tools/clang/tools/extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp:262
(gdb) p FileAndReplacements.first
$1 = (const clang::FileEntry *) 0x0
(gdb)
```

Added tests.

Before patch:

```
******************** TEST 'Clang Tools :: clang-apply-replacements/invalid-files.cpp' FAILED ********************
Script:
--
mkdir -p /home/kfunk/devel/build/llvm/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/invalid-files
clang-apply-replacements /home/kfunk/devel/build/llvm/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/invalid-files
ls -1 /home/kfunk/devel/build/llvm/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/invalid-files | FileCheck /home/kfunk/devel/src/llvm/tools/clang/tools/extra/test/clang-apply-replacements/invalid-files.cpp --check-prefix=YAML
--
Exit Code: 139

Command Output (stderr):
--
Described file 'idonotexist.h' doesn't exist. Ignoring...
/home/kfunk/devel/build/llvm/tools/clang/tools/extra/test/clang-apply-replacements/Output/invalid-files.cpp.script: line 4:  9919 Segmentation fault      clang-apply-replacements /home/kfunk/devel/build/llvm/tools/clang/tools/extra/test/clang-apply-   replacements/Output/Inputs/invalid-files

--
```

After Patch:

```
PASS: Clang Tools :: clang-apply-replacements/invalid-files.cpp (5 of 6)
```

Reviewers: alexfh, yawanng

Reviewed By: alexfh

Subscribers: cfe-commits, klimek, JDevlieghere, xazax.hun

Tags: #clang-tools-extra

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

llvm-svn: 308974
2017-07-25 14:28:16 +00:00
Dimitry Andric dbe776e86d Adjust SetVersionPrinter call for D33899
Summary:
In D33899, I'm adding a `raw_ostream &` parameter to the function
objects passed to `cl::SetVersionPrinter`.  Adjust the call in
clang-apply-replacements for this.

Reviewers: klimek, alexfh

Subscribers: cfe-commits

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

llvm-svn: 304837
2017-06-06 21:54:45 +00:00
Antonio Maiorano 0d7d9c20a5 Update tools to use new getStyle API
Depends on https://reviews.llvm.org/D28081

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

llvm-svn: 292175
2017-01-17 00:13:32 +00:00
Alexander Kornienko 563de799e3 [clang-tidy] Add check name to YAML export (clang-tools-extra part)
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: 290893
2017-01-03 14:36:13 +00:00
Piotr Padlewski 08124b110a modernize-use-auto NFC fixes
llvm-svn: 289656
2016-12-14 15:29:23 +00:00
Mandeep Singh Grang 7c7ea7d0ae [clang-tools-extra] Format sources with clang-format. NFC.
Summary:
Ran clang-format on all .c/.cpp/.h files in clang-tools-extra.
Excluded the test, unittests, clang-reorder-fields, include-fixer, modularize and pptrace directories.

Reviewers: klimek, alexfh

Subscribers: nemanjai

Tags: #clang-tools-extra

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

llvm-svn: 286221
2016-11-08 07:50:19 +00:00
Mehdi Amini 7ba59edbfb Fix clang-tools-extra build after r283815 (Store FileEntry::Filename as a StringRef instead of raw pointer)
llvm-svn: 283819
2016-10-10 23:24:16 +00:00
Eric Liu 267034ca9c Changes related to new implementation of tooling::Replacements as class.
Summary: See http://reviews.llvm.org/D21748 for details.

Reviewers: djasper, klimek

Subscribers: cfe-commits

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

llvm-svn: 277336
2016-08-01 10:16:39 +00:00
Chris Bieneman 2cc7fec76a Remove autoconf support
Summary:
This patch is provided in preparation for removing autoconf on 1/26. The proposal to remove autoconf on 1/26 was discussed on the llvm-dev thread here: http://lists.llvm.org/pipermail/llvm-dev/2016-January/093875.html

"Now I am become Death, the destroyer of worlds."
-J. Robert Oppenheimer

Reviewers: chandlerc, grosbach, bob.wilson, echristo

Subscribers: cfe-commits, klimek

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

llvm-svn: 258864
2016-01-26 21:31:36 +00:00
Daniel Jasper 5a59152fd0 Fix test failure introduced by r253859. I believe that the new behavior
in r253859 makes sense in many cases and thus, I have fixed the
implementation of calculateChangedRanges instead. It had a FIXME anyway
saying that it was unecessarily using shiftedCodePosition which
resulted in O(N^2) runtime.

llvm-svn: 253929
2015-11-23 22:28:56 +00:00
Alexander Kornienko 3b7df53d04 Refactor: Simplify boolean conditional return statements in clang-apply-replacements
Differential revision: http://reviews.llvm.org/D10025

Patch by Richard Thomson!

llvm-svn: 252207
2015-11-05 20:59:17 +00:00
Yaron Keren 8b563665c3 Replace double negation of !FileID.isInvalid() with FileID.isValid().
+couple more of double-negated !SourceLocation.isInvalid() unfixed in r249228.

llvm-svn: 249235
2015-10-03 10:46:20 +00:00
NAKAMURA Takumi e677e2f545 clang-tools-extra: Appease PR24881. [-Wdocumentation]
\returns doesn't accept \li, but \parblock \li.

llvm-svn: 248080
2015-09-19 02:21:28 +00:00
Benjamin Kramer e71037123b Make helpers static. clang-tools edition.
Also purge dead code found by it. NFC.

llvm-svn: 232948
2015-03-23 12:49:15 +00:00
Adrian Prantl b97f5c1eb2 Revert "Adapt clang-tools-extra to clang module format changes."
This reverts commit 230424.

llvm-svn: 230456
2015-02-25 02:46:37 +00:00
Adrian Prantl e95edbf5a9 Adapt clang-tools-extra to clang module format changes.
- add clangCodeGen.a to the tools that need it
- tweak pp-trace command line handling to not conflict with clang's.

llvm-svn: 230424
2015-02-25 01:32:04 +00:00
Adrian Prantl a22fd38174 Revert "Adapt Makefile dependencies for the clang module format change in r230089."
llvm-svn: 230104
2015-02-21 00:29:43 +00:00
Adrian Prantl 6897e3e456 Adapt Makefile dependencies for the clang module format change in r230089.
llvm-svn: 230090
2015-02-20 23:35:07 +00:00
Chris Bieneman fc4fd529c8 NFC. Migrating clang-tools-extra to the cl::HideUnrelatedOptions API.
llvm-svn: 227388
2015-01-28 22:45:26 +00:00
Pete Cooper 1d2f63a4ef Updated tools to match r227345 which changed the getRegisteredOptions method
llvm-svn: 227372
2015-01-28 21:34:05 +00:00
Nikola Smiljanic 76c21b5a27 Handle newlines on Windows correctly.
llvm-svn: 223750
2014-12-09 02:57:56 +00:00
NAKAMURA Takumi 5f687a036f [CMake] clangApplyReplacement: Add clangAST in libdeps to appease msc builder.
clangApplyReplacements.lib(ApplyReplacements.cpp.obj) : error LNK2001: unresolved external symbol "private: void __thiscall clang::APValue::DestroyDataAndMakeUninit(void)" (?DestroyDataAndMakeUninit@APValue@clang@@AAEXXZ)

They are not seen in mingw dll build. Investigating.

llvm-svn: 220895
2014-10-30 03:22:32 +00:00
NAKAMURA Takumi 9f99a7a417 [CMake] Prune redundant libdeps.
llvm-svn: 220893
2014-10-30 01:37:44 +00:00
NAKAMURA Takumi dc872ed908 [CMake] Add dependencies on clangToolingCore.
llvm-svn: 220890
2014-10-30 00:44:01 +00:00
Daniel Jasper c1de000e22 Fix Makefiles after r220867.
llvm-svn: 220868
2014-10-29 18:55:41 +00:00
Benjamin Kramer 91ea478d7c clang-apply-replacements: For-rangify.
No functionality change.

llvm-svn: 217442
2014-09-09 14:09:48 +00:00
Benjamin Kramer ab7cefc36b clang-apply-replacements: Deduplicate paths with FileManager.
Bucket replacements by FileEntry instead of path. The same file with
different paths is very common, relative #include paths and symlinks can
easily create them. When that occurs we would apply the fix twice.

llvm-svn: 217440
2014-09-09 13:53:51 +00:00
David Blaikie 715c98aeec Update for Clang API change.
llvm-svn: 216615
2014-08-27 20:54:50 +00:00
Rafael Espindola 7fa030330c Update for LLVM api change.
llvm-svn: 216584
2014-08-27 20:03:22 +00:00
Rafael Espindola b14bd53e6d Update for LLVM api change
llvm-svn: 216396
2014-08-25 18:17:00 +00:00
Alp Toker e208dfc2af Track clang r213171
The clang rewriter is now a core facility.

llvm-svn: 213172
2014-07-16 16:50:17 +00:00
Rafael Espindola 43f0aa6caf Update for llvm api change.
llvm-svn: 212406
2014-07-06 17:43:19 +00:00
Alp Toker 573583e2f2 Track IntrusiveRefCntPtr::get() changes from LLVM r212366
llvm-svn: 212367
2014-07-05 03:04:33 +00:00
Rafael Espindola c7f0d23f56 Prefix error_code with std.
llvm-svn: 210840
2014-06-12 22:08:48 +00:00
Rafael Espindola 002840cf66 Quick build fix.
llvm-svn: 210838
2014-06-12 22:01:48 +00:00
Rafael Espindola fd85bb3424 include system_error directly.
llvm-svn: 210797
2014-06-12 16:53:02 +00:00
Rafael Espindola 15c5784d3c Replace llvm::error_code with std::error_code.
llvm-svn: 210776
2014-06-12 13:32:11 +00:00
Craig Topper f61be9c971 [C++11] Use 'nullptr'.
llvm-svn: 210447
2014-06-09 02:03:06 +00:00
Ahmed Charles 6a2dc5c381 [C++11] Replace OwningPtr with std::unique_ptr.
This removes all references to OwningPtr, which should be fairly
undisruptive to out-of-tree projects since they are unlikely to use
clang-tools-extra as a library instead of a set of tools.

llvm-svn: 203382
2014-03-09 09:24:40 +00:00
NAKAMURA Takumi 9698686505 [CMake] Use LINK_LIBS instead of target_link_libraries().
llvm-svn: 202238
2014-02-26 06:41:29 +00:00