Commit Graph

3880 Commits

Author SHA1 Message Date
Benjamin Kramer c55e997556 Move some helpers from the global namespace into anonymous ones.
llvm-svn: 344468
2018-10-13 22:18:22 +00:00
Adam Balogh af1f374ece [clang-tidy] Fix for typos in the tests for `bugprone-exception-escape`
llvm-svn: 344445
2018-10-13 11:17:59 +00:00
Adam Balogh d053f5c616 [clang-tidy] Optimize query in bugprone-exception-escape
Checking whether a functions throws indirectly may be very expensive because it
needs to visit its whole call graph. Therefore we should first check whether the
function is forbidden to throw and only check whether it throws afterward. This
also seems to solve bug https://bugs.llvm.org/show_bug.cgi?id=39167 where the
execution time is so long that it seems to hang.

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

llvm-svn: 344444
2018-10-13 10:34:52 +00:00
Jonas Toth cd3e370504 Revert "[clang-tidy] New checker for not null-terminated result caused by strlen(), size() or equal length"
This reverts commit r344374.

llvm-svn: 344442
2018-10-13 09:30:58 +00:00
Jonas Toth bbbebeb928 Revert "[doc] fix markup in clang-tidy bugprone-not-null-terminated-result"
This reverts commit r344379.

llvm-svn: 344441
2018-10-13 09:30:46 +00:00
Miklos Vajna abfccc2cf6 [clang-tidy] add IgnoreMacros option to modernize-use-equals-delete
And also enable it by default to be consistent with e.g. modernize-use-using.
This improves consistency inside the check itself as well: both checks are now
disabled in macros by default.

This helps e.g. when running this check on client code where the macro is
provided by the system, so there is no easy way to modify it.

Reviewed By: alexfh

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

llvm-svn: 344440
2018-10-13 07:58:05 +00:00
Jonas Toth f79f8eecce [clangd] NFC fix semicolon warning
llvm-svn: 344384
2018-10-12 17:47:43 +00:00
Jonas Toth 6042235450 [doc] fix markup in clang-tidy bugprone-not-null-terminated-result
llvm-svn: 344379
2018-10-12 17:36:04 +00:00
Jonas Toth 78886233b3 [clang-tidy] New checker for not null-terminated result caused by strlen(), size() or equal length
New checker called bugprone-not-null-terminated-result. This check finds function calls where it is possible to cause a not null-terminated result. Usually the proper length of a string is strlen(src) + 1 or equal length of this expression, because the null terminator needs an extra space. Without the null terminator it can result in undefined behaviour when the string is read.

The following function calls are checked:
memcpy, wmemcpy, memcpy_s, wmemcpy_s, memchr, wmemchr, memmove, wmemmove, memmove_s, wmemmove_s, memset, wmemset, strerror_s, strncmp, wcsncmp, strxfrm, wcsxfrm

The following is a real-world example where the programmer forgot to increase the passed third argument, which is size_t length. That is why the length of the allocated memory is problematic too.

static char *StringCpy(const std::string &str) {
  char *result = reinterpret_cast<char *>(malloc(str.size()));
  memcpy(result, str.data(), str.size());
  return result;
}

After running the tool fix-it rewrites all the necessary code according to the given options. If it is necessary, the buffer size will be increased to hold the null terminator.

static char *StringCpy(const std::string &str) {
  char *result = reinterpret_cast<char *>(malloc(str.size() + 1));
  strcpy(result, str.data());
  return result;
}

Patch by Charusso.

Differential ID: https://reviews.llvm.org/D45050

llvm-svn: 344374
2018-10-12 17:22:36 +00:00
Sam McCall cbf497f452 [clangd] Return Command objects from onCodeAction, rather than ad-hoc JSON. NFC
llvm-svn: 344363
2018-10-12 16:51:48 +00:00
Zachary Turner 359544acc7 Fix one additional test broken by the YAML quoting change.
llvm-svn: 344362
2018-10-12 16:41:37 +00:00
Zinovy Nis 608dfb2bc7 [clang-tidy] Fix check_clang_tidy.py trivially passing default CHECK
Differential Revision: https://reviews.llvm.org/D53194

