[clang] b4243bb - [clang-format] Don't rewrite the input file if already formatted
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 14 14:28:01 PST 2023
Author: Owen Pan
Date: 2023-02-14T14:27:53-08:00
New Revision: b4243bb611a30137f3f1a7f0e531f91d331ab4be
URL: https://github.com/llvm/llvm-project/commit/b4243bb611a30137f3f1a7f0e531f91d331ab4be
DIFF: https://github.com/llvm/llvm-project/commit/b4243bb611a30137f3f1a7f0e531f91d331ab4be.diff
LOG: [clang-format] Don't rewrite the input file if already formatted
If IntegerLiteralSeparator is set but the integer literals are
already formatted, don't rewrite the input file.
Fixes #60651.
Differential Revision: https://reviews.llvm.org/D143831
Added:
Modified:
clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp b/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
index 24e758e986cf9..e5bee2e855bbc 100644
--- a/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ b/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -132,8 +132,11 @@ IntegerLiteralSeparatorFixer::process(const Environment &Env,
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};
More information about the cfe-commits
mailing list