Commit Graph

7799 Commits

Author SHA1 Message Date
Danny Mösch ef19de52ed [clang-tidy] Add release notes for changes made in 2b21fc5520 2022-04-03 15:48:39 +02:00
Richard f547fc89c0 [clang-tidy] Add modernize-macro-to-enum check
[buildbot issues fixed]

This check performs basic analysis of macros and replaces them
with an anonymous unscoped enum.  Using an unscoped anonymous enum
ensures that everywhere the macro token was used previously, the
enumerator name may be safely used.

Potential macros for replacement must meet the following constraints:
- Macros must expand only to integral literal tokens.  The unary
  operators plus, minus and tilde are recognized to allow for positive,
  negative and bitwise negated integers.
- Macros must be defined on sequential source file lines, or with
  only comment lines in between macro definitions.
- Macros must all be defined in the same source file.
- Macros must not be defined within a conditional compilation block.
- Macros must not be defined adjacent to other preprocessor directives.
- Macros must not be used in preprocessor conditions

Each cluster of macros meeting the above constraints is presumed to
be a set of values suitable for replacement by an anonymous enum.
From there, a developer can give the anonymous enum a name and
continue refactoring to a scoped enum if desired.  Comments on the
same line as a macro definition or between subsequent macro definitions
are preserved in the output.  No formatting is assumed in the provided
replacements.

The check cppcoreguidelines-macro-to-enum is an alias for this check.

Fixes #27408

Differential Revision: https://reviews.llvm.org/D117522
2022-04-01 15:24:21 -06:00
Kadir Cetinkaya e2f598bc1b
[clangd] Record IO precentage for first preamble build of the instance
Differential Revision: https://reviews.llvm.org/D122894
2022-04-01 15:12:37 +02:00
Kirill Bobyrev f43c4c5be2 Revert "[clangd] IncludeCleaner: Add support for IWYU pragma private"
This reverts commit 4cb38bfe76.

Awkwardly enough, this builds Windows buildbots:

http://45.33.8.238/win/55402/step_9.txt

It is yet unclear why this is happening but I will need more time to
diagnose the issue.
2022-03-31 17:59:52 +02:00
David Goldman d9739f29cd Serialize PragmaAssumeNonNullLoc to support preambles
Previously, if a `#pragma clang assume_nonnull begin` was at the
end of a premable with a `#pragma clang assume_nonnull end` at the
end of the main file, clang would diagnose an unterminated begin in
the preamble and an unbalanced end in the main file.

With this change, those errors no longer occur and the case above is
now properly handled. I've added a corresponding test to clangd,
which makes use of preambles, in order to verify this works as
expected.

Differential Revision: https://reviews.llvm.org/D122179
2022-03-31 11:08:01 -04:00
Kirill Bobyrev 4cb38bfe76
[clangd] IncludeCleaner: Add support for IWYU pragma private
Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D120306
2022-03-31 12:49:52 +02:00
Danny Mösch b3079e8a7e [clang-tidy] Make test work on architectures which do not provide a `__int128_t`
See f10cee91ae. The test did still not run successful since the
`CHECK-MESSAGE` line is still read and considered even though the `#ifdef` removes the code if
`__int128_t` is not available. Now there is a fallback type in this case.
2022-03-30 08:03:32 +02:00
Danny Mösch f10cee91ae [clang-tidy] Fix test failing on 32-bit architectures due to missing `__int128_t`
This was caused by ff60af91ac. The reason for the failure is that
the type `__int128_t` is not available on 32-bit architectures. So just exclude the test case if
128-bit integers are not available.
2022-03-29 17:58:12 +02:00
Nathan Ridge 9325e97a35 [clangd] Handle tabs in getIncrementalChangesAfterNewline()
Tabs are not handled by columnWidthUTF8() (they are considered
non-printable) so require additional logic to handle.

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

Differential Revision: https://reviews.llvm.org/D122554
2022-03-29 01:43:09 -04:00
Danny Mösch ff60af91ac [clang-tidy] Utilize comparison operation implemented in APInt
This is a fix for #53963.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D122544
2022-03-28 23:32:58 +02:00
Haojian Wu 16eaa5240e [pseudo] Fix the wrong rule ids in ForestTest. 2022-03-26 00:05:37 +01:00
Haojian Wu 41e69fb245 [pseudo] Add missing header guard for Forest.h 2022-03-25 23:51:19 +01:00
Martin Storsjö 9a3eeae321 [clang-tidy] Fix the condition for building CTTestTidyModule
This is the correct intended condition; the problematic case where
we don't want to try to build the plugin is "WIN32 AND LLVM_LINK_LLVM_DYLIB"
and thus the negation is "NOT WIN32 OR NOT LLVM_LINK_LLVM_DYLIB".