llvm-svn: 344343
2018-10-12 13:35:47 +00:00
Adam Balogh abd72e9851 [clang-tidy] White List Option for performance-unnecessary-value-param, performance-unnecessary-copy-initialization and performance-for-range-copy
New option added to these three checks to be able to silence false positives on
types that are intentionally passed by value or copied. Such types are e.g.
intrusive reference counting pointer types like llvm::IntrusiveRefCntPtr. The
new option is named WhiteListTypes and can contain a semicolon-separated list of
names of these types. Regular expressions are allowed. Default is empty.

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

llvm-svn: 344340
2018-10-12 13:05:21 +00:00
Haojian Wu 903f2a71a4 [clangd] Support hover on "aut^o *".
Reviewers: kadircet

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

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

llvm-svn: 344330
2018-10-12 10:11:02 +00:00
Eugene Zelenko 724a3b728a [Documentation] Rephrase modernize-deprecated-ios-base-aliases description. Add clangd and clang-doc placeholders in Release Notes.
llvm-svn: 344299
2018-10-11 21:40:32 +00:00
Fangrui Song 95b45cb4fd [clang-move] Remove clang:: qualifier
Summary:
The use sites are enclosed by `namespace clang`, so clang:: is not
necessary. Many unqualified names have already been used, e.g. SourceManager SourceLocation LangOptions. This change makes the code terser and more consistent.

Reviewers: hokein

Reviewed By: hokein

Subscribers: ioeric, cfe-commits

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

llvm-svn: 344256
2018-10-11 16:09:26 +00:00
Sam McCall 0f80d9f27d [clangd] Remove no-op crash handler, we never set a crash context.
Summary:
I think this was just copied from somewhere with the belief that it actually
did some crash handling.

