[llvm-branch-commits] Add pointer field protection feature. (PR #133538)
Oliver Hunt via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed May 14 23:39:09 PDT 2025
================
@@ -1319,14 +1319,66 @@ static llvm::Value *CoerceIntOrPtrToIntOrPtr(llvm::Value *Val, llvm::Type *Ty,
/// This safely handles the case when the src type is smaller than the
/// destination type; in this situation the values of bits which not
/// present in the src are undefined.
-static llvm::Value *CreateCoercedLoad(Address Src, llvm::Type *Ty,
+static llvm::Value *CreateCoercedLoad(Address Src, QualType SrcFETy,
+ llvm::Type *Ty,
CodeGenFunction &CGF) {
llvm::Type *SrcTy = Src.getElementType();
// If SrcTy and Ty are the same, just do a load.
if (SrcTy == Ty)
return CGF.Builder.CreateLoad(Src);
+ // 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, true);
----------------
ojhunt wrote:
It still doesn't make things worse than generating (and caching) a function, if the function is small then the inliner handles it - though here we're getting into: you should just be generating the correct copy, move, etc functions for the type, and all the other behaviors fall out of that automatically.
https://github.com/llvm/llvm-project/pull/133538
More information about the llvm-branch-commits
mailing list