aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorFlorian Mayer <fmayer@google.com>2025-02-11 09:05:35 -0800
committerGitHub <noreply@github.com>2025-02-11 09:05:35 -0800
commitb3510a88b3c19645fbde09cb58af6dead68ebd36 (patch)
tree3293ea138cb47dbf635eea57d369569febe5b44a /clang/lib/AST/ExprConstant.cpp
parent2f54223247e8f9f0fc006b944de8351f376814af (diff)
downloadllvm-b3510a88b3c19645fbde09cb58af6dead68ebd36.zip
llvm-b3510a88b3c19645fbde09cb58af6dead68ebd36.tar.gz
llvm-b3510a88b3c19645fbde09cb58af6dead68ebd36.tar.bz2
[NFC] [clang] simplify isDesignatorAtObjectEnd (#126658)
IsLastOrInvalidFieldDecl would always return true if `Invalid=true`, so we know that !IsLastOrInvalidFieldDecl(...) means !Invalid.
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r--clang/lib/AST/ExprConstant.cpp20
1 files changed, 8 insertions, 12 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 192b679..5c6ca4c 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");