Skip to content

Commit 1703f1a

Browse files
committed
Merge branch 'main' into clang-tidy_casttostruct
2 parents 72a38e4 + 6e47bff commit 1703f1a

File tree

1,299 files changed

+45061
-25748
lines changed

Some content is hidden

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

1,299 files changed

+45061
-25748
lines changed

.ci/compute_projects.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
"mlir": "check-mlir",
151151
"openmp": "check-openmp",
152152
"polly": "check-polly",
153+
"lit": "check-lit",
153154
}
154155

155156
RUNTIMES = {"libcxx", "libcxxabi", "libunwind", "compiler-rt", "libc", "flang-rt"}
@@ -166,8 +167,12 @@
166167
("llvm", "utils", "gn"): "gn",
167168
(".github", "workflows", "premerge.yaml"): ".ci",
168169
("third-party",): ".ci",
170+
("llvm", "utils", "lit"): "lit",
169171
}
170172

173+
# Projects that should run tests but cannot be explicitly built.
174+
SKIP_BUILD_PROJECTS = ["CIR", "lit"]
175+
171176
# Projects that should not run any tests. These need to be metaprojects.
172177
SKIP_PROJECTS = ["docs", "gn"]
173178

@@ -315,7 +320,9 @@ def get_env_variables(modified_files: list[str], platform: str) -> Set[str]:
315320
# clang build, but it requires an explicit option to enable. We set that
316321
# option here, and remove it from the projects_to_build list.
317322
enable_cir = "ON" if "CIR" in projects_to_build else "OFF"
318-
projects_to_build.discard("CIR")
323+
# Remove any metaprojects from the list of projects to build.
324+
for project in SKIP_BUILD_PROJECTS:
325+
projects_to_build.discard(project)
319326

320327
# We use a semicolon to separate the projects/runtimes as they get passed
321328
# to the CMake invocation and thus we need to use the CMake list separator

.ci/compute_projects_test.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,30 @@ def test_third_party_benchmark(self):
413413
"check-cxx check-cxxabi check-unwind",
414414
)
415415

416+
def test_lit(self):
417+
env_variables = compute_projects.get_env_variables(
418+
["llvm/utils/lit/CMakeLists.txt"], "Linux"
419+
)
420+
self.assertEqual(
421+
env_variables["projects_to_build"],
422+
"bolt;clang;clang-tools-extra;flang;lld;lldb;llvm;mlir;polly",
423+
)
424+
self.assertEqual(
425+
env_variables["project_check_targets"],
426+
"check-bolt check-clang check-clang-tools check-flang check-lit check-lld check-lldb check-llvm check-mlir check-polly",
427+
)
428+
self.assertEqual(
429+
env_variables["runtimes_to_build"], "libcxx;libcxxabi;libunwind"
430+
)
431+
self.assertEqual(
432+
env_variables["runtimes_check_targets"],
433+
"",
434+
)
435+
self.assertEqual(
436+
env_variables["runtimes_check_targets_needs_reconfig"],
437+
"check-cxx check-cxxabi check-unwind",
438+
)
439+
416440

417441
if __name__ == "__main__":
418442
unittest.main()

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@
132132
/mlir/**/Transforms/Mem2Reg.* @moxinilian
133133
/mlir/**/Transforms/SROA.* @moxinilian
134134

135+
# MLIR IRDL-related
136+
/mlir/**/*IRDL* @moxinilian
137+
135138
# BOLT
136139
/bolt/ @aaupov @maksfb @rafaelauler @ayermolo @yota9 @paschalis-mpeis @yozhu
137140

