Skip to content

Commit b684916

Browse files
author
Frank Laub
authored
Merge pull request #7 from plaidml/flaub-llvm-bump
Merge master into plaidml/plaidml-v1
2 parents 296e416 + 88d73ce commit b684916

File tree

7,903 files changed

+359667
-137885
lines changed

Some content is hidden

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

7,903 files changed

+359667
-137885
lines changed

.arclint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"linters": {
33
"clang-format": {
44
"type": "script-and-regex",
5-
"script-and-regex.script": "utils/arcanist/clang-format.sh",
5+
"script-and-regex.script": "bash utils/arcanist/clang-format.sh",
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)$)"

clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,14 @@ namespace abseil {
2323
// `FactoryName`, return `None`.
2424
static llvm::Optional<DurationScale>
2525
getScaleForFactory(llvm::StringRef FactoryName) {
26-
static const std::unordered_map<std::string, DurationScale> ScaleMap(
27-
{{"Nanoseconds", DurationScale::Nanoseconds},
28-
{"Microseconds", DurationScale::Microseconds},
29-
{"Milliseconds", DurationScale::Milliseconds},
30-
{"Seconds", DurationScale::Seconds},
31-
{"Minutes", DurationScale::Minutes},
32-
{"Hours", DurationScale::Hours}});
33-
34-
auto ScaleIter = ScaleMap.find(std::string(FactoryName));
35-
if (ScaleIter == ScaleMap.end())
36-
return llvm::None;
37-
38-
return ScaleIter->second;
26+
return llvm::StringSwitch<llvm::Optional<DurationScale>>(FactoryName)
27+
.Case("Nanoseconds", DurationScale::Nanoseconds)
28+
.Case("Microseconds", DurationScale::Microseconds)
29+
.Case("Milliseconds", DurationScale::Milliseconds)
30+
.Case("Seconds", DurationScale::Seconds)
31+
.Case("Minutes", DurationScale::Minutes)
32+
.Case("Hours", DurationScale::Hours)
33+
.Default(llvm::None);
3934
}
4035

4136
// Given either an integer or float literal, return its value.

clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ void StringFindStartswithCheck::registerMatchers(MatchFinder *Finder) {
5252
// Match [=!]= with a zero on one side and a string.find on the other.
5353
binaryOperator(
5454
hasAnyOperatorName("==", "!="),
55-
hasEitherOperand(ignoringParenImpCasts(ZeroLiteral)),
56-
hasEitherOperand(ignoringParenImpCasts(StringFind.bind("findexpr"))))
55+
hasOperands(ignoringParenImpCasts(ZeroLiteral),
56+
ignoringParenImpCasts(StringFind.bind("findexpr"))))
5757
.bind("expr"),
5858
this);
5959
}

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env python
22
#
3-
#===- add_new_check.py - clang-tidy check generator ----------*- python -*--===#
3+
#===- add_new_check.py - clang-tidy check generator ---------*- python -*--===#
44
#
55
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
66
# See https://llvm.org/LICENSE.txt for license information.
77
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
88
#
9-
#===------------------------------------------------------------------------===#
9+
#===-----------------------------------------------------------------------===#
1010

1111
from __future__ import print_function
1212

@@ -15,8 +15,9 @@
1515
import re
1616
import sys
1717

18-
# Adapts the module's CMakelist file. Returns 'True' if it could add a new entry
19-
# and 'False' if the entry already existed.
18+
19+
# Adapts the module's CMakelist file. Returns 'True' if it could add a new
20+
# entry and 'False' if the entry already existed.
2021
def adapt_cmake(module_path, check_name_camel):
2122
filename = os.path.join(module_path, 'CMakeLists.txt')
2223
with open(filename, 'r') as f:
@@ -172,7 +173,7 @@ def adapt_module(module_path, module, check_name, check_name_camel):
172173
lines = iter(lines)
173174
try:
174175
while True:
175-
line = lines.next()
176+
line = next(lines)
176177
if not header_added:
177178
match = re.search('#include "(.*)"', line)
178179
if match:
@@ -197,7 +198,7 @@ def adapt_module(module_path, module, check_name, check_name_camel):
197198
# If we didn't find the check name on this line, look on the
198199
# next one.
199200
prev_line = line
200-
line = lines.next()
201+
line = next(lines)
201202
match = re.search(' *"([^"]*)"', line)
202203
if match:
203204
current_check_name = match.group(1)
@@ -227,7 +228,6 @@ def add_release_notes(module_path, module, check_name):
227228
with open(filename, 'w') as f:
228229
note_added = False
229230
header_found = False
230-
next_header_found = False
231231
add_note_here = False
232232

233233
for line in lines:
@@ -241,7 +241,6 @@ def add_release_notes(module_path, module, check_name):
241241
add_note_here = True
242242

243243
if match_next:
244-
next_header_found = True
245244
add_note_here = True
246245

