1; RUN: opt -S -lowertypetests -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck --check-prefixes=CHECK,X64 %s
2; RUN: opt -S -lowertypetests -mtriple=wasm32-unknown-unknown < %s | FileCheck --check-prefixes=CHECK,WASM32 %s
3
4; Tests that we correctly handle external references, including the case where
5; all functions in a bitset are external references.
6
7; WASM32: private constant [0 x i8] zeroinitializer
8
9; WASM32: declare !type !{{[0-9]+}} !wasm.index !{{[0-9]+}} void @foo1()
10declare !type !0 void @foo1()
11; WASM32: declare !type !{{[0-9]+}} void @foo2()
12declare !type !1 void @foo2()
13
14; CHECK-LABEL: @bar
15define i1 @bar(i8* %ptr) {
16  ; CHECK: %[[ICMP:[0-9]+]] = icmp eq
17  ; CHECK: ret i1 %[[ICMP]]
18  %p = call i1 @llvm.type.test(i8* %ptr, metadata !"type1")
19  ret i1 %p
20}
21
22; CHECK-LABEL: @baz
23define i1 @baz(i8* %ptr) {
24  ; CHECK: ret i1 false
25  %p = call i1 @llvm.type.test(i8* %ptr, metadata !"type2")
26  ret i1 %p
27}
28
29; CHECK-LABEL: @addrtaken
30define void()* @addrtaken() {
31  ; X64: ret void ()* @[[JT:.*]]
32  ret void()* @foo1
33}
34
35declare i1 @llvm.type.test(i8* %ptr, metadata %bitset) nounwind readnone
36
37!0 = !{i64 0, !"type1"}
38!1 = !{i64 0, !"type2"}
39
40; X64: define private void @[[JT]]() #{{.*}} align {{.*}} {
41; X64:   call void asm sideeffect "jmp ${0:c}@plt\0Aint3\0Aint3\0Aint3\0A", "s"(void ()* @foo1)
42