aboutsummaryrefslogtreecommitdiff
path: root/clang/test/AST/ByteCode/builtin-functions.cpp
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2024-12-12 08:59:35 +0100
committerGitHub <noreply@github.com>2024-12-12 08:59:35 +0100
commit8713914d76cb9d6b54278dd75fecb68bb93f6ea5 (patch)
treed148346d9a552a53847ef9562034ca7d5f9492f1 /clang/test/AST/ByteCode/builtin-functions.cpp
parent9c50182bf4942f88cc9876eb29e70802448cddc8 (diff)
downloadllvm-8713914d76cb9d6b54278dd75fecb68bb93f6ea5.zip
llvm-8713914d76cb9d6b54278dd75fecb68bb93f6ea5.tar.gz
llvm-8713914d76cb9d6b54278dd75fecb68bb93f6ea5.tar.bz2
[clang][bytecode] Handle __builtin_memcmp (#119544)
Diffstat (limited to 'clang/test/AST/ByteCode/builtin-functions.cpp')
-rw-r--r--clang/test/AST/ByteCode/builtin-functions.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp
index ef6faae..83caa1d 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -1223,3 +1223,36 @@ namespace BuiltinMemcpy {
static_assert(test_memcpy(0, 1, sizeof(int) * 2) == 2334); // both-error {{not an integral constant expression}} \
// both-note {{in call}}
}
+
+namespace Memcmp {
+ constexpr unsigned char ku00fe00[] = {0x00, 0xfe, 0x00};
+ constexpr unsigned char ku00feff[] = {0x00, 0xfe, 0xff};
+ constexpr signed char ks00fe00[] = {0, -2, 0};
+ constexpr signed char ks00feff[] = {0, -2, -1};
+ static_assert(__builtin_memcmp(ku00feff, ks00fe00, 2) == 0);
+ static_assert(__builtin_memcmp(ku00feff, ks00fe00, 99) == 1);
+ static_assert(__builtin_memcmp(ku00fe00, ks00feff, 99) == -1);
+ static_assert(__builtin_memcmp(ks00feff, ku00fe00, 2) == 0);
+ static_assert(__builtin_memcmp(ks00feff, ku00fe00, 99) == 1);
+ static_assert(__builtin_memcmp(ks00fe00, ku00feff, 99) == -1);
+ static_assert(__builtin_memcmp(ks00fe00, ks00feff, 2) == 0);
+ static_assert(__builtin_memcmp(ks00feff, ks00fe00, 99) == 1);
+ static_assert(__builtin_memcmp(ks00fe00, ks00feff, 99) == -1);
+
+ struct Bool3Tuple { bool bb[3]; };
+ constexpr Bool3Tuple kb000100 = {{false, true, false}};
+ static_assert(sizeof(bool) != 1u || __builtin_memcmp(ks00fe00, kb000100.bb, 1) == 0); // both-error {{constant}} \
+ // both-note {{not supported}}
+
+ constexpr char a = 'a';
+ constexpr char b = 'a';
+ static_assert(__builtin_memcmp(&a, &b, 1) == 0);
+
+ extern struct Incomplete incomplete;
+ static_assert(__builtin_memcmp(&incomplete, "", 0u) == 0);
+ static_assert(__builtin_memcmp("", &incomplete, 0u) == 0);
+ static_assert(__builtin_memcmp(&incomplete, "", 1u) == 42); // both-error {{not an integral constant}} \
+ // both-note {{not supported}}
+ static_assert(__builtin_memcmp("", &incomplete, 1u) == 42); // both-error {{not an integral constant}} \
+ // both-note {{not supported}}
+}