mirror of
https://github.com/intel/llvm.git
synced 2026-01-26 03:56:16 +08:00
[LEB128] Don't initialize error on success
This change removes an unnecessary branch from a hot path. It's also questionable API to override any previous error unconditonally.
This commit is contained in:
@@ -1258,7 +1258,7 @@ static void findKeepUniqueSections(COFFLinkerContext &ctx) {
|
||||
const uint8_t *cur = contents.begin();
|
||||
while (cur != contents.end()) {
|
||||
unsigned size;
|
||||
const char *err;
|
||||
const char *err = nullptr;
|
||||
uint64_t symIndex = decodeULEB128(cur, &size, contents.end(), &err);
|
||||
if (err)
|
||||
fatal(toString(obj) + ": could not decode addrsig section: " + err);
|
||||
|
||||
@@ -2296,7 +2296,7 @@ static void findKeepUniqueSections(opt::InputArgList &args) {
|
||||
const uint8_t *cur = contents.begin();
|
||||
while (cur != contents.end()) {
|
||||
unsigned size;
|
||||
const char *err;
|
||||
const char *err = nullptr;
|
||||
uint64_t symIndex = decodeULEB128(cur, &size, contents.end(), &err);
|
||||
if (err)
|
||||
fatal(toString(f) + ": could not decode addrsig section: " + err);
|
||||
|
||||
@@ -125,14 +125,15 @@ inline unsigned encodeULEB128(uint64_t Value, uint8_t *p,
|
||||
}
|
||||
|
||||
/// Utility function to decode a ULEB128 value.
|
||||
///
|
||||
/// If \p error is non-null, it will point to a static error message,
|
||||
/// if an error occured. It will not be modified on success.
|
||||
inline uint64_t decodeULEB128(const uint8_t *p, unsigned *n = nullptr,
|
||||
const uint8_t *end = nullptr,
|
||||
const char **error = nullptr) {
|
||||
const uint8_t *orig_p = p;
|
||||
uint64_t Value = 0;
|
||||
unsigned Shift = 0;
|
||||
if (error)
|
||||
*error = nullptr;
|
||||
do {
|
||||
if (p == end) {
|
||||
if (error)
|
||||
@@ -158,6 +159,9 @@ inline uint64_t decodeULEB128(const uint8_t *p, unsigned *n = nullptr,
|
||||
}
|
||||
|
||||
/// Utility function to decode a SLEB128 value.
|
||||
///
|
||||
/// If \p error is non-null, it will point to a static error message,
|
||||
/// if an error occured. It will not be modified on success.
|
||||
inline int64_t decodeSLEB128(const uint8_t *p, unsigned *n = nullptr,
|
||||
const uint8_t *end = nullptr,
|
||||
const char **error = nullptr) {
|
||||
@@ -165,8 +169,6 @@ inline int64_t decodeSLEB128(const uint8_t *p, unsigned *n = nullptr,
|
||||
int64_t Value = 0;
|
||||
unsigned Shift = 0;
|
||||
uint8_t Byte;
|
||||
if (error)
|
||||
*error = nullptr;
|
||||
do {
|
||||
if (p == end) {
|
||||
if (error)
|
||||
|
||||
@@ -2996,7 +2996,7 @@ void ExportEntry::pushNode(uint64_t offset) {
|
||||
ErrorAsOutParameter ErrAsOutParam(E);
|
||||
const uint8_t *Ptr = Trie.begin() + offset;
|
||||
NodeState State(Ptr);
|
||||
const char *error;
|
||||
const char *error = nullptr;
|
||||
uint64_t ExportInfoSize = readULEB128(State.Current, &error);
|
||||
if (error) {
|
||||
*E = malformedError("export info size " + Twine(error) +
|
||||
@@ -3131,7 +3131,7 @@ void ExportEntry::pushNode(uint64_t offset) {
|
||||
|
||||
void ExportEntry::pushDownUntilBottom() {
|
||||
ErrorAsOutParameter ErrAsOutParam(E);
|
||||
const char *error;
|
||||
const char *error = nullptr;
|
||||
while (Stack.back().NextChildIndex < Stack.back().ChildCount) {
|
||||
NodeState &Top = Stack.back();
|
||||
CumulativeString.resize(Top.ParentStringLength);
|
||||
|
||||
@@ -202,7 +202,7 @@ static T getLEB128(StringRef Data, uint64_t *OffsetPtr, Error *Err,
|
||||
if (isError(Err))
|
||||
return T();
|
||||
|
||||
const char *error;
|
||||
const char *error = nullptr;
|
||||
unsigned bytes_read;
|
||||
T result =
|
||||
Decoder(Bytes.data() + *OffsetPtr, &bytes_read, Bytes.end(), &error);
|
||||
|
||||
@@ -2126,7 +2126,7 @@ void COFFDumper::printAddrsig() {
|
||||
const uint8_t *End = AddrsigContents.bytes_end();
|
||||
while (Cur != End) {
|
||||
unsigned Size;
|
||||
const char *Err;
|
||||
const char *Err = nullptr;
|
||||
uint64_t SymIndex = decodeULEB128(Cur, &Size, End, &Err);
|
||||
if (Err)
|
||||
reportError(createError(Err), Obj->getFileName());
|
||||
|
||||
@@ -5004,7 +5004,7 @@ static Expected<std::vector<uint64_t>> toULEB128Array(ArrayRef<uint8_t> Data) {
|
||||
const uint8_t *End = Data.end();
|
||||
while (Cur != End) {
|
||||
unsigned Size;
|
||||
const char *Err;
|
||||
const char *Err = nullptr;
|
||||
Ret.push_back(decodeULEB128(Cur, &Size, End, &Err));
|
||||
if (Err)
|
||||
return createError(Err);
|
||||
|
||||
Reference in New Issue
Block a user