[llvm] [llubi] Implement memory manipulation intrinsics (PR #204932)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 20 08:51:37 PDT 2026
================
@@ -698,6 +699,120 @@ class InstExecutor : public InstVisitor<InstExecutor, void>,
return V.asInteger();
}
+ AnyValue callMemTransferIntrinsic(ArrayRef<AnyValue> Args,
+ Intrinsic::ID IID) {
+ if (Args[2].isPoison()) {
+ reportImmediateUB() << "Memory transfer intrinsic with poison length.";
+ return AnyValue::poison();
+ }
+
+ const APInt &Length = Args[2].asInteger();
+ if (Length.getActiveBits() > 64) {
+ reportImmediateUB()
+ << "Memory transfer intrinsic length overflows uint64_t.";
+ return AnyValue::poison();
+ }
+
+ const uint64_t Len = Length.getZExtValue();
+ if (Len == 0)
+ return AnyValue();
+
+ if (Args[0].isPoison()) {
+ reportImmediateUB()
+ << "Memory transfer intrinsic with poison destination pointer.";
+ return AnyValue::poison();
+ }
+
+ if (Args[1].isPoison()) {
+ reportImmediateUB()
+ << "Memory copy intrinsic with poison source pointer.";
+ return AnyValue::poison();
+ }
+
+ const Pointer &DstPtr = Args[0].asPointer();
+ const Pointer &SrcPtr = Args[1].asPointer();
+
+ auto [SrcMO, SrcOffset] =
+ verifyMemAccess(SrcPtr, Len, Align(1), /*IsStore=*/false);
+ if (!SrcMO)
+ return AnyValue();
+
+ auto [DstMO, DstOffset] =
+ verifyMemAccess(DstPtr, Len, Align(1), /*IsStore=*/true);
+ if (!DstMO)
+ return AnyValue();
+
+ if (DstMO->isConstant()) {
+ reportImmediateUB() << "Try to write to a constant memory object: "
+ << DstPtr << ".";
+ return AnyValue::poison();
+ }
+
+ if (IID == Intrinsic::memcpy || IID == Intrinsic::memcpy_inline) {
+ if (SrcMO == DstMO && SrcOffset != DstOffset) {
----------------
nikic wrote:
Yes, it violates the C spec requirements for memcpy, on the assumption that the lowered implementation of memcpy will always handle it correctly.
https://github.com/llvm/llvm-project/pull/204932
More information about the llvm-commits
mailing list