[LLVMdev] Question about jumptable and indirect function call.

Tom Roeder tmroeder at google.com
Mon Oct 6 09:58:14 PDT 2014


On Mon, Oct 6, 2014 at 9:14 AM, XiaoGuang Wang <xjtuwxg at gmail.com> wrote:

> Thanks Tim,
>
>
>> On 5 October 2014 13:47, XiaoGuang Wang <xjtuwxg at gmail.com> wrote:
>> > So what's going on with my test. Is there something I did wrong with
>> > jumptable options? Or is the jumptable tried to address other problem,
>> not
>> > indirect call?
>>
>> I think LLVM's jump table pass requires explicit function annotations
>> in the IR for functions that should go via the table, which Clang
>> doesn't create. Something like this in its simplest form:
>>
>> define void @foo() unnamed_addr jumptable {
>>   ret void
>> }
>>
>> define void @main() {
>>   %var = alloca void()*
>>   store void()* @foo, void()** %var
>>   %func = load void()** %var
>>   call void %func()
>>   ret void
>> }
>>
>
>  You're right. It seems we need to manually annotate the IR function in
> this case. I just found a clang patch which Tom Roeder provided (
> http://comments.gmane.org/gmane.comp.compilers.clang.scm/102395). And I
> tried it, it works with clang -ffcif test.c.
>

Yes, that's the right patch to use.  You might also want to look at the
test cases in, e.g., test/CodeGen/X86/jump_table*.ll to see the code that
is generated by the annotations. I'd be happy to answer other questions you
might have.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141006/d0bc5ad9/attachment.html>


More information about the llvm-dev mailing list