[libc-commits] [libc] [libc][stdbit] fix return types (PR #80337)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Thu Feb 1 12:44:13 PST 2024


https://github.com/nickdesaulniers created https://github.com/llvm/llvm-project/pull/80337

All of the functions I've previously implemented return an unsigned int; not
the parameter type.


>From 7650a6f9ba13b2e08d49750be3430ffc1ff74306 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Thu, 1 Feb 2024 12:43:20 -0800
Subject: [PATCH] [libc][stdbit] fix return types

All of the functions I've previously implemented return an unsigned int; not
the parameter type.
---
 libc/include/llvm-libc-macros/stdbit-macros.h | 16 +++----
 libc/spec/stdc.td                             | 16 +++----
 libc/src/stdbit/stdc_leading_ones_uc.cpp      |  4 +-
 libc/src/stdbit/stdc_leading_ones_uc.h        |  2 +-
 libc/src/stdbit/stdc_leading_ones_ul.cpp      |  4 +-
 libc/src/stdbit/stdc_leading_ones_ul.h        |  2 +-
 libc/src/stdbit/stdc_leading_ones_ull.cpp     |  4 +-
 libc/src/stdbit/stdc_leading_ones_ull.h       |  2 +-
 libc/src/stdbit/stdc_leading_ones_us.cpp      |  5 +-
 libc/src/stdbit/stdc_leading_ones_us.h        |  2 +-
 libc/src/stdbit/stdc_leading_zeros_uc.cpp     |  5 +-
 libc/src/stdbit/stdc_leading_zeros_uc.h       |  2 +-
 libc/src/stdbit/stdc_leading_zeros_ul.cpp     |  5 +-
 libc/src/stdbit/stdc_leading_zeros_ul.h       |  2 +-
 libc/src/stdbit/stdc_leading_zeros_ull.cpp    |  5 +-
 libc/src/stdbit/stdc_leading_zeros_ull.h      |  2 +-
 libc/src/stdbit/stdc_leading_zeros_us.cpp     |  5 +-
 libc/src/stdbit/stdc_leading_zeros_us.h       |  2 +-
 libc/test/include/stdbit_test.cpp             | 46 ++++++++-----------
 .../src/stdbit/stdc_leading_ones_uc_test.cpp  |  6 +--
 .../src/stdbit/stdc_leading_ones_ui_test.cpp  |  6 +--
 .../src/stdbit/stdc_leading_ones_ul_test.cpp  |  6 +--
 .../src/stdbit/stdc_leading_ones_ull_test.cpp |  6 +--
 .../src/stdbit/stdc_leading_ones_us_test.cpp  |  4 +-
 .../src/stdbit/stdc_leading_zeros_uc_test.cpp |  5 +-
 .../src/stdbit/stdc_leading_zeros_ul_test.cpp |  4 +-
 .../stdbit/stdc_leading_zeros_ull_test.cpp    |  4 +-
 .../src/stdbit/stdc_leading_zeros_us_test.cpp |  4 +-
 28 files changed, 78 insertions(+), 98 deletions(-)

diff --git a/libc/include/llvm-libc-macros/stdbit-macros.h b/libc/include/llvm-libc-macros/stdbit-macros.h
index 5355be2832fbb..cc964a5268b0d 100644
--- a/libc/include/llvm-libc-macros/stdbit-macros.h
+++ b/libc/include/llvm-libc-macros/stdbit-macros.h
@@ -10,34 +10,34 @@
 #define __LLVM_LIBC_MACROS_STDBIT_MACROS_H
 
 #ifdef __cplusplus
-inline unsigned char stdc_leading_zeros(unsigned char x) {
+inline unsigned stdc_leading_zeros(unsigned char x) {
   return stdc_leading_zeros_uc(x);
 }
-inline unsigned short stdc_leading_zeros(unsigned short x) {
+inline unsigned stdc_leading_zeros(unsigned short x) {
   return stdc_leading_zeros_us(x);
 }
 inline unsigned stdc_leading_zeros(unsigned x) {
   return stdc_leading_zeros_ui(x);
 }
-inline unsigned long stdc_leading_zeros(unsigned long x) {
+inline unsigned stdc_leading_zeros(unsigned long x) {
   return stdc_leading_zeros_ul(x);
 }
-inline unsigned long long stdc_leading_zeros(unsigned long long x) {
+inline unsigned stdc_leading_zeros(unsigned long long x) {
   return stdc_leading_zeros_ull(x);
 }
-inline unsigned char stdc_leading_ones(unsigned char x) {
+inline unsigned stdc_leading_ones(unsigned char x) {
   return stdc_leading_ones_uc(x);
 }
-inline unsigned short stdc_leading_ones(unsigned short x) {
+inline unsigned stdc_leading_ones(unsigned short x) {
   return stdc_leading_ones_us(x);
 }
 inline unsigned stdc_leading_ones(unsigned x) {
   return stdc_leading_ones_ui(x);
 }
-inline unsigned long stdc_leading_ones(unsigned long x) {
+inline unsigned stdc_leading_ones(unsigned long x) {
   return stdc_leading_ones_ul(x);
 }
-inline unsigned long long stdc_leading_ones(unsigned long long x) {
+inline unsigned stdc_leading_ones(unsigned long long x) {
   return stdc_leading_ones_ull(x);
 }
 #else
diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index cb23a6700d913..6ff2c7c613696 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -775,16 +775,16 @@ def StdC : StandardSpec<"stdc"> {
       [], // Types
       [], // Enumerations
       [
-          FunctionSpec<"stdc_leading_zeros_uc", RetValSpec<UnsignedCharType>, [ArgSpec<UnsignedCharType>]>,
-          FunctionSpec<"stdc_leading_zeros_us", RetValSpec<UnsignedShortType>, [ArgSpec<UnsignedShortType>]>,
+          FunctionSpec<"stdc_leading_zeros_uc", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedCharType>]>,
+          FunctionSpec<"stdc_leading_zeros_us", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedShortType>]>,
           FunctionSpec<"stdc_leading_zeros_ui", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedIntType>]>,
-          FunctionSpec<"stdc_leading_zeros_ul", RetValSpec<UnsignedLongType>, [ArgSpec<UnsignedLongType>]>,
-          FunctionSpec<"stdc_leading_zeros_ull", RetValSpec<UnsignedLongLongType>, [ArgSpec<UnsignedLongLongType>]>,
-          FunctionSpec<"stdc_leading_ones_uc", RetValSpec<UnsignedCharType>, [ArgSpec<UnsignedCharType>]>,
-          FunctionSpec<"stdc_leading_ones_us", RetValSpec<UnsignedShortType>, [ArgSpec<UnsignedShortType>]>,
+          FunctionSpec<"stdc_leading_zeros_ul", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedLongType>]>,
+          FunctionSpec<"stdc_leading_zeros_ull", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedLongLongType>]>,
+          FunctionSpec<"stdc_leading_ones_uc", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedCharType>]>,
+          FunctionSpec<"stdc_leading_ones_us", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedShortType>]>,
           FunctionSpec<"stdc_leading_ones_ui", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedIntType>]>,
-          FunctionSpec<"stdc_leading_ones_ul", RetValSpec<UnsignedLongType>, [ArgSpec<UnsignedLongType>]>,
-          FunctionSpec<"stdc_leading_ones_ull", RetValSpec<UnsignedLongLongType>, [ArgSpec<UnsignedLongLongType>]>
+          FunctionSpec<"stdc_leading_ones_ul", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedLongType>]>,
+          FunctionSpec<"stdc_leading_ones_ull", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedLongLongType>]>
       ] // Functions
   >;
 