Differential Revision: https://reviews.llvm.org/D121687
2022-03-25 21:22:46 +02:00
Sam McCall 57ee624d79 [cmake] Provide CURRENT_TOOLS_DIR centrally, replacing CLANG_TOOLS_DIR
CLANG_TOOLS_DIR holds the the current bin/ directory, maybe with a %(build_mode)
placeholder. It is used to add the just-built binaries to $PATH for lit tests.
In most cases it equals LLVM_TOOLS_DIR, which is used for the same purpose.
But for a standalone build of clang, CLANG_TOOLS_DIR points at the build tree
and LLVM_TOOLS_DIR points at the provided LLVM binaries.

Currently CLANG_TOOLS_DIR is set in clang/test/, clang-tools-extra/test/, and
other things always built with clang. This is a few cryptic lines of CMake in
each place. Meanwhile LLVM_TOOLS_DIR is provided by configure_site_lit_cfg().

This patch moves CLANG_TOOLS_DIR to configure_site_lit_cfg() and renames it:
 - there's nothing clang-specific about the value
 - it will also replace LLD_TOOLS_DIR, LLDB_TOOLS_DIR etc (not in this patch)

It also defines CURRENT_LIBS_DIR. While I removed the last usage of
CLANG_LIBS_DIR in e4cab4e24d, there are LLD_LIBS_DIR usages etc that
may be live, and I'd like to mechanically update them in a followup patch.

Differential Revision: https://reviews.llvm.org/D121763
2022-03-25 20:22:01 +01:00
Douglas Yung cef52105bd Revert "[clang-tidy] Add modernize-macro-to-enum check"
This reverts commit 39b80c8380.

This change was causing build failures on several build bots:
- https://lab.llvm.org/buildbot/#/builders/139/builds/19210
- https://lab.llvm.org/buildbot/#/builders/93/builds/7956
2022-03-25 11:53:42 -07:00
Nathan James b97f26083b Reland "[ASTMatchers] Output currently processing match and nodes on crash"
This reverts commit cff34ccb60.

This relands commit d89f9e963e
2022-03-25 17:53:58 +00:00
Richard 39b80c8380 [clang-tidy] Add modernize-macro-to-enum check
This check performs basic analysis of macros and replaces them
with an anonymous unscoped enum.  Using an unscoped anonymous enum
ensures that everywhere the macro token was used previously, the
enumerator name may be safely used.

Potential macros for replacement must meet the following constraints:
- Macros must expand only to integral literal tokens.  The unary
  operators plus, minus and tilde are recognized to allow for positive,
  negative and bitwise negated integers.
- Macros must be defined on sequential source file lines, or with
  only comment lines in between macro definitions.
- Macros must all be defined in the same source file.
- Macros must not be defined within a conditional compilation block.
- Macros must not be defined adjacent to other preprocessor directives.
- Macros must not be used in preprocessor conditions

Each cluster of macros meeting the above constraints is presumed to
be a set of values suitable for replacement by an anonymous enum.
From there, a developer can give the anonymous enum a name and
continue refactoring to a scoped enum if desired.  Comments on the
same line as a macro definition or between subsequent macro definitions
are preserved in the output.  No formatting is assumed in the provided
replacements.

The check cppcoreguidelines-macro-to-enum is an alias for this check.

Fixes #27408

Differential Revision: https://reviews.llvm.org/D117522
2022-03-25 09:45:55 -06:00
Sam McCall 72864d9bfe [pseudo] Use box-drawing chars to prettify debug dumps. NFC 2022-03-25 14:17:38 +01:00
Kadir Cetinkaya 50f4f32b56
[clangd] Retain main file fixes attached to diags from preamble
Clangd ignores fixits if the diagnsotics is outside the main file (e.g.
a note on a declaration from a header), but the fix might still be inside the
main file (e.g. change the function call).

This patch changes the logic to retain fixes that touch main file, if the
diagnostic owning them is still inside main file, even if they are attached to a
note outside the main file.

Differential Revision: https://reviews.llvm.org/D122315
2022-03-24 15:19:25 +01:00
Haojian Wu 62d5f254cc [pseudo] Introduce parse forest.
Parse forest is the output of the GLR parser, it is a tree-like DAG
which presents all possible parse trees without duplicating subparse structures.

This is a patch split from https://reviews.llvm.org/D121150.

Differential Revision: https://reviews.llvm.org/D122139
2022-03-24 14:47:17 +01:00
Haojian Wu f383b88d82 [pseudo] Sort nonterminals based on their reduction order.
Reductions need to be performed in a careful order in GLR parser, to
make sure we gather all alternatives before creating an ambigous forest
node.

This patch encodes the nonterminal order into the rule id, so that we
can efficiently to determinal ordering of reductions in GLR parser.

