Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
clangimport: drop redundant per-branch typeIndex guards in getSpelling
  • Loading branch information
Nussu06 committed Oct 2, 2026
commit 9781751b103810ce0c357f7df0eb1b3253e5cf63
4 changes: 0 additions & 4 deletions lib/clangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,10 @@ std::string clangimport::AstNode::getSpelling() const
if (nodeType == FunctionDecl || nodeType == CXXConstructorDecl || nodeType == CXXMethodDecl) {
while (typeIndex >= 0 && mExtTokens[typeIndex][0] != '\'')
typeIndex--;
if (typeIndex <= 0)
return "";
}
if (nodeType == DeclRefExpr) {
while (typeIndex > 0 && std::isalpha(mExtTokens[typeIndex][0]))
typeIndex--;
if (typeIndex <= 0)
return "";
}
if (typeIndex <= 0)
return "";
Comment on lines +430 to +431

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is an AI review. Take it with a grain of salt and feel free to reject it by resolving the comment.

The fix looks correct. I verified that the new crash2 test fails on main (built with -D_GLIBCXX_ASSERTIONS: Assertion '__n < this->size()' failed in getSpelling()) and passes with this PR.

The description says the guard is hoisted, but the two existing if (typeIndex <= 0) return ""; checks in the FunctionDecl/CXXConstructorDecl/CXXMethodDecl and DeclRefExpr branches above are kept. They are now redundant, since this new check covers them. Maybe remove them so there is only one guard? I tried that locally and TestClangImport still passes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point, those two are redundant now. Dropped both so there's just the single guard before the index. TestClangImport still passes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is an AI review take it with a grain of salt. Please feel free to reject it by clicking on Resolve button

Thanks, the update looks good to me.

FYI: #8903 also adds a test right after crash() and a TEST_CASE line in the same place in test/testclangimport.cpp, so whichever of the two PRs is merged second will get a trivial merge conflict.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Noted, I checked and the two do overlap on the TEST_CASE line and the spot after crash(). Once one of them is merged I'll rebase the other and resolve it.

Expand Down
Loading