Commit Graph

7407 Commits

Author SHA1 Message Date
Adam Czachorowski fba563e92b [clangd] TargetFinder: Fix assert-crash on TemplateExpansion args.
Previously we would call getAsTemplate() when kind == TemplateExpansion,
which triggers an assertion. The call is now replaced with
getAsTemplateOrTemplatePattern(), which is exactly the same as
getAsTemplate(), except it allows calls when kind == TemplateExpansion.

No change in behavior for no-assert builds.

Differential Revision: https://reviews.llvm.org/D111648
2021-10-13 13:15:36 +02:00
Balázs Kéri a76cfc2e84 [clang-tidy] Update documentation of check bugprone-unused-return-value [NFC].
The list of checked functions was incomplete in the description.

Reviewed By: aaron.ballman, steakhal

Differential Revision: https://reviews.llvm.org/D111623
2021-10-12 16:43:45 +02:00
Carlos Galvez 40546cb381 Remove 'IgnoreDestructors = true' from cppcoreguidelines-explicit-virtual-functions
This requirement was introduced in the C++ Core guidelines in 2016:

1894380d0a

Then clang-tidy got updated to comply with the rule.

However in 2019 this decision was reverted:

5fdfb20b76

Therefore we need to apply the correct configuration to
clang-tidy again.

This also makes this cppcoreguidelines check consistent
with the other 2 alias checks: hicpp-use-override and
modernize-use-override.

Additionally, add another RUN line to the unit test,
to make sure cppcoreguidelines-explicit-virtual-functions
is tested.
2021-10-12 10:08:08 -04:00
Kirill Bobyrev 6393c21d47 [clangd] IncludeCleaner: Stop crashing when included file is not found 2021-10-08 14:51:11 +02:00
Kirill Bobyrev b1309a1ed9 [clangd] Revert unwanted change from D108194
Left-overs from the review process were not deleted.
2021-10-08 10:42:30 +02:00
Simon Pilgrim b9b90bb542 [clang] Replace report_fatal_error(std::string) uses with report_fatal_error(Twine)
As described on D111049, we're trying to remove the <string> dependency from error handling and replace uses of report_fatal_error(const std::string&) with the Twine() variant which can be forward declared.
2021-10-06 11:43:19 +01:00
Kirill Bobyrev 0c14e279c7
[clangd] Revert unwanted change from D108194 2021-10-05 18:44:43 +02:00
Matt Beardsley 32ab79ebc4 [clang-tidy] Fix add_new_check.py to generate correct list.rst autofix column from relative path
Previously, the code in add_new_check.py that looks for fixit keywords in check source files when generating list.rst assumed that the script would only be called from its own path. That means it doesn't find any source files for the checks it's attempting to scan for, and it defaults to writing out nothing in the "Offers fixes" column for all checks. Other parts of add_new_check.py work from other paths, just not this part.

After this fix, add_new_check.py's "offers fixes" column generation for list.rst will be consistent regardless of what path it's called from by using the caller path that's deduced elsewhere already from sys.argv[0].

Reviewed By: kbobyrev

Differential Revision: https://reviews.llvm.org/D110600
2021-10-05 18:09:53 +02:00
Kirill Bobyrev ebfcd06d42 [clangd] IncludeCleaner: Mark used headers
Follow-up on D105426.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D108194
2021-10-05 18:08:24 +02:00
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
Nathan Ridge 3e03d92e2f [clangd] Omit default template arguments from type hints
Differential Revision: https://reviews.llvm.org/D108975
2021-09-07 02:38:27 -04:00
Nathan Ridge c2810f2c16 [clangd] Omit type hints that are too long
Differential Revision: https://reviews.llvm.org/D108972
2021-09-07 02:33:58 -04:00
Kazu Hirata dfc46f0268 [clang-tidy] Drop unnecessary const from return types (NFC)
Identified with readability-const-return-type.
2021-09-05 08:37:27 -07:00
Louis Dionne 79f8b5f0d0 Revert "[Coroutines] [Clang] Look up coroutine component in std namespace first"
This reverts commit 2fbd254aa4, which broke the libc++ CI. I'm reverting
to get things stable again until we've figured out a way forward.

Differential Revision: https://reviews.llvm.org/D108696
2021-09-03 16:01:09 -04:00
David Goldman 2982bd9e9b [clangd] Use the active file's language for hover code blocks
This helps improve the syntax highlighting for Objective-C code,
although it currently doesn't work well in VS Code with
methods/properties/ivars since we don't currently include the proper
decl context (e.g. class).

