Skip to content

Commit 8ba21d8

Browse files
committed
SILGen: Fix some accesses of values after they've been consumed
We should not touch 'this' after a 'std::move(this)'.
1 parent 4b25945 commit 8ba21d8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,6 +2727,7 @@ static ManagedValue drillIntoComponent(SILGenFunction &SGF,
27272727
ManagedValue base,
27282728
AccessKind accessKind,
27292729
TSanKind tsanKind) {
2730+
bool isRValue = component.isRValue();
27302731
ManagedValue addr;
27312732
if (component.isPhysical()) {
27322733
addr = std::move(component.asPhysical()).offset(SGF, loc, base, accessKind);
@@ -2737,7 +2738,7 @@ static ManagedValue drillIntoComponent(SILGenFunction &SGF,
27372738

27382739
if (!SGF.getASTContext().LangOpts.DisableTsanInoutInstrumentation &&
27392740
SGF.getModule().getOptions().Sanitize == SanitizerKind::Thread &&
2740-
tsanKind == TSanKind::InoutAccess && !component.isRValue()) {
2741+
tsanKind == TSanKind::InoutAccess && !isRValue) {
27412742
emitTsanInoutAccess(SGF, loc, addr);
27422743
}
27432744

@@ -2777,6 +2778,9 @@ RValue SILGenFunction::emitLoadOfLValue(SILLocation loc, LValue &&src,
27772778
// Any writebacks should be scoped to after the load.
27782779
FormalEvaluationScope scope(*this);
27792780

2781+
auto substFormalType = src.getSubstFormalType();
2782+
auto &rvalueTL = getTypeLowering(src.getTypeOfRValue());
2783+
27802784
ManagedValue addr;
27812785
PathComponent &&component =
27822786
drillToLastComponent(*this, loc, std::move(src), addr, AccessKind::Read);
@@ -2785,9 +2789,9 @@ RValue SILGenFunction::emitLoadOfLValue(SILLocation loc, LValue &&src,
27852789
if (component.isPhysical()) {
27862790
addr = std::move(component.asPhysical())
27872791
.offset(*this, loc, addr, AccessKind::Read);
2788-
return RValue(*this, loc, src.getSubstFormalType(),
2792+
return RValue(*this, loc, substFormalType,
27892793
emitLoad(loc, addr.getValue(),
2790-
getTypeLowering(src.getTypeOfRValue()), C, IsNotTake,
2794+
rvalueTL, C, IsNotTake,
27912795
isGuaranteedValid));
27922796
}
27932797

@@ -2886,6 +2890,8 @@ void SILGenFunction::emitAssignLValueToLValue(SILLocation loc, LValue &&src,
28862890
return;
28872891
}
28882892

2893+
auto &rvalueTL = getTypeLowering(src.getTypeOfRValue());
2894+
28892895
auto srcAddr = emitAddressOfLValue(loc, std::move(src), AccessKind::Read)
28902896
.getUnmanagedValue();
28912897
auto destAddr = emitAddressOfLValue(loc, std::move(dest), AccessKind::Write)
@@ -2895,9 +2901,7 @@ void SILGenFunction::emitAssignLValueToLValue(SILLocation loc, LValue &&src,
28952901
B.createCopyAddr(loc, srcAddr, destAddr, IsNotTake, IsNotInitialization);
28962902
} else {
28972903
// If there's a semantic conversion necessary, do a load then assign.
2898-
auto loaded = emitLoad(loc, srcAddr, getTypeLowering(src.getTypeOfRValue()),
2899-
SGFContext(),
2900-
IsNotTake);
2904+
auto loaded = emitLoad(loc, srcAddr, rvalueTL, SGFContext(), IsNotTake);
29012905
loaded.assignInto(*this, loc, destAddr);
29022906
}
29032907
}

0 commit comments

Comments
 (0)