Skip to content

Commit 69b0cb9

Browse files
committed
Revert "[LEB128] Don't initialize error on success"
This reverts commit 545c8e0.
1 parent fc05a82 commit 69b0cb9

File tree

6 files changed

+10
-12
lines changed

6 files changed

+10
-12
lines changed

lld/COFF/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ static void findKeepUniqueSections(COFFLinkerContext &ctx) {
12581258
const uint8_t *cur = contents.begin();
12591259
while (cur != contents.end()) {
12601260
unsigned size;
1261-
const char *err = nullptr;
1261+
const char *err;
12621262
uint64_t symIndex = decodeULEB128(cur, &size, contents.end(), &err);
12631263
if (err)
12641264
fatal(toString(obj) + ": could not decode addrsig section: " + err);

lld/ELF/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2296,7 +2296,7 @@ static void findKeepUniqueSections(opt::InputArgList &args) {
22962296
const uint8_t *cur = contents.begin();
22972297
while (cur != contents.end()) {
22982298
unsigned size;
2299-
const char *err = nullptr;
2299+
const char *err;
23002300
uint64_t symIndex = decodeULEB128(cur, &size, contents.end(), &err);
23012301
if (err)
23022302
fatal(toString(f) + ": could not decode addrsig section: " + err);

llvm/include/llvm/Support/LEB128.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,14 @@ inline unsigned encodeULEB128(uint64_t Value, uint8_t *p,
125125
}
126126

127127
/// Utility function to decode a ULEB128 value.
128-
///
129-
/// If \p error is non-null, it will point to a static error message,
130-
/// if an error occured. It will not be modified on success.
131128
inline uint64_t decodeULEB128(const uint8_t *p, unsigned *n = nullptr,
132129
const uint8_t *end = nullptr,
133130
const char **error = nullptr) {
134131
const uint8_t *orig_p = p;
135132
uint64_t Value = 0;
136133
unsigned Shift = 0;
134+
if (error)
135+
*error = nullptr;
137136
do {
138137
if (p == end) {
139138
if (error)
@@ -159,16 +158,15 @@ inline uint64_t decodeULEB128(const uint8_t *p, unsigned *n = nullptr,
159158
}
160159

161160
/// Utility function to decode a SLEB128 value.
162-
///
163-
/// If \p error is non-null, it will point to a static error message,
164-
/// if an error occured. It will not be modified on success.
165161
inline int64_t decodeSLEB128(const uint8_t *p, unsigned *n = nullptr,
166162
const uint8_t *end = nullptr,
167163
const char **error = nullptr) {
168164
const uint8_t *orig_p = p;
169165
int64_t Value = 0;
170166
unsigned Shift = 0;
171167
uint8_t Byte;
168+
if (error)
169+
*error = nullptr;
172170
do {
173171
if (p == end) {
174172
if (error)

llvm/lib/Object/MachOObjectFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2996,7 +2996,7 @@ void ExportEntry::pushNode(uint64_t offset) {
29962996
ErrorAsOutParameter ErrAsOutParam(E);
29972997
const uint8_t *Ptr = Trie.begin() + offset;
29982998
NodeState State(Ptr);
2999-
const char *error = nullptr;
2999+
const char *error;
30003000
uint64_t ExportInfoSize = readULEB128(State.Current, &error);
30013001
if (error) {
30023002
*E = malformedError("export info size " + Twine(error) +
@@ -3131,7 +3131,7 @@ void ExportEntry::pushNode(uint64_t offset) {
31313131

31323132
void ExportEntry::pushDownUntilBottom() {
31333133
ErrorAsOutParameter ErrAsOutParam(E);
3134-
const char *error = nullptr;
3134+
const char *error;
31353135
while (Stack.back().NextChildIndex < Stack.back().ChildCount) {
31363136
NodeState &Top = Stack.back();
31373137
CumulativeString.resize(Top.ParentStringLength);

llvm/lib/Support/DataExtractor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ static T getLEB128(StringRef Data, uint64_t *OffsetPtr, Error *Err,
202202
if (isError(Err))
203203
return T();
204204

205-
const char *error = nullptr;
205+
const char *error;
206206
unsigned bytes_read;
207207
T result =
208208
Decoder(Bytes.data() + *OffsetPtr, &bytes_read, Bytes.end(), &error);

llvm/tools/llvm-readobj/ELFDumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5004,7 +5004,7 @@ static Expected<std::vector<uint64_t>> toULEB128Array(ArrayRef<uint8_t> Data) {
50045004
const uint8_t *End = Data.end();
50055005
while (Cur != End) {
50065006
unsigned Size;
5007-
const char *Err = nullptr;
5007+
const char *Err;
50085008
Ret.push_back(decodeULEB128(Cur, &Size, End, &Err));
50095009
if (Err)
50105010
return createError(Err);

0 commit comments

Comments
 (0)