Skip to content

Commit edbd93d

Browse files
[libc][stdbit] fix return types (#80337)
All of the functions I've previously implemented return an unsigned int; not the parameter type.
1 parent 59e5590 commit edbd93d

28 files changed

+77
-89
lines changed

libc/include/llvm-libc-macros/stdbit-macros.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,34 @@
1010
#define __LLVM_LIBC_MACROS_STDBIT_MACROS_H
1111

1212
#ifdef __cplusplus
13-
inline unsigned char stdc_leading_zeros(unsigned char x) {
13+
inline unsigned stdc_leading_zeros(unsigned char x) {
1414
return stdc_leading_zeros_uc(x);
1515
}
16-
inline unsigned short stdc_leading_zeros(unsigned short x) {
16+
inline unsigned stdc_leading_zeros(unsigned short x) {
1717
return stdc_leading_zeros_us(x);
1818
}
1919
inline unsigned stdc_leading_zeros(unsigned x) {
2020
return stdc_leading_zeros_ui(x);
2121
}
22-
inline unsigned long stdc_leading_zeros(unsigned long x) {
22+
inline unsigned stdc_leading_zeros(unsigned long x) {
2323
return stdc_leading_zeros_ul(x);
2424
}
25-
inline unsigned long long stdc_leading_zeros(unsigned long long x) {
25+
inline unsigned stdc_leading_zeros(unsigned long long x) {
2626
return stdc_leading_zeros_ull(x);
2727
}
28-
inline unsigned char stdc_leading_ones(unsigned char x) {
28+
inline unsigned stdc_leading_ones(unsigned char x) {
2929
return stdc_leading_ones_uc(x);
3030
}
31-
inline unsigned short stdc_leading_ones(unsigned short x) {
31+
inline unsigned stdc_leading_ones(unsigned short x) {
3232
return stdc_leading_ones_us(x);
3333
}
3434
inline unsigned stdc_leading_ones(unsigned x) {
3535
return stdc_leading_ones_ui(x);
3636
}
37-
inline unsigned long stdc_leading_ones(unsigned long x) {
37+
inline unsigned stdc_leading_ones(unsigned long x) {
3838
return stdc_leading_ones_ul(x);
3939
}
40-
inline unsigned long long stdc_leading_ones(unsigned long long x) {
40+
inline unsigned stdc_leading_ones(unsigned long long x) {
4141
return stdc_leading_ones_ull(x);
4242
}
4343
#else

libc/spec/stdc.td

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -775,16 +775,16 @@ def StdC : StandardSpec<"stdc"> {
775775
[], // Types
776776
[], // Enumerations
777777
[
778-
FunctionSpec<"stdc_leading_zeros_uc", RetValSpec<UnsignedCharType>, [ArgSpec<UnsignedCharType>]>,
779-
FunctionSpec<"stdc_leading_zeros_us", RetValSpec<UnsignedShortType>, [ArgSpec<UnsignedShortType>]>,
778+
FunctionSpec<"stdc_leading_zeros_uc", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedCharType>]>,
779+
FunctionSpec<"stdc_leading_zeros_us", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedShortType>]>,
780780
FunctionSpec<"stdc_leading_zeros_ui", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedIntType>]>,
781-
FunctionSpec<"stdc_leading_zeros_ul", RetValSpec<UnsignedLongType>, [ArgSpec<UnsignedLongType>]>,
782-
FunctionSpec<"stdc_leading_zeros_ull", RetValSpec<UnsignedLongLongType>, [ArgSpec<UnsignedLongLongType>]>,
783-
FunctionSpec<"stdc_leading_ones_uc", RetValSpec<UnsignedCharType>, [ArgSpec<UnsignedCharType>]>,
784-
FunctionSpec<"stdc_leading_ones_us", RetValSpec<UnsignedShortType>, [ArgSpec<UnsignedShortType>]>,
781+
FunctionSpec<"stdc_leading_zeros_ul", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedLongType>]>,
782+
FunctionSpec<"stdc_leading_zeros_ull", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedLongLongType>]>,
783+
FunctionSpec<"stdc_leading_ones_uc", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedCharType>]>,
784+
FunctionSpec<"stdc_leading_ones_us", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedShortType>]>,
785785
FunctionSpec<"stdc_leading_ones_ui", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedIntType>]>,
786-
FunctionSpec<"stdc_leading_ones_ul", RetValSpec<UnsignedLongType>, [ArgSpec<UnsignedLongType>]>,
787-
FunctionSpec<"stdc_leading_ones_ull", RetValSpec<UnsignedLongLongType>, [ArgSpec<UnsignedLongLongType>]>
786+
FunctionSpec<"stdc_leading_ones_ul", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedLongType>]>,
787+
FunctionSpec<"stdc_leading_ones_ull", RetValSpec<UnsignedIntType>, [ArgSpec<UnsignedLongLongType>]>
788788
] // Functions
789789
>;
790790

libc/src/stdbit/stdc_leading_ones_uc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
namespace LIBC_NAMESPACE {
1515

16-
LLVM_LIBC_FUNCTION(unsigned char, stdc_leading_ones_uc, (unsigned char value)) {
17-
return static_cast<unsigned char>(cpp::countl_one(value));
16+
LLVM_LIBC_FUNCTION(unsigned, stdc_leading_ones_uc, (unsigned char value)) {
17+
return static_cast<unsigned>(cpp::countl_one(value));
1818
}
1919

2020
} // namespace LIBC_NAMESPACE

libc/src/stdbit/stdc_leading_ones_uc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace LIBC_NAMESPACE {
1313

14-
unsigned char stdc_leading_ones_uc(unsigned char value);
14+
unsigned stdc_leading_ones_uc(unsigned char value);
1515

1616
} // namespace LIBC_NAMESPACE
1717

libc/src/stdbit/stdc_leading_ones_ul.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
namespace LIBC_NAMESPACE {
1515

16-
LLVM_LIBC_FUNCTION(unsigned long, stdc_leading_ones_ul, (unsigned long value)) {
17-
return static_cast<unsigned long>(cpp::countl_one(value));
16+
LLVM_LIBC_FUNCTION(unsigned, stdc_leading_ones_ul, (unsigned long value)) {
17+
return static_cast<unsigned>(cpp::countl_one(value));
1818
}
1919

2020
} // namespace LIBC_NAMESPACE

libc/src/stdbit/stdc_leading_ones_ul.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace LIBC_NAMESPACE {
1313

14-
unsigned long stdc_leading_ones_ul(unsigned long value);
14+
unsigned stdc_leading_ones_ul(unsigned long value);
1515

1616
} // namespace LIBC_NAMESPACE
1717

libc/src/stdbit/stdc_leading_ones_ull.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
namespace LIBC_NAMESPACE {
1515

16-
LLVM_LIBC_FUNCTION(unsigned long long, stdc_leading_ones_ull,
16+
LLVM_LIBC_FUNCTION(unsigned, stdc_leading_ones_ull,
1717
(unsigned long long value)) {
18-
return static_cast<unsigned long long>(cpp::countl_one(value));
18+
return static_cast<unsigned>(cpp::countl_one(value));
1919
}
2020

2121
} // namespace LIBC_NAMESPACE

libc/src/stdbit/stdc_leading_ones_ull.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace LIBC_NAMESPACE {
1313

14-
unsigned long long stdc_leading_ones_ull(unsigned long long value);
14+
unsigned stdc_leading_ones_ull(unsigned long long value);
1515

1616
} // namespace LIBC_NAMESPACE
1717

libc/src/stdbit/stdc_leading_ones_us.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313

1414
namespace LIBC_NAMESPACE {
1515

16-
LLVM_LIBC_FUNCTION(unsigned short, stdc_leading_ones_us,
17-
(unsigned short value)) {
18-
return static_cast<unsigned short>(cpp::countl_one(value));
16+
LLVM_LIBC_FUNCTION(unsigned, stdc_leading_ones_us, (unsigned short value)) {
17+
return static_cast<unsigned>(cpp::countl_one(value));
1918
}
2019

2120
} // namespace LIBC_NAMESPACE

libc/src/stdbit/stdc_leading_ones_us.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace LIBC_NAMESPACE {
1313

14-
unsigned short stdc_leading_ones_us(unsigned short value);
14+
unsigned stdc_leading_ones_us(unsigned short value);
1515

1616
} // namespace LIBC_NAMESPACE
1717

0 commit comments

Comments
 (0)