Debug Info: Add basic test coverage for the DWARF encoding of bitfields.
[oota-llvm.git] / test / DebugInfo / bitfields.ll
1 ; RUN: %llc_dwarf -mtriple x86_64-apple-macosx -O0 -filetype=obj -o %t_le.o %s
2 ; RUN: llvm-dwarfdump -debug-dump=info %t_le.o | FileCheck %s --check-prefix=CHECK-LE
3 ; RUN: %llc_dwarf -mtriple aarch64_be-gnu-linux -O0 -filetype=obj -o %t_be.o %s
4 ; RUN: llvm-dwarfdump -debug-dump=info %t_be.o | FileCheck %s --check-prefix=CHECK-BE
5
6 ; Produced at -O0 from:
7 ; struct bitfield {
8 ;   int a : 2;
9 ;   int b : 32;
10 ;   int c : 1;
11 ;   int d : 28;
12 ; };
13 ; struct bitfield b;
14
15 ; Note that DWARF 2 counts bit offsets backwards from the high end of
16 ; the storage unit to the high end of the bit field.
17
18 ; CHECK-LE: DW_TAG_member
19 ; CHECK-LE-NEXT: DW_AT_name{{.*}}"a"
20 ; CHECK-LE-NOT: DW_TAG_member
21 ; CHECK-LE:      DW_AT_byte_size  {{.*}} (0x04)
22 ; CHECK-LE-NEXT: DW_AT_bit_size   {{.*}} (0x02)
23 ; CHECK-LE-NEXT: DW_AT_bit_offset {{.*}} (0x1e)
24 ; CHECK-LE-NEXT: DW_AT_data_member_location {{.*}} 00
25
26 ; CHECK-LE: DW_TAG_member
27 ; CHECK-LE-NEXT: DW_AT_name{{.*}}"b"
28 ; CHECK-LE-NOT: DW_TAG_member
29 ; CHECK-LE:      DW_AT_data_member_location {{.*}} 04
30
31 ; CHECK-LE: DW_TAG_member
32 ; CHECK-LE-NEXT: DW_AT_name{{.*}}"c"
33 ; CHECK-LE-NOT: DW_TAG_member
34 ; CHECK-LE:      DW_AT_byte_size  {{.*}} (0x04)
35 ; CHECK-LE-NEXT: DW_AT_bit_size   {{.*}} (0x01)
36 ; CHECK-LE-NEXT: DW_AT_bit_offset {{.*}} (0x1f)
37 ; CHECK-LE-NEXT: DW_AT_data_member_location {{.*}} 08
38
39 ; CHECK-LE: DW_TAG_member
40 ; CHECK-LE-NEXT: DW_AT_name{{.*}}"d"
41 ; CHECK-LE-NOT: DW_TAG_member
42 ; CHECK-LE:      DW_AT_byte_size  {{.*}} (0x04)
43 ; CHECK-LE-NEXT: DW_AT_bit_size   {{.*}} (0x1c)
44 ; CHECK-LE-NEXT: DW_AT_bit_offset {{.*}} (0x03)
45 ; CHECK-LE-NEXT: DW_AT_data_member_location {{.*}} 08
46
47 ; CHECK-BE: DW_TAG_member
48 ; CHECK-BE-NEXT: DW_AT_name{{.*}}"a"
49 ; CHECK-BE-NOT: DW_TAG_member
50 ; CHECK-BE:      DW_AT_byte_size  {{.*}} (0x04)
51 ; CHECK-BE-NEXT: DW_AT_bit_size   {{.*}} (0x02)
52 ; CHECK-BE-NEXT: DW_AT_bit_offset {{.*}} (0x00)
53 ; CHECK-BE-NEXT: DW_AT_data_member_location {{.*}} 00
54
55 ; CHECK-BE: DW_TAG_member
56 ; CHECK-BE-NEXT: DW_AT_name{{.*}}"b"
57 ; CHECK-BE-NOT: DW_TAG_member
58 ; CHECK-BE:      DW_AT_data_member_location {{.*}} 04
59
60 ; CHECK-BE: DW_TAG_member
61 ; CHECK-BE-NEXT: DW_AT_name{{.*}}"c"
62 ; CHECK-BE-NOT: DW_TAG_member
63 ; CHECK-BE:      DW_AT_byte_size  {{.*}} (0x04)
64 ; CHECK-BE-NEXT: DW_AT_bit_size   {{.*}} (0x01)
65 ; CHECK-BE-NEXT: DW_AT_bit_offset {{.*}} (0x00)
66 ; CHECK-BE-NEXT: DW_AT_data_member_location {{.*}} 08
67
68 ; CHECK-BE: DW_TAG_member
69 ; CHECK-BE-NEXT: DW_AT_name{{.*}}"d"
70 ; CHECK-BE-NOT: DW_TAG_member
71 ; CHECK-BE:      DW_AT_byte_size  {{.*}} (0x04)
72 ; CHECK-BE-NEXT: DW_AT_bit_size   {{.*}} (0x1c)
73 ; CHECK-BE-NEXT: DW_AT_bit_offset {{.*}} (0x01)
74 ; CHECK-BE-NEXT: DW_AT_data_member_location {{.*}} 08
75
76 ; ModuleID = 'bitfields.c'
77 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
78 target triple = "x86_64-apple-macosx"
79
80 %struct.bitfield = type <{ i8, [3 x i8], i64 }>
81
82 @b = common global %struct.bitfield zeroinitializer, align 4
83
84 !llvm.dbg.cu = !{!0}
85 !llvm.module.flags = !{!13, !14, !15}
86 !llvm.ident = !{!16}
87
88 !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.7.0 (trunk 240548) (llvm/trunk 240554)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, retainedTypes: !2, subprograms: !2, globals: !3, imports: !2)
89 !1 = !DIFile(filename: "bitfields.c", directory: "/")
90 !2 = !{}
91 !3 = !{!4}
92 !4 = !DIGlobalVariable(name: "b", scope: !0, file: !5, line: 8, type: !6, isLocal: false, isDefinition: true, variable: %struct.bitfield* @b)
93 !5 = !DIFile(filename: "bitfields.c", directory: "/")
94 !6 = !DICompositeType(tag: DW_TAG_structure_type, name: "bitfield", file: !5, line: 1, size: 96, align: 32, elements: !7)
95 !7 = !{!8, !10, !11, !12}
96 !8 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !6, file: !5, line: 2, baseType: !9, size: 2, align: 32)
97 !9 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
98 !10 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !6, file: !5, line: 3, baseType: !9, size: 32, align: 32, offset: 32)
99 !11 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !6, file: !5, line: 4, baseType: !9, size: 1, align: 32, offset: 64)
100 !12 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !6, file: !5, line: 5, baseType: !9, size: 28, align: 32, offset: 65)
101 !13 = !{i32 2, !"Dwarf Version", i32 2}
102 !14 = !{i32 2, !"Debug Info Version", i32 3}
103 !15 = !{i32 1, !"PIC Level", i32 2}
104 !16 = !{!"clang version 3.7.0 (trunk 240548) (llvm/trunk 240554)"}