llvm-project/clang-tools-extra
Sam McCall b500c49cd4 [clangd] Don't mmap source files on all platforms --> don't crash on git checkout
Summary:
Previously we mmapped on unix and not on windows: on windows mmap takes
an exclusive lock on the file and prevents the user saving changes!

The failure mode on linux is a bit more subtle: if the file is changed on disk
but the SourceManager sticks around, then subsequent operations on the
SourceManager will fail as invariants are violated (e.g. null-termination).

This commonly manifests as crashes after switching git branches with many files
open in clangd.

Nominally mmap is for performance here, and we should be willing to give some
up to stop crashing. Measurements on my system (linux+desktop+SSD) at least
show no measurable regression on an a fairly IO-heavy workload: drop disk caches,
open SemaOverload.cpp, wait for first diagnostics.

for i in `seq 100`; do
  for variant in mmap volatile; do
    echo 3 | sudo tee /proc/sys/vm/drop_caches
    /usr/bin/time --append --quiet -o ~/timings -f "%C %E" \
    bin/clangd.$variant -sync -background-index=0 < /tmp/mirror > /dev/null
  done
done

bin/clangd.mmap -sync -background-index=0 0:07.60
bin/clangd.volatile -sync -background-index=0 0:07.89
bin/clangd.mmap -sync -background-index=0 0:07.44
bin/clangd.volatile -sync -background-index=0 0:07.89
bin/clangd.mmap -sync -background-index=0 0:07.42
bin/clangd.volatile -sync -background-index=0 0:07.50
bin/clangd.mmap -sync -background-index=0 0:07.90
bin/clangd.volatile -sync -background-index=0 0:07.53
bin/clangd.mmap -sync -background-index=0 0:07.64
bin/clangd.volatile -sync -background-index=0 0:07.55
bin/clangd.mmap -sync -background-index=0 0:07.75
bin/clangd.volatile -sync -background-index=0 0:07.47
bin/clangd.mmap -sync -background-index=0 0:07.90
bin/clangd.volatile -sync -background-index=0 0:07.50
bin/clangd.mmap -sync -background-index=0 0:07.81
bin/clangd.volatile -sync -background-index=0 0:07.95
bin/clangd.mmap -sync -background-index=0 0:07.55
bin/clangd.volatile -sync -background-index=0 0:07.65
bin/clangd.mmap -sync -background-index=0 0:08.15
bin/clangd.volatile -sync -background-index=0 0:07.54
bin/clangd.mmap -sync -background-index=0 0:07.78
bin/clangd.volatile -sync -background-index=0 0:07.61
bin/clangd.mmap -sync -background-index=0 0:07.78
bin/clangd.volatile -sync -background-index=0 0:07.55
bin/clangd.mmap -sync -background-index=0 0:07.41
bin/clangd.volatile -sync -background-index=0 0:07.40
bin/clangd.mmap -sync -background-index=0 0:07.54
bin/clangd.volatile -sync -background-index=0 0:07.42
bin/clangd.mmap -sync -background-index=0 0:07.45
bin/clangd.volatile -sync -background-index=0 0:07.49
bin/clangd.mmap -sync -background-index=0 0:07.95
bin/clangd.volatile -sync -background-index=0 0:07.66
bin/clangd.mmap -sync -background-index=0 0:08.04

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D73617
2020-01-29 19:44:14 +01:00
..
clang-apply-replacements NFC: Fix trivial typos in comments 2020-01-04 10:28:41 -05:00
clang-change-namespace Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
clang-doc More fixes of implicit std::string conversions 2020-01-29 15:29:46 +01:00
clang-include-fixer Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
clang-move Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
clang-query Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
clang-reorder-fields [ASTMatchers] StringRef'ify hasName 2020-01-29 10:53:08 +01:00
clang-tidy [clang-tidy] Initialize token before handing it to the lexer 2020-01-29 16:48:57 +01:00
clangd [clangd] Don't mmap source files on all platforms --> don't crash on git checkout 2020-01-29 19:44:14 +01:00
docs [clang-tidy] adjust scripts to subsubsections in Release Notes 2020-01-28 18:10:22 +00:00
modularize Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
pp-trace NFC: Fix trivial typos in comments 2020-01-04 10:28:41 -05:00
test [clang-tidy] Fix bugprone-use-after-move when move is in noexcept operator 2020-01-28 00:39:07 +00:00
tool-template Revert "Use InitLLVM to setup a pretty stack printer" 2019-11-25 21:06:56 -05:00
unittests Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
.arcconfig [clang-tools-extra] Set up .arcconfig to point to new Diffusion CTE repository 2017-11-27 15:58:25 +00:00
.gitignore
CMakeLists.txt Remove clang-tidy-vs from clang-tools-extra (PR41791) 2019-08-27 18:36:08 +00:00
CODE_OWNERS.TXT [clangd] add CODE_OWNERS 2020-01-29 12:43:19 +01:00
LICENSE.TXT Fix typos throughout the license files that somehow I and my reviewers 2019-01-21 09:52:34 +00:00
README.txt

README.txt

//===----------------------------------------------------------------------===//
// Clang Tools repository
//===----------------------------------------------------------------------===//

Welcome to the repository of extra Clang Tools.  This repository holds tools
that are developed as part of the LLVM compiler infrastructure project and the
Clang frontend.  These tools are kept in a separate "extra" repository to
allow lighter weight checkouts of the core Clang codebase.

This repository is only intended to be checked out inside of a full LLVM+Clang
tree, and in the 'tools/extra' subdirectory of the Clang checkout.

All discussion regarding Clang, Clang-based tools, and code in this repository
should be held using the standard Clang mailing lists:
  http://lists.llvm.org/mailman/listinfo/cfe-dev

Code review for this tree should take place on the standard Clang patch and
commit lists:
  http://lists.llvm.org/mailman/listinfo/cfe-commits

If you find a bug in these tools, please file it in the LLVM bug tracker:
  http://llvm.org/bugs/