File: thinlto-split-unit-start-lib.ll

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (96 lines) | stat: -rw-r--r-- 3,904 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
; REQUIRES: x86
; RUN: rm -rf %t; split-file %s %t

;; Split-LTO bitcode files can have the same symbol (typeinfo) twice in the
;; symbol table: First undefined in the main file, then defined in the index
;; file.
;; When used in --start-lib / --end-lib, ld64.lld creates lazy symbols
;; for all non-undefined symbols in the bitcode file.
;; In vtable.o below, the typeinfo __ZTI1S is present once as undefined and
;; once as defined. The defined version is added as a added as a LazyObject
;; symbol.
;; When vtable.o gets loaded due to the __ZN1SC1Ev ref from vtable_use.o,
;; the first __ZTI1S (undefined) used to cause vtable.o to be extracted
;; a second time, which used to cause an assert.
;; See PR59162 for details.

; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t/vtable.o %t/vtable.ll
; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t/vtable_use.o %t/vtable_use.ll

; RUN: %lld -lc++ --start-lib %t/vtable.o --end-lib %t/vtable_use.o -o /dev/null

;; Bitcode files created by:
; % cat vtable.cc
; struct S {
;   S();
;   virtual void f();
; };
; S::S() {}
; void S::f() {}

; % cat vtable_use.cc
; struct S {
;   S();
;   virtual void f();
; };
; int main() { S s; }

; % clang -c vtable_use.cc vtable.cc -emit-llvm -S -fno-exceptions -arch x86_64 -mmacos-version-min=11 -O1

; ...and then manually adding `, !type !8, type !9` based on `clang -S -emit-llvm -flto=thin` output,
; because splitAndWriteThinLTOBitcode() in ThinLTOBitcodeWriter.cpp only splits bitcode
; if type annotations are present. While at it, also removed unnecessary metadata.
; (NB: The first comment creates vtable.ll while the latter generates vtable.s! vtable.s
; contains a few things opt complains about, so we can't use the output of that directly.)

;--- vtable.ll
; ModuleID = 'vtable.cc'
source_filename = "vtable.cc"
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx11.0.0"

@_ZTV1S = unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr @_ZTI1S, ptr @_ZN1S1fEv] }, align 8
@_ZTVN10__cxxabiv117__class_type_infoE = external global ptr
@_ZTS1S = constant [3 x i8] c"1S\00", align 1
@_ZTI1S = constant { ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i64 2), ptr @_ZTS1S }, align 8, !type !0, !type !1

; Function Attrs: mustprogress nofree norecurse nosync nounwind ssp willreturn memory(argmem: write) uwtable
define void @_ZN1SC2Ev(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %this) unnamed_addr align 2 {
entry:
  store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTV1S, i64 0, inrange i32 0, i64 2), ptr %this, align 8
  ret void
}

; Function Attrs: mustprogress nofree norecurse nosync nounwind ssp willreturn memory(argmem: write) uwtable
define void @_ZN1SC1Ev(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(8) %this) unnamed_addr align 2 {
entry:
  store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTV1S, i64 0, inrange i32 0, i64 2), ptr %this, align 8
  ret void
}

; Function Attrs: mustprogress nofree norecurse nosync nounwind ssp willreturn memory(none) uwtable
define void @_ZN1S1fEv(ptr nocapture nonnull align 8 %this) unnamed_addr align 2 {
entry:
  ret void
}

!0 = !{i64 16, !"_ZTS1S"}
!1 = !{i64 16, !"_ZTSM1SFvvE.virtual"}

;--- vtable_use.ll
; ModuleID = 'vtable_use.cc'
source_filename = "vtable_use.cc"
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx11.0.0"

%struct.S = type { ptr }

; Function Attrs: mustprogress noinline norecurse nounwind optnone ssp uwtable
define noundef i32 @main() {
entry:
  %s = alloca %struct.S, align 8
  call void @_ZN1SC1Ev(ptr noundef nonnull align 8 dereferenceable(8) %s)
  ret i32 0
}

declare void @_ZN1SC1Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr