[clang] [clang] Lower _BitInt(129+) to a different type in LLVM IR (PR #91364)
Mariya Podchishchaeva via cfe-commits
cfe-commits at lists.llvm.org
Fri May 31 05:09:50 PDT 2024
================
@@ -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);
----------------
Fznamznon wrote:
I'm not seeing `undef`s in resulting constants. `zeroinitializer` for all unused bytes is emitted instead. The test CodeGen/ext-int.c illustrates this behavior.
https://github.com/llvm/llvm-project/pull/91364
More information about the cfe-commits
mailing list