Commit Graph

7366 Commits

Author SHA1 Message Date
David Blaikie aee4925507 Recommit: Compress formatting of array type names (int [4] -> int[4])
Based on post-commit review discussion on
2bd8493847 with Richard Smith.

Other uses of forcing HasEmptyPlaceHolder to false seem OK to me -
they're all around pointer/reference types where the pointer/reference
token will appear at the rightmost side of the left side of the type
name, so they make nested types (eg: the "int" in "int *") behave as
though there is a non-empty placeholder (because the "*" is essentially
the placeholder as far as the "int" is concerned).

This was originally committed in 277623f4d5

Reverted in f9ad1d1c77 due to breakages
outside of clang - lldb seems to have some strange/strong dependence on
"char [N]" versus "char[N]" when printing strings (not due to that name
appearing in DWARF, but probably due to using clang to stringify type
names) that'll need to be addressed, plus a few other odds and ends in
other subprojects (clang-tools-extra, compiler-rt, etc).
2021-10-21 11:34:43 -07:00
Kadir Cetinkaya 60e19f6752
[clangd] Fix use-after-free in HeaderIncluderCache
Includer cache could get into a bad state when a main file went bad and
added back afterwards. This patch adds a check to invalidate to prevent
that.

Differential Revision: https://reviews.llvm.org/D112130
2021-10-20 16:36:07 +02:00
Kadir Cetinkaya c959da9ef3
[clangd] Only publish preamble after rebuilds
Don't invoke parsing callback for preamble if clangd is using a
previously built one.

Differential Revision: https://reviews.llvm.org/D112137
2021-10-20 16:32:32 +02:00
Carlos Galvez 7812cb72a3 Use reference type in for loop
To fix failing build job.
2021-10-19 16:37:56 +00:00
Carlos Galvez bf6b0d1674 [clang-tidy] Support globbing in NOLINT* expressions
To simplify suppressing warnings (for example, for
when multiple check aliases are enabled).

The globbing format reuses the same code as for
globbing when enabling checks, so the semantics
and behavior is identical.

Differential Revision: https://reviews.llvm.org/D111208
2021-10-19 16:30:51 +00:00
Adam Czachorowski 8fbac4e88a [clangd] Add code completion of param name on /* inside function calls.
For example, if you have:
  void foo(int bar);
  foo(/*^
it should auto-complete to "bar=".

Because Sema callbacks for code completion in comments happen before we
have an AST we need to cheat in clangd by detecting completion on /*
before, moving cursor back by two characters, then running a simplified
verion of SignatureHelp to extract argument name(s) from possible
overloads.

Differential Revision: https://reviews.llvm.org/D110823
2021-10-19 12:49:46 +02:00
Carlos Galvez f0711106dc [clang-tidy] Fix false positive in cppcoreguidelines-virtual-class-destructor
Incorrectly triggers for template classes that inherit
from a base class that has virtual destructor.

Any class inheriting from a base that has a virtual destructor
will have their destructor also virtual, as per the Standard:

https://timsong-cpp.github.io/cppwp/n4140/class.dtor#9

> If a class has a base class with a virtual destructor,
> its destructor (whether user- or implicitly-declared) is virtual.

Added unit tests to prevent regression.

Fixes bug https://bugs.llvm.org/show_bug.cgi?id=51912

Differential Revision: https://reviews.llvm.org/D110614
2021-10-16 08:27:08 +00:00
Kirill Bobyrev 0ce3c7111e
[clangd] IncludeCleaner: Handle macros coming from ScratchBuffer
Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D111698
2021-10-14 13:36:37 +02:00
liuke ea72b55b5c bugprone-argument-comment: SourceLocation valid judgment avoid emitting coredump in isInSystemHeader
If the Node has an invalid location, it will trigger assert in
isInSystemHeader(...).

void test() {
  __builtin_va_list __args;
  // __builtin_va_list has no defination in any source file and its
  // CXXConstructorDecl has invalid sourcelocation
}
coredump with "Assertion `Loc.isValid() && "Can't get file
characteristic of invalid loc!"' failed." in
getFileCharacteristic(SourceLocation).
2021-10-13 12:31:02 -04:00
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