[clang] [llvm] [WebAssembly] Mark externref as not being valid vector elements (PR #71069)

Paulo Matos via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 2 08:42:01 PDT 2023


https://github.com/pmatos created https://github.com/llvm/llvm-project/pull/71069

Fixes #69894 .

>From deb62d806b4bba983d771eb87c3188a3fc3d56d5 Mon Sep 17 00:00:00 2001
From: Paulo Matos <pmatos at igalia.com>
Date: Tue, 31 Oct 2023 09:01:25 +0100
Subject: [PATCH 1/2] [WebAssembly] Reftypes are not valid element types

---
 llvm/lib/IR/Type.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 006278d16484c1c..b1d0f12498c3244 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -682,8 +682,11 @@ VectorType *VectorType::get(Type *ElementType, ElementCount EC) {
 }
 
 bool VectorType::isValidElementType(Type *ElemTy) {
+  if(PointerType *PTy = dyn_cast<PointerType>(ElemTy))
+    return PTy->getAddressSpace() != 10 && PTy->getAddressSpace() != 20;
+
   return ElemTy->isIntegerTy() || ElemTy->isFloatingPointTy() ||
-         ElemTy->isPointerTy() || ElemTy->getTypeID() == TypedPointerTyID;
+         ElemTy->getTypeID() == TypedPointerTyID;
 }
 
 //===----------------------------------------------------------------------===//

>From d93ec3a6ba414483efd6126fc7a953228b5e4150 Mon Sep 17 00:00:00 2001
From: Paulo Matos <pmatos at igalia.com>
Date: Thu, 2 Nov 2023 16:40:38 +0100
Subject: [PATCH 2/2] Add test

---
 .../CodeGen/WebAssembly/wasm-externref-novec.c   | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
 create mode 100644 clang/test/CodeGen/WebAssembly/wasm-externref-novec.c

diff --git a/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c b/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c
new file mode 100644
index 000000000000000..45042e3970c9343
--- /dev/null
+++ b/clang/test/CodeGen/WebAssembly/wasm-externref-novec.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -O2 -triple wasm32-unknown-unknown-wasm -emit-llvm -o - %s | FileCheck %s
+
+// From issue 69894. Reftypes need to be marked as not valid as vector elements.
+__externref_t foo(void);
+void bar(__externref_t);
+
+void
+test(int flag, __externref_t ref1, __externref_t ref2)
+{
+  if (flag) {
+    ref1 = foo();
+    ref2 = foo();
+  }
+  bar(ref1);
+  bar(ref2);
+}
\ No newline at end of file



More information about the cfe-commits mailing list