[libc][NFC] fix sprintf test on 32 bit systems

The expected number for the max ptrdiff value was expected to be exactly
4294967296 (2**32) for 32 bit systems, when it should be
4294967295 (2**32 - 1). This also adds a second test to check for this
case on non-32 bit systems.

Reviewed By: lntue, mikhail.ramalho

Differential Revision: https://reviews.llvm.org/D156257
This commit is contained in:
Michael Jones 2023-07-25 11:50:56 -07:00
parent e882edd5f1
commit 91eb99b841

View File

@ -122,13 +122,19 @@ TEST(LlvmLibcSPrintfTest, IntConv) {
EXPECT_EQ(written, 20);
ASSERT_STREQ(buff, "18446744073709551615"); // ull max
written = __llvm_libc::sprintf(buff, "%u", ~0);
if (sizeof(int) == 4) {
EXPECT_EQ(written, 10);
ASSERT_STREQ(buff, "4294967295");
}
written = __llvm_libc::sprintf(buff, "%tu", ~ptrdiff_t(0));
if (sizeof(ptrdiff_t) == 8) {
EXPECT_EQ(written, 20);
ASSERT_STREQ(buff, "18446744073709551615");
} else if (sizeof(ptrdiff_t) == 4) {
EXPECT_EQ(written, 10);
ASSERT_STREQ(buff, "4294967296");
ASSERT_STREQ(buff, "4294967295");
}
written = __llvm_libc::sprintf(buff, "%lld", -9223372036854775807ll - 1ll);