diff options
author | Timm Baeder <tbaeder@redhat.com> | 2025-03-20 21:01:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-20 21:01:14 +0100 |
commit | 7492666482aececf2a470a8b8a44580d7f8712c3 (patch) | |
tree | d5a896b24b03e9c6e76d989ee56ecb1a501b299b /clang/test/AST/ByteCode/builtin-functions.cpp | |
parent | 3520dc5e7a9a30de2db7e9f6b8b4863aed261ca8 (diff) | |
download | llvm-7492666482aececf2a470a8b8a44580d7f8712c3.zip llvm-7492666482aececf2a470a8b8a44580d7f8712c3.tar.gz llvm-7492666482aececf2a470a8b8a44580d7f8712c3.tar.bz2 |
[clang][bytecode] Implement __builtin_wmemchr (#132254)
Diffstat (limited to 'clang/test/AST/ByteCode/builtin-functions.cpp')
-rw-r--r-- | clang/test/AST/ByteCode/builtin-functions.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp index 11ff48b..3dd3480 100644 --- a/clang/test/AST/ByteCode/builtin-functions.cpp +++ b/clang/test/AST/ByteCode/builtin-functions.cpp @@ -20,6 +20,7 @@ extern "C" { extern size_t wcslen(const wchar_t *p); extern void *memchr(const void *s, int c, size_t n); extern char *strchr(const char *s, int c); + extern wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n); } namespace strcmp { @@ -1489,3 +1490,26 @@ namespace Strchr { constexpr bool a = !strchr("hello", 'h'); // both-error {{constant expression}} \ // both-note {{non-constexpr function 'strchr' cannot be used in a constant expression}} } + +namespace WMemChr { + constexpr const wchar_t *kStr = L"abca\xffff\0dL"; + constexpr wchar_t kFoo[] = {L'f', L'o', L'o'}; + + static_assert(__builtin_wmemchr(kStr, L'a', 0) == nullptr); + static_assert(__builtin_wmemchr(kStr, L'a', 1) == kStr); + static_assert(__builtin_wmemchr(kStr, L'\0', 5) == nullptr); + static_assert(__builtin_wmemchr(kStr, L'\0', 6) == kStr + 5); + static_assert(__builtin_wmemchr(kStr, L'\xffff', 8) == kStr + 4); + static_assert(__builtin_wmemchr(kFoo, L'x', 3) == nullptr); + static_assert(__builtin_wmemchr(kFoo, L'x', 4) == nullptr); // both-error {{not an integral constant}} \ + // both-note {{dereferenced one-past-the-end}} + static_assert(__builtin_wmemchr(nullptr, L'x', 3) == nullptr); // both-error {{not an integral constant}} \ + // both-note {{dereferenced null}} + static_assert(__builtin_wmemchr(nullptr, L'x', 0) == nullptr); + + constexpr bool b = !wmemchr(L"hello", L'h', 3); // both-error {{constant expression}} \ + // both-note {{non-constexpr function 'wmemchr' cannot be used in a constant expression}} + + constexpr wchar_t kStr2[] = {L'f', L'o', L'\xffff', L'o'}; + static_assert(__builtin_wmemchr(kStr2, L'\xffff', 4) == kStr2 + 2); +} |