diff --git a/libc/src/stdbit/stdc_leading_ones_uc.cpp b/libc/src/stdbit/stdc_leading_ones_uc.cpp
index beae134eeb91a..69322d957dbf2 100644
--- a/libc/src/stdbit/stdc_leading_ones_uc.cpp
+++ b/libc/src/stdbit/stdc_leading_ones_uc.cpp
@@ -13,8 +13,8 @@
 
 namespace LIBC_NAMESPACE {
 
-LLVM_LIBC_FUNCTION(unsigned char, stdc_leading_ones_uc, (unsigned char value)) {
-  return static_cast<unsigned char>(cpp::countl_one(value));
+LLVM_LIBC_FUNCTION(unsigned, stdc_leading_ones_uc, (unsigned char value)) {
+  return static_cast<unsigned>(cpp::countl_one(value));
 }
 
 } // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_leading_ones_uc.h b/libc/src/stdbit/stdc_leading_ones_uc.h
index 8303f3f7bd26e..fc4d2bdf623a6 100644
--- a/libc/src/stdbit/stdc_leading_ones_uc.h
+++ b/libc/src/stdbit/stdc_leading_ones_uc.h
@@ -11,7 +11,7 @@
 
 namespace LIBC_NAMESPACE {
 
-unsigned char stdc_leading_ones_uc(unsigned char value);
+unsigned stdc_leading_ones_uc(unsigned char value);
 
 } // namespace LIBC_NAMESPACE
 
diff --git a/libc/src/stdbit/stdc_leading_ones_ul.cpp b/libc/src/stdbit/stdc_leading_ones_ul.cpp
index ccfd9b9594e0b..5b2f61d43b027 100644
--- a/libc/src/stdbit/stdc_leading_ones_ul.cpp
+++ b/libc/src/stdbit/stdc_leading_ones_ul.cpp
@@ -13,8 +13,8 @@
 
 namespace LIBC_NAMESPACE {
 
-LLVM_LIBC_FUNCTION(unsigned long, stdc_leading_ones_ul, (unsigned long value)) {
-  return static_cast<unsigned long>(cpp::countl_one(value));
+LLVM_LIBC_FUNCTION(unsigned, stdc_leading_ones_ul, (unsigned long value)) {
+  return static_cast<unsigned>(cpp::countl_one(value));
 }
 
 } // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_leading_ones_ul.h b/libc/src/stdbit/stdc_leading_ones_ul.h
index 7643bd1ba81d9..3441edf861361 100644
--- a/libc/src/stdbit/stdc_leading_ones_ul.h
+++ b/libc/src/stdbit/stdc_leading_ones_ul.h
@@ -11,7 +11,7 @@
 
 namespace LIBC_NAMESPACE {
 
-unsigned long stdc_leading_ones_ul(unsigned long value);
+unsigned stdc_leading_ones_ul(unsigned long value);
 
 } // namespace LIBC_NAMESPACE
 
diff --git a/libc/src/stdbit/stdc_leading_ones_ull.cpp b/libc/src/stdbit/stdc_leading_ones_ull.cpp
index 8cb1ff08c7b00..05660b9fed653 100644
--- a/libc/src/stdbit/stdc_leading_ones_ull.cpp
+++ b/libc/src/stdbit/stdc_leading_ones_ull.cpp
@@ -13,9 +13,9 @@
 
 namespace LIBC_NAMESPACE {
 
-LLVM_LIBC_FUNCTION(unsigned long long, stdc_leading_ones_ull,
+LLVM_LIBC_FUNCTION(unsigned, stdc_leading_ones_ull,
                    (unsigned long long value)) {
-  return static_cast<unsigned long long>(cpp::countl_one(value));
+  return static_cast<unsigned>(cpp::countl_one(value));
 }
 
 } // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_leading_ones_ull.h b/libc/src/stdbit/stdc_leading_ones_ull.h
index 8ae8145109671..167eb732794d7 100644
--- a/libc/src/stdbit/stdc_leading_ones_ull.h
+++ b/libc/src/stdbit/stdc_leading_ones_ull.h
@@ -11,7 +11,7 @@
 
 namespace LIBC_NAMESPACE {
 
-unsigned long long stdc_leading_ones_ull(unsigned long long value);
+unsigned stdc_leading_ones_ull(unsigned long long value);
 
 } // namespace LIBC_NAMESPACE
 
diff --git a/libc/src/stdbit/stdc_leading_ones_us.cpp b/libc/src/stdbit/stdc_leading_ones_us.cpp
index 4b58cf5cee433..d93327db739b5 100644
--- a/libc/src/stdbit/stdc_leading_ones_us.cpp
+++ b/libc/src/stdbit/stdc_leading_ones_us.cpp
@@ -13,9 +13,8 @@
 
 namespace LIBC_NAMESPACE {
 
-LLVM_LIBC_FUNCTION(unsigned short, stdc_leading_ones_us,
-                   (unsigned short value)) {
-  return static_cast<unsigned short>(cpp::countl_one(value));
+LLVM_LIBC_FUNCTION(unsigned, stdc_leading_ones_us, (unsigned short value)) {
+  return static_cast<unsigned>(cpp::countl_one(value));
 }
 
 } // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_leading_ones_us.h b/libc/src/stdbit/stdc_leading_ones_us.h
index 583a479f79a81..2a552d784b195 100644
--- a/libc/src/stdbit/stdc_leading_ones_us.h
+++ b/libc/src/stdbit/stdc_leading_ones_us.h
@@ -11,7 +11,7 @@
 
 namespace LIBC_NAMESPACE {
 
-unsigned short stdc_leading_ones_us(unsigned short value);
+unsigned stdc_leading_ones_us(unsigned short value);
 
 } // namespace LIBC_NAMESPACE
 
diff --git a/libc/src/stdbit/stdc_leading_zeros_uc.cpp b/libc/src/stdbit/stdc_leading_zeros_uc.cpp
index 8c27043e055bf..dbd2d7662c44f 100644
--- a/libc/src/stdbit/stdc_leading_zeros_uc.cpp
+++ b/libc/src/stdbit/stdc_leading_zeros_uc.cpp
@@ -13,9 +13,8 @@
 
 namespace LIBC_NAMESPACE {
 
-LLVM_LIBC_FUNCTION(unsigned char, stdc_leading_zeros_uc,
-                   (unsigned char value)) {
-  return static_cast<unsigned char>(cpp::countl_zero(value));
+LLVM_LIBC_FUNCTION(unsigned, stdc_leading_zeros_uc, (unsigned char value)) {
+  return static_cast<unsigned>(cpp::countl_zero(value));
 }
 
 } // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_leading_zeros_uc.h b/libc/src/stdbit/stdc_leading_zeros_uc.h
index 0622e72b0683e..1edca66e13448 100644
--- a/libc/src/stdbit/stdc_leading_zeros_uc.h
+++ b/libc/src/stdbit/stdc_leading_zeros_uc.h
@@ -11,7 +11,7 @@
 
 namespace LIBC_NAMESPACE {
 
-unsigned char stdc_leading_zeros_uc(unsigned char value);
+unsigned stdc_leading_zeros_uc(unsigned char value);
 
 } // namespace LIBC_NAMESPACE
 
diff --git a/libc/src/stdbit/stdc_leading_zeros_ul.cpp b/libc/src/stdbit/stdc_leading_zeros_ul.cpp
index cf21ff449a8bf..0d5ff886fe991 100644
--- a/libc/src/stdbit/stdc_leading_zeros_ul.cpp
+++ b/libc/src/stdbit/stdc_leading_zeros_ul.cpp
@@ -13,9 +13,8 @@
 
 namespace LIBC_NAMESPACE {
 
-LLVM_LIBC_FUNCTION(unsigned long, stdc_leading_zeros_ul,
-                   (unsigned long value)) {
-  return static_cast<unsigned long>(cpp::countl_zero(value));
+LLVM_LIBC_FUNCTION(unsigned, stdc_leading_zeros_ul, (unsigned long value)) {
+  return static_cast<unsigned>(cpp::countl_zero(value));
 }
 
 } // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_leading_zeros_ul.h b/libc/src/stdbit/stdc_leading_zeros_ul.h
index a1f36299931dc..5bac6df1b14dc 100644
--- a/libc/src/stdbit/stdc_leading_zeros_ul.h
+++ b/libc/src/stdbit/stdc_leading_zeros_ul.h
@@ -11,7 +11,7 @@
 
 namespace LIBC_NAMESPACE {
 
-unsigned long stdc_leading_zeros_ul(unsigned long value);
+unsigned stdc_leading_zeros_ul(unsigned long value);
 
 } // namespace LIBC_NAMESPACE
 
diff --git a/libc/src/stdbit/stdc_leading_zeros_ull.cpp b/libc/src/stdbit/stdc_leading_zeros_ull.cpp
index d488559bbd14c..115f3c3fb0563 100644
--- a/libc/src/stdbit/stdc_leading_zeros_ull.cpp
+++ b/libc/src/stdbit/stdc_leading_zeros_ull.cpp
@@ -13,9 +13,8 @@
 
 namespace LIBC_NAMESPACE {
 
-LLVM_LIBC_FUNCTION(unsigned long long, stdc_leading_zeros_ull,
-                   (unsigned long long value)) {
-  return static_cast<unsigned long long>(cpp::countl_zero(value));
+LLVM_LIBC_FUNCTION(unsigned, stdc_leading_zeros_ull, (unsigned long long value)) {
+  return static_cast<unsigned>(cpp::countl_zero(value));
 }
 
 } // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_leading_zeros_ull.h b/libc/src/stdbit/stdc_leading_zeros_ull.h
index b05855b296af0..e13624345fc78 100644
--- a/libc/src/stdbit/stdc_leading_zeros_ull.h
+++ b/libc/src/stdbit/stdc_leading_zeros_ull.h
@@ -11,7 +11,7 @@
 
 namespace LIBC_NAMESPACE {
 
-unsigned long long stdc_leading_zeros_ull(unsigned long long value);
+unsigned stdc_leading_zeros_ull(unsigned long long value);
 
 } // namespace LIBC_NAMESPACE
 
diff --git a/libc/src/stdbit/stdc_leading_zeros_us.cpp b/libc/src/stdbit/stdc_leading_zeros_us.cpp
index 84df2b842d695..424fdc7282563 100644
--- a/libc/src/stdbit/stdc_leading_zeros_us.cpp
+++ b/libc/src/stdbit/stdc_leading_zeros_us.cpp
@@ -13,9 +13,8 @@
 
 namespace LIBC_NAMESPACE {
 
-LLVM_LIBC_FUNCTION(unsigned short, stdc_leading_zeros_us,
-                   (unsigned short value)) {
-  return static_cast<unsigned short>(cpp::countl_zero(value));
+LLVM_LIBC_FUNCTION(unsigned, stdc_leading_zeros_us, (unsigned short value)) {
+  return static_cast<unsigned>(cpp::countl_zero(value));
 }
 
 } // namespace LIBC_NAMESPACE
diff --git a/libc/src/stdbit/stdc_leading_zeros_us.h b/libc/src/stdbit/stdc_leading_zeros_us.h
index c0f62e2be2f02..6a3969002daf5 100644
--- a/libc/src/stdbit/stdc_leading_zeros_us.h
+++ b/libc/src/stdbit/stdc_leading_zeros_us.h
@@ -11,7 +11,7 @@
 
 namespace LIBC_NAMESPACE {
 
-unsigned short stdc_leading_zeros_us(unsigned short value);
+unsigned stdc_leading_zeros_us(unsigned short value);
 
 } // namespace LIBC_NAMESPACE
 
diff --git a/libc/test/include/stdbit_test.cpp b/libc/test/include/stdbit_test.cpp
index 5e45f971cb22b..26a1be05c605b 100644
--- a/libc/test/include/stdbit_test.cpp
+++ b/libc/test/include/stdbit_test.cpp
@@ -23,40 +23,34 @@
  * enabled.
  */
 extern "C" {
-unsigned char stdc_leading_zeros_uc(unsigned char) noexcept { return 0xAA; }
-unsigned short stdc_leading_zeros_us(unsigned short) noexcept { return 0xAB; }
-unsigned stdc_leading_zeros_ui(unsigned) noexcept { return 0xAC; }
-unsigned long stdc_leading_zeros_ul(unsigned long) noexcept { return 0xAD; }
-unsigned long long stdc_leading_zeros_ull(unsigned long long) noexcept {
-  return 0xAF;
+unsigned stdc_leading_zeros_uc(unsigned char) noexcept { return 0xAAU; }
+unsigned stdc_leading_zeros_us(unsigned short) noexcept { return 0xABU; }
+unsigned stdc_leading_zeros_ui(unsigned) noexcept { return 0xACU; }
+unsigned stdc_leading_zeros_ul(unsigned long) noexcept { return 0xADU; }
+unsigned stdc_leading_zeros_ull(unsigned long long) noexcept { return 0xAFU;
 }
-unsigned char stdc_leading_ones_uc(unsigned char) noexcept { return 0xBA; }
-unsigned short stdc_leading_ones_us(unsigned short) noexcept { return 0xBB; }
-unsigned stdc_leading_ones_ui(unsigned) noexcept { return 0xBC; }
-unsigned long stdc_leading_ones_ul(unsigned long) noexcept { return 0xBD; }
-unsigned long long stdc_leading_ones_ull(unsigned long long) noexcept {
-  return 0xBF;
+unsigned stdc_leading_ones_uc(unsigned char) noexcept { return 0xBAU; }
+unsigned stdc_leading_ones_us(unsigned short) noexcept { return 0xBBU; }
+unsigned stdc_leading_ones_ui(unsigned) noexcept { return 0xBCU; }
+unsigned stdc_leading_ones_ul(unsigned long) noexcept { return 0xBDU; }
+unsigned stdc_leading_ones_ull(unsigned long long) noexcept { return 0xBFU;
 }
 }
 
 #include "include/llvm-libc-macros/stdbit-macros.h"
 
 TEST(LlvmLibcStdbitTest, TypeGenericMacroLeadingZeros) {
-  EXPECT_EQ(stdc_leading_zeros(static_cast<unsigned char>(0U)),
-            static_cast<unsigned char>(0xAA));
-  EXPECT_EQ(stdc_leading_zeros(static_cast<unsigned short>(0U)),
-            static_cast<unsigned short>(0xAB));
-  EXPECT_EQ(stdc_leading_zeros(0U), static_cast<unsigned>(0xAC));
-  EXPECT_EQ(stdc_leading_zeros(0UL), static_cast<unsigned long>(0xAD));
-  EXPECT_EQ(stdc_leading_zeros(0ULL), static_cast<unsigned long long>(0xAF));
+  EXPECT_EQ(stdc_leading_zeros(static_cast<unsigned char>(0U)), 0xAAU);
+  EXPECT_EQ(stdc_leading_zeros(static_cast<unsigned short>(0U)), 0xABU);
+  EXPECT_EQ(stdc_leading_zeros(0U), 0xACU);
+  EXPECT_EQ(stdc_leading_zeros(0UL), 0xADU);
+  EXPECT_EQ(stdc_leading_zeros(0ULL), 0xAFU);
 }
 
 TEST(LlvmLibcStdbitTest, TypeGenericMacroLeadingOnes) {
-  EXPECT_EQ(stdc_leading_ones(static_cast<unsigned char>(0U)),
-            static_cast<unsigned char>(0xBA));
-  EXPECT_EQ(stdc_leading_ones(static_cast<unsigned short>(0U)),
-            static_cast<unsigned short>(0xBB));
-  EXPECT_EQ(stdc_leading_ones(0U), static_cast<unsigned>(0xBC));
-  EXPECT_EQ(stdc_leading_ones(0UL), static_cast<unsigned long>(0xBD));
-  EXPECT_EQ(stdc_leading_ones(0ULL), static_cast<unsigned long long>(0xBF));
+  EXPECT_EQ(stdc_leading_ones(static_cast<unsigned char>(0U)), 0xBAU);
+  EXPECT_EQ(stdc_leading_ones(static_cast<unsigned short>(0U)), 0xBBU);
+  EXPECT_EQ(stdc_leading_ones(0U), 0xBCU);
+  EXPECT_EQ(stdc_leading_ones(0UL), 0xBDU);
+  EXPECT_EQ(stdc_leading_ones(0ULL), 0xBFU);
 }
diff --git a/libc/test/src/stdbit/stdc_leading_ones_uc_test.cpp b/libc/test/src/stdbit/stdc_leading_ones_uc_test.cpp
index 2883065df3771..d0422e9fef0c8 100644
--- a/libc/test/src/stdbit/stdc_leading_ones_uc_test.cpp
+++ b/libc/test/src/stdbit/stdc_leading_ones_uc_test.cpp
@@ -11,12 +11,10 @@
 #include "test/UnitTest/Test.h"
 
 TEST(LlvmLibcStdcLeadingOnesUcTest, All) {
-  EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_ones_uc(UCHAR_MAX),
-            static_cast<unsigned char>(UCHAR_WIDTH));
+  EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_ones_uc(UCHAR_MAX), static_cast<unsigned>(UCHAR_WIDTH));
 }
 
 TEST(LlvmLibcStdcLeadingOnesUcTest, ZeroHot) {
   for (unsigned i = 0U; i != UCHAR_WIDTH; ++i)
-    EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_ones_uc(~(1U << i)),
-              static_cast<unsigned char>(UCHAR_WIDTH - i - 1));
+    EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_ones_uc(~(1U << i)), UCHAR_WIDTH - i - 1U);
 }
diff --git a/libc/test/src/stdbit/stdc_leading_ones_ui_test.cpp b/libc/test/src/stdbit/stdc_leading_ones_ui_test.cpp
index bae00573927ac..062f11cf6656e 100644
--- a/libc/test/src/stdbit/stdc_leading_ones_ui_test.cpp
+++ b/libc/test/src/stdbit/stdc_leading_ones_ui_test.cpp
@@ -11,12 +11,10 @@
 #include "test/UnitTest/Test.h"
 
 TEST(LlvmLibcStdcLeadingOnesUiTest, All) {
-  EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_ones_ui(UINT_MAX),
-            static_cast<unsigned>(UINT_WIDTH));
+  EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_ones_ui(UINT_MAX), static_cast<unsigned>(UINT_WIDTH));
 }
 
 TEST(LlvmLibcStdcLeadingOnesUiTest, ZeroHot) {
   for (unsigned i = 0U; i != UINT_WIDTH; ++i)
-    EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_ones_ui(~(1U << i)),
-              static_cast<unsigned>(UINT_WIDTH - i - 1));
+    EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_ones_ui(~(1U << i)), UINT_WIDTH - i - 1U);
 }
diff --git a/libc/test/src/stdbit/stdc_leading_ones_ul_test.cpp b/libc/test/src/stdbit/stdc_leading_ones_ul_test.cpp
index bb7b9755ebcc5..810afb0e711f1 100644
--- a/libc/test/src/stdbit/stdc_leading_ones_ul_test.cpp
+++ b/libc/test/src/stdbit/stdc_leading_ones_ul_test.cpp
@@ -11,12 +11,10 @@
 #include "test/UnitTest/Test.h"
 
 TEST(LlvmLibcStdcLeadingOnesUlTest, All) {
-  EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_ones_ul(ULONG_MAX),
-            static_cast<unsigned long>(ULONG_WIDTH));
+  EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_ones_ul(ULONG_MAX), static_cast<unsigned>(ULONG_WIDTH));
 }
 
 TEST(LlvmLibcStdcLeadingOnesUlTest, ZeroHot) {
   for (unsigned i = 0U; i != ULONG_WIDTH; ++i)
-    EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_ones_ul(~(1UL << i)),
-              static_cast<unsigned long>(ULONG_WIDTH - i - 1));
+    EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_ones_ul(~(1UL << i)), ULONG_WIDTH - i - 1U);
 }
