[clang] b3510a8 - [NFC] [clang] simplify isDesignatorAtObjectEnd (#126658)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 11 09:05:41 PST 2025
Author: Florian Mayer
Date: 2025-02-11T09:05:35-08:00
New Revision: b3510a88b3c19645fbde09cb58af6dead68ebd36
URL: https://github.com/llvm/llvm-project/commit/b3510a88b3c19645fbde09cb58af6dead68ebd36
DIFF: https://github.com/llvm/llvm-project/commit/b3510a88b3c19645fbde09cb58af6dead68ebd36.diff
LOG: [NFC] [clang] simplify isDesignatorAtObjectEnd (#126658)
IsLastOrInvalidFieldDecl would always return true if `Invalid=true`, so
we know that !IsLastOrInvalidFieldDecl(...) means !Invalid.
Added:
Modified:
clang/lib/AST/ExprConstant.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 192b679b4c9959..5c6ca4c9ee4dea 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -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();
@@ -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;
}
}
}
@@ -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");
More information about the cfe-commits
mailing list