diff options
| author | Atousa Duprat <atousa.p@gmail.com> | 2024-03-05 04:38:42 -0800 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-05 07:38:42 -0500 | 
| commit | c00c901f1cb714ebd053de5c6af564dc81754d3e (patch) | |
| tree | 46d75f4791f445ba32a31fd0e922cace727a387e /llvm/unittests/ADT/APIntTest.cpp | |
| parent | 341d674b6f1863d027ed30c44a14cd32599eb42d (diff) | |
| download | llvm-c00c901f1cb714ebd053de5c6af564dc81754d3e.zip llvm-c00c901f1cb714ebd053de5c6af564dc81754d3e.tar.gz llvm-c00c901f1cb714ebd053de5c6af564dc81754d3e.tar.bz2 | |
[clang] Use separator for large numeric values in overflow diagnostic (#80939)
Add functionality to APInt::toString() that allows it to insert
separators between groups of digits, using the C++ literal
separator ' between groups.
Fixes issue #58228
Reviewers:  @AaronBallman, @cjdb, @tbaederr
Diffstat (limited to 'llvm/unittests/ADT/APIntTest.cpp')
| -rw-r--r-- | llvm/unittests/ADT/APIntTest.cpp | 35 | 
1 files changed, 35 insertions, 0 deletions
| diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp index 2fe59f0..2432482 100644 --- a/llvm/unittests/ADT/APIntTest.cpp +++ b/llvm/unittests/ADT/APIntTest.cpp @@ -1379,6 +1379,23 @@ TEST(APIntTest, toString) {    EXPECT_EQ(std::string(S), "0");    S.clear(); +  // with separators +  APInt(64, 140).toString(S, 2, false, true, false, true); +  EXPECT_EQ(std::string(S), "0b1000'1100"); +  S.clear(); +  APInt(64, 1024).toString(S, 8, false, true, false, true); +  EXPECT_EQ(std::string(S), "02'000"); +  S.clear(); +  APInt(64, 1000000).toString(S, 10, false, true, false, true); +  EXPECT_EQ(std::string(S), "1'000'000"); +  S.clear(); +  APInt(64, 1000000).toString(S, 16, false, true, true, true); +  EXPECT_EQ(std::string(S), "0xF'4240"); +  S.clear(); +  APInt(64, 1'000'000'000).toString(S, 36, false, false, false, true); +  EXPECT_EQ(std::string(S), "gj'dgxs"); +  S.clear(); +    isSigned = false;    APInt(8, 255, isSigned).toString(S, 2, isSigned, true);    EXPECT_EQ(std::string(S), "0b11111111"); @@ -1415,6 +1432,24 @@ TEST(APIntTest, toString) {    APInt(8, 255, isSigned).toString(S, 36, isSigned, false);    EXPECT_EQ(std::string(S), "-1");    S.clear(); + +  // negative with separators +  APInt(64, -140, isSigned).toString(S, 2, isSigned, true, false, true); +  EXPECT_EQ(std::string(S), "-0b1000'1100"); +  S.clear(); +  APInt(64, -1024, isSigned).toString(S, 8, isSigned, true, false, true); +  EXPECT_EQ(std::string(S), "-02'000"); +  S.clear(); +  APInt(64, -1000000, isSigned).toString(S, 10, isSigned, true, false, true); +  EXPECT_EQ(std::string(S), "-1'000'000"); +  S.clear(); +  APInt(64, -1000000, isSigned).toString(S, 16, isSigned, true, true, true); +  EXPECT_EQ(std::string(S), "-0xF'4240"); +  S.clear(); +  APInt(64, -1'000'000'000, isSigned) +      .toString(S, 36, isSigned, false, false, true); +  EXPECT_EQ(std::string(S), "-gj'dgxs"); +  S.clear();  }  TEST(APIntTest, Log2) { | 
