Skip to content

Commit 5c92a0d

Browse files
committed
Merged master:b1a7a245ec2 into amd-gfx:08dd4e64e34
Local branch amd-gfx 08dd4e6 Merged master:7b74b0d4e54 into amd-gfx:46601da50bc Remote branch master b1a7a24 [NFC][MC] Rename alignBranches* to emitInstruction* Change-Id: Icb9cc815b8e5e8043d602f625a8f8743d50cee3c
2 parents 4f0a0d6 + b1a7a24 commit 5c92a0d

File tree

1,921 files changed

+17344
-9445
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,921 files changed

+17344
-9445
lines changed

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

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,22 @@ void DurationUnnecessaryConversionCheck::registerMatchers(MatchFinder *Finder) {
5252
callee(functionDecl(hasName("::absl::FDivDuration"))),
5353
hasArgument(0, expr().bind("arg")), hasArgument(1, factory_matcher));
5454

55+
// Matcher which matches a duration argument being scaled,
56+
// e.g. `absl::ToDoubleSeconds(dur) * 2`
57+
auto scalar_matcher = ignoringImpCasts(
58+
binaryOperator(hasOperatorName("*"),
59+
hasEitherOperand(expr(ignoringParenImpCasts(
60+
callExpr(callee(functionDecl(hasAnyName(
61+
FloatConversion, IntegerConversion))),
62+
hasArgument(0, expr().bind("arg")))
63+
.bind("inner_call")))))
64+
.bind("binop"));
65+
5566
Finder->addMatcher(
5667
callExpr(callee(functionDecl(hasName(DurationFactory))),
5768
hasArgument(0, anyOf(inverse_function_matcher,
58-
division_operator_matcher, fdiv_matcher)))
69+
division_operator_matcher, fdiv_matcher,
70+
scalar_matcher)))
5971
.bind("call"),
6072
this);
6173
}
@@ -64,16 +76,41 @@ void DurationUnnecessaryConversionCheck::registerMatchers(MatchFinder *Finder) {
6476
void DurationUnnecessaryConversionCheck::check(
6577
const MatchFinder::MatchResult &Result) {
6678
const auto *OuterCall = Result.Nodes.getNodeAs<Expr>("call");
67-
const auto *Arg = Result.Nodes.getNodeAs<Expr>("arg");
6879

6980
if (isInMacro(Result, OuterCall))
7081
return;
7182

83+
FixItHint Hint;
84+
if (const auto *Binop = Result.Nodes.getNodeAs<BinaryOperator>("binop")) {
85+
const auto *Arg = Result.Nodes.getNodeAs<Expr>("arg");
86+
const auto *InnerCall = Result.Nodes.getNodeAs<Expr>("inner_call");
87+
const Expr *LHS = Binop->getLHS();
88+
const Expr *RHS = Binop->getRHS();
89+
90+
if (LHS->IgnoreParenImpCasts() == InnerCall) {
91+
Hint = FixItHint::CreateReplacement(
92+
OuterCall->getSourceRange(),
93+
(llvm::Twine(tooling::fixit::getText(*Arg, *Result.Context)) + " * " +
94+
tooling::fixit::getText(*RHS, *Result.Context))
95+
.str());
96+
} else {
97+
assert(RHS->IgnoreParenImpCasts() == InnerCall &&
98+
"Inner call should be find on the RHS");
99+
100+
Hint = FixItHint::CreateReplacement(
101+
OuterCall->getSourceRange(),
102+
(llvm::Twine(tooling::fixit::getText(*LHS, *Result.Context)) + " * " +
103+
tooling::fixit::getText(*Arg, *Result.Context))
104+
.str());
105+
}
106+
} else if (const auto *Arg = Result.Nodes.getNodeAs<Expr>("arg")) {
107+
Hint = FixItHint::CreateReplacement(
108+
OuterCall->getSourceRange(),
109+
tooling::fixit::getText(*Arg, *Result.Context));
110+
}
72111
diag(OuterCall->getBeginLoc(),
73112
"remove unnecessary absl::Duration conversions")
74-
<< FixItHint::CreateReplacement(
75-
OuterCall->getSourceRange(),
76-
tooling::fixit::getText(*Arg, *Result.Context));
113+
<< Hint;
77114
}
78115

79116
} // namespace abseil

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

