Skip to content

Commit 392bd57

Browse files
[clangd] Guard against trivial FunctionProtoTypeLoc when creating inlay hints (#143087)
Fixes #142608
1 parent e27876a commit 392bd57

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang-tools-extra/clangd/InlayHints.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "llvm/ADT/StringExtras.h"
3434
#include "llvm/ADT/StringRef.h"
3535
#include "llvm/ADT/Twine.h"
36+
#include "llvm/ADT/identity.h"
3637
#include "llvm/Support/Casting.h"
3738
#include "llvm/Support/ErrorHandling.h"
3839
#include "llvm/Support/FormatVariadic.h"
@@ -375,7 +376,11 @@ static FunctionProtoTypeLoc getPrototypeLoc(Expr *Fn) {
375376
}
376377

377378
if (auto F = Target.getAs<FunctionProtoTypeLoc>()) {
378-
return F;
379+
// In some edge cases the AST can contain a "trivial" FunctionProtoTypeLoc
380+
// which has null parameters. Avoid these as they don't contain useful
381+
// information.
382+
if (llvm::all_of(F.getParams(), llvm::identity<ParmVarDecl *>()))
383+
return F;
379384
}
380385

381386
return {};

clang-tools-extra/clangd/unittests/InlayHintTests.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,11 +1011,16 @@ TEST(ParameterHints, FunctionPointer) {
10111011
f3_t f3;
10121012
using f4_t = void(__stdcall *)(int param);
10131013
f4_t f4;
1014+
__attribute__((noreturn)) f4_t f5;
10141015
void bar() {
10151016
f1($f1[[42]]);
10161017
f2($f2[[42]]);
10171018
f3($f3[[42]]);
10181019
f4($f4[[42]]);
1020+
// This one runs into an edge case in clang's type model
1021+
// and we can't extract the parameter name. But at least
1022+
// we shouldn't crash.
1023+
f5(42);
10191024
}
10201025
)cpp",
10211026
ExpectedHint{"param: ", "f1"}, ExpectedHint{"param: ", "f2"},

0 commit comments

Comments
 (0)