1 // RUN: %clang_cc1 -mconstructor-aliases -std=c++11 -fexceptions -emit-llvm %s -o - -triple=i386-pc-win32 | FileCheck %s
2 
3 struct A {
4   A(int a);
5   ~A();
6   int a;
7 };
8 
9 void foo(A a, A b, A c) {
10 }
11 
12 // Order of destruction should be left to right.
13 //
14 // CHECK-LABEL: define void @"\01?foo@@YAXUA@@00@Z"
15 // CHECK:          ([[argmem_ty:<{ %struct.A, %struct.A, %struct.A }>]]* inalloca)
16 // CHECK: %[[a:[^ ]*]] = getelementptr inbounds [[argmem_ty]]* %0, i32 0, i32 0
17 // CHECK: %[[b:[^ ]*]] = getelementptr inbounds [[argmem_ty]]* %0, i32 0, i32 1
18 // CHECK: %[[c:[^ ]*]] = getelementptr inbounds [[argmem_ty]]* %0, i32 0, i32 2
19 // CHECK: call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %[[a]])
20 // CHECK: call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %[[b]])
21 // CHECK: call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %[[c]])
22 // CHECK: ret void
23 
24 
25 void call_foo() {
26   foo(A(1), A(2), A(3));
27 }
28 
29 // Order of evaluation should be right to left, and we should clean up the right
30 // things as we unwind.
31 //
32 // CHECK-LABEL: define void @"\01?call_foo@@YAXXZ"()
33 // CHECK: call i8* @llvm.stacksave()
34 // CHECK: %[[argmem:[^ ]*]] = alloca inalloca [[argmem_ty]]
35 // CHECK: %[[arg3:[^ ]*]] = getelementptr inbounds [[argmem_ty]]* %[[argmem]], i32 0, i32 2
36 // CHECK: invoke x86_thiscallcc %struct.A* @"\01??0A@@QAE@H@Z"(%struct.A* %[[arg3]], i32 3)
37 // CHECK: %[[arg2:[^ ]*]] = getelementptr inbounds [[argmem_ty]]* %[[argmem]], i32 0, i32 1
38 // CHECK: invoke x86_thiscallcc %struct.A* @"\01??0A@@QAE@H@Z"(%struct.A* %[[arg2]], i32 2)
39 // CHECK: %[[arg1:[^ ]*]] = getelementptr inbounds [[argmem_ty]]* %[[argmem]], i32 0, i32 0
40 // CHECK: invoke x86_thiscallcc %struct.A* @"\01??0A@@QAE@H@Z"(%struct.A* %[[arg1]], i32 1)
41 // CHECK: invoke void @"\01?foo@@YAXUA@@00@Z"([[argmem_ty]]* inalloca %[[argmem]])
42 // CHECK: call void @llvm.stackrestore
43 // CHECK: ret void
44 //
45 //   lpad2:
46 // CHECK: call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %[[arg2]])
47 // CHECK: br label
48 //
49 //   ehcleanup:
50 // CHECK: call x86_thiscallcc void @"\01??1A@@QAE@XZ"(%struct.A* %[[arg3]])
51