llvm ir表现不如预期

时间:2016-11-05 15:53:22

标签: compiler-construction llvm code-generation llvm-ir

我有以下llvm ir并且花了大部分时间尝试调试它我似乎无法掌握它。在我的Windows机器上运行时,程序只是在循环中冻结(with)段错误。

; standard declaration etc
%gen__list__0 = type { i8*, i64, i64 }
%const_array_offset = type { i64, i64 }
; other declaration etc
@gbl_constant_59 = common constant [20 x i8] c"aaaaaaaaaaaaaaaaaaaa", align 
; more function declarations etc

define internal %gen__list__0 @gen__fun__elevate12(%const_array_offset*) {
entry:
  %1 = alloca %gen__list__0
  %2 = getelementptr %const_array_offset, %const_array_offset* %0, i32 0, i32 0
  %3 = load i64, i64* %2
  %4 = getelementptr %const_array_offset, %const_array_offset* %0, i32 0, i32 1
  %5 = load i64, i64* %4
  %6 = sub i64 %5, %3
  %7 = mul i64 %6, i64 2
  %8 = getelementptr %gen__list__0, %gen__list__0* %1, i32 0, i32 0
  %9 = getelementptr %gen__list__0, %gen__list__0* %1, i32 0, i32 1
  %10 = getelementptr %gen__list__0, %gen__list__0* %1, i32 0, i32 2
  store i64 %6, i64* %9
  store i64 %7, i64* %10
  %11 = mul i64 ptrtoint (i8* getelementptr (i8, i8* null, i32 1) to i64), %7
  %12 = call i8* @malloc(i64 %11)
  store i8* %12, i8** %8
  %13 = getelementptr %gen__list__0, %gen__list__0* %1, i32 0, i32 0
  %14 = load i8*, i8** %13
  %15 = getelementptr i8, i8* %14, i64 %6
  %16 = getelementptr [20 x i8], [20 x i8]* @gbl_constant_59, i32 0, i64 %3
  %17 = alloca i8*
  store i8* %16, i8** %17
  %18 = alloca i8*
  store i8* %14, i8** %18
  br label %bb2

bb2:                                              ; preds = %bb3, %entry
  %19 = load i8*, i8** %18
  %20 = icmp ne i8* %19, %15
  br i1 %20, label %bb3, label %bb4

bb3:                                              ; preds = %bb2
  %21 = load i8*, i8** %17
  %22 = getelementptr i8, i8* %21, i32 1
  store i8* %22, i8** %17
  %23 = load i8*, i8** %18
  %24 = getelementptr i8, i8* %23, i32 1
  store i8* %24, i8** %18
  br label %bb2

bb4:                                              ; preds = %bb2
  %25 = load %gen__list__0, %gen__list__0* %1
  ret %gen__list__0 %25
}

所有帮助都能理解这一点/它/我可能出错的地方。

循环只是实现

c ++ style psuedo代码,用于实现

的循环
for(iterator it = begin; it != end; ++it) {
     //code in loop - atm blank
}

1 个答案:

答案 0 :(得分:0)

通过将代码放入llc来找到问题。显然,使用公共链接标记的常量只能使用零初始化程序。要获得没有零初始值设定项的全局常量(如@gbl_constant_59的情况),您需要声明常量内部或外部。