Commit Graph

7348 Commits

Author SHA1 Message Date
Utkarsh Saxena 6831c1d868 [clangd] Include refs of base method in refs for derived method.
Addresses https://github.com/clangd/clangd/issues/881

Includes refs of base class method in refs of derived class method.
Previously we reported base class method's refs only for decl of derived
class method. Ideally this should work for all usages of derived class method.

Related patch:
fbeff2ec2b.

Differential Revision: https://reviews.llvm.org/D111039
2021-10-05 17:39:49 +02:00
David Goldman a90d57b6cc [clangd] Improve PopulateSwitch tweak
- Support enums in C and ObjC as their
  AST representations differ slightly.

- Add support for typedef'ed enums.

Differential Revision: https://reviews.llvm.org/D110954
2021-10-04 10:15:37 -04:00
Jay Foad d933adeaca [APInt] Stop using soft-deprecated constructors and methods in clang. NFC.
Stop using APInt constructors and methods that were soft-deprecated in
D109483. This fixes all the uses I found in clang.

Differential Revision: https://reviews.llvm.org/D110808
2021-10-04 09:38:11 +01:00
Kirill Bobyrev b06df22382
[clangd] Follow-up on rGdea48079b90d
Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D110925
2021-10-04 08:39:24 +02:00
Kadir Cetinkaya 512aa84850
[clangd] Handle members of anon structs in SelectionTree
References to fields inside anon structs contain an implicit children
for the container, which has the same SourceLocation with the field.
This was resulting in SelectionTree always picking the anon-struct rather than
the field as the selection.

This patch prevents that by claiming the range for the field early.

https://github.com/clangd/clangd/issues/877.

Differential Revision: https://reviews.llvm.org/D110825
2021-10-01 12:38:18 +02:00
Kirill Bobyrev 38ec2292f0
[clangd] Update comment after dea48079b9 2021-09-30 16:45:10 +02:00
Kirill Bobyrev dea48079b9
[clangd] Land D110386 again
This time, use llvm::sys::fs::UniqueID instead of unstable
FileEntry::getName(), this should solve the problems on Windows and
elsewhere.
2021-09-30 14:41:27 +02:00
Kirill Bobyrev 230a6edb49 Revert "[clangd] Reland D110386"
This reverts commits

- dd13f45e04
- d084c42bdf
- 87817bc523
2021-09-30 11:37:07 +02:00
Kirill Bobyrev 87817bc523 Fix the build after d084c42bdf 2021-09-30 09:53:04 +02:00
Kirill Bobyrev d084c42bdf Investigate failure in rGdd13f45e04366cc4f648b57ec87d20a5569e27c3
https://lab.llvm.org/buildbot/#/builders/123/builds/6406/steps/8/logs/stdio
2021-09-30 09:50:14 +02:00
Kirill Bobyrev dd13f45e04
[clangd] Reland D110386
D110711 will fix the bug on Windows side and allows me to reland this
patch.

Also land e50771181b on top of it.
2021-09-30 08:25:31 +02:00
Simon Pilgrim 7674bd4d44 [clang-tidy] Merges separate isa<>/assert/unreachable/dyn_cast<>/cast<> calls
We can directly use cast<> instead of separate dyn_cast<> with assertions as cast<> will perform this for us.

Similarly we can replace a if(isa<>)+cast<>/dyn_cast<> with if(dyn_cast<>)
2021-09-29 16:35:29 +01:00
Salman Javed 722e705f72 Revert 9b944c1843 with fixes
This reintroduces c0687e1984 (Add support
for `NOLINTBEGIN` ... `NOLINTEND` comments) but with fixes to the tests.
2021-09-29 08:00:45 -04:00
Nico Weber 5cf0606140 [clang] Let PPCallbacks::PragmaWarning() pass specifier as enum instead of string
Differential Revision: https://reviews.llvm.org/D110635
2021-09-28 19:47:27 -04:00
Aaron Ballman 9b944c1843 Revert "Add support for `NOLINTBEGIN` ... `NOLINTEND` comments"
This reverts commit c0687e1984.

