Skip to content

Commit fbf5f9d

Browse files
committed
Merge remote-tracking branch 'origin/main' into vplan-to-uniform-transforms
2 parents 451d82a + f557672 commit fbf5f9d

File tree

488 files changed

+22464
-10325
lines changed

Some content is hidden

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

488 files changed

+22464
-10325
lines changed

bolt/lib/Passes/PettisAndHansen.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,10 @@ std::vector<Cluster> pettisAndHansen(const CallGraph &Cg) {
143143
// Find an arc with max weight and merge its nodes
144144

145145
while (!Carcs.empty()) {
146-
auto Maxpos =
147-
std::max_element(Carcs.begin(), Carcs.end(),
148-
[&](const ClusterArc &Carc1, const ClusterArc &Carc2) {
149-
return Carc1.Weight < Carc2.Weight;
150-
});
146+
auto Maxpos = llvm::max_element(
147+
Carcs, [&](const ClusterArc &Carc1, const ClusterArc &Carc2) {
148+
return Carc1.Weight < Carc2.Weight;
149+
});
151150

152151
ClusterArc Max = *Maxpos;
153152
Carcs.erase(Maxpos);

bolt/lib/Target/RISCV/RISCVMCPlusBuilder.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
247247
Inst.clear();
248248
Inst.addOperand(MCOperand::createExpr(RISCVMCExpr::create(
249249
MCSymbolRefExpr::create(Target, MCSymbolRefExpr::VK_None, *Ctx),
250-
RISCVMCExpr::VK_CALL, *Ctx)));
250+
ELF::R_RISCV_CALL_PLT, *Ctx)));
251251
}
252252

253253
void createCall(MCInst &Inst, const MCSymbol *Target,
@@ -435,19 +435,19 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
435435
case ELF::R_RISCV_TLS_GD_HI20:
436436
// The GOT is reused so no need to create GOT relocations
437437
case ELF::R_RISCV_PCREL_HI20:
438-
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_PCREL_HI, Ctx);
438+
return RISCVMCExpr::create(Expr, ELF::R_RISCV_PCREL_HI20, Ctx);
439439
case ELF::R_RISCV_PCREL_LO12_I:
440440
case ELF::R_RISCV_PCREL_LO12_S:
441441
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_PCREL_LO, Ctx);
442442
case ELF::R_RISCV_HI20:
443-
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_HI, Ctx);
443+
return RISCVMCExpr::create(Expr, ELF::R_RISCV_HI20, Ctx);
444444
case ELF::R_RISCV_LO12_I:
445445
case ELF::R_RISCV_LO12_S:
446446
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_LO, Ctx);
447447
case ELF::R_RISCV_CALL:
448-
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_CALL, Ctx);
448+
return RISCVMCExpr::create(Expr, ELF::R_RISCV_CALL_PLT, Ctx);
449449
case ELF::R_RISCV_CALL_PLT:
450-
return RISCVMCExpr::create(Expr, RISCVMCExpr::VK_CALL_PLT, Ctx);
450+
return RISCVMCExpr::create(Expr, ELF::R_RISCV_CALL_PLT, Ctx);
451451
}
452452
}
453453

@@ -472,8 +472,7 @@ class RISCVMCPlusBuilder : public MCPlusBuilder {
472472
switch (cast<RISCVMCExpr>(ImmExpr)->getSpecifier()) {
473473
default:
474474
return false;
475-
case RISCVMCExpr::VK_CALL:
476-
case RISCVMCExpr::VK_CALL_PLT:
475+
case ELF::R_RISCV_CALL_PLT:
477476
return true;
478477
}
479478
}

clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,113 @@ class MustacheTemplateFile : public Template {
7070
MustacheTemplateFile(StringRef TemplateStr) : Template(TemplateStr) {}
7171
};
7272

