Commit 00054382 authored by Adam Czachorowski's avatar Adam Czachorowski
Browse files

[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
parent 3546b372
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -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
+3 −1
Original line number Diff line number Diff line
@@ -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)