Skip to content

Commit e8c471e

Browse files
authored
Merge branch 'main' into l0_plugin
2 parents 0c42764 + fbb587c commit e8c471e

File tree

679 files changed

+17013
-7419
lines changed

Some content is hidden

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

679 files changed

+17013
-7419
lines changed

.github/workflows/gha-codeql.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ on:
77
pull_request:
88
branches:
99
- main
10+
paths:
11+
- '.github/**'
1012
schedule:
1113
- cron: '30 0 * * *'
1214

.github/workflows/libclang-abi-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ jobs:
113113
./configure
114114
sudo make install
115115
- name: Download source code
116-
uses: llvm/actions/get-llvm-project-src@main
116+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
117117
with:
118118
ref: ${{ matrix.ref }}
119-
repo: ${{ matrix.repo }}
119+
repository: ${{ matrix.repo }}
120120
- name: Configure
121121
run: |
122122
mkdir install

.github/workflows/libcxx-run-benchmarks.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ jobs:
3333
3434
runs-on: llvm-premerge-libcxx-next-runners # TODO: This should run on a dedicated set of machines
3535
steps:
36-
- uses: actions/setup-python@v6
36+
- uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
3737
with:
3838
python-version: '3.10'
3939

4040
- name: Extract information from the PR
4141
id: vars
42+
env:
43+
COMMENT_BODY: ${{ github.event.comment.body }}
4244
run: |
4345
python3 -m venv .venv
4446
source .venv/bin/activate
@@ -51,7 +53,7 @@ jobs:
5153
print(f"pr_base={pr.base.sha}")
5254
print(f"pr_head={pr.head.sha}")
5355
EOF
54-
BENCHMARKS=$(echo "${{ github.event.comment.body }}" | sed -nE 's/\/libcxx-bot benchmark (.+)/\1/p')
56+
BENCHMARKS=$(echo "$COMMENT_BODY" | sed -nE 's/\/libcxx-bot benchmark (.+)/\1/p')
5557
echo "benchmarks=${BENCHMARKS}" >> ${GITHUB_OUTPUT}
5658
5759
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

.github/workflows/llvm-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ jobs:
101101
./configure
102102
sudo make install
103103
- name: Download source code
104-
uses: llvm/actions/get-llvm-project-src@main
104+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
105105
with:
106106
ref: ${{ matrix.ref }}
107-
repo: ${{ matrix.repo }}
107+
repository: ${{ matrix.repo }}
108108
- name: Configure
109109
run: |
110110
mkdir install

clang-tools-extra/clang-tidy/.clang-tidy

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Checks: >
55
-bugprone-branch-clone,
66
-bugprone-easily-swappable-parameters,
77
-bugprone-narrowing-conversions,
8-
-bugprone-suspicious-stringview-data-usage,
98
-bugprone-unchecked-optional-access,
109
-bugprone-unused-return-value,
1110
modernize-*,

