xref: /llvm-project/clang/test/CodeGenCXX/lambda-deterministic-captures.cpp (revision 94473f4db6a6f5f12d7c4081455b5b596094eac5)
1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm --std=c++17 %s -o - | FileCheck %s
2 
3 struct stream {
4   friend const stream &operator<<(const stream &, const float &);
5 };
6 
7 void foo() {
8   constexpr float f_zero = 0.0f;
9   constexpr float f_one = 1.0f;
10   constexpr float f_two = 2.0f;
11 
12   stream s;
13   [=]() {
14     s << f_zero << f_one << f_two;
15   }();
16 }
17 
18 // CHECK: define{{.*}} void @_Z3foov
19 // CHECK:      getelementptr inbounds nuw %{{.+}}, ptr %{{.+}}, i32 0, i32 1
20 // CHECK-NEXT: store float 0.000
21 // CHECK-NEXT: getelementptr inbounds nuw %{{.+}}, ptr %{{.+}}, i32 0, i32 2
22 // CHECK-NEXT: store float 1.000
23 // CHECK-NEXT: getelementptr inbounds nuw %{{.+}}, ptr %{{.+}}, i32 0, i32 3
24 // CHECK-NEXT: store float 2.000
25 
26 // The lambda body.  Reverse iteration when the captures aren't deterministic
27 // causes these to be laid out differently in the lambda.
28 // CHECK: define internal void
29 // CHECK: getelementptr inbounds nuw %{{.+}}, ptr %{{.+}}, i32 0, i32 1
30 // CHECK: getelementptr inbounds nuw %{{.+}}, ptr %{{.+}}, i32 0, i32 2
31 // CHECK: getelementptr inbounds nuw %{{.+}}, ptr %{{.+}}, i32 0, i32 3
32