Differential Revision: https://reviews.llvm.org/D108584
2021-09-03 11:38:27 -04:00
Chuanqi Xu 2fbd254aa4 [Coroutines] [Clang] Look up coroutine component in std namespace first
Summary: Now in libcxx and clang, all the coroutine components are
defined in std::experimental namespace.
And now the coroutine TS is merged into C++20. So in the working draft
like N4892, we could find the coroutine components is defined in std
namespace instead of std::experimental namespace.
And the coroutine support in clang seems to be relatively stable. So I
think it may be suitable to move the coroutine component into the
experiment namespace now.

But move the coroutine component into the std namespace may be an break
change. So I planned to split this change into two patch. One in clang
and other in libcxx.

This patch would make clang lookup coroutine_traits in std namespace
first. For the compatibility consideration, clang would lookup in
std::experimental namespace if it can't find definitions in std
namespace and emit a warning in this case. So the existing codes
wouldn't be break after update compiler.

Test Plan: check-clang, check-libcxx

Reviewed By: lxfind

Differential Revision: https://reviews.llvm.org/D108696
2021-09-03 10:22:55 +08:00
David Blaikie 5fb3f43778 Fully qualify template template parameters when printing
I discovered this quirk when working on some DWARF - AST printing prints
type template parameters fully qualified, but printed template template
parameters the way they were written syntactically, or wholely
unqualified - instead, we should print them consistently with the way we
print type template parameters: fully qualified.

The one place this got weird was for partial specializations like in
ast-print-temp-class.cpp - hence the need for checking for
TemplateNameDependenceScope::DependentInstantiation template template
parameters. (not 100% sure that's the right solution to that, though -
open to ideas)

Differential Revision: https://reviews.llvm.org/D108794
2021-09-02 15:04:34 -07:00
Kazu Hirata e1bb54b593 [clangd, llvm] Remove redundant calls to c_str() (NFC)
Identified with readability-redundant-string-cstr.
2021-09-02 09:07:13 -07:00
Kazu Hirata d8afa5777b [clang-tidy] Fix documentation typos (NFC) 2021-09-01 08:48:31 -07:00
Gabor Bencze 3373e84539 [clang-tidy] Add bugprone-suspicious-memory-comparison check
The check warns on suspicious calls to `memcmp`.
It currently checks for comparing types that do not have
unique object representations or are non-standard-layout.
Based on
  https://wiki.sei.cmu.edu/confluence/display/c/EXP42-C.+Do+not+compare+padding+data
  https://wiki.sei.cmu.edu/confluence/display/c/FLP37-C.+Do+not+use+object+representations+to+compare+floating-point+values
and part of
  https://wiki.sei.cmu.edu/confluence/display/cplusplus/OOP57-CPP.+Prefer+special+member+functions+and+overloaded+operators+to+C+Standard+Library+functions
Add alias `cert-exp42-c` and `cert-flp37-c`.

Some tests are currently failing at head, the check depends on D89649.
Originally started in D71973

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D89651
2021-08-26 09:23:37 +02:00
Whisperity 8d50a847d4 [clang-tidy] Hotfix default parameter value in 'bugprone-easily-swappable-parameters'
As identified by @RKSimon, there was a missing comma in the default
value for the "ignored parameter type suffixes" array, resulting in
bogus concatenation of two elements.
2021-08-24 16:10:19 +02:00
Simon Pilgrim b2aa470fae [clangd] detectClangPath() - remove (dead) return. NFC. 2021-08-20 12:41:38 +01:00
Kirill Bobyrev d1ec581ebf
[clangd] IncludeCleaner as a library: Find all references to symbols in the file
This is the first patch in an ongoing attempt of Include Cleaner: unused/missing
headere diagnostics, an IWYU-like functionality implementation for clangd. The
work is split into (mostly) distinct and parallelizable pieces:

- Finding all referenced locations (this patch).
- Finding all referenced locations of macros.
- Building IncludeGraph and marking headers as unused, used and directly used.
- Making use of the introduced library and add an option to use in clangd.

---

* Adding support for standard library headers (possibly through mapping
  genfiles).

Based on https://reviews.llvm.org/D100540.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D105426
2021-08-18 10:08:35 +02:00
Nathan Ridge 47d9d55c66 [clangd] Do not show inlay hints pertaining to code in other files
Fixes https://github.com/clangd/clangd/issues/817

