Skip to content
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

C++ error with no verbose output #433

Open
Martmists-GH opened this issue Dec 14, 2018 · 7 comments
Open

C++ error with no verbose output #433

Martmists-GH opened this issue Dec 14, 2018 · 7 comments
Labels

Comments

@Martmists-GH
Copy link

python3.7: /root/miniconda3/conda-bld/llvmdev_1531160641630/work/lib/Support/Error.cpp:116: void llvm::report_fatal_error(llvm::Error, bool): Assertion `Err && "report_fatal_error called with success value"' failed.

Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

Sadly due to lack of verbosity I have no clue what part of my code causes this.

@stuartarchibald
Copy link
Contributor

Thanks for the report. Do you have a reproducer ?

@Martmists-GH
Copy link
Author

I can give a zip of my entire code (around 1000 lines) if that works, it happens consistently.

@Martmists-GH
Copy link
Author

files.zip

Sorry for the delay, here's the files to make this work. Simply run core.py and it will happen.
Environment:
OS: Arch Linux x64
Python: 3.7.1
llvm: 7.0.1-1
llvmlite: 0.27.0

@Martmists-GH
Copy link
Author

@stuartarchibald any update on this?

@stuartarchibald
Copy link
Contributor

Think the IR generated is invalid. The entry block has no terminator.
e.g.

define i32 @"mul7126777023838580747"(i32 %"a", i32 %"b") 
{
entry:
  %".4" = alloca i32
  store i32 %"a", i32* %".4"
  %".6" = alloca i32
  store i32 %"b", i32* %".6"
  %"retval" = alloca i32
  ; there should be a terminator here!
exit:
  %".8" = load i32, i32* %"retval"
  ret i32 %".8"
}

then in the type_map.py's wrap_function nothing actually compiles the function_ir, something like this (straight from the examples http://llvmlite.pydata.org/en/latest/user-guide/binding/examples.html) should start you off:

def compile_ir(engine, llvm_ir):
    """
    Compile the LLVM IR string with the given engine.
    The compiled module object is returned.
    """
    # Create a LLVM module object from the IR
    import llvmlite.binding as llvm
    mod = llvm.parse_assembly(llvm_ir)
    mod.verify()
    # Now add the module and make sure it is ready for execution
    engine.add_module(mod)
    engine.finalize_object()
    engine.run_static_constructors()
    return mod

def wrap_function(func, engine):
    module = compile_ir(engine, str(func))
    args = func.type.pointee.args
    ret_type = func.type.pointee.return_type
    ret_ctype = wrap_type(ret_type)
    args_ctypes = map(wrap_type, args)

    functype = ctypes.CFUNCTYPE(ret_ctype, *args_ctypes)
    fptr = engine.get_function_address(func.name)

    cfunc = functype(fptr)
    cfunc.__name__ = func.name
    return cfunc

@Martmists-GH
Copy link
Author

Thank you, that makes the C++ error go away. I also see the issue you pointed out (which is now being reported as shown below), however I'm not sure how to fix it. I ported this code from llvmpy, which I believe used to handle exiting on its own. How would I fix this?

new error:

Traceback (most recent call last):
  File ".\core.py", line 145, in <module>
    print(f"10*20={mul(10, 20)}")
  File ".\core.py", line 66, in _wrapper
    pyfunc = wrap_module(argtys, llfunc)
  File "U:\Downloads\files\type_map.py", line 22, in wrap_module
    pfunc = wrap_function(llfunc, engine)
  File "U:\Downloads\files\type_map.py", line 43, in wrap_function
    module = compile_ir(engine, str(func))
  File "U:\Downloads\files\type_map.py", line 33, in compile_ir
    mod = llvm.parse_assembly(llvm_ir)
  File "U:\Downloads\Python\lib\site-packages\llvmlite\binding\module.py", line 26, in parse_assembly
    raise RuntimeError("LLVM IR parsing error\n{0}".format(errmsg))
RuntimeError: LLVM IR parsing error
<string>:9:1: error: expected instruction opcode
exit:
^

@stuartarchibald
Copy link
Contributor

No problem. At the end of the visit_Fun you need to branch to the next block. self.builder.branch(self.exit_block) just before self.end_function() would do it, but isn't general as the next block isn't always going to be the exit (unless your code always just has two blocks, entry and exit).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants