https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/215091

Instead of marking it as valid, mark it as constexpr, which means it won't be 
valid unless it actually has valid code attached.

>From 7407eb5330f13172f3f8833b92d8cb655ce4bae9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Sun, 9 Aug 2026 14:45:04 +0200
Subject: [PATCH] [clang][bytecode] Handle invalid lambda static invokers
 better

Instead of marking it as valid, mark it as constexpr, which means it
won't be valid unless it actually has valid code attached.
---
 clang/lib/AST/ByteCode/Function.cpp | 5 +++--
 clang/lib/AST/ByteCode/Function.h   | 2 +-
 clang/lib/AST/ByteCode/Interp.cpp   | 4 ----
 clang/test/AST/ByteCode/invalid.cpp | 6 ++++++
 4 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Function.cpp 
b/clang/lib/AST/ByteCode/Function.cpp
index cd0f7eb125230..22d26e498c5b6 100644
--- a/clang/lib/AST/ByteCode/Function.cpp
+++ b/clang/lib/AST/ByteCode/Function.cpp
@@ -39,9 +39,10 @@ Function::Function(Program &P, FunctionDeclTy Source, 
unsigned ArgSize,
     } else if (const auto *MD = dyn_cast<CXXMethodDecl>(F)) {
       ExplicitThisPointer = MD->isExplicitObjectMemberFunction();
       Virtual = MD->isVirtual();
-      if (IsLambdaStaticInvoker)
+      if (IsLambdaStaticInvoker) {
         Kind = FunctionKind::LambdaStaticInvoker;
-      else if (clang::isLambdaCallOperator(F))
+        Constexpr = true;
+      } else if (clang::isLambdaCallOperator(F))
         Kind = FunctionKind::LambdaCallOperator;
       else if (MD->isCopyAssignmentOperator() || 
MD->isMoveAssignmentOperator())
         Kind = FunctionKind::CopyOrMoveOperator;
diff --git a/clang/lib/AST/ByteCode/Function.h 
b/clang/lib/AST/ByteCode/Function.h
index 27edfc6d08916..9742a16b50f2c 100644
--- a/clang/lib/AST/ByteCode/Function.h
+++ b/clang/lib/AST/ByteCode/Function.h
@@ -178,7 +178,7 @@ class Function final {
   SourceInfo getSource(CodePtr PC) const;
 
   /// Checks if the function is valid to call.
-  bool isValid() const { return IsValid || isLambdaStaticInvoker(); }
+  bool isValid() const { return IsValid; }
 
   /// Checks if the function is virtual.
   bool isVirtual() const { return Virtual; };
diff --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index f7e74811cc9f5..3c2c47fc40150 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1153,10 +1153,6 @@ static bool CheckCallable(InterpState &S, CodePtr OpPC, 
const Function *F) {
     return false;
   }
 
-  // Implicitly constexpr.
-  if (F->isLambdaStaticInvoker())
-    return true;
-
   return diagnoseCallableDecl(S, OpPC, DiagDecl);
 }
 
diff --git a/clang/test/AST/ByteCode/invalid.cpp 
b/clang/test/AST/ByteCode/invalid.cpp
index 0e6d2d4b508b8..247c8ad732708 100644
--- a/clang/test/AST/ByteCode/invalid.cpp
+++ b/clang/test/AST/ByteCode/invalid.cpp
@@ -241,3 +241,9 @@ namespace InheritedCtor {
 
   SS ss{42};
 }
+
+namespace InvalidStaticInvoker {
+  auto foo = [](bar) { int j; return j; }; // both-error {{unknown type name 
'bar'}}
+  constexpr int (*baz)(int) = foo;
+  int i = baz(42);
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to