diff options
| author | Eli Friedman <efriedma@quicinc.com> | 2022-04-14 15:20:37 -0700 |
|---|---|---|
| committer | Eli Friedman <efriedma@quicinc.com> | 2022-04-15 12:09:57 -0700 |
| commit | 4802edd1ac7a5aea8c8488b5baec221d722cbdde (patch) | |
| tree | af966eaf276039183d3c78957587a1b02f491c7c /clang/lib/CodeGen/CodeGenModule.cpp | |
| parent | dc100ebfdabf9db484bf8069870299a593522aaf (diff) | |
Fix size of flexible array initializers, and re-enable assertions.
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.
Differential Revision: https://reviews.llvm.org/D123826
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 7 |
1 files changed, 1 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 5184a363f18f..bf5f2d1b4271 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -4615,7 +4615,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D, T = D->getType(); if (getLangOpts().CPlusPlus) { - if (!InitDecl->getFlexibleArrayInitChars(getContext()).isZero()) + if (InitDecl->hasFlexibleArrayInit(getContext())) ErrorUnsupported(D, "flexible array initializer"); Init = EmitNullConstant(T); NeedsGlobalCtor = true; @@ -4631,10 +4631,6 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D, if (getLangOpts().CPlusPlus && !NeedsGlobalDtor) DelayedCXXInitPosition.erase(D); -#if 0 - // FIXME: The following check doesn't handle flexible array members - // inside tail padding (which don't actually increase the size of - // the struct). #ifndef NDEBUG CharUnits VarSize = getContext().getTypeSizeInChars(ASTTy) + InitDecl->getFlexibleArrayInitChars(getContext()); @@ -4642,7 +4638,6 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D, getDataLayout().getTypeAllocSize(Init->getType())); assert(VarSize == CstSize && "Emitted constant has unexpected size"); #endif -#endif } } |
