[clang] 5b5c49a - [clang-format] Don't format already formatted integer literals

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 26 13:25:50 PDT 2023


Author: Owen Pan
Date: 2023-03-26T13:25:41-07:00
New Revision: 5b5c49ad4563f75debccbc6c3017d27a47ca217d

URL: https://github.com/llvm/llvm-project/commit/5b5c49ad4563f75debccbc6c3017d27a47ca217d
DIFF: https://github.com/llvm/llvm-project/commit/5b5c49ad4563f75debccbc6c3017d27a47ca217d.diff

LOG: [clang-format] Don't format already formatted integer literals

Fixes a bug in IntegerLiteralSeparatorFixer::checkSeparator() so that
only unformatted integer literals will be formatted.

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

Added: 
    

Modified: 
    clang/lib/Format/IntegerLiteralSeparatorFixer.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp b/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
index e5bee2e855bb..0eac3498d721 100644
--- a/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ b/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -130,13 +130,12 @@ IntegerLiteralSeparatorFixer::process(const Environment &Env,
       DigitsPerGroup = Hex;
     if (DigitsPerGroup > 0 && checkSeparator(Text, DigitsPerGroup))
       continue;
+    const auto &Formatted = format(Text, DigitsPerGroup);
+    assert(Formatted != Text);
     if (Start > 0)
       Location = Location.getLocWithOffset(Start);
-    if (const auto &Formatted = format(Text, DigitsPerGroup);
-        Formatted != Text) {
-      cantFail(Result.add(
-          tooling::Replacement(SourceMgr, Location, Length, Formatted)));
-    }
+    cantFail(Result.add(
+        tooling::Replacement(SourceMgr, Location, Length, Formatted)));
   }
 
   return {Result, 0};
@@ -153,9 +152,9 @@ bool IntegerLiteralSeparatorFixer::checkSeparator(
         return false;
       I = 0;
     } else {
-      ++I;
       if (I == DigitsPerGroup)
         return false;
+      ++I;
     }
   }
 


        


More information about the cfe-commits mailing list