Skip to content
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

[libc][stdbit] fix return types #80337

Merged
merged 2 commits into from
Feb 1, 2024

Conversation

nickdesaulniers
Copy link
Member

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

All of the functions I've previously implemented return an unsigned int; not
the parameter type.
@llvmbot llvmbot added the libc label Feb 1, 2024
@nickdesaulniers
Copy link
Member Author

I think I'm going to fix up our bit.h to return unsigned. Will do that as a distinct PR.

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 1, 2024

@llvm/pr-subscribers-libc

Author: Nick Desaulniers (nickdesaulniers)

Changes

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


Patch is 22.95 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/80337.diff

28 Files Affected:

  • (modified) libc/include/llvm-libc-macros/stdbit-macros.h (+8-8)
  • (modified) libc/spec/stdc.td (+8-8)
  • (modified) libc/src/stdbit/stdc_leading_ones_uc.cpp (+2-2)
  • (modified) libc/src/stdbit/stdc_leading_ones_uc.h (+1-1)
  • (modified) libc/src/stdbit/stdc_leading_ones_ul.cpp (+2-2)
  • (modified) libc/src/stdbit/stdc_leading_ones_ul.h (+1-1)
  • (modified) libc/src/stdbit/stdc_leading_ones_ull.cpp (+2-2)
  • (modified) libc/src/stdbit/stdc_leading_ones_ull.h (+1-1)
  • (modified) libc/src/stdbit/stdc_leading_ones_us.cpp (+2-3)
  • (modified) libc/src/stdbit/stdc_leading_ones_us.h (+1-1)
  • (modified) libc/src/stdbit/stdc_leading_zeros_uc.cpp (+2-3)
  • (modified) libc/src/stdbit/stdc_leading_zeros_uc.h (+1-1)
  • (modified) libc/src/stdbit/stdc_leading_zeros_ul.cpp (+2-3)
  • (modified) libc/src/stdbit/stdc_leading_zeros_ul.h (+1-1)
  • (modified) libc/src/stdbit/stdc_leading_zeros_ull.cpp (+2-3)
  • (modified) libc/src/stdbit/stdc_leading_zeros_ull.h (+1-1)
  • (modified) libc/src/stdbit/stdc_leading_zeros_us.cpp (+2-3)
  • (modified) libc/src/stdbit/stdc_leading_zeros_us.h (+1-1)
  • (modified) libc/test/include/stdbit_test.cpp (+20-26)
  • (modified) libc/test/src/stdbit/stdc_leading_ones_uc_test.cpp (+2-4)
  • (modified) libc/test/src/stdbit/stdc_leading_ones_ui_test.cpp (+2-4)
  • (modified) libc/test/src/stdbit/stdc_leading_ones_ul_test.cpp (+2-4)
  • (modified) libc/test/src/stdbit/stdc_leading_ones_ull_test.cpp (+2-4)
  • (modified) libc/test/src/stdbit/stdc_leading_ones_us_test.cpp (+2-2)
  • (modified) libc/test/src/stdbit/stdc_leading_zeros_uc_test.cpp (+2-3)
  • (modified) libc/test/src/stdbit/stdc_leading_zeros_ul_test.cpp (+2-2)
  • (modified) libc/test/src/stdbit/stdc_leading_zeros_ull_test.cpp (+2-2)
  • (modified) libc/test/src/stdbit/stdc_leading_zeros_us_test.cpp (+2-2)
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...
[truncated]

Copy link

github-actions bot commented Feb 1, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

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

The standard says that these functions return int, not unsigned.

EDIT: Nevermind, I was looking at an older version of the standard.

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

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

LGTM

@nickdesaulniers nickdesaulniers merged commit edbd93d into llvm:main Feb 1, 2024
4 checks passed
@nickdesaulniers nickdesaulniers deleted the stdbit_return_type branch February 1, 2024 21:09
ichaer added a commit to ichaer/llvm-project-onesided_lower_bound that referenced this pull request Feb 2, 2024
* llvm/main: (500 commits)
  [docs] Add beginner-focused office hours (llvm#80308)
  [mlir][sparse] external entry method wrapper for sparse tensors (llvm#80326)
  [StackSlotColoring] Ignore non-spill objects in RemoveDeadStores. (llvm#80242)
  [libc][stdbit] fix return types (llvm#80337)
  Revert "[RISCV] Refine cost on Min/Max reduction" (llvm#80340)
  [TTI]Add support for strided loads/stores.
  [analyzer][HTMLRewriter] Cache partial rewrite results. (llvm#80220)
  [flang][openacc][openmp] Use #0 from hlfir.declare value when generating bound ops (llvm#80317)
  [AArch64][PAC] Expand blend(reg, imm) operation in aarch64-pauth pass (llvm#74729)
  [SHT_LLVM_BB_ADDR_MAP][llvm-readobj] Implements llvm-readobj handling for PGOAnalysisMap. (llvm#79520)
  [libc] add bazel support for most of unistd (llvm#80078)
  [clang-tidy] Remove enforcement of rule C.48 from cppcoreguidelines-prefer-member-init (llvm#80330)
  [OpenMP] Fix typo (NFC) (llvm#80332)
  [BOLT] Enable re-writing of Linux kernel binary (llvm#80228)
  [BOLT] Adjust section sizes based on file offsets (llvm#80226)
  [libc] fix stdbit include test when not all entrypoints are available (llvm#80323)
  [RISCV][GISel] RegBank select and instruction select for vector G_ADD, G_SUB (llvm#74114)
  [RISCV] Add srmcfg CSR from Ssqosid extension. (llvm#79914)
  [mlir][sparse] add sparsification options to pretty print and debug s… (llvm#80205)
  [RISCV][MC] MC layer support for the experimental zalasr extension (llvm#79911)
  ...
agozillon pushed a commit to agozillon/llvm-project that referenced this pull request Feb 5, 2024
All of the functions I've previously implemented return an unsigned int; not
the parameter type.
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.

4 participants