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

Oliver Hunt via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Jan 13 12:46:46 PST 2026


================
@@ -585,12 +585,20 @@ static void EmitBaseInitializer(CodeGenFunction &CGF,
                                           isBaseVirtual);
 }
 
-static bool isMemcpyEquivalentSpecialMember(const CXXMethodDecl *D) {
+static bool isMemcpyEquivalentSpecialMember(CodeGenModule &CGM,
+                                            const CXXMethodDecl *D) {
   auto *CD = dyn_cast<CXXConstructorDecl>(D);
   if (!(CD && CD->isCopyOrMoveConstructor()) &&
       !D->isCopyAssignmentOperator() && !D->isMoveAssignmentOperator())
     return false;
 
+  // Non-trivially-copyable fields with pointer field protection need to be
+  // copied one by one.
+  if (!CGM.getContext().arePFPFieldsTriviallyCopyable(D->getParent()) &&
+      CGM.getContext().hasPFPFields(
+          CGM.getContext().getCanonicalTagType(D->getParent())))
----------------
ojhunt wrote:

```suggestion
  ASTContext &Ctx = CGM.getContext(); // The rest of the function should be updated to use this but not in this PR
  CXXRecordDecl *Parent = D->getParent();
  WhateverTheTypeIs *CanonicalParentType = 
    Ctx.getCanonicalTagType(Parent);
  if (!Ctx.arePFPFieldsTriviallyCopyable(Parent) &&
    Ctx.hasPFPFields(CanonicalParentType))
```

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


More information about the llvm-branch-commits mailing list