[clang] f62bfc1 - [clang][bytecode] Reject methods with invalid parent decls (#236338)

via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 28 06:27:07 PDT 2026


Author: Timm Baeder
Date: 2026-10-28T14:27:00+01:00
New Revision: f62bfc1a0d8ba8bee0be193fbc1dec0544b371f7

URL: https://github.com/llvm/llvm-project/commit/f62bfc1a0d8ba8bee0be193fbc1dec0544b371f7
DIFF: https://github.com/llvm/llvm-project/commit/f62bfc1a0d8ba8bee0be193fbc1dec0544b371f7.diff

LOG: [clang][bytecode] Reject methods with invalid parent decls (#236338)

E.g. the later call to `isEmpty()` via
`isReadByLValueToRValueConversion()` causes infinite recursion.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Compiler.cpp
    clang/test/AST/ByteCode/cxx23.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 8f42e0943458de..164dd155debd42 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6400,6 +6400,7 @@ static bool isTrivialMemoryOperation(const CXXMethodDecl *MD) {
     return false;
   if (!MD->isCopyAssignmentOperator() && !MD->isMoveAssignmentOperator())
     return false;
+  assert(!MD->getParent()->isInvalidDecl());
   return MD->getParent()->isUnion() ||
          (MD->isTrivial() && isReadByLvalueToRvalueConversion(MD->getParent()));
 }
@@ -6435,6 +6436,11 @@ bool Compiler<Emitter>::VisitCallExpr(const CallExpr *E) {
     }
   }
 
+  // Don't generate code for method with invalid parent decls.
+  if (const auto *MD = dyn_cast_if_present<CXXMethodDecl>(FuncDecl);
+      MD && MD->getParent()->isInvalidDecl())
+    return false;
+
   LocalScope<Emitter> CallScope(this, ScopeKind::Call);
   ArrayRef<const Expr *> Args(E->getArgs(), E->getNumArgs());
   bool ActivateLHS = false;

diff  --git a/clang/test/AST/ByteCode/cxx23.cpp b/clang/test/AST/ByteCode/cxx23.cpp
index ec6f7fe57cd55d..fbff5cb9f448bb 100644
--- a/clang/test/AST/ByteCode/cxx23.cpp
+++ b/clang/test/AST/ByteCode/cxx23.cpp
@@ -714,4 +714,18 @@ namespace WithinLifetime {
   static_assert(f(42), ""); // all-error {{not an integral constant expression}} \
                             // all-note {{in call to}}
 }
+
+namespace InvalidDeclInIsTrivialMemoryOperation {
+  struct A { // all-note {{definition}}
+    A((B)); // all-error {{field has incomplete type}}
+    struct B {
+    } b;
+  };
+  constexpr int foo() {
+    A a, b;
+    b = a;
+  }
+  static_assert(foo(), ""); // all-error {{not an integral constant expression}}
+}
+
 #endif


        


More information about the cfe-commits mailing list