[llvm-branch-commits] [clang] [Clang] Add pointer field protection feature. (PR #172119)
Florian Mayer via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jan 13 08:30:15 PST 2026
================
@@ -1310,21 +1310,92 @@ static llvm::Value *CoerceIntOrPtrToIntOrPtr(llvm::Value *Val, llvm::Type *Ty,
return Val;
}
+static std::vector<PFPField> findPFPCoercedFields(CodeGenFunction &CGF,
+ QualType SrcFETy) {
+ // Coercion directly through memory does not work if the structure has pointer
+ // field protection because the struct in registers has a different bit
+ // pattern to the struct in memory, so we must read the elements one by one
+ // and use them to form the coerced structure.
+ std::vector<PFPField> PFPFields;
+ CGF.getContext().findPFPFields(SrcFETy, CharUnits::Zero(), PFPFields,
+ /*IncludeVBases=*/true);
+
+ // Because we don't know which union member is selected, we don't modify the
+ // in-memory representation when passing a pointer that is part of a union
+ // field. This requires the union member to be trivially copyable;
+ // non-trivially-copyable unions cannot be directly passed by value.
+ llvm::erase_if(PFPFields, [](PFPField F) { return F.isWithinUnion; });
+ return PFPFields;
+}
+
+static llvm::Value *CreatePFPCoercedLoad(Address Src, QualType SrcFETy,
+ llvm::Type *Ty, CodeGenFunction &CGF) {
+ std::vector<PFPField> PFPFields = findPFPCoercedFields(CGF, SrcFETy);
----------------
fmayer wrote:
maybe let's use a different name? Throughout this change, `PFPFields` is for the result of `findPFPFields`
https://github.com/llvm/llvm-project/pull/172119
More information about the llvm-branch-commits
mailing list