Skip to content

Commit 3f6b74b

Browse files
authored
LLVM and SPIRV-LLVM-Translator
LLVM: e24e95f LLVM-SPIRV-Translator: 7a0767f2
2 parents 3baec18 + 8be9dec commit 3f6b74b

File tree

2,573 files changed

+121848
-13619
lines changed

Some content is hidden

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

2,573 files changed

+121848
-13619
lines changed

.git-blame-ignore-revs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@
1616

1717
# r280751: [Coding style change][lldb] Moved LLDB code base to use LLVM style
1818
b9c1b51e45b845debb76d8658edabca70ca56079
19+
20+
# r302421: That change incorrectly changed line endings in some libc++ files
21+
9669df28d4fd3c52d09f451186bd217cdc3322c0
22+
23+
# r302496: That is the revert of r302421
24+
ff63090b0e1072bd398b8efef8ae2291613a6ec9

clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.cpp

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ SpecialMemberFunctionsCheck::SpecialMemberFunctionsCheck(
2525
StringRef Name, ClangTidyContext *Context)
2626
: ClangTidyCheck(Name, Context),
2727
AllowMissingMoveFunctions(Options.get("AllowMissingMoveFunctions", 0)),
28-
AllowSoleDefaultDtor(Options.get("AllowSoleDefaultDtor", 0)) {}
28+
AllowSoleDefaultDtor(Options.get("AllowSoleDefaultDtor", 0)),
29+
AllowMissingMoveFunctionsWhenCopyIsDeleted(
30+
Options.get("AllowMissingMoveFunctionsWhenCopyIsDeleted", 0)) {}
2931

3032
void SpecialMemberFunctionsCheck::storeOptions(
3133
ClangTidyOptions::OptionMap &Opts) {
3234
Options.store(Opts, "AllowMissingMoveFunctions", AllowMissingMoveFunctions);
3335
Options.store(Opts, "AllowSoleDefaultDtor", AllowSoleDefaultDtor);
36+
Options.store(Opts, "AllowMissingMoveFunctionsWhenCopyIsDeleted",
37+
AllowMissingMoveFunctionsWhenCopyIsDeleted);
3438
}
3539

