================ @@ -1774,6 +1784,22 @@ llvm::Constant *ConstantEmitter::emitForMemory(CodeGenModule &CGM, return Res; } + if (destType->isBitIntType()) { + if (!CGM.getTypes().LLVMTypeLayoutMatchesAST(destType, C->getType())) { + // Long _BitInt has array of bytes as in-memory type. + // So, split constant into individual bytes. + ConstantAggregateBuilder Builder(CGM); + llvm::Type *DesiredTy = CGM.getTypes().ConvertTypeForMem(destType); + // LLVM type doesn't match AST type only for big enough _BitInts, these + // types don't appear in constant expressions involving ptrtoint, so it + // is safe to expect a constant int here. + auto *CI = cast<llvm::ConstantInt>(C); + llvm::APInt Value = CI->getValue(); + Builder.addBits(Value, /*OffsetInBits=*/0, /*AllowOverwrite=*/false); + return Builder.build(DesiredTy, /*AllowOversized*/ false); ---------------- rjmccall wrote:
`C` is of the scalar type, not the load/store type, right? So tail-padding with `zeroinitializer` is still wrong: - Given a negative value, we need to fill the "padding" with 1s, not 0s. - On a big-endian target, the padding needs to come before the value, not after it. Both of these are fixed by sign/zero-extending the constant to the load/store type. https://github.com/llvm/llvm-project/pull/91364 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits