[llvm-branch-commits] CodeGen: Fix implementation of __builtin_trivially_relocate. (PR #140312)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri May 16 14:38:26 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen
Author: Peter Collingbourne (pcc)
<details>
<summary>Changes</summary>
The builtin is documented to copy `count` elements, but the implementation
copies `count` bytes. Fix that.
---
Full diff: https://github.com/llvm/llvm-project/pull/140312.diff
2 Files Affected:
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+8)
- (modified) clang/test/CodeGenCXX/cxx2c-trivially-relocatable.cpp (+1-1)
``````````diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 48cfbda12b2ac..0cfb88a9d9789 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -4425,6 +4425,14 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
Address Dest = EmitPointerWithAlignment(E->getArg(0));
Address Src = EmitPointerWithAlignment(E->getArg(1));
Value *SizeVal = EmitScalarExpr(E->getArg(2));
+ if (BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_trivially_relocate)
+ SizeVal = Builder.CreateMul(
+ SizeVal,
+ ConstantInt::get(
+ SizeVal->getType(),
+ getContext()
+ .getTypeSizeInChars(E->getArg(0)->getType()->getPointeeType())
+ .getQuantity()));
EmitArgCheck(TCK_Store, Dest, E->getArg(0), 0);
EmitArgCheck(TCK_Load, Src, E->getArg(1), 1);
Builder.CreateMemMove(Dest, Src, SizeVal, false);
diff --git a/clang/test/CodeGenCXX/cxx2c-trivially-relocatable.cpp b/clang/test/CodeGenCXX/cxx2c-trivially-relocatable.cpp
index 17144cffb6476..63f3ba8e74ed5 100644
--- a/clang/test/CodeGenCXX/cxx2c-trivially-relocatable.cpp
+++ b/clang/test/CodeGenCXX/cxx2c-trivially-relocatable.cpp
@@ -8,7 +8,7 @@ struct S trivially_relocatable_if_eligible {
};
// CHECK: @_Z4testP1SS0_
-// CHECK: call void @llvm.memmove.p0.p0.i64
+// CHECK: call void @llvm.memmove.p0.p0.i64({{.*}}, i64 8
// CHECK-NOT: __builtin
// CHECK: ret
void test(S* source, S* dest) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/140312
More information about the llvm-branch-commits
mailing list