1 ; RUN: opt -passes='require<profile-summary>,function(codegenprepare)' -S < %s | FileCheck %s
2 ; RUN: opt -passes='require<profile-summary>,function(codegenprepare)' -S < %s --try-experimental-debuginfo-iterators | FileCheck %s
4 ; The following target lines are needed for the test to exercise what it should.
5 ; Without these lines, CodeGenPrepare does not try to sink the bitcasts.
6 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "x86_64-pc-windows-msvc"
9 declare i32 @__CxxFrameHandler3(...)
14 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #2
16 ; CodeGenPrepare will want to sink these bitcasts, but it selects the catchpad
17 ; blocks as the place to which the bitcast should be sunk. Since catchpads
18 ; do not allow non-phi instructions before the terminator, this isn't possible.
21 define void @test(ptr %addr) personality ptr @__CxxFrameHandler3 {
23 %x = getelementptr i32, ptr %addr, i32 1
25 to label %invoke.cont unwind label %catch1
28 ; CHECK-NEXT: %y = getelementptr i32, ptr %addr, i32 2
30 %y = getelementptr i32, ptr %addr, i32 2
32 to label %done unwind label %catch2
38 %cs1 = catchswitch within none [label %handler1] unwind to caller
41 %cp1 = catchpad within %cs1 []
42 br label %catch.shared
44 ; CHECK-NEXT: catchpad within %cs1
47 %cs2 = catchswitch within none [label %handler2] unwind to caller
50 %cp2 = catchpad within %cs2 []
51 br label %catch.shared
53 ; CHECK: catchpad within %cs2
55 ; CHECK: catch.shared:
56 ; CHECK-NEXT: %p = phi ptr [ %x, %handler1 ], [ %y, %handler2 ]
58 %p = phi ptr [ %x, %handler1 ], [ %y, %handler2 ]
63 ; CodeGenPrepare will want to hoist these llvm.dbg.value calls to the phi, but
64 ; there is no insertion point in a catchpad block.
66 ; CHECK-LABEL: @test_dbg_value(
67 define void @test_dbg_value() personality ptr @__CxxFrameHandler3 {
71 invoke void @f() to label %next unwind label %catch.dispatch
73 invoke void @f() to label %ret unwind label %catch.dispatch
78 %p = phi ptr [%a, %entry], [%b, %next]
79 %cs1 = catchswitch within none [label %catch] unwind to caller
82 %cp1 = catchpad within %cs1 []
83 tail call void @llvm.dbg.value(metadata ptr %p, i64 0, metadata !11, metadata !13), !dbg !14
85 catchret from %cp1 to label %ret
87 ; CHECK: catch.dispatch:
89 ; CHECK-NEXT: catchswitch
90 ; CHECK-NOT: #dbg_value
93 ; CHECK-NEXT: catchpad
94 ; CHECK-NEXT: #dbg_value
98 !llvm.module.flags = !{!7, !8, !9}
101 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0 (trunk 254906) (llvm/trunk 254917)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: null)
102 !1 = !DIFile(filename: "t.c", directory: "D:\5Csrc\5Cllvm\5Cbuild")
103 !4 = distinct !DISubprogram(name: "test_dbg_value", scope: !1, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: !0, retainedNodes: null)
104 !5 = !DISubroutineType(types: !6)
106 !7 = !{i32 2, !"Dwarf Version", i32 4}
107 !8 = !{i32 2, !"Debug Info Version", i32 3}
108 !9 = !{i32 1, !"PIC Level", i32 2}
109 !10 = !{!"clang version 3.8.0 (trunk 254906) (llvm/trunk 254917)"}
110 !11 = !DILocalVariable(name: "p", scope: !4, file: !1, line: 2, type: !12)
111 !12 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
112 !13 = !DIExpression(DW_OP_deref)
113 !14 = !DILocation(line: 2, column: 8, scope: !4)
114 !15 = !DILocation(line: 3, column: 1, scope: !4)