Skip to content

Commit fc2a5ff

Browse files
SC llvm teamsstipano
authored andcommitted
Merged main:007f601f1505 into amd-gfx:b8d70697615e
Local branch amd-gfx b8d7069 Merged main:2207e3e32549 into amd-gfx:40612bd87e86 Remote branch main 007f601 [Clang][Docs] Document -Xarch_ better (llvm#127890)
2 parents b8d7069 + 007f601 commit fc2a5ff

File tree

565 files changed

+17759
-7545
lines changed

Some content is hidden

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

565 files changed

+17759
-7545
lines changed

.github/new-prs-labeler.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ clang:static analyzer:
499499
- clang/tools/scan-build/**
500500
- clang/utils/analyzer/**
501501
- clang/docs/analyzer/**
502+
- clang/test/Analysis/**
502503

503504
pgo:
504505
- llvm/lib/Transforms/Instrumentation/CGProfile.cpp

bolt/lib/RuntimeLibs/InstrumentationRuntimeLibrary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void InstrumentationRuntimeLibrary::link(
219219
}
220220
outs() << "BOLT-INFO: output linked against instrumentation runtime "
221221
"library, lib entry point is 0x"
222-
<< Twine::utohexstr(RuntimeFiniAddress) << "\n";
222+
<< Twine::utohexstr(RuntimeStartAddress) << "\n";
223223
outs() << "BOLT-INFO: clear procedure is 0x"
224224
<< Twine::utohexstr(
225225
Linker.lookupSymbol("__bolt_instr_clear_counters").value_or(0))

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include "ConstCorrectnessCheck.h"
1010
#include "../utils/FixItHintUtils.h"
11+
#include "../utils/Matchers.h"
12+
#include "../utils/OptionsUtils.h"
1113
#include "clang/AST/ASTContext.h"
1214
#include "clang/ASTMatchers/ASTMatchFinder.h"
1315
#include "clang/ASTMatchers/ASTMatchers.h"
@@ -41,7 +43,9 @@ ConstCorrectnessCheck::ConstCorrectnessCheck(StringRef Name,
4143
TransformValues(Options.get("TransformValues", true)),
4244
TransformReferences(Options.get("TransformReferences", true)),
4345
TransformPointersAsValues(
44-
Options.get("TransformPointersAsValues", false)) {
46+
Options.get("TransformPointersAsValues", false)),
47+
AllowedTypes(
48+
utils::options::parseStringList(Options.get("AllowedTypes", ""))) {
4549
if (AnalyzeValues == false && AnalyzeReferences == false)
4650
this->configurationDiag(
4751
"The check 'misc-const-correctness' will not "
@@ -57,6 +61,8 @@ void ConstCorrectnessCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
5761
Options.store(Opts, "TransformValues", TransformValues);
5862
Options.store(Opts, "TransformReferences", TransformReferences);
5963
Options.store(Opts, "TransformPointersAsValues", TransformPointersAsValues);
64+
Options.store(Opts, "AllowedTypes",
65+
utils::options::serializeStringList(AllowedTypes));
6066
}
6167

6268
void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
@@ -73,6 +79,12 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
7379
hasType(referenceType(pointee(hasCanonicalType(templateTypeParmType())))),
7480
hasType(referenceType(pointee(substTemplateTypeParmType()))));
7581

82+
const auto AllowedType = hasType(qualType(anyOf(
83+
hasDeclaration(namedDecl(matchers::matchesAnyListedName(AllowedTypes))),
84+
references(namedDecl(matchers::matchesAnyListedName(AllowedTypes))),
85+
pointerType(pointee(hasDeclaration(
86+
namedDecl(matchers::matchesAnyListedName(AllowedTypes))))))));
87+
7688
const auto AutoTemplateType = varDecl(
7789
anyOf(hasType(autoType()), hasType(referenceType(pointee(autoType()))),
7890
hasType(pointerType(pointee(autoType())))));
@@ -87,7 +99,8 @@ void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
8799
unless(anyOf(ConstType, ConstReference, TemplateType,
88100
hasInitializer(isInstantiationDependent()), AutoTemplateType,
89101
RValueReference, FunctionPointerRef,
90-
hasType(cxxRecordDecl(isLambda())), isImplicit())));
102+
hasType(cxxRecordDecl(isLambda())), isImplicit(),
103+
AllowedType)));
91104

92105
// Match the function scope for which the analysis of all local variables
93106
// shall be run.

clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class ConstCorrectnessCheck : public ClangTidyCheck {
4545
const bool TransformValues;
4646
const bool TransformReferences;
4747
const bool TransformPointersAsValues;
48+
const std::vector<StringRef> AllowedTypes;
4849
};
4950

5051
} // namespace clang::tidy::misc

clang-tools-extra/clangd/CollectMacros.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
namespace clang {
1919
namespace clangd {
2020

21-
Range MacroOccurrence::toRange(const SourceManager &SM) const {
21+
CharSourceRange MacroOccurrence::toSourceRange(const SourceManager &SM) const {
2222
auto MainFile = SM.getMainFileID();
23-
return halfOpenToRange(
24-
SM, syntax::FileRange(MainFile, StartOffset, EndOffset).toCharRange(SM));
23+
return syntax::FileRange(MainFile, StartOffset, EndOffset).toCharRange(SM);
24+
}
25+
26+
Range MacroOccurrence::toRange(const SourceManager &SM) const {
27+
return halfOpenToRange(SM, toSourceRange(SM));
2528
}
2629

2730
void CollectMainFileMacros::add(const Token &MacroNameTok, const MacroInfo *MI,

clang-tools-extra/clangd/CollectMacros.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct MacroOccurrence {
3131
// True if the occurence is used in a conditional directive, e.g. #ifdef MACRO
3232
bool InConditionalDirective;
3333

34+
CharSourceRange toSourceRange(const SourceManager &SM) const;
3435
Range toRange(const SourceManager &SM) const;
3536
};
3637

clang-tools-extra/clangd/XRefs.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,15 @@ void enhanceLocatedSymbolsFromIndex(llvm::MutableArrayRef<LocatedSymbol> Result,
372372
});
373373
}
374374

375+
bool objcMethodIsTouched(const SourceManager &SM, const ObjCMethodDecl *OMD,
376+
SourceLocation Loc) {
377+
unsigned NumSels = OMD->getNumSelectorLocs();
378+
for (unsigned I = 0; I < NumSels; ++I)
379+
if (SM.getSpellingLoc(OMD->getSelectorLoc(I)) == Loc)
380+
return true;
381+
return false;
382+
}
383+
375384
// Decls are more complicated.
376385
// The AST contains at least a declaration, maybe a definition.
377386
// These are up-to-date, and so generally preferred over index results.
@@ -430,6 +439,26 @@ locateASTReferent(SourceLocation CurLoc, const syntax::Token *TouchedIdentifier,
430439
continue;
431440
}
432441
}
442+
// Special case: - (void)^method {} should jump to overrides, but the decl
443+
// shouldn't, only the definition. Note that an Objective-C method can
444+
// override a parent class or protocol.
445+
//
446+
// FIXME: Support jumping from a protocol decl to overrides on go-to
447+
// definition.
448+
if (const auto *OMD = llvm::dyn_cast<ObjCMethodDecl>(D)) {
449+
if (OMD->isThisDeclarationADefinition() && TouchedIdentifier &&
450+
objcMethodIsTouched(SM, OMD, TouchedIdentifier->location())) {
451+
llvm::SmallVector<const ObjCMethodDecl *, 4> Overrides;
452+
OMD->getOverriddenMethods(Overrides);
453+
if (!Overrides.empty()) {
454+
for (const auto *Override : Overrides)
455+
AddResultDecl(Override);
456+
LocateASTReferentMetric.record(1, "objc-overriden-method");
457+
}
458+
AddResultDecl(OMD);
459+
continue;
460+
}
461+
}
433462

434463
// Special case: the cursor is on an alias, prefer other results.
435464
// This targets "using ns::^Foo", where the target is more interesting.
@@ -1283,6 +1312,12 @@ std::vector<LocatedSymbol> findImplementations(ParsedAST &AST, Position Pos,
12831312
} else if (const auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
12841313
IDs.insert(getSymbolID(RD));
12851314
QueryKind = RelationKind::BaseOf;
1315+
} else if (const auto *OMD = dyn_cast<ObjCMethodDecl>(ND)) {
1316+
IDs.insert(getSymbolID(OMD));
1317+
QueryKind = RelationKind::OverriddenBy;
1318+
} else if (const auto *ID = dyn_cast<ObjCInterfaceDecl>(ND)) {
1319+
IDs.insert(getSymbolID(ID));
1320+
QueryKind = RelationKind::BaseOf;
12861321
}
12871322
}
12881323
return findImplementors(std::move(IDs), QueryKind, Index, AST.tuPath());
@@ -1302,6 +1337,21 @@ void getOverriddenMethods(const CXXMethodDecl *CMD,
13021337
}
13031338
}
13041339

1340+
// Recursively finds all the overridden methods of `OMD` in complete type
1341+
// hierarchy.
1342+
void getOverriddenMethods(const ObjCMethodDecl *OMD,
1343+
llvm::DenseSet<SymbolID> &OverriddenMethods) {
1344+
if (!OMD)
1345+
return;
1346+
llvm::SmallVector<const ObjCMethodDecl *, 4> Overrides;
1347+
OMD->getOverriddenMethods(Overrides);
1348+
for (const ObjCMethodDecl *Base : Overrides) {
1349+
if (auto ID = getSymbolID(Base))
1350+
OverriddenMethods.insert(ID);
1351+
getOverriddenMethods(Base, OverriddenMethods);
1352+
}
1353+
}
1354+
13051355
std::optional<std::string>
13061356
stringifyContainerForMainFileRef(const Decl *Container) {
13071357
// FIXME We might also want to display the signature here
@@ -1438,6 +1488,12 @@ ReferencesResult findReferences(ParsedAST &AST, Position Pos, uint32_t Limit,
14381488
getOverriddenMethods(CMD, OverriddenMethods);
14391489
}
14401490
}
1491+
// Special case: Objective-C methods can override a parent class or
1492+
// protocol, we should be sure to report references to those.
1493+
if (const auto *OMD = llvm::dyn_cast<ObjCMethodDecl>(ND)) {
1494+
OverriddenBy.Subjects.insert(getSymbolID(OMD));
1495+
getOverriddenMethods(OMD, OverriddenMethods);
1496+
}
14411497
}
14421498
}
14431499

clang-tools-extra/clangd/index/SymbolCollector.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,8 @@ void SymbolCollector::handleMacros(const MainFileMacros &MacroRefsToIndex) {
713713
// Add macro references.
714714
for (const auto &IDToRefs : MacroRefsToIndex.MacroRefs) {
715715
for (const auto &MacroRef : IDToRefs.second) {
716-
const auto &Range = MacroRef.toRange(SM);
716+
const auto &SR = MacroRef.toSourceRange(SM);
717+
auto Range = halfOpenToRange(SM, SR);
717718
bool IsDefinition = MacroRef.IsDefinition;
718719
Ref R;
719720
R.Location.Start.setLine(Range.start.line);
@@ -726,9 +727,7 @@ void SymbolCollector::handleMacros(const MainFileMacros &MacroRefsToIndex) {
726727
if (IsDefinition) {
727728
Symbol S;
728729
S.ID = IDToRefs.first;
729-
auto StartLoc = cantFail(sourceLocationInMainFile(SM, Range.start));
730-
auto EndLoc = cantFail(sourceLocationInMainFile(SM, Range.end));
731-
S.Name = toSourceCode(SM, SourceRange(StartLoc, EndLoc));
730+
S.Name = toSourceCode(SM, SR.getAsRange());
732731
S.SymInfo.Kind = index::SymbolKind::Macro;
733732
S.SymInfo.SubKind = index::SymbolSubKind::None;
734733
S.SymInfo.Properties = index::SymbolPropertySet();

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,42 @@ TEST_F(SymbolCollectorTest, OverrideRelationsMultipleInheritance) {
13351335
OverriddenBy(CBar, DBar), OverriddenBy(CBaz, DBaz)));
13361336
}
13371337

1338+
TEST_F(SymbolCollectorTest, ObjCOverrideRelationsSimpleInheritance) {
1339+
std::string Header = R"cpp(
1340+
@interface A
1341+
- (void)foo;
1342+
@end
1343+
@interface B : A
1344+
- (void)foo; // A::foo
1345+
- (void)bar;
1346+
@end
1347+
@interface C : B
1348+
- (void)bar; // B::bar
1349+
@end
1350+
@interface D : C
1351+
- (void)foo; // B::foo
1352+
- (void)bar; // C::bar
1353+
@end
1354+
)cpp";
1355+
runSymbolCollector(Header, /*Main=*/"",
1356+
{"-xobjective-c++", "-Wno-objc-root-class"});
1357+
const Symbol &AFoo = findSymbol(Symbols, "A::foo");
1358+
const Symbol &BFoo = findSymbol(Symbols, "B::foo");
1359+
const Symbol &DFoo = findSymbol(Symbols, "D::foo");
1360+
1361+
const Symbol &BBar = findSymbol(Symbols, "B::bar");
1362+
const Symbol &CBar = findSymbol(Symbols, "C::bar");
1363+
const Symbol &DBar = findSymbol(Symbols, "D::bar");
1364+
1365+
std::vector<Relation> Result;
1366+
for (const Relation &R : Relations)
1367+
if (R.Predicate == RelationKind::OverriddenBy)
1368+
Result.push_back(R);
1369+
EXPECT_THAT(Result, UnorderedElementsAre(
1370+
OverriddenBy(AFoo, BFoo), OverriddenBy(BBar, CBar),
1371+
OverriddenBy(BFoo, DFoo), OverriddenBy(CBar, DBar)));
1372+
}
1373+
13381374
TEST_F(SymbolCollectorTest, CountReferences) {
13391375
const std::string Header = R"(
13401376
class W;

0 commit comments

Comments
 (0)