Skip to content

[LLDB] Add negative number parsing to DIL #144557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lldb/source/ValueObject/DILParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a FIXME?

// FIXME: 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading