Skip to content

Commit 4256146

Browse files
authored
LLVM and LLVM-SPIRV-Translator pulldown
LLVM: 6201f66 LLVM-SPIRV-Translator: 39edc1dc
2 parents afff49b + 7aff55c commit 4256146

File tree

3,776 files changed

+132455
-46328
lines changed

Some content is hidden

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

3,776 files changed

+132455
-46328
lines changed

.arcconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"phabricator.uri" : "https://reviews.llvm.org/",
33
"repository.callsign" : "G",
4-
"conduit_uri" : "https://reviews.llvm.org/"
4+
"conduit_uri" : "https://reviews.llvm.org/",
5+
"base": "git:HEAD^"
56
}

clang-tools-extra/.arcconfig

Lines changed: 0 additions & 4 deletions
This file was deleted.

clang-tools-extra/clang-tidy/add_new_check.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def add_release_notes(module_path, module, check_name):
221221

222222
lineMatcher = re.compile('New checks')
223223
nextSectionMatcher = re.compile('New check aliases')
224-
checkerMatcher = re.compile('- New :doc:`(.*)')
224+
checkMatcher = re.compile('- New :doc:`(.*)')
225225

226226
print('Updating %s...' % filename)
227227
with open(filename, 'w') as f:
@@ -234,10 +234,10 @@ def add_release_notes(module_path, module, check_name):
234234
if not note_added:
235235
match = lineMatcher.match(line)
236236
match_next = nextSectionMatcher.match(line)
237-
match_checker = checkerMatcher.match(line)
238-
if match_checker:
239-
last_checker = match_checker.group(1)
240-
if last_checker > check_name_dashes:
237+
match_check = checkMatcher.match(line)
238+
if match_check:
239+
last_check = match_check.group(1)
240+
if last_check > check_name_dashes:
241241
add_note_here = True
242242

243243
if match_next:

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <algorithm>
1515
#include <cctype>
1616

17+
// FixItHint
18+
1719
using namespace clang::ast_matchers;
1820

