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.

Fixes https://github.com/llvm/llvm-project/issues/61676.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146844

Files:
  clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
  clang/unittests/Format/IntegerLiteralSeparatorTest.cpp


Index: clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
===================================================================
--- clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
+++ clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
@@ -47,6 +47,13 @@
   Style.IntegerLiteralSeparator.Hex = 2;
   verifyFormat("h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;", Hex, Style);
 
+  const StringRef UDL("u = 0xDEAD'BEEF'DE'AD'BEE'F_u64;");
+  verifyFormat("u = 0xDE'AD'BE'EF'DE'AD'BE'EF_u64;", UDL, Style);
+  Style.IntegerLiteralSeparator.Hex = -1;
+  verifyFormat("u = 0xDEADBEEFDEADBEEF_u64;", UDL, Style);
+  Style.IntegerLiteralSeparator.Hex = 0;
+  verifyFormat(UDL, Style);
+
   verifyFormat("o0 = 0;\n"
                "o1 = 07;\n"
                "o5 = 012345",
Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
===================================================================
--- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -44,10 +44,13 @@
 std::pair<tooling::Replacements, unsigned>
 IntegerLiteralSeparatorFixer::process(const Environment &Env,
                                       const FormatStyle &Style) {
+  std::string Suffix("uUlLzZn");
+
   switch (Style.Language) {
   case FormatStyle::LK_Cpp:
   case FormatStyle::LK_ObjC:
     Separator = '\'';
+    Suffix.push_back('_');
     break;
   case FormatStyle::LK_CSharp:
   case FormatStyle::LK_Java:
@@ -116,7 +119,7 @@
       continue;
     }
     const auto Start = Text[0] == '0' ? 2 : 0;
-    auto End = Text.find_first_of("uUlLzZn");
+    auto End = Text.find_first_of(Suffix);
     if (End == StringRef::npos)
       End = Length;
     if (Start > 0 || End < Length) {


Index: clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
===================================================================
--- clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
+++ clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
@@ -47,6 +47,13 @@
   Style.IntegerLiteralSeparator.Hex = 2;
   verifyFormat("h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;", Hex, Style);
 
+  const StringRef UDL("u = 0xDEAD'BEEF'DE'AD'BEE'F_u64;");
+  verifyFormat("u = 0xDE'AD'BE'EF'DE'AD'BE'EF_u64;", UDL, Style);
+  Style.IntegerLiteralSeparator.Hex = -1;
+  verifyFormat("u = 0xDEADBEEFDEADBEEF_u64;", UDL, Style);
+  Style.IntegerLiteralSeparator.Hex = 0;
+  verifyFormat(UDL, Style);
+
   verifyFormat("o0 = 0;\n"
                "o1 = 07;\n"
                "o5 = 012345",
Index: clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
===================================================================
--- clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -44,10 +44,13 @@
 std::pair<tooling::Replacements, unsigned>
 IntegerLiteralSeparatorFixer::process(const Environment &Env,
                                       const FormatStyle &Style) {
+  std::string Suffix("uUlLzZn");
+
   switch (Style.Language) {
   case FormatStyle::LK_Cpp:
   case FormatStyle::LK_ObjC:
     Separator = '\'';
+    Suffix.push_back('_');
     break;
   case FormatStyle::LK_CSharp:
   case FormatStyle::LK_Java:
@@ -116,7 +119,7 @@
       continue;
     }
     const auto Start = Text[0] == '0' ? 2 : 0;
-    auto End = Text.find_first_of("uUlLzZn");
+    auto End = Text.find_first_of(Suffix);
     if (End == StringRef::npos)
       End = Length;
     if (Start > 0 || End < Length) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to