[clang] [clang][bytecode] Only check static lambda captures if we have to (PR #178452)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 28 07:50:41 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
Call `getCaptureFields()` only if the function is static, because we only care about the captures in that case.
---
Full diff: https://github.com/llvm/llvm-project/pull/178452.diff
1 Files Affected:
- (modified) clang/lib/AST/ByteCode/Context.cpp (+6-6)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Context.cpp b/clang/lib/AST/ByteCode/Context.cpp
index 208fcb2a2732e..5d5816eb02cd2 100644
--- a/clang/lib/AST/ByteCode/Context.cpp
+++ b/clang/lib/AST/ByteCode/Context.cpp
@@ -555,15 +555,15 @@ const Function *Context::getOrCreateFunction(const FunctionDecl *FuncDecl) {
// the lambda captures.
if (!MD->getParent()->isCompleteDefinition())
return nullptr;
- llvm::DenseMap<const ValueDecl *, FieldDecl *> LC;
- FieldDecl *LTC;
+ if (MD->isStatic()) {
+ llvm::DenseMap<const ValueDecl *, FieldDecl *> LC;
+ FieldDecl *LTC;
- MD->getParent()->getCaptureFields(LC, LTC);
-
- if (MD->isStatic() && !LC.empty()) {
+ MD->getParent()->getCaptureFields(LC, LTC);
// Static lambdas cannot have any captures. If this one does,
// it has already been diagnosed and we can only ignore it.
- return nullptr;
+ if (!LC.empty())
+ return nullptr;
}
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/178452
More information about the cfe-commits
mailing list