Differential Revision: https://reviews.llvm.org/D106934
2021-08-16 01:58:23 -04:00
mydeveloperday fe866327c1 [clang-tidy] [PR50069] readability-braces-around-statements doesn't work well with [[likely]] [[unlikely]]
https://bugs.llvm.org/show_bug.cgi?id=50069

When clang-tidy sees:

```
if (true) [[unlikely]] {
    ...
}
```

It thinks the braces are missing and add them again.

```
if (true)  { [[unlikely]] {
    ...
  }
}
```

This revision aims to prevent that incorrect code generation

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D105479
2021-08-14 12:05:21 +01:00
liuke 1f2d40c47f [clang-tidy] fix duplicate '{}' in cppcoreguidelines-pro-type-member-init
The overload of the constructor will repeatedly fix the member variables that need to be initialized.
Removed the duplicate '{}'.

```
struct A {
  A() {}
  A(int) {}
  int _var;  // int _var{}{};  <--  wrong fix
};
```

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D107641
2021-08-14 10:48:04 +08:00
Sam McCall 7d65cc98f3 [clangd] Guard against null Attrs in the AST 2021-08-13 10:38:52 +02:00
Sam McCall 2ff7ca98a9 [clangd] Avoid "expected one compiler job" by picking the first eligible job.
This happens in createInvocationWithCommandLine but only clangd currently passes
ShouldRecoverOnErorrs (sic).

One cause of this (with correct command) is several -arch arguments for mac
multi-arch support.

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

Differential Revision: https://reviews.llvm.org/D107632
2021-08-13 00:36:30 +02:00
Christian Kandeler 6b28835b37 clangd: Make documentation property of completion items more similar
... to the one of signature hints.
In particular, completion items now also carry annotations, which client
code might be interested in.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D107365
2021-08-13 00:18:15 +02:00
Christian Kandeler f9c8602b53 clangd: Provide hover info for include directives
It's quite useful to be able to hover over an #include and see the full
path to the header file.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D107137
2021-08-13 00:07:23 +02:00
Sam McCall ece4e92085 [CodeComplete] Basic code completion for attribute names.
Only the bare name is completed, with no args.
For args to be useful we need arg names. These *are* in the tablegen but
not currently emitted in usable form, so left this as future work.

C++11, C2x, GNU, declspec, MS syntax is supported, with the appropriate
spellings of attributes suggested.
`#pragma clang attribute` is supported but not terribly useful as we
only reach completion if parens are balanced (i.e. the line is not truncated)

