[Lldb-commits] [lldb] [LLDB] Add an assert to verify sign_bit_pos is within the valid range (NFC) (PR #95678)
via lldb-commits
lldb-commits at lists.llvm.org
Sat Jun 15 11:59:41 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Shivam Gupta (xgupta)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/95678.diff
1 Files Affected:
- (modified) lldb/source/Utility/Scalar.cpp (+15-16)
``````````diff
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/95678
More information about the lldb-commits
mailing list