manmanren added a comment. Hi Akira,
How about the following? else if (LocalAlignment == 8) { if (NumBytesAtAlign8 == 0) { // We have not seen any 8-byte aligned element yet. There is no padding and we are either 4-byte // aligned or 8-byte aligned depending on NumBytesAtAlign4. // Add in 4 bytes padding if we are not 8-byte aligned including this element. if ((LocalSize + NumBytesAtAlign4) % 8 != 0) { memmove(&Buffer[Index - 4], &Buffer[Index], NumBytesAtAlign4); Index -= 4; } } else { unsigned Padding = NumBytesAtAlign4 % 8; if (Padding == 0) { if (LocalSize % 8 == 0) { // Everything is set: there's no padding and we don't need to add // any. } else { assert(LocalSize % 8 == 4); // No existing padding; add in 4 bytes padding memmove(&Buffer[Index - 4], &Buffer[Index], NumBytesAtAlign4); Index -= 4; } } else { assert(Padding == 4); if (LocalSize % 8 == 0) { // Everything is set: there's 4 bytes padding and we don't need // to add any. } else { assert(LocalSize % 8 == 4); // There are 4 bytes padding, but we don't need any; remove it. memmove(&Buffer[Index + 4], &Buffer[Index], NumBytesAtAlign4); Index += 4; } } } // Forget about any padding. NumBytesAtAlign4 = 0; NumBytesAtAlign8 += LocalSize; } Note that the handling of NumBytesAtAlign8 != 0 is the same for LocalAlignment == 4 vs. LocalAlignment == 8. Also mention in the commit message that the original code seems to assume LocalSize is a multiple of 8 when LocalAlignment is 8. Cheers, Manman http://reviews.llvm.org/D16843 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits