Skip to content

Commit 15be357

Browse files
committed
when DI is reporting an error about a multi-element access,
indicate the first element that is undefined, not the first element being accessed. In the example, passing the tuple inout uses both elements, but the first element is initialized, so we should complain about t2.1 being uninitialized, not t2.0 Swift SVN r10822
1 parent e24a5ea commit 15be357

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

lib/SILPasses/DefiniteInitialization.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,26 @@ void LifetimeChecker::diagnoseInitError(const DIMemoryUse &Use,
452452
else
453453
Name = "<unknown>";
454454

455-
// If the overall memory allocation is a tuple with multiple elements,
456-
// then dive in to explain *which* element is being used uninitialized.
457-
//
455+
// If the overall memory allocation has multiple elements, then dive in to
456+
// explain *which* element is being used uninitialized. Start by rerunning
457+
// the query, to get a bitmask of exactly which elements are uninitialized.
458+
// In a multi-element query, the first element may already be defined and
459+
// we want to point to the second one.
460+
AvailabilitySet Liveness =
461+
getLivenessAtInst(Use.Inst, Use.FirstElement, Use.NumElements);
462+
463+
unsigned FirstUndefElement = Use.FirstElement;
464+
while (Liveness.get(FirstUndefElement) == DIKind::Yes) {
465+
++FirstUndefElement;
466+
assert(FirstUndefElement != Use.FirstElement+Use.NumElements &&
467+
"No undef elements found?");
468+
}
469+
458470
// TODO: Given that we know the range of elements being accessed, we don't
459471
// need to go all the way deep into a recursive tuple here. We could print
460472
// an error about "v" instead of "v.0" when "v" has tuple type and the whole
461473
// thing is accessed inappropriately.
462-
TheMemory.getPathStringToElement(Use.FirstElement, Name);
474+
TheMemory.getPathStringToElement(FirstUndefElement, Name);
463475

464476
diagnose(Module, Inst->getLoc(), DiagMessage, Name);
465477

0 commit comments

Comments
 (0)