diff --git a/libc/test/src/stdbit/stdc_leading_ones_ull_test.cpp b/libc/test/src/stdbit/stdc_leading_ones_ull_test.cpp
index a8497a62bdd17..9961af55c2d19 100644
--- a/libc/test/src/stdbit/stdc_leading_ones_ull_test.cpp
+++ b/libc/test/src/stdbit/stdc_leading_ones_ull_test.cpp
@@ -11,12 +11,10 @@
 #include "test/UnitTest/Test.h"
 
 TEST(LlvmLibcStdcLeadingOnesUllTest, All) {
-  EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_ones_ull(ULLONG_MAX),
-            static_cast<unsigned long long>(ULLONG_WIDTH));
+  EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_ones_ull(ULLONG_MAX), static_cast<unsigned>(ULLONG_WIDTH));
 }
 
 TEST(LlvmLibcStdcLeadingOnesUllTest, ZeroHot) {
   for (unsigned i = 0U; i != ULLONG_WIDTH; ++i)
-    EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_ones_ull(~(1ULL << i)),
-              static_cast<unsigned long long>(ULLONG_WIDTH - i - 1));
+    EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_ones_ull(~(1ULL << i)), ULLONG_WIDTH - i - 1U);
 }
diff --git a/libc/test/src/stdbit/stdc_leading_ones_us_test.cpp b/libc/test/src/stdbit/stdc_leading_ones_us_test.cpp
index 40c34126b76dd..91a125370ec15 100644
--- a/libc/test/src/stdbit/stdc_leading_ones_us_test.cpp
+++ b/libc/test/src/stdbit/stdc_leading_ones_us_test.cpp
@@ -12,11 +12,11 @@
 
 TEST(LlvmLibcStdcLeadingOnesUsTest, All) {
   EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_ones_us(USHRT_MAX),
-            static_cast<unsigned short>(USHRT_WIDTH));
+            static_cast<unsigned>(USHRT_WIDTH));
 }
 
 TEST(LlvmLibcStdcLeadingOnesUsTest, ZeroHot) {
   for (unsigned i = 0U; i != USHRT_WIDTH; ++i)
     EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_ones_us(~(1U << i)),
-              static_cast<unsigned short>(USHRT_WIDTH - i - 1));
+              USHRT_WIDTH - i - 1U);
 }
