[libc-commits] [PATCH] D127694: [libc] Add explicit casts for string functions
Alex Brachet via Phabricator via libc-commits
libc-commits at lists.llvm.org
Mon Jun 13 14:08:02 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6d1543a16797: [libc] Add explicit casts for string functions (authored by abrachet).
Herald added a project: libc-project.
Herald added a subscriber: libc-commits.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D127694/new/
https://reviews.llvm.org/D127694
Files:
libc/src/string/memchr.cpp
libc/src/string/memory_utils/elements_x86.h
libc/src/string/memrchr.cpp
libc/src/string/strchr.cpp
libc/src/string/strrchr.cpp
Index: libc/src/string/strrchr.cpp
===================================================================
--- libc/src/string/strrchr.cpp
+++ libc/src/string/strrchr.cpp
@@ -13,7 +13,7 @@
namespace __llvm_libc {
LLVM_LIBC_FUNCTION(char *, strrchr, (const char *src, int c)) {
- const char ch = c;
+ const char ch = static_cast<char>(c);
char *last_occurrence = nullptr;
for (; *src; ++src) {
if (*src == ch)
Index: libc/src/string/strchr.cpp
===================================================================
--- libc/src/string/strchr.cpp
+++ libc/src/string/strchr.cpp
@@ -14,7 +14,7 @@
// TODO: Look at performance benefits of comparing words.
LLVM_LIBC_FUNCTION(char *, strchr, (const char *src, int c)) {
- const char ch = c;
+ const char ch = static_cast<char>(c);
for (; *src && *src != ch; ++src)
;
return *src == ch ? const_cast<char *>(src) : nullptr;
Index: libc/src/string/memrchr.cpp
===================================================================
--- libc/src/string/memrchr.cpp
+++ libc/src/string/memrchr.cpp
@@ -14,7 +14,7 @@
LLVM_LIBC_FUNCTION(void *, memrchr, (const void *src, int c, size_t n)) {
const unsigned char *str = reinterpret_cast<const unsigned char *>(src);
- const unsigned char ch = c;
+ const unsigned char ch = static_cast<unsigned char>(c);
for (; n != 0; --n) {
const unsigned char *s = str + n - 1;
if (*s == ch)
Index: libc/src/string/memory_utils/elements_x86.h
===================================================================
--- libc/src/string/memory_utils/elements_x86.h
+++ libc/src/string/memory_utils/elements_x86.h
@@ -67,7 +67,8 @@
using T = char __attribute__((__vector_size__(SIZE)));
static uint16_t mask(T value) {
// NOLINTNEXTLINE(llvmlibc-callee-namespace)
- return _mm_movemask_epi8(__llvm_libc::bit_cast<__m128i>(value));
+ return static_cast<uint16_t>(
+ _mm_movemask_epi8(__llvm_libc::bit_cast<__m128i>(value)));
}
static uint16_t not_equal_mask(T a, T b) { return mask(a != b); }
static T load(const char *ptr) {
Index: libc/src/string/memchr.cpp
===================================================================
--- libc/src/string/memchr.cpp
+++ libc/src/string/memchr.cpp
@@ -17,7 +17,8 @@
// TODO: Look at performance benefits of comparing words.
LLVM_LIBC_FUNCTION(void *, memchr, (const void *src, int c, size_t n)) {
return internal::find_first_character(
- reinterpret_cast<const unsigned char *>(src), c, n);
+ reinterpret_cast<const unsigned char *>(src),
+ static_cast<unsigned char>(c), n);
}
} // namespace __llvm_libc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127694.436562.patch
Type: text/x-patch
Size: 2613 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20220613/510da19f/attachment.bin>
More information about the libc-commits
mailing list