1; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t %s
2; RUN: llvm-modextract -b -n 0 -o - %t | llvm-dis | FileCheck --check-prefix=M0 %s
3; RUN: llvm-modextract -b -n 1 -o - %t | llvm-dis | FileCheck --check-prefix=M1 %s
4
5; M0: @g = external constant [10 x i8*]{{$}}
6; M1: @g = constant [10 x i8*]
7@g = constant [10 x i8*] [
8  i8* bitcast (i64 (i8*)* @ok1 to i8*),
9  i8* bitcast (i64 (i8*, i64)* @ok2 to i8*),
10  i8* bitcast (void (i8*)* @wrongtype1 to i8*),
11  i8* bitcast (i128 (i8*)* @wrongtype2 to i8*),
12  i8* bitcast (i64 ()* @wrongtype3 to i8*),
13  i8* bitcast (i64 (i8*, i8*)* @wrongtype4 to i8*),
14  i8* bitcast (i64 (i8*, i128)* @wrongtype5 to i8*),
15  i8* bitcast (i64 (i8*)* @usesthis to i8*),
16  i8* bitcast (i8 (i8*)* @reads to i8*),
17  i8* bitcast (i8* (i8*, i8)* @attributedFunc to i8*)
18], !type !0
19
20; M0: define i64 @ok1
21; M1: define available_externally i64 @ok1
22define i64 @ok1(i8* %this) {
23  ret i64 42
24}
25
26; M0: define i64 @ok2
27; M1: define available_externally i64 @ok2
28define i64 @ok2(i8* %this, i64 %arg) {
29  %1 = tail call { i64, i1 } @llvm.sadd.with.overflow.i64(i64 %arg, i64 %arg)
30  ret i64 %arg
31}
32
33; M1: declare { i64, i1 } @llvm.sadd.with.overflow.i64(i64, i64)
34declare { i64, i1 } @llvm.sadd.with.overflow.i64(i64, i64)
35
36; M0: define void @wrongtype1
37; M1: declare void @wrongtype1()
38define void @wrongtype1(i8*) {
39  ret void
40}
41
42; M0: define i128 @wrongtype2
43; M1: declare void @wrongtype2()
44define i128 @wrongtype2(i8*) {
45  ret i128 0
46}
47
48; M0: define i64 @wrongtype3
49; M1: declare void @wrongtype3()
50define i64 @wrongtype3() {
51  ret i64 0
52}
53
54; M0: define i64 @wrongtype4
55; M1: declare void @wrongtype4()
56define i64 @wrongtype4(i8*, i8*) {
57  ret i64 0
58}
59
60; M0: define i64 @wrongtype5
61; M1: declare void @wrongtype5()
62define i64 @wrongtype5(i8*, i128) {
63  ret i64 0
64}
65
66; M0: define i64 @usesthis
67; M1: declare void @usesthis()
68define i64 @usesthis(i8* %this) {
69  %i = ptrtoint i8* %this to i64
70  ret i64 %i
71}
72
73; M0: define i8 @reads
74; M1: declare void @reads()
75define i8 @reads(i8* %this) {
76  %l = load i8, i8* %this
77  ret i8 %l
78}
79
80; Check function attributes are copied over splitted module
81; M0: declare dso_local noundef i8* @attributedFunc(i8* noalias, i8 zeroext) unnamed_addr #[[ATTR0:[0-9]+]]
82; M1: declare dso_local void @attributedFunc() unnamed_addr #[[ATTR1:[0-9]+]]
83declare dso_local noundef i8* @attributedFunc(i8* noalias, i8 zeroext) unnamed_addr alwaysinline willreturn
84; M0: attributes #[[ATTR0]] = { alwaysinline willreturn }
85; M1: attributes #[[ATTR1]] = { alwaysinline willreturn }
86
87!0 = !{i32 0, !"typeid"}
88