[llvm-branch-commits] [clang] 6bf6630 - [clang-format] Don't format already formatted integer literals
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Apr 4 10:41:59 PDT 2023
Author: Owen Pan
Date: 2023-04-04T10:40:57-07:00
New Revision: 6bf663061947954d54fe66cd25da2615c0cfd9cb
URL: https://github.com/llvm/llvm-project/commit/6bf663061947954d54fe66cd25da2615c0cfd9cb
DIFF: https://github.com/llvm/llvm-project/commit/6bf663061947954d54fe66cd25da2615c0cfd9cb.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
(cherry picked from commit 5b5c49ad4563f75debccbc6c3017d27a47ca217d)
Added:
Modified:
clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp b/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
index 508dc82cabebc..063951976458d 100644
--- a/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ b/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -136,13 +136,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};
@@ -159,9 +158,9 @@ bool IntegerLiteralSeparatorFixer::checkSeparator(
return false;
I = 0;
} else {
- ++I;
if (I == DigitsPerGroup)
return false;
+ ++I;
}
}
More information about the llvm-branch-commits
mailing list