Skip to content

Commit efa1d0d

Browse files
committed
[LEB128] Mark error condition with LLVM_UNLIKELY
1 parent 963b186 commit efa1d0d

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

llvm/include/llvm/Support/LEB128.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,16 @@ inline uint64_t decodeULEB128(const uint8_t *p, unsigned *n = nullptr,
135135
uint64_t Value = 0;
136136
unsigned Shift = 0;
137137
do {
138-
if (p == end) {
138+
if (LLVM_UNLIKELY(p == end)) {
139139
if (error)
140140
*error = "malformed uleb128, extends past end";
141141
Value = 0;
142142
break;
143143
}
144144
uint64_t Slice = *p & 0x7f;
145-
if (Shift >= 63 && ((Shift == 63 && (Slice << Shift >> Shift) != Slice) ||
146-
(Shift > 63 && Slice != 0))) {
145+
if (LLVM_UNLIKELY(Shift >= 63) &&
146+
((Shift == 63 && (Slice << Shift >> Shift) != Slice) ||
147+
(Shift > 63 && Slice != 0))) {
147148
if (error)
148149
*error = "uleb128 too big for uint64";
149150
Value = 0;
@@ -169,7 +170,7 @@ inline int64_t decodeSLEB128(const uint8_t *p, unsigned *n = nullptr,
169170
unsigned Shift = 0;
170171
uint8_t Byte;
171172
do {
172-
if (p == end) {
173+
if (LLVM_UNLIKELY(p == end)) {
173174
if (error)
174175
*error = "malformed sleb128, extends past end";
175176
if (n)
@@ -178,8 +179,9 @@ inline int64_t decodeSLEB128(const uint8_t *p, unsigned *n = nullptr,
178179
}
179180
Byte = *p;
180181
uint64_t Slice = Byte & 0x7f;
181-
if ((Shift >= 63) && ((Shift == 63 && Slice != 0 && Slice != 0x7f) ||
182-
(Shift > 63 && Slice != (Value < 0 ? 0x7f : 0x00)))) {
182+
if (LLVM_UNLIKELY(Shift >= 63) &&
183+
((Shift == 63 && Slice != 0 && Slice != 0x7f) ||
184+
(Shift > 63 && Slice != (Value < 0 ? 0x7f : 0x00)))) {
183185
if (error)
184186
*error = "sleb128 too big for int64";
185187
if (n)

0 commit comments

Comments
 (0)