Create mark_dependence for array allocation in OSLogOptimization

With #70242 mark_dependence was added while emitting uninitialized array allocation
between the unsafe pointer and the array value returned.
Without it, we can end up with use after free of the unsafe pointer if the array's lifetime
is shortened. Along with this change, pattern matching of all array optimizations was updated to include
mark_dependence.

This change adds mark_dependence for uninitialized array allocation in OSLogOptimization which was left out previously.
With this, potential use-after-free of the unsafe pointer is prevented and all updated array optimizations apply
to the array created by OSLogOptimization.

Fixes rdar://122922902
This commit is contained in:
Meghana Gupta
2024-02-26 23:31:46 -08:00
parent bb6de776d9
commit 0fc2e1343e
2 changed files with 6 additions and 2 deletions

View File

@@ -529,6 +529,8 @@ static SILValue emitCodeForConstantArray(ArrayRef<SILValue> elements,
builder.createDestructureTuple(loc, applyInst);
SILValue arraySIL = destructureInst->getResults()[0];
SILValue storagePointerSIL = destructureInst->getResults()[1];
storagePointerSIL = builder.createMarkDependence(
loc, storagePointerSIL, arraySIL, MarkDependenceKind::Escaping);
if (elements.empty()) {
// Nothing more to be done if we are creating an empty array.