3640
void SpecialMemberFunctionsCheck::registerMatchers(MatchFinder *Finder) {
@@ -103,17 +107,18 @@ void SpecialMemberFunctionsCheck::check(
103107

104108
ClassDefId ID(MatchedDecl->getLocation(), std::string(MatchedDecl->getName()));
105109

106-
auto StoreMember = [this, &ID](SpecialMemberFunctionKind Kind) {
107-
llvm::SmallVectorImpl<SpecialMemberFunctionKind> &Members =
110+
auto StoreMember = [this, &ID](SpecialMemberFunctionData data) {
111+
llvm::SmallVectorImpl<SpecialMemberFunctionData> &Members =
108112
ClassWithSpecialMembers[ID];
109-
if (!llvm::is_contained(Members, Kind))
110-
Members.push_back(Kind);
113+
if (!llvm::is_contained(Members, data))
114+
Members.push_back(std::move(data));
111115
};
112116

113117
if (const auto *Dtor = Result.Nodes.getNodeAs<CXXMethodDecl>("dtor")) {
114-
StoreMember(Dtor->isDefaulted()
115-
? SpecialMemberFunctionKind::DefaultDestructor
116-
: SpecialMemberFunctionKind::NonDefaultDestructor);
118+
StoreMember({Dtor->isDefaulted()
119+
? SpecialMemberFunctionKind::DefaultDestructor
120+
: SpecialMemberFunctionKind::NonDefaultDestructor,
121+
Dtor->isDeleted()});
117122
}
118123

119124
std::initializer_list<std::pair<std::string, SpecialMemberFunctionKind>>
@@ -123,8 +128,9 @@ void SpecialMemberFunctionsCheck::check(
123128
{"move-assign", SpecialMemberFunctionKind::MoveAssignment}};
124129

125130
for (const auto &KV : Matchers)
126-
if (Result.Nodes.getNodeAs<CXXMethodDecl>(KV.first)) {
127-
StoreMember(KV.second);
131+
if (const auto *MethodDecl =
132+
Result.Nodes.getNodeAs<CXXMethodDecl>(KV.first)) {
133+
StoreMember({KV.second, MethodDecl->isDeleted()});
128134
}
129135
}
130136

@@ -136,11 +142,19 @@ void SpecialMemberFunctionsCheck::onEndOfTranslationUnit() {
136142

137143
void SpecialMemberFunctionsCheck::checkForMissingMembers(
138144
const ClassDefId &ID,
139-
llvm::ArrayRef<SpecialMemberFunctionKind> DefinedMembers) {
145+
llvm::ArrayRef<SpecialMemberFunctionData> DefinedMembers) {
140146
llvm::SmallVector<SpecialMemberFunctionKind, 5> MissingMembers;
141147

142148
auto HasMember = [&](SpecialMemberFunctionKind Kind) {
143-
return llvm::is_contained(DefinedMembers, Kind);
149+
return llvm::any_of(DefinedMembers, [Kind](const auto &data) {
150+
return data.FunctionKind == Kind;
151+
});
152+
};
153+
154+
auto IsDeleted = [&](SpecialMemberFunctionKind Kind) {
155+
return llvm::any_of(DefinedMembers, [Kind](const auto &data) {
156+
return data.FunctionKind == Kind && data.IsDeleted;
157+
});
144158
};
145159

146160
auto RequireMember = [&](SpecialMemberFunctionKind Kind) {
@@ -171,16 +185,23 @@ void SpecialMemberFunctionsCheck::checkForMissingMembers(
171185
RequireMember(SpecialMemberFunctionKind::CopyAssignment);
172186
}
173187

174-
if (RequireFive) {
188+
if (RequireFive &&
189+
!(AllowMissingMoveFunctionsWhenCopyIsDeleted &&
190+
(IsDeleted(SpecialMemberFunctionKind::CopyConstructor) &&
191+
IsDeleted(SpecialMemberFunctionKind::CopyAssignment)))) {
175192
assert(RequireThree);
176193
RequireMember(SpecialMemberFunctionKind::MoveConstructor);
177194
RequireMember(SpecialMemberFunctionKind::MoveAssignment);
178195
}
179196

180-
if (!MissingMembers.empty())
197+
if (!MissingMembers.empty()) {
198+
llvm::SmallVector<SpecialMemberFunctionKind, 5> DefinedMemberKinds;
199+
llvm::transform(DefinedMembers, std::back_inserter(DefinedMemberKinds),
200+
[](const auto &data) { return data.FunctionKind; });
181201
diag(ID.first, "class '%0' defines %1 but does not define %2")
182-
<< ID.second << cppcoreguidelines::join(DefinedMembers, " and ")
202+
<< ID.second << cppcoreguidelines::join(DefinedMemberKinds, " and ")
183203
<< cppcoreguidelines::join(MissingMembers, " or ");
204+
}
184205
}
185206

186207
} // namespace cppcoreguidelines

clang-tools-extra/clang-tidy/cppcoreguidelines/SpecialMemberFunctionsCheck.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,30 @@ class SpecialMemberFunctionsCheck : public ClangTidyCheck {
4343
MoveAssignment
4444
};
4545

46+
struct SpecialMemberFunctionData {
47+
SpecialMemberFunctionKind FunctionKind;
48+
bool IsDeleted;
49+
50+
bool operator==(const SpecialMemberFunctionData &Other) {
51+
return (Other.FunctionKind == FunctionKind) &&
52+
(Other.IsDeleted == IsDeleted);
53+
}
54+
};
55+
4656
using ClassDefId = std::pair<SourceLocation, std::string>;
4757

4858
using ClassDefiningSpecialMembersMap =
4959
llvm::DenseMap<ClassDefId,
50-
llvm::SmallVector<SpecialMemberFunctionKind, 5>>;
60+
llvm::SmallVector<SpecialMemberFunctionData, 5>>;
5161

5262
private:
5363
void checkForMissingMembers(
5464
const ClassDefId &ID,
55-
llvm::ArrayRef<SpecialMemberFunctionKind> DefinedSpecialMembers);
65+
llvm::ArrayRef<SpecialMemberFunctionData> DefinedSpecialMembers);
5666

5767
const bool AllowMissingMoveFunctions;
5868
const bool AllowSoleDefaultDtor;
69+
const bool AllowMissingMoveFunctionsWhenCopyIsDeleted;
5970
ClassDefiningSpecialMembersMap ClassWithSpecialMembers;
6071
};
6172

clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,14 @@ StringRef LoopConvertCheck::getContainerString(ASTContext *Context,
649649
const ForStmt *Loop,
650650
const Expr *ContainerExpr) {
651651
StringRef ContainerString;
652-
if (isa<CXXThisExpr>(ContainerExpr->IgnoreParenImpCasts())) {
652+
ContainerExpr = ContainerExpr->IgnoreParenImpCasts();
653+
if (isa<CXXThisExpr>(ContainerExpr)) {
653654
ContainerString = "this";
654655
} else {
656+
// For CXXOperatorCallExpr (e.g. vector_ptr->size()), its first argument is
657+
// the class object (vector_ptr) we are targeting.
658+
if (const auto* E = dyn_cast<CXXOperatorCallExpr>(ContainerExpr))
659+
ContainerExpr = E->getArg(0);
655660
ContainerString =
656661
getStringFromRange(Context->getSourceManager(), Context->getLangOpts(),
657662
ContainerExpr->getSourceRange());

clang-tools-extra/clangd/FindTarget.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "llvm/Support/Casting.h"
3838
#include "llvm/Support/Compiler.h"
3939
#include "llvm/Support/raw_ostream.h"
40+
#include <iterator>
4041
#include <utility>
4142
#include <vector>
4243

@@ -76,6 +77,11 @@ std::vector<const NamedDecl *> getMembersReferencedViaDependentName(
7677
bool IsNonstaticMember) {
7778
if (!T)
7879
return {};
80+
if (auto *ET = T->getAs<EnumType>()) {
81+
auto Result =
82+
ET->getDecl()->lookup(NameFactory(ET->getDecl()->getASTContext()));
83+
return {Result.begin(), Result.end()};
84+
}
7985
if (auto *ICNT = T->getAs<InjectedClassNameType>()) {
8086
T = ICNT->getInjectedSpecializationType().getTypePtrOrNull();
8187
}

clang-tools-extra/clangd/FormattedString.cpp

Lines changed: 136 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "llvm/ADT/SmallVector.h"
1313
#include "llvm/ADT/StringExtras.h"
1414
#include "llvm/ADT/StringRef.h"
15+
#include "llvm/Support/Compiler.h"
1516
#include "llvm/Support/ErrorHandling.h"
1617
#include "llvm/Support/FormatVariadic.h"
1718
#include "llvm/Support/raw_ostream.h"
@@ -26,23 +27,143 @@ namespace clangd {
2627
namespace markup {
2728

2829
namespace {
30+
31+
// Is <contents a plausible start to an HTML tag?
32+
// Contents may not be the rest of the line, but it's the rest of the plain
33+
// text, so we expect to see at least the tag name.
34+
bool looksLikeTag(llvm::StringRef Contents) {
35+
if (Contents.empty())
36+
return false;
37+
if (Contents.front() == '!' || Contents.front() == '?' ||
38+
Contents.front() == '/')
39+
return true;
40+
// Check the start of the tag name.
41+
if (!llvm::isAlpha(Contents.front()))
42+
return false;
43+
// Drop rest of the tag name, and following whitespace.
44+
Contents = Contents
45+
.drop_while([](char C) {
46+
return llvm::isAlnum(C) || C == '-' || C == '_' || C == ':';
47+
})
48+
.drop_while(isWhitespace);
49+
// The rest of the tag consists of attributes, which have restrictive names.
50+
// If we hit '=', all bets are off (attribute values can contain anything).
51+
for (; !Contents.empty(); Contents = Contents.drop_front()) {
52+
if (llvm::isAlnum(Contents.front()) || isWhitespace(Contents.front()))
53+
continue;
54+
if (Contents.front() == '>' || Contents.startswith("/>"))
55+
return true; // May close the tag.
56+
if (Contents.front() == '=')
57+
return true; // Don't try to parse attribute values.
58+
return false; // Random punctuation means this isn't a tag.
59+
}
60+
return true; // Potentially incomplete tag.
61+
}
62+
63+
// Tests whether C should be backslash-escaped in markdown.
64+
// The string being escaped is Before + C + After. This is part of a paragraph.
65+
// StartsLine indicates whether `Before` is the start of the line.
66+
// After may not be everything until the end of the line.
67+
//
68+
// It's always safe to escape punctuation, but want minimal escaping.
69+
// The strategy is to escape the first character of anything that might start
70+
// a markdown grammar construct.
71+
bool needsLeadingEscape(char C, llvm::StringRef Before, llvm::StringRef After,
72+
bool StartsLine) {
73+
assert(Before.take_while(isWhitespace).empty());
74+
auto RulerLength = [&]() -> /*Length*/ unsigned {
75+
if (!StartsLine || !Before.empty())
76+
return false;
77+
llvm::StringRef A = After.rtrim();
78+
return llvm::all_of(A, [C](char D) { return C == D; }) ? 1 + A.size() : 0;
79+
};
80+
auto IsBullet = [&]() {
81+
return StartsLine && Before.empty() &&
82+
(After.empty() || After.startswith(" "));
83+
};
84+
auto SpaceSurrounds = [&]() {
85+
return (After.empty() || isWhitespace(After.front())) &&
86+
(Before.empty() || isWhitespace(Before.back()));
87+
};
88+
auto WordSurrounds = [&]() {
89+
return (!After.empty() && llvm::isAlnum(After.front())) &&
90+
(!Before.empty() && llvm::isAlnum(Before.back()));
91+
};
92+
93+
switch (C) {
94+
case '\\': // Escaped character.
95+
return true;
96+
case '`': // Code block or inline code
97+
// Any number of backticks can delimit an inline code block that can end
98+
// anywhere (including on another line). We must escape them all.
99+
return true;
100+
case '~': // Code block
101+
return StartsLine && Before.empty() && After.startswith("~~");
102+
case '#': { // ATX heading.
103+
if (!StartsLine || !Before.empty())
104+
return false;
105+
llvm::StringRef Rest = After.ltrim(C);
106+
return Rest.empty() || Rest.startswith(" ");
107+
}
108+
case ']': // Link or link reference.
109+
// We escape ] rather than [ here, because it's more constrained:
110+
// ](...) is an in-line link
111+
// ]: is a link reference
112+
// The following are only links if the link reference exists:
113+
// ] by itself is a shortcut link
114+
// ][...] is an out-of-line link
115+
// Because we never emit link references, we don't need to handle these.
116+
return After.startswith(":") || After.startswith("(");
117+
case '=': // Setex heading.
118+
return RulerLength() > 0;
119+
case '_': // Horizontal ruler or matched delimiter.
120+
if (RulerLength() >= 3)
121+
return true;
122+
// Not a delimiter if surrounded by space, or inside a word.
123+
// (The rules at word boundaries are subtle).
124+
return !(SpaceSurrounds() || WordSurrounds());
125+
case '-': // Setex heading, horizontal ruler, or bullet.
126+
if (RulerLength() > 0)
127+
return true;
128+
return IsBullet();
129+
case '+': // Bullet list.
130+
return IsBullet();
131+
case '*': // Bullet list, horizontal ruler, or delimiter.
132+
return IsBullet() || RulerLength() >= 3 || !SpaceSurrounds();
133+
case '<': // HTML tag (or autolink, which we choose not to escape)
134+
return looksLikeTag(After);
135+
case '>': // Quote marker. Needs escaping at start of line.
136+
return StartsLine && Before.empty();
137+
case '&': { // HTML entity reference
138+
auto End = After.find(';');
139+
if (End == llvm::StringRef::npos)
140+
return false;
141+
llvm::StringRef Content = After.substr(0, End);
142+
if (Content.consume_front("#")) {
143+
if (Content.consume_front("x") || Content.consume_front("X"))
144+
return llvm::all_of(Content, llvm::isHexDigit);
145+
return llvm::all_of(Content, llvm::isDigit);
146+
}
147+
return llvm::all_of(Content, llvm::isAlpha);
148+
}
149+
case '.': // Numbered list indicator. Escape 12. -> 12\. at start of line.
150+
case ')':
151+
return StartsLine && !Before.empty() &&
152+
llvm::all_of(Before, llvm::isDigit) && After.startswith(" ");
153+
default:
154+
return false;
155+
}
156+
}
157+
29158
/// Escape a markdown text block. Ensures the punctuation will not introduce
30159
/// any of the markdown constructs.
31-
std::string renderText(llvm::StringRef Input) {
32-
// Escaping ASCII punctuation ensures we can't start a markdown construct.
33-
constexpr llvm::StringLiteral Punctuation =
34-
R"txt(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)txt";
35-
160+
std::string renderText(llvm::StringRef Input, bool StartsLine) {
36161
std::string R;
37-
for (size_t From = 0; From < Input.size();) {
38-
size_t Next = Input.find_first_of(Punctuation, From);
39-
R += Input.substr(From, Next - From);
40-
if (Next == llvm::StringRef::npos)
41-
break;
42-
R += "\\";
43-
R += Input[Next];
44-
45-
From = Next + 1;
162+
for (unsigned I = 0; I < Input.size(); ++I) {
163+
if (needsLeadingEscape(Input[I], Input.substr(0, I), Input.substr(I + 1),
164+
StartsLine))
165+
R.push_back('\\');
166+
R.push_back(Input[I]);
46167
}
47168
return R;
48169
}
@@ -236,7 +357,7 @@ void Paragraph::renderMarkdown(llvm::raw_ostream &OS) const {
236357
OS << Sep;
237358
switch (C.Kind) {
238359
case Chunk::PlainText:
239-
OS << renderText(C.Contents);
360+
OS << renderText(C.Contents, Sep.empty());
240361
break;
241362
case Chunk::InlineCode:
242363
OS << renderInlineBlock(C.Contents);

clang-tools-extra/clangd/FormattedString.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ class Document {
9595
BulletList &addBulletList();
9696

9797
/// Doesn't contain any trailing newlines.
98+
/// We try to make the markdown human-readable, e.g. avoid extra escaping.
99+
/// At least one client (coc.nvim) displays the markdown verbatim!
98100
std::string asMarkdown() const;
99101
/// Doesn't contain any trailing newlines.
100102
std::string asPlainText() const;

0 commit comments

Comments
 (0)