================ @@ -1774,6 +1805,50 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr( } } } + if (ZeroInitPadding) { + uint64_t TotalSize = CGF.getContext().toBits( + Dest.getPreferredSize(CGF.getContext(), DestLV.getType())); + DoZeroInitPadding(BaseAddr, LastFieldBitOffset, TotalSize); + } +} + +void AggExprEmitter::DoZeroInitPadding(const Address BaseAddr, + uint64_t StartBitOffset, + uint64_t EndBitOffset) { + if (StartBitOffset >= EndBitOffset) + return; + + auto InitBytes = [&](uint64_t Start, uint64_t End) { + Address Addr = CGF.Builder.CreateConstGEP(BaseAddr, Start); + llvm::Constant *SizeVal = CGF.Builder.getInt64(End - Start); + CGF.Builder.CreateMemSet(Addr, CGF.Builder.getInt8(0), SizeVal, false); + }; + auto InitBits = [&](uint64_t Byte, uint64_t Start, uint64_t End) { + Address Addr = CGF.Builder.CreateConstGEP(BaseAddr, Byte); + llvm::Value *Val = Builder.CreateLoad(Addr); ---------------- yabinc wrote:
Originally it was Int8Ty. Now changed to store 0 to Info.StorageSize before initializing bitfields. I tested in -O2 that the store was always merged with initialization for bitfields. Not sure if I need to consider Info.VolatileStorageSize, but I ran check-clang and test-suite successfully. https://github.com/llvm/llvm-project/pull/110051 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits