diff options
author | Timm Baeder <tbaeder@redhat.com> | 2025-03-24 15:03:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-24 15:03:49 +0100 |
commit | f7aea4d081f77dba48b0fc019f59b678fb679aa8 (patch) | |
tree | 7852cd4ab4c9d389bbe8e54b39b401ac92fca6ed /clang/test/AST/ByteCode/builtin-functions.cpp | |
parent | 7ada6f111f133ef2a749c7f395cf337acdaf0f31 (diff) | |
download | llvm-f7aea4d081f77dba48b0fc019f59b678fb679aa8.zip llvm-f7aea4d081f77dba48b0fc019f59b678fb679aa8.tar.gz llvm-f7aea4d081f77dba48b0fc019f59b678fb679aa8.tar.bz2 |
[clang][bytecode] Implement __builtin_{wcscmp,wcsncmp} (#132723)
Diffstat (limited to 'clang/test/AST/ByteCode/builtin-functions.cpp')
-rw-r--r-- | clang/test/AST/ByteCode/builtin-functions.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp index 8cba1ec..f42ff49 100644 --- a/clang/test/AST/ByteCode/builtin-functions.cpp +++ b/clang/test/AST/ByteCode/builtin-functions.cpp @@ -22,6 +22,8 @@ extern "C" { extern char *strchr(const char *s, int c); extern wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n); extern wchar_t *wcschr(const wchar_t *s, wchar_t c); + extern int wcscmp(const wchar_t *s1, const wchar_t *s2); + extern int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n); } namespace strcmp { @@ -66,6 +68,50 @@ namespace strcmp { static_assert(__builtin_strncmp("abab\0banana", "abab\0canada", 100) == 0); } +namespace WcsCmp { + constexpr wchar_t kFoobar[6] = {L'f',L'o',L'o',L'b',L'a',L'r'}; + constexpr wchar_t kFoobazfoobar[12] = {L'f',L'o',L'o',L'b',L'a',L'z',L'f',L'o',L'o',L'b',L'a',L'r'}; + + static_assert(__builtin_wcscmp(L"abab", L"abab") == 0); + static_assert(__builtin_wcscmp(L"abab", L"abba") == -1); + static_assert(__builtin_wcscmp(L"abab", L"abaa") == 1); + static_assert(__builtin_wcscmp(L"ababa", L"abab") == 1); + static_assert(__builtin_wcscmp(L"abab", L"ababa") == -1); + static_assert(__builtin_wcscmp(L"abab\0banana", L"abab") == 0); + static_assert(__builtin_wcscmp(L"abab", L"abab\0banana") == 0); + static_assert(__builtin_wcscmp(L"abab\0banana", L"abab\0canada") == 0); +#if __WCHAR_WIDTH__ == 32 + static_assert(__builtin_wcscmp(L"a\x83838383", L"a") == (wchar_t)-1U >> 31); +#endif + static_assert(__builtin_wcscmp(0, L"abab") == 0); // both-error {{not an integral constant}} \ + // both-note {{dereferenced null}} + static_assert(__builtin_wcscmp(L"abab", 0) == 0); // both-error {{not an integral constant}} \ + // both-note {{dereferenced null}} + + static_assert(__builtin_wcscmp(kFoobar, kFoobazfoobar) == -1); + static_assert(__builtin_wcscmp(kFoobar, kFoobazfoobar + 6) == 0); // both-error {{not an integral constant}} \ + // both-note {{dereferenced one-past-the-end}} + + static_assert(__builtin_wcsncmp(L"abaa", L"abba", 5) == -1); + static_assert(__builtin_wcsncmp(L"abaa", L"abba", 4) == -1); + static_assert(__builtin_wcsncmp(L"abaa", L"abba", 3) == -1); + static_assert(__builtin_wcsncmp(L"abaa", L"abba", 2) == 0); + static_assert(__builtin_wcsncmp(L"abaa", L"abba", 1) == 0); + static_assert(__builtin_wcsncmp(L"abaa", L"abba", 0) == 0); + static_assert(__builtin_wcsncmp(0, 0, 0) == 0); + static_assert(__builtin_wcsncmp(L"abab\0banana", L"abab\0canada", 100) == 0); +#if __WCHAR_WIDTH__ == 32 + static_assert(__builtin_wcsncmp(L"a\x83838383", L"aa", 2) == + (wchar_t)-1U >> 31); +#endif + + static_assert(__builtin_wcsncmp(kFoobar, kFoobazfoobar, 6) == -1); + static_assert(__builtin_wcsncmp(kFoobar, kFoobazfoobar, 7) == -1); + static_assert(__builtin_wcsncmp(kFoobar, kFoobazfoobar + 6, 6) == 0); + static_assert(__builtin_wcsncmp(kFoobar, kFoobazfoobar + 6, 7) == 0); // both-error {{not an integral constant}} \ + // both-note {{dereferenced one-past-the-end}} +} + /// Copied from constant-expression-cxx11.cpp namespace strlen { constexpr const char *a = "foo\0quux"; |