diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-08-21 04:20:22 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-08-21 04:20:22 +0000 |
commit | 5c816378f80334c2b88b0c887be51dca6c49a8ed (patch) | |
tree | 0f6c371b840574944c0b8943584422dab7165e9c /clang/test/CodeGen/packed-structure.c | |
parent | 49e5d12e592fb7877c385f1d89d2dd6900c18d55 (diff) | |
download | bcm5719-llvm-5c816378f80334c2b88b0c887be51dca6c49a8ed.tar.gz bcm5719-llvm-5c816378f80334c2b88b0c887be51dca6c49a8ed.zip |
IRgen: Set the alignment correctly when creating LValue for a decls.
- Fixes PR5598.
- Review appreciated.
llvm-svn: 111726
Diffstat (limited to 'clang/test/CodeGen/packed-structure.c')
-rw-r--r-- | clang/test/CodeGen/packed-structure.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/clang/test/CodeGen/packed-structure.c b/clang/test/CodeGen/packed-structure.c new file mode 100644 index 00000000000..2934d01d649 --- /dev/null +++ b/clang/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; } |