summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOwen Pan <owenpiano@gmail.com>2023-03-21 00:02:56 -0700
committerTom Stellard <tstellar@redhat.com>2023-04-04 10:40:57 -0700
commit6bf663061947954d54fe66cd25da2615c0cfd9cb (patch)
tree561bb2b901364f650c1c90041fe58cd65fb1789a
parent7b133944eb8912767b31695774ed018c52222177 (diff)
[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)
-rw-r--r--clang/lib/Format/IntegerLiteralSeparatorFixer.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp b/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
index 508dc82cabeb..063951976458 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;
}
}