[clang] [llvm] Add __builtin_wasm_test_function_pointer_signature (PR #147076)
https://github.com/hoodmane updated
https://github.com/llvm/llvm-project/pull/147076
>From ba4e21486455fcee36e5521050562cd9be35e9b4 Mon Sep 17 00:00:00 2001
From: Hood Chatham
Date: Sat, 10 May 2025 22:01:09 -0400
Subject: [PATCH 1/9] [WebAssembly] Add ref.test_func handling to AsmParser
---
.../AsmParser/WebAssemblyAsmParser.cpp| 2 ++
.../lib/Target/WebAssembly/WebAssemblyInstrRef.td | 8
llvm/test/MC/WebAssembly/reference-types.s| 15 +++
3 files changed, 25 insertions(+)
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index 7ee6a3d8304be..3fad1710c30c4 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -668,6 +668,8 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser
{
if (parseFunctionTableOperand(&FunctionTable))
return true;
ExpectFuncType = true;
+} else if (Name == "ref.test_func") {
+ ExpectFuncType = true;
}
// Returns true if the next tokens are a catch clause
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
index 2654a09387fd4..8786d78c8e5af 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
@@ -36,6 +36,14 @@ multiclass REF_I {
Requires<[HasReferenceTypes]>;
}
+defm REF_TEST_FUNCREF :
+ I<(outs I32: $res),
+(ins TypeIndex:$type, FUNCREF: $ref),
+(outs),
+(ins TypeIndex:$type),
+[],
+"ref.test_func\t$type, $ref", "ref.test_func $type", 0xfb14>;
+
defm "" : REF_I;
defm "" : REF_I;
defm "" : REF_I;
diff --git a/llvm/test/MC/WebAssembly/reference-types.s
b/llvm/test/MC/WebAssembly/reference-types.s
index cfadede8295ef..8f3bca79bb68f 100644
--- a/llvm/test/MC/WebAssembly/reference-types.s
+++ b/llvm/test/MC/WebAssembly/reference-types.s
@@ -27,6 +27,21 @@ ref_null_test:
drop
end_function
+# CHECK-LABEL: ref_test_test:
+# CHECK: ref.null_func # encoding: [0xd0,0x70]
+# CHECK: ref.test () -> () # encoding:
[0xfb,0x14,0x80'A',0x80'A',0x80'A',0x80'A',A]
+# CHECK: # fixup A - offset: 2, value: .Ltypeindex0@TYPEINDEX, kind:
fixup_uleb128_i32
+# CHECK: ref.null_func # encoding: [0xd0,0x70]
+# CHECK: ref.test () -> (i32) # encoding:
[0xfb,0x14,0x80'A',0x80'A',0x80'A',0x80'A',A]
+# CHECK: # fixup A - offset: 2, value: .Ltypeindex1@TYPEINDEX, kind:
fixup_uleb128_i32
+ref_test_test:
+ .functype ref_test_test () -> (i32, i32)
+ ref.null_func
+ ref.test_func () -> ()
+ ref.null_func
+ ref.test_func () -> (i32)
+ end_function
+
# CHECK-LABEL: ref_sig_test_funcref:
# CHECK-NEXT: .functype ref_sig_test_funcref (funcref) -> (funcref)
ref_sig_test_funcref:
>From 6a4693a238723f78c9126071b0b0be2ae5481af9 Mon Sep 17 00:00:00 2001
From: Hood Chatham
Date: Mon, 12 May 2025 20:19:55 -0400
Subject: [PATCH 2/9] Rename to ref.test
---
.../lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp | 2 +-
llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td| 2 +-
llvm/test/MC/WebAssembly/reference-types.s| 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index 3fad1710c30c4..c1b3936c1dcec 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -668,7 +668,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser
{
if (parseFunctionTableOperand(&FunctionTable))
return true;
ExpectFuncType = true;
-} else if (Name == "ref.test_func") {
+} else if (Name == "ref.test") {
ExpectFuncType = true;
}
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
index 8786d78c8e5af..40b87a084c687 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
@@ -42,7 +42,7 @@ defm REF_TEST_FUNCREF :
(outs),
(ins TypeIndex:$type),
[],
-"ref.test_func\t$type, $ref", "ref.test_func $type", 0xfb14>;
+"ref.test\t$type, $ref", "ref.test $type", 0xfb14>;
defm "" : REF_I;
defm "" : REF_I;
diff --git a/llvm/test/MC/WebAssembly/reference-types.s
b/llvm/test/MC/WebAssembly/reference-types.s
index 8f3bca79bb68f..08aafb23969eb 100644
--- a/llvm/test/MC/WebAssembly/reference-types.s
+++ b/llvm/test/MC/WebAssembly/reference-types.s
@@ -37,9 +37,9 @@ ref_null_test:
ref_test_test:
.functype ref_test_test () -> (i32, i32)
ref.null_func
- ref.test_func () -> ()
+ ref.test () -> ()
ref.null_func
- ref.test_func () -> (i32)
+ ref.test () -> (i32)
end_function
# CHECK-LABEL: ref_sig_te
[clang] [llvm] Add __builtin_wasm_test_function_pointer_signature (PR #147076)
https://github.com/hoodmane updated
https://github.com/llvm/llvm-project/pull/147076
>From ba4e21486455fcee36e5521050562cd9be35e9b4 Mon Sep 17 00:00:00 2001
From: Hood Chatham
Date: Sat, 10 May 2025 22:01:09 -0400
Subject: [PATCH 1/8] [WebAssembly] Add ref.test_func handling to AsmParser
---
.../AsmParser/WebAssemblyAsmParser.cpp| 2 ++
.../lib/Target/WebAssembly/WebAssemblyInstrRef.td | 8
llvm/test/MC/WebAssembly/reference-types.s| 15 +++
3 files changed, 25 insertions(+)
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index 7ee6a3d8304be..3fad1710c30c4 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -668,6 +668,8 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser
{
if (parseFunctionTableOperand(&FunctionTable))
return true;
ExpectFuncType = true;
+} else if (Name == "ref.test_func") {
+ ExpectFuncType = true;
}
// Returns true if the next tokens are a catch clause
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
index 2654a09387fd4..8786d78c8e5af 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
@@ -36,6 +36,14 @@ multiclass REF_I {
Requires<[HasReferenceTypes]>;
}
+defm REF_TEST_FUNCREF :
+ I<(outs I32: $res),
+(ins TypeIndex:$type, FUNCREF: $ref),
+(outs),
+(ins TypeIndex:$type),
+[],
+"ref.test_func\t$type, $ref", "ref.test_func $type", 0xfb14>;
+
defm "" : REF_I;
defm "" : REF_I;
defm "" : REF_I;
diff --git a/llvm/test/MC/WebAssembly/reference-types.s
b/llvm/test/MC/WebAssembly/reference-types.s
index cfadede8295ef..8f3bca79bb68f 100644
--- a/llvm/test/MC/WebAssembly/reference-types.s
+++ b/llvm/test/MC/WebAssembly/reference-types.s
@@ -27,6 +27,21 @@ ref_null_test:
drop
end_function
+# CHECK-LABEL: ref_test_test:
+# CHECK: ref.null_func # encoding: [0xd0,0x70]
+# CHECK: ref.test () -> () # encoding:
[0xfb,0x14,0x80'A',0x80'A',0x80'A',0x80'A',A]
+# CHECK: # fixup A - offset: 2, value: .Ltypeindex0@TYPEINDEX, kind:
fixup_uleb128_i32
+# CHECK: ref.null_func # encoding: [0xd0,0x70]
+# CHECK: ref.test () -> (i32) # encoding:
[0xfb,0x14,0x80'A',0x80'A',0x80'A',0x80'A',A]
+# CHECK: # fixup A - offset: 2, value: .Ltypeindex1@TYPEINDEX, kind:
fixup_uleb128_i32
+ref_test_test:
+ .functype ref_test_test () -> (i32, i32)
+ ref.null_func
+ ref.test_func () -> ()
+ ref.null_func
+ ref.test_func () -> (i32)
+ end_function
+
# CHECK-LABEL: ref_sig_test_funcref:
# CHECK-NEXT: .functype ref_sig_test_funcref (funcref) -> (funcref)
ref_sig_test_funcref:
>From 6a4693a238723f78c9126071b0b0be2ae5481af9 Mon Sep 17 00:00:00 2001
From: Hood Chatham
Date: Mon, 12 May 2025 20:19:55 -0400
Subject: [PATCH 2/8] Rename to ref.test
---
.../lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp | 2 +-
llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td| 2 +-
llvm/test/MC/WebAssembly/reference-types.s| 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index 3fad1710c30c4..c1b3936c1dcec 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -668,7 +668,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser
{
if (parseFunctionTableOperand(&FunctionTable))
return true;
ExpectFuncType = true;
-} else if (Name == "ref.test_func") {
+} else if (Name == "ref.test") {
ExpectFuncType = true;
}
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
index 8786d78c8e5af..40b87a084c687 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
@@ -42,7 +42,7 @@ defm REF_TEST_FUNCREF :
(outs),
(ins TypeIndex:$type),
[],
-"ref.test_func\t$type, $ref", "ref.test_func $type", 0xfb14>;
+"ref.test\t$type, $ref", "ref.test $type", 0xfb14>;
defm "" : REF_I;
defm "" : REF_I;
diff --git a/llvm/test/MC/WebAssembly/reference-types.s
b/llvm/test/MC/WebAssembly/reference-types.s
index 8f3bca79bb68f..08aafb23969eb 100644
--- a/llvm/test/MC/WebAssembly/reference-types.s
+++ b/llvm/test/MC/WebAssembly/reference-types.s
@@ -37,9 +37,9 @@ ref_null_test:
ref_test_test:
.functype ref_test_test () -> (i32, i32)
ref.null_func
- ref.test_func () -> ()
+ ref.test () -> ()
ref.null_func
- ref.test_func () -> (i32)
+ ref.test () -> (i32)
end_function
# CHECK-LABEL: ref_sig_te
[clang] [llvm] Add __builtin_wasm_test_function_pointer_signature (PR #147076)
https://github.com/hoodmane updated
https://github.com/llvm/llvm-project/pull/147076
>From ba4e21486455fcee36e5521050562cd9be35e9b4 Mon Sep 17 00:00:00 2001
From: Hood Chatham
Date: Sat, 10 May 2025 22:01:09 -0400
Subject: [PATCH 1/7] [WebAssembly] Add ref.test_func handling to AsmParser
---
.../AsmParser/WebAssemblyAsmParser.cpp| 2 ++
.../lib/Target/WebAssembly/WebAssemblyInstrRef.td | 8
llvm/test/MC/WebAssembly/reference-types.s| 15 +++
3 files changed, 25 insertions(+)
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index 7ee6a3d8304be..3fad1710c30c4 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -668,6 +668,8 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser
{
if (parseFunctionTableOperand(&FunctionTable))
return true;
ExpectFuncType = true;
+} else if (Name == "ref.test_func") {
+ ExpectFuncType = true;
}
// Returns true if the next tokens are a catch clause
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
index 2654a09387fd4..8786d78c8e5af 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
@@ -36,6 +36,14 @@ multiclass REF_I {
Requires<[HasReferenceTypes]>;
}
+defm REF_TEST_FUNCREF :
+ I<(outs I32: $res),
+(ins TypeIndex:$type, FUNCREF: $ref),
+(outs),
+(ins TypeIndex:$type),
+[],
+"ref.test_func\t$type, $ref", "ref.test_func $type", 0xfb14>;
+
defm "" : REF_I;
defm "" : REF_I;
defm "" : REF_I;
diff --git a/llvm/test/MC/WebAssembly/reference-types.s
b/llvm/test/MC/WebAssembly/reference-types.s
index cfadede8295ef..8f3bca79bb68f 100644
--- a/llvm/test/MC/WebAssembly/reference-types.s
+++ b/llvm/test/MC/WebAssembly/reference-types.s
@@ -27,6 +27,21 @@ ref_null_test:
drop
end_function
+# CHECK-LABEL: ref_test_test:
+# CHECK: ref.null_func # encoding: [0xd0,0x70]
+# CHECK: ref.test () -> () # encoding:
[0xfb,0x14,0x80'A',0x80'A',0x80'A',0x80'A',A]
+# CHECK: # fixup A - offset: 2, value: .Ltypeindex0@TYPEINDEX, kind:
fixup_uleb128_i32
+# CHECK: ref.null_func # encoding: [0xd0,0x70]
+# CHECK: ref.test () -> (i32) # encoding:
[0xfb,0x14,0x80'A',0x80'A',0x80'A',0x80'A',A]
+# CHECK: # fixup A - offset: 2, value: .Ltypeindex1@TYPEINDEX, kind:
fixup_uleb128_i32
+ref_test_test:
+ .functype ref_test_test () -> (i32, i32)
+ ref.null_func
+ ref.test_func () -> ()
+ ref.null_func
+ ref.test_func () -> (i32)
+ end_function
+
# CHECK-LABEL: ref_sig_test_funcref:
# CHECK-NEXT: .functype ref_sig_test_funcref (funcref) -> (funcref)
ref_sig_test_funcref:
>From 6a4693a238723f78c9126071b0b0be2ae5481af9 Mon Sep 17 00:00:00 2001
From: Hood Chatham
Date: Mon, 12 May 2025 20:19:55 -0400
Subject: [PATCH 2/7] Rename to ref.test
---
.../lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp | 2 +-
llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td| 2 +-
llvm/test/MC/WebAssembly/reference-types.s| 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index 3fad1710c30c4..c1b3936c1dcec 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -668,7 +668,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser
{
if (parseFunctionTableOperand(&FunctionTable))
return true;
ExpectFuncType = true;
-} else if (Name == "ref.test_func") {
+} else if (Name == "ref.test") {
ExpectFuncType = true;
}
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
index 8786d78c8e5af..40b87a084c687 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
@@ -42,7 +42,7 @@ defm REF_TEST_FUNCREF :
(outs),
(ins TypeIndex:$type),
[],
-"ref.test_func\t$type, $ref", "ref.test_func $type", 0xfb14>;
+"ref.test\t$type, $ref", "ref.test $type", 0xfb14>;
defm "" : REF_I;
defm "" : REF_I;
diff --git a/llvm/test/MC/WebAssembly/reference-types.s
b/llvm/test/MC/WebAssembly/reference-types.s
index 8f3bca79bb68f..08aafb23969eb 100644
--- a/llvm/test/MC/WebAssembly/reference-types.s
+++ b/llvm/test/MC/WebAssembly/reference-types.s
@@ -37,9 +37,9 @@ ref_null_test:
ref_test_test:
.functype ref_test_test () -> (i32, i32)
ref.null_func
- ref.test_func () -> ()
+ ref.test () -> ()
ref.null_func
- ref.test_func () -> (i32)
+ ref.test () -> (i32)
end_function
# CHECK-LABEL: ref_sig_te
[clang] [llvm] Add __builtin_wasm_test_function_pointer_signature (PR #147076)
https://github.com/hoodmane updated
https://github.com/llvm/llvm-project/pull/147076
>From ba4e21486455fcee36e5521050562cd9be35e9b4 Mon Sep 17 00:00:00 2001
From: Hood Chatham
Date: Sat, 10 May 2025 22:01:09 -0400
Subject: [PATCH 1/6] [WebAssembly] Add ref.test_func handling to AsmParser
---
.../AsmParser/WebAssemblyAsmParser.cpp| 2 ++
.../lib/Target/WebAssembly/WebAssemblyInstrRef.td | 8
llvm/test/MC/WebAssembly/reference-types.s| 15 +++
3 files changed, 25 insertions(+)
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index 7ee6a3d8304be..3fad1710c30c4 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -668,6 +668,8 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser
{
if (parseFunctionTableOperand(&FunctionTable))
return true;
ExpectFuncType = true;
+} else if (Name == "ref.test_func") {
+ ExpectFuncType = true;
}
// Returns true if the next tokens are a catch clause
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
index 2654a09387fd4..8786d78c8e5af 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
@@ -36,6 +36,14 @@ multiclass REF_I {
Requires<[HasReferenceTypes]>;
}
+defm REF_TEST_FUNCREF :
+ I<(outs I32: $res),
+(ins TypeIndex:$type, FUNCREF: $ref),
+(outs),
+(ins TypeIndex:$type),
+[],
+"ref.test_func\t$type, $ref", "ref.test_func $type", 0xfb14>;
+
defm "" : REF_I;
defm "" : REF_I;
defm "" : REF_I;
diff --git a/llvm/test/MC/WebAssembly/reference-types.s
b/llvm/test/MC/WebAssembly/reference-types.s
index cfadede8295ef..8f3bca79bb68f 100644
--- a/llvm/test/MC/WebAssembly/reference-types.s
+++ b/llvm/test/MC/WebAssembly/reference-types.s
@@ -27,6 +27,21 @@ ref_null_test:
drop
end_function
+# CHECK-LABEL: ref_test_test:
+# CHECK: ref.null_func # encoding: [0xd0,0x70]
+# CHECK: ref.test () -> () # encoding:
[0xfb,0x14,0x80'A',0x80'A',0x80'A',0x80'A',A]
+# CHECK: # fixup A - offset: 2, value: .Ltypeindex0@TYPEINDEX, kind:
fixup_uleb128_i32
+# CHECK: ref.null_func # encoding: [0xd0,0x70]
+# CHECK: ref.test () -> (i32) # encoding:
[0xfb,0x14,0x80'A',0x80'A',0x80'A',0x80'A',A]
+# CHECK: # fixup A - offset: 2, value: .Ltypeindex1@TYPEINDEX, kind:
fixup_uleb128_i32
+ref_test_test:
+ .functype ref_test_test () -> (i32, i32)
+ ref.null_func
+ ref.test_func () -> ()
+ ref.null_func
+ ref.test_func () -> (i32)
+ end_function
+
# CHECK-LABEL: ref_sig_test_funcref:
# CHECK-NEXT: .functype ref_sig_test_funcref (funcref) -> (funcref)
ref_sig_test_funcref:
>From 6a4693a238723f78c9126071b0b0be2ae5481af9 Mon Sep 17 00:00:00 2001
From: Hood Chatham
Date: Mon, 12 May 2025 20:19:55 -0400
Subject: [PATCH 2/6] Rename to ref.test
---
.../lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp | 2 +-
llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td| 2 +-
llvm/test/MC/WebAssembly/reference-types.s| 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index 3fad1710c30c4..c1b3936c1dcec 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -668,7 +668,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser
{
if (parseFunctionTableOperand(&FunctionTable))
return true;
ExpectFuncType = true;
-} else if (Name == "ref.test_func") {
+} else if (Name == "ref.test") {
ExpectFuncType = true;
}
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
index 8786d78c8e5af..40b87a084c687 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
@@ -42,7 +42,7 @@ defm REF_TEST_FUNCREF :
(outs),
(ins TypeIndex:$type),
[],
-"ref.test_func\t$type, $ref", "ref.test_func $type", 0xfb14>;
+"ref.test\t$type, $ref", "ref.test $type", 0xfb14>;
defm "" : REF_I;
defm "" : REF_I;
diff --git a/llvm/test/MC/WebAssembly/reference-types.s
b/llvm/test/MC/WebAssembly/reference-types.s
index 8f3bca79bb68f..08aafb23969eb 100644
--- a/llvm/test/MC/WebAssembly/reference-types.s
+++ b/llvm/test/MC/WebAssembly/reference-types.s
@@ -37,9 +37,9 @@ ref_null_test:
ref_test_test:
.functype ref_test_test () -> (i32, i32)
ref.null_func
- ref.test_func () -> ()
+ ref.test () -> ()
ref.null_func
- ref.test_func () -> (i32)
+ ref.test () -> (i32)
end_function
# CHECK-LABEL: ref_sig_te
[clang] [llvm] Add __builtin_wasm_test_function_pointer_signature (PR #147076)
https://github.com/hoodmane updated
https://github.com/llvm/llvm-project/pull/147076
>From ba4e21486455fcee36e5521050562cd9be35e9b4 Mon Sep 17 00:00:00 2001
From: Hood Chatham
Date: Sat, 10 May 2025 22:01:09 -0400
Subject: [PATCH 1/5] [WebAssembly] Add ref.test_func handling to AsmParser
---
.../AsmParser/WebAssemblyAsmParser.cpp| 2 ++
.../lib/Target/WebAssembly/WebAssemblyInstrRef.td | 8
llvm/test/MC/WebAssembly/reference-types.s| 15 +++
3 files changed, 25 insertions(+)
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index 7ee6a3d8304be..3fad1710c30c4 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -668,6 +668,8 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser
{
if (parseFunctionTableOperand(&FunctionTable))
return true;
ExpectFuncType = true;
+} else if (Name == "ref.test_func") {
+ ExpectFuncType = true;
}
// Returns true if the next tokens are a catch clause
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
index 2654a09387fd4..8786d78c8e5af 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
@@ -36,6 +36,14 @@ multiclass REF_I {
Requires<[HasReferenceTypes]>;
}
+defm REF_TEST_FUNCREF :
+ I<(outs I32: $res),
+(ins TypeIndex:$type, FUNCREF: $ref),
+(outs),
+(ins TypeIndex:$type),
+[],
+"ref.test_func\t$type, $ref", "ref.test_func $type", 0xfb14>;
+
defm "" : REF_I;
defm "" : REF_I;
defm "" : REF_I;
diff --git a/llvm/test/MC/WebAssembly/reference-types.s
b/llvm/test/MC/WebAssembly/reference-types.s
index cfadede8295ef..8f3bca79bb68f 100644
--- a/llvm/test/MC/WebAssembly/reference-types.s
+++ b/llvm/test/MC/WebAssembly/reference-types.s
@@ -27,6 +27,21 @@ ref_null_test:
drop
end_function
+# CHECK-LABEL: ref_test_test:
+# CHECK: ref.null_func # encoding: [0xd0,0x70]
+# CHECK: ref.test () -> () # encoding:
[0xfb,0x14,0x80'A',0x80'A',0x80'A',0x80'A',A]
+# CHECK: # fixup A - offset: 2, value: .Ltypeindex0@TYPEINDEX, kind:
fixup_uleb128_i32
+# CHECK: ref.null_func # encoding: [0xd0,0x70]
+# CHECK: ref.test () -> (i32) # encoding:
[0xfb,0x14,0x80'A',0x80'A',0x80'A',0x80'A',A]
+# CHECK: # fixup A - offset: 2, value: .Ltypeindex1@TYPEINDEX, kind:
fixup_uleb128_i32
+ref_test_test:
+ .functype ref_test_test () -> (i32, i32)
+ ref.null_func
+ ref.test_func () -> ()
+ ref.null_func
+ ref.test_func () -> (i32)
+ end_function
+
# CHECK-LABEL: ref_sig_test_funcref:
# CHECK-NEXT: .functype ref_sig_test_funcref (funcref) -> (funcref)
ref_sig_test_funcref:
>From 6a4693a238723f78c9126071b0b0be2ae5481af9 Mon Sep 17 00:00:00 2001
From: Hood Chatham
Date: Mon, 12 May 2025 20:19:55 -0400
Subject: [PATCH 2/5] Rename to ref.test
---
.../lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp | 2 +-
llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td| 2 +-
llvm/test/MC/WebAssembly/reference-types.s| 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index 3fad1710c30c4..c1b3936c1dcec 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -668,7 +668,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser
{
if (parseFunctionTableOperand(&FunctionTable))
return true;
ExpectFuncType = true;
-} else if (Name == "ref.test_func") {
+} else if (Name == "ref.test") {
ExpectFuncType = true;
}
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
index 8786d78c8e5af..40b87a084c687 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
@@ -42,7 +42,7 @@ defm REF_TEST_FUNCREF :
(outs),
(ins TypeIndex:$type),
[],
-"ref.test_func\t$type, $ref", "ref.test_func $type", 0xfb14>;
+"ref.test\t$type, $ref", "ref.test $type", 0xfb14>;
defm "" : REF_I;
defm "" : REF_I;
diff --git a/llvm/test/MC/WebAssembly/reference-types.s
b/llvm/test/MC/WebAssembly/reference-types.s
index 8f3bca79bb68f..08aafb23969eb 100644
--- a/llvm/test/MC/WebAssembly/reference-types.s
+++ b/llvm/test/MC/WebAssembly/reference-types.s
@@ -37,9 +37,9 @@ ref_null_test:
ref_test_test:
.functype ref_test_test () -> (i32, i32)
ref.null_func
- ref.test_func () -> ()
+ ref.test () -> ()
ref.null_func
- ref.test_func () -> (i32)
+ ref.test () -> (i32)
end_function
# CHECK-LABEL: ref_sig_te
[clang] [llvm] Add __builtin_wasm_test_function_pointer_signature (PR #147076)
github-actions[bot] wrote:
:warning: undef deprecator found issues in your code. :warning:
You can test this locally with the following command:
``bash
git diff -U0 --pickaxe-regex -S
'([^a-zA-Z0-9#_-]undef[^a-zA-Z0-9_-]|UndefValue::get)' 'HEAD~1' HEAD
clang/include/clang/Sema/SemaWasm.h
clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp clang/lib/Sema/SemaWasm.cpp
llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
``
The following files introduce new uses of undef:
- clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
[Undef](https://llvm.org/docs/LangRef.html#undefined-values) is now deprecated
and should only be used in the rare cases where no replacement is possible. For
example, a load of uninitialized memory yields `undef`. You should use `poison`
values for placeholders instead.
In tests, avoid using `undef` and having tests that trigger undefined behavior.
If you need an operand with some unimportant value, you can add a new argument
to the function and use that instead.
For example, this is considered a bad practice:
```llvm
define void @fn() {
...
br i1 undef, ...
}
```
Please use the following instead:
```llvm
define void @fn(i1 %cond) {
...
br i1 %cond, ...
}
```
Please refer to the [Undefined Behavior
Manual](https://llvm.org/docs/UndefinedBehavior.html) for more information.
https://github.com/llvm/llvm-project/pull/147076
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] Add __builtin_wasm_test_function_pointer_signature (PR #147076)
llvmbot wrote:
@llvm/pr-subscribers-mc
Author: Hood Chatham (hoodmane)
Changes
This uses ref.test to check whether the function pointer's runtime type
matches its static type. If so, then calling it won't trap with "indirect
call signature mismatch". This would be very useful here:
https://github.com/python/cpython/blob/main/Python/emscripten_trampoline.c
and would allow us to fix function pointer mismatches on the WASI target
and the Emscripten target in a uniform way.
This is on top of #139642.
---
Patch is 22.49 KiB, truncated to 20.00 KiB below, full version:
https://github.com/llvm/llvm-project/pull/147076.diff
11 Files Affected:
- (modified) clang/include/clang/Basic/BuiltinsWebAssembly.def (+6)
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+6)
- (modified) clang/include/clang/Sema/SemaWasm.h (+1)
- (modified) clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp (+58)
- (modified) clang/lib/Sema/SemaWasm.cpp (+49)
- (modified) llvm/include/llvm/IR/IntrinsicsWebAssembly.td (+4)
- (modified) llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
(+2)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp (+114)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td (+13)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp (+75)
- (modified) llvm/test/MC/WebAssembly/reference-types.s (+15)
``diff
diff --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def
b/clang/include/clang/Basic/BuiltinsWebAssembly.def
index ab480369b3820..85c6ddc125169 100644
--- a/clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -198,6 +198,12 @@ TARGET_BUILTIN(__builtin_wasm_ref_null_extern, "i", "nct",
"reference-types")
// return type.
TARGET_BUILTIN(__builtin_wasm_ref_null_func, "i", "nct", "reference-types")
+// Check if the static type of a function pointer matches its static type. Used
+// to avoid "function signature mismatch" traps. Takes a function pointer, uses
+// table.get to look up the pointer in __indirect_function_table and then
+// ref.test to test the type.
+TARGET_BUILTIN(__builtin_wasm_test_function_pointer_signature, "i.", "nct",
"reference-types")
+
// Table builtins
TARGET_BUILTIN(__builtin_wasm_table_set, "viii", "t", "reference-types")
TARGET_BUILTIN(__builtin_wasm_table_get, "iii", "t", "reference-types")
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e5a7cdc14a737..2ec556ee64fe5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7460,6 +7460,8 @@ def err_typecheck_illegal_increment_decrement : Error<
"cannot %select{decrement|increment}1 value of type %0">;
def err_typecheck_expect_int : Error<
"used type %0 where integer is required">;
+def err_typecheck_expect_function_pointer
+: Error<"used type %0 where function pointer is required">;
def err_typecheck_expect_hlsl_resource : Error<
"used type %0 where __hlsl_resource_t is required">;
def err_typecheck_arithmetic_incomplete_or_sizeless_type : Error<
@@ -12995,6 +12997,10 @@ def err_wasm_builtin_arg_must_match_table_element_type
: Error <
"%ordinal0 argument must match the element type of the WebAssembly table in
the %ordinal1 argument">;
def err_wasm_builtin_arg_must_be_integer_type : Error <
"%ordinal0 argument must be an integer">;
+def err_wasm_builtin_test_fp_sig_cannot_include_reference_type
+: Error<"__builtin_wasm_test_function_pointer_signature not supported for "
+"function pointers with reference types in their "
+"%select{return|parameter}0 type">;
// OpenACC diagnostics.
def warn_acc_routine_unimplemented
diff --git a/clang/include/clang/Sema/SemaWasm.h
b/clang/include/clang/Sema/SemaWasm.h
index 8841fdff23035..f97b72ff58579 100644
--- a/clang/include/clang/Sema/SemaWasm.h
+++ b/clang/include/clang/Sema/SemaWasm.h
@@ -36,6 +36,7 @@ class SemaWasm : public SemaBase {
bool BuiltinWasmTableGrow(CallExpr *TheCall);
bool BuiltinWasmTableFill(CallExpr *TheCall);
bool BuiltinWasmTableCopy(CallExpr *TheCall);
+ bool BuiltinWasmTestFunctionPointerSignature(CallExpr *TheCall);
WebAssemblyImportNameAttr *
mergeImportNameAttr(Decl *D, const WebAssemblyImportNameAttr &AL);
diff --git a/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
b/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
index 698f43215a1be..18ac488d8628c 100644
--- a/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
@@ -12,7 +12,10 @@
#include "CGBuiltin.h"
#include "clang/Basic/TargetBuiltins.h"
+#include "llvm/ADT/APInt.h"
+#include "llvm/IR/Constants.h"
#include "llvm/IR/IntrinsicsWebAssembly.h"
+#include "llvm/Support/ErrorHandling.h"
using namespace clang;
using namespace CodeGen;
@@ -213,6 +216,61 @@ Value
*CodeGenFunction::EmitWebAs
[clang] [llvm] Add __builtin_wasm_test_function_pointer_signature (PR #147076)
llvmbot wrote:
@llvm/pr-subscribers-backend-webassembly
@llvm/pr-subscribers-clang-codegen
@llvm/pr-subscribers-clang
Author: Hood Chatham (hoodmane)
Changes
This uses ref.test to check whether the function pointer's runtime type
matches its static type. If so, then calling it won't trap with "indirect
call signature mismatch". This would be very useful here:
https://github.com/python/cpython/blob/main/Python/emscripten_trampoline.c
and would allow us to fix function pointer mismatches on the WASI target
and the Emscripten target in a uniform way.
This is on top of #139642.
---
Patch is 22.49 KiB, truncated to 20.00 KiB below, full version:
https://github.com/llvm/llvm-project/pull/147076.diff
11 Files Affected:
- (modified) clang/include/clang/Basic/BuiltinsWebAssembly.def (+6)
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+6)
- (modified) clang/include/clang/Sema/SemaWasm.h (+1)
- (modified) clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp (+58)
- (modified) clang/lib/Sema/SemaWasm.cpp (+49)
- (modified) llvm/include/llvm/IR/IntrinsicsWebAssembly.td (+4)
- (modified) llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
(+2)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp (+114)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td (+13)
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp (+75)
- (modified) llvm/test/MC/WebAssembly/reference-types.s (+15)
``diff
diff --git a/clang/include/clang/Basic/BuiltinsWebAssembly.def
b/clang/include/clang/Basic/BuiltinsWebAssembly.def
index ab480369b3820..85c6ddc125169 100644
--- a/clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ b/clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -198,6 +198,12 @@ TARGET_BUILTIN(__builtin_wasm_ref_null_extern, "i", "nct",
"reference-types")
// return type.
TARGET_BUILTIN(__builtin_wasm_ref_null_func, "i", "nct", "reference-types")
+// Check if the static type of a function pointer matches its static type. Used
+// to avoid "function signature mismatch" traps. Takes a function pointer, uses
+// table.get to look up the pointer in __indirect_function_table and then
+// ref.test to test the type.
+TARGET_BUILTIN(__builtin_wasm_test_function_pointer_signature, "i.", "nct",
"reference-types")
+
// Table builtins
TARGET_BUILTIN(__builtin_wasm_table_set, "viii", "t", "reference-types")
TARGET_BUILTIN(__builtin_wasm_table_get, "iii", "t", "reference-types")
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e5a7cdc14a737..2ec556ee64fe5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -7460,6 +7460,8 @@ def err_typecheck_illegal_increment_decrement : Error<
"cannot %select{decrement|increment}1 value of type %0">;
def err_typecheck_expect_int : Error<
"used type %0 where integer is required">;
+def err_typecheck_expect_function_pointer
+: Error<"used type %0 where function pointer is required">;
def err_typecheck_expect_hlsl_resource : Error<
"used type %0 where __hlsl_resource_t is required">;
def err_typecheck_arithmetic_incomplete_or_sizeless_type : Error<
@@ -12995,6 +12997,10 @@ def err_wasm_builtin_arg_must_match_table_element_type
: Error <
"%ordinal0 argument must match the element type of the WebAssembly table in
the %ordinal1 argument">;
def err_wasm_builtin_arg_must_be_integer_type : Error <
"%ordinal0 argument must be an integer">;
+def err_wasm_builtin_test_fp_sig_cannot_include_reference_type
+: Error<"__builtin_wasm_test_function_pointer_signature not supported for "
+"function pointers with reference types in their "
+"%select{return|parameter}0 type">;
// OpenACC diagnostics.
def warn_acc_routine_unimplemented
diff --git a/clang/include/clang/Sema/SemaWasm.h
b/clang/include/clang/Sema/SemaWasm.h
index 8841fdff23035..f97b72ff58579 100644
--- a/clang/include/clang/Sema/SemaWasm.h
+++ b/clang/include/clang/Sema/SemaWasm.h
@@ -36,6 +36,7 @@ class SemaWasm : public SemaBase {
bool BuiltinWasmTableGrow(CallExpr *TheCall);
bool BuiltinWasmTableFill(CallExpr *TheCall);
bool BuiltinWasmTableCopy(CallExpr *TheCall);
+ bool BuiltinWasmTestFunctionPointerSignature(CallExpr *TheCall);
WebAssemblyImportNameAttr *
mergeImportNameAttr(Decl *D, const WebAssemblyImportNameAttr &AL);
diff --git a/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
b/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
index 698f43215a1be..18ac488d8628c 100644
--- a/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
+++ b/clang/lib/CodeGen/TargetBuiltins/WebAssembly.cpp
@@ -12,7 +12,10 @@
#include "CGBuiltin.h"
#include "clang/Basic/TargetBuiltins.h"
+#include "llvm/ADT/APInt.h"
+#include "llvm/IR/Constants.h"
#include "llvm/IR/IntrinsicsWebAssembly.h"
+#include "llvm/Support/ErrorHandling.h"
using namespace clang;
u
[clang] [llvm] Add __builtin_wasm_test_function_pointer_signature (PR #147076)
https://github.com/hoodmane created
https://github.com/llvm/llvm-project/pull/147076
This uses ref.test to check whether the function pointer's runtime type
matches its static type. If so, then calling it won't trap with "indirect
call signature mismatch". This would be very useful here:
https://github.com/python/cpython/blob/main/Python/emscripten_trampoline.c
and would allow us to fix function pointer mismatches on the WASI target
and the Emscripten target in a uniform way.
This is on top of #139642.
>From ba4e21486455fcee36e5521050562cd9be35e9b4 Mon Sep 17 00:00:00 2001
From: Hood Chatham
Date: Sat, 10 May 2025 22:01:09 -0400
Subject: [PATCH 1/3] [WebAssembly] Add ref.test_func handling to AsmParser
---
.../AsmParser/WebAssemblyAsmParser.cpp| 2 ++
.../lib/Target/WebAssembly/WebAssemblyInstrRef.td | 8
llvm/test/MC/WebAssembly/reference-types.s| 15 +++
3 files changed, 25 insertions(+)
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index 7ee6a3d8304be..3fad1710c30c4 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -668,6 +668,8 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser
{
if (parseFunctionTableOperand(&FunctionTable))
return true;
ExpectFuncType = true;
+} else if (Name == "ref.test_func") {
+ ExpectFuncType = true;
}
// Returns true if the next tokens are a catch clause
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
index 2654a09387fd4..8786d78c8e5af 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
@@ -36,6 +36,14 @@ multiclass REF_I {
Requires<[HasReferenceTypes]>;
}
+defm REF_TEST_FUNCREF :
+ I<(outs I32: $res),
+(ins TypeIndex:$type, FUNCREF: $ref),
+(outs),
+(ins TypeIndex:$type),
+[],
+"ref.test_func\t$type, $ref", "ref.test_func $type", 0xfb14>;
+
defm "" : REF_I;
defm "" : REF_I;
defm "" : REF_I;
diff --git a/llvm/test/MC/WebAssembly/reference-types.s
b/llvm/test/MC/WebAssembly/reference-types.s
index cfadede8295ef..8f3bca79bb68f 100644
--- a/llvm/test/MC/WebAssembly/reference-types.s
+++ b/llvm/test/MC/WebAssembly/reference-types.s
@@ -27,6 +27,21 @@ ref_null_test:
drop
end_function
+# CHECK-LABEL: ref_test_test:
+# CHECK: ref.null_func # encoding: [0xd0,0x70]
+# CHECK: ref.test () -> () # encoding:
[0xfb,0x14,0x80'A',0x80'A',0x80'A',0x80'A',A]
+# CHECK: # fixup A - offset: 2, value: .Ltypeindex0@TYPEINDEX, kind:
fixup_uleb128_i32
+# CHECK: ref.null_func # encoding: [0xd0,0x70]
+# CHECK: ref.test () -> (i32) # encoding:
[0xfb,0x14,0x80'A',0x80'A',0x80'A',0x80'A',A]
+# CHECK: # fixup A - offset: 2, value: .Ltypeindex1@TYPEINDEX, kind:
fixup_uleb128_i32
+ref_test_test:
+ .functype ref_test_test () -> (i32, i32)
+ ref.null_func
+ ref.test_func () -> ()
+ ref.null_func
+ ref.test_func () -> (i32)
+ end_function
+
# CHECK-LABEL: ref_sig_test_funcref:
# CHECK-NEXT: .functype ref_sig_test_funcref (funcref) -> (funcref)
ref_sig_test_funcref:
>From 6a4693a238723f78c9126071b0b0be2ae5481af9 Mon Sep 17 00:00:00 2001
From: Hood Chatham
Date: Mon, 12 May 2025 20:19:55 -0400
Subject: [PATCH 2/3] Rename to ref.test
---
.../lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp | 2 +-
llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td| 2 +-
llvm/test/MC/WebAssembly/reference-types.s| 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index 3fad1710c30c4..c1b3936c1dcec 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -668,7 +668,7 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser
{
if (parseFunctionTableOperand(&FunctionTable))
return true;
ExpectFuncType = true;
-} else if (Name == "ref.test_func") {
+} else if (Name == "ref.test") {
ExpectFuncType = true;
}
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
index 8786d78c8e5af..40b87a084c687 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrRef.td
@@ -42,7 +42,7 @@ defm REF_TEST_FUNCREF :
(outs),
(ins TypeIndex:$type),
[],
-"ref.test_func\t$type, $ref", "ref.test_func $type", 0xfb14>;
+"ref.test\t$type, $ref", "ref.test $type", 0xfb14>;
defm "" : REF_I;
defm "" : REF_I;
diff --git a/llvm/test/MC/WebAssembly/reference-types.s
b/llvm/test/MC/WebAssembly/refe