247246
if match:

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ using namespace clang::ast_matchers;
1919
namespace clang {
2020
namespace tidy {
2121
namespace bugprone {
22+
namespace {
23+
AST_MATCHER(Decl, isFromStdNamespace) {
24+
if (const auto *D = Node.getDeclContext()->getEnclosingNamespaceContext())
25+
return D->isStdNamespace();
26+
return false;
27+
}
28+
} // namespace
2229

2330
ArgumentCommentCheck::ArgumentCommentCheck(StringRef Name,
2431
ClangTidyContext *Context)
@@ -54,10 +61,18 @@ void ArgumentCommentCheck::registerMatchers(MatchFinder *Finder) {
5461
// don't check them against NewCallback's parameter names.
5562
// FIXME: Make this configurable.
5663
unless(hasDeclaration(functionDecl(
57-
hasAnyName("NewCallback", "NewPermanentCallback")))))
64+
hasAnyName("NewCallback", "NewPermanentCallback")))),
65+
// Ignore APIs from the standard library, since their names are
66+
// not specified by the standard, and standard library
67+
// implementations in practice have to use reserved names to
68+
// avoid conflicts with same-named macros.
69+
unless(hasDeclaration(isFromStdNamespace())))
70+
.bind("expr"),
71+
this);
72+
Finder->addMatcher(
73+
cxxConstructExpr(unless(hasDeclaration(isFromStdNamespace())))
5874
.bind("expr"),
5975
this);
60-
Finder->addMatcher(cxxConstructExpr().bind("expr"), this);
6176
}
6277

6378
static std::vector<std::pair<SourceLocation, StringRef>>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static std::string getExprAsString(const clang::Expr &E,
7676
Text.erase(
7777
llvm::remove_if(
7878
Text,
79-
[](char C) { return std::isspace(static_cast<unsigned char>(C)); }),
79+
[](char C) { return llvm::isSpace(static_cast<unsigned char>(C)); }),
8080
Text.end());
8181
return Text;
8282
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ ReservedIdentifierCheck::ReservedIdentifierCheck(StringRef Name,
4747
Options.get("AllowedIdentifiers", ""))) {}
4848

4949
void ReservedIdentifierCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
50+
RenamerClangTidyCheck::storeOptions(Opts);
5051
Options.store(Opts, "Invert", Invert);
5152
Options.store(Opts, "AllowedIdentifiers",
5253
utils::options::serializeStringList(AllowedIdentifiers));

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

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ static Matcher<TypedefDecl> hasAnyListedName(const std::string &Names) {
2929
SignedCharMisuseCheck::SignedCharMisuseCheck(StringRef Name,
3030
ClangTidyContext *Context)
3131
: ClangTidyCheck(Name, Context),
32-
CharTypdefsToIgnoreList(Options.get("CharTypdefsToIgnore", "")) {}
32+
CharTypdefsToIgnoreList(Options.get("CharTypdefsToIgnore", "")),
33+
DiagnoseSignedUnsignedCharComparisons(
34+
Options.get("DiagnoseSignedUnsignedCharComparisons", true)) {}
3335

3436
void SignedCharMisuseCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
3537
Options.store(Opts, "CharTypdefsToIgnore", CharTypdefsToIgnoreList);
38+
Options.store(Opts, "DiagnoseSignedUnsignedCharComparisons",
39+
DiagnoseSignedUnsignedCharComparisons);
3640
}
3741

3842
// Create a matcher for char -> integer cast.
@@ -92,21 +96,43 @@ void SignedCharMisuseCheck::registerMatchers(MatchFinder *Finder) {
9296

9397
Finder->addMatcher(Declaration, this);
9498

95-
// Catch signed char/unsigned char comparison.
96-
const auto CompareOperator =
97-
expr(binaryOperator(hasAnyOperatorName("==", "!="),
98-
anyOf(allOf(hasLHS(SignedCharCastExpr),
99-
hasRHS(UnSignedCharCastExpr)),
100-
allOf(hasLHS(UnSignedCharCastExpr),
101-
hasRHS(SignedCharCastExpr)))))
102-
.bind("comparison");
99+
if (DiagnoseSignedUnsignedCharComparisons) {
100+
// Catch signed char/unsigned char comparison.
101+
const auto CompareOperator =
102+
expr(binaryOperator(hasAnyOperatorName("==", "!="),
103+
anyOf(allOf(hasLHS(SignedCharCastExpr),
104+
hasRHS(UnSignedCharCastExpr)),
105+
allOf(hasLHS(UnSignedCharCastExpr),
106+
hasRHS(SignedCharCastExpr)))))
107+
.bind("comparison");
108+
109+
Finder->addMatcher(CompareOperator, this);
110+
}
111+
112+
// Catch array subscripts with signed char -> integer conversion.
113+
// Matcher for C arrays.
114+
const auto CArraySubscript =
115+
arraySubscriptExpr(hasIndex(SignedCharCastExpr)).bind("arraySubscript");
116+
117+
Finder->addMatcher(CArraySubscript, this);
103118

104-
Finder->addMatcher(CompareOperator, this);
119+
// Matcher for std arrays.
120+
const auto STDArraySubscript =
121+
cxxOperatorCallExpr(
122+
hasOverloadedOperatorName("[]"),
123+
hasArgument(0, hasType(cxxRecordDecl(hasName("::std::array")))),
124+
hasArgument(1, SignedCharCastExpr))
125+
.bind("arraySubscript");
126+
127+
Finder->addMatcher(STDArraySubscript, this);
105128
}
106129

