subprogram-linkonce-weak.ll 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. ; RUN: llvm-link %s %S/Inputs/subprogram-linkonce-weak.ll -S -o %t1
  2. ; RUN: FileCheck %s -check-prefix=LW -check-prefix=CHECK <%t1
  3. ; RUN: llvm-link %S/Inputs/subprogram-linkonce-weak.ll %s -S -o %t2
  4. ; RUN: FileCheck %s -check-prefix=WL -check-prefix=CHECK <%t2
  5. ; This testcase tests the following flow:
  6. ; - File A defines a linkonce version of @foo which has inlined into @bar.
  7. ; - File B defines a weak version of @foo (different definition).
  8. ; - Linkage rules state File B version of @foo wins.
  9. ; - @bar still has inlined debug info related to the linkonce @foo.
  10. ;
  11. ; This should fix PR22792, although the testcase was hand-written. There's a
  12. ; RUN line with a crasher for llc at the end with checks for the DWARF output.
  13. ; The LW prefix means linkonce (this file) first, then weak (the other file).
  14. ; The WL prefix means weak (the other file) first, then linkonce (this file).
  15. ; We'll see @bar before @foo if this file is first.
  16. ; LW-LABEL: define i32 @bar(
  17. ; LW: %sum = add i32 %a, %b, !dbg ![[FOOINBAR:[0-9]+]]
  18. ; LW: ret i32 %sum, !dbg ![[BARRET:[0-9]+]]
  19. ; LW-LABEL: define weak i32 @foo(
  20. ; LW: %sum = call i32 @fastadd(i32 %a, i32 %b), !dbg ![[FOOCALL:[0-9]+]]
  21. ; LW: ret i32 %sum, !dbg ![[FOORET:[0-9]+]]
  22. ; We'll see @foo before @bar if this file is second.
  23. ; WL-LABEL: define weak i32 @foo(
  24. ; WL: %sum = call i32 @fastadd(i32 %a, i32 %b), !dbg ![[FOOCALL:[0-9]+]]
  25. ; WL: ret i32 %sum, !dbg ![[FOORET:[0-9]+]]
  26. ; WL-LABEL: define i32 @bar(
  27. ; WL: %sum = add i32 %a, %b, !dbg ![[FOOINBAR:[0-9]+]]
  28. ; WL: ret i32 %sum, !dbg ![[BARRET:[0-9]+]]
  29. define i32 @bar(i32 %a, i32 %b) {
  30. entry:
  31. %sum = add i32 %a, %b, !dbg !DILocation(line: 2, scope: !4,
  32. inlinedAt: !DILocation(line: 12, scope: !3))
  33. ret i32 %sum, !dbg !DILocation(line: 13, scope: !3)
  34. }
  35. define linkonce i32 @foo(i32 %a, i32 %b) {
  36. entry:
  37. %sum = add i32 %a, %b, !dbg !DILocation(line: 2, scope: !4)
  38. ret i32 %sum, !dbg !DILocation(line: 3, scope: !4)
  39. }
  40. !llvm.module.flags = !{!0}
  41. !0 = !{i32 2, !"Debug Info Version", i32 3}
  42. ; CHECK-LABEL: !llvm.dbg.cu =
  43. ; LW-SAME: !{![[LCU:[0-9]+]], ![[WCU:[0-9]+]]}
  44. ; WL-SAME: !{![[WCU:[0-9]+]], ![[LCU:[0-9]+]]}
  45. !llvm.dbg.cu = !{!1}
  46. ; LW: ![[LCU]] = !DICompileUnit({{.*}} subprograms: ![[LSPs:[0-9]+]]
  47. ; LW: ![[LSPs]] = !{![[BARSP:[0-9]+]], ![[FOOSP:[0-9]+]]}
  48. ; LW: ![[BARSP]] = !DISubprogram(name: "bar",
  49. ; LW-SAME: function: i32 (i32, i32)* @bar
  50. ; LW: ![[FOOSP]] = {{.*}}!DISubprogram(name: "foo",
  51. ; LW-NOT: function:
  52. ; LW-SAME: ){{$}}
  53. ; LW: ![[WCU]] = !DICompileUnit({{.*}} subprograms: ![[WSPs:[0-9]+]]
  54. ; LW: ![[WSPs]] = !{![[WEAKFOOSP:[0-9]+]]}
  55. ; LW: ![[WEAKFOOSP]] = !DISubprogram(name: "foo",
  56. ; LW-SAME: function: i32 (i32, i32)* @foo
  57. ; LW: ![[FOOINBAR]] = !DILocation(line: 2, scope: ![[FOOSP]], inlinedAt: ![[BARIA:[0-9]+]])
  58. ; LW: ![[BARIA]] = !DILocation(line: 12, scope: ![[BARSP]])
  59. ; LW: ![[BARRET]] = !DILocation(line: 13, scope: ![[BARSP]])
  60. ; LW: ![[FOOCALL]] = !DILocation(line: 52, scope: ![[WEAKFOOSP]])
  61. ; LW: ![[FOORET]] = !DILocation(line: 53, scope: ![[WEAKFOOSP]])
  62. ; Same as above, but reordered.
  63. ; WL: ![[WCU]] = !DICompileUnit({{.*}} subprograms: ![[WSPs:[0-9]+]]
  64. ; WL: ![[WSPs]] = !{![[WEAKFOOSP:[0-9]+]]}
  65. ; WL: ![[WEAKFOOSP]] = !DISubprogram(name: "foo",
  66. ; WL-SAME: function: i32 (i32, i32)* @foo
  67. ; WL: ![[LCU]] = !DICompileUnit({{.*}} subprograms: ![[LSPs:[0-9]+]]
  68. ; WL: ![[LSPs]] = !{![[BARSP:[0-9]+]], ![[FOOSP:[0-9]+]]}
  69. ; WL: ![[BARSP]] = !DISubprogram(name: "bar",
  70. ; WL-SAME: function: i32 (i32, i32)* @bar
  71. ; WL: ![[FOOSP]] = {{.*}}!DISubprogram(name: "foo",
  72. ; Note, for symmetry, this should be "NOT: function:" and "SAME: ){{$}}".
  73. ; WL-SAME: function: i32 (i32, i32)* @foo
  74. ; WL: ![[FOOCALL]] = !DILocation(line: 52, scope: ![[WEAKFOOSP]])
  75. ; WL: ![[FOORET]] = !DILocation(line: 53, scope: ![[WEAKFOOSP]])
  76. ; WL: ![[FOOINBAR]] = !DILocation(line: 2, scope: ![[FOOSP]], inlinedAt: ![[BARIA:[0-9]+]])
  77. ; WL: ![[BARIA]] = !DILocation(line: 12, scope: ![[BARSP]])
  78. ; WL: ![[BARRET]] = !DILocation(line: 13, scope: ![[BARSP]])
  79. !1 = !DICompileUnit(language: DW_LANG_C99, file: !2, subprograms: !{!3, !4}, emissionKind: 1)
  80. !2 = !DIFile(filename: "bar.c", directory: "/path/to/dir")
  81. !3 = !DISubprogram(file: !2, scope: !2, line: 11, name: "bar", function: i32 (i32, i32)* @bar, type: !5)
  82. !4 = !DISubprogram(file: !2, scope: !2, line: 1, name: "foo", function: i32 (i32, i32)* @foo, type: !5)
  83. !5 = !DISubroutineType(types: !{})
  84. ; Crasher for llc.
  85. ; REQUIRES: object-emission
  86. ; RUN: %llc_dwarf -filetype=obj -O0 %t1 -o %t1.o
  87. ; RUN: llvm-dwarfdump %t1.o -debug-dump=all | FileCheck %s -check-prefix=DWLW -check-prefix=DW
  88. ; RUN: %llc_dwarf -filetype=obj -O0 %t2 -o %t2.o
  89. ; RUN: llvm-dwarfdump %t2.o -debug-dump=all | FileCheck %s -check-prefix=DWWL -check-prefix=DW
  90. ; Check that the debug info for the discarded linkonce version of @foo doesn't
  91. ; reference any code, and that the other subprograms look correct.
  92. ; DW-LABEL: .debug_info contents:
  93. ; DWLW: DW_TAG_compile_unit
  94. ; DWLW: DW_AT_name {{.*}}"bar.c"
  95. ; DWLW: DW_TAG_subprogram
  96. ; DWLW-NOT: DW_AT_low_pc
  97. ; DWLW-NOT: DW_AT_high_pc
  98. ; DWLW: DW_AT_name {{.*}}foo
  99. ; DWLW: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
  100. ; DWLW: DW_AT_decl_line {{.*}}(1)
  101. ; DWLW: DW_TAG_subprogram
  102. ; DWLW: DW_AT_low_pc
  103. ; DWLW: DW_AT_high_pc
  104. ; DWLW: DW_AT_name {{.*}}bar
  105. ; DWLW: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
  106. ; DWLW: DW_AT_decl_line {{.*}}(11)
  107. ; DWLW: DW_TAG_inlined_subroutine
  108. ; DWLW: DW_AT_abstract_origin
  109. ; DWLW: DW_TAG_compile_unit
  110. ; DWLW: DW_AT_name {{.*}}"foo.c"
  111. ; DWLW: DW_TAG_subprogram
  112. ; DWLW: DW_AT_low_pc
  113. ; DWLW: DW_AT_high_pc
  114. ; DWLW: DW_AT_name {{.*}}foo
  115. ; DWLW: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}foo.c"
  116. ; DWLW: DW_AT_decl_line {{.*}}(51)
  117. ; The DWARF output is already symmetric (just reordered).
  118. ; DWWL: DW_TAG_compile_unit
  119. ; DWWL: DW_AT_name {{.*}}"foo.c"
  120. ; DWWL: DW_TAG_subprogram
  121. ; DWWL: DW_AT_low_pc
  122. ; DWWL: DW_AT_high_pc
  123. ; DWWL: DW_AT_name {{.*}}foo
  124. ; DWWL: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}foo.c"
  125. ; DWWL: DW_AT_decl_line {{.*}}(51)
  126. ; DWWL: DW_TAG_compile_unit
  127. ; DWWL: DW_AT_name {{.*}}"bar.c"
  128. ; DWWL: DW_TAG_subprogram
  129. ; DWWL-NOT: DW_AT_low_pc
  130. ; DWWL-NOT: DW_AT_high_pc
  131. ; DWWL: DW_AT_name {{.*}}foo
  132. ; DWWL: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
  133. ; DWWL: DW_AT_decl_line {{.*}}(1)
  134. ; DWWL: DW_TAG_subprogram
  135. ; DWWL: DW_AT_low_pc
  136. ; DWWL: DW_AT_high_pc
  137. ; DWWL: DW_AT_name {{.*}}bar
  138. ; DWWL: DW_AT_decl_file {{.*}}"/path/to/dir{{/|\\}}bar.c"
  139. ; DWWL: DW_AT_decl_line {{.*}}(11)
  140. ; DWWL: DW_TAG_inlined_subroutine
  141. ; DWWL: DW_AT_abstract_origin
  142. ; DW-LABEL: .debug_line contents:
  143. ; Check that we have the right things in the line table as well.
  144. ; DWLW-LABEL: file_names[{{ *}}1]{{.*}} bar.c
  145. ; DWLW: 2 0 1 0 0 is_stmt prologue_end
  146. ; DWLW-LABEL: file_names[{{ *}}1]{{.*}} foo.c
  147. ; DWLW: 52 0 1 0 0 is_stmt prologue_end
  148. ; DWLW-NOT: prologue_end
  149. ; DWWL-LABEL: file_names[{{ *}}1]{{.*}} foo.c
  150. ; DWWL: 52 0 1 0 0 is_stmt prologue_end
  151. ; DWWL-LABEL: file_names[{{ *}}1]{{.*}} bar.c
  152. ; DWWL: 2 0 1 0 0 is_stmt prologue_end
  153. ; DWWL-NOT: prologue_end