This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Fix a clangd crash when indexing the standard library.
Needs ReviewPublic

Authored by hokein on Dec 23 2022, 3:04 AM.

Details

Reviewers
sammccall
Summary

Setup a current working directory (the build directoy) when creating a compile
instance. (otherwise clangd may die immediately when the VFS doesn't get input
files e.g. -fsanitize-ignorelist="../ignores.txt").

Diff Detail

Event Timeline

hokein created this revision.Dec 23 2022, 3:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 23 2022, 3:04 AM
hokein requested review of this revision.Dec 23 2022, 3:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 23 2022, 3:04 AM
nridge added a subscriber: nridge.Dec 26 2022, 1:04 AM

As I understand, we're crashing if the ignorelist isn't found, and this patch fixes the searching so that we find the file (assuming the compile command is correct).

But we'll still crash if the compile command is wrong, which seems pretty bad.

Fixing the way the ignorelist is populated in clang would be nice but is a bit of a yakshave.
Failing that, I think in this case we can just clear out the langopt in disableUnsupportedOptions(). This seems much more robust (though doing both is also fine)

Most of the uses of the asan ignorelist are in codegen which we don't care about.
It also affects record layout: see RecordDecl::mayInsertExtraPadding. We do calculate and show record layouts on hover, but I don't think we should care about ignorelists when doing so - people almost certainly really care about the non-asan size.
(In practice, I couldn't actually see any asan-specific differences through clangd in casual inspection).

clang-tools-extra/clangd/index/StdLib.cpp
227

I can't see where this is set in clang itself - I thought it was just a customization point for programmatic use. However the fix works, so it seems like it must be getting the correct value... very misterious