[llvm-branch-commits] [clang] 35bd94a - [clang-format] Handle <chrono> ud suffixes in IntegerLiteralSeparator

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue May 30 16:20:12 PDT 2023


Author: Owen Pan
Date: 2023-05-30T16:19:42-07:00
New Revision: 35bd94a4b791787e7f3938e10ce80f409831dd7e

URL: https://github.com/llvm/llvm-project/commit/35bd94a4b791787e7f3938e10ce80f409831dd7e
DIFF: https://github.com/llvm/llvm-project/commit/35bd94a4b791787e7f3938e10ce80f409831dd7e.diff

LOG: [clang-format] Handle <chrono> ud suffixes in IntegerLiteralSeparator

Fixes #62679.

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

(cherry picked from commit a72b064acf9546ee41c67c77ed8662d5d3b2fadc)

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp b/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
index 44034e44adec7..3cc68673cd13c 100644
--- a/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
+++ b/clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
@@ -113,7 +113,11 @@ IntegerLiteralSeparatorFixer::process(const Environment &Env,
       continue;
     }
     if (Style.isCpp()) {
-      if (const auto Pos = Text.find_first_of("_i"); Pos != StringRef::npos) {
+      // Hex alpha digits a-f/A-F must be at the end of the string literal.
+      StringRef Suffixes = "_himnsuyd";
+      if (const auto Pos =
+              Text.find_first_of(IsBase16 ? Suffixes.drop_back() : Suffixes);
+          Pos != StringRef::npos) {
         Text = Text.substr(0, Pos);
         Length = Pos;
       }

diff  --git a/clang/unittests/Format/IntegerLiteralSeparatorTest.cpp b/clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
index f3bcacbf02544..72dc6acad4495 100644
--- a/clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
+++ b/clang/unittests/Format/IntegerLiteralSeparatorTest.cpp
@@ -110,6 +110,24 @@ TEST_F(IntegerLiteralSeparatorTest, SingleQuoteAsSeparator) {
                "hil = 0xABCil;",
                Style);
 
+  verifyFormat("bd = 0b1'0000d;\n"
+               "dh = 1'234h;\n"
+               "dmin = 1'234min;\n"
+               "dns = 1'234ns;\n"
+               "ds = 1'234s;\n"
+               "dus = 1'234us;\n"
+               "hy = 0xA'BCy;",
+               "bd = 0b10000d;\n"
+               "dh = 1234h;\n"
+               "dmin = 1234min;\n"
+               "dns = 1234ns;\n"
+               "ds = 1234s;\n"
+               "dus = 1234us;\n"
+               "hy = 0xABCy;",
+               Style);
+
+  verifyFormat("hd = 0xAB'Cd;", "hd = 0xABCd;", Style);
+
   verifyFormat("d = 5'678_km;\n"
                "h = 0xD'EF_u16;",
                "d = 5678_km;\n"


        


More information about the llvm-branch-commits mailing list