2014-12-18 02:05:33 +01:00
|
|
|
; RUN: llvm-link %s %S/Inputs/replaced-function-matches-first-subprogram.ll -S | FileCheck %s
|
|
|
|
|
|
|
|
; Generated from C++ source:
|
|
|
|
;
|
|
|
|
; // repro/t.h
|
|
|
|
; template <class T> struct Class {
|
|
|
|
; int foo() { return 0; }
|
|
|
|
; };
|
|
|
|
; // repro/d1/t1.cpp
|
|
|
|
; #include "t.h"
|
|
|
|
; int foo() { return Class<int>().foo(); }
|
|
|
|
; // repro/d2/t2.cpp
|
|
|
|
; #include "t.h"
|
|
|
|
; template struct Class<int>;
|
|
|
|
|
|
|
|
%struct.Class = type { i8 }
|
|
|
|
|
2015-11-05 23:03:56 +01:00
|
|
|
; CHECK: define i32 @_Z3foov(){{.*}} !dbg ![[SP1:[0-9]+]]
|
|
|
|
define i32 @_Z3foov() !dbg !4 {
|
2014-12-18 02:05:33 +01:00
|
|
|
entry:
|
|
|
|
%tmp = alloca %struct.Class, align 1
|
|
|
|
%call = call i32 @_ZN5ClassIiE3fooEv(%struct.Class* %tmp), !dbg !14
|
|
|
|
ret i32 %call, !dbg !14
|
|
|
|
}
|
|
|
|
|
2015-11-05 23:03:56 +01:00
|
|
|
; CHECK: define weak_odr i32 @_ZN5ClassIiE3fooEv(%struct.Class* %this){{.*}} !dbg ![[SP2:[0-9]+]] {
|
2014-12-18 02:05:33 +01:00
|
|
|
; CHECK-NOT: }
|
|
|
|
; CHECK: !dbg ![[LOC:[0-9]+]]
|
2015-11-05 23:03:56 +01:00
|
|
|
define linkonce_odr i32 @_ZN5ClassIiE3fooEv(%struct.Class* %this) align 2 !dbg !7 {
|
2014-12-18 02:05:33 +01:00
|
|
|
entry:
|
|
|
|
%this.addr = alloca %struct.Class*, align 8
|
|
|
|
store %struct.Class* %this, %struct.Class** %this.addr, align 8
|
2015-02-27 22:17:42 +01:00
|
|
|
%this1 = load %struct.Class*, %struct.Class** %this.addr
|
2014-12-18 02:05:33 +01:00
|
|
|
ret i32 0, !dbg !15
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK: !llvm.dbg.cu = !{![[CU1:[0-9]+]], ![[CU2:[0-9]+]]}
|
|
|
|
!llvm.dbg.cu = !{!0}
|
|
|
|
!llvm.module.flags = !{!10, !11, !12}
|
|
|
|
!llvm.ident = !{!13}
|
|
|
|
|
|
|
|
; Extract out the list of subprograms from each compile unit.
|
2015-08-03 19:26:41 +02:00
|
|
|
; CHECK-DAG: ![[CU1]] = distinct !DICompileUnit({{.*}} subprograms: ![[SPs1:[0-9]+]]
|
|
|
|
; CHECK-DAG: ![[CU2]] = distinct !DICompileUnit({{.*}} subprograms: ![[SPs2:[0-9]+]]
|
|
|
|
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.6.0 (trunk 224193) (llvm/trunk 224197)", isOptimized: false, emissionKind: 2, file: !1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2)
|
2015-04-29 18:38:44 +02:00
|
|
|
!1 = !DIFile(filename: "t1.cpp", directory: "/Users/dexonsmith/data/llvm/staging/test/Linker/repro/d1")
|
2014-12-18 02:05:33 +01:00
|
|
|
!2 = !{}
|
|
|
|
|
Reapply "Linker: Drop function pointers for overridden subprograms"
This reverts commit r233254, effectively reapplying r233164 (and its
successors), with an additional testcase for when subprograms match
exactly. This fixes PR22792 (again).
I'm using the same approach, but I've moved up the call to
`stripReplacedSubprograms()`. The function pointers need to be dropped
before mapping any metadata from the source module, or else this can
drop the function from new subprograms that have merged (via Metadata
uniquing) with the old ones. Dropping the pointers first prevents them
from merging.
**** The original commit message follows. ****
Linker: Drop function pointers for overridden subprograms
Instead of dropping subprograms that have been overridden, just set
their function pointers to `nullptr`. This is a minor adjustment to the
stop-gap fix for PR21910 committed in r224487, and fixes the crasher
from PR22792.
The problem that r224487 put a band-aid on: how do we find the canonical
subprogram for a `Function`? Since the backend currently relies on
`DebugInfoFinder` (which does a naive in-order traversal of compile
units and picks the first subprogram) for this, r224487 tried dropping
non-canonical subprograms.
Dropping subprograms fails because the backend *also* builds up a map
from subprogram to compile unit (`DwarfDebug::SPMap`) based on the
subprogram lists. A missing subprogram causes segfaults later when an
inlined reference (such as in this testcase) is created.
Instead, just drop the `Function` pointer to `nullptr`, which nicely
mirrors what happens when an already-inlined `Function` is optimized
out. We can't really be sure that it's the same definition anyway, as
the testcase demonstrates.
This still isn't completely satisfactory. Two flaws at least that I can
think of:
- I still haven't found a straightforward way to make this symmetric
in the IR. (Interestingly, the DWARF output is already symmetric,
and I've tested for that to be sure we don't regress.)
- Using `DebugInfoFinder` to find the canonical subprogram for a
function is kind of crazy. We should just attach metadata to the
function, like this:
define weak i32 @foo(i32, i32) !dbg !MDSubprogram(...) {
llvm-svn: 233302
2015-03-26 19:35:30 +01:00
|
|
|
; Extract out each compile unit's single subprogram. The replaced subprogram's
|
|
|
|
; function should drop to null in the first compile unit.
|
2015-11-05 23:03:56 +01:00
|
|
|
; CHECK-DAG: ![[SPs1]] = !{![[SP1]], ![[SP2r:[0-9]+]]}
|
|
|
|
; CHECK-DAG: ![[SPs2]] = !{![[SP2]]}
|
2014-12-18 02:05:33 +01:00
|
|
|
!3 = !{!4, !7}
|
2015-11-05 23:03:56 +01:00
|
|
|
!4 = distinct !DISubprogram(name: "foo", line: 2, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 2, file: !1, scope: !5, type: !6, variables: !2)
|
2015-04-29 18:38:44 +02:00
|
|
|
!5 = !DIFile(filename: "t1.cpp", directory: "/Users/dexonsmith/data/llvm/staging/test/Linker/repro/d1")
|
|
|
|
!6 = !DISubroutineType(types: !2)
|
2014-12-18 02:05:33 +01:00
|
|
|
|
2015-11-05 23:03:56 +01:00
|
|
|
; Extract out the file from the replaced subprogram.
|
|
|
|
; CHECK-DAG: ![[SP2]] = distinct !DISubprogram({{.*}} file: ![[FILE:[0-9]+]],
|
Reapply "Linker: Drop function pointers for overridden subprograms"
This reverts commit r233254, effectively reapplying r233164 (and its
successors), with an additional testcase for when subprograms match
exactly. This fixes PR22792 (again).
I'm using the same approach, but I've moved up the call to
`stripReplacedSubprograms()`. The function pointers need to be dropped
before mapping any metadata from the source module, or else this can
drop the function from new subprograms that have merged (via Metadata
uniquing) with the old ones. Dropping the pointers first prevents them
from merging.
**** The original commit message follows. ****
Linker: Drop function pointers for overridden subprograms
Instead of dropping subprograms that have been overridden, just set
their function pointers to `nullptr`. This is a minor adjustment to the
stop-gap fix for PR21910 committed in r224487, and fixes the crasher
from PR22792.
The problem that r224487 put a band-aid on: how do we find the canonical
subprogram for a `Function`? Since the backend currently relies on
`DebugInfoFinder` (which does a naive in-order traversal of compile
units and picks the first subprogram) for this, r224487 tried dropping
non-canonical subprograms.
Dropping subprograms fails because the backend *also* builds up a map
from subprogram to compile unit (`DwarfDebug::SPMap`) based on the
subprogram lists. A missing subprogram causes segfaults later when an
inlined reference (such as in this testcase) is created.
Instead, just drop the `Function` pointer to `nullptr`, which nicely
mirrors what happens when an already-inlined `Function` is optimized
out. We can't really be sure that it's the same definition anyway, as
the testcase demonstrates.
This still isn't completely satisfactory. Two flaws at least that I can
think of:
- I still haven't found a straightforward way to make this symmetric
in the IR. (Interestingly, the DWARF output is already symmetric,
and I've tested for that to be sure we don't regress.)
- Using `DebugInfoFinder` to find the canonical subprogram for a
function is kind of crazy. We should just attach metadata to the
function, like this:
define weak i32 @foo(i32, i32) !dbg !MDSubprogram(...) {
llvm-svn: 233302
2015-03-26 19:35:30 +01:00
|
|
|
|
|
|
|
; We can't use CHECK-NOT/CHECK-SAME with a CHECK-DAG, so rely on field order to
|
|
|
|
; prove that there's no function: here.
|
2015-04-29 18:38:44 +02:00
|
|
|
; CHECK-DAG: ![[SP2r]] = {{.*}}!DISubprogram({{.*}} isOptimized: false, variables:
|
2015-11-05 23:03:56 +01:00
|
|
|
!7 = distinct !DISubprogram(name: "foo", line: 2, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 2, file: !8, scope: !9, type: !6, variables: !2)
|
2014-12-18 02:05:33 +01:00
|
|
|
|
|
|
|
; The new subprogram should be pointing at the new directory.
|
2015-04-29 18:38:44 +02:00
|
|
|
; CHECK-DAG: ![[FILE]] = !DIFile(filename: "../t.h", directory: "/Users/dexonsmith/data/llvm/staging/test/Linker/repro/d2")
|
|
|
|
!8 = !DIFile(filename: "../t.h", directory: "/Users/dexonsmith/data/llvm/staging/test/Linker/repro/d1")
|
|
|
|
!9 = !DIFile(filename: "../t.h", directory: "/Users/dexonsmith/data/llvm/staging/test/Linker/repro/d1")
|
2014-12-18 02:05:33 +01:00
|
|
|
!10 = !{i32 2, !"Dwarf Version", i32 2}
|
2015-03-03 18:24:31 +01:00
|
|
|
!11 = !{i32 2, !"Debug Info Version", i32 3}
|
2014-12-18 02:05:33 +01:00
|
|
|
!12 = !{i32 1, !"PIC Level", i32 2}
|
|
|
|
!13 = !{!"clang version 3.6.0 (trunk 224193) (llvm/trunk 224197)"}
|
2015-04-29 18:38:44 +02:00
|
|
|
!14 = !DILocation(line: 2, column: 20, scope: !4)
|
2014-12-18 02:05:33 +01:00
|
|
|
|
|
|
|
; The same subprogram should be pointed to by inside the !dbg reference.
|
2015-04-29 18:38:44 +02:00
|
|
|
; CHECK: ![[LOC]] = !DILocation(line: 2, column: 15, scope: ![[SP2]])
|
|
|
|
!15 = !DILocation(line: 2, column: 15, scope: !7)
|