llvm.org GIT mirror llvm / d55ce11
[WebAssembly] Fix CFI index to account for padding nullptr function The WebAssembly linker now creates a dummy function at index 0 to prevent miscomparisons with the NULL pointer, see https://github.com/WebAssembly/binaryen/pull/658. Thanks to pcc for pointing out this problem! Patch by Dominic Chen Differential Revision: https://reviews.llvm.org/D23137 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278073 91177308-0d34-0410-b5e6-96231b3b80d8 Derek Schuff 4 years ago
5 changed file(s) with 12 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
821821
822822 // Build consecutive monotonic integer ranges for each call target set
823823 DenseMap GlobalLayout;
824
824825 for (Function *F : Functions) {
825826 // Skip functions that are not address taken, to avoid bloating the table
826827 if (!F->hasAddressTaken())
10481049 LTT->Int64Ty = Type::getInt64Ty(M.getContext());
10491050 LTT->IntPtrTy = DL.getIntPtrType(M.getContext(), 0);
10501051 LTT->TypeTestCallSites.clear();
1051 LTT->IndirectIndex = 0;
1052 LTT->IndirectIndex = 1;
10521053 }
10531054
10541055 bool LowerTypeTests::runOnModule(Module &M) {
1313 }
1414
1515 ; CHECK-LABEL: f:
16 ; CHECK: .indidx 0
16 ; CHECK: .indidx 1
1717 define void @f() !type !0 {
1818 ret void
1919 }
2020
2121 ; CHECK-LABEL: g:
22 ; CHECK: .indidx 1
22 ; CHECK: .indidx 2
2323 define void @g() !type !1 {
2424 ret void
2525 }
3131
3232 define i1 @foo(i8* %p) {
3333 ; X64: icmp eq i64 {{.*}}, ptrtoint ([1 x <{ i8, i32, i8, i8, i8 }>]* @[[JT0]] to i64)
34 ; WASM32: icmp eq i64 {{.*}}, 0
34 ; WASM32: icmp eq i64 {{.*}}, 1
3535 %x = call i1 @llvm.type.test(i8* %p, metadata !"typeid1")
3636 ; X64: icmp eq i64 {{.*}}, ptrtoint ([1 x <{ i8, i32, i8, i8, i8 }>]* @[[JT1]] to i64)
37 ; WASM32: icmp eq i64 {{.*}}, 1
37 ; WASM32: icmp eq i64 {{.*}}, 2
3838 %y = call i1 @llvm.type.test(i8* %p, metadata !"typeid2")
3939 %z = add i1 %x, %y
4040 ret i1 %z
4141 }
4242
43 ; WASM32: ![[I0]] = !{i64 0}
44 ; WASM32: ![[I1]] = !{i64 1}
43 ; WASM32: ![[I0]] = !{i64 1}
44 ; WASM32: ![[I1]] = !{i64 2}
2121
2222 !0 = !{i64 0, !"void"}
2323 ; WASM-NOT: !{i64 0}
24 ; WASM-NOT: !{i64 1}
2929
3030 define i1 @foo(i8* %p) {
3131 ; X64: sub i64 {{.*}}, ptrtoint ([2 x <{ i8, i32, i8, i8, i8 }>]* @[[JT]] to i64)
32 ; WASM32: sub i64 {{.*}}, 0
32 ; WASM32: sub i64 {{.*}}, 1
3333 ; WASM32: icmp ult i64 {{.*}}, 2
3434 %x = call i1 @llvm.type.test(i8* %p, metadata !"typeid1")
3535 ret i1 %x
3636 }
3737
38 ; WASM32: ![[I0]] = !{i64 0}
39 ; WASM32: ![[I1]] = !{i64 1}
38 ; WASM32: ![[I0]] = !{i64 1}
39 ; WASM32: ![[I1]] = !{i64 2}