[PATCH] D143831: [clang-format] Don't rewrite the input file if already formatted
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 11 16:02:08 PST 2023
owenpan created this revision.
owenpan added reviewers: MyDeveloperDay, HazardyKnusperkeks, rymiel.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
If `IntegerLiteralSeparator` is set but the integer literals are already formatted, don't rewrite the input file.
Fixes https://github.com/llvm/llvm-project/issues/60651.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D143831
Files:
clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
===================================================================
--- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -132,8 +132,11 @@
continue;
if (Start > 0)
Location = Location.getLocWithOffset(Start);
- cantFail(Result.add(tooling::Replacement(SourceMgr, Location, Length,
- format(Text, DigitsPerGroup))));
+ if (const auto &Formatted = format(Text, DigitsPerGroup);
+ Formatted != Text) {
+ cantFail(Result.add(
+ tooling::Replacement(SourceMgr, Location, Length, Formatted)));
+ }
}
return {Result, 0};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143831.496722.patch
Type: text/x-patch
Size: 730 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230212/f756cf74/attachment-0001.bin>
More information about the cfe-commits
mailing list