[Lldb-commits] [lldb] [LLDB] Add an assert to verify sign_bit_pos is within the valid range (NFC) (PR #95678)
Shivam Gupta via lldb-commits
lldb-commits at lists.llvm.org
Sat Jun 15 11:59:11 PDT 2024
https://github.com/xgupta created https://github.com/llvm/llvm-project/pull/95678
None
>From 74efb6ae3187fe1e67e61cdca1f99b9de8146db4 Mon Sep 17 00:00:00 2001
From: Shivam Gupta <shivam98.tkg at gmail.com>
Date: Sun, 16 Jun 2024 00:21:51 +0530
Subject: [PATCH] [LLDB] Add an assert to verify sign_bit_pos is within the
valid range
---
lldb/source/Utility/Scalar.cpp | 31 +++++++++++++++----------------
1 file changed, 15 insertions(+), 16 deletions(-)
diff --git a/lldb/source/Utility/Scalar.cpp b/lldb/source/Utility/Scalar.cpp
index c680101aa9efa..6e2f1ca4c1613 100644
--- a/lldb/source/Utility/Scalar.cpp
+++ b/lldb/source/Utility/Scalar.cpp
@@ -745,26 +745,25 @@ Status Scalar::SetValueFromData(const DataExtractor &data,
bool Scalar::SignExtend(uint32_t sign_bit_pos) {
const uint32_t max_bit_pos = GetByteSize() * 8;
+ assert(sign_bit_pos < max_bit_pos);
- if (sign_bit_pos < max_bit_pos) {
- switch (m_type) {
- case Scalar::e_void:
- case Scalar::e_float:
- return false;
+ switch (m_type) {
+ case Scalar::e_void:
+ case Scalar::e_float:
+ return false;
- case Scalar::e_int:
- if (sign_bit_pos < (max_bit_pos - 1)) {
- llvm::APInt sign_bit = llvm::APInt::getSignMask(sign_bit_pos + 1);
- llvm::APInt bitwize_and = m_integer & sign_bit;
- if (bitwize_and.getBoolValue()) {
- llvm::APInt mask =
- ~(sign_bit) + llvm::APInt(m_integer.getBitWidth(), 1);
- m_integer |= APSInt(std::move(mask), m_integer.isUnsigned());
- }
- return true;
+ case Scalar::e_int:
+ if (sign_bit_pos < (max_bit_pos - 1)) {
+ llvm::APInt sign_bit = llvm::APInt::getSignMask(sign_bit_pos + 1);
+ llvm::APInt bitwize_and = m_integer & sign_bit;
+ if (bitwize_and.getBoolValue()) {
+ llvm::APInt mask =
+ ~(sign_bit) + llvm::APInt(m_integer.getBitWidth(), 1);
+ m_integer |= APSInt(std::move(mask), m_integer.isUnsigned());
}
- break;
+ return true;
}
+ break;
}
return false;
}
More information about the lldb-commits
mailing list