英文:
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'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'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'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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论