[ARM] Fix bug in also_compatible_with attribute parser

Check ScopedPrinter pointer before attempting to print the attribute's
parsed information.

Patch by Michael Platings and Victor Campos

Reviewed By: pratlucas

Differential Revision: https://reviews.llvm.org/D132214
This commit is contained in:
Victor Campos 2022-08-19 08:46:55 +01:00
parent 93cf0e8a28
commit 1d66c5ebbc
3 changed files with 16 additions and 8 deletions

View File

@ -42,6 +42,10 @@ protected:
void parseIndexList(SmallVectorImpl<uint8_t> &indexList);
Error parseSubsection(uint32_t length);
void setAttributeString(unsigned tag, StringRef value) {
attributesStr.emplace(tag, value);
}
public:
virtual ~ELFAttributeParser() { static_cast<void>(!cursor.takeError()); }
Error integerAttribute(unsigned tag);

View File

@ -448,14 +448,18 @@ Error ARMAttributeParser::also_compatible_with(AttrType tag) {
}
}
DictScope scope(*sw, "Attribute");
sw->printNumber("Tag", tag);
sw->printString("TagName",
ELFAttrs::attrTypeAsString(tag, tagToStringMap, false));
sw->printStringEscaped("Value", RawStringValue);
if (!Description.empty()) {
sw->printString("Description", Description);
setAttributeString(tag, RawStringValue);
if (sw) {
DictScope scope(*sw, "Attribute");
sw->printNumber("Tag", tag);
sw->printString("TagName",
ELFAttrs::attrTypeAsString(tag, tagToStringMap, false));
sw->printStringEscaped("Value", RawStringValue);
if (!Description.empty()) {
sw->printString("Description", Description);
}
}
cursor.seek(FinalOffset);
return returnValue ? std::move(*returnValue) : Error::success();

View File

@ -53,7 +53,7 @@ Error ELFAttributeParser::stringAttribute(unsigned tag) {
StringRef tagName =
ELFAttrs::attrTypeAsString(tag, tagToStringMap, /*hasTagPrefix=*/false);
StringRef desc = de.getCStrRef(cursor);
attributesStr.insert(std::make_pair(tag, desc));
setAttributeString(tag, desc);
if (sw) {
DictScope scope(*sw, "Attribute");