LLVM,预期指令?

huangapple go评论64阅读模式
英文:

LLVM, Expected Instruction?

问题

以下是翻译好的部分:

我编写了以下短小的Assembly LLVM代码(我知道它只是用于测试,不高效):

```assembly
define void @main() {
label_41:
%t22 = add i32 0, 0
label_43:
%t23 = add i32 0, 0
}

当我尝试这样运行它时,我收到了一个错误:

Downloads % /usr/local/opt/llvm/bin/lli t02.out
/usr/local/opt/llvm/bin/lli: lli: t02.out:4:1: error: expected instruction opcode
label_43:
^

问题是什么,缺少哪个操作码?


<details>
<summary>英文:</summary>

I wrote the following short Assembly LLVM code (I know it&#39;s not efficent only for testing purposes):

define void @main() {
label_41:
%t22 = add i32 0, 0
label_43:
%t23 = add i32 0, 0
}


When I try to run it like this I get an error:

Downloads % /usr/local/opt/llvm/bin/lli t02.out
/usr/local/opt/llvm/bin/lli: lli: t02.out:4:1: error: expected instruction opcode
label_43:
^


What&#39;s the problem, which opcode is missing?

</details>


# 答案1
**得分**: 10

LLVM中的标签开始一个新的块。而且每个块都必须以[终结指令](https://llvm.org/docs/LangRef.html#terminator-instructions)(如`ret`或`br`)结束。

LLVM出现错误是因为它达到了一个标签,但前面的块没有以终结指令结束。要使其编译通过,您需要在`label_43:`之前和函数结束之前添加终结指令。

<details>
<summary>英文:</summary>

A label in LLVM starts a new block. And each block must end with a [terminator instruction](https://llvm.org/docs/LangRef.html#terminator-instructions) such as `ret` or `br`.

LLVM is giving the error because it reached a label but the preceding block didn&#39;t end with a terminator instruction. To get this to compile, you need to add terminator instructions before `label_43:` and before the end of the function.

</details>



huangapple
  • 本文由 发表于 2023年7月4日 21:42:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76613261.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定