When clang-format couldn't replace the file to format for some reason,
it would segfault instead of printing a diagnostic message.
A very simple way to reproduce the issue is to create a non-writable
folder containing a file to format, and try to format the file
in-place.
On recent clang versions (11.0.0 for example), the following assert would
show up:
Assertion `getClient() && "DiagnosticClient not set!"' failed.
Set the DiagnosticClient by using a TextDiagnosticPrinter, similarly
to what is done for RewriterTestContext.
Here is a very simple reproducer:
mkdir folder echo "int main(){printf("hello"); return 0;}" > folder/file.c chmod -w folder build/bin/clang-format -i folder/file.c chmod +w folder rm -rf folder