Skip to content

Commit 0818b9e

Browse files
author
yinyangsx
committed
Merge branch 'sycl' of https://github.com/intel/llvm into sycl
2 parents 7bd6f02 + 4688cb3 commit 0818b9e

File tree

1,728 files changed

+58710
-19531
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,728 files changed

+58710
-19531
lines changed

.arclint

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"script-and-regex.regex": "/^(?P<severity>[[:alpha:]]+)\n(?P<message>[^\n]+)\n(====|(?P<line>\\d),(?P<char>\\d)\n(?P<original>.*)>>>>\n(?P<replacement>.*)<<<<\n)$/s",
77
"include": [
88
"(\\.(cc|cpp|h)$)"
9+
],
10+
"exclude": [
11+
"(^clang/test/)"
912
]
1013
}
1114
}

clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbols.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ CreateSymbolInfo(const NamedDecl *ND, const SourceManager &SM,
9999

100100
SourceLocation Loc = SM.getExpansionLoc(ND->getLocation());
101101
if (!Loc.isValid()) {
102-
llvm::errs() << "Declaration " << ND->getNameAsString() << "("
102+
llvm::errs() << "Declaration " << ND->getDeclName() << "("
103103
<< ND->getDeclKindName()
104104
<< ") has invalid declaration location.";
105105
return llvm::None;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void HelperDeclRGBuilder::run(
116116
const auto *DC = Result.Nodes.getNodeAs<Decl>("dc");
117117
assert(DC);
118118
LLVM_DEBUG(llvm::dbgs() << "Find helper function usage: "
119-
<< FuncRef->getDecl()->getNameAsString() << " ("
119+
<< FuncRef->getDecl()->getDeclName() << " ("
120120
<< FuncRef->getDecl() << ")\n");
121121
RG->addEdge(
122122
getOutmostClassOrFunDecl(DC->getCanonicalDecl()),
@@ -126,7 +126,7 @@ void HelperDeclRGBuilder::run(
126126
const auto *DC = Result.Nodes.getNodeAs<Decl>("dc");
127127
assert(DC);
128128
LLVM_DEBUG(llvm::dbgs()
129-
<< "Find helper class usage: " << UsedClass->getNameAsString()
129+
<< "Find helper class usage: " << UsedClass->getDeclName()
130130
<< " (" << UsedClass << ")\n");
131131
RG->addEdge(getOutmostClassOrFunDecl(DC->getCanonicalDecl()), UsedClass);
132132
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -675,8 +675,8 @@ void ClangMoveTool::run(const ast_matchers::MatchFinder::MatchResult &Result) {
675675
Result.Nodes.getNodeAs<NamedDecl>("helper_decls")) {
676676
MovedDecls.push_back(ND);
677677
HelperDeclarations.push_back(ND);
678-
LLVM_DEBUG(llvm::dbgs() << "Add helper : " << ND->getNameAsString() << " ("
679-
<< ND << ")\n");
678+
LLVM_DEBUG(llvm::dbgs()
679+
<< "Add helper : " << ND->getDeclName() << " (" << ND << ")\n");
680680
} else if (const auto *UD = Result.Nodes.getNodeAs<NamedDecl>("using_decl")) {
681681
MovedDecls.push_back(UD);
682682
}
@@ -735,12 +735,12 @@ void ClangMoveTool::removeDeclsInOldFiles() {
735735
// We remove the helper declarations which are not used in the old.cc after
736736
// moving the given declarations.
737737
for (const auto *D : HelperDeclarations) {
738-
LLVM_DEBUG(llvm::dbgs() << "Check helper is used: "
739-
<< D->getNameAsString() << " (" << D << ")\n");
738+
LLVM_DEBUG(llvm::dbgs() << "Check helper is used: " << D->getDeclName()
739+
<< " (" << D << ")\n");
740740
if (!UsedDecls.count(HelperDeclRGBuilder::getOutmostClassOrFunDecl(
741741
D->getCanonicalDecl()))) {
742742
LLVM_DEBUG(llvm::dbgs() << "Helper removed in old.cc: "
743-
<< D->getNameAsString() << " (" << D << ")\n");
743+
<< D->getDeclName() << " (" << D << ")\n");
744744
RemovedDecls.push_back(D);
745745
}
746746
}
@@ -820,7 +820,7 @@ void ClangMoveTool::moveDeclsToNewFiles() {
820820
D->getCanonicalDecl())))
821821
continue;
822822

823-
LLVM_DEBUG(llvm::dbgs() << "Helper used in new.cc: " << D->getNameAsString()
823+
LLVM_DEBUG(llvm::dbgs() << "Helper used in new.cc: " << D->getDeclName()
824824
<< " " << D << "\n");
825825
ActualNewCCDecls.push_back(D);
826826
}

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

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +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"
1314
#include "llvm/Support/raw_ostream.h"
1415

1516
namespace clang {
@@ -126,7 +127,7 @@ bool ClangTidyCheck::OptionsView::get<bool>(StringRef LocalName,
126127
llvm::Expected<bool> ValueOr = get<bool>(LocalName);
127128
if (ValueOr)
128129
return *ValueOr;
129-
logErrToStdErr(ValueOr.takeError());
130+
logIfOptionParsingError(ValueOr.takeError());
130131
return Default;
131132
}
132133

@@ -145,7 +146,7 @@ bool ClangTidyCheck::OptionsView::getLocalOrGlobal<bool>(StringRef LocalName,
145146
llvm::Expected<bool> ValueOr = getLocalOrGlobal<bool>(LocalName);
146147
if (ValueOr)
147148
return *ValueOr;
148-
logErrToStdErr(ValueOr.takeError());
149+
logIfOptionParsingError(ValueOr.takeError());
149150
return Default;
150151
}
151152

@@ -204,13 +205,33 @@ llvm::Expected<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
204205
Iter->getValue().Value);
205206
}
206207

207-
void ClangTidyCheck::OptionsView::logErrToStdErr(llvm::Error &&Err) {
208-
llvm::logAllUnhandledErrors(
209-
llvm::handleErrors(std::move(Err),
210-
[](const MissingOptionError &) -> llvm::Error {
211-
return llvm::Error::success();
212-
}),
213-
llvm::errs(), "warning: ");
208+
void ClangTidyCheck::OptionsView::logIfOptionParsingError(llvm::Error &&Err) {
209+
if (auto RemainingErrors =
210+
llvm::handleErrors(std::move(Err), [](const MissingOptionError &) {}))
211+
llvm::logAllUnhandledErrors(std::move(RemainingErrors),
212+
llvm::WithColor::warning());
214213
}
214+
215+
template <>
216+
Optional<std::string> ClangTidyCheck::OptionsView::getOptional<std::string>(
217+
StringRef LocalName) const {
218+
if (auto ValueOr = get(LocalName))
219+
return *ValueOr;
220+
else
221+
consumeError(ValueOr.takeError());
222+
return llvm::None;
223+
}
224+
225+
template <>
226+
Optional<std::string>
227+
ClangTidyCheck::OptionsView::getOptionalLocalOrGlobal<std::string>(
228+
StringRef LocalName) const {
229+
if (auto ValueOr = getLocalOrGlobal(LocalName))
230+
return *ValueOr;
231+
else
232+
consumeError(ValueOr.takeError());
233+
return llvm::None;
234+
}
235+
215236
} // namespace tidy
216237
} // namespace clang

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

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
268268
if (llvm::Expected<T> ValueOr = get<T>(LocalName))
269269
return *ValueOr;
270270
else
271-
logErrToStdErr(ValueOr.takeError());
271+
logIfOptionParsingError(ValueOr.takeError());
272272
return Default;
273273
}
274274

