Skip to content

Commit 0b6f58e

Browse files
authored
merge main into amd-staging (#803)
2 parents 5308ae5 + 30547dd commit 0b6f58e

File tree

114 files changed

+11621
-9823
lines changed

Some content is hidden

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

114 files changed

+11621
-9823
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ add_clang_library(clangTidyGoogleModule STATIC
2424

2525
LINK_LIBS
2626
clangTidy
27+
clangTidyModernizeModule
2728
clangTidyReadabilityModule
2829
clangTidyUtils
2930

clang-tools-extra/clangd/SemanticSelection.cpp

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -42,72 +42,6 @@ void addIfDistinct(const Range &R, std::vector<Range> &Result) {
4242
}
4343
}
4444

45-
std::optional<FoldingRange> toFoldingRange(SourceRange SR,
46-
const SourceManager &SM) {
47-
const auto Begin = SM.getDecomposedLoc(SR.getBegin()),
48-
End = SM.getDecomposedLoc(SR.getEnd());
49-
// Do not produce folding ranges if either range ends is not within the main
50-
// file. Macros have their own FileID so this also checks if locations are not
51-
// within the macros.
52-
if ((Begin.first != SM.getMainFileID()) || (End.first != SM.getMainFileID()))
53-
return std::nullopt;
54-
FoldingRange Range;
55-
Range.startCharacter = SM.getColumnNumber(Begin.first, Begin.second) - 1;
56-
Range.startLine = SM.getLineNumber(Begin.first, Begin.second) - 1;
57-
Range.endCharacter = SM.getColumnNumber(End.first, End.second) - 1;
58-
Range.endLine = SM.getLineNumber(End.first, End.second) - 1;
59-
return Range;
60-
}
61-
62-
std::optional<FoldingRange>
63-
extractFoldingRange(const syntax::Node *Node,
64-
const syntax::TokenBufferTokenManager &TM) {
65-
if (const auto *Stmt = dyn_cast<syntax::CompoundStatement>(Node)) {
66-
const auto *LBrace = cast_or_null<syntax::Leaf>(
67-
Stmt->findChild(syntax::NodeRole::OpenParen));
68-
// FIXME(kirillbobyrev): This should find the last child. Compound
69-
// statements have only one pair of braces so this is valid but for other
70-
// node kinds it might not be correct.
71-
const auto *RBrace = cast_or_null<syntax::Leaf>(
72-
Stmt->findChild(syntax::NodeRole::CloseParen));
73-
if (!LBrace || !RBrace)
74-
return std::nullopt;
75-
// Fold the entire range within braces, including whitespace.
76-
const SourceLocation LBraceLocInfo =
77-
TM.getToken(LBrace->getTokenKey())->endLocation(),
78-
RBraceLocInfo =
79-
TM.getToken(RBrace->getTokenKey())->location();
80-
auto Range = toFoldingRange(SourceRange(LBraceLocInfo, RBraceLocInfo),
81-
TM.sourceManager());
82-
// Do not generate folding range for compound statements without any
83-
// nodes and newlines.
84-
if (Range && Range->startLine != Range->endLine)
85-
return Range;
86-
}
87-
return std::nullopt;
88-
}
89-
90-
// Traverse the tree and collect folding ranges along the way.
91-
std::vector<FoldingRange>
92-
collectFoldingRanges(const syntax::Node *Root,
93-
const syntax::TokenBufferTokenManager &TM) {
94-
std::queue<const syntax::Node *> Nodes;
95-
Nodes.push(Root);
96-
std::vector<FoldingRange> Result;
97-
while (!Nodes.empty()) {
98-
const syntax::Node *Node = Nodes.front();
99-
Nodes.pop();
100-
const auto Range = extractFoldingRange(Node, TM);
101-
if (Range)
102-
Result.push_back(*Range);
103-
if (const auto *T = dyn_cast<syntax::Tree>(Node))
104-
for (const auto *NextNode = T->getFirstChild(); NextNode;
105-
NextNode = NextNode->getNextSibling())
106-
Nodes.push(NextNode);
107-
}
108-
return Result;
109-
}
110-
11145
} // namespace
11246

11347
llvm::Expected<SelectionRange> getSemanticRanges(ParsedAST &AST, Position Pos) {
@@ -230,18 +164,6 @@ class PragmaRegionFinder {
230164
}
231165
};
232166

