aboutsummaryrefslogtreecommitdiff
path: root/clang/test/AST/ByteCode/builtin-functions.cpp
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2025-03-26 08:19:31 +0100
committerGitHub <noreply@github.com>2025-03-26 08:19:31 +0100
commit0bc2c5b2a4ca49011db27f7e8632d5d5ebc0ef5d (patch)
treeab8884e548fee415f816741cca71e0aeb54f0f27 /clang/test/AST/ByteCode/builtin-functions.cpp
parentab5de9af4c00cecf166be51f3e93df2762692788 (diff)
downloadllvm-0bc2c5b2a4ca49011db27f7e8632d5d5ebc0ef5d.zip
llvm-0bc2c5b2a4ca49011db27f7e8632d5d5ebc0ef5d.tar.gz
llvm-0bc2c5b2a4ca49011db27f7e8632d5d5ebc0ef5d.tar.bz2
Reapply "[clang][bytecode] Implement __builtin_{wcscmp,wcsncmp} (#132… (#132963)
…723)" This reverts commit 1e2ad6793ac205607e7c809283cf69e1cc36a69a. Fix the previous commit on big-endian hosts by _not_ falling through to the `uint8_t` code path.
Diffstat (limited to 'clang/test/AST/ByteCode/builtin-functions.cpp')
-rw-r--r--clang/test/AST/ByteCode/builtin-functions.cpp46
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 8288223..8408286 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -28,6 +28,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 {
@@ -72,6 +74,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";