[clang] c4a3c97 - [clang][bytecode] Handle invalid lambda static invokers better (#215091)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 9 08:54:56 PDT 2026
Author: Timm Baeder
Date: 2026-08-09T17:54:52+02:00
New Revision: c4a3c977f1f9138fb69bf936e532c94f0bb8a3cd
URL: https://github.com/llvm/llvm-project/commit/c4a3c977f1f9138fb69bf936e532c94f0bb8a3cd
DIFF: https://github.com/llvm/llvm-project/commit/c4a3c977f1f9138fb69bf936e532c94f0bb8a3cd.diff
LOG: [clang][bytecode] Handle invalid lambda static invokers better (#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.
Added:
Modified:
clang/lib/AST/ByteCode/Function.cpp
clang/lib/AST/ByteCode/Function.h
clang/lib/AST/ByteCode/Interp.cpp
clang/test/AST/ByteCode/invalid.cpp
Removed:
################################################################################
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 4bc02967939e3..ece2e71408731 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);
+}
More information about the cfe-commits
mailing list