Skip to content

Commit 9bd600e

Browse files
authored
Merge pull request #25998 from gottesmm/pr-1bdafdcbc86d37c1b2001de333ad44efcdef50db
[diagnose-unreachable] Constant fold simple switch_enum_addr to elimi…
2 parents 35c0fa8 + 4cb03c2 commit 9bd600e

File tree

4 files changed

+679
-136
lines changed

4 files changed

+679
-136
lines changed

include/swift/SIL/Projection.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,15 @@ class Projection {
377377

378378
/// Returns true if this instruction projects from an address type to an
379379
/// address subtype.
380-
static SingleValueInstruction *isAddressProjection(SILValue V) {
381-
switch (V->getKind()) {
380+
static SingleValueInstruction *isAddressProjection(SILValue v) {
381+
switch (v->getKind()) {
382382
default:
383383
return nullptr;
384384
case ValueKind::IndexAddrInst: {
385-
auto I = cast<IndexAddrInst>(V);
386-
unsigned Scalar;
387-
if (getIntegerIndex(I->getIndex(), Scalar))
388-
return I;
385+
auto *i = cast<IndexAddrInst>(v);
386+
unsigned scalar;
387+
if (getIntegerIndex(i->getIndex(), scalar))
388+
return i;
389389
return nullptr;
390390
}
391391
case ValueKind::StructElementAddrInst:
@@ -394,10 +394,17 @@ class Projection {
394394
case ValueKind::ProjectBoxInst:
395395
case ValueKind::TupleElementAddrInst:
396396
case ValueKind::UncheckedTakeEnumDataAddrInst:
397-
return cast<SingleValueInstruction>(V);
397+
return cast<SingleValueInstruction>(v);
398398
}
399399
}
400400

401+
static SingleValueInstruction *isAddressProjection(SILInstruction *i) {
402+
auto *svi = dyn_cast<SingleValueInstruction>(i);
403+
if (!svi)
404+
return nullptr;
405+
return isAddressProjection(SILValue(svi));
406+
}
407+
401408
/// Returns true if this instruction projects from an object type to an object
402409
/// subtype.
403410
static SingleValueInstruction *isObjectProjection(SILValue V) {

0 commit comments

Comments
 (0)