[PATCH] D106654: [clangd] Avoid range-loop init-list lifetime subtleties.

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 23 05:26:55 PDT 2021


sammccall created this revision.
sammccall added a reviewer: kadircet.
Herald added subscribers: usaxena95, arphaman.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106654

Files:
  clang-tools-extra/clangd/GlobalCompilationDatabase.cpp


Index: clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
===================================================================
--- clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -285,9 +285,12 @@
         /*ErrorMsg*/ std::string &)>
         Parser;
   };
-  for (const auto &Entry : {CDBFile{&CompileCommandsJson, parseJSON},
-                            CDBFile{&BuildCompileCommandsJson, parseJSON},
-                            CDBFile{&CompileFlagsTxt, parseFixed}}) {
+  CDBFile Files[] = {
+      {&CompileCommandsJson, parseJSON},
+      {&BuildCompileCommandsJson, parseJSON},
+      {&CompileFlagsTxt, parseFixed},
+  };
+  for (const auto &Entry : Files) {
     bool Active = ActiveCachedFile == Entry.File;
     auto Loaded = Entry.File->load(FS, Active);
     switch (Loaded.Result) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106654.361165.patch
Type: text/x-patch
Size: 872 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210723/b7be428d/attachment.bin>


More information about the cfe-commits mailing list