Lines changed: 79 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ namespace clang {
1818
namespace tidy {
1919
namespace bugprone {
2020

21+
static constexpr int UnsignedASCIIUpperBound = 127;
22+
2123
static Matcher<TypedefDecl> hasAnyListedName(const std::string &Names) {
2224
const std::vector<std::string> NameList =
2325
utils::options::parseStringList(Names);
@@ -33,70 +35,114 @@ void SignedCharMisuseCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
3335
Options.store(Opts, "CharTypdefsToIgnore", CharTypdefsToIgnoreList);
3436
}
3537

36-
void SignedCharMisuseCheck::registerMatchers(MatchFinder *Finder) {
38+
// Create a matcher for char -> integer cast.
39+
BindableMatcher<clang::Stmt> SignedCharMisuseCheck::charCastExpression(
40+
bool IsSigned, const Matcher<clang::QualType> &IntegerType,
41+
const std::string &CastBindName) const {
3742
// We can ignore typedefs which are some kind of integer types
3843
// (e.g. typedef char sal_Int8). In this case, we don't need to
3944
// worry about the misinterpretation of char values.
4045
const auto IntTypedef = qualType(
4146
hasDeclaration(typedefDecl(hasAnyListedName(CharTypdefsToIgnoreList))));
4247

43-
const auto SignedCharType = expr(hasType(qualType(
44-
allOf(isAnyCharacter(), isSignedInteger(), unless(IntTypedef)))));
45-
46-
const auto IntegerType = qualType(allOf(isInteger(), unless(isAnyCharacter()),
47-
unless(booleanType())))
48-
.bind("integerType");
48+
auto CharTypeExpr = expr();
49+
if (IsSigned) {
50+
CharTypeExpr = expr(hasType(
51+
qualType(isAnyCharacter(), isSignedInteger(), unless(IntTypedef))));
52+
} else {
53+
CharTypeExpr = expr(hasType(qualType(
54+
isAnyCharacter(), unless(isSignedInteger()), unless(IntTypedef))));
55+
}
4956

50-
// We are interested in signed char -> integer conversion.
5157
const auto ImplicitCastExpr =
52-
implicitCastExpr(hasSourceExpression(SignedCharType),
58+
implicitCastExpr(hasSourceExpression(CharTypeExpr),
5359
hasImplicitDestinationType(IntegerType))
54-
.bind("castExpression");
60+
.bind(CastBindName);
5561

5662
const auto CStyleCastExpr = cStyleCastExpr(has(ImplicitCastExpr));
5763
const auto StaticCastExpr = cxxStaticCastExpr(has(ImplicitCastExpr));
5864
const auto FunctionalCastExpr = cxxFunctionalCastExpr(has(ImplicitCastExpr));
5965

6066
// We catch any type of casts to an integer. We need to have these cast
6167
// expressions explicitly to catch only those casts which are direct children
62-
// of an assignment/declaration.
63-
const auto CastExpr = expr(anyOf(ImplicitCastExpr, CStyleCastExpr,
64-
StaticCastExpr, FunctionalCastExpr));
68+
// of the checked expressions. (e.g. assignment, declaration).
69+
return expr(anyOf(ImplicitCastExpr, CStyleCastExpr, StaticCastExpr,
70+
FunctionalCastExpr));
71+
}
6572

66-
// Catch assignments with the suspicious type conversion.
67-
const auto AssignmentOperatorExpr = expr(binaryOperator(
68-
hasOperatorName("="), hasLHS(hasType(IntegerType)), hasRHS(CastExpr)));
73+
void SignedCharMisuseCheck::registerMatchers(MatchFinder *Finder) {
74+
const auto IntegerType =
75+
qualType(isInteger(), unless(isAnyCharacter()), unless(booleanType()))
76+
.bind("integerType");
77+
const auto SignedCharCastExpr =
78+
charCastExpression(true, IntegerType, "signedCastExpression");
79+
const auto UnSignedCharCastExpr =
80+
charCastExpression(false, IntegerType, "unsignedCastExpression");
81+
82+
// Catch assignments with singed char -> integer conversion.
83+
const auto AssignmentOperatorExpr =
84+
expr(binaryOperator(hasOperatorName("="), hasLHS(hasType(IntegerType)),
85+
hasRHS(SignedCharCastExpr)));
6986

7087
Finder->addMatcher(AssignmentOperatorExpr, this);
7188

72-
// Catch declarations with the suspicious type conversion.
73-
const auto Declaration =
74-
varDecl(isDefinition(), hasType(IntegerType), hasInitializer(CastExpr));
89+
// Catch declarations with singed char -> integer conversion.
90+
const auto Declaration = varDecl(isDefinition(), hasType(IntegerType),
91+
hasInitializer(SignedCharCastExpr));
7592

7693
Finder->addMatcher(Declaration, this);
94+
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");
103+
104+
Finder->addMatcher(CompareOperator, this);
77105
}
78106

79107
void SignedCharMisuseCheck::check(const MatchFinder::MatchResult &Result) {
80-
const auto *CastExpression =
81-
Result.Nodes.getNodeAs<ImplicitCastExpr>("castExpression");
82-
const auto *IntegerType = Result.Nodes.getNodeAs<QualType>("integerType");
83-
assert(CastExpression);
84-
assert(IntegerType);
108+
const auto *SignedCastExpression =
109+
Result.Nodes.getNodeAs<ImplicitCastExpr>("signedCastExpression");
85110

86-
// Ignore the match if we know that the value is not negative.
111+
// Ignore the match if we know that the signed char's value is not negative.
87112
// The potential misinterpretation happens for negative values only.
88113
Expr::EvalResult EVResult;
89-
if (!CastExpression->isValueDependent() &&
90-
CastExpression->getSubExpr()->EvaluateAsInt(EVResult, *Result.Context)) {
91-
llvm::APSInt Value1 = EVResult.Val.getInt();
92-
if (Value1.isNonNegative())
114+
if (!SignedCastExpression->isValueDependent() &&
115+
SignedCastExpression->getSubExpr()->EvaluateAsInt(EVResult,
116+
*Result.Context)) {
117+
llvm::APSInt Value = EVResult.Val.getInt();
118+
if (Value.isNonNegative())
93119
return;
94120
}
95121

96-
diag(CastExpression->getBeginLoc(),
97-
"'signed char' to %0 conversion; "
98-
"consider casting to 'unsigned char' first.")
99-
<< *IntegerType;
122+
if (const auto *Comparison = Result.Nodes.getNodeAs<Expr>("comparison")) {
123+
const auto *UnSignedCastExpression =
124+
Result.Nodes.getNodeAs<ImplicitCastExpr>("unsignedCastExpression");
125+
126+
// We can ignore the ASCII value range also for unsigned char.
127+
Expr::EvalResult EVResult;
128+
if (!UnSignedCastExpression->isValueDependent() &&
129+
UnSignedCastExpression->getSubExpr()->EvaluateAsInt(EVResult,
130+
*Result.Context)) {
131+
llvm::APSInt Value = EVResult.Val.getInt();
132+
if (Value <= UnsignedASCIIUpperBound)
133+
return;
134+
}
135+
136+
diag(Comparison->getBeginLoc(),
137+
"comparison between 'signed char' and 'unsigned char'");
138+
} else if (const auto *IntegerType =
139+
Result.Nodes.getNodeAs<QualType>("integerType")) {
140+
diag(SignedCastExpression->getBeginLoc(),
141+
"'signed char' to %0 conversion; "
142+
"consider casting to 'unsigned char' first.")
143+
<< *IntegerType;
144+
} else
145+
llvm_unreachable("Unexpected match");
100146
}
101147

102148
} // namespace bugprone

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ namespace clang {
1515
namespace tidy {
1616
namespace bugprone {
1717

18-
/// Finds ``signed char`` -> integer conversions which might indicate a programming
19-
/// error. The basic problem with the ``signed char``, that it might store the
20-
/// non-ASCII characters as negative values. The human programmer probably
21-
/// expects that after an integer conversion the converted value matches with the
22-
/// character code (a value from [0..255]), however, the actual value is in
23-
/// [-128..127] interval. This also applies to the plain ``char`` type on
24-
/// those implementations which represent ``char`` similar to ``signed char``.
18+
/// Finds those ``signed char`` -> integer conversions which might indicate a
19+
/// programming error. The basic problem with the ``signed char``, that it might
20+
/// store the non-ASCII characters as negative values. This behavior can cause a
21+
/// misunderstanding of the written code both when an explicit and when an
22+
/// implicit conversion happens.
2523
///
2624
/// For the user-facing documentation see:
2725
/// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-signed-char-misuse.html
@@ -34,6 +32,11 @@ class SignedCharMisuseCheck : public ClangTidyCheck {
3432
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
3533

3634
private:
35+
ast_matchers::internal::BindableMatcher<clang::Stmt> charCastExpression(
36+
bool IsSigned,
37+
const ast_matchers::internal::Matcher<clang::QualType> &IntegerType,
38+
const std::string &CastBindName) const;
39+
3740
const std::string CharTypdefsToIgnoreList;
3841
};
3942

clang-tools-extra/clangd/Protocol.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,9 @@ llvm::json::Value toJSON(const WorkDoneProgressBegin &P) {
407407
Result["cancellable"] = true;
408408
if (P.percentage)
409409
Result["percentage"] = 0;
410-
return Result;
410+
411+
// FIXME: workaround for older gcc/clang
412+
return std::move(Result);
411413
}
412414

413415
llvm::json::Value toJSON(const WorkDoneProgressReport &P) {
@@ -418,14 +420,16 @@ llvm::json::Value toJSON(const WorkDoneProgressReport &P) {
418420
Result["message"] = *P.message;
419421
if (P.percentage)
420422
Result["percentage"] = *P.percentage;
421-
return Result;
423+
// FIXME: workaround for older gcc/clang
424+
return std::move(Result);
422425
}
423426

424427
llvm::json::Value toJSON(const WorkDoneProgressEnd &P) {
425428
llvm::json::Object Result{{"kind", "end"}};
426429
if (P.message)
427430
Result["message"] = *P.message;
428-
return Result;
431+
// FIXME: workaround for older gcc/clang
432+
return std::move(Result);
429433
}
430434

431435
llvm::json::Value toJSON(const MessageType &R) {
@@ -530,6 +534,7 @@ llvm::json::Value toJSON(const Diagnostic &D) {
530534
Diag["source"] = D.source;
531535
if (D.relatedInformation)
532536
Diag["relatedInformation"] = *D.relatedInformation;
537+
// FIXME: workaround for older gcc/clang
533538
return std::move(Diag);
534539
}
535540

@@ -648,8 +653,8 @@ llvm::json::Value toJSON(const SymbolDetails &P) {
648653
if (P.ID.hasValue())
649654
Result["id"] = P.ID.getValue().str();
650655

651-
// Older clang cannot compile 'return Result', even though it is legal.
652-
return llvm::json::Value(std::move(Result));
656+
// FIXME: workaround for older gcc/clang
657+
return std::move(Result);
653658
}
654659

655660
llvm::raw_ostream &operator<<(llvm::raw_ostream &O, const SymbolDetails &S) {
@@ -711,8 +716,8 @@ llvm::json::Value toJSON(const DocumentSymbol &S) {
711716
Result["children"] = S.children;
712717
if (S.deprecated)
713718
Result["deprecated"] = true;
714-
// Older gcc cannot compile 'return Result', even though it is legal.
715-
return llvm::json::Value(std::move(Result));
719+
// FIXME: workaround for older gcc/clang
720+
return std::move(Result);
716721
}
717722

718723
llvm::json::Value toJSON(const WorkspaceEdit &WE) {

clang-tools-extra/docs/clang-tidy/checks/abseil-duration-unnecessary-conversion.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ Integer examples:
4040
// Suggestion - Remove division and conversion
4141
absl::Duration d2 = d1;
4242

43+
Unwrapping scalar operations:
44+
45+
.. code-block:: c++
46+
47+
// Original - Multiplication by a scalar
48+
absl::Duration d1;
49+
absl::Duration d2 = absl::Seconds(absl::ToInt64Seconds(d1) * 2);
50+
51+
// Suggestion - Remove unnecessary conversion
52+
absl::Duration d2 = d1 * 2;
53+
4354
Note: Converting to an integer and back to an ``absl::Duration`` might be a
4455
truncating operation if the value is not aligned to the scale of conversion.
4556
In the rare case where this is the intended result, callers should use

0 commit comments

Comments
 (0)