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 <pma...@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 <pma...@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

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to