Skip to content

[WebAssembly] Fix .functype directives in tests #108748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2024
Merged

Conversation

aheejin
Copy link
Member

@aheejin aheejin commented Sep 15, 2024

For defined functions, it appears .functype directive should be after the function label. Otherwise binary generation does not seem to work correctly. Also this fixes a case that the .functype directive's name is incorrect.

For defined functions, it appears `.functype` directive should be after
the function label. Otherwise binary generation does not seem to work
correctly. Also this fixes a case that the `.functype` directive's name
is incorrect.
@aheejin aheejin requested a review from dschuff September 15, 2024 10:31
@llvmbot llvmbot added backend:WebAssembly mc Machine (object) code labels Sep 15, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 15, 2024

@llvm/pr-subscribers-mc

@llvm/pr-subscribers-backend-webassembly

Author: Heejin Ahn (aheejin)

Changes

For defined functions, it appears .functype directive should be after the function label. Otherwise binary generation does not seem to work correctly. Also this fixes a case that the .functype directive's name is incorrect.


Full diff: https://github.com/llvm/llvm-project/pull/108748.diff

4 Files Affected:

  • (modified) llvm/test/MC/WebAssembly/eh-assembly.s (+3-2)
  • (modified) llvm/test/MC/WebAssembly/func-end-errors.s (+5-5)
  • (modified) llvm/test/MC/WebAssembly/funcref-from-table.s (+1-1)
  • (modified) llvm/test/MC/WebAssembly/type-checker-br.s (+1-1)
diff --git a/llvm/test/MC/WebAssembly/eh-assembly.s b/llvm/test/MC/WebAssembly/eh-assembly.s
index cd33d198f8d9f5..deba6cc683f035 100644
--- a/llvm/test/MC/WebAssembly/eh-assembly.s
+++ b/llvm/test/MC/WebAssembly/eh-assembly.s
@@ -4,10 +4,11 @@
 
   .tagtype  __cpp_exception i32
   .tagtype  __c_longjmp i32
-  .functype  eh_legacy_test () -> ()
   .functype  foo () -> ()
 
 eh_legacy_test:
+  .functype  eh_legacy_test () -> ()
+
   # try-catch with catch, catch_all, throw, and rethrow
   try
     i32.const 3
@@ -55,7 +56,7 @@ eh_legacy_test:
   end_function
 
 # CHECK-LABEL: eh_legacy_test:
-# CHECK-NEXT:    try
+# CHECK:         try
 # CHECK-NEXT:    i32.const       3
 # CHECK-NEXT:    throw           __cpp_exception
 # CHECK-NEXT:    catch           __cpp_exception
diff --git a/llvm/test/MC/WebAssembly/func-end-errors.s b/llvm/test/MC/WebAssembly/func-end-errors.s
index dda91654c83c93..42d581fbccaa43 100644
--- a/llvm/test/MC/WebAssembly/func-end-errors.s
+++ b/llvm/test/MC/WebAssembly/func-end-errors.s
@@ -4,14 +4,14 @@
 # assembly. This causes the parser to properly wrap up function info when there
 # is no other instructions present.
 
-.functype test0 () -> ()
 test0:
+  .functype test0 () -> ()
 
-.functype test1 () -> ()
-# CHECK: [[@LINE+1]]:1: error: Unmatched block construct(s) at function end: function
 test1:
+# CHECK: [[@LINE+1]]:{{.*}}: error: Unmatched block construct(s) at function end: function
+  .functype test1 () -> ()
   end_function
 
-.functype test2 () -> ()
 test2:
-# CHECK: [[@LINE+1]]:1: error: Unmatched block construct(s) at function end: function
+  .functype test2 () -> ()
+# CHECK: [[@LINE+1]]:{{.*}}: error: Unmatched block construct(s) at function end: function
diff --git a/llvm/test/MC/WebAssembly/funcref-from-table.s b/llvm/test/MC/WebAssembly/funcref-from-table.s
index 62c817c8b76bca..3b6e0102698c3a 100644
--- a/llvm/test/MC/WebAssembly/funcref-from-table.s
+++ b/llvm/test/MC/WebAssembly/funcref-from-table.s
@@ -6,7 +6,7 @@
 .globl obtain_funcref_from_table_index
 
 obtain_funcref_from_table_index:
-  .functype obtain_funcref_from_table_index(i32) -> (funcref)
+  .functype obtain_funcref_from_table_index (i32) -> (funcref)
   local.get 0
   table.get __indirect_function_table
   end_function
diff --git a/llvm/test/MC/WebAssembly/type-checker-br.s b/llvm/test/MC/WebAssembly/type-checker-br.s
index df3f88f9685e1a..859e9c52547336 100644
--- a/llvm/test/MC/WebAssembly/type-checker-br.s
+++ b/llvm/test/MC/WebAssembly/type-checker-br.s
@@ -16,7 +16,7 @@ br_block:
   end_function
 
 br_func:
-  .functype br_block () -> ()
+  .functype br_func () -> ()
   block i32
     br 1
     i32.const 1

@dschuff
Copy link
Member

dschuff commented Sep 16, 2024

Interesting that nobody noticed this, I guess in tests and for handwritten cases it's mostly used to test the asm system, and when generated it's just always after the symbol

@aheejin aheejin merged commit dbc5900 into llvm:main Sep 16, 2024
8 checks passed
@aheejin aheejin deleted the functype branch September 16, 2024 22:14
tmsri pushed a commit to tmsri/llvm-project that referenced this pull request Sep 19, 2024
For defined functions, it appears `.functype` directive should be after
the function label. Otherwise binary generation does not seem to work
correctly. Also this fixes a case that the `.functype` directive's name
is incorrect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:WebAssembly mc Machine (object) code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants