aaron.ballman added inline comments.
================
Comment at: clang/lib/AST/Interp/ByteCodeEmitter.cpp:56-57
+ const Record *R = P.getOrCreateRecord(MD->getParent());
+ llvm::DenseMap<const ValueDecl *, FieldDecl *> _LambdaCaptures;
+ FieldDecl *_LambdaThisCapture;
+
----------------
UB alert -- `_L` is reserved; let's pick names without leading underscores or
shadowing.
================
Comment at: clang/lib/AST/Interp/ByteCodeEmitter.h:73-74
llvm::DenseMap<const ParmVarDecl *, unsigned> Params;
+ /// Lambda captures.
+ llvm::DenseMap<const ValueDecl *, std::pair<unsigned, bool>> LambdaCaptures;
+ unsigned *LambdaThisCapture;
----------------
Can you add comments explaining what the `unsigned, bool` pair is encoding?
================
Comment at: clang/lib/AST/Interp/ByteCodeEmitter.h:75
+ llvm::DenseMap<const ValueDecl *, std::pair<unsigned, bool>> LambdaCaptures;
+ unsigned *LambdaThisCapture;
/// Local descriptors.
----------------
Why is this a pointer? Since it's not really implemented, I'd recommend
removing this for now and adding it back when you add support for capturing
`this`.
================
Comment at: clang/test/AST/Interp/lambda.cpp:92
+ static_assert(foo() == 1); // expected-error {{not an integral constant
expression}}
+}
+
----------------
How about some tests like:
```
constexpr int call_thru_func_ptr(int i) {
auto l = [](int i) { return i; };
int (*fp)(int) = l;
return fp(i);
}
static_assert(call_thru_func_ptr(12) == 12);
constexpr int call_through_copied_lambda(auto lam, int i) {
auto copy = lam;
return copy(i);
}
constexpr int call_through_copied_lambda(auto lam) {
auto copy = lam;
return copy();
}
void func() {
constexpr int i = 12;
static_assert(call_through_copied_lambda([i]() { return i; }) == 12);
}
```
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146030/new/
https://reviews.llvm.org/D146030
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits