Skip to content

Commit 7895513

Browse files
authored
[clang][bytecode] Handle memmove like memcpy (#118431)
This is the same thing for us, except for diagnostic differences.
1 parent 4516263 commit 7895513

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,9 +1802,11 @@ static bool interp__builtin_memcpy(InterpState &S, CodePtr OpPC,
18021802
peekToAPSInt(S.Stk, *S.getContext().classify(Call->getArg(2)));
18031803
assert(!Size.isSigned() && "memcpy and friends take an unsigned size");
18041804

1805-
if (ID == Builtin::BImemcpy)
1805+
if (ID == Builtin::BImemcpy || ID == Builtin::BImemmove)
18061806
diagnoseNonConstexprBuiltin(S, OpPC, ID);
18071807

1808+
bool Move = (ID == Builtin::BI__builtin_memmove || ID == Builtin::BImemmove);
1809+
18081810
if (DestPtr.isDummy() || SrcPtr.isDummy())
18091811
return false;
18101812

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

22922294
case Builtin::BI__builtin_memcpy:
22932295
case Builtin::BImemcpy:
2296+
case Builtin::BI__builtin_memmove:
2297+
case Builtin::BImemmove:
22942298
if (!interp__builtin_memcpy(S, OpPC, Frame, F, Call))
22952299
return false;
22962300
break;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,4 +1146,11 @@ namespace BuiltinMemcpy {
11461146
// both-note {{source of 'memcpy' is nullptr}}
11471147

11481148

1149+
constexpr int simpleMove() {
1150+
int a = 12;
1151+
int b = 0;
1152+
__builtin_memmove(&b, &a, sizeof(a));
1153+
return b;
1154+
}
1155+
static_assert(simpleMove() == 12);
11491156
}

0 commit comments

Comments
 (0)