diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index c5473322ecb28..b788656f9484f 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -1813,9 +1813,6 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC, bool Move = (ID == Builtin::BI__builtin_memmove || ID == Builtin::BImemmove); - if (DestPtr.isDummy() || SrcPtr.isDummy()) - return false; - // If the size is zero, we treat this as always being a valid no-op. if (Size.isZero()) { S.Stk.push(DestPtr); @@ -1830,6 +1827,10 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC, return false; } + // As a last resort, reject dummy pointers. + if (DestPtr.isDummy() || SrcPtr.isDummy()) + return false; + if (!DoBitCastPtr(S, OpPC, SrcPtr, DestPtr)) return false; diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp index 211ca6e164cbf..b951c04dde598 100644 --- a/clang/test/AST/ByteCode/builtin-functions.cpp +++ b/clang/test/AST/ByteCode/builtin-functions.cpp @@ -1169,6 +1169,10 @@ namespace BuiltinMemcpy { static_assert(__builtin_memcpy(null_incomplete, null_incomplete, sizeof(wchar_t))); // both-error {{not an integral constant expression}} \ // both-note {{source of 'memcpy' is nullptr}} + wchar_t global; + constexpr wchar_t *null = 0; + static_assert(__builtin_memcpy(&global, null, sizeof(wchar_t))); // both-error {{not an integral constant expression}} \ + // both-note {{source of 'memcpy' is nullptr}} constexpr int simpleMove() { int a = 12;