Skip to content

Commit b9917c3

Browse files
authored
Merge pull request #25298 from dcci/rdar51211938
[GenEnum] Fix getBitMaskForNoPayloadElements.
2 parents 15ecf92 + aef830d commit b9917c3

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

lib/IRGen/GenEnum.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3224,11 +3224,31 @@ namespace {
32243224
getBitMaskForNoPayloadElements() const override {
32253225
// Use the extra inhabitants mask from the payload.
32263226
auto &payloadTI = getFixedPayloadTypeInfo();
3227-
ClusteredBitVector extraInhabitantsMask;
3227+
APInt extraInhabitantsMaskInt;
3228+
3229+
// If we used extra inhabitants from the payload, then we can use the
3230+
// payload's mask to find the bits we need to test.
3231+
auto extraDiscriminatorBits = (~APInt(8, 0));
3232+
if (payloadTI.getFixedSize().getValueInBits() != 0)
3233+
extraDiscriminatorBits =
3234+
extraDiscriminatorBits.zextOrTrunc(
3235+
payloadTI.getFixedSize().getValueInBits());
3236+
if (getNumExtraInhabitantTagValues() > 0) {
3237+
extraInhabitantsMaskInt = payloadTI.getFixedExtraInhabitantMask(IGM);
3238+
// If we have more no-payload cases than extra inhabitants, also
3239+
// mask in up to four bytes for discriminators we generate using
3240+
// extra tag bits.
3241+
if (ExtraTagBitCount > 0) {
3242+
extraInhabitantsMaskInt |= extraDiscriminatorBits;
3243+
}
3244+
} else {
3245+
// If we only use extra tag bits, then we need that extra tag plus
3246+
// up to four bytes of discriminator.
3247+
extraInhabitantsMaskInt = extraDiscriminatorBits;
3248+
}
3249+
auto extraInhabitantsMask
3250+
= getBitVectorFromAPInt(extraInhabitantsMaskInt);
32283251

3229-
if (!payloadTI.isKnownEmpty(ResilienceExpansion::Maximal))
3230-
extraInhabitantsMask =
3231-
getBitVectorFromAPInt(payloadTI.getFixedExtraInhabitantMask(IGM));
32323252
// Extend to include the extra tag bits, which are always significant.
32333253
unsigned totalSize
32343254
= cast<FixedTypeInfo>(TI)->getFixedSize().getValueInBits();

0 commit comments

Comments
 (0)