Skip to content

Commit b9273c8

Browse files
committed
Merge remote-tracking branch 'refs/remotes/upstream/main' into gdb-index-remove
2 parents ec6fe0c + 77f75b4 commit b9273c8

File tree

502 files changed

+12380
-10954
lines changed

Some content is hidden

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

502 files changed

+12380
-10954
lines changed

bolt/include/bolt/Rewrite/DWARFRewriter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "bolt/Core/DIEBuilder.h"
1313
#include "bolt/Core/DebugData.h"
1414
#include "bolt/Core/DebugNames.h"
15+
#include "bolt/Core/GDBIndex.h"
1516
#include "llvm/ADT/StringRef.h"
1617
#include "llvm/CodeGen/DIE.h"
1718
#include "llvm/DWP/DWP.h"
@@ -131,7 +132,8 @@ class DWARFRewriter {
131132
makeFinalLocListsSection(DWARFVersion Version);
132133

133134
/// Finalize type sections in the main binary.
134-
CUOffsetMap finalizeTypeSections(DIEBuilder &DIEBlder, DIEStreamer &Streamer);
135+
CUOffsetMap finalizeTypeSections(DIEBuilder &DIEBlder, DIEStreamer &Streamer,
136+
GDBIndex &GDBIndexSection);
135137

136138
/// Process and write out CUs that are passsed in.
137139
void finalizeCompileUnits(DIEBuilder &DIEBlder, DIEStreamer &Streamer,

bolt/lib/Profile/BoltAddressTranslation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ std::error_code BoltAddressTranslation::parse(raw_ostream &OS, StringRef Buf) {
304304

305305
StringRef Name = Buf.slice(Offset, Offset + NameSz);
306306
Offset = alignTo(Offset + NameSz, 4);
307-
if (Name.substr(0, 4) != "BOLT")
307+
if (!Name.starts_with("BOLT"))
308308
return make_error_code(llvm::errc::io_error);
309309

310310
Error Err(Error::success());

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ namespace bolt {
184184
/// Emits debug information into .debug_info or .debug_types section.
185185
class DIEStreamer : public DwarfStreamer {
186186
DIEBuilder *DIEBldr;
187+
DWARFRewriter &Rewriter;
188+
GDBIndex &GDBIndexSection;
187189

188190
private:
189191
/// Emit the compilation unit header for \p Unit in the debug_info
@@ -246,7 +248,7 @@ class DIEStreamer : public DwarfStreamer {
246248
const uint64_t TypeSignature = cast<DWARFTypeUnit>(Unit).getTypeHash();
247249
DIE *TypeDIE = DIEBldr->getTypeDIE(Unit);
248250
const DIEBuilder::DWARFUnitInfo &UI = DIEBldr->getUnitInfoByDwarfUnit(Unit);
249-
Rewriter.addGDBTypeUnitEntry(
251+
GDBIndexSection.addGDBTypeUnitEntry(
250252
{UI.UnitOffset, TypeSignature, TypeDIE->getOffset()});
251253
if (Unit.getVersion() < 5) {
252254
// Switch the section to .debug_types section.
@@ -278,10 +280,12 @@ class DIEStreamer : public DwarfStreamer {
278280

279281
public:
280282
DIEStreamer(DIEBuilder *DIEBldr, DWARFRewriter &Rewriter,
283+
GDBIndex &GDBIndexSection,
281284
DWARFLinkerBase::OutputFileType OutFileType,
282285
raw_pwrite_stream &OutFile,
283286
DWARFLinkerBase::MessageHandlerTy Warning)
284-
: DwarfStreamer(OutFileType, OutFile, Warning), DIEBldr(DIEBldr){};
287+
: DwarfStreamer(OutFileType, OutFile, Warning), DIEBldr(DIEBldr),
288+
Rewriter(Rewriter), GDBIndexSection(GDBIndexSection) {};
285289

286290
using DwarfStreamer::emitCompileUnitHeader;
287291

@@ -324,12 +328,11 @@ static cl::opt<bool> KeepARanges(
324328
"keep or generate .debug_aranges section if .gdb_index is written"),
325329
cl::Hidden, cl::cat(BoltCategory));
326330

327-
static cl::opt<bool>
328-
DeterministicDebugInfo("deterministic-debuginfo",
329-
cl::desc("disables parallel execution of tasks that may produce "
330-
"nondeterministic debug info"),
331-
cl::init(true),
332-
cl::cat(BoltCategory));
331+
static cl::opt<bool> DeterministicDebugInfo(
332+
"deterministic-debuginfo",
333+
cl::desc("disables parallel execution of tasks that may produce "
334+
"nondeterministic debug info"),
335+
cl::init(true), cl::cat(BoltCategory));
333336

334337
static cl::opt<std::string> DwarfOutputPath(
335338
"dwarf-output-path",
@@ -458,10 +461,11 @@ static std::optional<uint64_t> getAsAddress(const DWARFUnit &DU,
458461
static std::unique_ptr<DIEStreamer>
459462
createDIEStreamer(const Triple &TheTriple, raw_pwrite_stream &OutFile,
460463
StringRef Swift5ReflectionSegmentName, DIEBuilder &DIEBldr,
461-
DWARFRewriter &Rewriter) {
464+
DWARFRewriter &Rewriter, GDBIndex &GDBIndexSection) {
462465

463466
std::unique_ptr<DIEStreamer> Streamer = std::make_unique<DIEStreamer>(
464-
&DIEBldr, Rewriter, DWARFLinkerBase::OutputFileType::Object, OutFile,
467+
&DIEBldr, Rewriter, GDBIndexSection,
468+
DWARFLinkerBase::OutputFileType::Object, OutFile,
465469
[&](const Twine &Warning, StringRef Context, const DWARFDie *) {});
466470
Error Err = Streamer->init(TheTriple, Swift5ReflectionSegmentName);
467471
if (Err)
@@ -482,13 +486,12 @@ emitUnit(DIEBuilder &DIEBldr, DIEStreamer &Streamer, DWARFUnit &Unit) {
482486
return {U.UnitOffset, U.UnitLength, TypeHash};
483487
}
484488

485-
static void emitDWOBuilder(const std::string &DWOName,
486-
DIEBuilder &DWODIEBuilder, DWARFRewriter &Rewriter,
487-
DWARFUnit &SplitCU, DWARFUnit &CU,
488-
DWARFRewriter::DWPState &State,
489-
DebugLocWriter &LocWriter,
490-
DebugStrOffsetsWriter &StrOffstsWriter,
491-
DebugStrWriter &StrWriter) {
489+
static void
490+
emitDWOBuilder(const std::string &DWOName, DIEBuilder &DWODIEBuilder,
491+
DWARFRewriter &Rewriter, DWARFUnit &SplitCU, DWARFUnit &CU,
492+
DWARFRewriter::DWPState &State, DebugLocWriter &LocWriter,
493+
DebugStrOffsetsWriter &StrOffstsWriter,
494+
DebugStrWriter &StrWriter, GDBIndex &GDBIndexSection) {
492495
// Populate debug_info and debug_abbrev for current dwo into StringRef.
493496
DWODIEBuilder.generateAbbrevs();
494497
DWODIEBuilder.finish();
@@ -498,8 +501,9 @@ static void emitDWOBuilder(const std::string &DWOName,
498501
std::make_shared<raw_svector_ostream>(OutBuffer);
499502
const object::ObjectFile *File = SplitCU.getContext().getDWARFObj().getFile();
500503
auto TheTriple = std::make_unique<Triple>(File->makeTriple());
501-
std::unique_ptr<DIEStreamer> Streamer = createDIEStreamer(
502-
*TheTriple, *ObjOS, "DwoStreamerInitAug2", DWODIEBuilder, Rewriter);
504+
std::unique_ptr<DIEStreamer> Streamer =
505+
createDIEStreamer(*TheTriple, *ObjOS, "DwoStreamerInitAug2",
506+
DWODIEBuilder, Rewriter, GDBIndexSection);
503507
DWARFRewriter::UnitMetaVectorType TUMetaVector;
504508
DWARFRewriter::UnitMeta CUMI = {0, 0, 0};
505509
if (SplitCU.getContext().getMaxDWOVersion() >= 5) {
@@ -650,6 +654,7 @@ void DWARFRewriter::updateDebugInfo() {
650654

651655
DWARF5AcceleratorTable DebugNamesTable(opts::CreateDebugNames, BC,
652656
*StrWriter);
657+
GDBIndex GDBIndexSection(BC);
653658
DWPState State;
654659
if (opts::WriteDWP)
655660
initDWPState(State);
@@ -702,7 +707,8 @@ void DWARFRewriter::updateDebugInfo() {
702707
TempRangesSectionWriter->finalizeSection();
703708

704709
emitDWOBuilder(DWOName, DWODIEBuilder, *this, **SplitCU, *Unit, State,
705-
DebugLocDWoWriter, DWOStrOffstsWriter, DWOStrWriter);
710+
DebugLocDWoWriter, DWOStrOffstsWriter, DWOStrWriter,
711+
GDBIndexSection);
706712
}
707713

708714
if (Unit->getVersion() >= 5) {
@@ -727,9 +733,10 @@ void DWARFRewriter::updateDebugInfo() {
727733
std::make_unique<raw_svector_ostream>(OutBuffer);
728734
const object::ObjectFile *File = BC.DwCtx->getDWARFObj().getFile();
729735
auto TheTriple = std::make_unique<Triple>(File->makeTriple());
730-
std::unique_ptr<DIEStreamer> Streamer =
731-
createDIEStreamer(*TheTriple, *ObjOS, "TypeStreamer", DIEBlder, *this);
732-
CUOffsetMap OffsetMap = finalizeTypeSections(DIEBlder, *Streamer);
736+
std::unique_ptr<DIEStreamer> Streamer = createDIEStreamer(
737+
*TheTriple, *ObjOS, "TypeStreamer", DIEBlder, *this, GDBIndexSection);
738+
CUOffsetMap OffsetMap =
739+
finalizeTypeSections(DIEBlder, *Streamer, GDBIndexSection);
733740

734741
const bool SingleThreadedMode =
735742
opts::NoThreads || opts::DeterministicDebugInfo;
@@ -759,7 +766,8 @@ void DWARFRewriter::updateDebugInfo() {
759766

760767
finalizeDebugSections(DIEBlder, DebugNamesTable, *Streamer, *ObjOS,
761768
OffsetMap);
762-
updateGdbIndexSection(OffsetMap, CUIndex);
769+
GDBIndexSection.updateGdbIndexSection(OffsetMap, CUIndex,
770+
*ARangesSectionWriter);
763771
}
764772

765773
void DWARFRewriter::updateUnitDebugInfo(
@@ -1427,7 +1435,8 @@ void DWARFRewriter::updateLineTableOffsets(const MCAsmLayout &Layout) {
14271435
}
14281436

14291437
CUOffsetMap DWARFRewriter::finalizeTypeSections(DIEBuilder &DIEBlder,
1430-
DIEStreamer &Streamer) {
1438+
DIEStreamer &Streamer,
1439+
GDBIndex &GDBIndexSection) {
14311440
// update TypeUnit DW_AT_stmt_list with new .debug_line information.
14321441
auto updateLineTable = [&](const DWARFUnit &Unit) -> void {
14331442
DIE *UnitDIE = DIEBlder.getUnitDIEbyUnit(Unit);
@@ -1447,8 +1456,8 @@ CUOffsetMap DWARFRewriter::finalizeTypeSections(DIEBuilder &DIEBlder,
14471456
std::make_shared<raw_svector_ostream>(OutBuffer);
14481457
const object::ObjectFile *File = BC.DwCtx->getDWARFObj().getFile();
14491458
auto TheTriple = std::make_unique<Triple>(File->makeTriple());
1450-
std::unique_ptr<DIEStreamer> TypeStreamer =
1451-
createDIEStreamer(*TheTriple, *ObjOS, "TypeStreamer", DIEBlder, *this);
1459+
std::unique_ptr<DIEStreamer> TypeStreamer = createDIEStreamer(
1460+
*TheTriple, *ObjOS, "TypeStreamer", DIEBlder, *this, GDBIndexSection);
14521461

14531462
// generate debug_info and CUMap
14541463
CUOffsetMap CUMap;

clang-tools-extra/clang-query/QueryParser.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,11 @@ QueryRef QueryParser::endQuery(QueryRef Q) {
144144
StringRef Extra = Line;
145145
StringRef ExtraTrimmed = Extra.ltrim(" \t\v\f\r");
146146

147-
if ((!ExtraTrimmed.empty() && ExtraTrimmed[0] == '\n') ||
148-
(ExtraTrimmed.size() >= 2 && ExtraTrimmed[0] == '\r' &&
149-
ExtraTrimmed[1] == '\n'))
147+
if (ExtraTrimmed.starts_with('\n') || ExtraTrimmed.starts_with("\r\n"))
150148
Q->RemainingContent = Extra;
151149
else {
152150
StringRef TrailingWord = lexWord();
153-
if (!TrailingWord.empty() && TrailingWord.front() == '#') {
151+
if (TrailingWord.starts_with('#')) {
154152
Line = Line.drop_until([](char c) { return c == '\n'; });
155153
Line = Line.drop_while([](char c) { return c == '\n'; });
156154
return endQuery(Q);

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,21 @@ AST_MATCHER(ImplicitCastExpr, isMultiLevelPointerConversion) {
4848
return SourcePtrLevel != TargetPtrLevel;
4949
}
5050

51+
AST_MATCHER(QualType, isPointerType) {
52+
const QualType Type =
53+
Node.getCanonicalType().getNonReferenceType().getUnqualifiedType();
54+
55+
return !Type.isNull() && Type->isPointerType();
56+
}
57+
5158
} // namespace
5259

5360
void MultiLevelImplicitPointerConversionCheck::registerMatchers(
5461
MatchFinder *Finder) {
5562
Finder->addMatcher(
56-
implicitCastExpr(hasCastKind(CK_BitCast), isMultiLevelPointerConversion())
63+
implicitCastExpr(hasCastKind(CK_BitCast), isMultiLevelPointerConversion(),
64+
unless(hasParent(explicitCastExpr(
65+
hasDestinationType(isPointerType())))))
5766
.bind("expr"),
5867
this);
5968
}

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ static constexpr bool RestrictToPODTypesDefault = false;
3232
static constexpr char IgnoreMacrosName[] = "IgnoreMacros";
3333
static constexpr bool IgnoreMacrosDefault = true;
3434

35+
static constexpr char StrictCStandardComplianceName[] =
36+
"StrictCStandardCompliance";
37+
static constexpr bool StrictCStandardComplianceDefault = true;
38+
39+
static constexpr char StrictCppStandardComplianceName[] =
40+
"StrictCppStandardCompliance";
41+
static constexpr bool StrictCppStandardComplianceDefault = true;
42+
3543
namespace {
3644

3745
struct Designators {
@@ -97,7 +105,12 @@ UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
97105
RestrictToPODTypes(
98106
Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)),
99107
IgnoreMacros(
100-
Options.getLocalOrGlobal(IgnoreMacrosName, IgnoreMacrosDefault)) {}
108+
Options.getLocalOrGlobal(IgnoreMacrosName, IgnoreMacrosDefault)),
109+
StrictCStandardCompliance(Options.get(StrictCStandardComplianceName,
110+
StrictCStandardComplianceDefault)),
111+
StrictCppStandardCompliance(
112+
Options.get(StrictCppStandardComplianceName,
113+
StrictCppStandardComplianceDefault)) {}
101114

102115
void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
103116
const auto HasBaseWithFields =
@@ -179,6 +192,9 @@ void UseDesignatedInitializersCheck::storeOptions(
179192
IgnoreSingleElementAggregates);
180193
Options.store(Opts, RestrictToPODTypesName, RestrictToPODTypes);
181194
Options.store(Opts, IgnoreMacrosName, IgnoreMacros);
195+
Options.store(Opts, StrictCStandardComplianceName, StrictCStandardCompliance);
196+
Options.store(Opts, StrictCppStandardComplianceName,
197+
StrictCppStandardCompliance);
182198
}
183199

184200
} // namespace clang::tidy::modernize

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,19 @@ class UseDesignatedInitializersCheck : public ClangTidyCheck {
2929
return TK_IgnoreUnlessSpelledInSource;
3030
}
3131

32+
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
33+
return LangOpts.CPlusPlus20 || LangOpts.C99 ||
34+
(LangOpts.CPlusPlus && !StrictCppStandardCompliance) ||
35+
(!LangOpts.CPlusPlus && !LangOpts.ObjC &&
36+
!StrictCStandardCompliance);
37+
}
38+
3239
private:
3340
bool IgnoreSingleElementAggregates;
3441
bool RestrictToPODTypes;
3542
bool IgnoreMacros;
43+
bool StrictCStandardCompliance;
44+
bool StrictCppStandardCompliance;
3645
};
3746

3847
} // namespace clang::tidy::modernize

clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ void recordRemoval(const DeclStmt &Stmt, ASTContext &Context,
7575
}
7676
}
7777

78-
AST_MATCHER_FUNCTION_P(StatementMatcher, isConstRefReturningMethodCall,
78+
AST_MATCHER_FUNCTION_P(StatementMatcher,
79+
isRefReturningMethodCallWithConstOverloads,
7980
std::vector<StringRef>, ExcludedContainerTypes) {
8081
// Match method call expressions where the `this` argument is only used as
81-
// const, this will be checked in `check()` part. This returned const
82-
// reference is highly likely to outlive the local const reference of the
83-
// variable being declared. The assumption is that the const reference being
84-
// returned either points to a global static variable or to a member of the
85-
// called object.
82+
// const, this will be checked in `check()` part. This returned reference is
83+
// highly likely to outlive the local const reference of the variable being
84+
// declared. The assumption is that the reference being returned either points
85+
// to a global static variable or to a member of the called object.
8686
const auto MethodDecl =
87-
cxxMethodDecl(returns(hasCanonicalType(matchers::isReferenceToConst())))
87+
cxxMethodDecl(returns(hasCanonicalType(referenceType())))
8888
.bind(MethodDeclId);
8989
const auto ReceiverExpr =
9090
ignoringParenImpCasts(declRefExpr(to(varDecl().bind(ObjectArgId))));
@@ -121,7 +121,7 @@ AST_MATCHER_FUNCTION_P(StatementMatcher, initializerReturnsReferenceToConst,
121121
declRefExpr(to(varDecl(hasLocalStorage()).bind(OldVarDeclId)));
122122
return expr(
123123
anyOf(isConstRefReturningFunctionCall(),
124-
isConstRefReturningMethodCall(ExcludedContainerTypes),
124+
isRefReturningMethodCallWithConstOverloads(ExcludedContainerTypes),
125125
ignoringImpCasts(OldVarDeclRef),
126126
ignoringImpCasts(unaryOperator(hasOperatorName("&"),
127127
hasUnaryOperand(OldVarDeclRef)))));
@@ -259,10 +259,11 @@ void UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {
259259
.bind("blockStmt");
260260
};
261261

262-
Finder->addMatcher(LocalVarCopiedFrom(anyOf(isConstRefReturningFunctionCall(),
263-
isConstRefReturningMethodCall(
264-
ExcludedContainerTypes))),
265-
this);
262+
Finder->addMatcher(
263+
LocalVarCopiedFrom(anyOf(
264+
isConstRefReturningFunctionCall(),
265+
isRefReturningMethodCallWithConstOverloads(ExcludedContainerTypes))),
266+
this);
266267

267268
Finder->addMatcher(LocalVarCopiedFrom(declRefExpr(
268269
to(varDecl(hasLocalStorage()).bind(OldVarDeclId)))),

clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
279279
hasParent(callExpr()),
280280
hasSourceExpression(binaryOperator(hasAnyOperatorName("==", "!="))));
281281

282+
auto IsInCompilerGeneratedFunction = hasAncestor(namedDecl(anyOf(
283+
isImplicit(), functionDecl(isDefaulted()), functionTemplateDecl())));
284+
282285
Finder->addMatcher(
283286
traverse(TK_AsIs,
284287
implicitCastExpr(
@@ -299,7 +302,7 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
299302
// additional parens in replacement.
300303
optionally(hasParent(stmt().bind("parentStmt"))),
301304
unless(isInTemplateInstantiation()),
302-
unless(hasAncestor(functionTemplateDecl())))
305+
unless(IsInCompilerGeneratedFunction))
303306
.bind("implicitCastToBool")),
304307
this);
305308

@@ -331,7 +334,7 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
331334
anyOf(hasParent(implicitCastExpr().bind("furtherImplicitCast")),
332335
anything()),
333336
unless(isInTemplateInstantiation()),
334-
unless(hasAncestor(functionTemplateDecl())))),
337+
unless(IsInCompilerGeneratedFunction))),
335338
this);
336339
}
337340

0 commit comments

Comments
 (0)