Skip to content
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

Clangd crash in Namer::VisitCXXMemberCallExpr() in InlayHints.cpp #1873

Closed
HighCommander4 opened this issue Dec 21, 2023 · 4 comments · Fixed by llvm/llvm-project#76492
Closed
Assignees

Comments

@HighCommander4
Copy link

HighCommander4 commented Dec 21, 2023

I'm getting a crash in this function.

I don't have a reduced test case at the moment, but just eyeballing the function, it's unconditionally dereferencing E->getMethodDecl() and E->getImplicitObjectArgument(), and either of those could potentially be null.

This is a regression from https://reviews.llvm.org/D155421 which introduced this code.

cc @sam-mccall, @hokein

@hokein
Copy link
Contributor

hokein commented Dec 22, 2023

Thanks. I think your analysis is right:

  • it is unlikely that the parameter E of VisitCXXMemberCallExpr will be null
  • E->getMethodDecl() could probably return nullptr (for invalid code)

We should make a sanity check for the E->getMethodDecl() there, it would be great to have a reproduced testcase, but if it is too hard, I think it is fine.

@HighCommander4
Copy link
Author

HighCommander4 commented Dec 28, 2023

Reduced testcase:

class A {};

using Predicate = bool(A::*)();
void foo(A* a, Predicate p) {
  if ((a->*p)()) {
  }
}

Note that this is valid code.

@HighCommander4
Copy link
Author

When the call is through a pointer to a member, CXXMemberCallExpr::getCallee() is (after unwrapping parens) a BinaryOperator (with the operator being ->*).

getMethodDecl() only returns non-null if the callee is a MemberExpr.

@HighCommander4
Copy link
Author

Proposed fix: llvm/llvm-project#76492

@HighCommander4 HighCommander4 self-assigned this Dec 28, 2023
HighCommander4 added a commit to HighCommander4/llvm-project that referenced this issue Dec 29, 2023
…k-end hint

For calls through a pointer to member, CXXMemberCallExpr::getCallee() is
a BinaryOperator with operator ->* (after unwrapping parens).

getMethodDecl() only returns non-null if the callee is a MemberExpr.

Fixes clangd/clangd#1873
HighCommander4 added a commit to llvm/llvm-project that referenced this issue Dec 29, 2023
…k-end hint (#76492)

For calls through a pointer to member, CXXMemberCallExpr::getCallee() is
a BinaryOperator with operator ->* (after unwrapping parens).

getMethodDecl() only returns non-null if the callee is a MemberExpr.

Fixes clangd/clangd#1873
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants