Skip to content
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

Merged

Conversation

fmayer
Copy link
Contributor

@fmayer fmayer commented Feb 11, 2025

IsLastOrInvalidFieldDecl would always return true if Invalid=true, so
we know that !IsLastOrInvalidFieldDecl(...) means !Invalid.

Created using spr 1.3.4
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Feb 11, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 11, 2025

@llvm/pr-subscribers-clang

Author: Florian Mayer (fmayer)

Changes

IsLastOrInvalidFieldDecl would always return true if Invalid=true, so
we know that !IsLastOrInvalidFieldDecl(...) means !Invalid.


Full diff: https://github.com/llvm/llvm-project/pull/126658.diff

1 Files Affected:

  • (modified) clang/lib/AST/ExprConstant.cpp (+11-12)
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");

Created using spr 1.3.4
@fmayer fmayer requested a review from cor3ntin February 11, 2025 03:13
Copy link
Contributor

@Fznamznon Fznamznon left a 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!

@fmayer fmayer merged commit b3510a8 into main Feb 11, 2025
8 checks passed
@fmayer fmayer deleted the users/fmayer/spr/nfc-clang-simplify-isdesignatoratobjectend branch February 11, 2025 17:05
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
IsLastOrInvalidFieldDecl would always return true if `Invalid=true`, so
we know that !IsLastOrInvalidFieldDecl(...) means !Invalid.
flovent pushed a commit to flovent/llvm-project that referenced this pull request Feb 13, 2025
IsLastOrInvalidFieldDecl would always return true if `Invalid=true`, so
we know that !IsLastOrInvalidFieldDecl(...) means !Invalid.
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
IsLastOrInvalidFieldDecl would always return true if `Invalid=true`, so
we know that !IsLastOrInvalidFieldDecl(...) means !Invalid.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
IsLastOrInvalidFieldDecl would always return true if `Invalid=true`, so
we know that !IsLastOrInvalidFieldDecl(...) means !Invalid.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants