Skip to content

Commit 3f39c5d

Browse files
authored
[clang][bytecode] Reject memcpy dummy pointers after null check (llvm#118460)
To match the diagnostic output of the current interpreter.
1 parent bdc6faf commit 3f39c5d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,9 +1813,6 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
18131813

18141814
bool Move = (ID == Builtin::BI__builtin_memmove || ID == Builtin::BImemmove);
18151815

1816-
if (DestPtr.isDummy() || SrcPtr.isDummy())
1817-
return false;
1818-
18191816
// If the size is zero, we treat this as always being a valid no-op.
18201817
if (Size.isZero()) {
18211818
S.Stk.push<Pointer>(DestPtr);
@@ -1830,6 +1827,10 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
18301827
return false;
18311828
}
18321829

1830+
// As a last resort, reject dummy pointers.
1831+
if (DestPtr.isDummy() || SrcPtr.isDummy())
1832+
return false;
1833+
18331834
if (!DoBitCastPtr(S, OpPC, SrcPtr, DestPtr))
18341835
return false;
18351836

clang/test/AST/ByteCode/builtin-functions.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,10 @@ namespace BuiltinMemcpy {
11691169
static_assert(__builtin_memcpy(null_incomplete, null_incomplete, sizeof(wchar_t))); // both-error {{not an integral constant expression}} \
11701170
// both-note {{source of 'memcpy' is nullptr}}
11711171

1172+
wchar_t global;
1173+
constexpr wchar_t *null = 0;
1174+
static_assert(__builtin_memcpy(&global, null, sizeof(wchar_t))); // both-error {{not an integral constant expression}} \
1175+
// both-note {{source of 'memcpy' is nullptr}}
11721176

11731177
constexpr int simpleMove() {
11741178
int a = 12;

0 commit comments

Comments
 (0)