1921
namespace clang {

clang-tools-extra/clang-tidy/misc/NoRecursionCheck.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,8 @@ void NoRecursionCheck::handleSCC(ArrayRef<CallGraphNode *> SCC) {
204204

205205
// First of all, call out every stongly connected function.
206206
for (CallGraphNode *N : SCC) {
207-
Decl *D = N->getDecl();
208-
diag(D->getLocation(), "function %0 is within a recursive call chain")
209-
<< cast<NamedDecl>(D);
207+
FunctionDecl *D = N->getDefinition();
208+
diag(D->getLocation(), "function %0 is within a recursive call chain") << D;
210209
}
211210

212211
// Now, SCC only tells us about strongly connected function declarations in
@@ -228,13 +227,13 @@ void NoRecursionCheck::handleSCC(ArrayRef<CallGraphNode *> SCC) {
228227
assert(CyclicCallStack.size() >= 2 && "Cycle requires at least 2 frames");
229228

230229
// Which function we decided to be the entry point that lead to the recursion?
231-
Decl *CycleEntryFn = CyclicCallStack.front().Callee->getDecl();
230+
FunctionDecl *CycleEntryFn = CyclicCallStack.front().Callee->getDefinition();
232231
// And now, for ease of understanding, let's print the call sequence that
233232
// forms the cycle in question.
234233
diag(CycleEntryFn->getLocation(),
235234
"example recursive call chain, starting from function %0",
236235
DiagnosticIDs::Note)
237-
<< cast<NamedDecl>(CycleEntryFn);
236+
<< CycleEntryFn;
238237
for (int CurFrame = 1, NumFrames = CyclicCallStack.size();
239238
CurFrame != NumFrames; ++CurFrame) {
240239
CallGraphNode::CallRecord PrevNode = CyclicCallStack[CurFrame - 1];

clang-tools-extra/clang-tidy/misc/RedundantExpressionCheck.cpp

Lines changed: 190 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
#include "llvm/ADT/APInt.h"
1919
#include "llvm/ADT/APSInt.h"
2020
#include "llvm/ADT/FoldingSet.h"
21+
#include "llvm/ADT/SmallBitVector.h"
2122
#include "llvm/Support/Casting.h"
23+
#include "llvm/Support/FormatVariadic.h"
2224
#include <algorithm>
2325
#include <cassert>
2426
#include <cstdint>
@@ -304,6 +306,132 @@ static void transformSubToCanonicalAddExpr(BinaryOperatorKind &Opcode,
304306
}
305307
}
306308

309+
// to use in the template below
310+
static OverloadedOperatorKind getOp(const BinaryOperator *Op) {
311+
return BinaryOperator::getOverloadedOperator(Op->getOpcode());
312+
}
313+
314+
static OverloadedOperatorKind getOp(const CXXOperatorCallExpr *Op) {
315+
if (Op->getNumArgs() != 2)
316+
return OO_None;
317+
return Op->getOperator();
318+
}
319+
320+
static std::pair<const Expr *, const Expr *>
321+
getOperands(const BinaryOperator *Op) {
322+
return {Op->getLHS()->IgnoreParenImpCasts(),
323+
Op->getRHS()->IgnoreParenImpCasts()};
324+
}
325+
326+
static std::pair<const Expr *, const Expr *>
327+
getOperands(const CXXOperatorCallExpr *Op) {
328+
return {Op->getArg(0)->IgnoreParenImpCasts(),
329+
Op->getArg(1)->IgnoreParenImpCasts()};
330+
}
331+
332+
template <typename TExpr>
333+
static const TExpr *checkOpKind(const Expr *TheExpr,
334+
OverloadedOperatorKind OpKind) {
335+
const auto *AsTExpr = dyn_cast_or_null<TExpr>(TheExpr);
336+
if (AsTExpr && getOp(AsTExpr) == OpKind)
337+
return AsTExpr;
338+
339+
return nullptr;
340+
}
341+
342+
// returns true if a subexpression has two directly equivalent operands and
343+
// is already handled by operands/parametersAreEquivalent
344+
template <typename TExpr, unsigned N>
345+
static bool collectOperands(const Expr *Part,
346+
SmallVector<const Expr *, N> &AllOperands,
347+
OverloadedOperatorKind OpKind) {
348+
if (const auto *BinOp = checkOpKind<TExpr>(Part, OpKind)) {
349+
const std::pair<const Expr *, const Expr *> Operands = getOperands(BinOp);
350+
if (areEquivalentExpr(Operands.first, Operands.second))
351+
return true;
352+
return collectOperands<TExpr>(Operands.first, AllOperands, OpKind) ||
353+
collectOperands<TExpr>(Operands.second, AllOperands, OpKind);
354+
}
355+
356+
AllOperands.push_back(Part);
357+
return false;
358+
}
359+
360+
template <typename TExpr>
361+
static bool hasSameOperatorParent(const Expr *TheExpr,
362+
OverloadedOperatorKind OpKind,
363+
ASTContext &Context) {
364+
// IgnoreParenImpCasts logic in reverse: skip surrounding uninteresting nodes
365+
const DynTypedNodeList Parents = Context.getParents(*TheExpr);
366+
for (ast_type_traits::DynTypedNode DynParent : Parents) {
367+
if (const auto *Parent = DynParent.get<Expr>()) {
368+
bool Skip = isa<ParenExpr>(Parent) || isa<ImplicitCastExpr>(Parent) ||
369+
isa<FullExpr>(Parent) ||
370+
isa<MaterializeTemporaryExpr>(Parent);
371+
if (Skip && hasSameOperatorParent<TExpr>(Parent, OpKind, Context))
372+
return true;
373+
if (checkOpKind<TExpr>(Parent, OpKind))
374+
return true;
375+
}
376+
}
377+
378+
return false;
379+
}
380+
381+
template <typename TExpr>
382+
static bool
383+
markDuplicateOperands(const TExpr *TheExpr,
384+
ast_matchers::internal::BoundNodesTreeBuilder *Builder,
385+
ASTContext &Context) {
386+
const OverloadedOperatorKind OpKind = getOp(TheExpr);
387+
if (OpKind == OO_None)
388+
return false;
389+
// if there are no nested operators of the same kind, it's handled by
390+
// operands/parametersAreEquivalent
391+
const std::pair<const Expr *, const Expr *> Operands = getOperands(TheExpr);
392+
if (!(checkOpKind<TExpr>(Operands.first, OpKind) ||
393+
checkOpKind<TExpr>(Operands.second, OpKind)))
394+
return false;
395+
396+
// if parent is the same kind of operator, it's handled by a previous call to
397+
// markDuplicateOperands
398+
if (hasSameOperatorParent<TExpr>(TheExpr, OpKind, Context))
399+
return false;
400+
401+
SmallVector<const Expr *, 4> AllOperands;
402+
if (collectOperands<TExpr>(Operands.first, AllOperands, OpKind))
403+
return false;
404+
if (collectOperands<TExpr>(Operands.second, AllOperands, OpKind))
405+
return false;
406+
size_t NumOperands = AllOperands.size();
407+
llvm::SmallBitVector Duplicates(NumOperands);
408+
for (size_t I = 0; I < NumOperands; I++) {
409+
if (Duplicates[I])
410+
continue;
411+
bool FoundDuplicates = false;
412+
413+
for (size_t J = I + 1; J < NumOperands; J++) {
414+
if (AllOperands[J]->HasSideEffects(Context))
415+
break;
416+
417+
if (areEquivalentExpr(AllOperands[I], AllOperands[J])) {
418+
FoundDuplicates = true;
419+
Duplicates.set(J);
420+
Builder->setBinding(
421+
SmallString<11>(llvm::formatv("duplicate{0}", J)),
422+
ast_type_traits::DynTypedNode::create(*AllOperands[J]));
423+
}
424+
}
425+
426+
if (FoundDuplicates)
427+
Builder->setBinding(
428+
SmallString<11>(llvm::formatv("duplicate{0}", I)),
429+
ast_type_traits::DynTypedNode::create(*AllOperands[I]));
430+
}
431+
432+
return Duplicates.any();
433+
}
434+
307435
AST_MATCHER(Expr, isIntegerConstantExpr) {
308436
if (Node.isInstantiationDependent())
309437
return false;
@@ -314,6 +442,10 @@ AST_MATCHER(BinaryOperator, operandsAreEquivalent) {
314442
return areEquivalentExpr(Node.getLHS(), Node.getRHS());
315443
}
316444

445+
AST_MATCHER(BinaryOperator, nestedOperandsAreEquivalent) {
446+
return markDuplicateOperands(&Node, Builder, Finder->getASTContext());
447+
}
448+
317449
AST_MATCHER(ConditionalOperator, expressionsAreEquivalent) {
318450
return areEquivalentExpr(Node.getTrueExpr(), Node.getFalseExpr());
319451
}
@@ -323,6 +455,10 @@ AST_MATCHER(CallExpr, parametersAreEquivalent) {
323455
areEquivalentExpr(Node.getArg(0), Node.getArg(1));
324456
}
325457

458+
AST_MATCHER(CXXOperatorCallExpr, nestedParametersAreEquivalent) {
459+
return markDuplicateOperands(&Node, Builder, Finder->getASTContext());
460+
}
461+
326462
AST_MATCHER(BinaryOperator, binaryOperatorIsInMacro) {
327463
return Node.getOperatorLoc().isMacroID();
328464
}
@@ -484,8 +620,15 @@ static bool isNonConstReferenceType(QualType ParamType) {
484620
// is a temporary expression. Whether the second parameter is checked is
485621
// controlled by the parameter `ParamsToCheckCount`.
486622
static bool
487-
canOverloadedOperatorArgsBeModified(const FunctionDecl *OperatorDecl,
623+
canOverloadedOperatorArgsBeModified(const CXXOperatorCallExpr *OperatorCall,
488624
bool checkSecondParam) {
625+
const auto *OperatorDecl =
626+
dyn_cast_or_null<FunctionDecl>(OperatorCall->getCalleeDecl());
627+
// if we can't find the declaration, conservatively assume it can modify
628+
// arguments
629+
if (!OperatorDecl)
630+
return true;
631+
489632
unsigned ParamCount = OperatorDecl->getNumParams();
490633

491634
// Overloaded operators declared inside a class have only one param.
@@ -527,14 +670,7 @@ static bool retrieveRelationalIntegerConstantExpr(
527670
Value = APSInt(32, false);
528671
} else if (const auto *OverloadedOperatorExpr =
529672
Result.Nodes.getNodeAs<CXXOperatorCallExpr>(OverloadId)) {
530-
const auto *OverloadedFunctionDecl = dyn_cast_or_null<FunctionDecl>(OverloadedOperatorExpr->getCalleeDecl());
531-
if (!OverloadedFunctionDecl)
532-
return false;
533-
534-
if (canOverloadedOperatorArgsBeModified(OverloadedFunctionDecl, false))
535-
return false;
536-
537-
if (canOverloadedOperatorArgsBeModified(OverloadedFunctionDecl, false))
673+
if (canOverloadedOperatorArgsBeModified(OverloadedOperatorExpr, false))
538674
return false;
539675

540676
if (const auto *Arg = OverloadedOperatorExpr->getArg(1)) {
@@ -714,6 +850,21 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
714850
.bind("binary"),
715851
this);
716852

853+
// Logical or bitwise operator with equivalent nested operands, like (X && Y
854+
// && X) or (X && (Y && X))
855+
Finder->addMatcher(
856+
binaryOperator(anyOf(hasOperatorName("|"), hasOperatorName("&"),
857+
hasOperatorName("||"), hasOperatorName("&&"),
858+
hasOperatorName("^")),
859+
nestedOperandsAreEquivalent(),
860+
// Filter noisy false positives.
861+
unless(isInTemplateInstantiation()),
862+
unless(binaryOperatorIsInMacro()),
863+
// TODO: if the banned macros are themselves duplicated
864+
unless(hasDescendant(BannedIntegerLiteral)))
865+
.bind("nested-duplicates"),
866+
this);
867+
717868
// Conditional (trenary) operator with equivalent operands, like (Y ? X : X).
718869
Finder->addMatcher(conditionalOperator(expressionsAreEquivalent(),
719870
// Filter noisy false positives.
@@ -740,6 +891,19 @@ void RedundantExpressionCheck::registerMatchers(MatchFinder *Finder) {
740891
.bind("call"),
741892
this);
742893

894+
// Overloaded operators with equivalent operands.
895+
Finder->addMatcher(
896+
cxxOperatorCallExpr(
897+
anyOf(hasOverloadedOperatorName("|"), hasOverloadedOperatorName("&"),
898+
hasOverloadedOperatorName("||"),
899+
hasOverloadedOperatorName("&&"),
900+
hasOverloadedOperatorName("^")),
901+
nestedParametersAreEquivalent(), argumentCountIs(2),
902+
// Filter noisy false positives.
903+
unless(isMacro()), unless(isInTemplateInstantiation()))
904+
.bind("nested-duplicates"),
905+
this);
906+
743907
// Match expressions like: !(1 | 2 | 3)
744908
Finder->addMatcher(
745909
implicitCastExpr(
@@ -1061,17 +1225,29 @@ void RedundantExpressionCheck::check(const MatchFinder::MatchResult &Result) {
10611225
}
10621226

10631227
if (const auto *Call = Result.Nodes.getNodeAs<CXXOperatorCallExpr>("call")) {
1064-
const auto *OverloadedFunctionDecl = dyn_cast_or_null<FunctionDecl>(Call->getCalleeDecl());
1065-
if (!OverloadedFunctionDecl)
1066-
return;
1067-
1068-
if (canOverloadedOperatorArgsBeModified(OverloadedFunctionDecl, true))
1228+
if (canOverloadedOperatorArgsBeModified(Call, true))
10691229
return;
10701230

10711231
diag(Call->getOperatorLoc(),
10721232
"both sides of overloaded operator are equivalent");
10731233
}
10741234

1235+
if (const auto *Op = Result.Nodes.getNodeAs<Expr>("nested-duplicates")) {
1236+
const auto *Call = dyn_cast<CXXOperatorCallExpr>(Op);
1237+
if (Call && canOverloadedOperatorArgsBeModified(Call, true))
1238+
return;
1239+
1240+
StringRef Message =
1241+
Call ? "overloaded operator has equivalent nested operands"
1242+
: "operator has equivalent nested operands";
1243+
1244+
const auto Diag = diag(Op->getExprLoc(), Message);
1245+
for (const auto &KeyValue : Result.Nodes.getMap()) {
1246+
if (StringRef(KeyValue.first).startswith("duplicate"))
1247+
Diag << KeyValue.second.getSourceRange();
1248+
}
1249+
}
1250+
10751251
if (const auto *NegateOperator =
10761252
Result.Nodes.getNodeAs<UnaryOperator>("logical-bitwise-confusion")) {
10771253
SourceLocation OperatorLoc = NegateOperator->getOperatorLoc();

clang-tools-extra/clang-tidy/misc/UnconventionalAssignOperatorCheck.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ void UnconventionalAssignOperatorCheck::registerMatchers(
6060
anyOf(unaryOperator(hasOperatorName("*"), hasUnaryOperand(cxxThisExpr())),
6161
cxxOperatorCallExpr(argumentCountIs(1),
6262
callee(unresolvedLookupExpr()),
63-
hasArgument(0, cxxThisExpr())))))));
63+
hasArgument(0, cxxThisExpr())),
64+
cxxOperatorCallExpr(
65+
hasOverloadedOperatorName("="),
66+
hasArgument(
67+
0, unaryOperator(hasOperatorName("*"),
68+
hasUnaryOperand(cxxThisExpr())))))))));
6469
const auto IsGoodAssign = cxxMethodDecl(IsAssign, HasGoodReturnType);
6570

6671
Finder->addMatcher(returnStmt(IsBadReturnStatement, forFunction(IsGoodAssign))

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,10 @@ namespace clang {
1616
namespace tidy {
1717
namespace modernize {
1818

19-
static const llvm::SmallVector<StringRef, 5> DeprecatedTypes = {
20-
{"::std::ios_base::io_state"},
21-
{"::std::ios_base::open_mode"},
22-
{"::std::ios_base::seek_dir"},
23-
{"::std::ios_base::streamoff"},
24-
{"::std::ios_base::streampos"}};
19+
static constexpr std::array<StringRef, 5> DeprecatedTypes = {
20+
"::std::ios_base::io_state", "::std::ios_base::open_mode",
21+
"::std::ios_base::seek_dir", "::std::ios_base::streamoff",
22+
"::std::ios_base::streampos"};
2523

2624
static const llvm::StringMap<StringRef> ReplacementTypes = {
2725
{"io_state", "iostate"},

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#define DEBUG_TYPE "clang-tidy"
2020

21+
// FixItHint
22+
2123
using namespace clang::ast_matchers;
2224

2325
namespace clang {

0 commit comments

Comments
 (0)