-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clang][DebugInfo][test] Add tests for lambda capture packs #160705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang][DebugInfo][test] Add tests for lambda capture packs #160705
Conversation
We didn't have coverage for this yet. And I'm planning on making some chnges in this area. These tests will be useful for that.
|
@llvm/pr-subscribers-clang Author: Michael Buch (Michael137) ChangesWe didn't have coverage for this yet. And I'm planning on making some chnges in this area. These tests will be useful for that. Full diff: https://github.com/llvm/llvm-project/pull/160705.diff 1 Files Affected:
diff --git a/clang/test/DebugInfo/CXX/lambda-capture-packs.cpp b/clang/test/DebugInfo/CXX/lambda-capture-packs.cpp
new file mode 100644
index 0000000000000..d5fd442ff2936
--- /dev/null
+++ b/clang/test/DebugInfo/CXX/lambda-capture-packs.cpp
@@ -0,0 +1,165 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm \
+// RUN: -debug-info-kind=standalone -std=c++26 %s -o - | FileCheck %s
+
+
+// CHECK: ![[PACK1:[0-9]+]] = distinct !DISubprogram(name: "capture_pack<int>"
+// CHECK: ![[PACK2:[0-9]+]] = distinct !DISubprogram(name: "capture_pack<int, int>"
+// CHECK: ![[PACK3:[0-9]+]] = distinct !DISubprogram(name: "capture_pack_and_locals<int>"
+// CHECK: ![[PACK4:[0-9]+]] = distinct !DISubprogram(name: "capture_pack_and_locals<int, int>"
+// CHECK: ![[PACK5:[0-9]+]] = distinct !DISubprogram(name: "capture_pack_and_this<int>"
+// CHECK: ![[PACK6:[0-9]+]] = distinct !DISubprogram(name: "capture_pack_and_this<int, int>"
+
+template<typename... Args>
+auto capture_pack(Args... args) {
+ return [args..., ...params = args] {
+ return 0;
+ }();
+}
+
+// CHECK: distinct !DICompositeType(tag: DW_TAG_class_type, scope: ![[PACK1]]
+// CHECK-SAME: elements: ![[PACK1_ELEMS:[0-9]+]]
+// CHECK-NEXT: ![[PACK1_ELEMS]] = !{![[PACK1_ARGS:[0-9]+]], ![[PACK1_PARAMS:[0-9]+]]}
+// CHECK-NEXT: ![[PACK1_ARGS]] = !DIDerivedType(tag: DW_TAG_member, name: "args"
+// CHECK-NEXT: ![[PACK1_PARAMS]] = !DIDerivedType(tag: DW_TAG_member, name: "params"
+// CHECK-NOT: DW_TAG_member
+
+// CHECK: distinct !DICompositeType(tag: DW_TAG_class_type, scope: ![[PACK2]]
+// CHECK-SAME: elements: ![[PACK2_ELEMS:[0-9]+]]
+// CHECK-NEXT: ![[PACK2_ELEMS]] = !{![[PACK2_ARGS:[0-9]+]]
+// CHECK-SAME: ![[PACK2_ARGS]]
+// CHECK-SAME: ![[PACK2_PARAMS:[0-9]+]]
+// CHECK-SAME: ![[PACK2_PARAMS]]}
+// CHECK-NEXT: ![[PACK2_ARGS]] = !DIDerivedType(tag: DW_TAG_member, name: "args"
+// CHECK-NEXT: ![[PACK2_PARAMS]] = !DIDerivedType(tag: DW_TAG_member, name: "params"
+// CHECK-NOT: DW_TAG_member
+
+template<typename... Args>
+auto capture_pack_and_locals(int x, Args... args) {
+ int w = 0;
+ return [=, &args..., &x, ...params = args] {
+ return w;
+ }();
+}
+
+// CHECK: distinct !DICompositeType(tag: DW_TAG_class_type, scope: ![[PACK3]]
+// CHECK-SAME: elements: ![[PACK3_ELEMS:[0-9]+]]
+// CHECK-NEXT: ![[PACK3_ELEMS]] = !{![[PACK3_ARGS:[0-9]+]]
+// CHECK-SAME: ![[PACK3_X:[0-9]+]]
+// CHECK-SAME: ![[PACK3_PARAMS:[0-9]+]]
+// CHECK-SAME: ![[PACK3_W:[0-9]+]]}
+// CHECK-NEXT: ![[PACK3_ARGS]] = !DIDerivedType(tag: DW_TAG_member, name: "args"
+// CHECK-NEXT: !DIDerivedType(tag: DW_TAG_reference_type
+// CHECK-NEXT: ![[PACK3_X]] = !DIDerivedType(tag: DW_TAG_member, name: "x"
+// CHECK-NEXT: ![[PACK3_PARAMS]] = !DIDerivedType(tag: DW_TAG_member, name: "params"
+// CHECK-NEXT: ![[PACK3_W]] = !DIDerivedType(tag: DW_TAG_member, name: "w"
+// CHECK-NOT: DW_TAG_member
+
+// CHECK: distinct !DICompositeType(tag: DW_TAG_class_type, scope: ![[PACK4]]
+// CHECK-SAME: elements: ![[PACK4_ELEMS:[0-9]+]]
+// CHECK-NEXT: ![[PACK4_ELEMS]] = !{![[PACK4_ARGS:[0-9]+]]
+// CHECK-SAME: ![[PACK4_ARGS]]
+// CHECK-SAME: ![[PACK4_X:[0-9]+]]
+// CHECK-SAME: ![[PACK4_PARAMS:[0-9]+]]
+// CHECK-SAME: ![[PACK4_PARAMS]]
+// CHECK-SAME: ![[PACK4_W:[0-9]+]]}
+// CHECK-NEXT: ![[PACK4_ARGS]] = !DIDerivedType(tag: DW_TAG_member, name: "args"
+// CHECK-NEXT: ![[PACK4_X]] = !DIDerivedType(tag: DW_TAG_member, name: "x"
+// CHECK-NEXT: ![[PACK4_PARAMS]] = !DIDerivedType(tag: DW_TAG_member, name: "params"
+// CHECK-NEXT: ![[PACK4_W]] = !DIDerivedType(tag: DW_TAG_member, name: "w"
+// CHECK-NOT: DW_TAG_member
+
+struct Foo {
+ template<typename... Args>
+ auto capture_pack_and_this(Args... args) {
+ auto val1 = [this, args..., ...params = args] {
+ return w;
+ }();
+
+ auto val2 = [args..., this, ...params = args] {
+ return w;
+ }();
+
+ auto val3 = [args..., ...params = args, this] {
+ return w;
+ }();
+
+ return val1 + val2 + val3;
+ }
+
+ int w = 10;
+} f;
+
+// CHECK: distinct !DICompositeType(tag: DW_TAG_class_type, scope: ![[PACK5]]
+// CHECK-SAME: elements: ![[PACK5a_ELEMS:[0-9]+]]
+// CHECK-NEXT: ![[PACK5a_ELEMS]] = !{![[PACK5a_THIS:[0-9]+]]
+// CHECK-SAME: ![[PACK5a_ARGS:[0-9]+]]
+// CHECK-SAME: ![[PACK5a_PARAMS:[0-9]+]]}
+// CHECK-NEXT: ![[PACK5a_THIS]] = !DIDerivedType(tag: DW_TAG_member, name: "this"
+// CHECK-NEXT: ![[PACK5a_ARGS]] = !DIDerivedType(tag: DW_TAG_member, name: "args"
+// CHECK-NEXT: ![[PACK5a_PARAMS]] = !DIDerivedType(tag: DW_TAG_member, name: "params"
+// CHECK-NOT: DW_TAG_member
+
+// CHECK: distinct !DICompositeType(tag: DW_TAG_class_type, scope: ![[PACK5]]
+// CHECK-SAME: elements: ![[PACK5b_ELEMS:[0-9]+]]
+// CHECK-NEXT: ![[PACK5b_ELEMS]] = !{![[PACK5b_ARGS:[0-9]+]]
+// CHECK-SAME: ![[PACK5b_THIS:[0-9]+]]
+// CHECK-SAME: ![[PACK5b_PARAMS:[0-9]+]]}
+// CHECK-NEXT: ![[PACK5b_ARGS]] = !DIDerivedType(tag: DW_TAG_member, name: "args"
+// CHECK-NEXT: ![[PACK5b_THIS]] = !DIDerivedType(tag: DW_TAG_member, name: "this"
+// CHECK-NEXT: ![[PACK5b_PARAMS]] = !DIDerivedType(tag: DW_TAG_member, name: "params"
+// CHECK-NOT: DW_TAG_member
+
+// CHECK: distinct !DICompositeType(tag: DW_TAG_class_type, scope: ![[PACK5]]
+// CHECK-SAME: elements: ![[PACK5c_ELEMS:[0-9]+]]
+// CHECK-NEXT: ![[PACK5c_ELEMS]] = !{![[PACK5c_ARGS:[0-9]+]]
+// CHECK-SAME: ![[PACK5c_PARAMS:[0-9]+]]
+// CHECK-SAME: ![[PACK5c_THIS:[0-9]+]]}
+// CHECK-NEXT: ![[PACK5c_ARGS]] = !DIDerivedType(tag: DW_TAG_member, name: "args"
+// CHECK-NEXT: ![[PACK5c_PARAMS]] = !DIDerivedType(tag: DW_TAG_member, name: "params"
+// CHECK-NEXT: ![[PACK5c_THIS]] = !DIDerivedType(tag: DW_TAG_member, name: "this"
+// CHECK-NOT: DW_TAG_member
+
+// CHECK: distinct !DICompositeType(tag: DW_TAG_class_type, scope: ![[PACK6]]
+// CHECK-SAME: elements: ![[PACK6a_ELEMS:[0-9]+]]
+// CHECK-NEXT: ![[PACK6a_ELEMS]] = !{![[PACK6a_THIS:[0-9]+]]
+// CHECK-SAME: ![[PACK6a_ARGS:[0-9]+]]
+// CHECK-SAME: ![[PACK6a_ARGS]]
+// CHECK-SAME: ![[PACK6a_PARAMS:[0-9]+]]
+// CHECK-SAME: ![[PACK6a_PARAMS]]
+// CHECK-NEXT: ![[PACK6a_THIS]] = !DIDerivedType(tag: DW_TAG_member, name: "this"
+// CHECK-NEXT: ![[PACK6a_ARGS]] = !DIDerivedType(tag: DW_TAG_member, name: "args"
+// CHECK-NEXT: ![[PACK6a_PARAMS]] = !DIDerivedType(tag: DW_TAG_member, name: "params"
+// CHECK-NOT: DW_TAG_member
+
+// CHECK: distinct !DICompositeType(tag: DW_TAG_class_type, scope: ![[PACK6]]
+// CHECK-SAME: elements: ![[PACK6b_ELEMS:[0-9]+]]
+// CHECK-NEXT: ![[PACK6b_ELEMS]] = !{![[PACK6b_ARGS:[0-9]+]]
+// CHECK-SAME: ![[PACK6b_ARGS]]
+// CHECK-SAME: ![[PACK6b_THIS:[0-9]+]]
+// CHECK-SAME: ![[PACK6b_PARAMS:[0-9]+]]
+// CHECK-SAME: ![[PACK6b_PARAMS]]}
+// CHECK-NEXT: ![[PACK6b_ARGS]] = !DIDerivedType(tag: DW_TAG_member, name: "args"
+// CHECK-NEXT: ![[PACK6b_THIS]] = !DIDerivedType(tag: DW_TAG_member, name: "this"
+// CHECK-NEXT: ![[PACK6b_PARAMS]] = !DIDerivedType(tag: DW_TAG_member, name: "params"
+// CHECK-NOT: DW_TAG_member
+
+// CHECK: distinct !DICompositeType(tag: DW_TAG_class_type, scope: ![[PACK6]]
+// CHECK-SAME: elements: ![[PACK6c_ELEMS:[0-9]+]]
+// CHECK-NEXT: ![[PACK6c_ELEMS]] = !{![[PACK6c_ARGS:[0-9]+]]
+// CHECK-SAME: ![[PACK6c_ARGS]]
+// CHECK-SAME: ![[PACK6c_PARAMS:[0-9]+]]
+// CHECK-SAME: ![[PACK6c_PARAMS]]
+// CHECK-SAME: ![[PACK6c_THIS:[0-9]+]]}
+// CHECK-NEXT: ![[PACK6c_ARGS]] = !DIDerivedType(tag: DW_TAG_member, name: "args"
+// CHECK-NEXT: ![[PACK6c_PARAMS]] = !DIDerivedType(tag: DW_TAG_member, name: "params"
+// CHECK-NEXT: ![[PACK6c_THIS]] = !DIDerivedType(tag: DW_TAG_member, name: "this"
+// CHECK-NOT: DW_TAG_member
+
+int main() {
+ return capture_pack(1)
+ + capture_pack(1, 2)
+ + capture_pack_and_locals(1, 2)
+ + capture_pack_and_locals(1, 2, 3)
+ + f.capture_pack_and_this(1)
+ + f.capture_pack_and_this(1, 2);
+}
|
|
I think this test case is needed: (by-reference, with initializer, and is a pack) return [&...params = args] {
return /* ... */;
}(); |
adrian-prantl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with minor modifications (relaxing the test)
|
|
||
| // CHECK: distinct !DICompositeType(tag: DW_TAG_class_type, scope: ![[PACK3]] | ||
| // CHECK-SAME: elements: ![[PACK3_ELEMS:[0-9]+]] | ||
| // CHECK-NEXT: ![[PACK3_ELEMS]] = !{![[PACK3_ARGS:[0-9]+]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's really no reason to expect this to be on the next line. I would just do a CHECK here.
|
|
||
| // CHECK: distinct !DICompositeType(tag: DW_TAG_class_type, scope: ![[PACK4]] | ||
| // CHECK-SAME: elements: ![[PACK4_ELEMS:[0-9]+]] | ||
| // CHECK-NEXT: ![[PACK4_ELEMS]] = !{![[PACK4_ARGS:[0-9]+]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
| // CHECK-SAME: ![[PACK7_PARAMS]] | ||
| // CHECK-SAME: ![[PACK7_ES:[0-9]+]] | ||
| // CHECK-SAME: ![[PACK7_E:[0-9]+]]} | ||
| // CHECK-NEXT: ![[PACK7_ARGS]] = !DIDerivedType(tag: DW_TAG_member, name: "args" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here — the order doesn't matter and might change.
The pack initialization isn't really important for debug-info (i don't think). The reason i have them in the tests is so we have multiple packs in the same capture lists. I do have a by-ref test for one of the packs |
We didn't have coverage for this yet. And I'm planning on making some chnges in this area. These tests will be useful for that.