Commit Graph

4588 Commits

Author SHA1 Message Date
Florian Gross e25a0e9510 Fixed: Duck-typing in readability-redundant-smartptr-get didn't catch MSVC STL smart pointers.
Differential Revision: https://reviews.llvm.org/D61209

llvm-svn: 359801
2019-05-02 16:41:28 +00:00
Sam McCall 1b29dec05f Reapply r359778: [clangd] Fix code completion of macros defined in the preamble region of the main file.
The bad assert has been removed, and updateOutOfDateIdentifier has been guarded.
This reverts commit r359796.

llvm-svn: 359799
2019-05-02 16:12:36 +00:00
Simon Pilgrim 73c44e45ec Revert rL359778 : [clangd] Fix code completion of macros defined in the preamble region of the main file.
Summary:
This is a tricky case (we baked the assumption that symbols come from
the preamble xor mainfile pretty deeply) and the fix is a bit of a hack:
We look at the code to guess the macro names, and deserialize them from
the preamble "by hand".

Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D60937
........
Fix buildbots http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-ubuntu-fast/builds/47684/

llvm-svn: 359796
2019-05-02 15:47:33 +00:00
Sam McCall 929f639eb8 [clangd] Fix code completion of macros defined in the preamble region of the main file.
Summary:
This is a tricky case (we baked the assumption that symbols come from
the preamble xor mainfile pretty deeply) and the fix is a bit of a hack:
We look at the code to guess the macro names, and deserialize them from
the preamble "by hand".

Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

llvm-svn: 359778
2019-05-02 11:06:44 +00:00
Sam McCall 15b89df9da [clangd] Improvements to header mapping: more precise parsing of cppreference symbol pages.
Summary:
Previously we were just jumping from the symbol index to the symbol page, and
grabbing all the headers mentioned there. But the page often lists multiple
symbols, and so we got false positives and thus ambiguities (which were dropped).

Now we look at which declarations are for the symbol we want, and prefer headers
listed above that symbol. If there are none, we fall back to the old behavior.

Reviewers: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

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

llvm-svn: 359771
2019-05-02 09:34:30 +00:00
Sam McCall 553c139fc3 [clangd] Standard library mapping: prefer "primary" versions of functions over variants.
Reviewers: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

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

llvm-svn: 359770
2019-05-02 09:31:24 +00:00
Sam McCall c9f5220af9 [clangd] Restore conventional names for lit configs, and .in/.py split. Fix build_mode indirection.
llvm-svn: 359763
2019-05-02 08:00:39 +00:00
Fangrui Song e54a93fe6f [clangd] Delete an unused declaration
llvm-svn: 359674
2019-05-01 12:16:37 +00:00
Sam McCall 5b54006be6 [clangd] gen_std uses multiprocessing pool to be fast. While here, log ambiguous symbols. NFC
llvm-svn: 359564
2019-04-30 14:21:10 +00:00
Simon Pilgrim 4723cc5a4c Fix Wpedantic "default argument specified for lambda parameter" warning. NFCI.
llvm-svn: 359548
2019-04-30 10:35:37 +00:00
Jan Korous fd76383d76 [clangd][xpc] Fix XPC unittests
Fix build after recent changes in clangd tests & add xpc unittests to
check-clangd target.

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

llvm-svn: 359489
2019-04-29 19:41:30 +00:00
Kadir Cetinkaya 250eae2452 [clangd] Fix serialization logic for Origin and Flags.
llvm-svn: 359470
2019-04-29 17:25:58 +00:00
Sam McCall 9cbe82d57f [clangd] Add separate unit tests for CanonicalIncludes. NFC
llvm-svn: 359455
2019-04-29 14:36:26 +00:00
Sam McCall a6159a226e [clangd] Fix unittests CMake rules
llvm-svn: 359442
2019-04-29 11:47:52 +00:00
Sam McCall 4c44d2f816 [clangd] Fix windows buildbot, remove stray file after r359424. NFC
llvm-svn: 359434
2019-04-29 10:35:56 +00:00
Kadir Cetinkaya 01efe64c2d [clangd] Surface diagnostics from headers inside main file
Reviewers: ioeric, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, jdoerfert, cfe-commits

Tags: #clang

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

llvm-svn: 359432
2019-04-29 10:25:44 +00:00
Fangrui Song 16a2131c62 [clangd] Delete config.clangd_xpc_support from test/ to unbreak check-llvm-tools
D61187 didn't delete config.clangd_xpc_support from test/
CLANGD_BUILD_XPC is defined in clangd/CMakeLists.txt and not available in test/lit.site.cfg.py.in

