Skip to content

Commit 7005664

Browse files
committed
fix unused variable
Created using spr 1.3.8-beta.1
2 parents cccf6db + e866587 commit 7005664

File tree

100 files changed

+5305
-2562
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+5305
-2562
lines changed

.github/workflows/issue-write.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- "Check code formatting"
77
- "Check for private emails used in PRs"
88
- "PR Request Release Note"
9+
- "Code lint"
910
types:
1011
- completed
1112

.github/workflows/pr-code-format.yml

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,6 @@ jobs:
3232
base_sha: 'HEAD~1'
3333
sha: 'HEAD'
3434

35-
# We need to pull the script from the main branch, so that we ensure
36-
# we get the latest version of this script.
37-
- name: Fetch code formatting utils
38-
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
39-
with:
40-
repository: ${{ github.repository }}
41-
ref: ${{ github.base_ref }}
42-
sparse-checkout: |
43-
llvm/utils/git/requirements_formatting.txt
44-
llvm/utils/git/code-format-helper.py
45-
sparse-checkout-cone-mode: false
46-
path: code-format-tools
47-
4835
- name: "Listed files"
4936
env:
5037
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
@@ -65,10 +52,10 @@ jobs:
6552
with:
6653
python-version: '3.11'
6754
cache: 'pip'
68-
cache-dependency-path: 'code-format-tools/llvm/utils/git/requirements_formatting.txt'
55+
cache-dependency-path: 'llvm/utils/git/requirements_formatting.txt'
6956

7057
- name: Install python dependencies
71-
run: pip install -r code-format-tools/llvm/utils/git/requirements_formatting.txt
58+
run: pip install -r llvm/utils/git/requirements_formatting.txt
7259

7360
- name: Run code formatter
7461
env:
@@ -77,7 +64,7 @@ jobs:
7764
# Create an empty comments file so the pr-write job doesn't fail.
7865
run: |
7966
echo "[]" > comments &&
80-
python ./code-format-tools/llvm/utils/git/code-format-helper.py \
67+
python ./llvm/utils/git/code-format-helper.py \
8168
--write-comment-to-file \
8269
--token ${{ secrets.GITHUB_TOKEN }} \
8370
--issue-number $GITHUB_PR_NUMBER \

.github/workflows/pr-code-lint.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: "Code lint"
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
pull_request:
8+
branches:
9+
- main
10+
- 'users/**'
11+
paths:
12+
- 'clang-tools-extra/clang-tidy/**'
13+
- '.github/workflows/pr-code-lint.yml'
14+
15+
jobs:
16+
code_linter:
17+
if: github.repository_owner == 'llvm'
18+
runs-on: ubuntu-24.04
19+
defaults:
20+
run:
21+
shell: bash
22+
container:
23+
image: 'ghcr.io/llvm/ci-ubuntu-24.04:latest'
24+
timeout-minutes: 60
25+
concurrency:
26+
group: ${{ github.workflow }}-${{ github.ref }}
27+
cancel-in-progress: true
28+
steps:
29+
- name: Fetch LLVM sources
30+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
31+
with:
32+
fetch-depth: 2
33+
34+
- name: Get changed files
35+
id: changed-files
36+
uses: step-security/changed-files@3dbe17c78367e7d60f00d78ae6781a35be47b4a1 # v45.0.1
37+
with:
38+
separator: ","
39+
skip_initial_fetch: true
40+
base_sha: 'HEAD~1'
41+
sha: 'HEAD'
42+
43+
- name: Listed files
44+
env:
45+
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
46+
run: |
47+
echo "Changed files:"
48+
echo "$CHANGED_FILES"
49+
50+
- name: Install clang-tidy
51+
uses: aminya/setup-cpp@17c11551771948abc5752bbf3183482567c7caf0 # v1.1.1
52+
with:
53+
clang-tidy: 20.1.8
54+
55+
- name: Setup Python env
56+
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5.4.0
57+
with:
58+
python-version: '3.12'
59+
60+
- name: Install Python dependencies
61+
run: python3 -m pip install -r llvm/utils/git/requirements_linting.txt
62+
63+
# TODO: create special mapping for 'codegen' targets, for now build predefined set
64+
# TODO: add entrypoint in 'compute_projects.py' that only adds a project and its direct dependencies
65+
- name: Configure and CodeGen
66+
run: |
67+
git config --global --add safe.directory '*'
68+
69+
. <(git diff --name-only HEAD~1...HEAD | python3 .ci/compute_projects.py)
70+
71+
if [[ "${projects_to_build}" == "" ]]; then
72+
echo "No projects to analyze"
73+
exit 0
74+
fi
75+
76+
cmake -G Ninja \
77+
-B build \
78+
-S llvm \
79+
-DLLVM_ENABLE_ASSERTIONS=OFF \
80+
-DLLVM_ENABLE_PROJECTS="${projects_to_build}" \
81+
-DCMAKE_CXX_COMPILER=clang++ \
82+
-DCMAKE_C_COMPILER=clang \
83+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
84+
-DLLVM_INCLUDE_TESTS=OFF \
85+
-DCLANG_INCLUDE_TESTS=OFF \
86+
-DCMAKE_BUILD_TYPE=Release
87+
88+
ninja -C build \
89+
clang-tablegen-targets \
90+
genconfusable # for "ConfusableIdentifierCheck.h"
91+
92+
- name: Run code linter
93+
env:
94+
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
95+
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
96+
run: |
97+
echo "[]" > comments &&
98+
python3 llvm/utils/git/code-lint-helper.py \
99+
--token ${{ secrets.GITHUB_TOKEN }} \
100+
--issue-number $GITHUB_PR_NUMBER \
101+
--start-rev HEAD~1 \
102+
--end-rev HEAD \
103+
--verbose \
104+
--changed-files "$CHANGED_FILES"
105+
106+
- name: Upload results
107+
uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 #v4.3.0
108+
if: always()
109+
with:
110+
name: workflow-args
111+
path: |
112+
comments