73+
static std::unique_ptr<MustacheTemplateFile> NamespaceTemplate = nullptr;
74+
75+
static std::unique_ptr<MustacheTemplateFile> RecordTemplate = nullptr;
76+
77+
static Error setupTemplateFiles(const clang::doc::ClangDocContext &CDCtx) {
78+
return Error::success();
79+
}
80+
7381
Error MustacheHTMLGenerator::generateDocs(
7482
StringRef RootDir, StringMap<std::unique_ptr<doc::Info>> Infos,
7583
const clang::doc::ClangDocContext &CDCtx) {
84+
if (auto Err = setupTemplateFiles(CDCtx))
85+
return Err;
86+
// Track which directories we already tried to create.
87+
StringSet<> CreatedDirs;
88+
// Collect all output by file name and create the necessary directories.
89+
StringMap<std::vector<doc::Info *>> FileToInfos;
90+
for (const auto &Group : Infos) {
91+
doc::Info *Info = Group.getValue().get();
92+
93+
SmallString<128> Path;
94+
sys::path::native(RootDir, Path);
95+
sys::path::append(Path, Info->getRelativeFilePath(""));
96+
if (!CreatedDirs.contains(Path)) {
97+
if (std::error_code EC = sys::fs::create_directories(Path))
98+
return createStringError(EC, "failed to create directory '%s'.",
99+
Path.c_str());
100+
CreatedDirs.insert(Path);
101+
}
102+
103+
sys::path::append(Path, Info->getFileBaseName() + ".html");
104+
FileToInfos[Path].push_back(Info);
105+
}
106+
107+
for (const auto &Group : FileToInfos) {
108+
std::error_code FileErr;
109+
raw_fd_ostream InfoOS(Group.getKey(), FileErr, sys::fs::OF_None);
110+
if (FileErr)
111+
return createFileOpenError(Group.getKey(), FileErr);
112+
113+
for (const auto &Info : Group.getValue())
114+
if (Error Err = generateDocForInfo(Info, InfoOS, CDCtx))
115+
return Err;
116+
}
76117
return Error::success();
77118
}
78119

120+
static json::Value extractValue(const NamespaceInfo &I,
121+
const ClangDocContext &CDCtx) {
122+
Object NamespaceValue = Object();
123+
return NamespaceValue;
124+
}
125+
126+
static json::Value extractValue(const RecordInfo &I,
127+
const ClangDocContext &CDCtx) {
128+
Object RecordValue = Object();
129+
return RecordValue;
130+
}
131+
132+
static Error setupTemplateValue(const ClangDocContext &CDCtx, json::Value &V,
133+
Info *I) {
134+
return createStringError(inconvertibleErrorCode(),
135+
"setupTemplateValue is unimplemented");
136+
}
137+
79138
Error MustacheHTMLGenerator::generateDocForInfo(Info *I, raw_ostream &OS,
80139
const ClangDocContext &CDCtx) {
140+
switch (I->IT) {
141+
case InfoType::IT_namespace: {
142+
json::Value V =
143+
extractValue(*static_cast<clang::doc::NamespaceInfo *>(I), CDCtx);
144+
if (auto Err = setupTemplateValue(CDCtx, V, I))
145+
return Err;
146+
NamespaceTemplate->render(V, OS);
147+
break;
148+
}
149+
case InfoType::IT_record: {
150+
json::Value V =
151+
extractValue(*static_cast<clang::doc::RecordInfo *>(I), CDCtx);
152+
if (auto Err = setupTemplateValue(CDCtx, V, I))
153+
return Err;
154+
// Serialize the JSON value to the output stream in a readable format.
155+
RecordTemplate->render(V, OS);
156+
break;
157+
}
158+
case InfoType::IT_enum:
159+
OS << "IT_enum\n";
160+
break;
161+
case InfoType::IT_function:
162+
OS << "IT_Function\n";
163+
break;
164+
case InfoType::IT_typedef:
165+
OS << "IT_typedef\n";
166+
break;
167+
case InfoType::IT_default:
168+
return createStringError(inconvertibleErrorCode(), "unexpected InfoType");
169+
}
81170
return Error::success();
82171
}
83172

