summaryrefslogtreecommitdiff
path: root/test/DebugInfo/X86/lexical-block-pr19238.ll
blob: 81e31391294eb8a56fc4b70ed45b1e6d72d18e9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -filetype=obj -O0 < %s  | llvm-dwarfdump -debug-dump=info - | FileCheck %s

;; This test checks the following:
;; 1. Useless lexical block entry is not emitted
;; 2. Function static variable, typedef, records (structure, class and union)
;;    that are defined in lexical basic block are emitted as children to
;;    these lexical blocks.
;;    * For typedef and record check that both are emitted in lexical block
;;      where they are declared and not in the one where they are used.
;;
;; This test was generated by running following command:
;; clang -cc1 -O0 -g -emit-llvm foo.cpp 
;; Where foo.cpp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;int foo(void) { 
;;  {
;;    {
;;      struct X {
;;        int x;
;;      };
;;      typedef int Y;
;;      {
;;        X a;
;;        Y b;
;;        static int c;
;;        return a.x + b + c;
;;      }
;;    }
;;  }
;;}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


; CHECK:      DW_TAG_subprogram
; CHECK-NOT: DW_TAG
; CHECK:        DW_AT_name {{.*}} "foo"
; CHECK-NOT: NULL
; CHECK:      DW_TAG_lexical_block

; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK:        DW_TAG_structure_type
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK:          DW_AT_name {{.*}} "X"
; CHECK:          NULL

; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK:        DW_TAG_typedef
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK:          DW_AT_name {{.*}} "Y"

; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK:        DW_TAG_lexical_block

; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK:        DW_TAG_variable
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK:          DW_AT_name {{.*}} "c"

; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK:        DW_TAG_variable
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK:          DW_AT_name {{.*}} "a"

; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK:        DW_TAG_variable
; CHECK-NOT: {{DW_TAG|NULL}}
; CHECK:          DW_AT_name {{.*}} "b"

; CHECK-NOT: {{DW_TAG}}
; CHECK:        NULL


%struct.X = type { i32 }

@_ZZ3foovE1c = internal global i32 0, align 4

; Function Attrs: nounwind
define i32 @_Z3foov() #0 {
entry:
  %a = alloca %struct.X, align 4
  %b = alloca i32, align 4
  call void @llvm.dbg.declare(metadata %struct.X* %a, metadata !21, metadata !22), !dbg !23
  call void @llvm.dbg.declare(metadata i32* %b, metadata !24, metadata !22), !dbg !25
  %x = getelementptr inbounds %struct.X, %struct.X* %a, i32 0, i32 0, !dbg !26
  %0 = load i32, i32* %x, align 4, !dbg !26
  %1 = load i32, i32* %b, align 4, !dbg !26
  %add = add nsw i32 %0, %1, !dbg !26
  %2 = load i32, i32* @_ZZ3foovE1c, align 4, !dbg !26
  %add1 = add nsw i32 %add, %2, !dbg !26
  ret i32 %add1, !dbg !26
}

; Function Attrs: nounwind readnone
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1

attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { nounwind readnone }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!18, !19}
!llvm.ident = !{!20}

!0 = !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.7.0 (trunk 237245)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, retainedTypes: !3, subprograms: !14, globals: !15, imports: !2)
!1 = !DIFile(filename: "foo.cpp", directory: "/")
!2 = !{}
!3 = !{!4, !13}
!4 = !DICompositeType(tag: DW_TAG_structure_type, name: "X", scope: !5, file: !1, line: 4, size: 32, align: 32, elements: !11)
!5 = distinct !DILexicalBlock(scope: !6, file: !1, line: 3)
!6 = distinct !DILexicalBlock(scope: !7, file: !1, line: 2)
!7 = !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: false, function: i32 ()* @_Z3foov, variables: !2)
!8 = !DISubroutineType(types: !9)
!9 = !{!10}
!10 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
!11 = !{!12}
!12 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !4, file: !1, line: 5, baseType: !10, size: 32, align: 32)
!13 = !DIDerivedType(tag: DW_TAG_typedef, name: "Y", scope: !5, file: !1, line: 7, baseType: !10)
!14 = !{!7}
!15 = !{!16}
!16 = !DIGlobalVariable(name: "c", scope: !17, file: !1, line: 11, type: !10, isLocal: true, isDefinition: true, variable: i32* @_ZZ3foovE1c)
!17 = distinct !DILexicalBlock(scope: !5, file: !1, line: 8)
!18 = !{i32 2, !"Dwarf Version", i32 4}
!19 = !{i32 2, !"Debug Info Version", i32 3}
!20 = !{!"clang version 3.7.0 (trunk 237245)"}
!21 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "a", scope: !17, file: !1, line: 9, type: !4)
!22 = !DIExpression()
!23 = !DILocation(line: 9, scope: !17)
!24 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "b", scope: !17, file: !1, line: 10, type: !13)
!25 = !DILocation(line: 10, scope: !17)
!26 = !DILocation(line: 12, scope: !17)