| 1 |
// RUN: %clang_cc1 -emit-llvm -triple x86_64-apple-darwin10 < %s | FileCheck %s |
| 2 |
|
| 3 |
struct Test1S { |
| 4 |
long NumDecls; |
| 5 |
long X; |
| 6 |
long Y; |
| 7 |
}; |
| 8 |
struct Test2S { |
| 9 |
long NumDecls; |
| 10 |
long X; |
| 11 |
}; |
| 12 |
|
| 13 |
// Make sure we don't generate extra memcpy for lvalues |
| 14 |
void test1a(struct Test1S, struct Test2S); |
| 15 |
// CHECK-LABEL: define{{.*}} void @test1( |
| 16 |
// CHECK-NOT: memcpy |
| 17 |
// CHECK: call void @test1a |
| 18 |
void test1(struct Test1S *A, struct Test2S *B) { |
| 19 |
test1a(*A, *B); |
| 20 |
} |
| 21 |
|
| 22 |
// The above gets tricker when the byval argument requires higher alignment |
| 23 |
// than the natural alignment of the type in question. |
| 24 |
|
| 25 |
// Make sure we do generate a memcpy when we cannot guarantee alignment. |
| 26 |
struct Test3S { |
| 27 |
int a,b,c,d,e,f,g,h,i,j,k,l; |
| 28 |
}; |
| 29 |
void test2a(struct Test3S q); |
| 30 |
// CHECK-LABEL: define{{.*}} void @test2( |
| 31 |
// CHECK: alloca %struct.Test3S, align 8 |
| 32 |
// CHECK: memcpy |
| 33 |
// CHECK: call void @test2a |
| 34 |
void test2(struct Test3S *q) { |
| 35 |
test2a(*q); |
| 36 |
} |
| 37 |
|
| 38 |
// But make sure we don't generate a memcpy when we can guarantee alignment. |
| 39 |
void fooey(void); |
| 40 |
// CHECK-LABEL: define{{.*}} void @test3( |
| 41 |
// CHECK: alloca %struct.Test3S, align 8 |
| 42 |
// CHECK: call void @fooey |
| 43 |
// CHECK-NOT: memcpy |
| 44 |
// CHECK: call void @test2a |
| 45 |
// CHECK-NOT: memcpy |
| 46 |
// CHECK: call void @test2a |
| 47 |
void test3(struct Test3S a) { |
| 48 |
struct Test3S b = a; |
| 49 |
fooey(); |
| 50 |
test2a(a); |
| 51 |
test2a(b); |
| 52 |
} |