[clang] Reapply "[clang][CodeGen] Zero init unspecified fields in initializers in C" (#109898) (PR #110051)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 27 15:26:12 PDT 2024
================
@@ -1748,6 +1771,26 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr(
CGF.getTypes().isZeroInitializable(ExprToVisit->getType()))
break;
+ if (ZeroInitPadding) {
+ uint64_t StartBitOffset = Layout.getFieldOffset(field->getFieldIndex());
+ CharUnits StartOffset =
+ CGF.getContext().toCharUnitsFromBits(StartBitOffset);
+ DoZeroInitPadding(SizeSoFar, StartOffset - SizeSoFar);
+ if (!field->isBitField()) {
+ CharUnits FieldSize =
+ CGF.getContext().getTypeSizeInChars(field->getType());
+ SizeSoFar = StartOffset + FieldSize;
+ } else {
+ const CGRecordLayout &RL =
+ CGF.getTypes().getCGRecordLayout(field->getParent());
+ const CGBitFieldInfo &Info = RL.getBitFieldInfo(field);
+ uint64_t EndBitOffset = StartBitOffset + Info.Size;
+ SizeSoFar = CGF.getContext().toCharUnitsFromBits(EndBitOffset);
+ if (EndBitOffset % CGF.getContext().getCharWidth() != 0) {
+ SizeSoFar++;
----------------
yabinc wrote:
I agree. I ignored padding less than 1 byte. It should be fixed in the new commit.
I think this problem doesn't exist for CGExprConstant.cpp. Because in const values, having a value for any bit of a byte can prevent this byte becoming undef value.
https://github.com/llvm/llvm-project/pull/110051
More information about the cfe-commits
mailing list