There are testing failures being caught by bots.
See http://45.33.8.238/linux/56886/step_8.txt as an example.
2021-09-28 14:49:27 -04:00
Salman Javed c0687e1984 Add support for `NOLINTBEGIN` ... `NOLINTEND` comments
Add support for NOLINTBEGIN ... NOLINTEND comments to suppress
clang-tidy warnings over multiple lines. All lines between the "begin"
and "end" markers are suppressed.

Example:

// NOLINTBEGIN(some-check)
<Code with warnings to be suppressed, line 1>
<Code with warnings to be suppressed, line 2>
<Code with warnings to be suppressed, line 3>
// NOLINTEND(some-check)
Follows similar syntax as the NOLINT and NOLINTNEXTLINE comments
that are already implemented, i.e. allows multiple checks to be provided
in parentheses; suppresses all checks if the parentheses are omitted,
etc.

If the comments are misused, e.g. using a NOLINTBEGIN but not
terminating it with a NOLINTEND, a clang-tidy-nolint diagnostic
message pointing to the misuse is generated.

As part of implementing this feature, the following bugs were fixed in
existing code:

IsNOLINTFound(): IsNOLINTFound("NOLINT", Str) returns true when Str is
"NOLINTNEXTLINE". This is because the textual search finds NOLINT as
the stem of NOLINTNEXTLINE.

