Returning many times doesn't work quite well...

4 views
Skip to first unread message

Ary Manzana

unread,
Aug 21, 2011, 5:09:32 PM8/21/11
to ruby-llvm
Hi,

The following new test case fails:

======================================================
require "test_helper"

class ReturnTestCase < Test::Unit::TestCase
def test_two_returns
value = run_function([], [], LLVM::Int) do |builder, function,
*arguments|
entry = function.basic_blocks.append
builder.position_at_end(entry)
builder.ret LLVM::Int(1)
builder.ret LLVM::Int(2)
end
assert_equal 1, value.to_i
end
end
======================================================

It returns garbage. I tried compiling the code generated when you dump
the module and it works ok, so it must be a problem with the JIT...
but I have no idea how to fix it or why it's happening.

Cheers,
Ary

Jeremy Voorhis

unread,
Aug 21, 2011, 5:13:12 PM8/21/11
to ruby...@googlegroups.com
Interesting find. Can you submit a pull request with the failing test? I'll see what I can find.

Jeremy

Ary Borenszweig

unread,
Aug 21, 2011, 5:20:21 PM8/21/11
to ruby...@googlegroups.com
I wanted to make a pull request but I already have one. When going to the pull request page it also shows that it includes that second commit with the failing test. Maybe you never merged the other pull request?


In any case, here's the commits on my side:


(I just realized a commited a test with just one return... I was checking if it worked with one return and forgot to add the second return back :-()

Jeremy Voorhis

unread,
Aug 21, 2011, 9:37:06 PM8/21/11
to ruby...@googlegroups.com
I just accepted your previous pull, minus the return test. I might have earlier, but with my travel schedule, it slipped by me.

Your return_test is in a new branch (double-terminators.) I'd love to find an elegant solution to this, but here is my first impression: the LLVM Builder class misbehaves when generating multiple terminator instructions, although the IR parser accepts the first. From a semantic viewpoint, I would prefer to raise a RuntimeError when a program attempts to emit a second terminator. This could be managed in ruby-llvm in an ad hoc way, but until that is implemented, it remains as undefined behavior. If you have any more insight, I'd love to hear it.

Best,

Jeremy


On Sunday, August 21, 2011 at 2:20 PM, Ary Borenszweig wrote:

> I wanted to make a pull request but I already have one. When going to the pull request page it also shows that it includes that second commit with the failing test. Maybe you never merged the other pull request?
>
> https://github.com/jvoorhis/ruby-llvm/pull/6
>
> In any case, here's the commits on my side:
>
> https://github.com/asterite/ruby-llvm/commit/ca999aa6f27308300c3cfbfaaf5c16c7edc76bc6
> https://github.com/asterite/ruby-llvm/commit/c8abae7b4a27ecc64a1060951258a4114e968b9d
>
> (I just realized a commited a test with just one return... I was checking if it worked with one return and forgot to add the second return back :-()
>

Ary Borenszweig

unread,
Aug 21, 2011, 10:25:56 PM8/21/11
to ruby...@googlegroups.com
Well, if the LLVM Builder class is the one that misbehaves, we should raise this issue to the LLVM developers. As I see it, LLVM abstracts you of many things, and I'd like it to abstract me of having to manually check if I already returned from a function (every language built on top of LLVM would have to check it, it's better to have that funcionality in LLVM itself).

I'll try to contact the LLVM developers and talk to them about this...

Thanks for checking this out, Jeremy.
Reply all
Reply to author
Forward
0 new messages