clang-tools-extra/clang-include-fixer/IncludeFixer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ bool IncludeFixerActionFactory::runInvocation(
9494

9595
// Create the compiler's actual diagnostics engine. We want to drop all
9696
// diagnostics here.
97-
Compiler.createDiagnostics(Files->getVirtualFileSystem(),
98-
new clang::IgnoringDiagConsumer,
97+
Compiler.createDiagnostics(new clang::IgnoringDiagConsumer,
9998
/*ShouldOwnClient=*/true);
10099
Compiler.createSourceManager(*Files);
101100

clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp

Lines changed: 30 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,17 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include <array>
910
#include <cmath>
1011
#include <optional>
1112

1213
#include "DurationRewriter.h"
1314
#include "clang/Tooling/FixIt.h"
14-
#include "llvm/ADT/IndexedMap.h"
1515

1616
using namespace clang::ast_matchers;
1717

1818
namespace clang::tidy::abseil {
1919

20-
struct DurationScale2IndexFunctor {
21-
using argument_type = DurationScale;
22-
unsigned operator()(DurationScale Scale) const {
23-
return static_cast<unsigned>(Scale);
24-
}
25-
};
26-
2720
/// Returns an integer if the fractional part of a `FloatingLiteral` is `0`.
2821
static std::optional<llvm::APSInt>
2922
truncateIfIntegral(const FloatingLiteral &FloatLiteral) {
@@ -39,31 +32,17 @@ truncateIfIntegral(const FloatingLiteral &FloatLiteral) {
3932

4033
const std::pair<llvm::StringRef, llvm::StringRef> &
4134
getDurationInverseForScale(DurationScale Scale) {
42-
static const llvm::IndexedMap<std::pair<llvm::StringRef, llvm::StringRef>,
43-
DurationScale2IndexFunctor>
44-
InverseMap = []() {
45-
// TODO: Revisit the immediately invoked lambda technique when
46-
// IndexedMap gets an initializer list constructor.
47-
llvm::IndexedMap<std::pair<llvm::StringRef, llvm::StringRef>,
48-
DurationScale2IndexFunctor>
49-
InverseMap;
50-
InverseMap.resize(6);
51-
InverseMap[DurationScale::Hours] =
52-
std::make_pair("::absl::ToDoubleHours", "::absl::ToInt64Hours");
53-
InverseMap[DurationScale::Minutes] =
54-
std::make_pair("::absl::ToDoubleMinutes", "::absl::ToInt64Minutes");
55-
InverseMap[DurationScale::Seconds] =
56-
std::make_pair("::absl::ToDoubleSeconds", "::absl::ToInt64Seconds");
57-
InverseMap[DurationScale::Milliseconds] = std::make_pair(
58-
"::absl::ToDoubleMilliseconds", "::absl::ToInt64Milliseconds");
59-
InverseMap[DurationScale::Microseconds] = std::make_pair(
60-
"::absl::ToDoubleMicroseconds", "::absl::ToInt64Microseconds");
61-
InverseMap[DurationScale::Nanoseconds] = std::make_pair(
62-
"::absl::ToDoubleNanoseconds", "::absl::ToInt64Nanoseconds");
63-
return InverseMap;
64-
}();
65-
66-
return InverseMap[Scale];
35+
static constexpr std::array<std::pair<llvm::StringRef, llvm::StringRef>, 6>
36+
InverseMap = {{
37+
{"::absl::ToDoubleHours", "::absl::ToInt64Hours"},
38+
{"::absl::ToDoubleMinutes", "::absl::ToInt64Minutes"},
39+
{"::absl::ToDoubleSeconds", "::absl::ToInt64Seconds"},
40+
{"::absl::ToDoubleMilliseconds", "::absl::ToInt64Milliseconds"},
41+
{"::absl::ToDoubleMicroseconds", "::absl::ToInt64Microseconds"},
42+
{"::absl::ToDoubleNanoseconds", "::absl::ToInt64Nanoseconds"},
43+
}};
44+
45+
return InverseMap[llvm::to_underlying(Scale)];
6746
}
6847

6948
/// If `Node` is a call to the inverse of `Scale`, return that inverse's
@@ -103,58 +82,31 @@ rewriteInverseTimeCall(const MatchFinder::MatchResult &Result,
10382

10483
/// Returns the factory function name for a given `Scale`.
10584
llvm::StringRef getDurationFactoryForScale(DurationScale Scale) {
106-
switch (Scale) {
107-
case DurationScale::Hours:
108-
return "absl::Hours";
109-
case DurationScale::Minutes:
110-
return "absl::Minutes";
111-
case DurationScale::Seconds:
112-
return "absl::Seconds";
113-
case DurationScale::Milliseconds:
114-
return "absl::Milliseconds";
115-
case DurationScale::Microseconds:
116-
return "absl::Microseconds";
117-
case DurationScale::Nanoseconds:
118-
return "absl::Nanoseconds";
119-
}
120-
llvm_unreachable("unknown scaling factor");
85+
static constexpr std::array<llvm::StringRef, 6> FactoryMap = {
86+
"absl::Hours", "absl::Minutes", "absl::Seconds",
87+
"absl::Milliseconds", "absl::Microseconds", "absl::Nanoseconds",
88+
};
89+
90+
return FactoryMap[llvm::to_underlying(Scale)];
12191
}
12292

12393
llvm::StringRef getTimeFactoryForScale(DurationScale Scale) {
124-
switch (Scale) {
125-
case DurationScale::Hours:
126-
return "absl::FromUnixHours";
127-
case DurationScale::Minutes:
128-
return "absl::FromUnixMinutes";
129-
case DurationScale::Seconds:
130-
return "absl::FromUnixSeconds";
131-
case DurationScale::Milliseconds:
132-
return "absl::FromUnixMillis";
133-
case DurationScale::Microseconds:
134-
return "absl::FromUnixMicros";
135-
case DurationScale::Nanoseconds:
136-
return "absl::FromUnixNanos";
137-
}
138-
llvm_unreachable("unknown scaling factor");
94+
static constexpr std::array<llvm::StringRef, 6> FactoryMap = {
95+
"absl::FromUnixHours", "absl::FromUnixMinutes", "absl::FromUnixSeconds",
96+
"absl::FromUnixMillis", "absl::FromUnixMicros", "absl::FromUnixNanos",
97+
};
98+
99+
return FactoryMap[llvm::to_underlying(Scale)];
139100
}
140101

141102
/// Returns the Time factory function name for a given `Scale`.
142103
llvm::StringRef getTimeInverseForScale(DurationScale Scale) {
143-
switch (Scale) {
144-
case DurationScale::Hours:
145-
return "absl::ToUnixHours";
146-
case DurationScale::Minutes:
147-
return "absl::ToUnixMinutes";
148-
case DurationScale::Seconds:
149-
return "absl::ToUnixSeconds";
150-
case DurationScale::Milliseconds:
151-
return "absl::ToUnixMillis";
152-
case DurationScale::Microseconds:
153-
return "absl::ToUnixMicros";
154-
case DurationScale::Nanoseconds:
155-
return "absl::ToUnixNanos";
156-
}
157-
llvm_unreachable("unknown scaling factor");
104+
static constexpr std::array<llvm::StringRef, 6> InverseMap = {
105+
"absl::ToUnixHours", "absl::ToUnixMinutes", "absl::ToUnixSeconds",
106+
"absl::ToUnixMillis", "absl::ToUnixMicros", "absl::ToUnixNanos",
107+
};
108+
109+
return InverseMap[llvm::to_underlying(Scale)];
158110
}
159111

160112
/// Returns `true` if `Node` is a value which evaluates to a literal `0`.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "CopyConstructorInitCheck.h"
2525
#include "CrtpConstructorAccessibilityCheck.h"
2626
#include "DanglingHandleCheck.h"
27+
#include "DerivedMethodShadowingBaseMethodCheck.h"
2728
#include "DynamicStaticInitializersCheck.h"
2829
#include "EasilySwappableParametersCheck.h"
2930
#include "EmptyCatchCheck.h"
@@ -136,6 +137,8 @@ class BugproneModule : public ClangTidyModule {
136137
"bugprone-copy-constructor-init");
137138
CheckFactories.registerCheck<DanglingHandleCheck>(
138139
"bugprone-dangling-handle");
140+
CheckFactories.registerCheck<DerivedMethodShadowingBaseMethodCheck>(
141+
"bugprone-derived-method-shadowing-base-method");
139142
CheckFactories.registerCheck<DynamicStaticInitializersCheck>(
140143
"bugprone-dynamic-static-initializers");
141144
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
@@ -20,6 +20,7 @@ add_clang_library(clangTidyBugproneModule STATIC
2020
CopyConstructorInitCheck.cpp
2121
CrtpConstructorAccessibilityCheck.cpp
2222
DanglingHandleCheck.cpp
23+
DerivedMethodShadowingBaseMethodCheck.cpp
2324
DynamicStaticInitializersCheck.cpp
2425
EasilySwappableParametersCheck.cpp
2526
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

0 commit comments

Comments
 (0)