-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
[NFC] [clang] simplify isDesignatorAtObjectEnd #126658
[NFC] [clang] simplify isDesignatorAtObjectEnd #126658
Conversation
Created using spr 1.3.4
@llvm/pr-subscribers-clang Author: Florian Mayer (fmayer) ChangesIsLastOrInvalidFieldDecl would always return true if Full diff: https://github.com/llvm/llvm-project/pull/126658.diff 1 Files Affected:
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 192b679b4c9959..69179a0b88519a 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,14 @@ 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 +12590,9 @@ 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");
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thank you!
IsLastOrInvalidFieldDecl would always return true if `Invalid=true`, so we know that !IsLastOrInvalidFieldDecl(...) means !Invalid.
IsLastOrInvalidFieldDecl would always return true if `Invalid=true`, so we know that !IsLastOrInvalidFieldDecl(...) means !Invalid.
IsLastOrInvalidFieldDecl would always return true if `Invalid=true`, so we know that !IsLastOrInvalidFieldDecl(...) means !Invalid.
IsLastOrInvalidFieldDecl would always return true if `Invalid=true`, so we know that !IsLastOrInvalidFieldDecl(...) means !Invalid.
IsLastOrInvalidFieldDecl would always return true if
Invalid=true
, sowe know that !IsLastOrInvalidFieldDecl(...) means !Invalid.