This patch also abstracts to a TestGrammar, which is shared among tests.

This is a part of the GLR parser, https://reviews.llvm.org/D121368,
https://reviews.llvm.org/D121150

Differential Revision: https://reviews.llvm.org/D122303
2022-03-24 14:30:12 +01:00
Sam McCall 31dc248ffc [clangd] Fix IncludeFixer test on windows
Actual functionality doesn't seem to work with (default)
-fms-compatibility. Not sure why yet...
2022-03-23 18:57:08 +01:00
Sam McCall 2da5c5781e [clangd] Add inlay hints for auto-typed parameters with one instantiation.
This takes a similar approach as b9b6938183, and shares some code.
The code sharing is limited as inlay hints wants to deduce the type of the
variable rather than the type of the `auto` per-se.

It drops support (in both places) for multiple instantiations yielding the same
type, as this is pretty rare and hard to build a nice API around.

Differential Revision: https://reviews.llvm.org/D120258
2022-03-23 17:26:25 +01:00
Sam McCall b857a5092c [clangd] Support include-fixer inside macro arguments.
Motivating case: EXPECT_EQ(42, missingFunction(bar));

Differential Revision: https://reviews.llvm.org/D120619
2022-03-23 17:12:33 +01:00
Danny Mösch a749e3295d Replace links to archived mailing lists by links to Discourse forums 2022-03-23 10:10:20 -04:00
Fabian Wolff 07675b0b38 [clang-tidy] Fix false positives in `misc-redundant-expression` check
Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D122111
2022-03-23 00:32:45 +01:00
Haojian Wu 1579090141 Reland "[pseudo] Split greatergreater token."
It was reverted, because the test had a lift-time issue.
Reland f66d3758bd with a fix.
2022-03-22 10:27:52 +01:00
Martin Storsjö 3e7a8aab75 [clang-tidy] Don't try to build CTTestTidyModule for Windows with dylibs
In MinGW mode, it's possible to build LLVM/Clang with
LLVM_LINK_LLVM_DYLIB (which implicitly enables plugins too). Other
existing ways of building plugins on Windows is to build with
LLVM_EXPORT_SYMBOLS_FOR_PLUGINS, where each executable exports its
symbols.

With LLVM_LINK_LLVM_DYLIB, we can't generally skip building plugins
even if they are set up with PLUGIN_TOOL, as some plugins (e.g.
under clang/examples) set up that way do build properly (as
they manually call clang_target_link_libraries, which links in the
libclang-cpp.dll dylib).

For CTTestTidyModule, there's no corresponding dylib that would
provide the same exports.

Differential Revision: https://reviews.llvm.org/D121687
2022-03-22 11:08:32 +02:00
Nathan James cff34ccb60 Revert "[ASTMatchers] Output currently processing match and nodes on crash"
This reverts commit d89f9e963e.
2022-03-21 22:29:22 +00:00
Eric Li 9edeceaece [libTooling] Generalize string explanation as templated metadata
Change RewriteRule from holding an `Explanation` to being able to generate
arbitrary metadata. Where TransformerClangTidyCheck was interested in a string
description for the diagnostic, other tools may be interested in richer metadata
at a higher level of abstraction than at the edit level (which is currently
available as ASTEdit::Metadata).

Reviewed By: ymandel

Differential Revision: https://reviews.llvm.org/D120360
2022-03-21 20:39:35 +00:00
Nathan James d89f9e963e
[ASTMatchers] Output currently processing match and nodes on crash
Create a PrettyStackTraceEvent that will dump the current `MatchCallback` id as well as the `BoundNodes` if the 'run' method of a `MatchCallback` results in a crash.
The purpose of this is sometimes clang-tidy checks can crash in the `check` method. And in a large codebase with alot of checks enabled and in a release build, it can be near impossible to figure out which check as well as the source code that caused the crash. Without that information a reproducer is very hard to create.
This is a more generalised version of D118520 which has a nicer integration and should be useful to clients other than clang-tidy.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D120185
2022-03-21 19:13:36 +00:00
Yitzhak Mandelbaum 8351726e6d Revert "[libTooling] Generalize string explanation as templated metadata"
This reverts commit 18440547d3. Causing failures
in some build modes.

e.g. https://lab.llvm.org/buildbot/#/builders/217/builds/1886
2022-03-21 19:06:59 +00:00
Eric Li 18440547d3 [libTooling] Generalize string explanation as templated metadata
Change RewriteRule from holding an `Explanation` to being able to generate
arbitrary metadata. Where TransformerClangTidyCheck was interested in a string
description for the diagnostic, other tools may be interested in richer metadata
at a higher level of abstraction than at the edit level (which is currently
available as ASTEdit::Metadata).

Reviewed By: ymandel

