This is an archive of the discontinued LLVM Phabricator instance.

Fix size of flexible array initializers, and re-enable assertions.
ClosedPublic

Authored by efriedma on Apr 14 2022, 4:04 PM.

Details

Summary

In D123649, I got the formula for getFlexibleArrayInitChars slightly wrong: the flexible array elements can be contained in the tail padding of the struct. Fix the formula to account for that.

With the fixed formula, we run into another issue: in some cases, we were emitting extra padding for flexible arrray initializers. Fix CGExprConstant so it uses a packed struct when necessary, to avoid this extra padding.

Diff Detail

Event Timeline

efriedma created this revision.Apr 14 2022, 4:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2022, 4:04 PM
efriedma requested review of this revision.Apr 14 2022, 4:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2022, 4:04 PM
erichkeane accepted this revision.Apr 15 2022, 6:02 AM

Couple nits, otherwise LGTM.

clang/lib/AST/Decl.cpp
2731
2732
2735

Same here

This revision is now accepted and ready to land.Apr 15 2022, 6:02 AM
efriedma added inline comments.Apr 15 2022, 8:54 AM
clang/lib/AST/Decl.cpp
2735

You want something like this?

if (auto *List = dyn_cast<InitListExpr>(getInit()->IgnoreParens())) {
  const Expr *FlexibleInit = List->getInit(List->getNumInits() - 1);
  if (auto InitTy = Ctx.getAsConstantArrayType(FlexibleInit->getType())) {
    return InitTy->getSize() != 0;
  }
}
return false;
erichkeane added inline comments.Apr 15 2022, 8:55 AM
clang/lib/AST/Decl.cpp
2735

ah, shucks, i missed that this was an early exit (that is, I missed the '!'). Disregard. LGTM.

This revision was landed with ongoing or failed builds.Apr 15 2022, 12:10 PM
This revision was automatically updated to reflect the committed changes.