llvm-svn: 359428
2019-04-29 09:36:54 +00:00
Sam McCall b804eef090 [clangd] Move clangd tests to clangd directory. check-clangd is no longer part of check-clang-tools.
Summary:
Motivation:
 - this layout is a pain to work with
 - without a common root, it's painful to express things like "disable clangd" (D61122)
 - CMake/lit configs are a maintenance hazard, and the more the one-off hacks
   for various tools are entangled, the more we see apathy and non-ownership.

This attempts to use the bare-minimum configuration needed (while still
supporting the difficult cases: windows, standalone clang build, dynamic libs).
In particular the lit.cfg.py and lit.site.cfg.py.in are merged into lit.cfg.in.
The logic in these files is now minimal.

(Much of clang-tools-extra's lit configs can probably be cleaned up by reusing
lit.llvm.llvm_config.use_clang(), and every llvm project does its own version of
LDPATH mangling. I haven't attempted to fix any of those).

Docs are still in clang-tools-extra/docs, I don't have any plans to touch those.

Reviewers: gribozavr

Subscribers: mgorny, javed.absar, MaskRay, jkorous, arphaman, kadircet, jfb, cfe-commits, ilya-biryukov, thakis

Tags: #clang

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

llvm-svn: 359424
2019-04-29 08:44:01 +00:00
Nick Lewycky 1d30f0c93e Fix typo in documentation.
llvm-svn: 359329
2019-04-26 17:56:22 +00:00
Ilya Biryukov 0d4b1dd1a4 [clangd] Remove unused ClangdServer::dynamicIndex(). NFC
llvm-svn: 359291
2019-04-26 09:36:22 +00:00
Sam McCall b8c1cc97f3 filecheck etc are not clangd-specific deps. NFC
llvm-svn: 359289
2019-04-26 09:20:36 +00:00
Sam McCall c316b22496 [clangd] Query index in code completion no-compile mode.
Summary: We scrape the enclosing scopes from the source file, and use them in the query.

Reviewers: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, mgrang, arphaman, cfe-commits

Tags: #clang

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

llvm-svn: 359284
2019-04-26 07:45:49 +00:00
Sam McCall e3559eee63 [clangd] Optimize "don't include me" check.
Summary:
llvm::Regex is really slow, and regex evaluation during preamble indexing was
showing up as 25% on a profile of clangd in a codebase with large preambles.

Reviewers: ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

llvm-svn: 359214
2019-04-25 17:47:07 +00:00
Sam McCall 79e7e439e5 [clangd] Use JSON streaming API for Trace rather than pasting strings. NFC
llvm-svn: 359202
2019-04-25 16:37:07 +00:00
Ilya Biryukov 6fae38ec91 [Testing] Move clangd::Annotations to llvm testing support
Summary:
Annotations allow writing nice-looking unit test code when one needs
access to locations from the source code, e.g. running code completion
at particular offsets in a file. See comments in Annotations.cpp for
more details on the API.

Also got rid of a duplicate annotations parsing code in clang's code
complete tests.

Reviewers: gribozavr, sammccall

Reviewed By: gribozavr

Subscribers: mgorny, hiraditya, ioeric, MaskRay, jkorous, arphaman, kadircet, jdoerfert, cfe-commits, llvm-commits

Tags: #clang, #llvm

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

llvm-svn: 359179
2019-04-25 10:08:31 +00:00
Don Hinton 28413dd87a [clang-tidy] Add new checker: llvm-prefer-isa-or-dyn-cast-in-conditionals
Summary:
Looks at conditionals and finds cases of ``cast<>``, which will
assert rather than return a null pointer, and ``dyn_cast<>`` where
the return value is not captured. Additionally, finds cases that
match the pattern ``var.foo() && isa<X>(var.foo())``, where the
method is called twice and could be expensive.

.. code-block:: c++

  // Finds cases like these:
  if (auto x = cast<X>(y)) <...>
  if (cast<X>(y)) <...>

  // But not cases like these:
  if (auto f = cast<Z>(y)->foo()) <...>
  if (cast<Z>(y)->foo()) <...>

Reviewers: alexfh, rjmccall, hokein, aaron.ballman, JonasToth

Reviewed By: aaron.ballman

Subscribers: xbolva00, Eugene.Zelenko, mgorny, xazax.hun, cfe-commits

Tags: #clang-tools-extra, #clang

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

llvm-svn: 359142
2019-04-24 21:25:57 +00:00
Sam McCall c60a4099a1 [clangd] Fix broken helper deep in unit test. NFC
llvm-svn: 359112
2019-04-24 17:00:38 +00:00
Kadir Cetinkaya 3ba9a43057 [clangd] Fix handling of include paths in windows tests
llvm-svn: 359079
2019-04-24 09:42:53 +00:00
Kadir Cetinkaya 936c67d3ef [clang][HeaderSuggestion] Handle the case of dotdot with an absolute path
Summary:
Include insertion in clangd was inserting absolute paths when the
include directory was an absolute path with a double dot. This patch makes sure
double dots are handled both with absolute and relative paths.

Reviewers: sammccall

Subscribers: ilya-biryukov, ioeric, jkorous, arphaman, cfe-commits

Tags: #clang

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

llvm-svn: 359078
2019-04-24 09:23:31 +00:00
Artem Dergachev 8c099ce72d Re-apply r357823 "[Lexer] NFC: Fix an off-by-one bug in getAsCharRange()."
It now comes with a follow-up fix for the clients of this API
in clangd and clang-tidy.

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

llvm-svn: 359035
2019-04-23 21:15:26 +00:00
Fangrui Song bca2d266d1 [clangd] Support dependent bases in type hierarchy
Patch by Nathan Ridge!

Dependent bases are handled heuristically, by replacing them with the
class template that they are a specialization of, where possible. Care
is taken to avoid infinite recursion.

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

llvm-svn: 358866
2019-04-22 01:38:53 +00:00
Sam McCall 3a75330f57 [CodeComplete] Remove obsolete isOutputBinary().
Summary:
It's never set to true. Its only effect would be to set stdout to binary mode.
Hopefully we have better ways of doing this by now :-)

Reviewers: hokein

Subscribers: jkorous, arphaman, kadircet, llvm-commits

Tags: #llvm

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

llvm-svn: 358696
2019-04-18 17:35:55 +00:00
Sam McCall c9e4ee9ca9 [clangd] Support relatedInformation in diagnostics.
Summary: We already have the structure internally, we just need to expose it.

Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

llvm-svn: 358675
2019-04-18 15:17:07 +00:00
Haojian Wu 8bbbd31cdd [clang-tidy] Address post-commit comments
Summary:
Also add a test to verify clang-tidy only apply the first alternative
fix.

Reviewers: alexfh

Subscribers: xazax.hun, cfe-commits

Tags: #clang

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

llvm-svn: 358666
2019-04-18 14:18:14 +00:00
Kadir Cetinkaya f8537b3c69 [clangd] Use llvm::set_thread_priority in background-index
Reviewers: gribozavr

Subscribers: krytarowski, ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, jfb, cfe-commits

Tags: #clang

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

llvm-svn: 358664
2019-04-18 13:46:40 +00:00
Haojian Wu 0842daf5ba [clangd] Emit better error messages when rename fails.
Summary:
Currently we emit an unfriendly "clang diagnostic" message when rename fails. This
patch makes clangd to emit a detailed diagnostic message.

Reviewers: sammccall

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

llvm-svn: 358658
2019-04-18 11:35:22 +00:00
Sam McCall 99b7277d39 [clangd] Log verbosely (LSP bodies) in lit tests. NFC
llvm-svn: 358655
2019-04-18 10:32:08 +00:00
Alexander Kornienko 4c177038e0 [clang-tidy] Don't issue cppcoreguidelines-macro-usage on builtin macros
Before the patch calling clang-tidy with -header-filter=.* -system-headers would
result in a few hundred useless warnings:
  warning: macro '_GNU_SOURCE' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage]
  warning: macro '_LP64' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage]
  warning: macro '__ATOMIC_ACQUIRE' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage]
  warning: macro '__ATOMIC_ACQ_REL' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage]
  warning: macro '__ATOMIC_CONSUME' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage]
  warning: macro '__ATOMIC_RELAXED' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage]
  warning: macro '__ATOMIC_RELEASE' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage]
  warning: macro '__ATOMIC_SEQ_CST' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage]
  warning: macro '__BIGGEST_ALIGNMENT__' used to declare a constant; consider using a 'constexpr' constant [cppcoreguidelines-macro-usage]
  ... and so on

llvm-svn: 358621
2019-04-17 22:35:36 +00:00
Stephane Moore b0c1f8c09e [clang-tidy] Add a check for [super self] in initializers 🔍
Summary:
This check aims to address a relatively common benign error where
Objective-C subclass initializers call -self on their superclass instead
of invoking a superclass initializer, typically -init. The error is
typically benign because libobjc recognizes that improper initializer
chaining is common¹.

One theory for the frequency of this error might be that -init and -self
have the same return type which could potentially cause inappropriate
autocompletion to -self instead of -init. The equal selector lengths and
triviality of common initializer code probably contribute to errors like
this slipping through code review undetected.

This check aims to flag errors of this form in the interests of
correctness and reduce incidence of initialization failing to chain to
-[NSObject init].

[1] "In practice, it will be hard to rely on this function.
     Many classes do not properly chain -init calls."
From  _objc_rootInit in https://opensource.apple.com/source/objc4/objc4-750.1/runtime/NSObject.mm.auto.html.

