Skip to content

Commit 808ff62

Browse files
author
Valery N Dmitriev
committed
Merge from 'master' to 'sycl-web' (#1)
2 parents 4b6c6bf + 930eaad commit 808ff62

File tree

2,610 files changed

+85564
-34383
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,610 files changed

+85564
-34383
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ autoconf/autom4te.cache
5454
# VS2017 and VSCode config files.
5555
.vscode
5656
.vs
57-
# clangd index
58-
.clangd
57+
# clangd index. (".clangd" is a config file now, thus trailing slash)
58+
.clangd/
59+
.cache
5960
# static analyzer regression testing project files
6061
/clang/utils/analyzer/projects/*/CachedSource
6162
/clang/utils/analyzer/projects/*/PatchedSource

clang-tools-extra/clang-move/Move.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -552,20 +552,22 @@ void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
552552

553553
// Match static functions/variable definitions which are defined in named
554554
// namespaces.
555-
Optional<ast_matchers::internal::Matcher<NamedDecl>> HasAnySymbolNames;
555+
SmallVector<std::string, 4> QualNames;
556+
QualNames.reserve(Context->Spec.Names.size());
556557
for (StringRef SymbolName : Context->Spec.Names) {
557-
llvm::StringRef GlobalSymbolName = SymbolName.trim().ltrim(':');
558-
const auto HasName = hasName(("::" + GlobalSymbolName).str());
559-
HasAnySymbolNames =
560-
HasAnySymbolNames ? anyOf(*HasAnySymbolNames, HasName) : HasName;
558+
QualNames.push_back(("::" + SymbolName.trim().ltrim(':')).str());
561559
}
562560

563-
if (!HasAnySymbolNames) {
561+
if (QualNames.empty()) {
564562
llvm::errs() << "No symbols being moved.\n";
565563
return;
566564
}
565+
566+
ast_matchers::internal::Matcher<NamedDecl> HasAnySymbolNames =
567+
hasAnyName(SmallVector<StringRef, 4>(QualNames.begin(), QualNames.end()));
568+
567569
auto InMovedClass =
568-
hasOutermostEnclosingClass(cxxRecordDecl(*HasAnySymbolNames));
570+
hasOutermostEnclosingClass(cxxRecordDecl(HasAnySymbolNames));
569571

570572
// Matchers for helper declarations in old.cc.
571573
auto InAnonymousNS = hasParent(namespaceDecl(isAnonymous()));
@@ -612,38 +614,38 @@ void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
612614
// Create a MatchCallback for class declarations.
613615
MatchCallbacks.push_back(std::make_unique<ClassDeclarationMatch>(this));
614616
// Match moved class declarations.
615-
auto MovedClass = cxxRecordDecl(InOldFiles, *HasAnySymbolNames,
616-
isDefinition(), TopLevelDecl)
617-
.bind("moved_class");
617+
auto MovedClass =
618+
cxxRecordDecl(InOldFiles, HasAnySymbolNames, isDefinition(), TopLevelDecl)
619+
.bind("moved_class");
618620
Finder->addMatcher(MovedClass, MatchCallbacks.back().get());
619621
// Match moved class methods (static methods included) which are defined
620622
// outside moved class declaration.
621-
Finder->addMatcher(
622-
cxxMethodDecl(InOldFiles, ofOutermostEnclosingClass(*HasAnySymbolNames),
623-
isDefinition())
624-
.bind("class_method"),
625-
MatchCallbacks.back().get());
623+
Finder->addMatcher(cxxMethodDecl(InOldFiles,
624+
ofOutermostEnclosingClass(HasAnySymbolNames),
625+
isDefinition())
626+
.bind("class_method"),
627+
MatchCallbacks.back().get());
626628
// Match static member variable definition of the moved class.
627629
Finder->addMatcher(
628630
varDecl(InMovedClass, InOldFiles, isDefinition(), isStaticDataMember())
629631
.bind("class_static_var_decl"),
630632
MatchCallbacks.back().get());
631633

632634
MatchCallbacks.push_back(std::make_unique<FunctionDeclarationMatch>(this));
633-
Finder->addMatcher(functionDecl(InOldFiles, *HasAnySymbolNames, TopLevelDecl)
635+
Finder->addMatcher(functionDecl(InOldFiles, HasAnySymbolNames, TopLevelDecl)
634636
.bind("function"),
635637
MatchCallbacks.back().get());
636638

637639
MatchCallbacks.push_back(std::make_unique<VarDeclarationMatch>(this));
638640
Finder->addMatcher(
639-
varDecl(InOldFiles, *HasAnySymbolNames, TopLevelDecl).bind("var"),
641+
varDecl(InOldFiles, HasAnySymbolNames, TopLevelDecl).bind("var"),
640642
MatchCallbacks.back().get());
641643

642644
// Match enum definition in old.h. Enum helpers (which are defined in old.cc)
643645
// will not be moved for now no matter whether they are used or not.
644646
MatchCallbacks.push_back(std::make_unique<EnumDeclarationMatch>(this));
645647
Finder->addMatcher(
646-
enumDecl(InOldHeader, *HasAnySymbolNames, isDefinition(), TopLevelDecl)
648+
enumDecl(InOldHeader, HasAnySymbolNames, isDefinition(), TopLevelDecl)
647649
.bind("enum"),
648650
MatchCallbacks.back().get());
649651

@@ -653,7 +655,7 @@ void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
653655
MatchCallbacks.push_back(std::make_unique<TypeAliasMatch>(this));
654656
Finder->addMatcher(namedDecl(anyOf(typedefDecl().bind("typedef"),
655657
typeAliasDecl().bind("type_alias")),
656-
InOldHeader, *HasAnySymbolNames, TopLevelDecl),
658+
InOldHeader, HasAnySymbolNames, TopLevelDecl),
657659
MatchCallbacks.back().get());
658660
}
659661

clang-tools-extra/clang-query/Query.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ bool HelpQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
4646
" set traversal <kind> "
4747
"Set traversal kind of clang-query session. Available kinds are:\n"
4848
" AsIs "
49-
"Print and match the AST as clang sees it.\n"
49+
"Print and match the AST as clang sees it. This mode is the "
50+
"default.\n"
5051
" IgnoreImplicitCastsAndParentheses "
5152
"Omit implicit casts and parens in matching and dumping.\n"
5253
" IgnoreUnlessSpelledInSource "
53-
"Omit AST nodes unless spelled in the source. This mode is the "
54-
"default.\n"
54+
"Omit AST nodes unless spelled in the source.\n"
5555
" set output <feature> "
5656
"Set whether to output only <feature> content.\n"
5757
" enable output <feature> "
@@ -157,8 +157,7 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
157157
OS << "Binding for \"" << BI->first << "\":\n";
158158
const ASTContext &Ctx = AST->getASTContext();
159159
const SourceManager &SM = Ctx.getSourceManager();
160-
ASTDumper Dumper(OS, &Ctx.getCommentCommandTraits(), &SM,
161-
SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
160+
ASTDumper Dumper(OS, Ctx, SM.getDiagnostics().getShowColors());
162161
Dumper.SetTraversalKind(QS.TK);
163162
Dumper.Visit(BI->second);
164163
OS << "\n";

clang-tools-extra/clang-query/QuerySession.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class QuerySession {
2626
QuerySession(llvm::ArrayRef<std::unique_ptr<ASTUnit>> ASTs)
2727
: ASTs(ASTs), PrintOutput(false), DiagOutput(true),
2828
DetailedASTOutput(false), BindRoot(true), PrintMatcher(false),
29-
Terminate(false), TK(ast_type_traits::TK_IgnoreUnlessSpelledInSource) {}
29+
Terminate(false), TK(ast_type_traits::TK_AsIs) {}
3030

3131
llvm::ArrayRef<std::unique_ptr<ASTUnit>> ASTs;
3232

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
#include "clang/Basic/Diagnostic.h"
1515
#include "clang/Tooling/Core/Diagnostic.h"
1616
#include "llvm/ADT/DenseMap.h"
17-
18-
namespace llvm {
19-
class Regex;
20-
}
17+
#include "llvm/Support/Regex.h"
2118

2219
namespace clang {
2320

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "MisplacedWideningCastCheck.h"
3535
#include "MoveForwardingReferenceCheck.h"
3636
#include "MultipleStatementMacroCheck.h"
37+
#include "NoEscapeCheck.h"
3738
#include "NotNullTerminatedResultCheck.h"
3839
#include "ParentVirtualCallCheck.h"
3940
#include "PosixReturnCheck.h"
@@ -120,6 +121,7 @@ class BugproneModule : public ClangTidyModule {
120121
"bugprone-multiple-statement-macro");
121122
CheckFactories.registerCheck<cppcoreguidelines::NarrowingConversionsCheck>(
122123
"bugprone-narrowing-conversions");
124+
CheckFactories.registerCheck<NoEscapeCheck>("bugprone-no-escape");
123125
CheckFactories.registerCheck<NotNullTerminatedResultCheck>(
124126
"bugprone-not-null-terminated-result");
125127
CheckFactories.registerCheck<ParentVirtualCallCheck>(

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ add_clang_library(clangTidyBugproneModule
2929
MisplacedWideningCastCheck.cpp
3030
MoveForwardingReferenceCheck.cpp
3131
MultipleStatementMacroCheck.cpp
32+
NoEscapeCheck.cpp
3233
NotNullTerminatedResultCheck.cpp
3334
ParentVirtualCallCheck.cpp
3435
PosixReturnCheck.cpp

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

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/ASTMatchers/ASTMatchFinder.h"
1212
#include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
13+
#include "../utils/Aliasing.h"
1314

1415
using namespace clang::ast_matchers;
16+
using clang::tidy::utils::hasPtrOrReferenceInFunc;
1517

1618
namespace clang {
1719
namespace tidy {
@@ -24,54 +26,6 @@ loopEndingStmt(internal::Matcher<Stmt> Internal) {
2426
callExpr(Internal, callee(functionDecl(isNoReturn())))));
2527
}
2628

27-
/// Return whether `S` is a reference to the declaration of `Var`.
28-
static bool isAccessForVar(const Stmt *S, const VarDecl *Var) {
29-
if (const auto *DRE = dyn_cast<DeclRefExpr>(S))
30-
return DRE->getDecl() == Var;
31-
32-
return false;
33-
}
34-
35-
/// Return whether `Var` has a pointer or reference in `S`.
36-
static bool isPtrOrReferenceForVar(const Stmt *S, const VarDecl *Var) {
37-
if (const auto *DS = dyn_cast<DeclStmt>(S)) {
38-
for (const Decl *D : DS->getDeclGroup()) {
39-
if (const auto *LeftVar = dyn_cast<VarDecl>(D)) {
40-
if (LeftVar->hasInit() && LeftVar->getType()->isReferenceType()) {
41-
return isAccessForVar(LeftVar->getInit(), Var);
42-
}
43-
}
44-
}
45-
} else if (const auto *UnOp = dyn_cast<UnaryOperator>(S)) {
46-
if (UnOp->getOpcode() == UO_AddrOf)
47-
return isAccessForVar(UnOp->getSubExpr(), Var);
48-
}
49-
50-
return false;
51-
}
52-
53-
/// Return whether `Var` has a pointer or reference in `S`.
54-
static bool hasPtrOrReferenceInStmt(const Stmt *S, const VarDecl *Var) {
55-
if (isPtrOrReferenceForVar(S, Var))
56-
return true;
57-
58-
for (const Stmt *Child : S->children()) {
59-
if (!Child)
60-
continue;
61-
62-
if (hasPtrOrReferenceInStmt(Child, Var))
63-
return true;
64-
}
65-
66-
return false;
67-
}
68-
69-
/// Return whether `Var` has a pointer or reference in `Func`.
70-
static bool hasPtrOrReferenceInFunc(const FunctionDecl *Func,
71-
const VarDecl *Var) {
72-
return hasPtrOrReferenceInStmt(Func->getBody(), Var);
73-
}
74-
7529
/// Return whether `Var` was changed in `LoopStmt`.
7630
static bool isChanged(const Stmt *LoopStmt, const VarDecl *Var,
7731
ASTContext *Context) {

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@ namespace bugprone {
1919

2020
void MisplacedOperatorInStrlenInAllocCheck::registerMatchers(
2121
MatchFinder *Finder) {
22-
const auto StrLenFunc = functionDecl(anyOf(
23-
hasName("::strlen"), hasName("::std::strlen"), hasName("::strnlen"),
24-
hasName("::std::strnlen"), hasName("::strnlen_s"),
25-
hasName("::std::strnlen_s"), hasName("::wcslen"),
26-
hasName("::std::wcslen"), hasName("::wcsnlen"), hasName("::std::wcsnlen"),
27-
hasName("::wcsnlen_s"), hasName("std::wcsnlen_s")));
22+
const auto StrLenFunc = functionDecl(hasAnyName(
23+
"::strlen", "::std::strlen", "::strnlen", "::std::strnlen", "::strnlen_s",
24+
"::std::strnlen_s", "::wcslen", "::std::wcslen", "::wcsnlen",
25+
"::std::wcsnlen", "::wcsnlen_s", "std::wcsnlen_s"));
2826

2927
const auto BadUse =
3028
callExpr(callee(StrLenFunc),
@@ -42,12 +40,10 @@ void MisplacedOperatorInStrlenInAllocCheck::registerMatchers(
4240
hasDescendant(BadUse)),
4341
BadUse);
4442

45-
const auto Alloc0Func =
46-
functionDecl(anyOf(hasName("::malloc"), hasName("std::malloc"),
47-
hasName("::alloca"), hasName("std::alloca")));
48-
const auto Alloc1Func =
49-
functionDecl(anyOf(hasName("::calloc"), hasName("std::calloc"),
50-
hasName("::realloc"), hasName("std::realloc")));
43+
const auto Alloc0Func = functionDecl(
44+
hasAnyName("::malloc", "std::malloc", "::alloca", "std::alloca"));
45+
const auto Alloc1Func = functionDecl(
46+
hasAnyName("::calloc", "std::calloc", "::realloc", "std::realloc"));
5147

5248
const auto Alloc0FuncPtr =
5349
varDecl(hasType(isConstQualified()),

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ namespace bugprone {
1919

2020
void MisplacedPointerArithmeticInAllocCheck::registerMatchers(
2121
MatchFinder *Finder) {
22-
const auto AllocFunc = functionDecl(
23-
anyOf(hasName("::malloc"), hasName("std::malloc"), hasName("::alloca"),
24-
hasName("::calloc"), hasName("std::calloc"), hasName("::realloc"),
25-
hasName("std::realloc")));
22+
const auto AllocFunc =
23+
functionDecl(hasAnyName("::malloc", "std::malloc", "::alloca", "::calloc",
24+
"std::calloc", "::realloc", "std::realloc"));
2625

2726
const auto AllocFuncPtr =
2827
varDecl(hasType(isConstQualified()),
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//===--- NoEscapeCheck.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 "NoEscapeCheck.h"
10+
#include "clang/AST/ASTContext.h"
11+
#include "clang/ASTMatchers/ASTMatchFinder.h"
12+
13+
using namespace clang::ast_matchers;
14+
15+
namespace clang {
16+
namespace tidy {
17+
namespace bugprone {
18+
19+
void NoEscapeCheck::registerMatchers(MatchFinder *Finder) {
20+
Finder->addMatcher(callExpr(callee(functionDecl(hasName("::dispatch_async"))),
21+
argumentCountIs(2),
22+
hasArgument(1, blockExpr().bind("arg-block"))),
23+
this);
24+
Finder->addMatcher(callExpr(callee(functionDecl(hasName("::dispatch_after"))),
25+
argumentCountIs(3),
26+
hasArgument(2, blockExpr().bind("arg-block"))),
27+
this);
28+
}
29+
30+
void NoEscapeCheck::check(const MatchFinder::MatchResult &Result) {
31+
const auto *MatchedEscapingBlock =
32+
Result.Nodes.getNodeAs<BlockExpr>("arg-block");
33+
const BlockDecl *EscapingBlockDecl = MatchedEscapingBlock->getBlockDecl();
34+
for (const BlockDecl::Capture &CapturedVar : EscapingBlockDecl->captures()) {
35+
const VarDecl *Var = CapturedVar.getVariable();
36+
if (Var && Var->hasAttr<NoEscapeAttr>()) {
37+
// FIXME: Add a method to get the location of the use of a CapturedVar so
38+
// that we can diagnose the use of the pointer instead of the block.
39+
diag(MatchedEscapingBlock->getBeginLoc(),
40+
"pointer %0 with attribute 'noescape' is captured by an "
41+
"asynchronously-executed block")
42+
<< Var;
43+
diag(Var->getBeginLoc(), "the 'noescape' attribute is declared here.",
44+
DiagnosticIDs::Note);
45+
}
46+
}
47+
}
48+
49+
} // namespace bugprone
50+
} // namespace tidy
51+
} // namespace clang
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===--- NoEscapeCheck.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_NOESCAPECHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NOESCAPECHECK_H
11+
12+
#include "../ClangTidyCheck.h"
13+
14+
namespace clang {
15+
namespace tidy {
16+
namespace bugprone {
17+
18+
/// Block arguments in `dispatch_async()` and `dispatch_after()` are guaranteed
19+
/// to escape. If those blocks capture any pointers with the `noescape`
20+
/// attribute, then we warn the user of their error.
21+
///
22+
/// For the user-facing documentation see:
23+
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-no-escape.html
24+
class NoEscapeCheck : public ClangTidyCheck {
25+
public:
26+
NoEscapeCheck(StringRef Name, ClangTidyContext *Context)
27+
: ClangTidyCheck(Name, Context) {}
28+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
29+
return LangOpts.Blocks;
30+
}
31+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
32+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
33+
};
34+
35+
} // namespace bugprone
36+
} // namespace tidy
37+
} // namespace clang
38+
39+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_NOESCAPECHECK_H

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ void SpuriouslyWakeUpFunctionsCheck::registerMatchers(MatchFinder *Finder) {
5454
.bind("wait"));
5555

5656
auto hasWaitDescendantC = hasDescendant(
57-
callExpr(callee(functionDecl(
58-
anyOf(hasName("cnd_wait"), hasName("cnd_timedwait")))))
57+
callExpr(callee(functionDecl(hasAnyName("cnd_wait", "cnd_timedwait"))))
5958
.bind("wait"));
6059
if (getLangOpts().CPlusPlus) {
6160
// Check for `CON54-CPP`

0 commit comments

Comments
 (0)