Skip to content

[libc] Fix missing UINTMAX_WIDTH #87092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 29, 2024

Conversation

michaelrj-google
Copy link
Contributor

In patch #82461 the sprintf tests were made to use UINTMAX_WIDTH which
isn't defined on all systems. This patch changes it to
sizeof(uintmax_t)*CHAR_BIT which is more portable.

In patch llvm#82461 the sprintf tests were made to use UINTMAX_WIDTH which
isn't defined on all systems. This patch changes it to
sizeof(uintmax_t)*CHAR_BIT which is more portable.
@llvmbot llvmbot added the libc label Mar 29, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 29, 2024

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

Changes

In patch #82461 the sprintf tests were made to use UINTMAX_WIDTH which
isn't defined on all systems. This patch changes it to
sizeof(uintmax_t)*CHAR_BIT which is more portable.


Full diff: https://github.com/llvm/llvm-project/pull/87092.diff

1 Files Affected:

  • (modified) libc/test/src/stdio/sprintf_test.cpp (+4-3)
diff --git a/libc/test/src/stdio/sprintf_test.cpp b/libc/test/src/stdio/sprintf_test.cpp
index ba31034146fedf..8e9870f71a9595 100644
--- a/libc/test/src/stdio/sprintf_test.cpp
+++ b/libc/test/src/stdio/sprintf_test.cpp
@@ -203,9 +203,10 @@ TEST(LlvmLibcSPrintfTest, IntConv) {
 
   char format[64];
   char uintmax[128];
-  LIBC_NAMESPACE::sprintf(format, "%%w%du", UINTMAX_WIDTH);
-  const int uintmax_len = LIBC_NAMESPACE::sprintf(uintmax, "%ju", UINTMAX_MAX);
-  written = LIBC_NAMESPACE::sprintf(buff, format, UINTMAX_MAX);
+  LIBC_NAMESPACE::sprintf(format, "%%w%du", sizeof(uintmax_t) * CHAR_BIT);
+  const int uintmax_len =
+      LIBC_NAMESPACE::sprintf(uintmax, "%ju", sizeof(uintmax_t) * CHAR_BIT);
+  written = LIBC_NAMESPACE::sprintf(buff, format, sizeof(uintmax_t) * CHAR_BIT);
   EXPECT_EQ(written, uintmax_len);
   ASSERT_STREQ(buff, uintmax);
 

Copy link
Member

@nickdesaulniers nickdesaulniers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also do something like:

#ifndef UINTMAX_WIDTH
#define UINTMAX_WIDTH sizeof(uintmax_t) * CHAR_BIT
#endif

But happy to take this to unbreak builds.

@nickdesaulniers
Copy link
Member

See also bf7d997

@michaelrj-google michaelrj-google merged commit 838b118 into llvm:main Mar 29, 2024
@michaelrj-google michaelrj-google deleted the libcFixPrintfWF branch March 29, 2024 17:32
@nickdesaulniers
Copy link
Member

More context:

$ git branch -a --contains bf7d997 | grep origin/release
  remotes/origin/release/14.x
  remotes/origin/release/15.x
  remotes/origin/release/16.x
  remotes/origin/release/17.x
  remotes/origin/release/18.x

shows that bf7d997 first landed in 14.x (or exists there, don't know if it was backported earlier). So clang's <stdint.h> did not define UINTMAX_WIDTH until clang-14, which is the clang version the failed buildbots are running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants