Skip to content

Commit 0b4a56d

Browse files
authored
LLVM and SPIRV-LLVM-Translator pulldown (WW01-02) #3015
LLVM: llvm/llvm-project@b4655a0 SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@f57e6c9
2 parents 3372601 + fbd9079 commit 0b4a56d

File tree

1,408 files changed

+770532
-471956
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,408 files changed

+770532
-471956
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@
2222
#include "ExpandModularHeadersPPCallbacks.h"
2323
#include "clang-tidy-config.h"
2424
#include "clang/AST/ASTConsumer.h"
25-
#include "clang/AST/ASTContext.h"
26-
#include "clang/AST/Decl.h"
2725
#include "clang/ASTMatchers/ASTMatchFinder.h"
2826
#include "clang/Format/Format.h"
2927
#include "clang/Frontend/ASTConsumers.h"
3028
#include "clang/Frontend/CompilerInstance.h"
31-
#include "clang/Frontend/FrontendActions.h"
3229
#include "clang/Frontend/FrontendDiagnostic.h"
3330
#include "clang/Frontend/MultiplexConsumer.h"
3431
#include "clang/Frontend/TextDiagnosticPrinter.h"
@@ -43,7 +40,6 @@
4340
#include "clang/Tooling/ReplacementsYaml.h"
4441
#include "clang/Tooling/Tooling.h"
4542
#include "llvm/Support/Process.h"
46-
#include "llvm/Support/Signals.h"
4743
#include <algorithm>
4844
#include <utility>
4945

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
#include "llvm/ADT/SmallString.h"
1111
#include "llvm/ADT/StringRef.h"
1212
#include "llvm/Support/Error.h"
13-
#include "llvm/Support/WithColor.h"
1413
#include "llvm/Support/YAMLParser.h"
15-
#include "llvm/Support/raw_ostream.h"
1614

