File: function-pointer64.ll

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (63 lines) | stat: -rw-r--r-- 1,732 bytes parent folder | download | duplicates (6)
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
; RUN: llc < %s -asm-verbose=false -O2 | FileCheck %s
; RUN: llc < %s -asm-verbose=false -mattr=+reference-types -O2 | FileCheck --check-prefix=REF %s
; RUN: llc < %s -asm-verbose=false -O2 --filetype=obj | obj2yaml | FileCheck --check-prefix=YAML %s

; This tests pointer features that may codegen differently in wasm64.

target triple = "wasm64-unknown-unknown"

define void @bar(i32 %n) {
entry:
  ret void
}

define void @foo(void (i32)* %fp) {
entry:
  call void %fp(i32 1)
  ret void
}

define void @test() {
entry:
  call void @foo(void (i32)* @bar)
  store void (i32)* @bar, void (i32)** @fptr
  ret void
}

@fptr = global void (i32)* @bar

; For simplicity (and compatibility with UB C/C++ code) we keep all types
; of pointers the same size, so function pointers (which are 32-bit indices
; in Wasm) are represented as 64-bit until called.

; CHECK:      .functype foo (i64) -> ()
; CHECK-NEXT: i32.const 1
; CHECK-NEXT: local.get 0
; CHECK-NEXT: i32.wrap_i64
; CHECK-NEXT: call_indirect (i32) -> ()
; REF:        call_indirect __indirect_function_table, (i32) -> ()

; CHECK:      .functype test () -> ()
; CHECK-NEXT: i64.const bar
; CHECK-NEXT: call foo


; Check we're emitting a 64-bit relocs for the call_indirect, the
; `i64.const bar` reference in code, and the global.

; YAML:      Memory:
; YAML-NEXT:   Flags:   [ IS_64 ]
; YAML-NEXT:   Minimum: 0x1

; YAML:      - Type:   CODE
; YAML:      - Type:   R_WASM_TABLE_INDEX_SLEB64
; YAML-NEXT:   Index:  0
; YAML-NEXT:   Offset: 0x16
; YAML:      - Type:   R_WASM_TABLE_INDEX_SLEB64
; YAML-NEXT:   Index:  0
; YAML-NEXT:   Offset: 0x29

; YAML:      - Type:   DATA
; YAML:      - Type:   R_WASM_TABLE_INDEX_I64
; YAML-NEXT:   Index:  0
; YAML-NEXT:   Offset: 0x6