Skip to content

[clang][bytecode] Handle memmove like memcpy #118431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions clang/lib/AST/ByteCode/InterpBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1802,9 +1802,11 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
peekToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(2)));
assert(!Size.isSigned() && "memcpy and friends take an unsigned size");

if (ID == Builtin::BImemcpy)
if (ID == Builtin::BImemcpy || ID == Builtin::BImemmove)
diagnoseNonConstexprBuiltin(S, OpPC, ID);

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

if (DestPtr.isDummy() || SrcPtr.isDummy())
return false;

Expand All @@ -1817,7 +1819,7 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
if (SrcPtr.isZero() || DestPtr.isZero()) {
Pointer DiagPtr = (SrcPtr.isZero() ? SrcPtr : DestPtr);
S.FFDiag(S.Current->getSource(OpPC), diag::note_constexpr_memcpy_null)
<< /*IsMove=*/false << /*IsWchar=*/false << !SrcPtr.isZero()
<< /*IsMove=*/Move << /*IsWchar=*/false << !SrcPtr.isZero()
<< DiagPtr.toDiagnosticString(S.getASTContext());
return false;
}
Expand Down Expand Up @@ -2291,6 +2293,8 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,

case Builtin::BI__builtin_memcpy:
case Builtin::BImemcpy:
case Builtin::BI__builtin_memmove:
case Builtin::BImemmove:
if (!interp__builtin_memcpy(S, OpPC, Frame, F, Call))
return false;
break;
Expand Down
7 changes: 7 additions & 0 deletions clang/test/AST/ByteCode/builtin-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,4 +1146,11 @@ namespace BuiltinMemcpy {
// both-note {{source of 'memcpy' is nullptr}}


constexpr int simpleMove() {
int a = 12;
int b = 0;
__builtin_memmove(&b, &a, sizeof(a));
return b;
}
static_assert(simpleMove() == 12);
}
Loading