[LLVMdev] indirect jumps
Eli Friedman
eli.friedman at gmail.com
Wed Apr 14 15:27:10 PDT 2010
On Wed, Apr 14, 2010 at 2:43 PM, dan mihai <dnmh68 at hotmail.com> wrote:
> Hi,
>
> What kind of C/C++ high level code can generate a computed jump, such as:
> jmpq *%r14
> or
> jmpq *(%r14,%rbx,8)
> ?
>
> I imagine that any calls (including virtual) would use something like 'call
> *%r14',
> and the above jumps are mostly from 'switch' statements.
>
> Is this correct?
> Anything else?
Ways I can think of to generate computed jumps:
int f1(int (*b)(void)) { return b(); } // Tail call (recently
implemented in LLVM)
void f(void), g(void), h(void), i(void);
void f2(int x) { switch (x) { case 1: f(); case 2: g(); case 3: h();
case 4: i(); } } // switch
void f3(int n) { void* x[] = { &&L1, &&L2, &&L3 }; goto *x[n]; L1:
f(); L2: g(); L3: h(); } // computed goto
Note that virtual thunks, which show up with C++ class hierarchies,
internally look similar to f1.
-Eli
More information about the llvm-dev
mailing list