2
0

subprogram-linkonce-weak-odr.ll 7.6 KB

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