小编Bin*_*ain的帖子

LLVM alloca导致while语句上的堆栈溢出

我正在为针对LLVM-IR的玩具语言实现前端编译器,并且在运行编译while语句时遇到堆栈溢出:

例如,此代码应该永远运行,但我们的编译版本堆栈在一段时间后溢出.

def run(): Void = {
    i = 0;
    while(true) {
        i = i + 1;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是编译的LLVM-IR:

define i32 @run() nounwind ssp {
    ; i = 0
    %i = alloca i32, align 4
    %1 = alloca i32, align 4
    store i32 0, i32* %1, align 4
    %2 = load i32* %1, align 4
    store i32 %2, i32* %i, align 4
    br label %3

; <label>: %3
    ; while(true)
    ; Generated by compileExpression(condition)
    %4 = alloca …
Run Code Online (Sandbox Code Playgroud)

compiler-construction llvm llvm-ir

4
推荐指数
1
解决办法
822
查看次数

标签 统计

compiler-construction ×1

llvm ×1

llvm-ir ×1