Of course the question arises: *should* we set one? I don't think so:
 - clangd used to crash a lot, now it's pretty stable, because we found and
   fixed the crashes. I think the long-term effects of crashing hard are good.
 - the implementation can't do any magic, it just uses longjmp to return without
   running any destructors by default. This is unsafe in general (e.g. mutexes
   won't unlock) and will certainly end up leaking memory. Whatever UB caused
   the crash may still stomp all over global state, etc.

I think there's an argument for isolating the background indexer (autoindex)
because it's not directly under the user's control, the crash surface is larger,
and it doesn't particularly need to interact with the rest of clangd.
But there, fork() and communicate through the FS is safer.

Reviewers: ioeric, ilya-biryukov

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

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

llvm-svn: 344245
2018-10-11 13:06:10 +00:00
Chandler Carruth d966ce4c98 Fix the qualification of `IntrusiveRefCntPtr` to use `llvm::`.
Without this, the code only compiled if the header was included after
something introduced the alias from `clang::` to `llvm::` for this type.
Any modules build would fail here.

llvm-svn: 344225
2018-10-11 08:05:10 +00:00
Jonas Devlieghere fc51490baf Lift VFS from clang to llvm (NFC)
This patch moves the virtual file system form clang to llvm so it can be
used by more projects.

Concretely the patch:
 - Moves VirtualFileSystem.{h|cpp} from clang/Basic to llvm/Support.
 - Moves the corresponding unit test from clang to llvm.
 - Moves the vfs namespace from clang::vfs to llvm::vfs.
 - Formats the lines affected by this change, mostly this is the result of
   the added llvm namespace.

RFC on the mailing list:
http://lists.llvm.org/pipermail/llvm-dev/2018-October/126657.html

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

llvm-svn: 344140
2018-10-10 13:27:25 +00:00
Sam McCall 26fac469d2 [clangd] Make FSProvider const-correct. NFC
llvm-svn: 344118
2018-10-10 07:46:15 +00:00
Alexander Kornienko c968c98880 [clang-tidy] Fix handling of parens around new expressions in make_<smartptr> checks.
Summary:
Extra parentheses around a new expression result in incorrect code
after applying fixes.

Reviewers: hokein

Reviewed By: hokein

Subscribers: xazax.hun, cfe-commits

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

llvm-svn: 344058
2018-10-09 15:58:18 +00:00
Eric Liu 254b017905 [clang-move] Fix broken json output.
llvm-svn: 344055
2018-10-09 15:17:16 +00:00
Haojian Wu 292a36a0d5 [clangd] Fix an accident change in r342999.
llvm-svn: 344054
2018-10-09 15:16:14 +00:00
Jonas Toth c831f55fb1 [clang-tidy] NFC fix warnings from missing braces
The std::array create multiple StringRef but did not wrap
them in braces. Some compilers warned for that. Adding the
braces is not possible and result in a compilation error.
This commit changes the array to vector which works without warning.

llvm-svn: 344046
2018-10-09 13:29:31 +00:00
Jonas Toth 3acdd020b4 [clangd] fix miscompiling lower_bound call
llvm-svn: 344044
2018-10-09 13:24:50 +00:00
Kadir Cetinkaya e324027b72 [clangd] Mark colon as a safe character when percent-encoding.
Summary: Also change output of percent-encoding to use upper-case letters.

Reviewers: sammccall

Reviewed By: sammccall

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

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

llvm-svn: 344033
2018-10-09 10:29:54 +00:00
Sam McCall c92e4f35fd [clangd] Fix nondeterministic test
llvm-svn: 344030
2018-10-09 10:02:02 +00:00
Kadir Cetinkaya 84bf607eac [clangd] Revert back to previous heuristic for diagnostic range extraction.
Summary: Also add a few new test cases and a special case into handling of empty fixit ranges that  collides with location of a diag.

Reviewers: sammccall, ilya-biryukov

Reviewed By: sammccall

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

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

llvm-svn: 344025
2018-10-09 08:41:12 +00:00
Eric Liu 7734e63ad8 [clangd] Avoid cache main file status in preamble.
Summary: Main file can certainly change when reusing preamble.

Reviewers: sammccall

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

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

llvm-svn: 344024
2018-10-09 08:27:31 +00:00
Zinovy Nis 7ce9334ad7 [clang-tidy][docs] Update docs for `--check-suffixes`
Differential Revision: https://reviews.llvm.org/D52971

llvm-svn: 344016
2018-10-09 05:48:57 +00:00
Zinovy Nis 72a6b28b3c [clang-tidy] The patch extends the existing command line option -check-suffix
(with alias -check-suffixes) to accept multiple comma-separated FileCheck prefixes.

Usage:

// RUN: %check_clang_tidy -check-suffix=USING-C,USING-D %s misc-unused-using-decls %t -- -- ...
or for the same:
// RUN: %check_clang_tidy -check-suffixes=USING-C,USING-D %s misc-unused-using-decls %t -- -- ...

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

llvm-svn: 344015
2018-10-09 05:40:03 +00:00
Eric Liu bce181c64f [clang-move] Dump whether a declaration is templated.
llvm-svn: 343982
2018-10-08 17:22:50 +00:00
Haojian Wu 162510f619 [clangd] Update the out-of-date yaml-symbol-file flag in clangd.
Summary:
The flag is stale due to the recent changes of clangd indexer, this
patch renames the flag to "index-file".

Reviewers: sammccall

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

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

llvm-svn: 343963
2018-10-08 10:44:54 +00:00
Fangrui Song 8380c9e918 [clangd] Migrate to LLVM STLExtras range API
llvm-svn: 343946
2018-10-07 17:21:08 +00:00
Kirill Bobyrev 4a5ff88fdb [clangd] NFC: Migrate to LLVM STLExtras API where possible
This patch improves readability by migrating `std::function(ForwardIt
start, ForwardIt end, ...)` to LLVM's STLExtras range-based equivalent
`llvm::function(RangeT &&Range, ...)`.

Similar change in Clang: D52576.

Reviewed By: sammccall

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

llvm-svn: 343937
2018-10-07 14:49:41 +00:00
Simon Pilgrim b616b809a3 Revert rL343916: Fix -Wmissing-braces warning. NFCI.
llvm-svn: 343917
2018-10-06 11:59:31 +00:00
Simon Pilgrim 2a6bfa0c30 Fix -Wmissing-braces warning. NFCI.
llvm-svn: 343916
2018-10-06 11:46:27 +00:00
Fangrui Song 39f7b3967a [clangd] Remove unused headers from CodeComplete.cpp
queue is not used after index-provided completions' merge with those from Sema
USRGeneration.h is not used after introduction of getSymbolID

llvm-svn: 343912
2018-10-06 07:00:50 +00:00
Jonas Toth a78c249af6 [clang-tidy] NFC refactor lexer-utils to be usable without ASTContext
Summary:
This patch is a small refactoring necessary for
'readability-isolate-declaration' and does not introduce functional changes.
It allows to use the utility functions without a full `ASTContext` and requires only the `SourceManager` and the `LangOpts`.

Reviewers: alexfh, aaron.ballman, hokein

Reviewed By: alexfh

Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits

Tags: #clang-tools-extra

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

llvm-svn: 343850
2018-10-05 14:15:19 +00:00
Sam McCall 5fb9746c49 [clangd] Remove last usage of ast matchers from SymbolCollector. NFC
llvm-svn: 343849
2018-10-05 14:03:04 +00:00
Jonas Toth d079436571 [clang-tidy] Replace deprecated std::ios_base aliases
This check warns the uses of the deprecated member types of std::ios_base
and replaces those that have a non-deprecated equivalent.

Patch by andobence!

Reviewd by: alexfh

Revision ID: https://reviews.llvm.org/D51332

llvm-svn: 343848
2018-10-05 13:36:00 +00:00
Sam McCall 75dd87bed1 [clangd] Remove debugging output in test
llvm-svn: 343845
2018-10-05 12:22:40 +00:00
Sam McCall b2d530e035 [clangd] Fix a subtle case for GetBeginningOfIdentifier.
Calling getMacroArgExpansionLocation too early was causing
Lexer::getRawToken to do the wrong thing - lexing the macro name instead
of the arg contents.

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

llvm-svn: 343844
2018-10-05 12:08:06 +00:00
Sam McCall 722d6c6041 [clangd] Make binary index format the default, remove dead flag.
Reviewers: hokein

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

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

llvm-svn: 343841
2018-10-05 09:05:28 +00:00
Julie Hockett e122f94fa0 [clang-doc] Clean up Markdown output
Make the output for the MDGenerator cleaner and more readable.

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

llvm-svn: 343818
2018-10-04 21:34:13 +00:00
Sam McCall 50b89f0a9b [clangd] Simplify Dex query tree logic and fix missing-posting-list bug
Summary:
The bug being fixed: when a posting list doesn't exist in the index, it
was previously just dropped from the query rather than being treated as
empty. Now that we have the FALSE iterator, we can use it instead.

The query tree logic previously had a bunch of special cases to detect whether
subtrees are empty. Now we just naively build the whole tree, and rely
on the query optimizations to drop the trivial parts.

Finally, there was a bug in trigram generation: the empty query would
generate a single trigram "$$$" instead of no trigrams.
This had no effect (there was no posting list, so the other bug
cancelled it out). But we now have to fix this bug too.

Reviewers: ilya-biryukov

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

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

llvm-svn: 343802
2018-10-04 17:18:55 +00:00
Sam McCall aa728f1afa [clangd] Dex: FALSE iterator, peephole optimizations, fix AND bug
Summary:
The FALSE iterator will be used in a followup patch to fix a logic bug in Dex
(currently, tokens that don't have posting lists in the index are simply dropped
from the query, changing semantics).

It can usually be optimized away, so added the following opmitizations:
 - simplify booleans inside AND/OR
 - replace effectively-empty AND/OR with booleans
 - flatten nested AND/ORs

While working on this, found a bug in the AND iterator: its constructor sync()
assumes that ReachedEnd is set if applicable, but the constructor never sets it.
This crashes if a non-first iterator is nonempty.

Reviewers: ilya-biryukov

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

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

llvm-svn: 343801
2018-10-04 17:18:49 +00:00
Sam McCall bd7718ec26 [clangd] Add std::move for converting-return to satisfy older compilers
llvm-svn: 343800
2018-10-04 17:15:41 +00:00
Jonas Toth 8920428376 [clang-tidy] fix failing unit tests
The removal from the FIX-IT notes through the check-clang-tidy
script was done incorrect. I did not detect beforehand but adjusted
the script and tests accordingly

llvm-svn: 343797
2018-10-04 16:39:41 +00:00
Jonas Toth 0451440f89 [clangd] fix another ambigous constructor in DexTest
llvm-svn: 343796
2018-10-04 16:29:58 +00:00