Skip to content

Commit 586c375

Browse files
committed
[lldb] Remove [US]IntValueIsValidForSize from CommandObjectMemory
Use llvm::is(U)IntN (MathExtras.h) instead.
1 parent e2d24d9 commit 586c375

File tree

1 file changed

+6
-30
lines changed

1 file changed

+6
-30
lines changed

lldb/source/Commands/CommandObjectMemory.cpp

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
#include "lldb/Utility/DataBufferHeap.h"
3434
#include "lldb/Utility/DataBufferLLVM.h"
3535
#include "lldb/Utility/StreamString.h"
36-
37-
36+
#include "llvm/Support/MathExtras.h"
3837
#include <cinttypes>
3938
#include <memory>
4039

@@ -1281,29 +1280,6 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
12811280

12821281
Options *GetOptions() override { return &m_option_group; }
12831282

1284-
bool UIntValueIsValidForSize(uint64_t uval64, size_t total_byte_size) {
1285-
if (total_byte_size > 8)
1286-
return false;
1287-
1288-
if (total_byte_size == 8)
1289-
return true;
1290-
1291-
const uint64_t max = ((uint64_t)1 << (uint64_t)(total_byte_size * 8)) - 1;
1292-
return uval64 <= max;
1293-
}
1294-
1295-
bool SIntValueIsValidForSize(int64_t sval64, size_t total_byte_size) {
1296-
if (total_byte_size > 8)
1297-
return false;
1298-
1299-
if (total_byte_size == 8)
1300-
return true;
1301-
1302-
const int64_t max = ((int64_t)1 << (uint64_t)(total_byte_size * 8 - 1)) - 1;
1303-
const int64_t min = ~(max);
1304-
return min <= sval64 && sval64 <= max;
1305-
}
1306-
13071283
protected:
13081284
bool DoExecute(Args &command, CommandReturnObject &result) override {
13091285
// No need to check "process" for validity as eCommandRequiresProcess
@@ -1449,7 +1425,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
14491425
"'%s' is not a valid hex string value.\n", entry.c_str());
14501426
result.SetStatus(eReturnStatusFailed);
14511427
return false;
1452-
} else if (!UIntValueIsValidForSize(uval64, item_byte_size)) {
1428+
} else if (!llvm::isUIntN(item_byte_size * 8, uval64)) {
14531429
result.AppendErrorWithFormat("Value 0x%" PRIx64
14541430
" is too large to fit in a %" PRIu64
14551431
" byte unsigned integer value.\n",
@@ -1477,7 +1453,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
14771453
"'%s' is not a valid binary string value.\n", entry.c_str());
14781454
result.SetStatus(eReturnStatusFailed);
14791455
return false;
1480-
} else if (!UIntValueIsValidForSize(uval64, item_byte_size)) {
1456+
} else if (!llvm::isUIntN(item_byte_size * 8, uval64)) {
14811457
result.AppendErrorWithFormat("Value 0x%" PRIx64
14821458
" is too large to fit in a %" PRIu64
14831459
" byte unsigned integer value.\n",
@@ -1516,7 +1492,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
15161492
"'%s' is not a valid signed decimal value.\n", entry.c_str());
15171493
result.SetStatus(eReturnStatusFailed);
15181494
return false;
1519-
} else if (!SIntValueIsValidForSize(sval64, item_byte_size)) {
1495+
} else if (!llvm::isIntN(item_byte_size * 8, sval64)) {
15201496
result.AppendErrorWithFormat(
15211497
"Value %" PRIi64 " is too large or small to fit in a %" PRIu64
15221498
" byte signed integer value.\n",
@@ -1535,7 +1511,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
15351511
entry.c_str());
15361512
result.SetStatus(eReturnStatusFailed);
15371513
return false;
1538-
} else if (!UIntValueIsValidForSize(uval64, item_byte_size)) {
1514+
} else if (!llvm::isUIntN(item_byte_size * 8, uval64)) {
15391515
result.AppendErrorWithFormat("Value %" PRIu64
15401516
" is too large to fit in a %" PRIu64
15411517
" byte unsigned integer value.\n",
@@ -1552,7 +1528,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
15521528
"'%s' is not a valid octal string value.\n", entry.c_str());
15531529
result.SetStatus(eReturnStatusFailed);
15541530
return false;
1555-
} else if (!UIntValueIsValidForSize(uval64, item_byte_size)) {
1531+
} else if (!llvm::isUIntN(item_byte_size * 8, uval64)) {
15561532
result.AppendErrorWithFormat("Value %" PRIo64
15571533
" is too large to fit in a %" PRIu64
15581534
" byte unsigned integer value.\n",

0 commit comments

Comments
 (0)