diff options
author | Timm Baeder <tbaeder@redhat.com> | 2024-12-11 12:06:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-11 12:06:56 +0100 |
commit | 4dde52d76b5342fd7e0b51094580818f3934ae2f (patch) | |
tree | f05dcc656c2ab511b48f3d3a372a1b32dbcdf9b3 /clang/test/AST/ByteCode/builtin-functions.cpp | |
parent | 14dcf8214f9c66172d17c1cfaec6aec0030748e0 (diff) | |
download | llvm-4dde52d76b5342fd7e0b51094580818f3934ae2f.zip llvm-4dde52d76b5342fd7e0b51094580818f3934ae2f.tar.gz llvm-4dde52d76b5342fd7e0b51094580818f3934ae2f.tar.bz2 |
[clang][bytecode] Check for overlapping memcpy regions (#119535)
Diffstat (limited to 'clang/test/AST/ByteCode/builtin-functions.cpp')
-rw-r--r-- | clang/test/AST/ByteCode/builtin-functions.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp index 7dd08cb..ef6faae 100644 --- a/clang/test/AST/ByteCode/builtin-functions.cpp +++ b/clang/test/AST/ByteCode/builtin-functions.cpp @@ -1207,4 +1207,19 @@ namespace BuiltinMemcpy { } static_assert(memcpyTypeRem() == 12); // both-error {{not an integral constant expression}} \ // both-note {{in call to}} + + template<typename T> + constexpr T result(T (&arr)[4]) { + return arr[0] * 1000 + arr[1] * 100 + arr[2] * 10 + arr[3]; + } + + constexpr int test_memcpy(int a, int b, int n) { + int arr[4] = {1, 2, 3, 4}; + __builtin_memcpy(arr + a, arr + b, n); // both-note {{overlapping memory regions}} + return result(arr); + } + + static_assert(test_memcpy(1, 2, sizeof(int)) == 1334); + static_assert(test_memcpy(0, 1, sizeof(int) * 2) == 2334); // both-error {{not an integral constant expression}} \ + // both-note {{in call}} } |