[clang] 85cedd8 - [clang][Interp] Ignore incomplete records when visiting lambdas
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 16 06:04:48 PDT 2024
Author: Timm Bäder
Date: 2024-07-16T15:04:32+02:00
New Revision: 85cedd8e59be5eebad6292aee3b053f31afc8977
URL: https://github.com/llvm/llvm-project/commit/85cedd8e59be5eebad6292aee3b053f31afc8977
DIFF: https://github.com/llvm/llvm-project/commit/85cedd8e59be5eebad6292aee3b053f31afc8977.diff
LOG: [clang][Interp] Ignore incomplete records when visiting lambdas
We need them to be complete so we have knowledge about all the
lambda captures.
Added:
Modified:
clang/lib/AST/Interp/ByteCodeEmitter.cpp
clang/lib/AST/Interp/Context.cpp
clang/test/AST/Interp/lambda.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index ae777d555e916..17da77bc63c9b 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -93,6 +93,11 @@ Function *ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
// Set up lambda capture to closure record field mapping.
if (isLambdaCallOperator(MD)) {
+ // The parent record needs to be complete, we need to know about all
+ // the lambda captures.
+ if (!MD->getParent()->isCompleteDefinition())
+ return nullptr;
+
const Record *R = P.getOrCreateRecord(MD->getParent());
llvm::DenseMap<const ValueDecl *, FieldDecl *> LC;
FieldDecl *LTC;
diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp
index 913e8d514282a..b5e992c5a9ac1 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -31,6 +31,9 @@ bool Context::isPotentialConstantExpr(State &Parent, const FunctionDecl *FD) {
if (!Func || !Func->hasBody())
Func = Compiler<ByteCodeEmitter>(*this, *P).compileFunc(FD);
+ if (!Func)
+ return false;
+
APValue DummyResult;
if (!Run(Parent, Func, DummyResult))
return false;
diff --git a/clang/test/AST/Interp/lambda.cpp b/clang/test/AST/Interp/lambda.cpp
index 0eb12643b1b7f..d68fe995e8fa1 100644
--- a/clang/test/AST/Interp/lambda.cpp
+++ b/clang/test/AST/Interp/lambda.cpp
@@ -280,3 +280,9 @@ namespace InvalidCapture {
} ();
}
}
+
+constexpr int fn() {
+ int Capture = 42;
+ return [=]() constexpr { return Capture; }();
+}
+static_assert(fn() == 42, "");
More information about the cfe-commits
mailing list