mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SILMem2Reg: fix a problem with leaking enum values
When optimizing an enum `store` to an `alloc_stack`, require that all uses are in the same block. Otherwise it could be a `switch_enum` of an optional where the none-case does not have a destroy of the enum value. After transforming such an `alloc_stack`, the value would leak in the none-case block. It fixes the same OSSA verification error as done for TempRValueOpt in a previous commit.
This commit is contained in:
@@ -1757,6 +1757,14 @@ bool MemoryToRegisters::promoteSingleAllocation(AllocStackInst *alloc) {
|
||||
b.createDeallocStack(next->getLoc(), alloc);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// For enums we require that all uses are in the same block.
|
||||
// Otherwise there could be a switch_enum of an optional where the none-case
|
||||
// does not have a destroy of the enum value.
|
||||
// After transforming such an alloc_stack, the value would leak in the none-
|
||||
// case block.
|
||||
if (f.hasOwnership() && alloc->getType().isOrHasEnum())
|
||||
return false;
|
||||
}
|
||||
|
||||
LLVM_DEBUG(llvm::dbgs() << "*** Need to insert BB arguments for " << *alloc);
|
||||
|
||||
Reference in New Issue
Block a user