LineIsMarkedWithNOLINT(): NOLINTNEXTLINEs on the very first line of a
file are ignored. This is due to rsplit('\n\').second returning a blank
string when there are no more newline chars to split on.
2021-09-28 07:53:23 -04:00
Kirill Bobyrev e7a5347b55
Revert "[clangd] Refactor IncludeStructure: use File (unsigned) for most computations"
This reverts

- d1c6e54930
- 7394d3ba27
- e50771181b
- 1bcd6b51a9
2021-09-28 13:34:42 +02:00
M Bakinovsky 4f01a02d73 Fix documentation typos; NFC
Fixes bugprone-virtual-near-miss & performance-type-promotion-in-math-fn.
2021-09-28 06:56:49 -04:00
Kirill Bobyrev d1c6e54930
Investigate D110386 failures even further 2021-09-28 12:02:13 +02:00
Kirill Bobyrev 7394d3ba27 Investigate D110386 Windows failures
Add more information for test failures inspection.
2021-09-28 09:53:01 +02:00
Kirill Bobyrev e50771181b
Attempt to fix Windows builds after D110386
http://45.33.8.238/win/46013/summary.html
2021-09-28 08:13:01 +02:00
Kirill Bobyrev 1bcd6b51a9
[clangd] Refactor IncludeStructure: use File (unsigned) for most computations
Preparation for D108194.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D110386
2021-09-28 07:44:28 +02:00
Nico Weber 36dc5c048a Revert "[clangd] Refactor IncludeStructure: use File (unsigned) for most computations"
This reverts commit 0b1eff1bc5.
Breaks check-clangd on Windows, see comments on
https://reviews.llvm.org/D110386
2021-09-27 14:38:18 -04:00
Aaron Ballman ef0f728abe Add a missing include to appease the build bots 2021-09-27 14:19:39 -04:00
Carlos Galvez b2a2c38349 Fix bug in readability-uppercase-literal-suffix
Fixes https://bugs.llvm.org/show_bug.cgi?id=51790. The check triggers
incorrectly with non-type template parameters.

A bisect determined that the bug was introduced here:
ea2225a10b

Unfortunately that patch can no longer be reverted on top of the main
branch, so add a fix instead. Add a unit test to avoid regression in
the future.
2021-09-27 14:03:53 -04:00
Kirill Bobyrev 0b1eff1bc5
[clangd] Refactor IncludeStructure: use File (unsigned) for most computations
Preparation for D108194.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D110386
2021-09-27 17:50:53 +02:00
liuke e4902480f1 Fix wrong FixIt about union in cppcoreguidelines-pro-type-member-init
At most one variant member of a union may have a default member
initializer. The case of anonymous records with multiple levels of
nesting like the following also needs to meet this rule. The original
logic is to horizontally obtain all the member variables in a record
that need to be initialized and then filter to the variables that need
to be fixed. Obviously, it is impossible to correctly initialize the
desired variables according to the nesting relationship.

See Example 3 in class.union

union U {
  U() {}
  int x;  // int x{};
  union {
    int k;  // int k{};  <==  wrong fix
  };
  union {
    int z;  // int z{};  <== wrong fix
    int y;
  };
};
2021-09-24 13:15:21 -04:00
Simon Pilgrim 45617e1dd8 [clang-doc] Pass Record argument by const-ref. NFCI.
Record is a SmallVector<uint64_t, 1024> - we really need to avoid passing this by value.

Avoid unnecessary big copies, reported by coverity.
2021-09-24 10:06:13 +01:00
David Goldman d75fb1ee79 [clangd] Support `#pragma mark` in the outline
Xcode uses `#pragma mark -` to draw a divider in the outline view
and `#pragma mark Note` to add `Note` in the outline view. For more
information, see https://nshipster.com/pragma/.

Since the LSP spec doesn't contain dividers for the symbol outline,
instead we treat `#pragma mark -` as a group with children - the
decls that come after it, implicitly terminating when the symbol's
parent ends.

The following code:

```
@implementation MyClass

- (id)init {}

- (int)foo;
@end
```

Would give an outline like

```
MyClass
        > Overrides
                    > init
        > Public Accessors
                    > foo
```

Differential Revision: https://reviews.llvm.org/D105904
2021-09-23 17:13:30 -04:00
Louis Dionne e6126faba0 [libc++] Remove unused macro in __config
That macro was being defined but not used anywhere in libc++, so it
must be safe to remove it.

As a fly-by fix, also remove mentions of this macro in other places
in LLVM, to make sure they were not depending on the value defined in
libc++.

Differential Revision: https://reviews.llvm.org/D110289
2021-09-23 13:09:32 -04:00
Christian Kandeler eb209c13cc clangd: Do not report inline overrides twice
... in textDocument/references.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D110324
2021-09-23 16:09:13 +02:00
Nathan Ridge 4223195de3 [clangd] Ensure lambda init-capture gets semantic token
Prior to this patch, CollectExtraHighlightings would incorrectly produce
a token for the init-capture's type which overlapped the name and
resulted in both being dropped.

Fixes https://github.com/clangd/clangd/issues/868

Differential Revision: https://reviews.llvm.org/D110130
2021-09-23 03:52:57 -04:00
Nathan Ridge d87d1aa076 [clangd] Deduplicate inlay hints
Duplicates can sometimes appear due to e.g. explicit template
instantiations

Differential Revision: https://reviews.llvm.org/D110051
2021-09-21 03:23:04 -04:00
Kadir Cetinkaya 444a5f304f
[clangd] Bail-out when an empty compile flag is encountered
Fixes https://github.com/clangd/clangd/issues/865

Differential Revision: https://reviews.llvm.org/D109894
2021-09-20 16:51:56 +02:00
Saleem Abdulrasool f1e8ceb305 docs: correct SPHNIX document reference
The trailing `>` was missing, which resulted in the reference not being
processed properly.
2021-09-16 17:43:59 +00:00
Kadir Cetinkaya 64fe045886
[clangd] PreamblePatch should be no-op if includes arent patched
Don't create a useless functional patch with only filename in it when
there is only include directives to be patched but they're not
requested.

Differential Revision: https://reviews.llvm.org/D109880
2021-09-16 17:11:31 +02:00
Kadir Cetinkaya ea79b77da3
[clangd] Dont work on diags if we are not going to emit
Don't install clang-tidy checks and IncludeFixer or process clang diags
when they're going to be dropped. Also disables analysis for some
warnings completely.

Differential Revision: https://reviews.llvm.org/D109884
2021-09-16 16:50:42 +02:00
Queen Dela Cruz 9c4a1686d7
[clangd] Fix clangd crash when including a header
Fixes https://github.com/clangd/clangd/issues/819

SourceLocation of macros change when a header file is included above it. This is not checked when creating a PreamblePatch, resulting in reusing previously built preamble with an incorrect source location for the macro in the example test case.
This patch stores the SourceLocation in the struct TextualPPDirective so that it gets checked when comparing old vs new preambles.

Also creates a preamble patch for code completion parsing so that clangd does not crash when following the example test case with a large file.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D108045
2021-09-16 10:27:15 +02:00
Saleem Abdulrasool d249200fa7 Revert "Re-Revert "clang-tidy: introduce readability-containter-data-pointer check""
This reverts commit 626586fc25.

Tweak the test for Windows.  Windows defaults to delayed template
parsing, which resulted in the main template definition not registering
the test on Windows.  Process the file with the additional
`-fno-delayed-template-parsing` flag to change the default beahviour.
Additionally, add an extra check for the fix it and use a more robust
test to ensure that the value is always evaluated.

Differential Revision: https://reviews.llvm.org/D108893
2021-09-15 20:52:55 +00:00
Nico Weber 626586fc25 Re-Revert "clang-tidy: introduce readability-containter-data-pointer check"
This reverts commit 49992c0414.
The test is still failing on Windows, see comments on https://reviews.llvm.org/D108893
2021-09-14 22:27:59 -04:00
Saleem Abdulrasool 49992c0414 Revert "Revert "clang-tidy: introduce readability-containter-data-pointer check""
This reverts commit 76dc8ac36d.

Restore the change.  The test had an incorrect negative from testing.
The test is expected to trigger a failure as mentioned in the review
comments.  This corrects the test and should resolve the failure.
2021-09-14 10:52:35 -07:00
Nico Weber 76dc8ac36d Revert "clang-tidy: introduce readability-containter-data-pointer check"
This reverts commit d0d9e6f084.
Breaks tests, see e.g. https://lab.llvm.org/buildbot/#/builders/188/builds/3326
2021-09-14 12:37:10 -04:00
Saleem Abdulrasool d0d9e6f084 clang-tidy: introduce readability-containter-data-pointer check
This introduces a new check, readability-containter-data-pointer.  This
check is meant to catch the cases where the user may be trying to
materialize the data pointer by taking the address of the 0-th member of
a container.  With C++11 or newer, the `data` member should be used for
this.  This provides the following benefits:

- `.data()` is easier to read than `&[0]`
- it avoids an unnecessary re-materialization of the pointer
  * this doesn't matter in the case of optimized code, but in the case
    of unoptimized code, this will be visible
- it avoids a potential invalid memory de-reference caused by the
  indexing when the container is empty (in debug mode, clang will
  normally optimize away the re-materialization in optimized builds).

The small potential behavioural change raises the question of where the
check should belong.  A reasoning of defense in depth applies here, and
this does an unchecked conversion, with the assumption that users can
use the static analyzer to catch cases where we can statically identify
an invalid memory de-reference.  For the cases where the static analysis
is unable to prove the size of the container, UBSan can be used to track
the invalid access.

Special thanks to Aaron Ballmann for the discussion on whether this
check would be useful and where to place it.

This also partially resolves PR26817!

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D108893
2021-09-14 08:12:10 -07:00
David Goldman 8401713b3e [clangd] Ignore ObjC `id` and `instancetype` in FindTarget
Even though they're implemented via typedefs, we typically
want to treat them like keywords.

We could add hover information / xrefs, but it's very unlikely
to provide any value.

Differential Revision: https://reviews.llvm.org/D108556
2021-09-14 09:53:42 -04:00
Corentin Jabot 601102d282 Cleanup identifier parsing; NFC
Rename methods to clearly signal when they only deal with ASCII,
simplify the parsing of identifier, and use start/continue instead of
head/body for consistency with Unicode terminology.
2021-09-14 09:12:22 -04:00
Tom Praschan 5a85f9b1d4 Add semantic token modifier for non-const reference parameter
See https://github.com/clangd/clangd/issues/839

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D108320
2021-09-13 00:51:09 -04:00
Matt Beardsley c6bf8b8592 Fix python 2-vs-3 issues in add_new_check.py and rename_check.py
As of this commit:
  https://github.com/llvm/llvm-project/commit/307b1fdd

If either of those scripts are invoked with python 2, neither works due to:
  "TypeError: write() argument 1 must be unicode, not str"

And if rename_check.py is invoked with python 3:
  "ValueError: binary mode doesn't take an encoding argument"
(referring to `with io.open(filename, 'wb', encoding='utf8') as f:`), and

Another issue in rename_check.py in python 2:
  "TypeError: list object is not an iterator"
(referring to `next(filter( ... os.listdir(old_module_path)))`)

(so, rename_check doesn't work with either 2 or 3, and add_new_check
doesn't work with 2, but does work with 3)

I ran these steps to test both python versions:
(manually - appears to be the "status quo" for these files)

  python3 clang-tools-extra/clang-tidy/add_new_check.py readability ggggg
  python3 clang-tools-extra/clang-tidy/rename_check.py readability-ggggg readability-hhhhh

  git checkout HEAD -- clang-tools-extra/clang-tidy/readability/CMakeLists.txt clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/docs/clang-tidy/checks/list.rst
  rm -f clang-tools-extra/clang-tidy/readability/GggggCheck.cpp clang-tools-extra/clang-tidy/readability/GggggCheck.h clang-tools-extra/docs/clang-tidy/checks/readability-ggggg.rst clang-tools-extra/test/clang-tidy/checkers/readability-ggggg.cpp clang-tools-extra/clang-tidy/readability/HhhhhCheck.cpp clang-tools-extra/clang-tidy/readability/HhhhhCheck.h clang-tools-extra/docs/clang-tidy/checks/readability-hhhhh.rst

  python2 clang-tools-extra/clang-tidy/add_new_check.py readability ggggg
  python2 clang-tools-extra/clang-tidy/rename_check.py readability-ggggg readability-hhhhh

  git checkout HEAD -- clang-tools-extra/clang-tidy/readability/CMakeLists.txt clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/docs/clang-tidy/checks/list.rst
  rm -f clang-tools-extra/clang-tidy/readability/GggggCheck.cpp clang-tools-extra/clang-tidy/readability/GggggCheck.h clang-tools-extra/docs/clang-tidy/checks/readability-ggggg.rst clang-tools-extra/test/clang-tidy/checkers/readability-ggggg.cpp clang-tools-extra/clang-tidy/readability/HhhhhCheck.cpp clang-tools-extra/clang-tidy/readability/HhhhhCheck.h clang-tools-extra/docs/clang-tidy/checks/readability-hhhhh.rst

Reviewed By: kbobyrev

Differential Revision: https://reviews.llvm.org/D109127
2021-09-11 09:52:50 +02:00
Nilay Vaish e976fc61ec Add "profiling" to the list of absl libraries.
Reviewed By: ymandel

Differential Revision: https://reviews.llvm.org/D109470
2021-09-09 20:31:06 +00:00
Marco Gartmann c58c7a6ea0 [clang-tidy] cppcoreguidelines-virtual-base-class-destructor: a new check
Finds base classes and structs whose destructor is neither public and
virtual nor protected and non-virtual.
A base class's destructor should be specified in one of these ways to
prevent undefined behaviour.

Fixes are available for user-declared and implicit destructors that are
either public and non-virtual or protected and virtual.

This check implements C.35 [1] from the CppCoreGuidelines.

Reviewed By: aaron.ballman, njames93

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

  [1]: http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-dtor-virtual
2021-09-09 13:23:38 +02:00
Artem Dergachev dcde8fdeeb [clang-tidy] bugprone-infinite-loop: Fix false positives with volatile addresses.
Low-level code may occasionally deal with direct access by concrete addresses
such as 0x1234. Values at these addresses act like globals: they can change
at any time. They typically wear volatile qualifiers.

Suppress all warnings on loops with conditions that involve casting anything to
a pointer-to-...-pointer-to-volatile type.

The closely related bugprone-redundant-branch-condition check
doesn't seem to be affected. Add a test just in case.

Differential Revision: https://reviews.llvm.org/D108808
2021-09-07 15:10:46 -07:00