@@ -314,7 +314,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
314314
if (llvm::Expected<T> ValueOr = getLocalOrGlobal<T>(LocalName))
315315
return *ValueOr;
316316
else
317-
logErrToStdErr(ValueOr.takeError());
317+
logIfOptionParsingError(ValueOr.takeError());
318318
return Default;
319319
}
320320

@@ -353,7 +353,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
353353
if (auto ValueOr = get<T>(LocalName, IgnoreCase))
354354
return *ValueOr;
355355
else
356-
logErrToStdErr(ValueOr.takeError());
356+
logIfOptionParsingError(ValueOr.takeError());
357357
return Default;
358358
}
359359

@@ -395,10 +395,35 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
395395
if (auto ValueOr = getLocalOrGlobal<T>(LocalName, IgnoreCase))
396396
return *ValueOr;
397397
else
398-
logErrToStdErr(ValueOr.takeError());
398+
logIfOptionParsingError(ValueOr.takeError());
399399
return Default;
400400
}
401401

402+
/// Returns the value for the option \p LocalName represented as a ``T``.
403+
/// If the option is missing returns None, if the option can't be parsed
404+
/// as a ``T``, log that to stderr and return None.
405+
template <typename T = std::string>
406+
llvm::Optional<T> getOptional(StringRef LocalName) const {
407+
if (auto ValueOr = get<T>(LocalName))
408+
return *ValueOr;
409+
else
410+
logIfOptionParsingError(ValueOr.takeError());
411+
return llvm::None;
412+
}
413+
414+
/// Returns the value for the local or global option \p LocalName
415+
/// represented as a ``T``.
416+
/// If the option is missing returns None, if the
417+
/// option can't be parsed as a ``T``, log that to stderr and return None.
418+
template <typename T = std::string>
419+
llvm::Optional<T> getOptionalLocalOrGlobal(StringRef LocalName) const {
420+
if (auto ValueOr = getLocalOrGlobal<T>(LocalName))
421+
return *ValueOr;
422+
else
423+
logIfOptionParsingError(ValueOr.takeError());
424+
return llvm::None;
425+
}
426+
402427
/// Stores an option with the check-local name \p LocalName with
403428
/// string value \p Value to \p Options.
404429
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
@@ -456,7 +481,8 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
456481
void storeInt(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
457482
int64_t Value) const;
458483

