[clang] [clang][bytecode] Handle invalid lambda static invokers better (PR #215091)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 9 05:46:48 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
Instead of marking it as valid, mark it as constexpr, which means it won't be valid unless it actually has valid code attached.
---
Full diff: https://github.com/llvm/llvm-project/pull/215091.diff
4 Files Affected:
- (modified) clang/lib/AST/ByteCode/Function.cpp (+3-2)
- (modified) clang/lib/AST/ByteCode/Function.h (+1-1)
- (modified) clang/lib/AST/ByteCode/Interp.cpp (-4)
- (modified) clang/test/AST/ByteCode/invalid.cpp (+6)
``````````diff
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);
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/215091
More information about the cfe-commits
mailing list