Skip to content

IRGen: Fix a map entry use-after-free issue in LargeLoadableHeuristic #77455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/IRGen/LoadableByAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3519,7 +3519,7 @@ class LargeLoadableHeuristic {
"Expected only two categories: address and object");
assert(!canType->hasTypeParameter());

auto &entry = largeTypeProperties[ty];
auto entry = largeTypeProperties[ty];
auto cached = entry.getNumRegisters();
if (cached)
return cached;
Expand All @@ -3532,6 +3532,7 @@ class LargeLoadableHeuristic {
auto explosionSchema = TI.getSchema();
auto res = std::max(nativeSchemaOrigParam.size(), explosionSchema.size());
entry.setNumRegisters(res);
largeTypeProperties[ty] = entry;
return entry.getNumRegisters();
}

Expand All @@ -3545,15 +3546,18 @@ void LargeLoadableHeuristic::visit(SILArgument *arg) {
if (numRegisters(objType) < NumRegistersLargeType)
return;

auto &entry = largeTypeProperties[objType];
auto entry = largeTypeProperties[objType];
for (auto *use : arg->getUses()) {
auto *usr = use->getUser();
switch (usr->getKind()) {
case SILInstructionKind::TupleExtractInst:
case SILInstructionKind::StructExtractInst: {
auto projectionTy = cast<SingleValueInstruction>(usr)->getType();
if (numRegisters(projectionTy) >= NumRegistersLargeType)
if (numRegisters(projectionTy) >= NumRegistersLargeType) {
entry.addProjection();

largeTypeProperties[objType] = entry;
}
break;
}
default:
Expand All @@ -3575,8 +3579,9 @@ void LargeLoadableHeuristic::visit(SILInstruction *i) {
auto resTy = bitcast->getType();
if (numRegisters(resTy) > NumRegistersLargeType) {
// Force the source type to be indirect.
auto &entry = largeTypeProperties[opdTy];
auto entry = largeTypeProperties[opdTy];
entry.setNumRegisters(65535);
largeTypeProperties[opdTy] = entry;
return;
}
}
Expand All @@ -3589,7 +3594,7 @@ void LargeLoadableHeuristic::visit(SILInstruction *i) {
if (registerCount < NumRegistersLargeType)
continue;

auto &entry = largeTypeProperties[objType];
auto entry = largeTypeProperties[objType];

switch (i->getKind()) {
case SILInstructionKind::TupleExtractInst:
Expand Down Expand Up @@ -3639,6 +3644,8 @@ void LargeLoadableHeuristic::visit(SILInstruction *i) {
entry.addUse();
break;
}

largeTypeProperties[objType] = entry;
}
}

Expand Down