https://github.com/kuilpd created https://github.com/llvm/llvm-project/pull/144557
None >From 49a615d48433dabc6f05848f40e38601222efe38 Mon Sep 17 00:00:00 2001 From: Ilia Kuklin <ikuk...@accesssoftek.com> Date: Tue, 17 Jun 2025 21:06:49 +0500 Subject: [PATCH] [LLDB] Add negative number parsing to DIL --- lldb/source/ValueObject/DILParser.cpp | 11 +++++++++-- .../ArraySubscript/TestFrameVarDILArraySubscript.py | 6 +----- .../frame/var-dil/basics/ArraySubscript/main.cpp | 1 + 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lldb/source/ValueObject/DILParser.cpp b/lldb/source/ValueObject/DILParser.cpp index 32af0820acb98..146ef8154283e 100644 --- a/lldb/source/ValueObject/DILParser.cpp +++ b/lldb/source/ValueObject/DILParser.cpp @@ -348,8 +348,15 @@ void DILParser::BailOut(const std::string &error, uint32_t loc, // ? Integer constant ? // std::optional<int64_t> DILParser::ParseIntegerConstant() { - auto spelling = CurToken().GetSpelling(); - llvm::StringRef spelling_ref = spelling; + std::string number_spelling; + if (CurToken().GetKind() == Token::minus) { + // StringRef::getAsInteger<>() can parse negative numbers. + // Remove this once unary minus operator is added. + number_spelling = "-"; + m_dil_lexer.Advance(); + } + number_spelling.append(CurToken().GetSpelling()); + llvm::StringRef spelling_ref = number_spelling; int64_t raw_value; if (!spelling_ref.getAsInteger<int64_t>(0, raw_value)) { m_dil_lexer.Advance(); diff --git a/lldb/test/API/commands/frame/var-dil/basics/ArraySubscript/TestFrameVarDILArraySubscript.py b/lldb/test/API/commands/frame/var-dil/basics/ArraySubscript/TestFrameVarDILArraySubscript.py index c90e0eaa63638..c0ef29fab8597 100644 --- a/lldb/test/API/commands/frame/var-dil/basics/ArraySubscript/TestFrameVarDILArraySubscript.py +++ b/lldb/test/API/commands/frame/var-dil/basics/ArraySubscript/TestFrameVarDILArraySubscript.py @@ -60,11 +60,7 @@ def test_subscript(self): self.expect_var_path("*(&int_arr[1])", value="2") # Test for negative index. - self.expect( - "frame var 'int_arr[-1]'", - error=True, - substrs=["failed to parse integer constant"], - ) + self.expect_var_path("int_ptr_1[-1]", True, value="1") # Test for floating point index self.expect( diff --git a/lldb/test/API/commands/frame/var-dil/basics/ArraySubscript/main.cpp b/lldb/test/API/commands/frame/var-dil/basics/ArraySubscript/main.cpp index 485666ae46c20..a9a3612dfae5a 100644 --- a/lldb/test/API/commands/frame/var-dil/basics/ArraySubscript/main.cpp +++ b/lldb/test/API/commands/frame/var-dil/basics/ArraySubscript/main.cpp @@ -3,6 +3,7 @@ int main(int argc, char **argv) { int int_arr[] = {1, 2, 3}; int *int_ptr = int_arr; + int *int_ptr_1 = &int_arr[1]; int(&int_arr_ref)[3] = int_arr; void *p_void = (void *)int_arr; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits