Skip to content

Compiling ANTLR with tinygo returning Function return type does not match operand type of return inst! #1887

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

Closed
jjeb opened this issue May 17, 2021 · 8 comments
Labels
bug Something isn't working

Comments

@jjeb
Copy link

jjeb commented May 17, 2021

Hi, I am trying to compile ANTLR4 using tinyGo, I am fully aware that there is some challenges so I am not really looking for a solution but to understand a little bit more about the error so I can try to figure it out:

▶ tinygo version
tinygo version 0.18.0 darwin/amd64 (using go version go1.16 and LLVM version 11.0.0)

github.com/tinygo-antlr  tinygo18_single_import ✗   
▶ tinygo build -o fe-test/public/main.wasm -target wasm main.go
Function return type does not match operand type of return inst!
  ret %"github.com/antlr/antlr4/runtime/Go/antlr.ATN.187"* %3, !dbg !27382
 %"github.com/antlr/antlr4/runtime/Go/antlr.ATN"*Function return type does not match operand type of return inst!
  ret %"github.com/antlr/antlr4/runtime/Go/antlr.ATN.187"* %5, !dbg !27382
 %"github.com/antlr/antlr4/runtime/Go/antlr.ATN"*Function return type does not match operand type of return inst!
  ret %"github.com/antlr/antlr4/runtime/Go/antlr.ATN.187"* %9, !dbg !27382
 %"github.com/antlr/antlr4/runtime/Go/antlr.ATN"*Function return type does not match operand type of return inst!
  ret %"github.com/antlr/antlr4/runtime/Go/antlr.ParserATNSimulator.206"* %3, !dbg !27311
 %"github.com/antlr/antlr4/runtime/Go/antlr.ParserATNSimulator"*Function return type does not match operand type of return inst!
  ret %"github.com/antlr/antlr4/runtime/Go/antlr.ParserATNSimulator.206"* %5, !dbg !27311
 %"github.com/antlr/antlr4/runtime/Go/antlr.ParserATNSimulator"*Function return type does not match operand type of return inst!
  ret %"github.com/antlr/antlr4/runtime/Go/antlr.ParserATNSimulator.206"* %9, !dbg !27311
 %"github.com/antlr/antlr4/runtime/Go/antlr.ParserATNSimulator"*Function return type does not match operand type of return inst!
  ret %"github.com/antlr/antlr4/runtime/Go/antlr.ParserATNSimulator.206"* %10, !dbg !27311
 %"github.com/antlr/antlr4/runtime/Go/antlr.ParserATNSimulator"*error: optimizations caused a verification failure

@aykevl
Copy link
Member

aykevl commented May 19, 2021

That certainly looks like a bug in TinyGo. Can you share a small code sample that reproduces this problem?

@jjeb
Copy link
Author

jjeb commented May 20, 2021

I created a repo with the minimum code to reproduce the issue, you can find it in here: https://github.com/jjeb/ql.

I did some digging and it seems like something on ANTLR does not compile on tinyGo, I am still not sure what is it.

Thank in advance.

@aykevl
Copy link
Member

aykevl commented May 20, 2021

Thank you! Now I can reproduce the issue.

aykevl added a commit that referenced this issue May 20, 2021
This fix is very similar to
#1768, but now for the return
type. It fixes the issue in
#1887.

Like #1768, I'm not sure how to test this as it is very specific to
certain renames that LLVM does and that don't seem very reproducable.
@aykevl
Copy link
Member

aykevl commented May 20, 2021

Here is a fix: #1898

@deadprogram
Copy link
Member

Hello @jjeb can you please check to see if this fix works for you. Thanks.

@deadprogram deadprogram added the bug Something isn't working label May 23, 2021
@jjeb
Copy link
Author

jjeb commented May 25, 2021

Hello @deadprogram / @aykevl

It does compiles but it does not work, I am getting and error in web console, when I tried to execute it:

panic: runtime error: nil pointer dereference
main.wasm:0x6505 Uncaught (in promise) RuntimeError: unreachable
    at runtime.runtimePanic (http://localhost:9000/tinygo/main.wasm:wasm-function[100]:0x6505)
    at runtime.nilPanic (http://localhost:9000/tinygo/main.wasm:wasm-function[28]:0x1b1d)
    at (github.com/antlr/antlr4/runtime/Go/antlr.TokenStream).LT (http://localhost:9000/tinygo/main.wasm:wasm-function[863]:0x545c6)
    at (*github.com/antlr/antlr4/runtime/Go/antlr.BaseParser).EnterRule (http://localhost:9000/tinygo/main.wasm:wasm-function[870]:0x55c41)
    at (*github.com/ql/parser.QlParser).Query (http://localhost:9000/tinygo/main.wasm:wasm-function[954]:0x5d660)
    at getCompletionItems (http://localhost:9000/tinygo/main.wasm:wasm-function[252]:0x1294f)
    at _start (http://localhost:9000/tinygo/main.wasm:wasm-function[249]:0x11cf4)
    at global.Go.run (http://localhost:9000/tinygo/wasm_exec.js:478:24)
    at Goinit (http://localhost:9000/tinygo/:11:12)
runtime.runtimePanic @ main.wasm:0x6505
runtime.nilPanic @ main.wasm:0x1b1d
(github.com/antlr/antlr4/runtime/Go/antlr.TokenStream).LT @ main.wasm:0x545c6
(*github.com/antlr/antlr4/runtime/Go/antlr.BaseParser).EnterRule @ main.wasm:0x55c41
(*github.com/ql/parser.QlParser).Query @ main.wasm:0x5d660
getCompletionItems @ main.wasm:0x1294f
_start @ main.wasm:0x11cf4
run @ wasm_exec.js:478
Goinit @ (index):11
async function (async)
Goinit @ (index):10
(anonymous) @ (index):13
favicon.ico:1 

I updated the repo-example so there is a consistent way to reproduce the issue and you can see the error.

The tinygo version after build from the branch with the fix is:

tinygo version 0.19.0-dev darwin/amd64 (using go version go1.16.3 and LLVM version 11.1.0)

Thank you

@bluezheng
Copy link

Hello,

I met the same problem.
Is there any update on this issue?

Thank you

dgryski pushed a commit to dgryski/tinygo that referenced this issue Oct 21, 2021
This fix is very similar to
tinygo-org#1768, but now for the return
type. It fixes the issue in
tinygo-org#1887.

Like tinygo-org#1768, I'm not sure how to test this as it is very specific to
certain renames that LLVM does and that don't seem very reproducable.
deadprogram pushed a commit that referenced this issue Oct 28, 2021
This fix is very similar to
#1768, but now for the return
type. It fixes the issue in
#1887.

Like #1768, I'm not sure how to test this as it is very specific to
certain renames that LLVM does and that don't seem very reproducable.
@deadprogram deadprogram added the next-release Will be part of next release label Oct 28, 2021
@deadprogram
Copy link
Member

I think the request was fulfilled in the new release, so closing. Please reopen if needed. Thanks!

@deadprogram deadprogram removed the next-release Will be part of next release label Nov 18, 2021
ardnew pushed a commit to ardnew/tinygo that referenced this issue Jun 21, 2022
This fix is very similar to
tinygo-org#1768, but now for the return
type. It fixes the issue in
tinygo-org#1887.

Like tinygo-org#1768, I'm not sure how to test this as it is very specific to
certain renames that LLVM does and that don't seem very reproducable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants