================
@@ -1342,14 +1277,53 @@ Interpreter::Visit(const BitFieldExtractionNode &node) {
return llvm::make_error<DILDiagnosticError>(
m_expr, "could not get the index as an integer", node.GetLocation());
+ // Reject negative indices before the swap below, so the diagnostic reports
+ // the range as the user wrote it. A negative index would also wrap to a huge
+ // offset in the uint32_t GetSyntheticBitFieldChild call below.
+ if (first_index < 0 || last_index < 0) {
+ std::string message =
+ llvm::formatv("bitfield range {0}:{1} is not valid (negative index)",
+ first_index, last_index);
+ return llvm::make_error<DILDiagnosticError>(m_expr, message,
+ node.GetLocation());
+ }
+
// if the format given is [high-low], swap range
if (first_index > last_index)
std::swap(first_index, last_index);
+ // GetMaxU64Bitfield in the data layer only supports up to 64 bits (it
asserts
+ // bitfield_bit_size <= 64 and otherwise shifts out of bounds), so reject a
+ // wider range here.
+ if (last_index - first_index + 1 > 64) {
----------------
firmiana402 wrote:
Could we avoid the `+ 1` in signed arithmetic here? For a range such as
`value[0:9223372036854775807]`, this expression overflows `int64_t` before the
comparison. Since the indices are already non-negative and normalized,
`last_index - first_index >= 64` is equivalent and avoids the overflow.
https://github.com/llvm/llvm-project/pull/213055
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits