[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


================
@@ -2268,13 +2293,22 @@ CodeGenFunction::EmitNullInitialization(Address DestPtr, QualType Ty) {
 
     // Get and call the appropriate llvm.memcpy overload.
     Builder.CreateMemCpy(DestPtr, SrcPtr, SizeVal, false);
-    return;
+  } else {
+    // Otherwise, just memset the whole thing to zero.  This is legal
----------------
ojhunt wrote:

This means types that require constructors will be doing zero initialization, then reinitializing fields. From a codegen PoV this can lead to codegen along the lines of

```
zero the memory; // compiler is set to initialize all memory
zero the memory; // this branch means objects that are not zero initializable get initialized again
initialize the memory; // the struct is not zero initializable the constructor/initializer will run
```
Ideally the compiler will optimized this down, but it's both extra codegen, and extra optimization work.

Given that your model assumes that null is a safe value for PFP fields, the `isZeroInitializable()` call should return true. For non-zero initializable objects, the initialization code for the object is responsible for initializing the PFP fields.

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


More information about the llvm-branch-commits mailing list