[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 17:27:28 PDT 2025
================
@@ -2201,6 +2215,22 @@ void CodeGenFunction::EmitCXXConstructorCall(
EmitTypeCheck(CodeGenFunction::TCK_ConstructorCall, Loc, This,
getContext().getRecordType(ClassDecl), CharUnits::Zero());
+ // When initializing an object that has pointer field protection and whose
+ // fields are not trivially relocatable we must initialize any pointer fields
+ // to a valid signed pointer (any pointer value will do, but we just use null
+ // pointers). This is because if the object is subsequently copied, its copy
+ // constructor will need to read and authenticate any pointer fields in order
+ // to copy the object to a new address, which will fail if the pointers are
+ // uninitialized.
+ if (!getContext().arePFPFieldsTriviallyRelocatable(D->getParent())) {
----------------
ojhunt wrote:
Correctly initializing the object is the job of the constructor, not the caller. in cases where a constructor is being called, you should be ensuring that the constructor does the correct thing.
https://github.com/llvm/llvm-project/pull/133538
More information about the llvm-branch-commits
mailing list