Skip to content

Commit 02dd118

Browse files
author
Vyacheslav Zakharin
committed
Merge from 'master' to 'sycl-web' (#7)
CONFLICT (content): Merge conflict in clang/test/Preprocessor/predefined-macros.c
2 parents 2606290 + 3a1b075 commit 02dd118

File tree

3,491 files changed

+45162
-17362
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,491 files changed

+45162
-17362
lines changed

clang-tools-extra/clang-query/tool/ClangQuery.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "llvm/Support/CommandLine.h"
3636
#include "llvm/Support/MemoryBuffer.h"
3737
#include "llvm/Support/Signals.h"
38+
#include "llvm/Support/WithColor.h"
3839
#include <fstream>
3940
#include <string>
4041

@@ -86,7 +87,14 @@ bool runCommandsInFile(const char *ExeName, std::string const &FileName,
8687
int main(int argc, const char **argv) {
8788
llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
8889

89-
CommonOptionsParser OptionsParser(argc, argv, ClangQueryCategory);
90+
llvm::Expected<CommonOptionsParser> OptionsParser =
91+
CommonOptionsParser::create(argc, argv, ClangQueryCategory,
92+
llvm::cl::OneOrMore);
93+
94+
if (!OptionsParser) {
95+
llvm::WithColor::error() << llvm::toString(OptionsParser.takeError());
96+
return 1;
97+
}
9098

9199
if (!Commands.empty() && !CommandFiles.empty()) {
92100
llvm::errs() << argv[0] << ": cannot specify both -c and -f\n";
@@ -99,8 +107,8 @@ int main(int argc, const char **argv) {
99107
return 1;
100108
}
101109

102-
ClangTool Tool(OptionsParser.getCompilations(),
103-
OptionsParser.getSourcePathList());
110+
ClangTool Tool(OptionsParser->getCompilations(),
111+
OptionsParser->getSourcePathList());
104112
std::vector<std::unique_ptr<ASTUnit>> ASTs;
105113
int Status = Tool.buildASTs(ASTs);
106114
int ASTStatus = 0;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ void ProTypeMemberInitCheck::checkMissingMemberInitializer(
454454
return;
455455
// Don't suggest fixes for enums because we don't know a good default.
456456
// Don't suggest fixes for bitfields because in-class initialization is not
457-
// possible until C++2a.
457+
// possible until C++20.
458458
if (F->getType()->isEnumeralType() ||
459459
(!getLangOpts().CPlusPlus20 && F->isBitField()))
460460
return;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ void NonPrivateMemberVariablesInClassesCheck::registerMatchers(
5959
// If we are ok with public fields, then we only want to complain about
6060
// protected fields, else we want to complain about all non-private fields.
6161
// We can ignore public member variables in structs/classes, in unions.
62-
auto InterestingField = fieldDecl(
63-
IgnorePublicMemberVariables ? isProtected() : unless(isPrivate()));
62+
auto InterestingField = IgnorePublicMemberVariables
63+
? fieldDecl(isProtected())
64+
: fieldDecl(unless(isPrivate()));
6465

6566
// We only want the records that not only contain the mutable data (non-static
6667
// member variables), but also have some logic (non-static, non-implicit

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ add_clang_library(clangTidyReadabilityModule
4242
StringCompareCheck.cpp
4343
UniqueptrDeleteReleaseCheck.cpp
4444
UppercaseLiteralSuffixCheck.cpp
45+
UseAnyOfAllOfCheck.cpp
4546

4647
LINK_LIBS
48+
clangAnalysis
4749
clangAST
4850
clangASTMatchers
4951
clangBasic

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "StringCompareCheck.h"
4646
#include "UniqueptrDeleteReleaseCheck.h"
4747
#include "UppercaseLiteralSuffixCheck.h"
48+
#include "UseAnyOfAllOfCheck.h"
4849

4950
namespace clang {
5051
namespace tidy {
@@ -125,6 +126,8 @@ class ReadabilityModule : public ClangTidyModule {
125126
"readability-uniqueptr-delete-release");
126127
CheckFactories.registerCheck<UppercaseLiteralSuffixCheck>(
127128
"readability-uppercase-literal-suffix");
129+
CheckFactories.registerCheck<UseAnyOfAllOfCheck>(
130+
"readability-use-anyofallof");
128131
}
129132
};
130133

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
//===--- UseAnyOfAllOfCheck.cpp - clang-tidy-------------------------------===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#include "UseAnyOfAllOfCheck.h"
11+
#include "clang/AST/ASTContext.h"
12+
#include "clang/ASTMatchers/ASTMatchFinder.h"
13+
#include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
14+
#include "clang/Frontend/CompilerInstance.h"
15+
16+
using namespace clang::ast_matchers;
17+
18+
namespace clang {
19+
namespace {
20+
/// Matches a Stmt whose parent is a CompoundStmt, and which is directly
21+
/// followed by a Stmt matching the inner matcher.
22+
AST_MATCHER_P(Stmt, nextStmt, ast_matchers::internal::Matcher<Stmt>,
23+
InnerMatcher) {
24+
DynTypedNodeList Parents = Finder->getASTContext().getParents(Node);
25+
if (Parents.size() != 1)
26+
return false;
27+
28+
auto *C = Parents[0].get<CompoundStmt>();
29+
if (!C)
30+
return false;
31+
32+
const auto *I = llvm::find(C->body(), &Node);
33+
assert(I != C->body_end() && "C is parent of Node");
34+
if (++I == C->body_end())
35+
return false; // Node is last statement.
36+
37+
return InnerMatcher.matches(**I, Finder, Builder);
38+
}
39+
} // namespace
40+
41+
namespace tidy {
42+
namespace readability {
43+
44+
void UseAnyOfAllOfCheck::registerMatchers(MatchFinder *Finder) {
45+
auto returns = [](bool V) {
46+
return returnStmt(hasReturnValue(cxxBoolLiteral(equals(V))));
47+
};
48+
49+
auto returnsButNotTrue =
50+
returnStmt(hasReturnValue(unless(cxxBoolLiteral(equals(true)))));
51+
auto returnsButNotFalse =
52+
returnStmt(hasReturnValue(unless(cxxBoolLiteral(equals(false)))));
53+
54+
Finder->addMatcher(
55+
cxxForRangeStmt(
56+
nextStmt(returns(false).bind("final_return")),
57+
hasBody(allOf(hasDescendant(returns(true)),
58+
unless(anyOf(hasDescendant(breakStmt()),
59+
hasDescendant(gotoStmt()),
60+
hasDescendant(returnsButNotTrue))))))
61+
.bind("any_of_loop"),
62+
this);
63+
64+
Finder->addMatcher(
65+
cxxForRangeStmt(
66+
nextStmt(returns(true).bind("final_return")),
67+
hasBody(allOf(hasDescendant(returns(false)),
68+
unless(anyOf(hasDescendant(breakStmt()),
69+
hasDescendant(gotoStmt()),
70+
hasDescendant(returnsButNotFalse))))))
71+
.bind("all_of_loop"),
72+
this);
73+
}
74+
75+
static bool isViableLoop(const CXXForRangeStmt &S, ASTContext &Context) {
76+
77+
ExprMutationAnalyzer Mutations(*S.getBody(), Context);
78+
if (Mutations.isMutated(S.getLoopVariable()))
79+
return false;
80+
const auto Matches =
81+
match(findAll(declRefExpr().bind("decl_ref")), *S.getBody(), Context);
82+
83+
return llvm::none_of(Matches, [&Mutations](auto &DeclRef) {
84+
// TODO: allow modifications of loop-local variables
85+
return Mutations.isMutated(
86+
DeclRef.template getNodeAs<DeclRefExpr>("decl_ref")->getDecl());
87+
});
88+
}
89+
90+
void UseAnyOfAllOfCheck::check(const MatchFinder::MatchResult &Result) {
91+
StringRef Ranges = getLangOpts().CPlusPlus20 ? "::ranges" : "";
92+
93+
if (const auto *S = Result.Nodes.getNodeAs<CXXForRangeStmt>("any_of_loop")) {
94+
if (!isViableLoop(*S, *Result.Context))
95+
return;
96+
97+
diag(S->getForLoc(), "replace loop by 'std%0::any_of()'") << Ranges;
98+
} else if (const auto *S =
99+
Result.Nodes.getNodeAs<CXXForRangeStmt>("all_of_loop")) {
100+
if (!isViableLoop(*S, *Result.Context))
101+
return;
102+
103+
diag(S->getForLoc(), "replace loop by 'std%0::all_of()'") << Ranges;
104+
}
105+
}
106+
107+
} // namespace readability
108+
} // namespace tidy
109+
} // namespace clang
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//===--- UseAnyOfAllOfCheck.h - clang-tidy-----------------------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_USEALGORITHMCHECK_H
11+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_USEALGORITHMCHECK_H
12+
13+
#include "../ClangTidy.h"
14+
#include "../utils/IncludeInserter.h"
15+
16+
namespace clang {
17+
namespace tidy {
18+
namespace readability {
19+
20+
/// Finds ranged-based for loops that can be replaced by a call to std::any_of
21+
/// or std::all_of.
22+
///
23+
/// For the user-facing documentation see:
24+
/// http://clang.llvm.org/extra/clang-tidy/checks/readability-use-anyofallof.html
25+
class UseAnyOfAllOfCheck : public ClangTidyCheck {
26+
public:
27+
using ClangTidyCheck::ClangTidyCheck;
28+
29+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
30+
return LangOpts.CPlusPlus11;
31+
}
32+
33+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
34+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
35+
};
36+
37+
} // namespace readability
38+
} // namespace tidy
39+
} // namespace clang
40+
41+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_USEALGORITHMCHECK_H

clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "llvm/Support/Process.h"
2424
#include "llvm/Support/Signals.h"
2525
#include "llvm/Support/TargetSelect.h"
26+
#include "llvm/Support/WithColor.h"
2627

2728
using namespace clang::ast_matchers;
2829
using namespace clang::driver;
@@ -333,8 +334,14 @@ getVfsFromFile(const std::string &OverlayFile,
333334

334335
int clangTidyMain(int argc, const char **argv) {
335336
llvm::InitLLVM X(argc, argv);
336-
CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory,
337-
cl::ZeroOrMore);
337+
llvm::Expected<CommonOptionsParser> OptionsParser =
338+
CommonOptionsParser::create(argc, argv, ClangTidyCategory,
339+
cl::ZeroOrMore);
340+
if (!OptionsParser) {
341+
llvm::WithColor::error() << llvm::toString(OptionsParser.takeError());
342+
return 1;
343+
}
344+
338345
llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> BaseFS(
339346
new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
340347

@@ -365,7 +372,7 @@ int clangTidyMain(int argc, const char **argv) {
365372
SmallString<256> ProfilePrefix = MakeAbsolute(StoreCheckProfile);
366373

367374
StringRef FileName("dummy");
368-
auto PathList = OptionsParser.getSourcePathList();
375+
auto PathList = OptionsParser->getSourcePathList();
369376
if (!PathList.empty()) {
370377
FileName = PathList.front();
371378
}
@@ -433,7 +440,7 @@ int clangTidyMain(int argc, const char **argv) {
433440
ClangTidyContext Context(std::move(OwningOptionsProvider),
434441
AllowEnablingAnalyzerAlphaCheckers);
435442
std::vector<ClangTidyError> Errors =
436-
runClangTidy(Context, OptionsParser.getCompilations(), PathList, BaseFS,
443+
runClangTidy(Context, OptionsParser->getCompilations(), PathList, BaseFS,
437444
EnableCheckProfile, ProfilePrefix);
438445
bool FoundErrors = llvm::find_if(Errors, [](const ClangTidyError &E) {
439446
return E.DiagLevel == ClangTidyError::Error;

clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ class RenamerClangTidyCheckPPCallbacks : public PPCallbacks {
7373
/// MacroDefined calls checkMacro for macros in the main file
7474
void MacroDefined(const Token &MacroNameTok,
7575
const MacroDirective *MD) override {
76+
if (MD->getMacroInfo()->isBuiltinMacro())
77+
return;
78+
if (PP->getSourceManager().isWrittenInBuiltinFile(
79+
MacroNameTok.getLocation()))
80+
return;
81+
if (PP->getSourceManager().isWrittenInCommandLineFile(
82+
MacroNameTok.getLocation()))
83+
return;
7684
Check->checkMacro(PP->getSourceManager(), MacroNameTok, MD->getMacroInfo());
7785
}
7886

clang-tools-extra/clangd/ParsedAST.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ class ReplayPreamble : private PPCallbacks {
116116
// Attach preprocessor hooks such that preamble events will be injected at
117117
// the appropriate time.
118118
// Events will be delivered to the *currently registered* PP callbacks.
119-
static void attach(const IncludeStructure &Includes, CompilerInstance &Clang,
119+
static void attach(std::vector<Inclusion> Includes, CompilerInstance &Clang,
120120
const PreambleBounds &PB) {
121121
auto &PP = Clang.getPreprocessor();
122122
auto *ExistingCallbacks = PP.getPPCallbacks();
123123
// No need to replay events if nobody is listening.
124124
if (!ExistingCallbacks)
125125
return;
126126
PP.addPPCallbacks(std::unique_ptr<PPCallbacks>(new ReplayPreamble(
127-
Includes, ExistingCallbacks, Clang.getSourceManager(), PP,
127+
std::move(Includes), ExistingCallbacks, Clang.getSourceManager(), PP,
128128
Clang.getLangOpts(), PB)));
129129
// We're relying on the fact that addPPCallbacks keeps the old PPCallbacks
130130
// around, creating a chaining wrapper. Guard against other implementations.
@@ -133,10 +133,10 @@ class ReplayPreamble : private PPCallbacks {
133133
}
134134

135135
private:
136-
ReplayPreamble(const IncludeStructure &Includes, PPCallbacks *Delegate,
136+
ReplayPreamble(std::vector<Inclusion> Includes, PPCallbacks *Delegate,
137137
const SourceManager &SM, Preprocessor &PP,
138138
const LangOptions &LangOpts, const PreambleBounds &PB)
139-
: Includes(Includes), Delegate(Delegate), SM(SM), PP(PP) {
139+
: Includes(std::move(Includes)), Delegate(Delegate), SM(SM), PP(PP) {
140140
// Only tokenize the preamble section of the main file, as we are not
141141
// interested in the rest of the tokens.
142142
MainFileTokens = syntax::tokenize(
@@ -167,7 +167,7 @@ class ReplayPreamble : private PPCallbacks {
167167
}
168168

169169
void replay() {
170-
for (const auto &Inc : Includes.MainFileIncludes) {
170+
for (const auto &Inc : Includes) {
171171
const FileEntry *File = nullptr;
172172
if (Inc.Resolved != "")
173173
if (auto FE = SM.getFileManager().getFile(Inc.Resolved))
@@ -227,7 +227,7 @@ class ReplayPreamble : private PPCallbacks {
227227
}
228228
}
229229

230-
const IncludeStructure &Includes;
230+
const std::vector<Inclusion> Includes;
231231
PPCallbacks *Delegate;
232232
const SourceManager &SM;
233233
Preprocessor &PP;
@@ -382,7 +382,8 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
382382
Includes = Preamble->Includes;
383383
Includes.MainFileIncludes = Patch->preambleIncludes();
384384
// Replay the preamble includes so that clang-tidy checks can see them.
385-
ReplayPreamble::attach(Includes, *Clang, Preamble->Preamble.getBounds());
385+
ReplayPreamble::attach(Patch->preambleIncludes(), *Clang,
386+
Preamble->Preamble.getBounds());
386387
}
387388
// Important: collectIncludeStructure is registered *after* ReplayPreamble!
388389
// Otherwise we would collect the replayed includes again...

clang-tools-extra/clangd/index/FileIndex.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ FileShardedIndex::getShard(llvm::StringRef Uri) const {
201201
RelB.insert(*Rel);
202202
}
203203
IF.Relations = std::move(RelB).build();
204-
return IF;
204+
// Explicit move here is needed by some compilers.
205+
return std::move(IF);
205206
}
206207

207208
SlabTuple indexMainDecls(ParsedAST &AST) {

clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ TEST_F(DocumentSymbolsTest, DeclarationDefinition) {
441441
}
442442

443443
TEST_F(DocumentSymbolsTest, Concepts) {
444-
CDB.ExtraClangFlags = {"-std=c++2a"};
444+
CDB.ExtraClangFlags = {"-std=c++20"};
445445
std::string FilePath = testPath("foo.cpp");
446446
addFile(FilePath,
447447
"template <typename T> concept C = requires(T t) { t.foo(); };");

clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ TEST_F(TargetDeclTest, Concept) {
401401
t.foo();
402402
}
403403
)cpp";
404-
Flags.push_back("-std=c++2a");
404+
Flags.push_back("-std=c++20");
405405
EXPECT_DECLS(
406406
"ConceptSpecializationExpr",
407407
// FIXME: Should we truncate the pretty-printed form of a concept decl
@@ -642,7 +642,7 @@ class FindExplicitReferencesTest : public ::testing::Test {
642642
// FIXME: Auto-completion in a template requires disabling delayed template
643643
// parsing.
644644
TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
645-
TU.ExtraArgs.push_back("-std=c++2a");
645+
TU.ExtraArgs.push_back("-std=c++20");
646646
TU.ExtraArgs.push_back("-xobjective-c++");
647647

648648
auto AST = TU.build();

0 commit comments

Comments
 (0)