summaryrefslogtreecommitdiffstats
path: root/clang/test/CodeGenCXX/lambda-expressions.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2012-02-17 03:02:34 +0000
committerDouglas Gregor <dgregor@apple.com>2012-02-17 03:02:34 +0000
commit355efbb2e044126adecdcadca87c8cdfb5c33a85 (patch)
tree1414f54d5ff0cc4f6b5b09b8b806178a0ae2d9e2 /clang/test/CodeGenCXX/lambda-expressions.cpp
parentd608bac682fc88eb8ab7dc1ef65245c0f5c75712 (diff)
downloadbcm5719-llvm-355efbb2e044126adecdcadca87c8cdfb5c33a85.tar.gz
bcm5719-llvm-355efbb2e044126adecdcadca87c8cdfb5c33a85.zip
Rework the Sema/AST/IRgen dance for the lambda closure type's
conversion to function pointer. Rather than having IRgen synthesize the body of this function, we instead introduce a static member function "__invoke" with the same signature as the lambda's operator() in the AST. Sema then generates a body for the conversion to function pointer which simply returns the address of __invoke. This approach makes it easier to evaluate a call to the conversion function as a constant, makes the linkage of the __invoke function follow the normal rules for member functions, and may make life easier down the road if we ever want to constexpr'ify some of lambdas. Note that IR generation is responsible for filling in the body of __invoke (Sema just adds a dummy body), because the body can't generally be expressed in C++. Eli, please review! llvm-svn: 150783
Diffstat (limited to 'clang/test/CodeGenCXX/lambda-expressions.cpp')
-rw-r--r--clang/test/CodeGenCXX/lambda-expressions.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/clang/test/CodeGenCXX/lambda-expressions.cpp b/clang/test/CodeGenCXX/lambda-expressions.cpp
index 237687037d7..e1aab1889c0 100644
--- a/clang/test/CodeGenCXX/lambda-expressions.cpp
+++ b/clang/test/CodeGenCXX/lambda-expressions.cpp
@@ -47,8 +47,26 @@ int e(E a, E b, bool cond) { [a,b,cond](){ return (cond ? a : b).x; }(); }
// CHECK: invoke i32 @"_ZZ1e1ES_bENK3$_4clEv"
// CHECK: call void @"_ZZ1e1ES_bEN3$_4D1Ev"
// CHECK: call void @"_ZZ1e1ES_bEN3$_4D1Ev"
+
// CHECK: define internal i32 @"_ZZ1e1ES_bENK3$_4clEv"
// CHECK: trunc i8
// CHECK: load i32*
// CHECK: ret i32
+
+void f() {
+ // CHECK: define void @_Z1fv()
+ // CHECK: {{call.*_5cvPFiiiEEv}}
+ // CHECK-NEXT: store i32 (i32, i32)*
+ // CHECK-NEXT: ret void
+ int (*fp)(int, int) = [](int x, int y){ return x + y; };
+}
+
+// CHECK: define internal i32 @"_ZZ1fvEN3$_58__invokeEii"
+// CHECK: store i32
+// CHECK-NEXT: store i32
+// CHECK-NEXT: load i32*
+// CHECK-NEXT: load i32*
+// CHECK-NEXT: call i32 @"_ZZ1fvENK3$_5clEii"
+// CHECK-NEXT: ret i32
+
// CHECK: define internal void @"_ZZ1e1ES_bEN3$_4D2Ev"
OpenPOWER on IntegriCloud