Differential Revision: https://reviews.llvm.org/D120360
2022-03-21 18:45:39 +00:00
Sam McCall 46dbd19afb [clangd] Fix nullptr crash in AddUsing tweak on catch(...)
Fixes https://github.com/clangd/clangd/issues/1072
2022-03-21 18:56:45 +01:00
Adam Czachorowski 6009d0d580 [clangd] Track time spent in filesystem ops during preamble builds
In some deployments, for example when running on FUSE or using some
network-based VFS implementation, the filesystem operations might add up
to a significant fraction of preamble build time. This change allows us
to track time spent in FS operations to better understand the problem.

Differential Revision: https://reviews.llvm.org/D121712
2022-03-21 18:33:01 +01:00
Kadir Cetinkaya 164a10dcf2
[clangd] Test against path insensitivity
Differential Revision: https://reviews.llvm.org/D121286
2022-03-21 17:27:05 +01:00
Sam McCall 1f92f44ec9 [pseudo] fix typo'd test assertions 2022-03-21 14:05:21 +01:00
Evgeny Shulgin fc354d3752 [clang-tidy] Skip parentheses in `readability-make-member-function-const`
The checker should ignore parentheses when looking whether the
function should be marked as `const`.

Fixes https://github.com/llvm/llvm-project/issues/52838

Reviewed By: mgehre-amd, njames93

Differential Revision: https://reviews.llvm.org/D122075
2022-03-21 14:18:17 +03:00
Zequan Wu 217f267efe Revert "[pseudo] Split greatergreater token."
This reverts commit f66d3758bd.

It breaks windows bot.
2022-03-18 10:15:48 -07:00
David Goldman 8522a01e84 Attempt forward fix for Linux buildbots for D116385 2022-03-17 12:49:16 -04:00
David Goldman 1af5fbd5c6 [clangd] Code action for creating an ObjC initializer
The code action creates an initializer for the selected
ivars/properties, defaulting to all if only the interface/implementation
container is selected.

We add it based on the position of the first non initializer that we
see, and default to adding it where the @end token is.

We also use the ObjC parameter form of (nullable id) instead of
(id _Nullable) if the property has the nullable attribute.

Differential Revision: https://reviews.llvm.org/D116385
2022-03-17 11:31:14 -04:00
Haojian Wu 30de15e100 [pseudo] Tweak some docs, NFC
Consitently use the "nonterminal", "pseudoparser" terms.
2022-03-17 13:58:42 +01:00
Haojian Wu eb265e3ba2 [clangd] Re-enable clang-tidy's nolint blocks
The previous inefficient implementation is polished.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D119701
2022-03-17 13:48:55 +01:00
Haojian Wu f66d3758bd [pseudo] Split greatergreater token.
For a >> token (a right shift operator, or a nested template?), the clang
lexer always returns a single greatergreater token, as a result,
the grammar-based GLR parser never try to parse the nested template
case.

We derive a token stream by always splitting the >> token, so that the
GLR parser is able to pursue both options during parsing (usually 1
path fails).

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D121678
2022-03-17 13:46:58 +01:00
Shreyas Atre 9e1f4f1398 [clang-tidy][run-clang-tidy.py] Add --config-file=<string> option
Link to the GitHub Issue: https://github.com/llvm/llvm-project/issues/53745

Added config_path variable within the python script which makes the
required call to the clang-tidy binary with --config-file option.
If the config_path is None then config will be used. No error is raised
if both are given but silently chooses config_path over config
2022-03-17 07:30:28 -04:00
Evgeny Shulgin 6043520c20 [clang-tidy] Don't check decltype return types in `readability-const-return-type`
The checker removes `const`s that are superfluos and badly affect
readability. `decltype(auto)`/`decltype(expr)` are often const-qualified, but
have no effect on readability and usually can't stop being const-qualified
without significant code change.

Fixes https://github.com/llvm/llvm-project/issues/52890

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D119470
2022-03-17 14:27:09 +03:00
Haojian Wu 5a624956ce [pseudo] Fix some naming-style violations. 2022-03-17 09:47:24 +01:00
Nathan Ridge 606ba8a68f [clangd] Handle more than two conflicting semantic tokens in resolveConflict()
Fixes https://github.com/clangd/clangd/issues/1057

Differential Revision: https://reviews.llvm.org/D121775
2022-03-16 12:53:04 -04:00
Haojian Wu e5b1b9edb8 [pseudo] Cleanup the leftover header guards after the movement, NFC. 2022-03-16 16:25:18 +01:00
Sam McCall e4cab4e24d [lit] Remove clang_libs_dir
Seems to have been added accidentally in 58db03a116 and then
copied into clangd by me (but not actually needed).
2022-03-16 03:03:02 +01:00