1715
namespace clang {
1816
namespace tidy {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,24 @@
2323
#include "clang/AST/Attr.h"
2424
#include "clang/Basic/Diagnostic.h"
2525
#include "clang/Basic/DiagnosticOptions.h"
26-
#include "clang/Basic/FileManager.h"
2726
#include "clang/Basic/SourceManager.h"
2827
#include "clang/Frontend/DiagnosticRenderer.h"
2928
#include "clang/Tooling/Core/Diagnostic.h"
3029
#include "clang/Tooling/Core/Replacement.h"
3130
#include "llvm/ADT/STLExtras.h"
3231
#include "llvm/ADT/SmallString.h"
3332
#include "llvm/ADT/StringMap.h"
34-
#include "llvm/Support/ErrorHandling.h"
3533
#include "llvm/Support/FormatVariadic.h"
3634
#include "llvm/Support/Regex.h"
3735
#include <tuple>
3836
#include <vector>
3937
using namespace clang;
4038
using namespace tidy;
4139

40+
#ifdef LLVM_CLANG_AST_ATTR_H
41+
//#error
42+
#endif
43+
4244
namespace {
4345
class ClangTidyDiagnosticRenderer : public DiagnosticRenderer {
4446
public:

clang-tools-extra/clang-tidy/ClangTidyModule.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
#include "llvm/ADT/StringMap.h"
1414
#include "llvm/ADT/StringRef.h"
1515
#include <functional>
16-
#include <map>
1716
#include <memory>
18-
#include <string>
1917

2018
namespace clang {
2119
namespace tidy {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "llvm/Support/MemoryBufferRef.h"
1717
#include "llvm/Support/Path.h"
1818
#include "llvm/Support/YAMLTraits.h"
19-
#include "llvm/Support/raw_ostream.h"
2019
#include <utility>
2120

2221
#define DEBUG_TYPE "clang-tidy-options"

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "ClangTidyProfiling.h"
10-
#include "llvm/ADT/STLExtras.h"
1110
#include "llvm/ADT/SmallString.h"
1211
#include "llvm/Support/FileSystem.h"
1312
#include "llvm/Support/Path.h"
14-
#include "llvm/Support/YAMLTraits.h"
1513
#include "llvm/Support/raw_ostream.h"
1614
#include <system_error>
1715
#include <utility>

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

Lines changed: 148 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,77 @@
1616
using namespace clang::ast_matchers;
1717

1818
namespace clang {
19+
namespace ast_matchers {
20+
AST_POLYMORPHIC_MATCHER_P2(hasAnyArgumentWithParam,
21+
AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr,
22+
CXXConstructExpr),
23+
internal::Matcher<Expr>, ArgMatcher,
24+
internal::Matcher<ParmVarDecl>, ParamMatcher) {
25+
BoundNodesTreeBuilder Result;
26+
// The first argument of an overloaded member operator is the implicit object
27+
// argument of the method which should not be matched against a parameter, so
28+
// we skip over it here.
29+
BoundNodesTreeBuilder Matches;
30+
unsigned ArgIndex = cxxOperatorCallExpr(callee(cxxMethodDecl()))
31+
.matches(Node, Finder, &Matches)
32+
? 1
33+
: 0;
34+
int ParamIndex = 0;
35+
for (; ArgIndex < Node.getNumArgs(); ++ArgIndex) {
36+
BoundNodesTreeBuilder ArgMatches(*Builder);
37+
if (ArgMatcher.matches(*(Node.getArg(ArgIndex)->IgnoreParenCasts()), Finder,
38+
&ArgMatches)) {
39+
BoundNodesTreeBuilder ParamMatches(ArgMatches);
40+
if (expr(anyOf(cxxConstructExpr(hasDeclaration(cxxConstructorDecl(
41+
hasParameter(ParamIndex, ParamMatcher)))),
42+
callExpr(callee(functionDecl(
43+
hasParameter(ParamIndex, ParamMatcher))))))
44+
.matches(Node, Finder, &ParamMatches)) {
45+
Result.addMatch(ParamMatches);
46+
*Builder = std::move(Result);
47+
return true;
48+
}
49+
}
50+
++ParamIndex;
51+
}
52+
return false;
53+
}
54+
55+
AST_MATCHER(Expr, usedInBooleanContext) {
56+
const char *ExprName = "__booleanContextExpr";
57+
auto Result =
58+
expr(expr().bind(ExprName),
59+
anyOf(hasParent(varDecl(hasType(booleanType()))),
60+
hasParent(cxxConstructorDecl(
61+
hasAnyConstructorInitializer(cxxCtorInitializer(
62+
withInitializer(expr(equalsBoundNode(ExprName))),
63+
forField(hasType(booleanType())))))),
64+
hasParent(fieldDecl(hasType(booleanType()))),
65+
hasParent(stmt(anyOf(
66+
explicitCastExpr(hasDestinationType(booleanType())),
67+
ifStmt(hasCondition(expr(equalsBoundNode(ExprName)))),
68+
doStmt(hasCondition(expr(equalsBoundNode(ExprName)))),
69+
whileStmt(hasCondition(expr(equalsBoundNode(ExprName)))),
70+
forStmt(hasCondition(expr(equalsBoundNode(ExprName)))),
71+
conditionalOperator(
72+
hasCondition(expr(equalsBoundNode(ExprName)))),
73+
parenListExpr(hasParent(varDecl(hasType(booleanType())))),
74+
parenExpr(hasParent(
75+
explicitCastExpr(hasDestinationType(booleanType())))),
76+
returnStmt(forFunction(returns(booleanType()))),
77+
cxxUnresolvedConstructExpr(hasType(booleanType())),
78+
callExpr(hasAnyArgumentWithParam(
79+
expr(equalsBoundNode(ExprName)),
80+
parmVarDecl(hasType(booleanType())))),
81+
binaryOperator(hasAnyOperatorName("&&", "||")),
82+
unaryOperator(hasOperatorName("!")).bind("NegOnSize"))))))
83+
.matches(Node, Finder, Builder);
84+
Builder->removeBindings([ExprName](const BoundNodesMap &Nodes) {
85+
return Nodes.getNode(ExprName).getNodeKind().isNone();
86+
});
87+
return Result;
88+
}
89+
} // namespace ast_matchers
1990
namespace tidy {
2091
namespace readability {
2192

@@ -26,18 +97,27 @@ ContainerSizeEmptyCheck::ContainerSizeEmptyCheck(StringRef Name,
2697
: ClangTidyCheck(Name, Context) {}
2798

2899
void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
29-
const auto ValidContainer = qualType(hasUnqualifiedDesugaredType(
30-
recordType(hasDeclaration(cxxRecordDecl(isSameOrDerivedFrom(
31-
namedDecl(
32-
has(cxxMethodDecl(
33-
isConst(), parameterCountIs(0), isPublic(),
34-
hasName("size"),
35-
returns(qualType(isInteger(), unless(booleanType()))))
36-
.bind("size")),
37-
has(cxxMethodDecl(isConst(), parameterCountIs(0), isPublic(),
38-
hasName("empty"), returns(booleanType()))
39-
.bind("empty")))
40-
.bind("container")))))));
100+
const auto ValidContainerRecord = cxxRecordDecl(isSameOrDerivedFrom(
101+
namedDecl(
102+
has(cxxMethodDecl(isConst(), parameterCountIs(0), isPublic(),
103+
hasName("size"),
104+
returns(qualType(isInteger(), unless(booleanType()),
105+
unless(elaboratedType()))))
106+
.bind("size")),
107+
has(cxxMethodDecl(isConst(), parameterCountIs(0), isPublic(),
108+
hasName("empty"), returns(booleanType()))
109+
.bind("empty")))
110+
.bind("container")));
111+
112+
const auto ValidContainerNonTemplateType =
113+
qualType(hasUnqualifiedDesugaredType(
114+
recordType(hasDeclaration(ValidContainerRecord))));
115+
const auto ValidContainerTemplateType =
116+
qualType(hasUnqualifiedDesugaredType(templateSpecializationType(
117+
hasDeclaration(classTemplateDecl(has(ValidContainerRecord))))));
118+
119+
const auto ValidContainer = qualType(
120+
anyOf(ValidContainerNonTemplateType, ValidContainerTemplateType));
41121

42122
const auto WrongUse = traverse(
43123
TK_AsIs,
@@ -52,18 +132,34 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
52132
anyOf(hasParent(
53133
unaryOperator(hasOperatorName("!")).bind("NegOnSize")),
54134
anything()))),
55-
hasParent(explicitCastExpr(hasDestinationType(booleanType())))));
135+
usedInBooleanContext()));
56136

57137
Finder->addMatcher(
58-
cxxMemberCallExpr(on(expr(anyOf(hasType(ValidContainer),
138+
cxxMemberCallExpr(unless(isInTemplateInstantiation()),
139+
on(expr(anyOf(hasType(ValidContainer),
59140
hasType(pointsTo(ValidContainer)),
60-
hasType(references(ValidContainer))))),
141+
hasType(references(ValidContainer))))
142+
.bind("MemberCallObject")),
61143
callee(cxxMethodDecl(hasName("size"))), WrongUse,
62144
unless(hasAncestor(cxxMethodDecl(
63145
ofClass(equalsBoundNode("container"))))))
64146
.bind("SizeCallExpr"),
65147
this);
66148

149+
Finder->addMatcher(
150+
callExpr(has(cxxDependentScopeMemberExpr(
151+
hasObjectExpression(
152+
expr(anyOf(hasType(ValidContainer),
153+
hasType(pointsTo(ValidContainer)),
154+
hasType(references(ValidContainer))))
155+
.bind("MemberCallObject")),
156+
hasMemberName("size"))),
157+
WrongUse,
158+
unless(hasAncestor(
159+
cxxMethodDecl(ofClass(equalsBoundNode("container"))))))
160+
.bind("SizeCallExpr"),
161+
this);
162+
67163
// Empty constructor matcher.
68164
const auto DefaultConstructor = cxxConstructExpr(
69165
hasDeclaration(cxxConstructorDecl(isDefaultConstructor())));
@@ -72,12 +168,11 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
72168
ignoringImpCasts(stringLiteral(hasSize(0))),
73169
ignoringImpCasts(cxxBindTemporaryExpr(has(DefaultConstructor))),
74170
ignoringImplicit(DefaultConstructor),
75-
cxxConstructExpr(
76-
hasDeclaration(cxxConstructorDecl(isCopyConstructor())),
77-
has(expr(ignoringImpCasts(DefaultConstructor)))),
78-
cxxConstructExpr(
79-
hasDeclaration(cxxConstructorDecl(isMoveConstructor())),
80-
has(expr(ignoringImpCasts(DefaultConstructor)))));
171+
cxxConstructExpr(hasDeclaration(cxxConstructorDecl(isCopyConstructor())),
172+
has(expr(ignoringImpCasts(DefaultConstructor)))),
173+
cxxConstructExpr(hasDeclaration(cxxConstructorDecl(isMoveConstructor())),
174+
has(expr(ignoringImpCasts(DefaultConstructor)))),
175+
cxxUnresolvedConstructExpr(argumentCountIs(0)));
81176
// Match the object being compared.
82177
const auto STLArg =
83178
anyOf(unaryOperator(
@@ -87,31 +182,41 @@ void ContainerSizeEmptyCheck::registerMatchers(MatchFinder *Finder) {
87182
expr(hasType(ValidContainer)).bind("STLObject"));
88183
Finder->addMatcher(
89184
cxxOperatorCallExpr(
185+
unless(isInTemplateInstantiation()),
90186
hasAnyOverloadedOperatorName("==", "!="),
91187
anyOf(allOf(hasArgument(0, WrongComparend), hasArgument(1, STLArg)),
92188
allOf(hasArgument(0, STLArg), hasArgument(1, WrongComparend))),
93189
unless(hasAncestor(
94190
cxxMethodDecl(ofClass(equalsBoundNode("container"))))))
95191
.bind("BinCmp"),
96192
this);
193+
Finder->addMatcher(
194+
binaryOperator(hasAnyOperatorName("==", "!="),
195+
anyOf(allOf(hasLHS(WrongComparend), hasRHS(STLArg)),
196+
allOf(hasLHS(STLArg), hasRHS(WrongComparend))),
197+
unless(hasAncestor(
198+
cxxMethodDecl(ofClass(equalsBoundNode("container"))))))
199+
.bind("BinCmp"),
200+
this);
97201
}
98202

99203
void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) {
100-
const auto *MemberCall =
101-
Result.Nodes.getNodeAs<CXXMemberCallExpr>("SizeCallExpr");
204+
const auto *MemberCall = Result.Nodes.getNodeAs<Expr>("SizeCallExpr");
205+
const auto *MemberCallObject =
206+
Result.Nodes.getNodeAs<Expr>("MemberCallObject");
102207
const auto *BinCmp = Result.Nodes.getNodeAs<CXXOperatorCallExpr>("BinCmp");
208+
const auto *BinCmpTempl = Result.Nodes.getNodeAs<BinaryOperator>("BinCmp");
103209
const auto *BinaryOp = Result.Nodes.getNodeAs<BinaryOperator>("SizeBinaryOp");
104210
const auto *Pointee = Result.Nodes.getNodeAs<Expr>("Pointee");
105211
const auto *E =
106-
MemberCall
107-
? MemberCall->getImplicitObjectArgument()
212+
MemberCallObject
213+
? MemberCallObject
108214
: (Pointee ? Pointee : Result.Nodes.getNodeAs<Expr>("STLObject"));
109215
FixItHint Hint;
110216
std::string ReplacementText = std::string(
111217
Lexer::getSourceText(CharSourceRange::getTokenRange(E->getSourceRange()),
112218
*Result.SourceManager, getLangOpts()));
113-
if (BinCmp && IsBinaryOrTernary(E)) {
114-
// Not just a DeclRefExpr, so parenthesize to be on the safe side.
219+
if (IsBinaryOrTernary(E) || isa<UnaryOperator>(E)) {
115220
ReplacementText = "(" + ReplacementText + ")";
116221
}
117222
if (E->getType()->isPointerType())
@@ -125,7 +230,13 @@ void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) {
125230
}
126231
Hint =
127232
FixItHint::CreateReplacement(BinCmp->getSourceRange(), ReplacementText);
128-
} else if (BinaryOp) { // Determine the correct transformation.
233+
} else if (BinCmpTempl) {
234+
if (BinCmpTempl->getOpcode() == BinaryOperatorKind::BO_NE) {
235+
ReplacementText = "!" + ReplacementText;
236+
}
237+
Hint = FixItHint::CreateReplacement(BinCmpTempl->getSourceRange(),
238+
ReplacementText);
239+
} else if (BinaryOp) { // Determine the correct transformation.
129240
bool Negation = false;
130241
const bool ContainerIsLHS =
131242
!llvm::isa<IntegerLiteral>(BinaryOp->getLHS()->IgnoreImpCasts());
@@ -195,15 +306,17 @@ void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) {
195306
"!" + ReplacementText);
196307
}
197308

198-
if (MemberCall) {
199-
diag(MemberCall->getBeginLoc(),
200-
"the 'empty' method should be used to check "
201-
"for emptiness instead of 'size'")
309+
auto WarnLoc = MemberCall ? MemberCall->getBeginLoc() : SourceLocation{};
310+
311+
if (WarnLoc.isValid()) {
312+
diag(WarnLoc, "the 'empty' method should be used to check "
313+
"for emptiness instead of 'size'")
202314
<< Hint;
203315
} else {
204-
diag(BinCmp->getBeginLoc(),
205-
"the 'empty' method should be used to check "
206-
"for emptiness instead of comparing to an empty object")
316+
WarnLoc = BinCmpTempl ? BinCmpTempl->getBeginLoc()
317+
: (BinCmp ? BinCmp->getBeginLoc() : SourceLocation{});
318+
diag(WarnLoc, "the 'empty' method should be used to check "
319+
"for emptiness instead of comparing to an empty object")
207320
<< Hint;
208321
}
209322

clang-tools-extra/clangd/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ if (NOT DEFINED CLANGD_BUILD_XPC)
1414
unset(CLANGD_BUILD_XPC_DEFAULT)
1515
endif ()
1616

17+
option(CLANGD_MALLOC_TRIM "Call malloc_trim(3) periodically in Clangd. (only takes effect when using glibc)" ON)
18+
1719
llvm_canonicalize_cmake_booleans(
1820
CLANGD_BUILD_XPC
1921
CLANGD_ENABLE_REMOTE
22+
CLANGD_MALLOC_TRIM
2023
LLVM_ENABLE_ZLIB
2124
)
2225

0 commit comments

Comments
 (0)