LLVM 的 'invoke' 指令是终止符吗?如果是,为什么不在语法上?

Is LLVM's 'invoke' instruction a terminator, and if so, why not syntactically?

在文档[1]中,invoke指令被列为终止符指令,但语法上写为:

<result> = invoke [cconv] [ret attrs] <ty>|<fnty> <fnptrval>(<function args>) 
              [fn attrs] [operand bundles] to label <normal label> 
              unwind label <exception label>

并且在描述中它说它就像一个 call(它也绑定了一个结果)。

如果指令是终止符指令,为什么要这样写?是否可以使用该指令<result>?事实上,invoke 之后的任何指令是否可以访问?

在实验中,似乎在 return 成功时,控制流向 <normal label>。有没有一种特殊的方法 returning 而不是 return 控制 invoke 之后的指令?

与此相关,如果控制总是传递给 <normal label>,是否有可能访问 returned 的值(假设不是 returning void) 来自被调用的函数?

  1. http://llvm.org/docs/LangRef.html#terminator-instructions

您有多个问题:

  1. Why is the instruction written this way if it is a terminator instruction?

这样写是为了支持异常处理。这是一种处理正常结果流或异常捕获的快捷方式(而且非常方便),无需大量额外的机器。

  1. is it ever possible to use that <result>?

在以相应标签开头的基本块中,您应该能够访问结果。尝试这样做时是否遇到错误?

  1. Indeed, will any instructions after an invoke ever be reachable?

因为它是基本块的终止指令,所以一般答案是.接下来通常是某物的标签,可以是 invoke 中的那些设置,也可以是其他一些 branch/switch 标签。

  1. is it possible to get access to the value that is returned (assuming not returning void) from the invoked function?

这看起来像是问题 #2 的重复。所以同样的答案适用。