alloca-dbgdeclare.ll 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. ; RUN: opt -inline -S < %s | FileCheck %s
  2. ; struct A {
  3. ; int arg0;
  4. ; double arg1[2];
  5. ; } a, b;
  6. ;
  7. ; void fn3(A p1) {
  8. ; if (p1.arg0)
  9. ; a = p1;
  10. ; }
  11. ;
  12. ; void fn4() { fn3(b); }
  13. ;
  14. ; void fn5() {
  15. ; while (1)
  16. ; fn4();
  17. ; }
  18. ; ModuleID = 'test.cpp'
  19. target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
  20. target triple = "aarch64-apple-darwin"
  21. %struct.A = type { i32, [2 x double] }
  22. @a = global %struct.A zeroinitializer, align 8
  23. @b = global %struct.A zeroinitializer, align 8
  24. ; Function Attrs: nounwind
  25. declare void @_Z3fn31A(%struct.A* nocapture readonly %p1) #0
  26. ; Function Attrs: nounwind readnone
  27. declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
  28. ; Function Attrs: nounwind
  29. declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture readonly, i64, i32, i1) #2
  30. ; Function Attrs: nounwind
  31. define void @_Z3fn4v() #0 {
  32. entry:
  33. ; Test that the dbg.declare is moved together with the alloca.
  34. ; CHECK: define void @_Z3fn5v()
  35. ; CHECK-NEXT: entry:
  36. ; CHECK-NEXT: %agg.tmp.sroa.3.i = alloca [20 x i8], align 4
  37. ; CHECK-NEXT: call void @llvm.dbg.declare(metadata [20 x i8]* %agg.tmp.sroa.3.i,
  38. %agg.tmp.sroa.3 = alloca [20 x i8], align 4
  39. tail call void @llvm.dbg.declare(metadata [20 x i8]* %agg.tmp.sroa.3, metadata !46, metadata !48), !dbg !49
  40. %agg.tmp.sroa.0.0.copyload = load i32, i32* getelementptr inbounds (%struct.A, %struct.A* @b, i64 0, i32 0), align 8, !dbg !50
  41. tail call void @llvm.dbg.value(metadata i32 %agg.tmp.sroa.0.0.copyload, i64 0, metadata !46, metadata !51), !dbg !49
  42. %agg.tmp.sroa.3.0..sroa_idx = getelementptr inbounds [20 x i8], [20 x i8]* %agg.tmp.sroa.3, i64 0, i64 0, !dbg !50
  43. call void @llvm.memcpy.p0i8.p0i8.i64(i8* %agg.tmp.sroa.3.0..sroa_idx, i8* getelementptr (i8, i8* bitcast (%struct.A* @b to i8*), i64 4), i64 20, i32 4, i1 false), !dbg !50
  44. tail call void @llvm.dbg.declare(metadata %struct.A* undef, metadata !46, metadata !31) #2, !dbg !49
  45. %tobool.i = icmp eq i32 %agg.tmp.sroa.0.0.copyload, 0, !dbg !52
  46. br i1 %tobool.i, label %_Z3fn31A.exit, label %if.then.i, !dbg !53
  47. if.then.i: ; preds = %entry
  48. store i32 %agg.tmp.sroa.0.0.copyload, i32* getelementptr inbounds (%struct.A, %struct.A* @a, i64 0, i32 0), align 8, !dbg !54
  49. call void @llvm.memcpy.p0i8.p0i8.i64(i8* getelementptr (i8, i8* bitcast (%struct.A* @a to i8*), i64 4), i8* %agg.tmp.sroa.3.0..sroa_idx, i64 20, i32 4, i1 false), !dbg !54
  50. br label %_Z3fn31A.exit, !dbg !54
  51. _Z3fn31A.exit: ; preds = %entry, %if.then.i
  52. ret void, !dbg !50
  53. }
  54. ; Function Attrs: noreturn nounwind
  55. define void @_Z3fn5v() #3 {
  56. entry:
  57. br label %while.body, !dbg !55
  58. while.body: ; preds = %entry, %while.body
  59. call void @_Z3fn4v(), !dbg !56
  60. br label %while.body, !dbg !55
  61. }
  62. ; Function Attrs: nounwind readnone
  63. declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1
  64. attributes #0 = { nounwind }
  65. attributes #1 = { nounwind readnone }
  66. attributes #2 = { nounwind }
  67. attributes #3 = { noreturn nounwind }
  68. !llvm.dbg.cu = !{!0}
  69. !llvm.module.flags = !{!28, !29}
  70. !llvm.ident = !{!30}
  71. !0 = !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.7.0 (trunk 227480) (llvm/trunk 227517)", isOptimized: true, emissionKind: 1, file: !1, enums: !2, retainedTypes: !3, subprograms: !14, globals: !25, imports: !2)
  72. !1 = !DIFile(filename: "<stdin>", directory: "")
  73. !2 = !{}
  74. !3 = !{!4}
  75. !4 = !DICompositeType(tag: DW_TAG_structure_type, name: "A", line: 1, size: 192, align: 64, file: !5, elements: !6, identifier: "_ZTS1A")
  76. !5 = !DIFile(filename: "test.cpp", directory: "")
  77. !6 = !{!7, !9}
  78. !7 = !DIDerivedType(tag: DW_TAG_member, name: "arg0", line: 2, size: 32, align: 32, file: !5, scope: !"_ZTS1A", baseType: !8)
  79. !8 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
  80. !9 = !DIDerivedType(tag: DW_TAG_member, name: "arg1", line: 3, size: 128, align: 64, offset: 64, file: !5, scope: !"_ZTS1A", baseType: !10)
  81. !10 = !DICompositeType(tag: DW_TAG_array_type, size: 128, align: 64, baseType: !11, elements: !12)
  82. !11 = !DIBasicType(tag: DW_TAG_base_type, name: "double", size: 64, align: 64, encoding: DW_ATE_float)
  83. !12 = !{!13}
  84. !13 = !DISubrange(count: 2)
  85. !14 = !{!15, !21, !24}
  86. !15 = !DISubprogram(name: "fn3", linkageName: "_Z3fn31A", line: 6, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 6, file: !5, scope: !16, type: !17, function: void (%struct.A*)* @_Z3fn31A, variables: !19)
  87. !16 = !DIFile(filename: "test.cpp", directory: "")
  88. !17 = !DISubroutineType(types: !18)
  89. !18 = !{null, !"_ZTS1A"}
  90. !19 = !{!20}
  91. !20 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "p1", line: 6, arg: 1, scope: !15, file: !16, type: !"_ZTS1A")
  92. !21 = !DISubprogram(name: "fn4", linkageName: "_Z3fn4v", line: 11, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 11, file: !5, scope: !16, type: !22, function: void ()* @_Z3fn4v, variables: !2)
  93. !22 = !DISubroutineType(types: !23)
  94. !23 = !{null}
  95. !24 = !DISubprogram(name: "fn5", linkageName: "_Z3fn5v", line: 13, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 13, file: !5, scope: !16, type: !22, function: void ()* @_Z3fn5v, variables: !2)
  96. !25 = !{!26, !27}
  97. !26 = !DIGlobalVariable(name: "a", line: 4, isLocal: false, isDefinition: true, scope: null, file: !16, type: !"_ZTS1A", variable: %struct.A* @a)
  98. !27 = !DIGlobalVariable(name: "b", line: 4, isLocal: false, isDefinition: true, scope: null, file: !16, type: !"_ZTS1A", variable: %struct.A* @b)
  99. !28 = !{i32 2, !"Dwarf Version", i32 4}
  100. !29 = !{i32 2, !"Debug Info Version", i32 3}
  101. !30 = !{!"clang version 3.7.0 (trunk 227480) (llvm/trunk 227517)"}
  102. !31 = !DIExpression(DW_OP_deref)
  103. !32 = !DILocation(line: 6, scope: !15)
  104. !33 = !DILocation(line: 7, scope: !34)
  105. !34 = distinct !DILexicalBlock(line: 7, column: 0, file: !5, scope: !15)
  106. !35 = !{!36, !37, i64 0}
  107. !36 = !{!"_ZTS1A", !37, i64 0, !38, i64 8}
  108. !37 = !{!"int", !38, i64 0}
  109. !38 = !{!"omnipotent char", !39, i64 0}
  110. !39 = !{!"Simple C/C++ TBAA"}
  111. !40 = !DILocation(line: 7, scope: !15)
  112. !41 = !DILocation(line: 8, scope: !34)
  113. !42 = !{i64 0, i64 4, !43, i64 8, i64 16, !44}
  114. !43 = !{!37, !37, i64 0}
  115. !44 = !{!38, !38, i64 0}
  116. !45 = !DILocation(line: 9, scope: !15)
  117. !46 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "p1", line: 6, arg: 1, scope: !15, file: !16, type: !"_ZTS1A")
  118. !47 = distinct !DILocation(line: 11, scope: !21)
  119. !48 = !DIExpression(DW_OP_bit_piece, 32, 160)
  120. !49 = !DILocation(line: 6, scope: !15, inlinedAt: !47)
  121. !50 = !DILocation(line: 11, scope: !21)
  122. !51 = !DIExpression(DW_OP_bit_piece, 0, 32)
  123. !52 = !DILocation(line: 7, scope: !34, inlinedAt: !47)
  124. !53 = !DILocation(line: 7, scope: !15, inlinedAt: !47)
  125. !54 = !DILocation(line: 8, scope: !34, inlinedAt: !47)
  126. !55 = !DILocation(line: 14, scope: !24)
  127. !56 = !DILocation(line: 15, scope: !24)