[llvm-branch-commits] [clang] [Clang] Add pointer field protection feature. (PR #133538)

Florian Mayer via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Dec 4 16:35:48 PST 2025


================
@@ -4522,18 +4522,48 @@ 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));
+    Value *TypeSize = ConstantInt::get(
+        SizeVal->getType(),
+        getContext()
+            .getTypeSizeInChars(E->getArg(0)->getType()->getPointeeType())
+            .getQuantity());
     if (BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_trivially_relocate)
-      SizeVal = Builder.CreateMul(
-          SizeVal,
-          ConstantInt::get(
-              SizeVal->getType(),
-              getContext()
-                  .getTypeSizeInChars(E->getArg(0)->getType()->getPointeeType())
-                  .getQuantity()));
+      SizeVal = Builder.CreateMul(SizeVal, TypeSize);
     EmitArgCheck(TCK_Store, Dest, E->getArg(0), 0);
     EmitArgCheck(TCK_Load, Src, E->getArg(1), 1);
     auto *I = Builder.CreateMemMove(Dest, Src, SizeVal, false);
     addInstToNewSourceAtom(I, nullptr);
+    if (BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_trivially_relocate) {
+      if (getContext().hasPFPFields(
+              E->getArg(0)->getType()->getPointeeType())) {
+        BasicBlock *Entry = Builder.GetInsertBlock();
+        BasicBlock *Loop = createBasicBlock("loop");
----------------
fmayer wrote:

should we call this in a way that leaves some breadcrumbs that this is from pfp? `pfp.relocate.loop` or something?

maybe also add a comment like
```
// call emitPFPTrivialRelocation for every object in the array we are relocating?
```

(if my understanding of this loop is correct)

https://github.com/llvm/llvm-project/pull/133538


More information about the llvm-branch-commits mailing list