diff --git a/libc/test/src/stdbit/stdc_leading_zeros_uc_test.cpp b/libc/test/src/stdbit/stdc_leading_zeros_uc_test.cpp
index 4e2e1db3bd72b..c454d3a90f5ae 100644
--- a/libc/test/src/stdbit/stdc_leading_zeros_uc_test.cpp
+++ b/libc/test/src/stdbit/stdc_leading_zeros_uc_test.cpp
@@ -11,12 +11,11 @@
 #include "test/UnitTest/Test.h"
 
 TEST(LlvmLibcStdcLeadingZerosUcTest, Zero) {
-  EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_zeros_uc(0U),
-            static_cast<unsigned char>(UCHAR_WIDTH));
+  EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_zeros_uc(0U), static_cast<unsigned>(UCHAR_WIDTH));
 }
 
 TEST(LlvmLibcStdcLeadingZerosUcTest, OneHot) {
   for (unsigned i = 0U; i != UCHAR_WIDTH; ++i)
     EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_zeros_uc(1U << i),
-              static_cast<unsigned char>(UCHAR_WIDTH - i - 1));
+              UCHAR_WIDTH - i - 1U);
 }
diff --git a/libc/test/src/stdbit/stdc_leading_zeros_ul_test.cpp b/libc/test/src/stdbit/stdc_leading_zeros_ul_test.cpp
index 9a73aece89acc..fd82cef548b6f 100644
--- a/libc/test/src/stdbit/stdc_leading_zeros_ul_test.cpp
+++ b/libc/test/src/stdbit/stdc_leading_zeros_ul_test.cpp
@@ -13,11 +13,11 @@
 
 TEST(LlvmLibcStdcLeadingZerosUlTest, Zero) {
   EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_zeros_ul(0UL),
-            static_cast<unsigned long>(ULONG_WIDTH));
+            static_cast<unsigned>(ULONG_WIDTH));
 }
 
 TEST(LlvmLibcStdcLeadingZerosUlTest, OneHot) {
   for (unsigned i = 0U; i != ULONG_WIDTH; ++i)
     EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_zeros_ul(1UL << i),
-              static_cast<unsigned long>(ULONG_WIDTH - i - 1));
+              ULONG_WIDTH - i - 1U);
 }
