[clang] 7895513 - [clang][bytecode] Handle memmove like memcpy (#118431)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 2 22:56:10 PST 2024
Author: Timm Baeder
Date: 2024-12-03T07:56:06+01:00
New Revision: 789551362e20c1adf1f292a256b7276c2045d4e1
URL: https://github.com/llvm/llvm-project/commit/789551362e20c1adf1f292a256b7276c2045d4e1
DIFF: https://github.com/llvm/llvm-project/commit/789551362e20c1adf1f292a256b7276c2045d4e1.diff
LOG: [clang][bytecode] Handle memmove like memcpy (#118431)
This is the same thing for us, except for diagnostic differences.
Added:
Modified:
clang/lib/AST/ByteCode/InterpBuiltin.cpp
clang/test/AST/ByteCode/builtin-functions.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index aab380c0925d29..f3024dc3e26fe1 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -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;
@@ -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;
}
@@ -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;
diff --git a/clang/test/AST/ByteCode/builtin-functions.cpp b/clang/test/AST/ByteCode/builtin-functions.cpp
index dfee35d6399a6c..b94adfa3ab36bd 100644
--- a/clang/test/AST/ByteCode/builtin-functions.cpp
+++ b/clang/test/AST/ByteCode/builtin-functions.cpp
@@ -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);
}
More information about the cfe-commits
mailing list