This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Fix a crash when indexing invalid ObjC method declaration
ClosedPublic

Authored by adamcz on Jan 18 2021, 9:19 AM.

Details

Summary

This fix will make us not crash, but ideally we would handle this case
better.

Diff Detail

Event Timeline

adamcz created this revision.Jan 18 2021, 9:19 AM
adamcz requested review of this revision.Jan 18 2021, 9:19 AM
dgoldman added inline comments.Jan 21 2021, 12:48 PM
clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
1844–1848

It's hard to tell what Clang makes of this, I think instead we should test out the root cause of this crash, IIUC, are the legacy C style parameters:

@interface Foo
- (void)func:(bool)foo, bool bar;
@end
1853–1856

We should verify the method name is exactly as expected but comment we mostly care about not crashing.

clang/lib/Sema/SemaCodeComplete.cpp
3536

I think it might be simpler just to check the index:

unsigned NumSelectorArgs = Sel.getNumArgs();

P != PEnd && Idx < NumSelectorArgs

and note that we need to check this due to legacy use of C-style parameters in Objective-C method declarations which in practice only occurs due to typos

adamcz updated this revision to Diff 318529.Jan 22 2021, 8:03 AM
adamcz marked an inline comment as done.

addressed review comments

clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp
1844–1848

Oh yeah, thanks. Like I said, I don't know ObjC, so I was just randomly changing code until it crashed ;-)

1853–1856

Oops, that's a copy/paste leftover, sorry about that.

dgoldman requested changes to this revision.Jan 22 2021, 9:24 AM

Looks good but I think for posterity we should add a similar test to clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp for the exact intended code complete behavior (or instead of SymbolCollectorTests.cpp - is there a particular reason you added a test there)?

This revision now requires changes to proceed.Jan 22 2021, 9:24 AM

The crash happens while indexing the file, not during code completion. The code completion tests generally specify a cursor position, but in this case it is not relevant and could confuse the reader. This seemed like a logical place for indexing bug, in the spirit of using minimal repro case (i.e. you don't need to trigger code completion at all)

dgoldman accepted this revision.Jan 22 2021, 10:21 AM

The crash happens while indexing the file, not during code completion. The code completion tests generally specify a cursor position, but in this case it is not relevant and could confuse the reader. This seemed like a logical place for indexing bug, in the spirit of using minimal repro case (i.e. you don't need to trigger code completion at all)

I see, thanks.

This revision is now accepted and ready to land.Jan 22 2021, 10:21 AM