[clang] Reapply "[clang][CodeGen] Zero init unspecified fields in initializers in C" (#109898) (PR #110051)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 2 13:34:03 PDT 2024
================
@@ -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);
----------------
efriedma-quic wrote:
(Ideally, we'd use load/store operations with the same width as the bitfield, as computed by CGBitFieldInfo, to make the result easier for LLVM to optimize.)
https://github.com/llvm/llvm-project/pull/110051
More information about the cfe-commits
mailing list