diff options
author | dim <dim@FreeBSD.org> | 2010-09-17 15:54:40 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2010-09-17 15:54:40 +0000 |
commit | 36c49e3f258dced101949edabd72e9bc3f1dedc4 (patch) | |
tree | 0bbe07708f7571f8b5291f6d7b96c102b7c99dee /test/CodeGen/packed-structure.c | |
parent | fc84956ac8b7cd244ef30e7a4d4d38a58dec5904 (diff) | |
download | FreeBSD-src-36c49e3f258dced101949edabd72e9bc3f1dedc4.zip FreeBSD-src-36c49e3f258dced101949edabd72e9bc3f1dedc4.tar.gz |
Vendor import of clang r114020 (from the release_28 branch):
http://llvm.org/svn/llvm-project/cfe/branches/release_28@114020
Approved by: rpaulo (mentor)
Diffstat (limited to 'test/CodeGen/packed-structure.c')
-rw-r--r-- | test/CodeGen/packed-structure.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/test/CodeGen/packed-structure.c b/test/CodeGen/packed-structure.c new file mode 100644 index 0000000..2934d01 --- /dev/null +++ b/test/CodeGen/packed-structure.c @@ -0,0 +1,89 @@ +// RUN: %clang_cc1 -triple x86_64 -emit-llvm -o - %s | opt -S -strip -o %t +// RUX: llvm-gcc -flto -S -O3 -o %t %s +// RUN: FileCheck --check-prefix=CHECK-GLOBAL < %t %s +// RUN: FileCheck --check-prefix=CHECK-FUNCTIONS < %t %s + +struct s0 { + int x; + int y __attribute__((packed)); +}; + +// CHECK-GLOBAL: @s0_align_x = global i32 4 + +// FIXME: This should be 1 to match gcc. PR7951. +// CHECK-GLOBAL: @s0_align_y = global i32 4 + +// CHECK-GLOBAL: @s0_align = global i32 4 +int s0_align_x = __alignof(((struct s0*)0)->x); +int s0_align_y = __alignof(((struct s0*)0)->y); +int s0_align = __alignof(struct s0); + +// CHECK-FUNCTIONS: define i32 @s0_load_x +// CHECK-FUNCTIONS: [[s0_load_x:%.*]] = load i32* {{.*}}, align 4 +// CHECK-FUNCTIONS: ret i32 [[s0_load_x]] +int s0_load_x(struct s0 *a) { return a->x; } +// FIXME: This seems like it should be align 1. This is actually something which +// has changed in llvm-gcc recently, previously both x and y would be loaded +// with align 1 (in 2363.1 at least). +// +// CHECK-FUNCTIONS: define i32 @s0_load_y +// CHECK-FUNCTIONS: [[s0_load_y:%.*]] = load i32* {{.*}}, align 4 +// CHECK-FUNCTIONS: ret i32 [[s0_load_y]] +int s0_load_y(struct s0 *a) { return a->y; } +// CHECK-FUNCTIONS: define void @s0_copy +// CHECK-FUNCTIONS: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* {{.*}}, i64 8, i32 4, i1 false) +void s0_copy(struct s0 *a, struct s0 *b) { *b = *a; } + +// + +struct s1 { + int x; + int y; +} __attribute__((packed)); + +// CHECK-GLOBAL: @s1_align_x = global i32 1 +// CHECK-GLOBAL: @s1_align_y = global i32 1 +// CHECK-GLOBAL: @s1_align = global i32 1 +int s1_align_x = __alignof(((struct s1*)0)->x); +int s1_align_y = __alignof(((struct s1*)0)->y); +int s1_align = __alignof(struct s1); + +// CHECK-FUNCTIONS: define i32 @s1_load_x +// CHECK-FUNCTIONS: [[s1_load_x:%.*]] = load i32* {{.*}}, align 1 +// CHECK-FUNCTIONS: ret i32 [[s1_load_x]] +int s1_load_x(struct s1 *a) { return a->x; } +// CHECK-FUNCTIONS: define i32 @s1_load_y +// CHECK-FUNCTIONS: [[s1_load_y:%.*]] = load i32* {{.*}}, align 1 +// CHECK-FUNCTIONS: ret i32 [[s1_load_y]] +int s1_load_y(struct s1 *a) { return a->y; } +// CHECK-FUNCTIONS: define void @s1_copy +// CHECK-FUNCTIONS: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* {{.*}}, i64 8, i32 1, i1 false) +void s1_copy(struct s1 *a, struct s1 *b) { *b = *a; } + +// + +#pragma pack(push,2) +struct s2 { + int x; + int y; +}; +#pragma pack(pop) + +// CHECK-GLOBAL: @s2_align_x = global i32 2 +// CHECK-GLOBAL: @s2_align_y = global i32 2 +// CHECK-GLOBAL: @s2_align = global i32 2 +int s2_align_x = __alignof(((struct s2*)0)->x); +int s2_align_y = __alignof(((struct s2*)0)->y); +int s2_align = __alignof(struct s2); + +// CHECK-FUNCTIONS: define i32 @s2_load_x +// CHECK-FUNCTIONS: [[s2_load_y:%.*]] = load i32* {{.*}}, align 2 +// CHECK-FUNCTIONS: ret i32 [[s2_load_y]] +int s2_load_x(struct s2 *a) { return a->x; } +// CHECK-FUNCTIONS: define i32 @s2_load_y +// CHECK-FUNCTIONS: [[s2_load_y:%.*]] = load i32* {{.*}}, align 2 +// CHECK-FUNCTIONS: ret i32 [[s2_load_y]] +int s2_load_y(struct s2 *a) { return a->y; } +// CHECK-FUNCTIONS: define void @s2_copy +// CHECK-FUNCTIONS: call void @llvm.memcpy.p0i8.p0i8.i64(i8* {{.*}}, i8* {{.*}}, i64 8, i32 2, i1 false) +void s2_copy(struct s2 *a, struct s2 *b) { *b = *a; } |