-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Implemented wmemmove #142245
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
Merged
Merged
[libc] Implemented wmemmove #142245
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e4b5c76
implemented wmemmove
uzairnawaz 8119ac2
fix death testcase
uzairnawaz 2e8a5c8
style
uzairnawaz 0dc2431
format
uzairnawaz acc65a1
fixed build file
uzairnawaz e652fd9
Merge branch 'main' into wmemmove
uzairnawaz 3ed9728
Merge branch 'main' into wmemmove
uzairnawaz da02ea4
Merge branch 'main' into wmemmove
uzairnawaz 67ea997
Merge branch 'main' into wmemmove
uzairnawaz 542e709
Switched to __builtin_memmove
uzairnawaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//===-- Implementation of wmemmove ----------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/wchar/wmemmove.h" | ||
|
||
#include "hdr/types/size_t.h" | ||
#include "hdr/types/wchar_t.h" | ||
#include "src/__support/common.h" | ||
#include "src/__support/macros/null_check.h" | ||
#include "src/string/memory_utils/inline_memmove.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
LLVM_LIBC_FUNCTION(wchar_t *, wmemmove, | ||
(wchar_t * dest, const wchar_t *src, size_t n)) { | ||
LIBC_CRASH_ON_NULLPTR(dest); | ||
LIBC_CRASH_ON_NULLPTR(src); | ||
|
||
inline_memmove(dest, src, n * sizeof(wchar_t)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the memory functions we're moving away from calling the internal ones and towards using the builtins. For that reason this should be |
||
return dest; | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE_DECL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
//===-- Implementation header for wmemmove --------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SRC_WCHAR_WMEMMOVE_H | ||
#define LLVM_LIBC_SRC_WCHAR_WMEMMOVE_H | ||
|
||
#include "hdr/types/size_t.h" | ||
#include "hdr/types/wchar_t.h" | ||
#include "src/__support/macros/config.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
wchar_t *wmemmove(wchar_t *dest, const wchar_t *src, size_t n); | ||
|
||
} // namespace LIBC_NAMESPACE_DECL | ||
|
||
#endif // LLVM_LIBC_SRC_WCHAR_WMEMMOVE_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
//===-- Unittests for wmemmove --------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "hdr/types/size_t.h" | ||
#include "hdr/types/wchar_t.h" | ||
#include "src/wchar/wmemmove.h" | ||
#include "test/UnitTest/Test.h" | ||
|
||
TEST(LlvmLibcWMemmoveTest, MoveZeroByte) { | ||
wchar_t buffer[] = {L'a', L'b', L'y', L'z'}; | ||
|
||
wchar_t *ret = LIBC_NAMESPACE::wmemmove(buffer, buffer + 2, 0); | ||
EXPECT_EQ(ret, buffer); | ||
|
||
const wchar_t expected[] = {L'a', L'b', L'y', L'z'}; | ||
EXPECT_TRUE(buffer[0] == expected[0]); | ||
EXPECT_TRUE(buffer[1] == expected[1]); | ||
EXPECT_TRUE(buffer[2] == expected[2]); | ||
EXPECT_TRUE(buffer[3] == expected[3]); | ||
} | ||
|
||
TEST(LlvmLibcWMemmoveTest, DstAndSrcPointToSameAddress) { | ||
wchar_t buffer[] = {L'a', L'b'}; | ||
|
||
wchar_t *ret = LIBC_NAMESPACE::wmemmove(buffer, buffer, 1); | ||
EXPECT_EQ(ret, buffer); | ||
|
||
const wchar_t expected[] = {L'a', L'b'}; | ||
EXPECT_TRUE(buffer[0] == expected[0]); | ||
EXPECT_TRUE(buffer[1] == expected[1]); | ||
} | ||
|
||
TEST(LlvmLibcWMemmoveTest, DstStartsBeforeSrc) { | ||
// Set boundary at beginning and end for not overstepping when | ||
// copy forward or backward. | ||
wchar_t buffer[] = {L'z', L'a', L'b', L'c', L'z'}; | ||
|
||
wchar_t *dst = buffer + 1; | ||
wchar_t *ret = LIBC_NAMESPACE::wmemmove(dst, buffer + 2, 2); | ||
EXPECT_EQ(ret, dst); | ||
|
||
const wchar_t expected[] = {L'z', L'b', L'c', L'c', L'z'}; | ||
EXPECT_TRUE(buffer[0] == expected[0]); | ||
EXPECT_TRUE(buffer[1] == expected[1]); | ||
EXPECT_TRUE(buffer[2] == expected[2]); | ||
EXPECT_TRUE(buffer[3] == expected[3]); | ||
EXPECT_TRUE(buffer[4] == expected[4]); | ||
} | ||
|
||
TEST(LlvmLibcWMemmoveTest, DstStartsAfterSrc) { | ||
wchar_t buffer[] = {L'z', L'a', L'b', L'c', L'z'}; | ||
|
||
wchar_t *dst = buffer + 2; | ||
wchar_t *ret = LIBC_NAMESPACE::wmemmove(dst, buffer + 1, 2); | ||
EXPECT_EQ(ret, dst); | ||
|
||
const wchar_t expected[] = {L'z', L'a', L'a', L'b', L'z'}; | ||
EXPECT_TRUE(buffer[0] == expected[0]); | ||
EXPECT_TRUE(buffer[1] == expected[1]); | ||
EXPECT_TRUE(buffer[2] == expected[2]); | ||
EXPECT_TRUE(buffer[3] == expected[3]); | ||
EXPECT_TRUE(buffer[4] == expected[4]); | ||
} | ||
|
||
// e.g. `Dst` follow `src`. | ||
// str: [abcdefghij] | ||
// [__src_____] | ||
// [_____Dst__] | ||
TEST(LlvmLibcWMemmoveTest, SrcFollowDst) { | ||
wchar_t buffer[] = {L'z', L'a', L'b', L'z'}; | ||
|
||
wchar_t *dst = buffer + 1; | ||
wchar_t *ret = LIBC_NAMESPACE::wmemmove(dst, buffer + 2, 1); | ||
EXPECT_EQ(ret, dst); | ||
|
||
const char expected[] = {L'z', L'b', L'b', L'z'}; | ||
EXPECT_TRUE(buffer[0] == expected[0]); | ||
EXPECT_TRUE(buffer[1] == expected[1]); | ||
EXPECT_TRUE(buffer[2] == expected[2]); | ||
EXPECT_TRUE(buffer[3] == expected[3]); | ||
} | ||
|
||
TEST(LlvmLibcWMemmoveTest, DstFollowSrc) { | ||
wchar_t buffer[] = {L'z', L'a', L'b', L'z'}; | ||
|
||
wchar_t *dst = buffer + 2; | ||
wchar_t *ret = LIBC_NAMESPACE::wmemmove(dst, buffer + 1, 1); | ||
EXPECT_EQ(ret, dst); | ||
|
||
const char expected[] = {L'z', L'a', L'a', L'z'}; | ||
EXPECT_TRUE(buffer[0] == expected[0]); | ||
EXPECT_TRUE(buffer[1] == expected[1]); | ||
EXPECT_TRUE(buffer[2] == expected[2]); | ||
EXPECT_TRUE(buffer[3] == expected[3]); | ||
} | ||
|
||
#if defined(LIBC_ADD_NULL_CHECKS) && !defined(LIBC_HAS_SANITIZER) | ||
TEST(LlvmLibcWMemmoveTest, NullptrCrash) { | ||
wchar_t buffer[] = {L'a', L'b'}; | ||
// Passing in a nullptr should crash the program. | ||
EXPECT_DEATH([&buffer] { LIBC_NAMESPACE::wmemmove(buffer, nullptr, 2); }, | ||
WITH_SIGNAL(-1)); | ||
EXPECT_DEATH([&buffer] { LIBC_NAMESPACE::wmemmove(nullptr, buffer, 2); }, | ||
WITH_SIGNAL(-1)); | ||
} | ||
#endif // LIBC_HAS_ADDRESS_SANITIZER |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function uses
inline_memmove
and notwctype_utils
, need to correct the dependency here.