clang-tools-extra/clang-tidy/ClangTidyOptions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ void yamlize(IO &IO, ClangTidyOptions::OptionMap &Val, bool,
9999
for (auto &Option : SortedOptions) {
100100
bool UseDefault = false;
101101
void *SaveInfo = nullptr;
102+
// Requires 'llvm::yaml::IO' to accept 'StringRef'
103+
// NOLINTNEXTLINE(bugprone-suspicious-stringview-data-usage)
102104
IO.preflightKey(Option.first.data(), true, false, UseDefault, SaveInfo);
103105
IO.scalarString(Option.second, needsQuotes(Option.second));
104106
IO.postflightKey(SaveInfo);
@@ -116,6 +118,8 @@ void yamlize(IO &IO, ClangTidyOptions::OptionMap &Val, bool,
116118
} else if (isa<MappingNode>(I.getCurrentNode())) {
117119
IO.beginMapping();
118120
for (StringRef Key : IO.keys()) {
121+
// Requires 'llvm::yaml::IO' to accept 'StringRef'
122+
// NOLINTNEXTLINE(bugprone-suspicious-stringview-data-usage)
119123
IO.mapRequired(Key.data(), Val[Key].Value);
120124
}
121125
IO.endMapping();

clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "CopyConstructorInitCheck.h"
2424
#include "CrtpConstructorAccessibilityCheck.h"
2525
#include "DanglingHandleCheck.h"
26+
#include "DerivedMethodShadowingBaseMethodCheck.h"
2627
#include "DynamicStaticInitializersCheck.h"
2728
#include "EasilySwappableParametersCheck.h"
2829
#include "EmptyCatchCheck.h"
@@ -134,6 +135,8 @@ class BugproneModule : public ClangTidyModule {
134135
"bugprone-copy-constructor-init");
135136
CheckFactories.registerCheck<DanglingHandleCheck>(
136137
"bugprone-dangling-handle");
138+
CheckFactories.registerCheck<DerivedMethodShadowingBaseMethodCheck>(
139+
"bugprone-derived-method-shadowing-base-method");
137140
CheckFactories.registerCheck<DynamicStaticInitializersCheck>(
138141
"bugprone-dynamic-static-initializers");
139142
CheckFactories.registerCheck<EasilySwappableParametersCheck>(

clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ add_clang_library(clangTidyBugproneModule STATIC
1919
CopyConstructorInitCheck.cpp
2020
CrtpConstructorAccessibilityCheck.cpp
2121
DanglingHandleCheck.cpp
22+
DerivedMethodShadowingBaseMethodCheck.cpp
2223
DynamicStaticInitializersCheck.cpp
2324
EasilySwappableParametersCheck.cpp
2425
EmptyCatchCheck.cpp
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "DerivedMethodShadowingBaseMethodCheck.h"
10+
#include "clang/ASTMatchers/ASTMatchFinder.h"
11+
#include "clang/ASTMatchers/ASTMatchers.h"
12+
13+
using namespace clang::ast_matchers;
14+
15+
namespace clang::tidy::bugprone {
16+
17+
static bool sameBasicType(const ParmVarDecl *Lhs, const ParmVarDecl *Rhs) {
18+
return Lhs && Rhs &&
19+
Lhs->getType()
20+
.getCanonicalType()
21+
.getNonReferenceType()
22+
.getUnqualifiedType() == Rhs->getType()
23+
.getCanonicalType()
24+
.getNonReferenceType()
25+
.getUnqualifiedType();
26+
}
27+
28+
static bool namesCollide(const CXXMethodDecl &Lhs, const CXXMethodDecl &Rhs) {
29+
if (Lhs.getNameAsString() != Rhs.getNameAsString())
30+
return false;
31+
if (Lhs.isConst() != Rhs.isConst())
32+
return false;
33+
if (Lhs.getNumParams() != Rhs.getNumParams())
34+
return false;
35+
for (unsigned int It = 0; It < Lhs.getNumParams(); ++It)
36+
if (!sameBasicType(Lhs.getParamDecl(It), Rhs.getParamDecl(It)))
37+
return false;
38+
return true;
39+
}
40+
41+
namespace {
42+
43+
AST_MATCHER(CXXMethodDecl, nameCollidesWithMethodInBase) {
44+
const CXXRecordDecl *DerivedClass = Node.getParent();
45+
for (const auto &Base : DerivedClass->bases()) {
46+
llvm::SmallVector<const CXXBaseSpecifier *, 8> Stack;
47+
Stack.push_back(&Base);
48+
while (!Stack.empty()) {
49+
const CXXBaseSpecifier *CurrentBaseSpec = Stack.back();
50+
Stack.pop_back();
51+
52+
if (CurrentBaseSpec->getAccessSpecifier() ==
53+
clang::AccessSpecifier::AS_private)
54+
continue;
55+
56+
const CXXRecordDecl *CurrentRecord =
57+
CurrentBaseSpec->getType()->getAsCXXRecordDecl();
58+
if (!CurrentRecord)
59+
continue;
60+
61+
// For multiple inheritance, we ignore only the bases that come from the
62+
// std:: namespace
63+
if (CurrentRecord->isInStdNamespace())
64+
continue;
65+
66+
for (const auto &BaseMethod : CurrentRecord->methods()) {
67+
if (namesCollide(*BaseMethod, Node)) {
68+
ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
69+
Builder->setBinding("base_method",
70+
clang::DynTypedNode::create(*BaseMethod));
71+
return true;
72+
}
73+
}
74+
75+
for (const auto &SubBase : CurrentRecord->bases())
76+
Stack.push_back(&SubBase);
77+
}
78+
}
79+
return false;
80+
}
81+
82+
// Same as clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp,
83+
// similar matchers are used elsewhere in LLVM
84+
AST_MATCHER(CXXMethodDecl, isOutOfLine) { return Node.isOutOfLine(); }
85+
86+
} // namespace
87+
88+
DerivedMethodShadowingBaseMethodCheck::DerivedMethodShadowingBaseMethodCheck(
89+
StringRef Name, ClangTidyContext *Context)
90+
: ClangTidyCheck(Name, Context) {}
91+
92+
void DerivedMethodShadowingBaseMethodCheck::registerMatchers(
93+
MatchFinder *Finder) {
94+
Finder->addMatcher(
95+
cxxMethodDecl(
96+
unless(anyOf(isOutOfLine(), isStaticStorageClass(), isImplicit(),
97+
cxxConstructorDecl(), isOverride(), isPrivate(),
98+
// isFinal(), //included with isOverride,
99+
// Templates are not handled yet
100+
ast_matchers::isTemplateInstantiation(),
101+
ast_matchers::isExplicitTemplateSpecialization())),
102+
ofClass(cxxRecordDecl(isDerivedFrom(cxxRecordDecl()))
103+
.bind("derived_class")),
104+
nameCollidesWithMethodInBase())
105+
.bind("shadowing_method"),
106+
this);
107+
}
108+
109+
void DerivedMethodShadowingBaseMethodCheck::check(
110+
const MatchFinder::MatchResult &Result) {
111+
const auto *ShadowingMethod =
112+
Result.Nodes.getNodeAs<CXXMethodDecl>("shadowing_method");
113+
const auto *DerivedClass =
114+
Result.Nodes.getNodeAs<CXXRecordDecl>("derived_class");
115+
const auto *BaseMethod = Result.Nodes.getNodeAs<CXXMethodDecl>("base_method");
116+
117+
if (!ShadowingMethod || !DerivedClass || !BaseMethod)
118+
llvm_unreachable("Required binding not found");
119+
120+
diag(ShadowingMethod->getBeginLoc(),
121+
"'%0' shadows method with the same name in class %1")
122+
<< ShadowingMethod->getQualifiedNameAsString() << BaseMethod->getParent();
123+
diag(BaseMethod->getBeginLoc(), "previous definition of %0 is here",
124+
DiagnosticIDs::Note)
125+
<< ShadowingMethod;
126+
}
127+
128+
} // namespace clang::tidy::bugprone
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DERIVEDMETHODSHADOWINGBASEMETHODCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DERIVEDMETHODSHADOWINGBASEMETHODCHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang::tidy::bugprone {
15+
16+
/// Checks that a derived class does not define the same (non virtual) method as
17+
/// a base class
18+
///
19+
/// For the user-facing documentation see:
20+
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/derived-method-shadowing-base-method.html
21+
class DerivedMethodShadowingBaseMethodCheck : public ClangTidyCheck {
22+
public:
23+
DerivedMethodShadowingBaseMethodCheck(StringRef Name,
24+
ClangTidyContext *Context);
25+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
26+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
27+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
28+
return LangOpts.CPlusPlus;
29+
}
30+
std::optional<TraversalKind> getCheckTraversalKind() const override {
31+
return TK_IgnoreUnlessSpelledInSource;
32+
}
33+
};
34+
35+
} // namespace clang::tidy::bugprone
36+
37+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_DERIVEDMETHODSHADOWINGBASEMETHODCHECK_H

0 commit comments

Comments
 (0)