diff --git a/libc/test/src/stdbit/stdc_leading_zeros_ull_test.cpp b/libc/test/src/stdbit/stdc_leading_zeros_ull_test.cpp
index 9df2f015f9b6f..cdeeb30323004 100644
--- a/libc/test/src/stdbit/stdc_leading_zeros_ull_test.cpp
+++ b/libc/test/src/stdbit/stdc_leading_zeros_ull_test.cpp
@@ -13,11 +13,11 @@
 
 TEST(LlvmLibcStdcLeadingZerosUllTest, Zero) {
   EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_zeros_ull(0ULL),
-            static_cast<unsigned long long>(ULLONG_WIDTH));
+            static_cast<unsigned>(ULLONG_WIDTH));
 }
 
 TEST(LlvmLibcStdcLeadingZerosUllTest, OneHot) {
   for (unsigned i = 0U; i != ULLONG_WIDTH; ++i)
     EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_zeros_ull(1ULL << i),
-              static_cast<unsigned long long>(ULLONG_WIDTH - i - 1));
+              ULLONG_WIDTH - i - 1U);
 }
diff --git a/libc/test/src/stdbit/stdc_leading_zeros_us_test.cpp b/libc/test/src/stdbit/stdc_leading_zeros_us_test.cpp
index b396a740e43b7..afb418a24ad54 100644
--- a/libc/test/src/stdbit/stdc_leading_zeros_us_test.cpp
+++ b/libc/test/src/stdbit/stdc_leading_zeros_us_test.cpp
@@ -12,11 +12,11 @@
 
 TEST(LlvmLibcStdcLeadingZerosUsTest, Zero) {
   EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_zeros_us(0U),
-            static_cast<unsigned short>(USHRT_WIDTH));
+            static_cast<unsigned>(USHRT_WIDTH));
 }
 
 TEST(LlvmLibcStdcLeadingZerosUsTest, OneHot) {
   for (unsigned i = 0U; i != USHRT_WIDTH; ++i)
     EXPECT_EQ(LIBC_NAMESPACE::stdc_leading_zeros_us(1U << i),
-              static_cast<unsigned short>(USHRT_WIDTH - i - 1));
+              USHRT_WIDTH - i - 1U);
 }



More information about the libc-commits mailing list