Test Notes:
Verified via `make check-clang-tools`.

Subscribers: mgorny, xazax.hun, jdoerfert, cfe-commits

Tags: #clang

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

llvm-svn: 358620
2019-04-17 22:29:06 +00:00
Sam McCall aa4eb10a7a [clangd] Strip the ' [some-check-name]' suffix from clang-tidy diagnostics. The check name is reported in Diagnostic.code.
Reviewers: kadircet

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

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

llvm-svn: 358612
2019-04-17 20:15:08 +00:00
Sam McCall d98170c324 [clangd] Use shorter, more recognizable codes for diagnostics.
Summary:
 - for warnings, use the flag the warning is controlled by (-Wfoo)
 - for errors, keep using the internal name (there's nothing better) but
   drop the err_ prefix

This comes at the cost of uniformity, it's no longer totally obvious
exactly what the code field contains. But the -Wname flags are so much
more useful to end-users than the internal warn_foo that this seems worth it.

Reviewers: kadircet

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

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

llvm-svn: 358611
2019-04-17 20:12:03 +00:00
Sam McCall a96efb654e [clangd] Recognize "don't include me directly" pattern, and suppress include insertion.
Summary:
Typically used with umbrella headers, e.g. GTK:

 #if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
 #error "Only <gtk/gtk.h> can be included directly."
 #endif

Heuristic is fairly conservative, a quick code search over github showed
a fair number of hits and few/no false positives. (Not all were umbrella
headers, but I'd be happy avoiding include insertion for all of them).

We may want to relax the heuristic later to catch more cases.

Reviewers: ioeric

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

llvm-svn: 358605
2019-04-17 18:33:07 +00:00
Alexander Kornienko e31fe508e8 [clang-tidy] Fix invalid location in readability-misleading-indentation diagnostic
Before this patch readability-misleading-indentation could issue diagnostics
with an invalid location, which would lead to an assertion failure in
ClangTidyContext::diag()

llvm-svn: 358589
2019-04-17 16:19:47 +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
Sam McCall 641caa57cc [clangd] Include textual diagnostic ID as Diagnostic.code.
Reviewers: kadircet

Subscribers: ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, jdoerfert, cfe-commits

Tags: #clang

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

llvm-svn: 358575
2019-04-17 12:35:16 +00:00
Sam McCall 62e2472321 [clangd] Include insertion: require header guards, drop other heuristics, treat .def like .inc.
Summary:
We do have some reports of include insertion behaving badly in some
codebases. Requiring header guards both makes sense in principle, and is
likely to disable this "nice-to-have" feature in codebases where headers don't
follow the expected pattern.

With this we can drop some other heuristics, such as looking at file
extensions to detect known non-headers - implementation files have no guards.

One wrinkle here is #import - objc headers may not have guards because
they're intended to be used via #import. If the header is the main file
or is #included, we won't collect locations - merge should take care of
this if we see the file #imported somewhere. Seems likely to be OK.

Headers which have a canonicalization (stdlib, IWYU) are exempt from this check.
*.inc files continue to be handled by looking up to the including file.
This patch also adds *.def here - tablegen wants this pattern too.

In terms of code structure, the division between SymbolCollector and
CanonicalIncludes has shifted: SymbolCollector is responsible for more.
This is because SymbolCollector has all the SourceManager/HeaderSearch access
needed for checking for guards, and we interleave these checks with the *.def
checks in a loop (potentially).
We could hand all the info into CanonicalIncludes and put the logic there
if that's preferable.

Reviewers: ioeric

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

llvm-svn: 358571
2019-04-17 10:36:02 +00:00
Sam McCall 277754c71d [clangd] lower_bound -> bsearch, NFC
llvm-svn: 358561
2019-04-17 07:00:36 +00:00
Peter Collingbourne 990514cec8 clangd: Change Windows.h to windows.h.
This makes the file more cross compilation friendly.

llvm-svn: 358549
2019-04-17 03:02:18 +00:00
Eric Liu 417c889409 [clangd] Check file path of declaring header when deciding whether to insert include.
Summary:
Previously, we would use include spelling of the declaring header to check
whether the inserted header is the same as the main file. This doesn't help because
we only have file path of the main file.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

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

llvm-svn: 358496
2019-04-16 14:35:49 +00:00
Kadir Cetinkaya bb6cd8254c [clangd] Fallback to OrigD when SLoc is invalid
Summary:
Some implicit/built-in decls lack the source location
information. Fallback to OrigD that we've seen in the source code
instead of the canonical one in those cases.

Reviewers: sammccall

Subscribers: cfe-commits, arphaman, jkorous, MaskRay, ioeric, ilya-biryukov

Tags: #clang

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

llvm-svn: 358413
2019-04-15 14:38:46 +00:00