Skip to content

Commit e638133

Browse files
authored
Merge pull request #272 from AMD-Lightning-Internal/amd/merge/upstream_merge_20250122182524
merge main into amd-staging
2 parents c04b0a1 + 6115fd1 commit e638133

File tree

316 files changed

+17701
-9060
lines changed

Some content is hidden

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

316 files changed

+17701
-9060
lines changed

clang-tools-extra/clang-reorder-fields/ReorderFieldsAction.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,29 @@ findMembersUsedInInitExpr(const CXXCtorInitializer *Initializer,
118118
return Results;
119119
}
120120

121+
/// Returns the start of the leading comments before `Loc`.
122+
static SourceLocation getStartOfLeadingComment(SourceLocation Loc,
123+
const SourceManager &SM,
124+
const LangOptions &LangOpts) {
125+
// We consider any leading comment token that is on the same line or
126+
// indented similarly to the first comment to be part of the leading comment.
127+
const unsigned Line = SM.getPresumedLineNumber(Loc);
128+
const unsigned Column = SM.getPresumedColumnNumber(Loc);
129+
std::optional<Token> Tok =
130+
Lexer::findPreviousToken(Loc, SM, LangOpts, /*IncludeComments=*/true);
131+
while (Tok && Tok->is(tok::comment)) {
132+
const SourceLocation CommentLoc =
133+
Lexer::GetBeginningOfToken(Tok->getLocation(), SM, LangOpts);
134+
if (SM.getPresumedLineNumber(CommentLoc) != Line &&
135+
SM.getPresumedColumnNumber(CommentLoc) != Column) {
136+
break;
137+
}
138+
Loc = CommentLoc;
139+
Tok = Lexer::findPreviousToken(Loc, SM, LangOpts, /*IncludeComments=*/true);
140+
}
141+
return Loc;
142+
}
143+
121144
/// Returns the end of the trailing comments after `Loc`.
122145
static SourceLocation getEndOfTrailingComment(SourceLocation Loc,
123146
const SourceManager &SM,
@@ -159,6 +182,7 @@ static SourceRange getFullFieldSourceRange(const FieldDecl &Field,
159182
if (CurrentToken->is(tok::semi))
160183
break;
161184
}
185+
Begin = getStartOfLeadingComment(Begin, SM, LangOpts);
162186
End = getEndOfTrailingComment(End, SM, LangOpts);
163187
return SourceRange(Begin, End);
164188
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "clang/AST/ASTContext.h"
1111
#include "clang/AST/Decl.h"
1212
#include "clang/ASTMatchers/ASTMatchFinder.h"
13+
#include "clang/ASTMatchers/ASTMatchers.h"
1314
#include "clang/Lex/Lexer.h"
1415

1516
using namespace clang::ast_matchers;

clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ UseIntegerSignComparisonCheck::UseIntegerSignComparisonCheck(
8080
: ClangTidyCheck(Name, Context),
8181
IncludeInserter(Options.getLocalOrGlobal("IncludeStyle",
8282
utils::IncludeSorter::IS_LLVM),
83-
areDiagsSelfContained()) {}
83+
areDiagsSelfContained()),
84+
EnableQtSupport(Options.get("EnableQtSupport", false)) {}
8485

8586
void UseIntegerSignComparisonCheck::storeOptions(
8687
ClangTidyOptions::OptionMap &Opts) {
8788
Options.store(Opts, "IncludeStyle", IncludeInserter.getStyle());
89+
Options.store(Opts, "EnableQtSupport", EnableQtSupport);
8890
}
8991

9092
void UseIntegerSignComparisonCheck::registerMatchers(MatchFinder *Finder) {
@@ -154,8 +156,17 @@ void UseIntegerSignComparisonCheck::check(
154156
DiagnosticBuilder Diag =
155157
diag(BinaryOp->getBeginLoc(),
156158
"comparison between 'signed' and 'unsigned' integers");
157-
const std::string CmpNamespace = ("std::" + parseOpCode(OpCode)).str();
158-
const std::string CmpHeader = "<utility>";
159+
std::string CmpNamespace;
160+
llvm::StringRef CmpHeader;
161+
162+
if (getLangOpts().CPlusPlus20) {
163+
CmpHeader = "<utility>";
164+
CmpNamespace = llvm::Twine("std::" + parseOpCode(OpCode)).str();
165+
} else if (getLangOpts().CPlusPlus17 && EnableQtSupport) {
166+
CmpHeader = "<QtCore/q20utility.h>";
167+
CmpNamespace = llvm::Twine("q20::" + parseOpCode(OpCode)).str();
168+
}
169+
159170
// Prefer modernize-use-integer-sign-comparison when C++20 is available!
160171
Diag << FixItHint::CreateReplacement(
161172
CharSourceRange(R1, SubExprLHS != nullptr),

clang-tools-extra/clang-tidy/modernize/UseIntegerSignComparisonCheck.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ class UseIntegerSignComparisonCheck : public ClangTidyCheck {
3030
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
3131
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
3232
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
33-
return LangOpts.CPlusPlus20;
33+
return LangOpts.CPlusPlus20 || (LangOpts.CPlusPlus17 && EnableQtSupport);
3434
}
3535

3636
private:
3737
utils::IncludeInserter IncludeInserter;
38+
const bool EnableQtSupport;
3839
};
3940

4041
} // namespace clang::tidy::modernize

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,16 @@ namespace clang::tidy::utils::lexer {
1717
std::pair<Token, SourceLocation>
1818
getPreviousTokenAndStart(SourceLocation Location, const SourceManager &SM,
1919
const LangOptions &LangOpts, bool SkipComments) {
20-
Token Token;
21-
Token.setKind(tok::unknown);
20+
const std::optional<Token> Tok =
21+
Lexer::findPreviousToken(Location, SM, LangOpts, !SkipComments);
2222

23-
Location = Location.getLocWithOffset(-1);
24-
if (Location.isInvalid())
25-
return {Token, Location};
26-
27-
const auto StartOfFile = SM.getLocForStartOfFile(SM.getFileID(Location));
28-
while (Location != StartOfFile) {
29-
Location = Lexer::GetBeginningOfToken(Location, SM, LangOpts);
30-
if (!Lexer::getRawToken(Location, Token, SM, LangOpts) &&
31-
(!SkipComments || !Token.is(tok::comment))) {
32-
break;
33-
}
34-
if (Location == StartOfFile)
35-
return {Token, Location};
36-
Location = Location.getLocWithOffset(-1);
23+
if (Tok.has_value()) {
24+
return {*Tok, Lexer::GetBeginningOfToken(Tok->getLocation(), SM, LangOpts)};
3725
}
38-
return {Token, Location};
26+
27+
Token Token;
28+
Token.setKind(tok::unknown);
29+
return {Token, SourceLocation()};
3930
}
4031

4132
Token getPreviousToken(SourceLocation Location, const SourceManager &SM,

clang-tools-extra/clangd/GlobalCompilationDatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ OverlayCDB::getProjectModules(PathRef File) const {
837837
PathRef CommandPath) {
838838
Mangler(Command, CommandPath);
839839
});
840-
return std::move(MDB);
840+
return MDB;
841841
}
842842

843843
DelegatingCDB::DelegatingCDB(const GlobalCompilationDatabase *Base)

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ Changes in existing checks
329329
<clang-tidy/checks/modernize/use-designated-initializers>` check to fix a
330330
crash when a class is declared but not defined.
331331

332+
- Improved :doc:`modernize-use-integer-sign-comparison
333+
<clang-tidy/checks/modernize/use-integer-sign-comparison>` check to
334+
add an option ``EnableQtSupport``, that makes C++17 ``q20::cmp_*`` alternative
335+
available for Qt-based applications.
336+
332337
- Improved :doc:`modernize-use-nullptr
333338
<clang-tidy/checks/modernize/use-nullptr>` check to also recognize
334339
``NULL``/``__null`` (but not ``0``) when used with a templated type.

clang-tools-extra/docs/clang-tidy/checks/modernize/use-integer-sign-comparison.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ Options
3434

3535
A string specifying which include-style is used, `llvm` or `google`.
3636
Default is `llvm`.
37+
38+
.. option:: EnableQtSupport
39+
40+
Makes C++17 ``q20::cmp_*`` alternative available for Qt-based
41+
applications. Default is `false`.

clang-tools-extra/test/clang-reorder-fields/Comments.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: clang-reorder-fields -record-name Foo -fields-order e1,e3,e2,a,c,b %s -- | FileCheck %s
1+
// RUN: clang-reorder-fields -record-name Foo -fields-order c,e1,e3,e2,a,b %s -- | FileCheck %s
22

33
class Foo {
44
int a; // Trailing comment for a.
@@ -12,12 +12,15 @@ class Foo {
1212
int e3 /*c-like*/;
1313
};
1414

15-
// CHECK: /*c-like*/ int e1;
15+
// Note: the position of the empty line is somewhat arbitrary.
16+
17+
// CHECK: // Prefix comments for c.
18+
// CHECK-NEXT: int c;
19+
// CHECK-NEXT: /*c-like*/ int e1;
1620
// CHECK-NEXT: int e3 /*c-like*/;
21+
// CHECK-EMPTY:
1722
// CHECK-NEXT: int /*c-like*/ e2;
1823
// CHECK-NEXT: int a; // Trailing comment for a.
19-
// CHECK-NEXT: // Prefix comments for c.
20-
// CHECK-NEXT: int c;
2124
// CHECK-NEXT: int b; // Multiline
2225
// CHECK-NEXT: // trailing for b.
2326

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// CHECK-FIXES: #include <QtCore/q20utility.h>
2+
// RUN: %check_clang_tidy -std=c++17 %s modernize-use-integer-sign-comparison %t -- \
3+
// RUN: -config="{CheckOptions: {modernize-use-integer-sign-comparison.EnableQtSupport: true}}"
4+
5+
// The code that triggers the check
6+
#define MAX_MACRO(a, b) (a < b) ? b : a
7+
8+
unsigned int FuncParameters(int bla) {
9+
unsigned int result = 0;
10+
if (result == bla)
11+
return 0;
12+
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
13+
// CHECK-FIXES: if (q20::cmp_equal(result , bla))
14+
15+
return 1;
16+
}
17+
18+
template <typename T>
19+
void TemplateFuncParameter(T val) {
20+
unsigned long uL = 0;
21+
if (val >= uL)
22+
return;
23+
// CHECK-MESSAGES-NOT: warning:
24+
}
25+
26+
template <typename T1, typename T2>
27+
int TemplateFuncParameters(T1 val1, T2 val2) {
28+
if (val1 >= val2)
29+
return 0;
30+
// CHECK-MESSAGES-NOT: warning:
31+
return 1;
32+
}
33+
34+
int AllComparisons() {
35+
unsigned int uVar = 42;
36+
unsigned short uArray[7] = {0, 1, 2, 3, 9, 7, 9};
37+
38+
int sVar = -42;
39+
short sArray[7] = {-1, -2, -8, -94, -5, -4, -6};
40+
41+
enum INT_TEST {
42+
VAL1 = 0,
43+
VAL2 = -1
44+
};
45+
46+
char ch = 'a';
47+
unsigned char uCh = 'a';
48+
signed char sCh = 'a';
49+
bool bln = false;
50+
51+
if (bln == sVar)
52+
return 0;
53+
// CHECK-MESSAGES-NOT: warning:
54+
55+
if (ch > uCh)
56+
return 0;
57+
// CHECK-MESSAGES-NOT: warning:
58+
59+
if (sVar <= INT_TEST::VAL2)
60+
return 0;
61+
// CHECK-MESSAGES-NOT: warning:
62+
63+
if (uCh < sCh)
64+
return -1;
65+
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
66+
// CHECK-FIXES: if (q20::cmp_less(uCh , sCh))
67+
68+
if ((int)uVar < sVar)
69+
return 0;
70+
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
71+
// CHECK-FIXES: if (q20::cmp_less(uVar, sVar))
72+
73+
(uVar != sVar) ? uVar = sVar
74+
: sVar = uVar;
75+
// CHECK-MESSAGES: :[[@LINE-2]]:6: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
76+
// CHECK-FIXES: (q20::cmp_not_equal(uVar , sVar)) ? uVar = sVar
77+
78+
while (uArray[0] <= sArray[0])
79+
return 0;
80+
// CHECK-MESSAGES: :[[@LINE-2]]:12: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
81+
// CHECK-FIXES: while (q20::cmp_less_equal(uArray[0] , sArray[0]))
82+
83+
if (uArray[1] > sArray[1])
84+
return 0;
85+
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
86+
// CHECK-FIXES: if (q20::cmp_greater(uArray[1] , sArray[1]))
87+
88+
MAX_MACRO(uVar, sArray[0]);
89+
// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
90+
91+
if (static_cast<unsigned int>(uArray[2]) < static_cast<int>(sArray[2]))
92+
return 0;
93+
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
94+
// CHECK-FIXES: if (q20::cmp_less(uArray[2],sArray[2]))
95+
96+
if ((unsigned int)uArray[3] < (int)sArray[3])
97+
return 0;
98+
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
99+
// CHECK-FIXES: if (q20::cmp_less(uArray[3],sArray[3]))
100+
101+
if ((unsigned int)(uArray[4]) < (int)(sArray[4]))
102+
return 0;
103+
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
104+
// CHECK-FIXES: if (q20::cmp_less((uArray[4]),(sArray[4])))
105+
106+
if (uArray[5] > sArray[5])
107+
return 0;
108+
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
109+
// CHECK-FIXES: if (q20::cmp_greater(uArray[5] , sArray[5]))
110+
111+
#define VALUE sArray[6]
112+
if (uArray[6] > VALUE)
113+
return 0;
114+
// CHECK-MESSAGES: :[[@LINE-2]]:9: warning: comparison between 'signed' and 'unsigned' integers [modernize-use-integer-sign-comparison]
115+
// CHECK-FIXES: if (q20::cmp_greater(uArray[6] , VALUE))
116+
117+
118+
FuncParameters(uVar);
119+
TemplateFuncParameter(sVar);
120+
TemplateFuncParameters(uVar, sVar);
121+
122+
return 0;
123+
}

0 commit comments

Comments
 (0)