llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.23k stars 11.66k forks source link

Assertion `false && "Fix conflicts with existing fix!"' failed. #34756

Open mikaelholmen opened 6 years ago

mikaelholmen commented 6 years ago
Bugzilla Link 35408
Version unspecified
OS Linux
Attachments reproducer
CC @henrickarlsson

Extended Description

clang-tidy foo.c --

on foo.c only containing

a = a && 3;

gives a failed assertion:

Fix conflicts with existing fix! The new replacement overlaps with an existing replacement. New replacement: /data/repo/llvm-dev2/foo.c: 5:+5:"" Existing replacement: /data/repo/llvm-dev2/foo.c: 6:+2:"&" clang-tidy: ../tools/clang/tools/extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:86: virtual void (anonymous namespace)::ClangTidyDiagnosticRenderer::emitCodeContext(clang::FullSourceLoc, DiagnosticsEngine::Level, SmallVectorImpl &, ArrayRef): Assertion `false && "Fix conflicts with existing fix!"' failed. Abort

Changing the input to:

a = a && 1;

avoids the crash and instead we get a bunch of (seemingly correct) warnings.

The crash started appearing with clang-tools-extra commit r284399 2016-10-17:

[clang-tidy] Clean up code after applying replacements.

Summary:
Remove empty namespaces and initializer list commas / colons in
affected ranges. Initial patch: proper options for enabling the cleanup and
specifying the format style are needed.

Reviewers: hokein, ioeric

Subscribers: beanz, mgorny, cfe-commits

Differential Revision: https://reviews.llvm.org/D24572

git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@284399 91177308-0d34-0410-b5e6-96231b3b80d8
henrickarlsson commented 6 years ago

Problem seem to originate from that we have found two different replacements.

I don't see a need for the assert unless we have actually used the -fix or -fix-error flag. Then you can at least get the diagnostics.

Maybe it's possible to save both solutions and try to resolve the conflict when they are actually applied, and if it can't be resolved, just leave the code untouched. But this is probably a more complex change.