Page MenuHomePhabricator

[clang-format] Fix segfault when printing diagnostic
Needs RevisionPublic

Authored by rmelotte on Mar 25 2020, 10:01 AM.



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

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

Diff Detail

Event Timeline

rmelotte created this revision.Mar 25 2020, 10:01 AM
rmelotte edited the summary of this revision. (Show Details)Mar 25 2020, 10:03 AM
rmelotte added a subscriber: llvm-commits.
MyDeveloperDay requested changes to this revision.Mar 26 2020, 7:37 AM
MyDeveloperDay added a subscriber: MyDeveloperDay.

We specifically dropped clangFrontEnd from clang-format, please don't include it again

This revision now requires changes to proceed.Mar 26 2020, 7:37 AM

see the discussion at D68969: [clang-format] Remove the dependency on frontendD69854: [clang-format] [RELAND] Remove the dependency on frontendD68554: [clang-format] Proposal for clang-format to give compiler style warnings

given the effort to remove frontEnd It would be a shame to simply just bring it back like like that. (it has an impact I believe on binary size etc...)