Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions clang/test/CodeGen/WebAssembly/wasm-externref-novec.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %clang -O2 --target=wasm32 -S -emit-llvm -mreference-types -o - %s | FileCheck %s

// Issue: https://github.com/llvm/llvm-project/issues/69894

__externref_t foo(void);
// CHECK: declare ptr addrspace(10) @foo()

void bar(__externref_t);
// CHECK: declare void @bar(ptr addrspace(10))

void test(int flag, __externref_t ref1, __externref_t ref2) {
if (flag) {
ref1 = foo();
ref2 = foo();
}
bar(ref1);
bar(ref2);
}
2 changes: 2 additions & 0 deletions llvm/include/llvm/IR/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ class Type {
}
static Type *getFloatingPointTy(LLVMContext &C, const fltSemantics &S);

static constexpr unsigned WasmExternrefAddressSpace = 10;
static constexpr unsigned WasmFuncrefAddressSpace = 20;
//===--------------------------------------------------------------------===//
// Convenience methods for getting pointer types.
//
Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/CodeGen/ValueTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,15 @@ MVT MVT::getVT(Type *Ty, bool HandleUnknown){
getVT(VTy->getElementType(), /*HandleUnknown=*/ false),
VTy->getElementCount());
}
case Type::PointerTyID: {
if (Ty->getPointerAddressSpace() == Type::WasmExternrefAddressSpace)
return MVT(MVT::externref);
if (Ty->getPointerAddressSpace() == Type::WasmFuncrefAddressSpace)
return MVT(MVT::funcref);
if (HandleUnknown)
return MVT(MVT::Other);
llvm_unreachable("Unknown pointer type!");
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/IR/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ IntegerType *Type::getIntNTy(LLVMContext &C, unsigned N) {

Type *Type::getWasm_ExternrefTy(LLVMContext &C) {
// opaque pointer in addrspace(10)
static PointerType *Ty = PointerType::get(C, 10);
static PointerType *Ty = PointerType::get(C, WasmExternrefAddressSpace);
return Ty;
}

Type *Type::getWasm_FuncrefTy(LLVMContext &C) {
// opaque pointer in addrspace(20)
static PointerType *Ty = PointerType::get(C, 20);
static PointerType *Ty = PointerType::get(C, WasmFuncrefAddressSpace);
return Ty;
}

Expand Down