user2084755
user2084755

Reputation: 169

How does the invoke instruction work in LLVM?

Can someone explain to me how the llvm invoke the works? I have the statement:

invoke void @ _ZN7sc_core9sc_signalIN5sc_dt6sc_intILi16EEEEC1Ev (% "class.sc_core :: sc_signal.57" *% operator1) to label %invoke.cont unwind label %lpad

It seems to me that it makes a call to a function and then jumps to a label. But which label? label %invoke.cont or label %lpad?? How to identify the label for which it jumps?

Upvotes: 3

Views: 1964

Answers (1)

bames53
bames53

Reputation: 88225

LLVM Language Reference

Syntax

<result> = invoke [cconv] [ret attrs] <ptr to function ty> <function ptr val>(<function args>) [fn attrs]
 to label <normal label> unwind label <exception label>

Overview

The ‘invoke‘ instruction causes control to transfer to a specified function, with the possibility of control flow transfer to either the ‘normal‘ label or the ‘exception‘ label. If the callee function returns with the “ret” instruction, control flow will return to the “normal” label. If the callee (or any indirect callees) returns via the “resume” instruction or other exception handling mechanism, control is interrupted and continued at the dynamically nearest “exception” label.

The syntax specification identifies the first label as the normal label, used for ret, and the second label as the exception label, used for exceptions. This is easy to remember because the term 'unwind' refers to cleanup performed when exceptions are thrown. So the instruction explicitly identifies the 'unwind label'. And the code used for this is often referred to as a 'landing pad', thus the label 'lpad' works as a reminder of what that basic block does.

Upvotes: 4

Related Questions