Skip to content

[NFC] [clang] simplify isDesignatorAtObjectEnd #126658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12536,10 +12536,9 @@ static const Expr *ignorePointerCastsAndParens(const Expr *E) {
static bool isDesignatorAtObjectEnd(const ASTContext &Ctx, const LValue &LVal) {
assert(!LVal.Designator.Invalid);

auto IsLastOrInvalidFieldDecl = [&Ctx](const FieldDecl *FD, bool &Invalid) {
auto IsLastOrInvalidFieldDecl = [&Ctx](const FieldDecl *FD) {
const RecordDecl *Parent = FD->getParent();
Invalid = Parent->isInvalidDecl();
if (Invalid || Parent->isUnion())
if (Parent->isInvalidDecl() || Parent->isUnion())
return true;
const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(Parent);
return FD->getFieldIndex() + 1 == Layout.getFieldCount();
Expand All @@ -12548,14 +12547,12 @@ static bool isDesignatorAtObjectEnd(const ASTContext &Ctx, const LValue &LVal) {
auto &Base = LVal.getLValueBase();
if (auto *ME = dyn_cast_or_null<MemberExpr>(Base.dyn_cast<const Expr *>())) {
if (auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
bool Invalid;
if (!IsLastOrInvalidFieldDecl(FD, Invalid))
return Invalid;
if (!IsLastOrInvalidFieldDecl(FD))
return false;
} else if (auto *IFD = dyn_cast<IndirectFieldDecl>(ME->getMemberDecl())) {
for (auto *FD : IFD->chain()) {
bool Invalid;
if (!IsLastOrInvalidFieldDecl(cast<FieldDecl>(FD), Invalid))
return Invalid;
if (!IsLastOrInvalidFieldDecl(cast<FieldDecl>(FD)))
return false;
}
}
}
Expand Down Expand Up @@ -12591,9 +12588,8 @@ static bool isDesignatorAtObjectEnd(const ASTContext &Ctx, const LValue &LVal) {
return false;
BaseType = CT->getElementType();
} else if (auto *FD = getAsField(Entry)) {
bool Invalid;
if (!IsLastOrInvalidFieldDecl(FD, Invalid))
return Invalid;
if (!IsLastOrInvalidFieldDecl(FD))
return false;
BaseType = FD->getType();
} else {
assert(getAsBaseClass(Entry) && "Expecting cast to a base class");
Expand Down