84173
Error MustacheHTMLGenerator::createResources(ClangDocContext &CDCtx) {
174+
for (const auto &FilePath : CDCtx.UserStylesheets)
175+
if (Error Err = copyFile(FilePath, CDCtx.OutDirectory))
176+
return Err;
177+
for (const auto &FilePath : CDCtx.JsScripts)
178+
if (Error Err = copyFile(FilePath, CDCtx.OutDirectory))
179+
return Err;
85180
return Error::success();
86181
}
87182

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "LambdaFunctionNameCheck.h"
4242
#include "MacroParenthesesCheck.h"
4343
#include "MacroRepeatedSideEffectsCheck.h"
44+
#include "MisleadingSetterOfReferenceCheck.h"
4445
#include "MisplacedOperatorInStrlenInAllocCheck.h"
4546
#include "MisplacedPointerArithmeticInAllocCheck.h"
4647
#include "MisplacedWideningCastCheck.h"
@@ -170,6 +171,8 @@ class BugproneModule : public ClangTidyModule {
170171
"bugprone-macro-parentheses");
171172
CheckFactories.registerCheck<MacroRepeatedSideEffectsCheck>(
172173
"bugprone-macro-repeated-side-effects");
174+
CheckFactories.registerCheck<MisleadingSetterOfReferenceCheck>(
175+
"bugprone-misleading-setter-of-reference");
173176
CheckFactories.registerCheck<MisplacedOperatorInStrlenInAllocCheck>(
174177
"bugprone-misplaced-operator-in-strlen-in-alloc");
175178
CheckFactories.registerCheck<MisplacedPointerArithmeticInAllocCheck>(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ add_clang_library(clangTidyBugproneModule STATIC
4242
LambdaFunctionNameCheck.cpp
4343
MacroParenthesesCheck.cpp
4444
MacroRepeatedSideEffectsCheck.cpp
45+
MisleadingSetterOfReferenceCheck.cpp
4546
MisplacedOperatorInStrlenInAllocCheck.cpp
4647
MisplacedPointerArithmeticInAllocCheck.cpp
4748
MisplacedWideningCastCheck.cpp
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//===--- MisleadingSetterOfReferenceCheck.cpp - clang-tidy-----------------===//
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 "MisleadingSetterOfReferenceCheck.h"
10+
#include "clang/AST/ASTContext.h"
11+
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
13+
using namespace clang::ast_matchers;
14+
15+
namespace clang::tidy::bugprone {
16+
17+
void MisleadingSetterOfReferenceCheck::registerMatchers(MatchFinder *Finder) {
18+
auto RefField = fieldDecl(hasType(hasCanonicalType(referenceType(
19+
pointee(equalsBoundNode("type"))))))
20+
.bind("member");
21+
auto AssignLHS = memberExpr(
22+
hasObjectExpression(ignoringParenCasts(cxxThisExpr())), member(RefField));
23+
auto DerefOperand = expr(ignoringParenCasts(
24+
declRefExpr(to(parmVarDecl(equalsBoundNode("parm"))))));
25+
auto AssignRHS = expr(ignoringParenCasts(
26+
unaryOperator(hasOperatorName("*"), hasUnaryOperand(DerefOperand))));
27+
28+
auto BinaryOpAssign = binaryOperator(hasOperatorName("="), hasLHS(AssignLHS),
29+
hasRHS(AssignRHS));
30+
auto CXXOperatorCallAssign = cxxOperatorCallExpr(
31+
hasOverloadedOperatorName("="), hasLHS(AssignLHS), hasRHS(AssignRHS));
32+
33+
auto SetBody =
34+
compoundStmt(statementCountIs(1),
35+
anyOf(has(BinaryOpAssign), has(CXXOperatorCallAssign)));
36+
auto BadSetFunction =
37+
cxxMethodDecl(
38+
parameterCountIs(1),
39+
hasParameter(
40+
0,
41+
parmVarDecl(hasType(hasCanonicalType(pointerType(pointee(qualType(
42+
hasCanonicalType(qualType().bind("type"))))))))
43+
.bind("parm")),
44+
hasBody(SetBody))
45+
.bind("bad-set-function");
46+
Finder->addMatcher(BadSetFunction, this);
47+
}
48+
49+
void MisleadingSetterOfReferenceCheck::check(
50+
const MatchFinder::MatchResult &Result) {
51+
const auto *Found = Result.Nodes.getNodeAs<CXXMethodDecl>("bad-set-function");
52+
const auto *Member = Result.Nodes.getNodeAs<FieldDecl>("member");
53+
54+
diag(Found->getBeginLoc(),
55+
"function '%0' can be mistakenly used in order to change the "
56+
"reference '%1' instead of the value of it; consider not using a "
57+
"pointer as argument")
58+
<< Found->getName() << Member->getName();
59+
}
60+
61+
} // namespace clang::tidy::bugprone
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//===--- MisleadingSetterOfReferenceCheck.h - clang-tidy---------*- C++ -*-===//
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_MISLEADINGSETTEROFREFERENCECHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_MISLEADINGSETTEROFREFERENCECHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang::tidy::bugprone {
15+
16+
/// Emits a warning when a setter-like function that has a pointer parameter
17+
/// is used to set value of a field with reference type.
18+
///
19+
/// For the user-facing documentation see:
20+
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/throw-keyword-missing.html
21+
class MisleadingSetterOfReferenceCheck : public ClangTidyCheck {
22+
public:
23+
MisleadingSetterOfReferenceCheck(StringRef Name, ClangTidyContext *Context)
24+
: ClangTidyCheck(Name, Context) {}
25+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
26+
return LangOpts.CPlusPlus;
27+
}
28+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
29+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
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_MISLEADINGSETTEROFREFERENCECHECK_H

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ New checks
124124
pointer and store it as class members without handle the copy and move
125125
constructors and the assignments.
126126

127+
- New :doc:`bugprone-misleading-setter-of-reference
128+
<clang-tidy/checks/bugprone/misleading-setter-of-reference>` check.
129+
130+
Finds setter-like member functions that take a pointer parameter and set a
131+
reference member of the same class with the pointed value.
132+
127133
- New :doc:`bugprone-unintended-char-ostream-output
128134
<clang-tidy/checks/bugprone/unintended-char-ostream-output>` check.
129135

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
.. title:: clang-tidy - bugprone-misleading-setter-of-reference
2+
3+
bugprone-misleading-setter-of-reference
4+
=======================================
5+
6+
Finds setter-like member functions that take a pointer parameter and set a
7+
reference member of the same class with the pointed value.
8+
9+
The check detects member functions that take a single pointer parameter,
10+
and contain a single expression statement that dereferences the parameter and
11+
assigns the result to a data member with a reference type.
12+
13+
The fact that a setter function takes a pointer might cause the belief that an
14+
internal reference (if it would be a pointer) is changed instead of the
15+
pointed-to (or referenced) value.
16+
17+
Example:
18+
19+
.. code-block:: c++
20+
21+
class MyClass {
22+
int &InternalRef; // non-const reference member
23+
public:
24+
MyClass(int &Value) : InternalRef(Value) {}
25+
26+
// Warning: This setter could lead to unintended behaviour.
27+
void setRef(int *Value) {
28+
InternalRef = *Value; // This assigns to the referenced value, not changing what InternalRef references.
29+
}
30+
};
31+
32+
int main() {
33+
int Value1 = 42;
34+
int Value2 = 100;
35+
MyClass X(Value1);
36+
37+
// This might look like it changes what InternalRef references to,
38+
// but it actually modifies Value1 to be 100.
39+
X.setRef(&Value2);
40+
}
41+
42+
Possible fixes:
43+
- Change the parameter type of the "set" function to non-pointer type (for
44+
example, a const reference).
45+
- Change the type of the member variable to a pointer and in the "set"
46+
function assign a value to the pointer (without dereference).

clang-tools-extra/docs/clang-tidy/checks/list.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Clang-Tidy Checks
109109
:doc:`bugprone-lambda-function-name <bugprone/lambda-function-name>`,
110110
:doc:`bugprone-macro-parentheses <bugprone/macro-parentheses>`, "Yes"
111111
:doc:`bugprone-macro-repeated-side-effects <bugprone/macro-repeated-side-effects>`,
112+
:doc:`bugprone-misleading-setter-of-reference <bugprone/misleading-setter-of-reference>`,
112113
:doc:`bugprone-misplaced-operator-in-strlen-in-alloc <bugprone/misplaced-operator-in-strlen-in-alloc>`, "Yes"
113114
:doc:`bugprone-misplaced-pointer-arithmetic-in-alloc <bugprone/misplaced-pointer-arithmetic-in-alloc>`, "Yes"
114115
:doc:`bugprone-misplaced-widening-cast <bugprone/misplaced-widening-cast>`,

0 commit comments

Comments
 (0)