233-
// FIXME(kirillbobyrev): Collect comments, PP conditional regions, includes and
234-
// other code regions (e.g. public/private/protected sections of classes,
235-
// control flow statement bodies).
236-
// Related issue: https://github.com/clangd/clangd/issues/310
237-
llvm::Expected<std::vector<FoldingRange>> getFoldingRanges(ParsedAST &AST) {
238-
syntax::Arena A;
239-
syntax::TokenBufferTokenManager TM(AST.getTokens(), AST.getLangOpts(),
240-
AST.getSourceManager());
241-
const auto *SyntaxTree = syntax::buildSyntaxTree(A, TM, AST.getASTContext());
242-
return collectFoldingRanges(SyntaxTree, TM);
243-
}
244-
245167
// FIXME( usaxena95): Collect includes and other code regions (e.g.
246168
// public/private/protected sections of classes, control flow statement bodies).
247169
// Related issue: https://github.com/clangd/clangd/issues/310

clang-tools-extra/clangd/SemanticSelection.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ namespace clangd {
2626
/// If pos is not in any interesting range, return [Pos, Pos).
2727
llvm::Expected<SelectionRange> getSemanticRanges(ParsedAST &AST, Position Pos);
2828

29-
/// Returns a list of ranges whose contents might be collapsible in an editor.
30-
/// This should include large scopes, preprocessor blocks etc.
31-
llvm::Expected<std::vector<FoldingRange>> getFoldingRanges(ParsedAST &AST);
32-
3329
/// Returns a list of ranges whose contents might be collapsible in an editor.
3430
/// This version uses the pseudoparser which does not require the AST.
3531
llvm::Expected<std::vector<FoldingRange>>

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

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -196,76 +196,6 @@ TEST(SemanticSelection, RunViaClangdServer) {
196196
ElementsAre(SourceAnnotations.range("empty")));
197197
}
198198

