Skip to content

Commit b3510a8

Browse files
authored
[NFC] [clang] simplify isDesignatorAtObjectEnd (#126658)
IsLastOrInvalidFieldDecl would always return true if `Invalid=true`, so we know that !IsLastOrInvalidFieldDecl(...) means !Invalid.
1 parent 2f54223 commit b3510a8

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

Diff for: clang/lib/AST/ExprConstant.cpp

+8-12
Original file line numberDiff line numberDiff line change
@@ -12536,10 +12536,9 @@ static const Expr *ignorePointerCastsAndParens(const Expr *E) {
1253612536
static bool isDesignatorAtObjectEnd(const ASTContext &Ctx, const LValue &LVal) {
1253712537
assert(!LVal.Designator.Invalid);
1253812538

12539-
auto IsLastOrInvalidFieldDecl = [&Ctx](const FieldDecl *FD, bool &Invalid) {
12539+
auto IsLastOrInvalidFieldDecl = [&Ctx](const FieldDecl *FD) {
1254012540
const RecordDecl *Parent = FD->getParent();
12541-
Invalid = Parent->isInvalidDecl();
12542-
if (Invalid || Parent->isUnion())
12541+
if (Parent->isInvalidDecl() || Parent->isUnion())
1254312542
return true;
1254412543
const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(Parent);
1254512544
return FD->getFieldIndex() + 1 == Layout.getFieldCount();
@@ -12548,14 +12547,12 @@ static bool isDesignatorAtObjectEnd(const ASTContext &Ctx, const LValue &LVal) {
1254812547
auto &Base = LVal.getLValueBase();
1254912548
if (auto *ME = dyn_cast_or_null<MemberExpr>(Base.dyn_cast<const Expr *>())) {
1255012549
if (auto *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
12551-
bool Invalid;
12552-
if (!IsLastOrInvalidFieldDecl(FD, Invalid))
12553-
return Invalid;
12550+
if (!IsLastOrInvalidFieldDecl(FD))
12551+
return false;
1255412552
} else if (auto *IFD = dyn_cast<IndirectFieldDecl>(ME->getMemberDecl())) {
1255512553
for (auto *FD : IFD->chain()) {
12556-
bool Invalid;
12557-
if (!IsLastOrInvalidFieldDecl(cast<FieldDecl>(FD), Invalid))
12558-
return Invalid;
12554+
if (!IsLastOrInvalidFieldDecl(cast<FieldDecl>(FD)))
12555+
return false;
1255912556
}
1256012557
}
1256112558
}
@@ -12591,9 +12588,8 @@ static bool isDesignatorAtObjectEnd(const ASTContext &Ctx, const LValue &LVal) {
1259112588
return false;
1259212589
BaseType = CT->getElementType();
1259312590
} else if (auto *FD = getAsField(Entry)) {
12594-
bool Invalid;
12595-
if (!IsLastOrInvalidFieldDecl(FD, Invalid))
12596-
return Invalid;
12591+
if (!IsLastOrInvalidFieldDecl(FD))
12592+
return false;
1259712593
BaseType = FD->getType();
1259812594
} else {
1259912595
assert(getAsBaseClass(Entry) && "Expecting cast to a base class");

0 commit comments

Comments
 (0)