owenpan created this revision. owenpan added reviewers: MyDeveloperDay, HazardyKnusperkeks, rymiel. owenpan added a project: clang-format. Herald added a project: All. owenpan requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
If `IntegerLiteralSeparator` is set but the integer literals are already formatted, don't rewrite the input file. Fixes https://github.com/llvm/llvm-project/issues/60651. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D143831 Files: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp =================================================================== --- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp +++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp @@ -132,8 +132,11 @@ 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};
Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp =================================================================== --- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp +++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp @@ -132,8 +132,11 @@ 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};
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits