• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt %s -simplifycfg -verify -S -o - | FileCheck %s
2;
3; Verify that SimplifyCFG does not invalidate operands for
4; llvm.dbg.value intrinsics.
5;
6; Reduced from the following example, compiled with
7; -O1 -g -fno-exceptions -fno-discard-value-names:
8;
9; void test() {
10;   bool a = false;
11;   bool b = false;
12;   bool c = false;
13;   [&a, &b, &c] { b = true; }();
14;
15;   if (a || b || c) {
16;     __builtin_debugtrap();
17;   }
18; }
19
20; CHECK: _Z4testv
21; CHECK-NOT: llvm.dbg.value(metadata !
22; CHECK: ret void
23
24%class.anon = type { i8*, i8*, i8* }
25
26; Function Attrs: nounwind uwtable
27define dso_local void @_Z4testv() local_unnamed_addr !dbg !7 {
28entry:
29  %a = alloca i8, align 1
30  %b = alloca i8, align 1
31  %c = alloca i8, align 1
32  %ref.tmp = alloca %class.anon, align 8
33  call void @llvm.dbg.value(metadata i8* %a, metadata !12, metadata !DIExpression(DW_OP_deref)), !dbg !16
34  call void @llvm.dbg.value(metadata i8 0, metadata !12, metadata !DIExpression()), !dbg !16
35  store i8 0, i8* %a, align 1, !dbg !16
36  call void @llvm.dbg.value(metadata i8* %b, metadata !14, metadata !DIExpression(DW_OP_deref)), !dbg !16
37  call void @llvm.dbg.value(metadata i8 0, metadata !14, metadata !DIExpression()), !dbg !16
38  store i8 0, i8* %b, align 1, !dbg !16
39  call void @llvm.dbg.value(metadata i8* %c, metadata !15, metadata !DIExpression(DW_OP_deref)), !dbg !16
40  call void @llvm.dbg.value(metadata i8 0, metadata !15, metadata !DIExpression()), !dbg !16
41  store i8 0, i8* %c, align 1, !dbg !16
42  %0 = bitcast %class.anon* %ref.tmp to i8*, !dbg !16
43  %1 = getelementptr inbounds %class.anon, %class.anon* %ref.tmp, i64 0, i32 0, !dbg !16
44  store i8* %a, i8** %1, align 8, !dbg !16
45  %2 = getelementptr inbounds %class.anon, %class.anon* %ref.tmp, i64 0, i32 1, !dbg !16
46  store i8* %b, i8** %2, align 8, !dbg !16
47  %3 = getelementptr inbounds %class.anon, %class.anon* %ref.tmp, i64 0, i32 2, !dbg !16
48  store i8* %c, i8** %3, align 8, !dbg !16
49  call fastcc void @"_ZZ4testvENK3$_0clEv"(%class.anon* nonnull %ref.tmp), !dbg !16
50  %4 = load i8, i8* %a, align 1, !dbg !17
51  call void @llvm.dbg.value(metadata i8 %4, metadata !12, metadata !DIExpression()), !dbg !16
52  %tobool = icmp eq i8 %4, 0, !dbg !17
53  br i1 %tobool, label %lor.lhs.false, label %if.then, !dbg !17
54
55lor.lhs.false:                                    ; preds = %entry
56  %5 = load i8, i8* %b, align 1, !dbg !17
57  call void @llvm.dbg.value(metadata i8 %5, metadata !14, metadata !DIExpression()), !dbg !16
58  %tobool1 = icmp eq i8 %5, 0, !dbg !17
59  br i1 %tobool1, label %lor.lhs.false2, label %if.then, !dbg !17
60
61lor.lhs.false2:                                   ; preds = %lor.lhs.false
62  %6 = load i8, i8* %c, align 1, !dbg !17
63  call void @llvm.dbg.value(metadata i8 %6, metadata !15, metadata !DIExpression()), !dbg !16
64  %tobool3 = icmp eq i8 %6, 0, !dbg !17
65  br i1 %tobool3, label %if.end, label %if.then, !dbg !16
66
67if.then:                                          ; preds = %lor.lhs.false2, %lor.lhs.false, %entry
68  call void @llvm.debugtrap(), !dbg !19
69  br label %if.end, !dbg !19
70
71if.end:                                           ; preds = %lor.lhs.false2, %if.then
72  call void @llvm.dbg.value(metadata i8* %c, metadata !15, metadata !DIExpression(DW_OP_deref)), !dbg !16
73  call void @llvm.dbg.value(metadata i8* %b, metadata !14, metadata !DIExpression(DW_OP_deref)), !dbg !16
74  call void @llvm.dbg.value(metadata i8* %a, metadata !12, metadata !DIExpression(DW_OP_deref)), !dbg !16
75  ret void, !dbg !16
76}
77
78; Function Attrs: inlinehint nounwind uwtable
79define internal fastcc void @"_ZZ4testvENK3$_0clEv"(%class.anon* %this) unnamed_addr align 2 !dbg !21 {
80entry:
81  call void @llvm.dbg.value(metadata %class.anon* %this, metadata !34, metadata !DIExpression()), !dbg !36
82  %0 = getelementptr inbounds %class.anon, %class.anon* %this, i32 0, i32 1, !dbg !36
83  %1 = load i8*, i8** %0, align 8, !dbg !36
84  store i8 1, i8* %1, align 1, !dbg !36
85  ret void, !dbg !36
86}
87
88; Function Attrs: nounwind
89declare void @llvm.debugtrap()
90
91; Function Attrs: nounwind readnone speculatable
92declare void @llvm.dbg.value(metadata, metadata, metadata)
93
94!llvm.dbg.cu = !{!0}
95!llvm.module.flags = !{!3, !4, !5}
96!llvm.ident = !{!6}
97
98!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 8.0.1-4 (tags/RELEASE_801/final)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
99!1 = !DIFile(filename: "test.cc", directory: "/dir")
100!2 = !{}
101!3 = !{i32 2, !"Dwarf Version", i32 4}
102!4 = !{i32 2, !"Debug Info Version", i32 3}
103!5 = !{i32 1, !"wchar_size", i32 4}
104!6 = !{!"clang version 8.0.1-4 (tags/RELEASE_801/final)"}
105!7 = distinct !DISubprogram(name: "test", linkageName: "_Z4testv", scope: !8, file: !8, line: 1, type: !9, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
106!8 = !DIFile(filename: "test.cc", directory: "/dir")
107!9 = !DISubroutineType(types: !10)
108!10 = !{null}
109!11 = !{!12, !14, !15}
110!12 = !DILocalVariable(name: "a", scope: !7, file: !8, line: 2, type: !13)
111!13 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
112!14 = !DILocalVariable(name: "b", scope: !7, file: !8, line: 3, type: !13)
113!15 = !DILocalVariable(name: "c", scope: !7, file: !8, line: 4, type: !13)
114!16 = !DILocation(line: 2, scope: !7)
115!17 = !DILocation(line: 7, scope: !18)
116!18 = distinct !DILexicalBlock(scope: !7, file: !8, line: 7)
117!19 = !DILocation(line: 8, scope: !20)
118!20 = distinct !DILexicalBlock(scope: !18, file: !8, line: 7)
119!21 = distinct !DISubprogram(name: "operator()", linkageName: "_ZZ4testvENK3$_0clEv", scope: !22, file: !8, line: 5, type: !28, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, declaration: !32, retainedNodes: !33)
120!22 = distinct !DICompositeType(tag: DW_TAG_class_type, scope: !7, file: !8, line: 5, size: 192, flags: DIFlagTypePassByValue, elements: !23)
121!23 = !{!24, !26, !27}
122!24 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !22, file: !8, line: 5, baseType: !25, size: 64)
123!25 = !DIDerivedType(tag: DW_TAG_reference_type, baseType: !13, size: 64)
124!26 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !22, file: !8, line: 5, baseType: !25, size: 64, offset: 64)
125!27 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !22, file: !8, line: 5, baseType: !25, size: 64, offset: 128)
126!28 = !DISubroutineType(types: !29)
127!29 = !{null, !30}
128!30 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !31, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
129!31 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !22)
130!32 = !DISubprogram(name: "operator()", scope: !22, file: !8, line: 5, type: !28, scopeLine: 5, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized)
131!33 = !{!34}
132!34 = !DILocalVariable(name: "this", arg: 1, scope: !21, type: !35, flags: DIFlagArtificial | DIFlagObjectPointer)
133!35 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !31, size: 64)
134!36 = !DILocation(line: 0, scope: !21)
135