xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenObjC/bitfield-access.m (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple i386-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5 -emit-llvm -o %t1 %s
2*f4a2713aSLionel Sambuc// RUN: FileCheck -check-prefix=CHECK-I386 < %t1 %s
3*f4a2713aSLionel Sambuc
4*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -triple armv6-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5 -target-abi apcs-gnu -emit-llvm -o %t2 %s
5*f4a2713aSLionel Sambuc// RUN: FileCheck -check-prefix=CHECK-ARM < %t2 %s
6*f4a2713aSLionel Sambuc
7*f4a2713aSLionel Sambuc@interface I0 {
8*f4a2713aSLionel Sambuc@public
9*f4a2713aSLionel Sambuc    unsigned x:15;
10*f4a2713aSLionel Sambuc    unsigned y: 1;
11*f4a2713aSLionel Sambuc}
12*f4a2713aSLionel Sambuc@end
13*f4a2713aSLionel Sambuc
14*f4a2713aSLionel Sambuc// Check that we don't try to use an i32 load here, which would reach beyond the
15*f4a2713aSLionel Sambuc// end of the structure.
16*f4a2713aSLionel Sambuc//
17*f4a2713aSLionel Sambuc// CHECK-I386-LABEL: define i32 @f0(
18*f4a2713aSLionel Sambuc// CHECK-I386:   [[t0_0:%.*]] = load i8* {{.*}}, align 1
19*f4a2713aSLionel Sambuc// CHECK-I386:   lshr i8 [[t0_0]], 7
20*f4a2713aSLionel Sambuc// CHECK-I386: }
21*f4a2713aSLionel Sambucint f0(I0 *a) {
22*f4a2713aSLionel Sambuc  return a->y;
23*f4a2713aSLionel Sambuc}
24*f4a2713aSLionel Sambuc
25*f4a2713aSLionel Sambuc// Check that we can handled straddled loads.
26*f4a2713aSLionel Sambuc//
27*f4a2713aSLionel Sambuc// CHECK-ARM-LABEL: define i32 @f1(
28*f4a2713aSLionel Sambuc// CHECK-ARM:    [[t1_ptr:%.*]] = getelementptr
29*f4a2713aSLionel Sambuc// CHECK-ARM:    [[t1_base:%.*]] = bitcast i8* [[t1_ptr]] to i40*
30*f4a2713aSLionel Sambuc// CHECK-ARM:    [[t1_0:%.*]] = load i40* [[t1_base]], align 1
31*f4a2713aSLionel Sambuc// CHECK-ARM:    [[t1_1:%.*]] = lshr i40 [[t1_0]], 1
32*f4a2713aSLionel Sambuc// CHECK-ARM:    [[t1_2:%.*]] = and i40 [[t1_1]],
33*f4a2713aSLionel Sambuc// CHECK-ARM:                   trunc i40 [[t1_2]] to i32
34*f4a2713aSLionel Sambuc// CHECK-ARM: }
35*f4a2713aSLionel Sambuc@interface I1 {
36*f4a2713aSLionel Sambuc@public
37*f4a2713aSLionel Sambuc    unsigned x: 1;
38*f4a2713aSLionel Sambuc    unsigned y:32;
39*f4a2713aSLionel Sambuc}
40*f4a2713aSLionel Sambuc@end
41*f4a2713aSLionel Sambuc
42*f4a2713aSLionel Sambucint f1(I1 *a) { return a->y; }
43