[clang] fix: compatible C++ empty record with align UB with gcc (PR #72197)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 15 11:28:40 PST 2023
================
@@ -296,10 +296,16 @@ bool CodeGen::isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays,
return false;
// If this is a C++ record, check the bases first.
- if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
+ if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
for (const auto &I : CXXRD->bases())
if (!isEmptyRecord(Context, I.getType(), true, AsIfNoUniqueAddr))
return false;
+ // C++ object size >= 1 byte, empty struct is 1 byte.
----------------
erichkeane wrote:
This addition makes this not match the comment above, and makes me think that we're doing this wrong. This ends up applying to only C++ and not C, which seems wrong. Additionally, I don't think that the assumption of 'greater than 1 byte' is the right way to determine this empty. Perhaps one of the codegen folks would have a better idea.
https://github.com/llvm/llvm-project/pull/72197
More information about the cfe-commits
mailing list