Skip to content

Commit 99cf9b3

Browse files
committed
Fix usage of out-of-scope variable.
Change TagsNamesMap to be static.
1 parent 299e2c6 commit 99cf9b3

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

llvm/include/llvm/Support/AArch64AttributeParser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace llvm {
1616

1717
class AArch64AttributeParser : public ELFExtendedAttrParser {
18-
static std::vector<SubsectionAndTagToTagName> returnTagsNamesMap();
18+
static std::vector<SubsectionAndTagToTagName> &returnTagsNamesMap();
1919

2020
public:
2121
AArch64AttributeParser(ScopedPrinter *Sw)

llvm/include/llvm/Support/ELFAttrParserExtended.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,12 @@ class ELFExtendedAttrParser : public ELFAttributeParser {
4242
std::optional<StringRef> getAttributeString(StringRef BuildAttrSubsectionName,
4343
unsigned Tag) const override;
4444

45-
ELFExtendedAttrParser(ScopedPrinter *Sw,
46-
std::vector<SubsectionAndTagToTagName> TagsNamesMap)
45+
ELFExtendedAttrParser(
46+
ScopedPrinter *Sw,
47+
const std::vector<SubsectionAndTagToTagName> TagsNamesMap)
4748
: Sw(Sw), TagsNamesMap(TagsNamesMap) {}
48-
ELFExtendedAttrParser(std::vector<SubsectionAndTagToTagName> TagsNamesMap)
49+
ELFExtendedAttrParser(
50+
const std::vector<SubsectionAndTagToTagName> TagsNamesMap)
4951
: Sw(nullptr), TagsNamesMap(TagsNamesMap) {}
5052
};
5153
} // namespace llvm

llvm/lib/Support/AArch64AttributeParser.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99

1010
#include "llvm/Support/AArch64AttributeParser.h"
1111

12-
std::vector<llvm::SubsectionAndTagToTagName>
12+
std::vector<llvm::SubsectionAndTagToTagName> &
1313
llvm::AArch64AttributeParser::returnTagsNamesMap() {
14-
return {{"aeabi_pauthabi", 1, "Tag_PAuth_Platform"},
15-
{"aeabi_pauthabi", 2, "Tag_PAuth_Schema"},
16-
{"aeabi_feature_and_bits", 0, "Tag_Feature_BTI"},
17-
{"aeabi_feature_and_bits", 1, "Tag_Feature_PAC"},
18-
{"aeabi_feature_and_bits", 2, "Tag_Feature_GCS"}};
14+
static std::vector<SubsectionAndTagToTagName> TagsNamesMap = {
15+
{"aeabi_pauthabi", 1, "Tag_PAuth_Platform"},
16+
{"aeabi_pauthabi", 2, "Tag_PAuth_Schema"},
17+
{"aeabi_feature_and_bits", 0, "Tag_Feature_BTI"},
18+
{"aeabi_feature_and_bits", 1, "Tag_Feature_PAC"},
19+
{"aeabi_feature_and_bits", 2, "Tag_Feature_GCS"}};
20+
return TagsNamesMap;
1921
}

llvm/lib/Support/ELFAttrParserExtended.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,17 @@ Error ELFExtendedAttrParser::parse(ArrayRef<uint8_t> Section,
136136
uint64_t Tag = De.getULEB128(Cursor);
137137

138138
StringRef TagName = getTagName(VendorName, Tag);
139-
if ("" == TagName)
140-
TagName = StringRef(utostr(Tag));
141139

142140
uint64_t ValueInt = 0;
143141
std::string ValueStr = "";
144142
if (Type) { // type==1 --> ntbs
145143
ValueStr = De.getCStrRef(Cursor);
146144
if (Sw)
147-
Sw->printString(TagName, ValueStr);
145+
Sw->printString("" != TagName ? TagName : utostr(Tag), ValueStr);
148146
} else { // type==0 --> uleb128
149-
uint64_t ValueInt = De.getULEB128(Cursor);
147+
ValueInt = De.getULEB128(Cursor);
150148
if (Sw)
151-
Sw->printNumber(TagName, ValueInt);
149+
Sw->printNumber("" != TagName ? TagName : utostr(Tag), ValueInt);
152150
}
153151

154152
// populate data structure

0 commit comments

Comments
 (0)