[libc-commits] [libc] [libc] Use int in a64l instead of int32_t. (PR #150034)
via libc-commits
libc-commits at lists.llvm.org
Tue Jul 22 08:11:03 PDT 2025
https://github.com/lntue updated https://github.com/llvm/llvm-project/pull/150034
>From acf7adb880063651f9ba5cd00a7eb889bed2ba3b Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Tue, 22 Jul 2025 14:43:42 +0000
Subject: [PATCH 1/2] [libc] Use int in a64l instead of int32_t.
---
libc/src/stdlib/a64l.cpp | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/libc/src/stdlib/a64l.cpp b/libc/src/stdlib/a64l.cpp
index 84be2d208f7d7..4b63c76033454 100644
--- a/libc/src/stdlib/a64l.cpp
+++ b/libc/src/stdlib/a64l.cpp
@@ -12,14 +12,12 @@
#include "src/__support/ctype_utils.h"
#include "src/__support/macros/config.h"
-#include <stdint.h>
-
namespace LIBC_NAMESPACE_DECL {
// I'm not sure this should go in ctype_utils since the specific ordering of
// base64 is so very implementation specific, and also this set is unusual.
// Returns -1 on any char without a specified value.
-constexpr static int32_t b64_char_to_int(char ch) {
+constexpr static int b64_char_to_int(char ch) {
// from the standard: "The characters used to represent digits are '.' (dot)
// for 0, '/' for 1, '0' through '9' for [2,11], 'A' through 'Z' for [12,37],
// and 'a' through 'z' for [38,63]."
@@ -44,10 +42,10 @@ constexpr static int32_t b64_char_to_int(char ch) {
LLVM_LIBC_FUNCTION(long, a64l, (const char *s)) {
// the standard says to only use up to 6 characters.
constexpr size_t MAX_LENGTH = 6;
- int32_t result = 0;
+ int result = 0;
for (size_t i = 0; i < MAX_LENGTH && s[i] != '\0'; ++i) {
- int32_t cur_val = b64_char_to_int(s[i]);
+ int cur_val = b64_char_to_int(s[i]);
// The standard says what happens on an unspecified character is undefined,
// here we treat it as the end of the string.
if (cur_val == -1)
>From 8d22d6bf2becacca5b4b683d25972b59b49ded14 Mon Sep 17 00:00:00 2001
From: Tue Ly <lntue.h at gmail.com>
Date: Tue, 22 Jul 2025 15:10:29 +0000
Subject: [PATCH 2/2] Also replace `size_t` usage and dependency with
`unsigned`.
---
libc/src/stdlib/CMakeLists.txt | 1 -
libc/src/stdlib/a64l.cpp | 5 ++---
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/libc/src/stdlib/CMakeLists.txt b/libc/src/stdlib/CMakeLists.txt
index 74ae864f72e23..4abb59ab49c8e 100644
--- a/libc/src/stdlib/CMakeLists.txt
+++ b/libc/src/stdlib/CMakeLists.txt
@@ -192,7 +192,6 @@ add_entrypoint_object(
a64l.h
DEPENDS
libc.src.__support.ctype_utils
- libc.hdr.types.size_t
)
add_entrypoint_object(
diff --git a/libc/src/stdlib/a64l.cpp b/libc/src/stdlib/a64l.cpp
index 4b63c76033454..4ebb9d494a46f 100644
--- a/libc/src/stdlib/a64l.cpp
+++ b/libc/src/stdlib/a64l.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "src/stdlib/a64l.h"
-#include "hdr/types/size_t.h"
#include "src/__support/common.h"
#include "src/__support/ctype_utils.h"
#include "src/__support/macros/config.h"
@@ -41,10 +40,10 @@ constexpr static int b64_char_to_int(char ch) {
// TODO: use LIBC_ADD_NULL_CHECKS for checking if the input is a null pointer.
LLVM_LIBC_FUNCTION(long, a64l, (const char *s)) {
// the standard says to only use up to 6 characters.
- constexpr size_t MAX_LENGTH = 6;
+ constexpr unsigned MAX_LENGTH = 6;
int result = 0;
- for (size_t i = 0; i < MAX_LENGTH && s[i] != '\0'; ++i) {
+ for (unsigned i = 0; i < MAX_LENGTH && s[i] != '\0'; ++i) {
int cur_val = b64_char_to_int(s[i]);
// The standard says what happens on an unspecified character is undefined,
// here we treat it as the end of the string.
More information about the libc-commits
mailing list