@@ -4785,7 +4785,11 @@ namespace {
4785
4785
Address payloadAddr = projectPayload (IGF, enumAddr);
4786
4786
auto payload = EnumPayload::load (IGF, payloadAddr, PayloadSchema);
4787
4787
4788
- auto spareBitMask = ~PayloadTagBits.asAPInt ();
4788
+ // We need to mask not only the payload tag bits, but all spare bits,
4789
+ // because the other spare bits may be used to tag a single-payload
4790
+ // enum containing this enum as a payload. Single payload layout
4791
+ // unfortunately assumes that tagging the payload case is a no-op.
4792
+ auto spareBitMask = ~CommonSpareBits.asAPInt ();
4789
4793
APInt tagBitMask
4790
4794
= interleaveSpareBits (IGF.IGM , PayloadTagBits, PayloadTagBits.size (),
4791
4795
spareTagBits, 0 );
@@ -4823,7 +4827,11 @@ namespace {
4823
4827
auto payload = EnumPayload::load (IGF, payloadAddr, PayloadSchema);
4824
4828
4825
4829
// Mask off the spare bits.
4826
- auto spareBitMask = ~PayloadTagBits.asAPInt ();
4830
+ // We need to mask not only the payload tag bits, but all spare bits,
4831
+ // because the other spare bits may be used to tag a single-payload
4832
+ // enum containing this enum as a payload. Single payload layout
4833
+ // unfortunately assumes that tagging the payload case is a no-op.
4834
+ auto spareBitMask = ~CommonSpareBits.asAPInt ();
4827
4835
payload.emitApplyAndMask (IGF, spareBitMask);
4828
4836
4829
4837
// Store the tag into the spare bits.
0 commit comments