Skip to content

Commit 83381ba

Browse files
authored
[LLDB] Add negative number parsing to DIL (#144557)
1 parent 493a359 commit 83381ba

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

lldb/source/ValueObject/DILParser.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,15 @@ void DILParser::BailOut(const std::string &error, uint32_t loc,
348348
// ? Integer constant ?
349349
//
350350
std::optional<int64_t> DILParser::ParseIntegerConstant() {
351-
auto spelling = CurToken().GetSpelling();
352-
llvm::StringRef spelling_ref = spelling;
351+
std::string number_spelling;
352+
if (CurToken().GetKind() == Token::minus) {
353+
// StringRef::getAsInteger<>() can parse negative numbers.
354+
// FIXME: Remove this once unary minus operator is added.
355+
number_spelling = "-";
356+
m_dil_lexer.Advance();
357+
}
358+
number_spelling.append(CurToken().GetSpelling());
359+
llvm::StringRef spelling_ref = number_spelling;
353360
int64_t raw_value;
354361
if (!spelling_ref.getAsInteger<int64_t>(0, raw_value)) {
355362
m_dil_lexer.Advance();

lldb/test/API/commands/frame/var-dil/basics/ArraySubscript/TestFrameVarDILArraySubscript.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,7 @@ def test_subscript(self):
6060
self.expect_var_path("*(&int_arr[1])", value="2")
6161

6262
# Test for negative index.
63-
self.expect(
64-
"frame var 'int_arr[-1]'",
65-
error=True,
66-
substrs=["failed to parse integer constant"],
67-
)
63+
self.expect_var_path("int_ptr_1[-1]", True, value="1")
6864

6965
# Test for floating point index
7066
self.expect(

lldb/test/API/commands/frame/var-dil/basics/ArraySubscript/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
int main(int argc, char **argv) {
44
int int_arr[] = {1, 2, 3};
55
int *int_ptr = int_arr;
6+
int *int_ptr_1 = &int_arr[1];
67
int(&int_arr_ref)[3] = int_arr;
78
void *p_void = (void *)int_arr;
89

0 commit comments

Comments
 (0)