Files
swift-mirror/lib/SILOptimizer/LoopTransforms/LoopRotate.cpp
Arnold Schwaighofer 300ba4c051 [6.2] LoopRotate: Fix a by reference map bug under reallocation
Issue:
When using a densemap subscript expression on both sides of an
assignment in the same statement of the same map we run into the issue
that the map can reallocate because of the assignment but we are
referencing the value of the RHS map subscript by reference --
i.e we can reference deallocated memory.

Not good.

Scope: A "silent" memory error that one might run into including the
reporter of the bug.

Risk: Extremely, low. The fix is spliting an assignment from a map value
to a map entry into: A value assignment of the map value to a local. And
then storing the local in the map entry forgoing the reference of
reallocated memory bug.

```
  valueMap[bfi] = valueMap[bfi->getBorrowedValue()];

=>

  auto mappedMValue = valueMap[bfi->getBorrowedValue()];
  valueMap[bfi] = mappedValue;
```

Reviewed by: Meghana G, Erik E., Joe G.

Testing: The fix was tested on the reporting project.

rdar://151031297
2025-06-05 07:09:22 -07:00

20 KiB