forked from OSchip/llvm-project
[clangd] Fix a crash when indexing invalid ObjC method declaration
This fix will make us not crash, but ideally we would handle this case better. Differential Revision: https://reviews.llvm.org/D94919
This commit is contained in:
parent
3546b37221
commit
00054382b9
|
@ -1838,6 +1838,20 @@ TEST_F(SymbolCollectorTest, UndefOfModuleMacro) {
|
|||
EXPECT_THAT(TU.headerSymbols(), Not(Contains(QName("X"))));
|
||||
}
|
||||
|
||||
TEST_F(SymbolCollectorTest, NoCrashOnObjCMethodCStyleParam) {
|
||||
auto TU = TestTU::withCode(R"objc(
|
||||
@interface Foo
|
||||
- (void)fun:(bool)foo, bool bar;
|
||||
@end
|
||||
)objc");
|
||||
TU.ExtraArgs.push_back("-xobjective-c++");
|
||||
|
||||
TU.build();
|
||||
// We mostly care about not crashing.
|
||||
EXPECT_THAT(TU.headerSymbols(),
|
||||
UnorderedElementsAre(QName("Foo"), QName("Foo::fun:")));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace clangd
|
||||
} // namespace clang
|
||||
|
|
|
@ -3529,9 +3529,11 @@ CodeCompletionString *CodeCompletionResult::createCodeCompletionStringForDecl(
|
|||
Result.AddTypedTextChunk("");
|
||||
}
|
||||
unsigned Idx = 0;
|
||||
// The extra Idx < Sel.getNumArgs() check is needed due to legacy C-style
|
||||
// method parameters.
|
||||
for (ObjCMethodDecl::param_const_iterator P = Method->param_begin(),
|
||||
PEnd = Method->param_end();
|
||||
P != PEnd; (void)++P, ++Idx) {
|
||||
P != PEnd && Idx < Sel.getNumArgs(); (void)++P, ++Idx) {
|
||||
if (Idx > 0) {
|
||||
std::string Keyword;
|
||||
if (Idx > StartParameter)
|
||||
|
|
Loading…
Reference in New Issue