clang-tools-extra/clang-tidy/llvm/UseRangesCheck.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include "UseRangesCheck.h"
1010

11+
// FixItHint - Let the docs script know that this class does provide fixits
12+
1113
namespace clang::tidy::llvm_check {
1214

1315
namespace {

clang-tools-extra/clang-tidy/readability/ContainerContainsCheck.cpp

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,43 @@
99
#include "ContainerContainsCheck.h"
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
#include "clang/Lex/Lexer.h"
1213

1314
using namespace clang::ast_matchers;
1415

1516
namespace clang::tidy::readability {
1617
void ContainerContainsCheck::registerMatchers(MatchFinder *Finder) {
17-
const auto HasContainsMatchingParamType = hasMethod(
18-
cxxMethodDecl(isConst(), parameterCountIs(1), returns(booleanType()),
19-
hasName("contains"), unless(isDeleted()), isPublic(),
20-
hasParameter(0, hasType(hasUnqualifiedDesugaredType(
21-
equalsBoundNode("parameterType"))))));
18+
const auto Literal0 = integerLiteral(equals(0));
19+
const auto Literal1 = integerLiteral(equals(1));
20+
21+
const auto ClassWithContains = cxxRecordDecl(
22+
hasMethod(cxxMethodDecl(isConst(), parameterCountIs(1), isPublic(),
23+
unless(isDeleted()), returns(booleanType()),
24+
hasAnyName("contains", "Contains"))
25+
.bind("contains_fun")));
2226

2327
const auto CountCall =
24-
cxxMemberCallExpr(
25-
argumentCountIs(1),
26-
callee(cxxMethodDecl(
27-
hasName("count"),
28-
hasParameter(0, hasType(hasUnqualifiedDesugaredType(
29-
type().bind("parameterType")))),
30-
ofClass(cxxRecordDecl(HasContainsMatchingParamType)))))
28+
cxxMemberCallExpr(argumentCountIs(1),
29+
callee(cxxMethodDecl(hasAnyName("count", "Count"),
30+
ofClass(ClassWithContains))))
3131
.bind("call");
3232

3333
const auto FindCall =
34+
// Either one argument, or assume the second argument is the position to
35+
// start searching from.
3436
cxxMemberCallExpr(
35-
argumentCountIs(1),
36-
callee(cxxMethodDecl(
37-
hasName("find"),
38-
hasParameter(0, hasType(hasUnqualifiedDesugaredType(
39-
type().bind("parameterType")))),
40-
ofClass(cxxRecordDecl(HasContainsMatchingParamType)))))
37+
anyOf(argumentCountIs(1),
38+
allOf(argumentCountIs(2), hasArgument(1, Literal0))),
39+
callee(cxxMethodDecl(hasAnyName("find", "Find"),
40+
ofClass(ClassWithContains))))
4141
.bind("call");
4242

4343
const auto EndCall = cxxMemberCallExpr(
44-
argumentCountIs(0),
45-
callee(
46-
cxxMethodDecl(hasName("end"),
47-
// In the matchers below, FindCall should always appear
48-
// before EndCall so 'parameterType' is properly bound.
49-
ofClass(cxxRecordDecl(HasContainsMatchingParamType)))));
44+
argumentCountIs(0), callee(cxxMethodDecl(hasAnyName("end", "End"),
45+
ofClass(ClassWithContains))));
5046

51-
const auto Literal0 = integerLiteral(equals(0));
52-
const auto Literal1 = integerLiteral(equals(1));
47+
const auto StringNpos = anyOf(declRefExpr(to(varDecl(hasName("npos")))),
48+
memberExpr(member(hasName("npos"))));
5349

5450
auto AddSimpleMatcher = [&](auto Matcher) {
5551
Finder->addMatcher(
@@ -94,12 +90,14 @@ void ContainerContainsCheck::registerMatchers(MatchFinder *Finder) {
9490
binaryOperation(hasLHS(Literal1), hasOperatorName(">"), hasRHS(CountCall))
9591
.bind("negativeComparison"));
9692

97-
// Find membership tests based on `find() == end()`.
93+
// Find membership tests based on `find() == end()` or `find() == npos`.
9894
AddSimpleMatcher(
99-
binaryOperation(hasOperatorName("!="), hasOperands(FindCall, EndCall))
95+
binaryOperation(hasOperatorName("!="),
96+
hasOperands(FindCall, anyOf(EndCall, StringNpos)))
10097
.bind("positiveComparison"));
10198
AddSimpleMatcher(
102-
binaryOperation(hasOperatorName("=="), hasOperands(FindCall, EndCall))
99+
binaryOperation(hasOperatorName("=="),
100+
hasOperands(FindCall, anyOf(EndCall, StringNpos)))
103101
.bind("negativeComparison"));
104102
}
105103

@@ -114,29 +112,39 @@ void ContainerContainsCheck::check(const MatchFinder::MatchResult &Result) {
114112
"only one of PositiveComparison or NegativeComparison should be set");
115113
bool Negated = NegativeComparison != nullptr;
116114
const auto *Comparison = Negated ? NegativeComparison : PositiveComparison;
115+
const StringRef ContainsFunName =
116+
Result.Nodes.getNodeAs<CXXMethodDecl>("contains_fun")->getName();
117+
const Expr *SearchExpr = Call->getArg(0)->IgnoreParenImpCasts();
117118

118119
// Diagnose the issue.
119-
auto Diag =
120-
diag(Call->getExprLoc(), "use 'contains' to check for membership");
120+
auto Diag = diag(Call->getExprLoc(), "use '%0' to check for membership")
121+
<< ContainsFunName;
121122

122123
// Don't fix it if it's in a macro invocation. Leave fixing it to the user.
123124
SourceLocation FuncCallLoc = Comparison->getEndLoc();
124125
if (!FuncCallLoc.isValid() || FuncCallLoc.isMacroID())
125126
return;
126127

127-
// Create the fix it.
128-
const auto *Member = cast<MemberExpr>(Call->getCallee());
129-
Diag << FixItHint::CreateReplacement(
130-
Member->getMemberNameInfo().getSourceRange(), "contains");
131-
SourceLocation ComparisonBegin = Comparison->getSourceRange().getBegin();
132-
SourceLocation ComparisonEnd = Comparison->getSourceRange().getEnd();
133-
SourceLocation CallBegin = Call->getSourceRange().getBegin();
134-
SourceLocation CallEnd = Call->getSourceRange().getEnd();
128+
const StringRef SearchExprText = Lexer::getSourceText(
129+
CharSourceRange::getTokenRange(SearchExpr->getSourceRange()),
130+
*Result.SourceManager, Result.Context->getLangOpts());
131+
132+
// Remove everything before the function call.
133+
Diag << FixItHint::CreateRemoval(CharSourceRange::getCharRange(
134+
Comparison->getBeginLoc(), Call->getBeginLoc()));
135+
136+
// Rename the function to `contains`.
137+
Diag << FixItHint::CreateReplacement(Call->getExprLoc(), ContainsFunName);
138+
139+
// Replace arguments and everything after the function call.
135140
Diag << FixItHint::CreateReplacement(
136-
CharSourceRange::getCharRange(ComparisonBegin, CallBegin),
137-
Negated ? "!" : "");
138-
Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
139-
CallEnd.getLocWithOffset(1), ComparisonEnd));
141+
CharSourceRange::getTokenRange(Call->getArg(0)->getBeginLoc(),
142+
Comparison->getEndLoc()),
143+
(SearchExprText + ")").str());
144+
145+
// Add negation if necessary.
146+
if (Negated)
147+
Diag << FixItHint::CreateInsertion(Call->getBeginLoc(), "!");
140148
}
141149

