1; RUN: llc < %s -asm-verbose=false -O2 | FileCheck %s 2; RUN: llc < %s -asm-verbose=false -mattr=+reference-types -O2 | FileCheck --check-prefix=REF %s 3; RUN: llc < %s -asm-verbose=false -O2 --filetype=obj | obj2yaml | FileCheck --check-prefix=YAML %s 4 5; This tests pointer features that may codegen differently in wasm64. 6 7target datalayout = "e-m:e-p:64:64-i64:64-n32:64-S128" 8target triple = "wasm64-unknown-unknown" 9 10define void @bar(i32 %n) { 11entry: 12 ret void 13} 14 15define void @foo(void (i32)* %fp) { 16entry: 17 call void %fp(i32 1) 18 ret void 19} 20 21define void @test() { 22entry: 23 call void @foo(void (i32)* @bar) 24 store void (i32)* @bar, void (i32)** @fptr 25 ret void 26} 27 28@fptr = global void (i32)* @bar 29 30; For simplicity (and compatibility with UB C/C++ code) we keep all types 31; of pointers the same size, so function pointers (which are 32-bit indices 32; in Wasm) are represented as 64-bit until called. 33 34; CHECK: .functype foo (i64) -> () 35; CHECK-NEXT: i32.const 1 36; CHECK-NEXT: local.get 0 37; CHECK-NEXT: i32.wrap_i64 38; CHECK-NEXT: call_indirect (i32) -> () 39; REF: call_indirect __indirect_function_table, (i32) -> () 40 41; CHECK: .functype test () -> () 42; CHECK-NEXT: i64.const bar 43; CHECK-NEXT: call foo 44 45 46; Check we're emitting a 64-bit relocs for the call_indirect, the 47; `i64.const bar` reference in code, and the global. 48 49; YAML: Memory: 50; YAML-NEXT: Flags: [ IS_64 ] 51; YAML-NEXT: Minimum: 0x1 52 53; YAML: - Type: CODE 54; YAML: - Type: R_WASM_TABLE_INDEX_SLEB64 55; YAML-NEXT: Index: 0 56; YAML-NEXT: Offset: 0x16 57; YAML: - Type: R_WASM_TABLE_INDEX_SLEB64 58; YAML-NEXT: Index: 0 59; YAML-NEXT: Offset: 0x29 60 61; YAML: - Type: DATA 62; YAML: - Type: R_WASM_TABLE_INDEX_I64 63; YAML-NEXT: Index: 0 64; YAML-NEXT: Offset: 0x6 65