This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Avoid range-loop init-list lifetime subtleties.
ClosedPublic

Authored by sammccall on Jul 23 2021, 5:26 AM.

Details

Summary

The original code appears to be OK per the spec, but we've had 3 reports of
crashes with certain unofficial builds of clangd that look a lot like old
compilers (GCC 5.4?) getting lifetime rules wrong.

Fixes https://github.com/clangd/clangd/issues/800

Diff Detail

Event Timeline

sammccall created this revision.Jul 23 2021, 5:26 AM
sammccall requested review of this revision.Jul 23 2021, 5:26 AM
kadircet accepted this revision.Jul 23 2021, 6:27 AM

thanks! it is unfortunate that history won't remember what an adventure it was to figure out the issue :D

clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
292

nit: I'd make it static const just to make sure they are not going away this time + it will save up some stack space.

nit: Maybe also get rid of the struct's name ? (static const struct { ... } Files[] = { ... };)

This revision is now accepted and ready to land.Jul 23 2021, 6:27 AM
kadircet added inline comments.Jul 23 2021, 6:32 AM
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
292

as discussed, CachedFile entries are actually pointers to members, so NVM the static.

sammccall marked an inline comment as done.Jul 23 2021, 6:34 AM
sammccall added inline comments.
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
292

There are pointers to members in here! The fact that static const even compiles is a massive footgun :-(
We should write a clang-tidy check for that.