199-
TEST(FoldingRanges, ASTAll) {
200-
const char *Tests[] = {
201-
R"cpp(
202-
#define FOO int foo() {\
203-
int Variable = 42; \
204-
return 0; \
205-
}
206-
207-
// Do not generate folding range for braces within macro expansion.
208-
FOO
209-
210-
// Do not generate folding range within macro arguments.
211-
#define FUNCTOR(functor) functor
212-
void func() {[[
213-
FUNCTOR([](){});
214-
]]}
215-
216-
// Do not generate folding range with a brace coming from macro.
217-
#define LBRACE {
218-
void bar() LBRACE
219-
int X = 42;
220-
}
221-
)cpp",
222-
R"cpp(
223-
void func() {[[
224-
int Variable = 100;
225-
226-
if (Variable > 5) {[[
227-
Variable += 42;
228-
]]} else if (Variable++)
229-
++Variable;
230-
else {[[
231-
Variable--;
232-
]]}
233-
234-
// Do not generate FoldingRange for empty CompoundStmts.
235-
for (;;) {}
236-
237-
// If there are newlines between {}, we should generate one.
238-
for (;;) {[[
239-
240-
]]}
241-
]]}
242-
)cpp",
243-
R"cpp(
244-
class Foo {
245-
public:
246-
Foo() {[[
247-
int X = 1;
248-
]]}
249-
250-
private:
251-
int getBar() {[[
252-
return 42;
253-
]]}
254-
255-
// Braces are located at the same line: no folding range here.
256-
void getFooBar() { }
257-
};
258-
)cpp",
259-
};
260-
for (const char *Test : Tests) {
261-
auto T = Annotations(Test);
262-
auto AST = TestTU::withCode(T.code()).build();
263-
EXPECT_THAT(gatherFoldingRanges(llvm::cantFail(getFoldingRanges(AST))),
264-
UnorderedElementsAreArray(T.ranges()))
265-
<< Test;
266-
}
267-
}
268-
269199
TEST(FoldingRanges, PseudoParserWithoutLineFoldings) {
270200
const char *Tests[] = {
271201
R"cpp(

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12945,6 +12945,12 @@ def warn_target_clone_duplicate_options
1294512945
def warn_target_clone_no_impact_options
1294612946
: Warning<"version list contains entries that don't impact code generation">,
1294712947
InGroup<FunctionMultiVersioning>;
12948+
def warn_version_priority_out_of_range
12949+
: Warning<"version priority '%0' is outside the allowed range [1-255]; ignoring priority">,
12950+
InGroup<FunctionMultiVersioning>;
12951+
def warn_invalid_default_version_priority
12952+
: Warning<"priority of default version cannot be overridden; ignoring priority">,
12953+
InGroup<FunctionMultiVersioning>;
1294812954

1294912955
// three-way comparison operator diagnostics
1295012956
def err_implied_comparison_category_type_not_found : Error<

clang/include/clang/Sema/SemaARM.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ class SemaARM : public SemaBase {
9292
/// false otherwise.
9393
bool areLaxCompatibleSveTypes(QualType FirstType, QualType SecondType);
9494

95-
bool checkTargetVersionAttr(const StringRef Str, const SourceLocation Loc);
95+
bool checkTargetVersionAttr(const StringRef Param, const SourceLocation Loc,
96+
SmallString<64> &NewParam);
9697
bool checkTargetClonesAttr(SmallVectorImpl<StringRef> &Params,
9798
SmallVectorImpl<SourceLocation> &Locs,
9899
SmallVectorImpl<SmallString<64>> &NewParams);

clang/include/clang/Sema/SemaRISCV.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class SemaRISCV : public SemaBase {
5656

5757
std::unique_ptr<sema::RISCVIntrinsicManager> IntrinsicManager;
5858

59-
bool checkTargetVersionAttr(const StringRef Param, const SourceLocation Loc);
59+
bool checkTargetVersionAttr(const StringRef Param, const SourceLocation Loc,
60+
SmallString<64> &NewParam);
6061
bool checkTargetClonesAttr(SmallVectorImpl<StringRef> &Params,
6162
SmallVectorImpl<SourceLocation> &Locs,
6263
SmallVectorImpl<SmallString<64>> &NewParams);

clang/lib/CodeGen/Targets/AArch64.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,9 +1359,10 @@ void AArch64ABIInfo::appendAttributeMangling(StringRef AttrStr,
13591359

13601360
llvm::SmallDenseSet<StringRef, 8> UniqueFeats;
13611361
for (auto &Feat : Features)
1362-
if (auto Ext = llvm::AArch64::parseFMVExtension(Feat))
1363-
if (UniqueFeats.insert(Ext->Name).second)
1364-
Out << 'M' << Ext->Name;
1362+
if (getTarget().doesFeatureAffectCodeGen(Feat))
1363+
if (auto Ext = llvm::AArch64::parseFMVExtension(Feat))
1364+
if (UniqueFeats.insert(Ext->Name).second)
1365+
Out << 'M' << Ext->Name;
13651366
}
13661367

13671368
std::unique_ptr<TargetCodeGenInfo>

clang/lib/Sema/SemaARM.cpp

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,19 +1593,54 @@ bool SemaARM::areLaxCompatibleSveTypes(QualType FirstType,
15931593
IsLaxCompatible(SecondType, FirstType);
15941594
}
15951595

1596+
static void appendFeature(StringRef Feat, SmallString<64> &Buffer) {
1597+
if (!Buffer.empty())
1598+
Buffer.append("+");
1599+
Buffer.append(Feat);
1600+
}
1601+
1602+
static void convertPriorityString(unsigned Priority,
1603+
SmallString<64> &NewParam) {
1604+
StringRef PriorityString[8] = {"P0", "P1", "P2", "P3",
1605+
"P4", "P5", "P6", "P7"};
1606+
1607+
assert(Priority > 0 && Priority < 256 && "priority out of range");
1608+
// Convert priority=[1-255] -> P0 + ... + P7
1609+
for (unsigned BitPos = 0; BitPos < 8; ++BitPos)
1610+
if (Priority & (1U << BitPos))
1611+
appendFeature(PriorityString[BitPos], NewParam);
1612+
}
1613+
15961614
bool SemaARM::checkTargetVersionAttr(const StringRef Param,
1597-
const SourceLocation Loc) {
1615+
const SourceLocation Loc,
1616+
SmallString<64> &NewParam) {
15981617
using namespace DiagAttrParams;
15991618

1619+
auto [LHS, RHS] = Param.split(';');
1620+
RHS = RHS.trim();
1621+
bool IsDefault = false;
16001622
llvm::SmallVector<StringRef, 8> Features;
1601-
Param.split(Features, '+');
1623+
LHS.split(Features, '+');
16021624
for (StringRef Feat : Features) {
16031625
Feat = Feat.trim();
16041626
if (Feat == "default")
1605-
continue;
1606-
if (!getASTContext().getTargetInfo().validateCpuSupports(Feat))
1627+
IsDefault = true;
1628+
else if (!getASTContext().getTargetInfo().validateCpuSupports(Feat))
16071629
return Diag(Loc, diag::warn_unsupported_target_attribute)
16081630
<< Unsupported << None << Feat << TargetVersion;
1631+
appendFeature(Feat, NewParam);
1632+
}
1633+
1634+
if (!RHS.empty() && RHS.consume_front("priority=")) {
1635+
if (IsDefault)
1636+
Diag(Loc, diag::warn_invalid_default_version_priority);
1637+
else {
1638+
unsigned Digit;
1639+
if (RHS.getAsInteger(0, Digit) || Digit < 1 || Digit > 255)
1640+
Diag(Loc, diag::warn_version_priority_out_of_range) << RHS;
1641+
else
1642+
convertPriorityString(Digit, NewParam);
1643+
}
16091644
}
16101645
return false;
16111646
}
@@ -1627,15 +1662,21 @@ bool SemaARM::checkTargetClonesAttr(
16271662
const StringRef Param = Params[I].trim();
16281663
const SourceLocation &Loc = Locs[I];
16291664

1630-
if (Param.empty())
1665+
auto [LHS, RHS] = Param.split(';');
1666+
RHS = RHS.trim();
1667+
bool HasPriority = !RHS.empty() && RHS.consume_front("priority=");
1668+
1669+
if (LHS.empty())
16311670
return Diag(Loc, diag::warn_unsupported_target_attribute)
16321671
<< Unsupported << None << "" << TargetClones;
16331672

1634-
if (Param == "default") {
1673+
if (LHS == "default") {
16351674
if (HasDefault)
16361675
Diag(Loc, diag::warn_target_clone_duplicate_options);
16371676
else {
1638-
NewParams.push_back(Param);
1677+
if (HasPriority)
1678+
Diag(Loc, diag::warn_invalid_default_version_priority);
1679+
NewParams.push_back(LHS);
16391680
HasDefault = true;
16401681
}
16411682
continue;
@@ -1644,7 +1685,7 @@ bool SemaARM::checkTargetClonesAttr(
16441685
bool HasCodeGenImpact = false;
16451686
llvm::SmallVector<StringRef, 8> Features;
16461687
llvm::SmallVector<StringRef, 8> ValidFeatures;
1647-
Param.split(Features, '+');
1688+
LHS.split(Features, '+');
16481689
for (StringRef Feat : Features) {
16491690
Feat = Feat.trim();
16501691
if (!getASTContext().getTargetInfo().validateCpuSupports(Feat)) {
@@ -1674,6 +1715,14 @@ bool SemaARM::checkTargetClonesAttr(
16741715
continue;
16751716
}
16761717

1718+
if (HasPriority) {
1719+
unsigned Digit;
1720+
if (RHS.getAsInteger(0, Digit) || Digit < 1 || Digit > 255)
1721+
Diag(Loc, diag::warn_version_priority_out_of_range) << RHS;
1722+
else
1723+
convertPriorityString(Digit, NewParam);
1724+
}
1725+
16771726
// Valid non-default argument.
16781727
NewParams.push_back(NewParam);
16791728
HasNonDefault = true;

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,19 +3445,20 @@ bool Sema::checkTargetAttr(SourceLocation LiteralLoc, StringRef AttrStr) {
34453445
static void handleTargetVersionAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
34463446
StringRef Param;
34473447
SourceLocation Loc;
3448+
SmallString<64> NewParam;
34483449
if (!S.checkStringLiteralArgumentAttr(AL, 0, Param, &Loc))
34493450
return;
34503451

34513452
if (S.Context.getTargetInfo().getTriple().isAArch64()) {
3452-
if (S.ARM().checkTargetVersionAttr(Param, Loc))
3453+
if (S.ARM().checkTargetVersionAttr(Param, Loc, NewParam))
34533454
return;
34543455
} else if (S.Context.getTargetInfo().getTriple().isRISCV()) {
3455-
if (S.RISCV().checkTargetVersionAttr(Param, Loc))
3456+
if (S.RISCV().checkTargetVersionAttr(Param, Loc, NewParam))
34563457
return;
34573458
}
34583459

34593460
TargetVersionAttr *NewAttr =
3460-
::new (S.Context) TargetVersionAttr(S.Context, AL, Param);
3461+
::new (S.Context) TargetVersionAttr(S.Context, AL, NewParam);
34613462
D->addAttr(NewAttr);
34623463
}
34633464

0 commit comments

Comments
 (0)