459-
static void logErrToStdErr(llvm::Error &&Err);
484+
/// Logs an Error to stderr if a \p Err is not a MissingOptionError.
485+
static void logIfOptionParsingError(llvm::Error &&Err);
460486

461487
std::string NamePrefix;
462488
const ClangTidyOptions::OptionMap &CheckOptions;
@@ -524,6 +550,19 @@ void ClangTidyCheck::OptionsView::store<bool>(
524550
ClangTidyOptions::OptionMap &Options, StringRef LocalName,
525551
bool Value) const;
526552

553+
/// Returns the value for the option \p LocalName.
554+
/// If the option is missing returns None.
555+
template <>
556+
Optional<std::string> ClangTidyCheck::OptionsView::getOptional<std::string>(
557+
StringRef LocalName) const;
558+
559+
/// Returns the value for the local or global option \p LocalName.
560+
/// If the option is missing returns None.
561+
template <>
562+
Optional<std::string>
563+
ClangTidyCheck::OptionsView::getOptionalLocalOrGlobal<std::string>(
564+
StringRef LocalName) const;
565+
527566
} // namespace tidy
528567
} // namespace clang
529568

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct NOptionMap {
7070
NOptionMap(IO &, const ClangTidyOptions::OptionMap &OptionMap) {
7171
Options.reserve(OptionMap.size());
7272
for (const auto &KeyValue : OptionMap)
73-
Options.emplace_back(KeyValue.getKey(), KeyValue.getValue().Value);
73+
Options.emplace_back(std::string(KeyValue.getKey()), KeyValue.getValue().Value);
7474
}
7575
ClangTidyOptions::OptionMap denormalize(IO &) {
7676
ClangTidyOptions::OptionMap Map;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ static Preprocessor *PP;
3030

3131
void BadSignalToKillThreadCheck::check(const MatchFinder::MatchResult &Result) {
3232
const auto IsSigterm = [](const auto &KeyValue) -> bool {
33-
return KeyValue.first->getName() == "SIGTERM";
33+
return KeyValue.first->getName() == "SIGTERM" &&
34+
KeyValue.first->hasMacroDefinition();
3435
};
3536
const auto TryExpandAsInteger =
3637
[](Preprocessor::macro_iterator It) -> Optional<unsigned> {
3738
if (It == PP->macro_end())
3839
return llvm::None;
3940
const MacroInfo *MI = PP->getMacroInfo(It->first);
4041
const Token &T = MI->tokens().back();
42+
if (!T.isLiteral())
43+
return llvm::None;
4144
StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
4245

4346
llvm::APInt IntValue;

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

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,53 +20,68 @@ void BoolPointerImplicitConversionCheck::registerMatchers(MatchFinder *Finder) {
2020
Finder->addMatcher(
2121
traverse(
2222
ast_type_traits::TK_AsIs,
23-
ifStmt(hasCondition(findAll(implicitCastExpr(
24-
unless(hasParent(unaryOperator(hasOperatorName("!")))),
25-
hasSourceExpression(expr(
26-
hasType(pointerType(pointee(booleanType()))),
27-
ignoringParenImpCasts(declRefExpr().bind("expr")))),
28-
hasCastKind(CK_PointerToBoolean)))),
29-
unless(isInTemplateInstantiation()))
23+
ifStmt(
24+
hasCondition(findAll(implicitCastExpr(
25+
unless(hasParent(unaryOperator(hasOperatorName("!")))),
26+
hasSourceExpression(expr(
27+
hasType(pointerType(pointee(booleanType()))),
28+
ignoringParenImpCasts(anyOf(declRefExpr().bind("expr"),
29+
memberExpr().bind("expr"))))),
30+
hasCastKind(CK_PointerToBoolean)))),
31+
unless(isInTemplateInstantiation()))
3032
.bind("if")),
3133
this);
3234
}
3335

34-
void BoolPointerImplicitConversionCheck::check(
35-
const MatchFinder::MatchResult &Result) {
36-
auto *If = Result.Nodes.getNodeAs<IfStmt>("if");
37-
auto *Var = Result.Nodes.getNodeAs<DeclRefExpr>("expr");
38-
36+
static void checkImpl(const MatchFinder::MatchResult &Result, const Expr *Ref,
37+
const IfStmt *If,
38+
const ast_matchers::internal::Matcher<Expr> &RefMatcher,
39+
ClangTidyCheck &Check) {
3940
// Ignore macros.
40-
if (Var->getBeginLoc().isMacroID())
41+
if (Ref->getBeginLoc().isMacroID())
4142
return;
4243

43-
// Only allow variable accesses for now, no function calls or member exprs.
44+
// Only allow variable accesses and member exprs for now, no function calls.
4445
// Check that we don't dereference the variable anywhere within the if. This
4546
// avoids false positives for checks of the pointer for nullptr before it is
4647
// dereferenced. If there is a dereferencing operator on this variable don't
4748
// emit a diagnostic. Also ignore array subscripts.
48-
const Decl *D = Var->getDecl();
49-
auto DeclRef = ignoringParenImpCasts(declRefExpr(to(equalsNode(D))));
50-
if (!match(findAll(
51-
unaryOperator(hasOperatorName("*"), hasUnaryOperand(DeclRef))),
49+
if (!match(findAll(unaryOperator(hasOperatorName("*"),
50+
hasUnaryOperand(RefMatcher))),
5251
*If, *Result.Context)
5352
.empty() ||
54-
!match(findAll(arraySubscriptExpr(hasBase(DeclRef))), *If,
53+
!match(findAll(arraySubscriptExpr(hasBase(RefMatcher))), *If,
5554
*Result.Context)
5655
.empty() ||
5756
// FIXME: We should still warn if the paremater is implicitly converted to
5857
// bool.
59-
!match(findAll(callExpr(hasAnyArgument(ignoringParenImpCasts(DeclRef)))),
60-
*If, *Result.Context)
58+
!match(
59+
findAll(callExpr(hasAnyArgument(ignoringParenImpCasts(RefMatcher)))),
60+
*If, *Result.Context)
6161
.empty() ||
62-
!match(findAll(cxxDeleteExpr(has(ignoringParenImpCasts(expr(DeclRef))))),
63-
*If, *Result.Context)
62+
!match(
63+
findAll(cxxDeleteExpr(has(ignoringParenImpCasts(expr(RefMatcher))))),
64+
*If, *Result.Context)
6465
.empty())
6566
return;
6667

67-
diag(Var->getBeginLoc(), "dubious check of 'bool *' against 'nullptr', did "
68-
"you mean to dereference it?")
69-
<< FixItHint::CreateInsertion(Var->getBeginLoc(), "*");
68+
Check.diag(Ref->getBeginLoc(),
69+
"dubious check of 'bool *' against 'nullptr', did "
70+
"you mean to dereference it?")
71+
<< FixItHint::CreateInsertion(Ref->getBeginLoc(), "*");
72+
}
73+
74+
void BoolPointerImplicitConversionCheck::check(
75+
const MatchFinder::MatchResult &Result) {
76+
const auto *If = Result.Nodes.getNodeAs<IfStmt>("if");
77+
if (const auto *E = Result.Nodes.getNodeAs<Expr>("expr")) {
78+
const Decl *D = isa<DeclRefExpr>(E) ? cast<DeclRefExpr>(E)->getDecl()
79+
: cast<MemberExpr>(E)->getMemberDecl();
80+
const auto M =
81+
ignoringParenImpCasts(anyOf(declRefExpr(to(equalsNode(D))),
82+
memberExpr(hasDeclaration(equalsNode(D)))));
83+
checkImpl(Result, E, If, M, *this);
84+
}
7085
}
7186

7287
} // namespace bugprone

0 commit comments

Comments
 (0)