-
Notifications
You must be signed in to change notification settings - Fork 3
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
Have a try at upgrading to LLVM 15 #11
base: master
Are you sure you want to change the base?
Conversation
Here is the valgrind backtrace i got:
|
Does your code work in LLVM 14? I'm getting curious segfaults from LLVMBuildGEP when I tried a test program, but I don't know if I'm doing something stupid. #include <llvm-c/Core.h>
#include <stddef.h>
int main()
{
LLVMContextRef ctx = LLVMGetGlobalContext();
// LLVMContextSetOpaquePointers(ctx, 0);
LLVMModuleRef m = LLVMModuleCreateWithNameInContext("mod", ctx);
LLVMTypeRef argtys[] = {
LLVMInt32Type(),
LLVMPointerType(LLVMPointerType(LLVMInt8Type(), 0), 0)
};
LLVMTypeRef fty = LLVMFunctionType(LLVMInt32Type(), argtys, 2, 0);
LLVMValueRef main = LLVMAddFunction(m, "main", fty);
LLVMBasicBlockRef bb = LLVMAppendBasicBlockInContext(ctx, main, "entry");
LLVMBuilderRef b = LLVMCreateBuilderInContext(ctx);
LLVMPositionBuilderAtEnd(b, bb);
LLVMValueRef indices[] = {
LLVMConstInt(LLVMInt32Type(), 0, 0),
LLVMConstInt(LLVMInt32Type(), 0, 0)
};
LLVMBuildGEP(b, LLVMGetParam(main, 1), indices, 2, "gep");
LLVMValueRef args[] = {
LLVMGetParam(main, 0),
LLVMGetParam(main, 1)
};
LLVMValueRef call = LLVMBuildCall(b, main, args, 2, "rec");
LLVMBuildRet(b, call);
LLVMDumpModule(m);
LLVMDisposeModule(m);
return 0;
} compiled with |
No, but for different reason: see #10 (I'm guessing it should work if we tried to backport your nnp patch to LLVM 14 but we'll never know) |
I read the getelementpointer documentation more closely, and I think I probably used it wrong. What I was doing, indexing twice into an #include <llvm-c/Core.h>
#include <stddef.h>
int main()
{
LLVMContextRef ctx = LLVMGetGlobalContext();
LLVMContextSetOpaquePointers(ctx, 0);
LLVMModuleRef m = LLVMModuleCreateWithNameInContext("mod", ctx);
LLVMTypeRef argtys[] = {
LLVMInt32Type(),
LLVMPointerType(LLVMPointerType(LLVMInt8Type(), 0), 0)
};
LLVMTypeRef fty = LLVMFunctionType(LLVMInt32Type(), argtys, 2, 0);
LLVMValueRef main = LLVMAddFunction(m, "main", fty);
LLVMBasicBlockRef bb = LLVMAppendBasicBlockInContext(ctx, main, "entry");
LLVMBuilderRef b = LLVMCreateBuilderInContext(ctx);
LLVMPositionBuilderAtEnd(b, bb);
LLVMValueRef indices[] = {
LLVMConstInt(LLVMInt32Type(), 0, 0)
};
LLVMBuildGEP(b, LLVMGetParam(main, 1), indices, 1, "gep");
LLVMValueRef args[] = {
LLVMGetParam(main, 0),
LLVMGetParam(main, 1)
};
LLVMValueRef call = LLVMBuildCall(b, main, args, 2, "rec");
LLVMBuildRet(b, call);
LLVMDumpModule(m);
LLVMDisposeModule(m);
return 0;
} compiled with |
Unless some expectations around GEP changed between LLVM 12 (where it definitely worked) and 15, i don't think this is the same kind of error |
Yeah, I can see your code is different than the likely incorrect thing I tried to do in my first test program. From what I can tell, you have a global called |
if i remember correctly, yes |
#include <llvm-c/Core.h>
#include <stddef.h>
int main()
{
LLVMContextRef ctx = LLVMGetGlobalContext();
LLVMContextSetOpaquePointers(ctx, 0);
LLVMModuleRef m = LLVMModuleCreateWithNameInContext("mod", ctx);
LLVMValueRef gcglob =
LLVMAddGlobal(m, LLVMPointerType(LLVMInt8Type(), 0), "gc");
LLVMValueRef offglob =
LLVMAddGlobal(m, LLVMInt32Type(), "offset");
LLVMTypeRef fty = LLVMFunctionType(LLVMInt32Type(), NULL, 0, 0);
LLVMValueRef main = LLVMAddFunction(m, "main", fty);
LLVMBasicBlockRef bb = LLVMAppendBasicBlockInContext(ctx, main, "entry");
LLVMBuilderRef b = LLVMCreateBuilderInContext(ctx);
LLVMPositionBuilderAtEnd(b, bb);
LLVMValueRef gc = LLVMBuildLoad(b, gcglob, "");
LLVMValueRef off = LLVMBuildLoad(b, offglob, "");
LLVMValueRef indices[] = { off };
LLVMBuildGEP(b, gc, indices, 1, "gep");
LLVMBuildRet(b, LLVMConstInt(LLVMInt32Type(), 0, 0));
LLVMDumpModule(m);
LLVMDisposeModule(m);
return 0;
} Does this test program (which works) represent what your code does? What are the steps you took to install my forked LLVM to opam and build and test this project? I want to investigate what is happening. |
I'm not sure but here is a close to minimal reproduction case using the OCaml binding:
the content of let c = Llvm.global_context ()
let () = Llvm.set_opaque_pointers c false
let m = Llvm.create_module c "_main_"
let i8 = Llvm.i8_type c
let i32 = Llvm.i32_type c
let star = Llvm.pointer_type i8
let gc_heap = Llvm.define_global "GC_heap" (Llvm.const_null star) m
let gc_heap_cursor = Llvm.define_global "GC_heap_cursor" (Llvm.const_int i32 0) m
let fill_gc_malloc builder =
let current_heap_cursor = Llvm.build_load gc_heap_cursor "" builder in
let (res, builder) =
let func = Llvm.block_parent (Llvm.insertion_block builder) in
let block = Llvm.append_block c "" func in
let builder = Llvm.builder_at_end c block in
let current_heap = Llvm.build_load gc_heap "" builder in
let _ = Llvm.build_gep current_heap [|current_heap_cursor|] "" builder in
assert false (* BOOM *)
in
Llvm.build_ret res builder
let () =
let f = Llvm.define_function "GC_malloc" (Llvm.function_type star [|i32|]) m in
let _ = fill_gc_malloc (Llvm.builder_at_end c (Llvm.entry_block f)) in
() Just do
Simply by doing the installation by hand (see opam file), from the source directory:
|
Trying alan-j-hu/llvm-dune#9 but it still segfaults.
@alan-j-hu What should i do? Is
Llvm.set_opaque_pointers
meant to be used another way?