dotnet / LLVMSharp

LLVM bindings for .NET Standard written in C# using ClangSharp
MIT License
844 stars 97 forks source link

std::bad_alloc + seg fault when creating function #202

Closed AnErrupTion closed 1 year ago

AnErrupTion commented 2 years ago

Hello!

I'm encountering a very weird error when using those bindings. If I create an empty module then dump it, it works fine:

using LLVMSharp.Interop;

var module = LLVMModuleRef.CreateWithName("Test");
module.Dump();

But as soon as I add a function like this, before dumping:

module.AddFunction("main", LLVMTypeRef.Void);

It crashes and seg faults like this:

; ModuleID = 'Test'
source_filename = "Test"
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc

Process finished with exit code 134.

I've never encountered this, and in fact, it only seems to happen with those bindings, as the llvm-sys Rust bindings work just fine. I've tried LLVMSharp 14 and 15 (having 14 on my system), but same issue.

I'm using Fedora 36 with LLVM 14.0.5, if that helps.

tannergooding commented 2 years ago

I'll try to take a look this weekend. Might end up having to debug into libLLVM to see what's failing on the native side.

AnErrupTion commented 2 years ago

@tannergooding Any news?

AnErrupTion commented 1 year ago

This issue still seems to occur, even on the JavaCPP bindings. However, I tried the C++ API and it works just fine. I'm not sure what could be the cause of this error...

AnErrupTion commented 1 year ago

Actually, it was my fault all along. I was using directly the void type instead of creating a function type...