Skip to content

Commit 3c04e28

Browse files
authored
Merge branch 'main' into log1p
2 parents 6e7496b + c76045d commit 3c04e28

File tree

697 files changed

+31206
-8844
lines changed

Some content is hidden

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

697 files changed

+31206
-8844
lines changed

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3684,9 +3684,8 @@ BinaryFunction::BasicBlockListType BinaryFunction::dfs() const {
36843684
BinaryBasicBlock *BB = Stack.top();
36853685
Stack.pop();
36863686

3687-
if (Visited.find(BB) != Visited.end())
3687+
if (!Visited.insert(BB).second)
36883688
continue;
3689-
Visited.insert(BB);
36903689
DFS.push_back(BB);
36913690

36923691
for (BinaryBasicBlock *SuccBB : BB->landing_pads()) {
@@ -3879,11 +3878,8 @@ void BinaryFunction::disambiguateJumpTables(
38793878
JumpTable *JT = getJumpTable(Inst);
38803879
if (!JT)
38813880
continue;
3882-
auto Iter = JumpTables.find(JT);
3883-
if (Iter == JumpTables.end()) {
3884-
JumpTables.insert(JT);
3881+
if (JumpTables.insert(JT).second)
38853882
continue;
3886-
}
38873883
// This instruction is an indirect jump using a jump table, but it is
38883884
// using the same jump table of another jump. Try all our tricks to
38893885
// extract the jump table symbol and make it point to a new, duplicated JT

bolt/lib/Passes/Instrumentation.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,8 @@ static bool hasAArch64ExclusiveMemop(
109109
BinaryBasicBlock *BB = BBQueue.front().first;
110110
bool IsLoad = BBQueue.front().second;
111111
BBQueue.pop();
112-
if (Visited.find(BB) != Visited.end())
112+
if (!Visited.insert(BB).second)
113113
continue;
114-
Visited.insert(BB);
115114

116115
for (const MCInst &Inst : *BB) {
117116
// Two loads one after another - skip whole function
@@ -126,8 +125,7 @@ static bool hasAArch64ExclusiveMemop(
126125
if (BC.MIB->isAArch64ExclusiveLoad(Inst))
127126
IsLoad = true;
128127

129-
if (IsLoad && BBToSkip.find(BB) == BBToSkip.end()) {
130-
BBToSkip.insert(BB);
128+
if (IsLoad && BBToSkip.insert(BB).second) {
131129
if (opts::Verbosity >= 2) {
132130
outs() << "BOLT-INSTRUMENTER: skip BB " << BB->getName()
133131
<< " due to exclusive instruction in function "

bolt/tools/driver/llvm-bolt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ int main(int argc, char **argv) {
202202

203203
ToolName = argv[0];
204204

205-
if (llvm::sys::path::filename(ToolName) == "perf2bolt")
205+
if (llvm::sys::path::filename(ToolName).starts_with("perf2bolt"))
206206
perf2boltMode(argc, argv);
207-
else if (llvm::sys::path::filename(ToolName) == "llvm-boltdiff")
207+
else if (llvm::sys::path::filename(ToolName).starts_with("llvm-boltdiff"))
208208
boltDiffMode(argc, argv);
209209
else
210210
boltMode(argc, argv);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ void CrtpConstructorAccessibilityCheck::check(
165165

166166
WithFriendHintIfNeeded(
167167
diag(Ctor->getLocation(),
168-
"%0 contructor allows the CRTP to be %select{inherited "
168+
"%0 constructor allows the CRTP to be %select{inherited "
169169
"from|constructed}1 as a regular template class; consider making "
170170
"it private%select{| and declaring the derived class as friend}2")
171171
<< Access << IsPublic << NeedsFriend

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,9 @@ StyleKind IdentifierNamingCheck::findStyleKind(
11351135
if (isa<TypeAliasDecl>(D) && NamingStyles[SK_TypeAlias])
11361136
return SK_TypeAlias;
11371137

1138+
if (isa<NamespaceAliasDecl>(D) && NamingStyles[SK_Namespace])
1139+
return SK_Namespace;
1140+
11381141
if (const auto *Decl = dyn_cast<NamespaceDecl>(D)) {
11391142
if (Decl->isAnonymousNamespace())
11401143
return SK_Invalid;

clang-tools-extra/clangd/AST.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,13 @@ getQualification(ASTContext &Context, const DeclContext *DestContext,
144144
// since we stored inner-most parent first.
145145
std::string Result;
146146
llvm::raw_string_ostream OS(Result);
147-
for (const auto *Parent : llvm::reverse(Parents))
147+
for (const auto *Parent : llvm::reverse(Parents)) {
148+
if (Parent != *Parents.rbegin() && Parent->isDependent() &&
149+
Parent->getAsRecordDecl() &&
150+
Parent->getAsRecordDecl()->getDescribedClassTemplate())
151+
OS << "template ";
148152
Parent->print(OS, Context.getPrintingPolicy());
153+
}
149154
return OS.str();
150155
}
151156

clang-tools-extra/clangd/refactor/tweaks/DefineOutline.cpp

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,28 @@ getFunctionSourceAfterReplacements(const FunctionDecl *FD,
128128
SM.getBufferData(SM.getMainFileID()), Replacements);
129129
if (!QualifiedFunc)
130130
return QualifiedFunc.takeError();
131-
return QualifiedFunc->substr(FuncBegin, FuncEnd - FuncBegin + 1);
131+
132+
std::string TemplatePrefix;
133+
if (auto *MD = llvm::dyn_cast<CXXMethodDecl>(FD)) {
134+
for (const CXXRecordDecl *Parent = MD->getParent(); Parent;
135+
Parent =
136+
llvm::dyn_cast_or_null<const CXXRecordDecl>(Parent->getParent())) {
137+
if (const TemplateParameterList *Params =
138+
Parent->getDescribedTemplateParams()) {
139+
std::string S;
140+
llvm::raw_string_ostream Stream(S);
141+
Params->print(Stream, FD->getASTContext());
142+
if (!S.empty())
143+
*S.rbegin() = '\n'; // Replace space with newline
144+
TemplatePrefix.insert(0, S);
145+
}
146+
}
147+
}
148+
149+
auto Source = QualifiedFunc->substr(FuncBegin, FuncEnd - FuncBegin + 1);
150+
if (!TemplatePrefix.empty())
151+
Source.insert(0, TemplatePrefix);
152+
return Source;
132153
}
133154

134155
// Returns replacements to delete tokens with kind `Kind` in the range
@@ -212,9 +233,13 @@ getFunctionSourceCode(const FunctionDecl *FD, const DeclContext *TargetContext,
212233
}
213234
}
214235
const NamedDecl *ND = Ref.Targets.front();
215-
const std::string Qualifier =
236+
std::string Qualifier =
216237
getQualification(AST, TargetContext,
217238
SM.getLocForStartOfFile(SM.getMainFileID()), ND);
239+
if (ND->getDeclContext()->isDependentContext() &&
240+
llvm::isa<TypeDecl>(ND)) {
241+
Qualifier.insert(0, "typename ");
242+
}
218243
if (auto Err = DeclarationCleanups.add(
219244
tooling::Replacement(SM, Ref.NameLoc, 0, Qualifier)))
220245
Errors = llvm::joinErrors(std::move(Errors), std::move(Err));
@@ -407,10 +432,23 @@ class DefineOutline : public Tweak {
407432
return !SameFile;
408433
}
409434

410-
// Bail out in templated classes, as it is hard to spell the class name,
411-
// i.e if the template parameter is unnamed.
412-
if (MD->getParent()->isTemplated())
413-
return false;
435+
for (const CXXRecordDecl *Parent = MD->getParent(); Parent;
436+
Parent =
437+
llvm::dyn_cast_or_null<const CXXRecordDecl>(Parent->getParent())) {
438+
if (const TemplateParameterList *Params =
439+
Parent->getDescribedTemplateParams()) {
440+
441+
// Class template member functions must be defined in the
442+
// same file.
443+
SameFile = true;
444+
445+
// Bail out if the template parameter is unnamed.
446+
for (NamedDecl *P : *Params) {
447+
if (!P->getIdentifier())
448+
return false;
449+
}
450+
}
451+
}
414452

415453
// The refactoring is meaningless for unnamed classes and namespaces,
416454
// unless we're outlining in the same file

clang-tools-extra/clangd/unittests/tweaks/DefineOutlineTests.cpp

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ TEST_F(DefineOutlineTest, TriggersOnFunctionDecl) {
105105
F^oo(const Foo&) = delete;
106106
};)cpp");
107107

108-
// Not available within templated classes, as it is hard to spell class name
109-
// out-of-line in such cases.
108+
// Not available within templated classes with unnamed parameters, as it is
109+
// hard to spell class name out-of-line in such cases.
110110
EXPECT_UNAVAILABLE(R"cpp(
111111
template <typename> struct Foo { void fo^o(){} };
112112
)cpp");
@@ -154,7 +154,6 @@ TEST_F(DefineOutlineTest, FailsWithoutSource) {
154154
}
155155

156156
TEST_F(DefineOutlineTest, ApplyTest) {
157-
llvm::StringMap<std::string> EditedFiles;
158157
ExtraFiles["Test.cpp"] = "";
159158
FileName = "Test.hpp";
160159

@@ -229,17 +228,18 @@ TEST_F(DefineOutlineTest, ApplyTest) {
229228
// Ctor initializer with attribute.
230229
{
231230
R"cpp(
232-
class Foo {
233-
F^oo(int z) __attribute__((weak)) : bar(2){}
231+
template <typename T> class Foo {
232+
F^oo(T z) __attribute__((weak)) : bar(2){}
234233
int bar;
235234
};)cpp",
236235
R"cpp(
237-
class Foo {
238-
Foo(int z) __attribute__((weak)) ;
236+
template <typename T> class Foo {
237+
Foo(T z) __attribute__((weak)) ;
239238
int bar;
240-
};)cpp",
241-
"Foo::Foo(int z) __attribute__((weak)) : bar(2){}\n",
242-
},
239+
};template <typename T>
240+
Foo<T>::Foo(T z) __attribute__((weak)) : bar(2){}
241+
)cpp",
242+
""},
243243
// Virt specifiers.
244244
{
245245
R"cpp(
@@ -369,7 +369,31 @@ TEST_F(DefineOutlineTest, ApplyTest) {
369369
};)cpp",
370370
" void A::foo(int) {}\n",
371371
},
372-
// Destrctors
372+
// Complex class template
373+
{
374+
R"cpp(
375+
template <typename T, typename ...U> struct O1 {
376+
template <class V, int A> struct O2 {
377+
enum E { E1, E2 };
378+
struct I {
379+
E f^oo(T, U..., V, E) { return E1; }
380+
};
381+
};
382+
};)cpp",
383+
R"cpp(
384+
template <typename T, typename ...U> struct O1 {
385+
template <class V, int A> struct O2 {
386+
enum E { E1, E2 };
387+
struct I {
388+
E foo(T, U..., V, E) ;
389+
};
390+
};
391+
};template <typename T, typename ...U>
392+
template <class V, int A>
393+
typename O1<T, U...>::template O2<V, A>::E O1<T, U...>::template O2<V, A>::I::foo(T, U..., V, E) { return E1; }
394+
)cpp",
395+
""},
396+
// Destructors
373397
{
374398
"class A { ~A^(){} };",
375399
"class A { ~A(); };",
@@ -378,9 +402,14 @@ TEST_F(DefineOutlineTest, ApplyTest) {
378402
};
379403
for (const auto &Case : Cases) {
380404
SCOPED_TRACE(Case.Test);
405+
llvm::StringMap<std::string> EditedFiles;
381406
EXPECT_EQ(apply(Case.Test, &EditedFiles), Case.ExpectedHeader);
382-
EXPECT_THAT(EditedFiles, testing::ElementsAre(FileWithContents(
383-
testPath("Test.cpp"), Case.ExpectedSource)));
407+
if (Case.ExpectedSource.empty()) {
408+
EXPECT_TRUE(EditedFiles.empty());
409+
} else {
410+
EXPECT_THAT(EditedFiles, testing::ElementsAre(FileWithContents(
411+
testPath("Test.cpp"), Case.ExpectedSource)));
412+
}
384413
}
385414
}
386415

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ Objective-C
8888
Miscellaneous
8989
^^^^^^^^^^^^^
9090

91+
- The DefineOutline tweak now handles member functions of class templates.
92+
9193
Improvements to clang-doc
9294
-------------------------
9395

@@ -242,6 +244,10 @@ Changes in existing checks
242244
<clang-tidy/checks/readability/redundant-smartptr-get>` check to
243245
remove `->`, when redundant `get()` is removed.
244246

247+
- Improved :doc:`readability-identifier-naming
248+
<clang-tidy/checks/readability/identifier-naming>` check to
249+
validate ``namespace`` aliases.
250+
245251
Removed checks
246252
^^^^^^^^^^^^^^
247253

clang-tools-extra/test/clang-tidy/checkers/bugprone/crtp-constructor-accessibility.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ template <typename T>
2626
class CRTP {
2727
public:
2828
CRTP() = default;
29-
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: public contructor allows the CRTP to be constructed as a regular template class; consider making it private and declaring the derived class as friend [bugprone-crtp-constructor-accessibility]
29+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: public constructor allows the CRTP to be constructed as a regular template class; consider making it private and declaring the derived class as friend [bugprone-crtp-constructor-accessibility]
3030
// CHECK-FIXES: private:{{[[:space:]]*}}CRTP() = default;{{[[:space:]]*}}public:
3131
// CHECK-FIXES: friend T;
3232
};
@@ -39,7 +39,7 @@ template <typename T>
3939
class CRTP {
4040
public:
4141
CRTP(int) {}
42-
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: public contructor allows the CRTP to be constructed as a regular template class; consider making it private and declaring the derived class as friend [bugprone-crtp-constructor-accessibility]
42+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: public constructor allows the CRTP to be constructed as a regular template class; consider making it private and declaring the derived class as friend [bugprone-crtp-constructor-accessibility]
4343
// CHECK-FIXES: private:{{[[:space:]]*}}CRTP(int) {}{{[[:space:]]*}}public:
4444
// CHECK-FIXES: friend T;
4545
};
@@ -52,10 +52,10 @@ template <typename T>
5252
class CRTP {
5353
public:
5454
CRTP(int) {}
55-
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: public contructor allows the CRTP to be constructed as a regular template class; consider making it private and declaring the derived class as friend [bugprone-crtp-constructor-accessibility]
55+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: public constructor allows the CRTP to be constructed as a regular template class; consider making it private and declaring the derived class as friend [bugprone-crtp-constructor-accessibility]
5656
// CHECK-FIXES: private:{{[[:space:]]*}}CRTP(int) {}{{[[:space:]]*}}public:
5757
CRTP(float) {}
58-
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: public contructor allows the CRTP to be constructed as a regular template class; consider making it private and declaring the derived class as friend [bugprone-crtp-constructor-accessibility]
58+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: public constructor allows the CRTP to be constructed as a regular template class; consider making it private and declaring the derived class as friend [bugprone-crtp-constructor-accessibility]
5959
// CHECK-FIXES: private:{{[[:space:]]*}}CRTP(float) {}{{[[:space:]]*}}public:
6060

6161
// CHECK-FIXES: friend T;
@@ -70,13 +70,13 @@ template <typename T>
7070
class CRTP {
7171
protected:
7272
CRTP(int) {}
73-
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: protected contructor allows the CRTP to be inherited from as a regular template class; consider making it private and declaring the derived class as friend [bugprone-crtp-constructor-accessibility]
73+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: protected constructor allows the CRTP to be inherited from as a regular template class; consider making it private and declaring the derived class as friend [bugprone-crtp-constructor-accessibility]
7474
// CHECK-FIXES: private:{{[[:space:]]*}}CRTP(int) {}{{[[:space:]]*}}protected:
7575
CRTP() = default;
76-
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: protected contructor allows the CRTP to be inherited from as a regular template class; consider making it private and declaring the derived class as friend [bugprone-crtp-constructor-accessibility]
76+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: protected constructor allows the CRTP to be inherited from as a regular template class; consider making it private and declaring the derived class as friend [bugprone-crtp-constructor-accessibility]
7777
// CHECK-FIXES: private:{{[[:space:]]*}}CRTP() = default;{{[[:space:]]*}}protected:
7878
CRTP(float) {}
79-
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: protected contructor allows the CRTP to be inherited from as a regular template class; consider making it private and declaring the derived class as friend [bugprone-crtp-constructor-accessibility]
79+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: protected constructor allows the CRTP to be inherited from as a regular template class; consider making it private and declaring the derived class as friend [bugprone-crtp-constructor-accessibility]
8080
// CHECK-FIXES: private:{{[[:space:]]*}}CRTP(float) {}{{[[:space:]]*}}protected:
8181

8282
// CHECK-FIXES: friend T;
@@ -101,7 +101,7 @@ namespace struct_default_ctor {
101101
template <typename T>
102102
struct CRTP {
103103
CRTP() = default;
104-
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: public contructor allows the CRTP to be constructed as a regular template class; consider making it private and declaring the derived class as friend [bugprone-crtp-constructor-accessibility]
104+
// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: public constructor allows the CRTP to be constructed as a regular template class; consider making it private and declaring the derived class as friend [bugprone-crtp-constructor-accessibility]
105105
// CHECK-FIXES: private:{{[[:space:]]*}}CRTP() = default;{{[[:space:]]*}}public:
106106
// CHECK-FIXES: friend T;
107107
};

0 commit comments

Comments
 (0)