[llvm-branch-commits] [clang] b98d959 - [clang-format] Don't rewrite the input file if already formatted

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Feb 20 22:53:08 PST 2023


Author: Owen Pan
Date: 2023-02-21T07:52:43+01:00
New Revision: b98d95984f0eb81a5f06eeaa3df29bbb1834a04b

URL: https://github.com/llvm/llvm-project/commit/b98d95984f0eb81a5f06eeaa3df29bbb1834a04b
DIFF: https://github.com/llvm/llvm-project/commit/b98d95984f0eb81a5f06eeaa3df29bbb1834a04b.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

(cherry picked from commit b4243bb611a30137f3f1a7f0e531f91d331ab4be)

Added: 
    

Modified: 
    clang/lib/Format/IntegerLiteralSeparatorFixer.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp b/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
index ef07ab06760b3..05e37c34a8a04 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 llvm-branch-commits mailing list