Skip to content

[clangd] Guard against trivial FunctionProtoTypeLoc when creating inlay hints #143087

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 1 commit into from
Jun 9, 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
7 changes: 6 additions & 1 deletion clang-tools-extra/clangd/InlayHints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/identity.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormatVariadic.h"
Expand Down Expand Up @@ -368,7 +369,11 @@ static FunctionProtoTypeLoc getPrototypeLoc(Expr *Fn) {
}

if (auto F = Target.getAs<FunctionProtoTypeLoc>()) {
return F;
// In some edge cases the AST can contain a "trivial" FunctionProtoTypeLoc
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: We have a duplicated one in SemaCodeComplete.cpp, see the FIXME on line 337. I guess the same issue should happen there as well (signaturehelp?). I see options 1) duplicate the workaround 2) unify these two implementations. Either works for me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the reminder about this. Now that we've upstreamed HeuristicResolver, it's a good place for a unified implementation of this sort of thing. I'll do that in #143240.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Posted #143345 for this.

// which has null parameters. Avoid these as they don't contain useful
// information.
if (llvm::all_of(F.getParams(), llvm::identity<ParmVarDecl *>()))
return F;
}

return {};
Expand Down
5 changes: 5 additions & 0 deletions clang-tools-extra/clangd/unittests/InlayHintTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,11 +997,16 @@ TEST(ParameterHints, FunctionPointer) {
f3_t f3;
using f4_t = void(__stdcall *)(int param);
f4_t f4;
__attribute__((noreturn)) f4_t f5;
void bar() {
f1($f1[[42]]);
f2($f2[[42]]);
f3($f3[[42]]);
f4($f4[[42]]);
// This one runs into an edge case in clang's type model
// and we can't extract the parameter name. But at least
// we shouldn't crash.
f5(42);
}
)cpp",
ExpectedHint{"param: ", "f1"}, ExpectedHint{"param: ", "f2"},
Expand Down