As noticed in https://reviews.llvm.org/D122925, the routine DenseIntOrFPElementsAttr::convertEndianOfArrayRefForBEmachine does not handle sub-byte types correctly.
convertEndianOfArrayRefForBEmachine may call convertEndianOfCharForBEmachine with an elementBitWidth of 1, which falls into this default case:
default: { size_t nBytes = elementBitWidth / CHAR_BIT; for (size_t i = 0; i < nBytes; i++) std::copy_n(inRawData + (nBytes - 1 - i), 1, outRawData + i); break; }
If elementBitWidth is smaller than CHAR_BIT, that simply does nothing and leaves outRawData unmodified.
However, for sub-byte types no endian conversion is actually necessary, so this patch simply copies the input to the output.
Note that this touches only one caller of DenseIntOrFPElementsAttr::convertEndianOfArrayRefForBEmachine, but all other callers always pass a multiple of CHAR_BITS as elementBitWidth.