142150
} // namespace clang::tidy::readability

clang-tools-extra/clangd/FeatureModule.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ FeatureModule::Facilities &FeatureModule::facilities() {
2222
return *Fac;
2323
}
2424

25+
void FeatureModuleSet::add(std::unique_ptr<FeatureModule> M) {
26+
Modules.push_back(std::move(M));
27+
}
28+
2529
bool FeatureModuleSet::addImpl(void *Key, std::unique_ptr<FeatureModule> M,
2630
const char *Source) {
2731
if (!Map.try_emplace(Key, M.get()).second) {
@@ -33,5 +37,16 @@ bool FeatureModuleSet::addImpl(void *Key, std::unique_ptr<FeatureModule> M,
3337
return true;
3438
}
3539

40+
FeatureModuleSet FeatureModuleSet::fromRegistry() {
41+
FeatureModuleSet ModuleSet;
42+
for (FeatureModuleRegistry::entry E : FeatureModuleRegistry::entries()) {
43+
vlog("Adding feature module '{0}' ({1})", E.getName(), E.getDesc());
44+
ModuleSet.add(E.instantiate());
45+
}
46+
return ModuleSet;
47+
}
48+
3649
} // namespace clangd
3750
} // namespace clang
51+
52+
LLVM_INSTANTIATE_REGISTRY(clang::clangd::FeatureModuleRegistry)

clang-tools-extra/clangd/FeatureModule.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/ADT/FunctionExtras.h"
1616
#include "llvm/Support/Compiler.h"
1717
#include "llvm/Support/JSON.h"
18+
#include "llvm/Support/Registry.h"
1819
#include <memory>
1920
#include <optional>
2021
#include <type_traits>
@@ -143,9 +144,14 @@ class FeatureModule {
143144

144145
/// A FeatureModuleSet is a collection of feature modules installed in clangd.
145146
///
146-
/// Modules can be looked up by type, or used via the FeatureModule interface.
147-
/// This allows individual modules to expose a public API.
148-
/// For this reason, there can be only one feature module of each type.
147+
/// Modules added with explicit type specification can be looked up by type, or
148+
/// used via the FeatureModule interface. This allows individual modules to
149+
/// expose a public API. For this reason, there can be only one feature module
150+
/// of each type.
151+
///
152+
/// Modules added using a base class pointer can be used only via the
153+
/// FeatureModule interface and can't be looked up by type, thus custom public
154+
/// API (if provided by the module) can't be used.
149155
///
150156
/// The set owns the modules. It is itself owned by main, not ClangdServer.
151157
class FeatureModuleSet {
@@ -164,6 +170,8 @@ class FeatureModuleSet {
164170
public:
165171
FeatureModuleSet() = default;
166172

173+
static FeatureModuleSet fromRegistry();
174+
167175
using iterator = llvm::pointee_iterator<decltype(Modules)::iterator>;
168176
using const_iterator =
169177
llvm::pointee_iterator<decltype(Modules)::const_iterator>;
@@ -172,6 +180,7 @@ class FeatureModuleSet {
172180
const_iterator begin() const { return const_iterator(Modules.begin()); }
173181
const_iterator end() const { return const_iterator(Modules.end()); }
174182

183+
void add(std::unique_ptr<FeatureModule> M);
175184
template <typename Mod> bool add(std::unique_ptr<Mod> M) {
176185
return addImpl(&ID<Mod>::Key, std::move(M), LLVM_PRETTY_FUNCTION);
177186
}
@@ -185,6 +194,13 @@ class FeatureModuleSet {
185194

186195
template <typename Mod> int FeatureModuleSet::ID<Mod>::Key;
187196

197+
using FeatureModuleRegistry = llvm::Registry<FeatureModule>;
198+
188199
} // namespace clangd
189200
} // namespace clang
201+
202+
namespace llvm {
203+
extern template class Registry<clang::clangd::FeatureModule>;
204+
} // namespace llvm
205+
190206
#endif

0 commit comments

Comments
 (0)