blob: d4b751a48bd9440ccad26a8e4f38e651a7bacced [file] [log] [blame]
Eli Friedman55d48482011-05-26 00:10:27 +00001// RUN: %clang_cc1 -emit-llvm -triple x86_64-apple-darwin10 < %s | FileCheck %s
2
3struct Test1S {
4 long NumDecls;
5 long X;
6 long Y;
7};
8struct Test2S {
9 long NumDecls;
10 long X;
11};
12
13// Make sure we don't generate extra memcpy for lvalues
14void test1a(struct Test1S, struct Test2S);
Stephen Lin93ab6bf2013-08-15 06:47:53 +000015// CHECK-LABEL: define void @test1(
Eli Friedman55d48482011-05-26 00:10:27 +000016// CHECK-NOT: memcpy
17// CHECK: call void @test1a
18void test1(struct Test1S *A, struct Test2S *B) {
19 test1a(*A, *B);
20}
Eli Friedmanea5e4da2011-06-14 01:37:52 +000021
22// The above gets tricker when the byval argument requires higher alignment
23// than the natural alignment of the type in question.
24// rdar://9483886
25
26// Make sure we do generate a memcpy when we cannot guarantee alignment.
27struct Test3S {
28 int a,b,c,d,e,f,g,h,i,j,k,l;
29};
30void test2a(struct Test3S q);
Stephen Lin93ab6bf2013-08-15 06:47:53 +000031// CHECK-LABEL: define void @test2(
Eli Friedmanea5e4da2011-06-14 01:37:52 +000032// CHECK: alloca %struct.Test3S, align 8
33// CHECK: memcpy
34// CHECK: call void @test2a
35void test2(struct Test3S *q) {
36 test2a(*q);
37}
38
39// But make sure we don't generate a memcpy when we can guarantee alignment.
40void fooey(void);
Stephen Lin93ab6bf2013-08-15 06:47:53 +000041// CHECK-LABEL: define void @test3(
Eli Friedmanea5e4da2011-06-14 01:37:52 +000042// CHECK: alloca %struct.Test3S, align 8
43// CHECK: call void @fooey
44// CHECK-NOT: memcpy
45// CHECK: call void @test2a
46// CHECK-NOT: memcpy
47// CHECK: call void @test2a
48void test3(struct Test3S a) {
49 struct Test3S b = a;
50 fooey();
51 test2a(a);
52 test2a(b);
53}