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

Fix crash on accessing function parameters #3

Open
sampsyo opened this issue Mar 19, 2017 · 6 comments
Open

Fix crash on accessing function parameters #3

sampsyo opened this issue Mar 19, 2017 · 6 comments

Comments

@sampsyo
Copy link
Collaborator

sampsyo commented Mar 19, 2017

We're currently hitting a segfault when trying to iterate over the arguments of a newly-constructed function. Here's a piece of the traceback, from LLDB:

 * frame #0: 0x0000000106116f88 libLLVM.dylib`llvm::LLVMContext::shouldDiscardValueNames() const + 4
   frame #1: 0x0000000106145b77 libLLVM.dylib`llvm::Value::setNameImpl(llvm::Twine const&) + 39
   frame #2: 0x0000000106145e0c libLLVM.dylib`llvm::Value::setName(llvm::Twine const&) + 14
   frame #3: 0x00000001060f5f7a libLLVM.dylib`llvm::Argument::Argument(llvm::Type*, llvm::Twine const&, llvm::Function*) + 110
   frame #4: 0x00000001060f702b libLLVM.dylib`llvm::Function::BuildLazyArguments() const + 105
   frame #5: 0x00000001060d9dd1 libLLVM.dylib`LLVMGetParam + 27
sampsyo added a commit that referenced this issue Mar 19, 2017
In an attempt to clarify the problem with #3.
@sampsyo
Copy link
Collaborator Author

sampsyo commented Mar 19, 2017

Hey @rhenwood39—in the above commit, I tried exploring your hypothesis that constructing the argument types for LLVMFunctionType was going wrong. I tried switching to ref-array to make sure we were constructing the array of pointers correctly, to no avail. 😢

@sampsyo
Copy link
Collaborator Author

sampsyo commented Mar 19, 2017

Wait a second! I actually had just not waited long enough for my tsc --watch to catch up. It works, for me at least!

Ready> def f(a b) a+b
Program: def f(a b) a+b

Read function definition:
; ModuleID = 'calculator_module'
source_filename = "calculator_module"

define float @f(float %a, float %b) {
entry:
  %addtmp = fadd float %a, %b
  ret float %addtmp
}



Ready>

🎉

@rhenwood39
Copy link
Contributor

Awesome!

@rhenwood39
Copy link
Contributor

It looks like it still complains when you actually try to call a function though. I'll take a look at that later.

@sampsyo
Copy link
Collaborator Author

sampsyo commented Mar 20, 2017

I suppose that makes sense—in this buildCall method here:

node-llvmc/src/wrapped.ts

Lines 100 to 102 in 0367634

buildCall(func: Function, args: Value[], name: string): Value {
return new Value(LLVM.LLVMBuildCall(func, args, args.length, name));
}

we'll need to use the same trick to build up a C array of pointers from the JavaScript array of objects. Maybe this stanza:

node-llvmc/src/wrapped.ts

Lines 240 to 246 in 0367634

// Construct an array containing the parameter references.
let paramtypes = new PointerArray(params.length);
let i = 0;
for (let param of params) {
paramtypes[i] = param.ref;
++i;
}

should be put into a helper function and reused there?

@rhenwood39
Copy link
Contributor

Got it working :)

I think we are going to have to go through llvm.ts eventually and convert the voidpp's, etc. to PointerArrays where appropriate. I think we have an issue open regarding that, so I'll make a follow-up note there.

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

No branches or pull requests

2 participants