Skip to content

Commit 86f4ba3

Browse files
committed
Resolving merge conflicts
Signed-off-by: Gail Lyons <gail.lyons@intel.com>
2 parents e96a951 + 06f667a commit 86f4ba3

File tree

3,221 files changed

+108219
-42276
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,221 files changed

+108219
-42276
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-change-namespace/ChangeNamespace.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,8 @@ namespace change_namespace {
1919

2020
namespace {
2121

22-
inline std::string
23-
joinNamespaces(const llvm::SmallVectorImpl<StringRef> &Namespaces) {
24-
if (Namespaces.empty())
25-
return "";
26-
std::string Result(Namespaces.front());
27-
for (auto I = Namespaces.begin() + 1, E = Namespaces.end(); I != E; ++I)
28-
Result += ("::" + *I).str();
29-
return Result;
22+
inline std::string joinNamespaces(ArrayRef<StringRef> Namespaces) {
23+
return llvm::join(Namespaces, "::");
3024
}
3125

3226
// Given "a::b::c", returns {"a", "b", "c"}.

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/ClangTidyCheck.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,25 @@ ClangTidyCheck::OptionsView::get(StringRef LocalName) const {
7676
return llvm::make_error<MissingOptionError>((NamePrefix + LocalName).str());
7777
}
7878

79+
static ClangTidyOptions::OptionMap::const_iterator
80+
findPriorityOption(const ClangTidyOptions::OptionMap &Options, StringRef NamePrefix,
81+
StringRef LocalName) {
82+
auto IterLocal = Options.find((NamePrefix + LocalName).str());
83+
auto IterGlobal = Options.find(LocalName.str());
84+
if (IterLocal == Options.end())
85+
return IterGlobal;
86+
if (IterGlobal == Options.end())
87+
return IterLocal;
88+
if (IterLocal->second.Priority >= IterGlobal->second.Priority)
89+
return IterLocal;
90+
return IterGlobal;
91+
}
92+
7993
llvm::Expected<std::string>
8094
ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef LocalName) const {
81-
auto IterLocal = CheckOptions.find(NamePrefix + LocalName.str());
82-
auto IterGlobal = CheckOptions.find(LocalName.str());
83-
if (IterLocal != CheckOptions.end() &&
84-
(IterGlobal == CheckOptions.end() ||
85-
IterLocal->second.Priority >= IterGlobal->second.Priority))
86-
return IterLocal->second.Value;
87-
if (IterGlobal != CheckOptions.end())
88-
return IterGlobal->second.Value;
95+
auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName);
96+
if (Iter != CheckOptions.end())
97+
return Iter->second.Value;
8998
return llvm::make_error<MissingOptionError>((NamePrefix + LocalName).str());
9099
}
91100

@@ -124,14 +133,9 @@ bool ClangTidyCheck::OptionsView::get<bool>(StringRef LocalName,
124133
template <>
125134
llvm::Expected<bool>
126135
ClangTidyCheck::OptionsView::getLocalOrGlobal<bool>(StringRef LocalName) const {
127-
auto IterLocal = CheckOptions.find(NamePrefix + LocalName.str());
128-
auto IterGlobal = CheckOptions.find(LocalName.str());
129-
if (IterLocal != CheckOptions.end() &&
130-
(IterGlobal == CheckOptions.end() ||
131-
IterLocal->second.Priority >= IterGlobal->second.Priority))
132-
return getAsBool(IterLocal->second.Value, NamePrefix + LocalName);
133-
if (IterGlobal != CheckOptions.end())
134-
return getAsBool(IterGlobal->second.Value, llvm::Twine(LocalName));
136+
auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName);
137+
if (Iter != CheckOptions.end())
138+
return getAsBool(Iter->second.Value, Iter->first);
135139
return llvm::make_error<MissingOptionError>((NamePrefix + LocalName).str());
136140
}
137141

@@ -160,9 +164,8 @@ void ClangTidyCheck::OptionsView::store(ClangTidyOptions::OptionMap &Options,
160164
llvm::Expected<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
161165
StringRef LocalName, ArrayRef<std::pair<StringRef, int64_t>> Mapping,
162166
bool CheckGlobal, bool IgnoreCase) {
163-
auto Iter = CheckOptions.find((NamePrefix + LocalName).str());
164-
if (CheckGlobal && Iter == CheckOptions.end())
165-
Iter = CheckOptions.find(LocalName.str());
167+
auto Iter = CheckGlobal ? findPriorityOption(CheckOptions, NamePrefix, LocalName)
168+
: CheckOptions.find((NamePrefix + LocalName).str());
166169
if (Iter == CheckOptions.end())
167170
return llvm::make_error<MissingOptionError>((NamePrefix + LocalName).str());
168171

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()),

0 commit comments

Comments
 (0)