Files
clang-p2996/llvm/test/CodeGen/WebAssembly/global-get.ll
Wouter van Oortmerssen 9647a6f719 [WebAssembly] Added initial type checker to MC Assembler
This to protect against non-sensical instruction sequences being assembled,
which would either cause asserts/crashes further down, or a Wasm module being output that doesn't validate.

Unlike a validator, this type checker is able to give type-errors as part of the parsing process, which makes the assembler much friendlier to be used by humans writing manual input.

Because the MC system is single pass (instructions aren't even stored in MC format, they are directly output) the type checker has to be single pass as well, which means that from now on .globaltype and .functype decls must come before their use. An extra pass is added to Codegen to collect information for this purpose, since AsmPrinter is normally single pass / streaming as well, and would otherwise generate this information on the fly.

A `-no-type-check` flag was added to llvm-mc (and any other tools that take asm input) that surpresses type errors, as a quick escape hatch for tests that were not intended to be type correct.

This is a first version of the type checker that ignores control flow, i.e. it checks that types are correct along the linear path, but not the branch path. This will still catch most errors. Branch checking could be added in the future.

Differential Revision: https://reviews.llvm.org/D104945
2021-07-09 14:07:25 -07:00

82 lines
2.4 KiB
LLVM

; RUN: llc < %s --mtriple=wasm32-unknown-unknown -asm-verbose=false | FileCheck %s
@i32_global = local_unnamed_addr addrspace(1) global i32 undef
@i64_global = local_unnamed_addr addrspace(1) global i64 undef
@f32_global = local_unnamed_addr addrspace(1) global float undef
@f64_global = local_unnamed_addr addrspace(1) global double undef
@i32_external_used = external addrspace(1) global i32
@i32_external_unused = external addrspace(1) global i32
define i32 @return_i32_global() {
; CHECK-LABEL: return_i32_global:
; CHECK-NEXT: functype return_i32_global () -> (i32)
; CHECK-NEXT: global.get i32_global
; CHECK-NEXT: end_function
%v = load i32, i32 addrspace(1)* @i32_global
ret i32 %v
}
define i64 @return_i64_global() {
; CHECK-LABEL: return_i64_global:
; CHECK-NEXT: functype return_i64_global () -> (i64)
; CHECK-NEXT: global.get i64_global
; CHECK-NEXT: end_function
%v = load i64, i64 addrspace(1)* @i64_global
ret i64 %v
}
define float @return_f32_global() {
; CHECK-LABEL: return_f32_global:
; CHECK-NEXT: functype return_f32_global () -> (f32)
; CHECK-NEXT: global.get f32_global
; CHECK-NEXT: end_function
%v = load float, float addrspace(1)* @f32_global
ret float %v
}
define double @return_f64_global() {
; CHECK-LABEL: return_f64_global:
; CHECK-NEXT: functype return_f64_global () -> (f64)
; CHECK-NEXT: global.get f64_global
; CHECK-NEXT: end_function
%v = load double, double addrspace(1)* @f64_global
ret double %v
}
define i32 @return_extern_i32_global() {
; CHECK-LABEL: return_extern_i32_global:
; CHECK-NEXT: functype return_extern_i32_global () -> (i32)
; CHECK-NEXT: global.get i32_external_used
; CHECK-NEXT: end_function
%v = load i32, i32 addrspace(1)* @i32_external_used
ret i32 %v
}
; CHECK: .globl i32_global
; CHECK: .globaltype i32_global, i32
; CHECK-LABEL: i32_global:
; CHECK: .globl i64_global
; CHECK: .globaltype i64_global, i64
; CHECK-LABEL: i64_global:
; CHECK: .globl f32_global
; CHECK: .globaltype f32_global, f32
; CHECK-LABEL: f32_global:
; CHECK: .globl f64_global
; CHECK: .globaltype f64_global, f64
; CHECK-LABEL: f64_global:
; FIXME: are we still expecting these to be emitted?
; CHECK-NOT: .global i32_external_used
; CHECK-NOT: .globaltype i32_external_used, i32
; CHECK-NOT: i32_external_used:
; CHECK-NOT: .global i32_external_unused
; CHECK-NOT: .globaltype i32_external_unused, i32
; CHECK-NOT: i32_external_unused: