Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions llvm/lib/DebugInfo/DWARF/DWARFAcceleratorTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ LLVM_DUMP_METHOD void AppleAcceleratorTable::dump(raw_ostream &OS) const {
}

for (unsigned HashIdx = Index; HashIdx < Hdr.HashCount; ++HashIdx) {
uint64_t HashOffset = HashesBase + HashIdx*4;
uint64_t OffsetsOffset = OffsetsBase + HashIdx*4;
uint64_t HashOffset = HashesBase + HashIdx * 4;
uint64_t OffsetsOffset = OffsetsBase + HashIdx * 4;
uint32_t Hash = AccelSection.getU32(&HashOffset);

if (Hash % Hdr.BucketCount != Bucket)
Expand Down Expand Up @@ -443,7 +443,7 @@ void DWARFDebugNames::Header::dump(ScopedPrinter &W) const {
}

Error DWARFDebugNames::Header::extract(const DWARFDataExtractor &AS,
uint64_t *Offset) {
uint64_t *Offset) {
auto HeaderError = [Offset = *Offset](Error E) {
return createStringError(errc::illegal_byte_sequence,
"parsing .debug_names header at 0x%" PRIx64 ": %s",
Expand Down Expand Up @@ -830,8 +830,9 @@ bool DWARFDebugNames::NameIndex::dumpEntry(ScopedPrinter &W,
uint64_t EntryId = *Offset;
auto EntryOr = getEntry(Offset);
if (!EntryOr) {
handleAllErrors(EntryOr.takeError(), [](const SentinelError &) {},
[&W](const ErrorInfoBase &EI) { EI.log(W.startLine()); });
handleAllErrors(
EntryOr.takeError(), [](const SentinelError &) {},
[&W](const ErrorInfoBase &EI) { EI.log(W.startLine()); });
return false;
}

Expand Down Expand Up @@ -1117,7 +1118,8 @@ std::optional<StringRef> llvm::StripTemplateParameters(StringRef Name) {
//
// We look for > at the end but if it does not contain any < then we
// have something like operator>>. We check for the operator<=> case.
if (!Name.ends_with(">") || Name.count("<") == 0 || Name.ends_with("<=>"))
if (Name.starts_with("<") || !Name.ends_with(">") || Name.count("<") == 0 ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this Name.starts_with("<") check anymore right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct. I can remove it.

Name.ends_with("<=>"))
return {};

// How many < until we have the start of the template parameters.
Expand Down
14 changes: 14 additions & 0 deletions llvm/unittests/DebugInfo/DWARF/DWARFAcceleratorTableTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,18 @@ TEST(DWARFDebugNames, UnsupportedForm) {
Sections,
FailedWithMessage("unsupported Form for YAML debug_names emitter"));
}

TEST(DWARFDebugNames, TestStripTemplateParameters) {

std::optional<StringRef> stripped_name;
// Make sure we can extract the name "foo" from the template parameters.
stripped_name = StripTemplateParameters("foo<int>");
ASSERT_TRUE(stripped_name.has_value());
ASSERT_EQ(*stripped_name, StringRef("foo"));
// Make sure that we don't get an empty name back when the string starts with
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the comment says "we DON'T get an empty name", but the assert seems to be the opposite?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reworded the comment to indicate we expect to not get a string back. Previously we were getting an empty string back from this call.

// '<'.
stripped_name = StripTemplateParameters("<int>");
ASSERT_FALSE(stripped_name.has_value());
}

} // end anonymous namespace
Loading