107130
void SignedCharMisuseCheck::check(const MatchFinder::MatchResult &Result) {
108131
const auto *SignedCastExpression =
109132
Result.Nodes.getNodeAs<ImplicitCastExpr>("signedCastExpression");
133+
const auto *IntegerType = Result.Nodes.getNodeAs<QualType>("integerType");
134+
assert(SignedCastExpression);
135+
assert(IntegerType);
110136

111137
// Ignore the match if we know that the signed char's value is not negative.
112138
// The potential misinterpretation happens for negative values only.
@@ -135,14 +161,17 @@ void SignedCharMisuseCheck::check(const MatchFinder::MatchResult &Result) {
135161

136162
diag(Comparison->getBeginLoc(),
137163
"comparison between 'signed char' and 'unsigned char'");
138-
} else if (const auto *IntegerType =
139-
Result.Nodes.getNodeAs<QualType>("integerType")) {
164+
} else if (Result.Nodes.getNodeAs<Expr>("arraySubscript")) {
165+
diag(SignedCastExpression->getBeginLoc(),
166+
"'signed char' to %0 conversion in array subscript; "
167+
"consider casting to 'unsigned char' first.")
168+
<< *IntegerType;
169+
} else {
140170
diag(SignedCastExpression->getBeginLoc(),
141171
"'signed char' to %0 conversion; "
142172
"consider casting to 'unsigned char' first.")
143173
<< *IntegerType;
144-
} else
145-
llvm_unreachable("Unexpected match");
174+
}
146175
}
147176

148177
} // namespace bugprone

clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class SignedCharMisuseCheck : public ClangTidyCheck {
3838
const std::string &CastBindName) const;
3939

4040
const std::string CharTypdefsToIgnoreList;
41+
const bool DiagnoseSignedUnsignedCharComparisons;
4142
};
4243

4344
} // namespace bugprone

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
163163
if (WarnOnSizeOfCompareToConstant) {
164164
Finder->addMatcher(
165165
binaryOperator(matchers::isRelationalOperator(),
166-
hasEitherOperand(ignoringParenImpCasts(SizeOfExpr)),
167-
hasEitherOperand(ignoringParenImpCasts(
168-
anyOf(integerLiteral(equals(0)),
169-
integerLiteral(isBiggerThan(0x80000))))))
166+
hasOperands(ignoringParenImpCasts(SizeOfExpr),
167+
ignoringParenImpCasts(anyOf(
168+
integerLiteral(equals(0)),
169+
integerLiteral(isBiggerThan(0x80000))))))
170170
.bind("sizeof-compare-constant"),
171171
this);
172172
}
@@ -205,10 +205,11 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
205205

206206
Finder->addMatcher(
207207
binaryOperator(hasOperatorName("*"),
208-
hasEitherOperand(ignoringParenImpCasts(SizeOfExpr)),
209-
hasEitherOperand(ignoringParenImpCasts(binaryOperator(
210-
hasOperatorName("*"),
211-
hasEitherOperand(ignoringParenImpCasts(SizeOfExpr))))))
208+
hasOperands(ignoringParenImpCasts(SizeOfExpr),
209+
ignoringParenImpCasts(binaryOperator(
210+
hasOperatorName("*"),
211+
hasEitherOperand(
212+
ignoringParenImpCasts(SizeOfExpr))))))
212213
.bind("sizeof-multiply-sizeof"),
213214
this);
214215

@@ -232,12 +233,12 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
232233
Finder->addMatcher(
233234
binaryOperator(
234235
hasAnyOperatorName("==", "!=", "<", "<=", ">", ">=", "+", "-"),
235-
hasEitherOperand(expr(anyOf(
236-
ignoringParenImpCasts(SizeOfExpr),
237-
ignoringParenImpCasts(binaryOperator(
238-
hasOperatorName("*"),
239-
hasEitherOperand(ignoringParenImpCasts(SizeOfExpr))))))),
240-
hasEitherOperand(ignoringParenImpCasts(PtrDiffExpr)))
236+
hasOperands(expr(anyOf(ignoringParenImpCasts(SizeOfExpr),
237+
ignoringParenImpCasts(binaryOperator(
238+
hasOperatorName("*"),
239+
hasEitherOperand(
240+
ignoringParenImpCasts(SizeOfExpr)))))),
241+
ignoringParenImpCasts(PtrDiffExpr)))
241242
.bind("sizeof-in-ptr-arithmetic-mul"),
242243
this);
243244

0 commit comments

Comments
 (0)