There's no filtering of which attributes might make sense in this
grammatical context (e.g. attached to a function). In code-completion context
this is hard to do, and will only work in few cases :-(

There's also no filtering by langopts: this is because currently the
only way of checking is to try to produce diagnostics, which requires a
valid ParsedAttr which is hard to get.
This should be fairly simple to fix but requires some tablegen changes
to expose the logic without the side-effect.

Differential Revision: https://reviews.llvm.org/D107696
2021-08-12 23:49:10 +02:00
Sam McCall 08c04ca005 [clangd] Overload bundles are only deprecated if each overloads is.
Fixes https://github.com/clangd/clangd/issues/705

Differential Revision: https://reviews.llvm.org/D97803
2021-08-12 23:46:08 +02:00
Sam McCall 18f9e25ce1 [AST][clangd] Expose documentation of Attrs on hover.
This adds a method to Attr to get at the documentation programmatically.

Differential Revision: https://reviews.llvm.org/D107703
2021-08-12 21:16:37 +02:00
Aaron Ballman a49ca198ba Speculatively fix the build bots.
This is a fix for commit d2c5cbc3a8
2021-08-12 11:56:17 -04:00
Florin Iucha d2c5cbc3a8 Add a check for enforcing minimum length for variable names
Add a check for enforcing minimum length for variable names. A default
minimum length of three characters is applied to regular variables
(including function parameters). Loop counters and exception variables
have a minimum of two characters. Additionally, the 'i', 'j' and 'k'
are accepted as legacy values.

All three sizes, as well as the list of accepted legacy loop counter
names are configurable.
2021-08-12 11:31:26 -04:00
Whisperity 39bbbc2c2a [clang-tidy][docs] Remove the entry about 'cppcoreguidelines-init-variables' from the release notes
The patch in http://reviews.llvm.org/D106431 landed in commit
4a097efe77 to the main branch.
However, this patch was also backported to upcoming release 13.0.0 in
commit 8dcdfc0de84f60b5b4af97ac5b357881af55bc6e, which makes this entry
in the release notes **NOT** a new thing for the purposes of 14.0.0.
2021-08-12 10:41:46 +02:00
Christopher Di Bella c874dd5362 [llvm][clang][NFC] updates inline licence info
Some files still contained the old University of Illinois Open Source
Licence header. This patch replaces that with the Apache 2 with LLVM
Exception licence.

Differential Revision: https://reviews.llvm.org/D107528
2021-08-11 02:48:53 +00:00
Sam McCall 0cecb42e4e [Sema] Include full range of the switch condition in -Wswitch diagnostic 2021-08-10 22:50:40 +02:00
Tom Lokovic 1fdb3e36ff abseil-string-find-str-contains should not propose an edit for the three-parameter version of find().
std::string, std::string_view, and absl::string_view all have a three-parameter version of find()
which has a "count" (or "n") paremeter limiting the size of the substring to search.  We don't want
to propose changing to absl::StrContains in those cases.  This change fixes that and adds unit tests
to confirm.

Reviewed By: ymandel

Differential Revision: https://reviews.llvm.org/D107837
2021-08-10 16:39:17 +00:00
Florian Mayer 45abbaf2e5 Revert "[clangd] Support `#pragma mark` in the outline"
This reverts commit ba06ac8b45.
2021-08-10 14:25:52 +01:00
David Goldman ba06ac8b45 [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-08-09 16:23:53 -04:00
Sam McCall c5c3cdb9c9 [clangd] Populate-switch triggers when the whole condition is selected.
This allows vscode to find it as a diagnostic quickfix for -Wswitch.

While here, group the code into chunks and add a couple more comments.
2021-08-08 21:06:08 +02:00
Sam McCall bb81e7083d [clangd] Add basic support for attributes (selection, hover)
These aren't terribly common, but we currently mishandle them badly.
Not only do we not recogize the attributes themselves, but we often end up
selecting some node other than the parent (because source ranges aren't accurate
in the presence of attributes).

Differential Revision: https://reviews.llvm.org/D89785
2021-08-06 22:49:14 +02:00
Sam McCall c8f148274f Reapply "Support Attr in DynTypedNode and ASTMatchers."
This reverts commit 3241680f11.
Fixed mangled post-test formatting :-(
2021-08-06 22:30:32 +02:00
Sam McCall 3241680f11 Revert "Support Attr in DynTypedNode and ASTMatchers."
This reverts commit a4bdcdadc6.

Fails bots:
https://lab.llvm.org/buildbot/#/builders/109/builds/20231/steps/6/logs/stdio
2021-08-06 22:27:54 +02:00
Sam McCall a4bdcdadc6 Support Attr in DynTypedNode and ASTMatchers.
Differential Revision: https://reviews.llvm.org/D89743
2021-08-06 22:06:04 +02:00
Sam McCall 4ad9ec8a32 [clangd] Rename Features.h -> Feature.h to avoid confilct with libstdc++
Fixes https://github.com/clangd/clangd/issues/835

Differential Revision: https://reviews.llvm.org/D107624
2021-08-06 18:56:41 +02:00
Kadir Cetinkaya 79c2616d31
[clangd] Canonicalize inputs provided with `--`
We already strip all the inputs provided without `--`, this patch also
handles the cases with `--`.

Differential Revision: https://reviews.llvm.org/D107637
2021-08-06 15:04:04 +02:00
Kadir Cetinkaya 3bf77980d9
[clangd] Strip mutliple arch options
This patch strips all the arch options in case of multiple ones. As it
results in multiple compiler jobs, which clangd cannot handle.

It doesn't pick any over the others as it is unclear which one the user wants
and defaulting to host architecture seems less surprising. Users also have the
ability to explicitly specify the architecture they want via clangd config
files.

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

Differential Revision: https://reviews.llvm.org/D107634
2021-08-06 15:04:04 +02:00
Christian Kandeler 159a269648 [clangd] Add new semantic token modifier "virtual"
This is needed for clients that want to highlight virtual functions
differently.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D107145
2021-08-03 19:53:01 -07:00
Douglas Chen 559d142331 [clang-tidy] Fix command line is too long issue which breaks test on Windows
This patch tries to fix command line too long problem on Windows for
https://reviews.llvm.org/D86671.

The command line is too long with check_clang_tidy.py program on Windows,
because the configuration is long for regression test. Fix this issue by
passing the settings in file instead.

Differential Revision: https://reviews.llvm.org/D107325
2021-08-03 22:12:46 +02:00